On 6/11/06, Barton Willis <willisb at unk.edu> wrote:
>
>
> (%i1) declare(f,additive)$
> (%i2) f(x) := if mapatom(x) then 5 else funmake(f,[x])$
> (%i3) f(a+b);
> (%o3) f(b)+f(a)
> The output %o3 is simplified, but it isn't evaluated. Is this a
> bug?
This is not a bug. If you trace meval, you will see that 'f' is indeed
being called, with the arguments [a+b]. It is not being called with
arguments [a] and [b], because funmake is explicitly defined to construct an
application without evaluating it. If you change that by substituting
'apply' for 'funmake', then of course you get an infinite recursion.
I suppose you could do something fancy like simplify, see if the result is
different from the input, and if so, reevaluate the applications of 'f', but
that would be messy.
Simplification itself should never call evaluation. In general, programming
functions (a.k.a. evaluating functions, defined using ":=") and mathematical
functions (a.k.a. simplifying functions, defined by simplification rules)
should probably be kept quite distinct. Where they are conflated, as with
'integrate and 'diff, the noun/verb business comes into play and makes
things very messy, as we've seen with 'sum. In the above example, you seem
to be trying to simulate a simplification rule using an evaluated function.
Maxima does not make it easy to write simplification functions in user code,
other than with the pattern-matching facilities.
-s