From: Robert D. <rob...@us...> - 2007-07-17 13:42:59
|
Update of /cvsroot/maxima/maxima/share/contrib/ezunits In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv22144/share/contrib/ezunits Modified Files: ezunits.mac Log Message: (1) Implement simplify_units to assume units symbols are positive. Call simplify_units from the exponent rule (as well as the multiplication rule). (2) Quote the symbol "dimensional" in functions to quiet complaint from translation code about "undeclared global variable" (something like that). Index: ezunits.mac =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/ezunits/ezunits.mac,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ezunits.mac 11 Mar 2007 02:22:30 -0000 1.3 +++ ezunits.mac 17 Jul 2007 13:42:52 -0000 1.4 @@ -16,8 +16,8 @@ apply ('define_variable, [a%, a%, any_check]), put (a%, units_check (a%), value_check), put (a%, u%, units), - if featurep (a%, dimensional) = false - then apply (declare, [a%, dimensional])); + if featurep (a%, 'dimensional) = false + then apply (declare, [a%, 'dimensional])); declare_qty (a%, q%) := block (local (a%, q%), @@ -30,7 +30,8 @@ */ declare1_qty (a%, q%) := block (local (a%, q%), - if featurep (a%, dimensional) = false then apply (declare, [a%, dimensional]), put (a%, q%, qty)); + if featurep (a%, 'dimensional) = false + then apply (declare, [a%, 'dimensional]), put (a%, q%, qty)); units_check (zz%) := block (local (zz%), @@ -41,22 +42,22 @@ qty(e%) := block (local (e%), if atom(e%) then - if featurep (e%, dimensional) then + if featurep (e%, 'dimensional) then if get (e%, qty) = false then 'qty(e%) else get (e%, qty) else e% else if unitop_p(e%) then first(e%) - else if featurep (op(e%), dimensional) then 'qty(e%) + else if featurep (op(e%), 'dimensional) then 'qty(e%) else apply (op(e%), map (qty, args(e%)))); units(e%) := block (local (e%), if atom(e%) then - if featurep (e%, dimensional) then + if featurep (e%, 'dimensional) then if get (e%, units) = false then 'units(e%) else get (e%, units) else 1 else if mapatom (e%) then units (op (e%)) /* mapatom but not atom => subscripted */ else if unitop_p(e%) then second(e%) - else if featurep (op(e%), dimensional) then units(op(e%)) + else if featurep (op(e%), 'dimensional) then units(op(e%)) else apply (op(e%), map (units, args(e%)))); d(e%) := dimension (units (e%)); @@ -71,7 +72,7 @@ xx%, nonconstantp); simp: false$ -tellsimpafter (uu%^ccn1%, (qty(uu%)^ccn1%) ` (units(uu%)^ccn1%)); +tellsimpafter (uu%^ccn1%, (qty(uu%)^ccn1%) ` simplify_units (units(uu%)^ccn1%)); tellsimpafter (nd% * uu%, multiply_with_units (nd%, uu%)); tellsimpafter (nd% + uu%, add_with_units (nd%, uu%)); @@ -82,9 +83,9 @@ unitop_p (e%) := atom (op(e%)) and is (nounify (op(e%)) = nounify ("`")); unitp (e%) := - if atom(e%) then featurep (e%, dimensional) + if atom(e%) then featurep (e%, 'dimensional) else if unitop_p (e%) then true - else featurep (op(e%), dimensional); + else featurep (op(e%), 'dimensional); constantp_not1 (x%) := constantp(x%) and x% # 1; constantp_not0 (x%) := constantp(x%) and x% # 0; @@ -125,7 +126,13 @@ everything_else(e%) := e%/constant_factors(e%); -simplify_units (e%) := e%; +simplify_units (e%) := block + ([L% : listofvars (e%)], + L% : makelist (x% > 0, x%, L%), + apply (assume, L%), + e% : expand (e%, 0, 0), + apply (forget, L%), + e%); /* Compile matchdeclare predicate functions in hopes of greater speed */ compile (constantp_not0, constantp_not1, mult_expr_nontrivialconstfactorsp, nondimensional, unitp, nonconstantp); |