Mathematica -difference of two Symbolic summations

  • Context: Mathematica 
  • Thread starter Thread starter Osiris
  • Start date Start date
  • Tags Tags
    Maple Mathematica
Click For Summary
SUMMARY

The discussion focuses on manipulating symbolic summations in Mathematica, specifically the challenge of adjusting the limits of summation variables. Users encountered issues with expressions like Sum[f[i], {i, 0, m}] - Sum[f[i], {i, 0, j}] not yielding the expected results. The conversation highlights the limitations of both Mathematica and Maple in handling abstract manipulations on unevaluated sums and integrals. A recommended approach involves using a dummy sum command and pattern recognition to automate operations on sums, as demonstrated through specific rules and examples.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of symbolic summation concepts
  • Knowledge of pattern recognition techniques in programming
  • Basic experience with Maple for comparison
NEXT STEPS
  • Explore advanced pattern recognition in Mathematica
  • Learn about dummy functions and their applications in symbolic computation
  • Investigate the limitations of Maple for symbolic manipulations
  • Study the implementation of custom summation rules in Mathematica
USEFUL FOR

Mathematica users, mathematicians, and computer scientists interested in symbolic computation and manipulation of summations and integrals.

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 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K