How to define commutative and linear
- Subject: How to define commutative and linear
- From: Robert Dodier
- Date: Thu, 22 Jul 2010 23:38:22 -0600
On 7/21/10, Niitsuma Hirotaka <hirotaka.niitsuma at gmail.com> wrote:
> How to define f(u+b*v,x+a*y)=f(u,x)+a*f(v,x)+b*f(u,y)+a*b*f(v,z) ?
Hmm. Don't you mean:
f(u + b*v, x + a*y) = f(u, x) + a*f(u, y) + b*f(v, x) + a*b*f(v, y) ??
Maxima doesn't have a bilinear or multilinear declaration,
so far as I know. (There is some share code for a multiadditive
declaration, but it doesn't handle the scalar factors.)
How about this:
declare (FOO, commutative);
matchdeclare (aa, all) $
matchdeclare (bb, lambda ([e], scalarp(e) and e # 1)) $
matchdeclare (cc, lambda ([e], not scalarp(e))) $
tellsimpafter (FOO (aa, bb*cc), bb * FOO (aa, cc)) $
tellsimpafter (FOO (bb*cc, aa), bb * FOO (cc, aa)) $
matchdeclare (pp, lambda ([e], not atom(e) and op(e) = "+")) $
tellsimpafter (FOO (pp, aa), map (lambda ([e], FOO (e, aa)), pp)) $
tellsimpafter (FOO (aa, pp), map (lambda ([e], FOO (aa, e)), pp)) $
/* examples:
declare ([a, b, c], scalar);
declare ([x, y, z], nonscalar);
FOO (x, y) - FOO (y, x);
FOO (a*x + b*y, z);
FOO (x, b*y - c*z);
FOO (x - z, y - z);
FOO (x, x + y - 2*z);
FOO (a, b);
FOO (x, y);
(may need to invoke rules repeatedly via ''%
dunno how to get all rules applied in one fell swoop)
*/
Hope this helps,
Robert Dodier