On 5/23/10, Grigory Sarnitskiy <sargrigory at yandex.ru> wrote:
> RAv(expr1+expr2) = RAv(expr1) + RAv(expr2)
> RAv(expr1*expr2) = RAv(expr1) * RAv(expr2) + RCr(expr1, expr2)
>
> where RCr is some another function.
Maxima has some pattern matching functions, which have their
limitations but are still probably more powerful than what can be
achieved by part hacking. e.g.
matchdeclare (xx, lambda ([e], not atom(e) and op(e) = "+"));
matchdeclare (yy, lambda ([e], not atom(e) and op(e) = "*"));
tellsimp (Rav (xx), map (Rav, xx));
tellsimp (Rav (yy), Rav (first (yy)) * Rav (rest (yy)) + Rcr (first
(yy), rest (yy)));
With that, I get:
(%i6) Rav (x + y + z);
(%o6) Rav(z)+Rav(y)+Rav(x)
(%i7) Rav (x * y * z);
(%o7) Rav(x)*(Rav(y)*Rav(z)+Rcr(y,z))+Rcr(x,y*z)
(%i8) expand (%);
(%o8) Rav(x)*Rav(y)*Rav(z)+Rav(x)*Rcr(y,z)+Rcr(x,y*z)
(%i9) Rav (a*b - c*d);
(%o9) Rav(-c*d)+Rav(a)*Rav(b)+Rcr(a,b)
Rav(-c*d) doesn't simplify according to these rules because
op(-c*d) => "-", not "*" (as in -1*c*d). If it matters, we can
make up another rule to handle "-" expressions.
best
Robert Dodier