[Aimmath-commit] AIM/WEB-INF/maple/aim Inert.mpl,1.7,1.8 LaTeX.mpl,1.12,1.13
Brought to you by:
gustav_delius,
npstrick
From: <mo...@us...> - 2003-10-10 15:40:05
|
Update of /cvsroot/aimmath/AIM/WEB-INF/maple/aim In directory sc8-pr-cvs1:/tmp/cvs-serv12648 Modified Files: Inert.mpl LaTeX.mpl Log Message: improved implementation of the Inert package Index: Inert.mpl =================================================================== RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/Inert.mpl,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Inert.mpl 23 Sep 2003 21:35:32 -0000 1.7 --- Inert.mpl 10 Oct 2003 15:39:58 -0000 1.8 *************** *** 138,142 **** cat("InertFunction\\left(",TeX(args),"\\right)") end, ! "Returns a LaTeX string representation of this function evaluated on its args. The default method returns the string formed by concatenating the @inertFunction@ with the LaTeX form of the arguments in parentheses. Usually overridden by the constructor. " ], --- 138,142 ---- cat("InertFunction\\left(",TeX(args),"\\right)") end, ! "Returns a LaTeX string representation of this function evaluated on its args. The default method returns the string formed by concatenating the name @InertFunction@ with the LaTeX form of the arguments in parentheses. Usually overridden by the constructor. Note that when creating your own @Inert@ objects keep in mind that the arguments will often be @InertExpr@ objects whose @Value@ is of the correct type, so any routine that overrides this routine should handle them appropriately. " ], *************** *** 203,211 **** ", proc(this,F::Inert) ! local f,d,ARGS,Values,R; this['InertFunction']:=eval(F); ! ARGS:=args[3..nargs]; ! R:=this['setArgs',ARGS]; # if an error string is returned, let them know # ttd, change this to try/catch and pass along the error for better reporting? --- 203,210 ---- ", proc(this,F::Inert) ! local f,d,Values,R; this['InertFunction']:=eval(F); ! R:=this['setArgs',args[3..nargs]]; # if an error string is returned, let them know # ttd, change this to try/catch and pass along the error for better reporting? *************** *** 241,245 **** NewArgs:=args[2..nargs]; fi; ! NewArgs:=[NewArgs]; # now check that the new args have the correct quantity and are in the domain --- 240,244 ---- NewArgs:=args[2..nargs]; fi; ! NewArgs:=map(eval,[NewArgs]); # now check that the new args have the correct quantity and are in the domain *************** *** 256,260 **** if not d(Values) then # if a string is returned the arguments were invalid ! return sprintf("Invalid arguments for Inert function %s: %q",F['Name'],Values); fi; --- 255,259 ---- if not d(Values) then # if a string is returned the arguments were invalid ! return sprintf("Invalid arguments for Inert function %s: %q",F['Name'],`Inert/Note`(Values)); fi; *************** *** 269,275 **** G['NeedsParentheses'] and F['Precedence']>G['Precedence'] then ! ParenArgs:=eval(ParenArgs),cat("\\left(",i['TeX'],"\\right)") else ! ParenArgs:=eval(ParenArgs),i['TeX']; fi: else --- 268,276 ---- G['NeedsParentheses'] and F['Precedence']>G['Precedence'] then ! # WAS: ParenArgs:=eval(ParenArgs),cat("\\left(",i['TeX'],"\\right)") ! ParenArgs:=eval(ParenArgs),Parentheses(i) else ! # WAS: ParenArgs:=eval(ParenArgs),i['TeX']; ! ParenArgs:=eval(ParenArgs),eval(i) fi: else *************** *** 317,320 **** --- 318,322 ---- local a,g,NewArgs,Xvar,Xval; + if type(f,constant) then f *************** *** 330,343 **** Apply(f,op(Indets(f,symbol))=args[2],args[3..-1]) elif type(args[2],symbol=anything) then - Xvar:=op(1,args[2]); Xval:=op(2,args[2]); NewArgs:=NULL; ! g:=eval(copy(f)); ! for a in g['Args'] do ! NewArgs:=eval(NewArgs),eval(Apply(eval(a),args[2..-1])); od: ! g['setArgs',NewArgs]; ! eval(g); else f --- 332,342 ---- Apply(f,op(Indets(f,symbol))=args[2],args[3..-1]) elif type(args[2],symbol=anything) then Xvar:=op(1,args[2]); Xval:=op(2,args[2]); NewArgs:=NULL; ! for a in f['Args'] do ! NewArgs:=eval(NewArgs),eval(Apply(a,args[2..-1])); od: ! return `new/InertExpr`(f['InertFunction'],NewArgs) else f *************** *** 473,477 **** end, -1, # Nargs ! 'algebraic',# Domain "Identity", # Name false, # Needs parentheses --- 472,476 ---- end, -1, # Nargs ! 'anything', # Domain "Identity", # Name false, # Needs parentheses *************** *** 494,502 **** `Inert/Decimal`::Inert, "This inert represents the identity map for reals. It formats a real constant as a floating point number to certain specifications. The first argument is the number to be formatted. The optional second argument is a formatting string suitable to be used as a first argument for @sprintf@. If no format string is specified, @Decimal(r)@ will format the float @r@ in a ! \"reasonable\" manner.", `new/Inert`( proc(x) x end, # Map (we ignore the formatting string) # TeX ! proc(x::constant,s::string) local d,n,t,man,ex,sf; if nargs=1 then if abs(evalf(x))=0.0 then --- 493,503 ---- `Inert/Decimal`::Inert, "This inert represents the identity map for reals. It formats a real constant as a floating point number to certain specifications. The first argument is the number to be formatted. The optional second argument is a formatting string suitable to be used as a first argument for @sprintf@. If no format string is specified, @Decimal(r)@ will format the float @r@ in a ! \"reasonable\" manner. If @x@ is an @InertExpr@ whose value is a float, @TeX(Decimal(x))@ returns the existing formatting, i.e. @TeX(x)@. To override the existing format use @Decimal(Value(x))@ instead.", `new/Inert`( proc(x) x end, # Map (we ignore the formatting string) # TeX ! proc(x::{constant,InertExpr},s::string) local d,n,t,man,ex,sf; + + if type(x,InertExpr) then return x['TeX'] fi: if nargs=1 then if abs(evalf(x))=0.0 then *************** *** 542,546 **** `Package/Assign`( `Inert/Plus`::Inert, ! "The Inert + function. Associative and produces a signed sum. Ex: Plus(1,-2,3) formats as 1-2+3", `new/Inert`(`+`, # TeX --- 543,547 ---- `Package/Assign`( `Inert/Plus`::Inert, ! "The Inert + function. Associative and produces a signed sum. Simplifies @0+a@ and @a+0@ to @a@. Ex: @Plus(1,-2,0)@ formats as @1-2@", `new/Inert`(`+`, # TeX *************** *** 552,556 **** s:=""; for i to nargs do ! if not (args[i]=0 or (args[i]="0")) then if i>1 and not s="" then s:=s,"\\,",`aim/LaTeX/Signed`(args[i]); --- 553,557 ---- s:=""; for i to nargs do ! if not Value(args[i])=0 then if i>1 and not s="" then s:=s,"\\,",`aim/LaTeX/Signed`(args[i]); *************** *** 672,683 **** `new/Inert`(`-`, proc(x) # TeX ! if type(x,negative) or ! (type(x,InertExpr) and ! StringTools:-Remove( ! rcurry(member,{"{"," ","}"}),TeX(x))[1..1]="-") ! then ! return cat("-",Parentheses(x)[TeX]) else ! return PercentStringToProc("-%1")(x) fi: end, --- 673,680 ---- `new/Inert`(`-`, proc(x) # TeX ! if `aim/StartsNegative`(x) then ! return cat("-\\left(",TeX(x),"\\right)") else ! return cat("-",TeX(x)) fi: end, *************** *** 733,737 **** `Package/Assign`( `Inert/Times`::Inert, ! "The Inert * function. Uses concatentation to denote a product.", `new/Inert`(`*`, # Map proc() # TeX --- 730,734 ---- `Package/Assign`( `Inert/Times`::Inert, ! "The Inert * function. Uses concatentation to denote a product. Associative and simplifies @1*a@ and @a*1@ to @a@.", `new/Inert`(`*`, # Map proc() # TeX *************** *** 743,761 **** s:=""; for i to nargs do ! if not (args[i]=1 or (args[i]="1")) then if i=1 and nargs>1 and args[1]=-1 then s:="-"; else if not (s="-" or s="") then ! u:=StringTools:-Remove( ! rcurry(member,{"{"," ","}"}),s); ! t:=StringTools:-Remove(rcurry(member,{"{"," ","}"}), ! TeX(args[i])); ! if length(u)>0 and ! `Util/Numeric`(u[-1..-1]) and ! length(t)>0 and ! (`Util/Numeric`(t[1..1]) or t[1..1]="-") then ! s:=cat(s,"\\cdot{}",TeX(args[i])); else s:=cat(s,"\\,",TeX(args[i])); --- 740,761 ---- s:=""; for i to nargs do ! if not args[i]=1 then if i=1 and nargs>1 and args[1]=-1 then s:="-"; else if not (s="-" or s="") then ! u:=`aim/LaTeX/CleanNonprinting`(s); ! t:=`aim/LaTeX/CleanNonprinting`(TeX(args[i])); ! if length(u)>0 and length(t)>0 and ! `Util/Numeric`(u[-1..-1]) then ! if `Util/Numeric`(t[1..1]) then ! s:=cat(s,"\\cdot{}",TeX(args[i])); ! elif t[1..1]="-" then ! s:=cat(s,"\\cdot{}\\left(", ! TeX(args[i]),"\\right)"); ! else ! s:=cat(s,"\\,",TeX(args[i])); ! fi: else s:=cat(s,"\\,",TeX(args[i])); *************** *** 865,874 **** `Package/Assign`( `Inert/ToThe`::Inert, ! "The Inert ^ function. Inserts a ^ between terms and is not associative.", `new/Inert`(`^`, # Map proc(a,b) # TeX ! if b=1 or b="1" then TeX(a) ! elif b=0 or b="0" then "1" elif type(a,negative) or type(a,float) then --- 865,874 ---- `Package/Assign`( `Inert/ToThe`::Inert, ! "The Inert ^ function. Inserts a ^ between terms and is not associative. Simplifies @a^1@ to @a@ and @a^0@ to @1@.", `new/Inert`(`^`, # Map proc(a,b) # TeX ! if Value(b)=1 then TeX(a) ! elif Value(b)=0 then "1" elif type(a,negative) or type(a,float) then *************** *** 938,942 **** `Inert/Exp`::Inert, "The Inert exponential function.", ! `new/Inert`( exp, # Map proc(x) # TeX if x=1 then --- 938,942 ---- `Inert/Exp`::Inert, "The Inert exponential function.", ! `new/Inert`( exp, # Map proc(x) # TeX if x=1 then Index: LaTeX.mpl =================================================================== RCS file: /cvsroot/aimmath/AIM/WEB-INF/maple/aim/LaTeX.mpl,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** LaTeX.mpl 19 Sep 2003 04:11:15 -0000 1.12 --- LaTeX.mpl 10 Oct 2003 15:39:58 -0000 1.13 *************** *** 750,757 **** (type(r,`*`) and type(op(1,r),negative)) then # pull negative signs out front return cat(" - ",TeX(-r)) ! elif type(r,string) and r[1]="-" then # it already has a negative out front ! return cat(" - ",r[2..-1]) ! elif type(r,InertExpr) and r['TeX'][1]="-" then # it already has a negative out front ! return cat(" - ",r['TeX'][2..-1]) else return cat(" + ",TeX(r)) --- 750,755 ---- (type(r,`*`) and type(op(1,r),negative)) then # pull negative signs out front return cat(" - ",TeX(-r)) ! elif `aim/StartsNegative`(r) then # it already has a negative out front ! return TeX(r) else return cat(" + ",TeX(r)) |