On 2013-06-08, Barton Willis <willisb at unk.edu> wrote:
> (%i1) (x:a,a:b,b:c,c:d,d:e)$
>
> OK:
>
> (%i2) substitute('cos = lambda([w],1-w^2/2), cos(x));
> (%o2) 1-a^2/2
I think that's a bug -- a function shouldn't reevaluate its result.
The bug originates in SIMPLIFYA, which calls MAPPLY1 when the operator
of an expression is a lambda expression (line 541 in src/simp.lisp in
the current version). I'm inclined to believe that function calls should
not be evaluated in simplification.
Disabling the call to MAPPLY1 changes a few results in the test suite,
most or maybe all of which stem from use of lambda substitutions in
share/algebra/nusum.mac. If we agreed to change SIMPLIFYA, it would
probably be straightforward to modify nusum accordingly.
> Not OK:
>
> (%i3) f : substitute([li[2] = lambda([w],w+w^2/4)], li[2](x));
> (%o3) lambda([w],w+w^2/4)(a)
I think that's correct. MAPPLY1 isn't called in this case because the
expression to be simplified looks like ((MQAPPLY) ((LAMBDA) ...) FOO)
instead of (((LAMBDA) ..) FOO). I don't know if it's design or accident
that the result is different.
best
Robert Dodier