Mathematica Mathematica -difference of two Symbolic summations

  • Thread starter Thread starter Osiris
  • Start date Start date
  • Tags Tags
    Maple Mathematica
AI Thread Summary
The discussion centers on difficulties encountered while manipulating summations in Mathematica and Maple. The original goal was to compute the difference between two sums, but attempts to adjust the limits of summation resulted in unexpected outputs. It was noted that both Mathematica and Maple struggle with abstract manipulations of unevaluated sums and integrals. The recommended approach is to use a dummy sum command or a list to encapsulate both the summand and its limits, allowing for easier manipulation before reintroducing it into the sum. An example was provided illustrating how to define rules for manipulating sums, which can automate operations through pattern recognition. The discussion highlights the importance of structuring expressions carefully to improve efficiency in computations.
Osiris
Messages
19
Reaction score
0
I wish to compute
Sum[f, {i, 0, m}] - Sum[f, {i, 0, j}]

but can't get the expected result
Sum[f, {i, j+1, m}]


I also tried
Sum[f, {i, 0, m}] - f[0]
but can't get the expected result
Sum[f, {i, 1, m}]


It seems that mathematica can't change the minimum/maximum value of the summation variable i above...

I also tried maple, but failed.
 
Physics news on Phys.org
Yep, Mma and Maple aren't very good at abstract manipulations on unevaluated sums and integrals. If you need to do these types of operations on sums/integrals it is best to work with an object (eg a List or a dummy sum command) containing both the summand/integrand and the range/limits, then plug it back into the integral/sum once you are done. Many operations like the one you have above can be automated with pattern recognition.
 
Simon_Tyler said:
Yep, Mma and Maple aren't very good at abstract manipulations on unevaluated sums and integrals. If you need to do these types of operations on sums/integrals it is best to work with an object (eg a List or a dummy sum command) containing both the summand/integrand and the range/limits, then plug it back into the integral/sum once you are done. Many operations like the one you have above can be automated with pattern recognition.

Thanks Simon. I am a newbie of Mathematica and not quite clear about using pattern recognition.

Could you please show an example for an operation above?

How about a more general case:
Sum[a*f, {i, 0, m}] - b*f[0]
I expect to get
Sum[a*f, {i, 1, m}]+(a-b)*f(0)
where a and b are positive integers.
 
Here's a few rules and examples to get you started. I've defined a dummy sum command so that Mma does not try to evaluate the sum at each step.

The last rule is pretty ugly.
i.e. it will be slow in expressions with lots of terms, because it will get tested many times. If you have a more specific structure in mind, then you could make the rules more specific and thus faster.

Code:
In[1]:= sumRules={
sum[expr_,{i_,low_,up1_}]+sum[expr_,{i_,up1_,up2_}]:>sum[expr,{i,low,up2}],
sum[expr_,{i_,low_,up1_}]-sum[expr_,{i_,low_,up2_}]:>sum[expr,{i,up2,up1}],
sum[a_. expr_,{i_,low_,up_}]+b_. expr2_/;(expr2==expr/.i->low):>sum[expr,{i,low+1,up}]+(a+b)expr2};
In[2]:= sumToSum[expr_]:=expr/.sum->Sum

Code:
In[3]:= sum[f[i],{i,0,m}]+sum[f[i],{i,m,j}]/.sumRules
Out[3]= sum[f[i],{i,0,j}]
In[4]:= sum[f[i],{i,0,m}]-sum[f[i],{i,0,j}]/.sumRules
Out[4]= sum[f[i],{i,j,m}]

Code:
In[5]:= sum[7f[i],{i,0,m}]-2f[0]/.sumRules
%/.f[i_]:>i^2+1
%//sumToSum
Out[5]= 5 f[0]+sum[f[i],{i,1,m}]
Out[6]= 5+sum[1+i^2,{i,1,m}]
Out[7]= 5+1/6 (7 m+3 m^2+2 m^3)
 
Last edited:

Similar threads

Replies
19
Views
2K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
4
Views
2K
Back
Top