How to evaluate a noun expresion



To prevent your function from entering an infinite loop, you need to
replace 'F(x) with
funmake(F,[x]). Thus

(%i34) F(x):=block([inflag:true],
 if atom(x)=true then funmake(F,[x])
 else
 if inpart(x,0)="+" then  map(F,x)
 else funmake(F,[x]))$

(%i35) F(a+b);
(%o35) F(b)+F(a)

(%i36) expr:subst(x=a+b,F(x));
(%o36) F(b+a)

(%i37) ev(expr,nouns);
(%o37) F(b)+F(a)

Not that it really matters, but here is a shorter version of F:

(%i38) ff(x) := block([inflag : true], if atom(x) or not op(x) = "+" then
funmake(ff,[x]) else map(ff, x));

Also, you can declare a function to be additive or multiadditive; for
example

(%i42) declare(g,multiadditive)$

(%i43) g(x+y,a+b);
(%o43) g(y,b)+g(y,a)+g(x,b)+g(x,a)

(%i44) g(x+y+z,a+b);
(%o44) g(z,b)+g(z,a)+g(y,b)+g(y,a)+g(x,b)+g(x,a)

Barton

-----maxima-bounces at math.utexas.edu wrote: -----

>To: maxima at math.utexas.edu
>From: jcano <jcano at agt.uva.es>
>Sent by: maxima-bounces at math.utexas.edu
>Date: 01/31/2008 04:08AM
>Subject: How to evaluate a noun expresion
>
>I use a  modified version of the newdiff function found in the Maxima
>book section 7.11.
>This function output some noun form and after that I have problems to
>evaluate expresions.
>
>My problem can be described with the following function:
>
>F(x):=block([inflag:true],
>  if atom(x)=true then 'F(x)
>  else
>  if inpart(x,0)="+" then  map(F,x)
>  else 'F(x));
>
>Hence
>
>(%i2) F(a+b);
>(%o2)                             F(b) + F(a)
>
>Assume that I have constructed some expresion like
>
>(%i3) expr:subst(x=a+b,F(x));
>(%o3)                              F(b + a)
>
>Now I dont know how to evaluate expr in order to obtain F(b)+F(a) :
>
>(%i4) ev(expr,eval);
>(%o4)                              F(b + a)
>(%i5) ev(expr,nouns);
>
>*** - Program stack overflow. RESET
>and also ev(expr,F) enter in an endless loop.
>
>Some help ?
>
>jose cano
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima