On 2013-12-02, Litvinov Sergey <slitvinov at gmail.com> wrote:
> I am defining a following simplification for a functional E and a list
> of atoms. E should pull out everything that does not depend on any of
> the atoms in the list, but also it should pull out E(<...>). One can
> think of E as a time averaging functional, and about the atoms in the
> list as functions of time.
Here's my attempt. I think we can get the simplification rule machinery
to do some of the work for us. Here cc matches an expression which is
constant wrt E, either because it is free of the designated variables,
or because it is an E expression. (Incidentally if it were up to me, I'd
write list_of_nonconstants instead of runningthewordstogether.) I've
exploited a trick to catch everything else: if cc succeeds the catch-all
match variable (as determine by ordergreatp), then cc will get first
pick of the terms in a "*" expression and the catch-all will get all
the rest. (Now I feel dirty just for saying it. Yikes.)
matchdeclare (cc, lambda ([e], apply (freeof, append (get ('E, 'listofnonconstants), [e])) or (not atom(e) and op(e) = 'E))) $
matchdeclare (aa, all) $
tellsimpafter (E (aa * cc), cc * E (aa)) $
tellsimpafter (E (cc), cc) $
put ('E, '[x, y], 'listofnonconstants) $
OK, now we can try some examples.
[E (a), E (x * a), E (E (x) * a)];
=> [a,a*E(x),E(1)*a*E(x)]
Hmm. E(1) should simplify to 1, but tellsimpafter rules won't carry out
recursive simplifications (to avoid unterminating loops). Tell Maxima
to reevaluate and resimplify the previous result.
''%;
=> [a,a*E(x),a*E(x)]
So far, so good. Resimplification needed for next example also.
[E (y * E (x) * a), E (E (b * y * x) * a), E (a + b)];
=> [a*E(x)*E(y),E(1)*a*b*E(x*y),b+a]
''%;
=> [a*E(x)*E(y),a*b*E(x*y),b+a]
E (f(x) * g(y) * h(z));
=> E(f(x)*g(y))*h(z)
E (E (E (x)));
=> E(x)
E (E (E (x) * y) * z * %pi);
=> %pi*E(1)*E(x)*E(y)*z
You didn't mention it, but maybe E should be additive. Just guessing.
declare (E, additive) $
E (a*x + b*y);
=> b*E(y)+a*E(x)
Hope this helps, & good luck.
Robert Dodier