defrule for altering sum expressions?



Maybe this is a sum noun / verb thing? 

My favorite way to do such transformations is to substitute a lambda form
for the function (notice the nounify('sum)).

(%i156) change_sum_limits(e,lo,hi) := subst(nounify('sum) = 
lambda([q,k,a,b], sum(q,k,lo,hi)),e)$

(%i157) change_sum_limits(42 + sum(f(k),k,a,b),i-1,i+1);
(%o157) f(i+1)+f(i)+f(i-1)+42

--Barton

maxima-bounces at math.utexas.edu wrote on 01/25/2012 01:48:43 PM:

> From: dlakelan <dlakelan at street-artists.org>
> To: Maxima Mailing List <maxima at math.utexas.edu>
> Date: 01/25/2012 01:47 PM
> Subject: defrule for altering sum expressions?
> Sent by: maxima-bounces at math.utexas.edu
> 
> I'd like to define the following rule and have it convert a sum into a
> "nearest neighbor sum" so that the sum is from i-1 to i+1 no matter what
> the original bounds are. Any ideas why it doesn't work?
> 
> numorsym(a) := numberp(a) or symbolp(a);
> 
> defmatch(A,true, [low,high],numorsym);
> 
> defrule(nearestneighborsum,sum(A,j,low,high),sum(A,j,i-1,i+1));
> 
> but it doesn't work:
> 
> (%i71) numorsym(x) := numberp(x) or symbolp(x);
> (%o71)              numorsym(x) := numberp(x) or symbolp(x)
> (%i72) matchdeclare(A,true,[low,high],numorsym);
> (%o72)                               done
> (%i73) defrule(nearestneighborsum,sum(A,j,low,high),sum(A,j,i-1,i+1));
> (%o73) nearestneighborsum : sum(A, j, low, high) -> sum(A, j, i - 1, i + 
1)
> (%i74) nearestneighborsum(sum(foobar[j],j,1,N));
> (%o74)                               false
> 
> 
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima