maxima - rules and patterns



 
First of all, let me point out that this is somewhat unnatural to do,
 with respect to sums and products... e.g. the matching program
generally will succeed in matching a pattern p*q  against an
expression X  by allowing p=X and q=1.



For forms with a fixed number of arguments like sin, cos, etc. there is
no problem.

try this

matchdeclare(g,true);

defrule(r1, d(sin(g)), cos(g)*d(g));

sin(sin(x));
apply1(%,r1);



but also try..

matchdeclare([g,h],true);
defmatch(m1,g*h);
m1(X);

you may try to attach more conditions on the pattern match variables, like
they will not match 1, etc.

But you are looking for a syntactic match, and maxima's matcher is
too clever for you.

You could write a "tree walker" and check to see if op(expression,0)="+"
and do things with op(expression,1) ... op(expression,length(expression))

etc.

This would be needed only for + * and maybe - /.



RJF
> -----Original Message-----
> From: maxima-bounces at math.utexas.edu 
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Robert Marik
> Sent: Monday, February 25, 2008 3:07 AM
> To: maxima at math.utexas.edu
> Subject: maxima - rules and patterns
> 
> Dear users of maxima
> 
> I solve the following problem: I wish to write tools which enable to
> differentiate expresions in simple single steps, something like
> www.calc101.com
> 
> My problems are:
> 
> First problem:
> --------------
> write a function diffsin(expr) which scans the epxression expr for
> strings derivative(sin(....)) and has the following output
> 
> diffsin(2*sin(x)+derivative(sin(x)) + derivative(sin(x^2)))
> =
> 2*sin(x)+cos(x)+cos(x^2)*derivative(x^2)
> 
> and similar functions for the other basic elementary functions and for
> product, quotient and addition
> 
> for example I wish to define function diffproduct with the 
> following output
> diffproduct(1+x^7*sin(x)+derivative(x^2*cos(x)))
> =1+x^7*sin(x)+derivative(x^2)*cos(x)+x^2*derivative(cos(x))
> 
> I know that the quotient is treated as product in maxima, but I hope
> to solve this problem somehow (with simp:false?)
> 
> User will choose one step in diferentiation and Maxima will do the
> computations. Something similar to
> http://user.mendelu.cz/marik/maw/index.php?lang=en&form=integral
> (not yet translated into english, sorry)
> 
> Second problem:
> ---------------
> 
> given the expression, find the rule which has to be used as the first,
> second, ..... and apply them to get a result similar to
> http://calc101.com/webMathematica/derivatives.jsp
> 
> 
> 
> I looked into the maxima manual and I have seen that there are
> powerfull tools for this in maxima, but I am confused, which of the
> function should I use. I started my attemtps with
> 
> defrule(diffsum,derivative(a+b),derivative(a)+derivative(b));
> 
> but
> 
> diffsum(x+sin(x))
> 
> returns false :(
> 
> Can you give me a few pointers and tips to the following?
> 
> 1. which commnds to use to solve my problems, defrule, defmatch, 
> tellsimp, let?
> 2. which literature and which examples to study?
> 3. is there allready a similar package somewhere on the Internet?
> 4. what is wrong in my example?
> 
> 
> Thank you very much
> 
> Robert Marik
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>