Mathematica -difference of two Symbolic summations

• Mathematica
• Osiris
In summary, For the operation "Sum[f[i], {i, 0, m}] - Sum[f[i], {i, 0, j}]", the expected result can be achieved by using an object containing both the summand and range, and then plugging it back into the sum. This can be automated using pattern recognition, with rules such as "sum[expr_,{i_,low_,up1_}]+sum[expr_,{i_,up1_,up2_}]:>sum[expr,{i,low,up2}]" and "sum[a_. expr_,{i_,low_,up_}]+b_. expr2_/;(expr2==expr/.i->low):>sum[
Osiris
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.

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:

As a scientist, it is important to carefully consider and troubleshoot any unexpected results or errors that may occur in our calculations. In this case, it seems that Mathematica is having trouble changing the minimum/maximum value of the summation variable i. This could be due to a number of reasons, such as incorrect syntax or a limitation of the software. It may be helpful to consult the documentation or reach out to the Mathematica support team for assistance in resolving this issue. Additionally, trying a different software such as Maple may also provide a solution. It is important to thoroughly test and verify our calculations to ensure accurate results.

1. What is Mathematica?

Mathematica is a software program designed for mathematical and scientific computations. It allows users to perform complex calculations, create visualizations, and solve equations.

2. How can Mathematica be used to find the difference of two symbolic summations?

To find the difference of two symbolic summations, you can use the built-in function "Sum". For example, if you have two symbolic summations, Sum[a[i], {i, 1, n}] and Sum[b[i], {i, 1, n}], you can use the command "Sum[a[i] - b[i], {i, 1, n}]" to find their difference.

3. Can Mathematica handle complex mathematical expressions?

Yes, Mathematica is designed to handle complex mathematical expressions, including symbolic summations, integrals, and differential equations. It also has built-in functions for simplifying and manipulating these expressions.

4. Is Mathematica only useful for mathematicians?

No, Mathematica can be useful for anyone who needs to perform mathematical or scientific computations. It has a user-friendly interface and built-in functions that make it accessible for users with varying levels of mathematical knowledge.

5. Can Mathematica be used for data analysis and visualization?

Yes, Mathematica has powerful data analysis and visualization capabilities. It can import and manipulate data from various sources and has built-in functions for creating charts, graphs, and other visualizations of the data.

Similar threads

• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
187
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
446
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
400
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
410
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
• General Math
Replies
9
Views
1K