# Can't take difference of two sums

I am taking difference between two sums. Of course, what I wanted is A_s

But it's not evaluating this.

I tried Simplify, FullSimplify, Expand, and so on. But nothing works. What should I do?

I tried Nasser's suggestion. It is great! However, it works when I write it as you did, but it doesn't work when I write it as visually easy-to-read equation. Why is it like this? • as far as I know, Mathematica does not simplify sums with symbolic index. But maybe someone knows better. You could always use this trick ((Sum[a[t], {t, 1, s}] - Sum[a[t], {t, 1, s - 1}]) /. s -> 10) /. 10 -> s and this gives a[s] – Nasser Sep 2 '16 at 5:06
• @Nasser Thank you!. Just one thing that's going strange. It works when I write it as you did, but it doesn't work when I write it as visually easy-to-read equation. I edited my question to show what I mean. – user42459 Sep 2 '16 at 5:53
• I think may be you have syntax error. If you post plain Mathematica code it will be easier. The "/." is the ReplaceAll command. Make sure it is the same in your 2D illustration. – Nasser Sep 2 '16 at 6:35
• You need a space between the "." and the "1" to avoid it being interpreted as "0.1". – mikado Sep 2 '16 at 18:46

Try this:

 rule1 = Sum[a_.[t], {t, 1, m_}] - Sum[a_.[t], {t, 1, m_ - k_.}] :>
Sum[a[t], {t, m - k + 1, m}];


and then:

(Sum[a[t], {t, 1, s}] - Sum[a[t], {t, 1, s - 1}]) /. rule1

(*  a[s]  *)


Have fun!

• Wow this is a magic. Thank you so much. But what is ":>" ?? I googled but couldn't find it. Can you show me some mathematica documentation for ":>" ? Looks so useful. – user42459 Sep 2 '16 at 8:06
• @ user42459 Type ?:> in a notebook and evaluate. You will get an answer. Click then over the chevron >> in the end of this answer and you will have more details and examples. – Alexei Boulbitch Sep 2 '16 at 8:10
• @user42459 check this: reference.wolfram.com/language/ref/RuleDelayed.html – mattiav27 Sep 2 '16 at 8:11