sum macro



On Fri, Nov 7, 2008 at 4:04 PM, Hal Finkel <hal.finkel at yale.edu> wrote:
> Hello,
>
> I am trying to figure out how to define a macro or function which will
> sum a given expression of a given variable from 1 to 4.
>
> This does not work:
> sum1to4(exp, var) ::= sum(exp, var, 1, 4);
>
> sum1to4(x, x);
> 4*x
>
> sum(x, x, 1, 4);
> 10

This has to to with the way sum evaluates its arguments. A possible
definition which works is:

(%i3) sum1to4(expr, var) := apply(sum, [expr, var, 1, 4]);
(%o3) sum1to4(expr,var):=apply(sum,[expr,var,1,4])
(%i4) sum1to4(x,x);
(%o4) 10

HTH,
-- 
Andrej