<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, How to substract two Sums</title>
    <link>http://www.mapleprimes.com/questions/99927-How-To-Substract-Two-Sums</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 07:23:37 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 07:23:37 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, How to substract two Sums</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, How to substract two Sums</title>
      <link>http://www.mapleprimes.com/questions/99927-How-To-Substract-Two-Sums</link>
    </image>
    <item>
      <title>combine</title>
      <link>http://www.mapleprimes.com/questions/99927-How-To-Substract-Two-Sums?ref=Feed:MaplePrimes:How to substract two Sums:Comments#answer99937</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=combine/range"&gt;?combine/range&lt;/a&gt; is one possibility, but its limitations mean that it cannot combine the two sums as they currently are. However, the correct result can be achieved by changing the two sums into three sums with overlapping ranges.&lt;/p&gt;
&lt;p&gt;s1 := Sum(x(i), i = n-1 .. m):&lt;br&gt;s2 := Sum(x(i), i = n .. m):&lt;br&gt;s3 := Sum(x(i), i = n .. m+1):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;s1 - s2:&lt;br&gt;c1:=combine(%, 'range'):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;s3 - s2:&lt;br&gt;c2:=combine(%, 'range'):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;value(c1+c2);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x(n - 1) + x(m + 1)&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;Duncan&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=combine/range"&gt;?combine/range&lt;/a&gt; is one possibility, but its limitations mean that it cannot combine the two sums as they currently are. However, the correct result can be achieved by changing the two sums into three sums with overlapping ranges.&lt;/p&gt;
&lt;p&gt;s1 := Sum(x(i), i = n-1 .. m):&lt;br&gt;s2 := Sum(x(i), i = n .. m):&lt;br&gt;s3 := Sum(x(i), i = n .. m+1):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;s1 - s2:&lt;br&gt;c1:=combine(%, 'range'):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;s3 - s2:&lt;br&gt;c2:=combine(%, 'range'):&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;value(c1+c2);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x(n - 1) + x(m + 1)&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;Duncan&lt;/p&gt;</description>
      <guid>99937</guid>
      <pubDate>Tue, 07 Dec 2010 04:12:15 Z</pubDate>
      <itunes:author>DuncanA</itunes:author>
      <author>DuncanA</author>
    </item>
    <item>
      <title>more generally</title>
      <link>http://www.mapleprimes.com/questions/99927-How-To-Substract-Two-Sums?ref=Feed:MaplePrimes:How to substract two Sums:Comments#answer99975</link>
      <itunes:summary>&lt;p&gt;It can get trickier, if there are more "mismatches" at the range ends. A procedure can be constructed which uses a single intermediate that seems to do the trick (in at least some more cases).&lt;/p&gt;
&lt;pre&gt;&amp;gt; combminus:=proc(s::specfunc(anything,Sum),t::specfunc(anything,Sum))
&amp;gt;    local temp;
&amp;gt;    if op(1,s) = op(1,t) then
&amp;gt;       temp:=Sum(op(1,s),i=op(1,rhs(op(2,s)))..op(2,rhs(op(2,t))));
&amp;gt;       value(combine(s-temp)+combine(temp-t));
&amp;gt;    else
&amp;gt;       s-t;
&amp;gt;    end if;
&amp;gt; end proc:


&amp;gt; s1 := Sum(x(i), i = n-1 .. m-1):
&amp;gt; s3 := Sum(x(i), i = n+1 .. m+1):

&amp;gt; value(combine(s3-s1));

              /  m - 1         \   /  m + 1      \
              | -----          |   | -----       |
              |  \             |   |  \          |
              |   )            |   |   )         |
              |  /      (-x(i))| + |  /      x(i)|
              | -----          |   | -----       |
              \i = n - 1       /   \i = n + 1    /

&amp;gt; combminus(s3,s1);

               x(m) + x(m + 1) - x(n - 1) - x(n)

# The single intermediate s2 (as in DuncanA's Answer) does not suffice alone.
# (Not that anyone has claimed it would, of course.)
&amp;gt; s2 := Sum(x(i), i = n .. m):

&amp;gt; value(combine(s3-s2)
&amp;gt;       +combine(s2-s1));

     /  m + 1      \   /  m          \   /  m - 1         \
     | -----       |   |-----        |   | -----          |
     |  \          |   | \           |   |  \             |
     |   )         |   |  )          |   |   )            |
     |  /      x(i)| + | /    (-x(i))| + |  /      (-x(i))|
     | -----       |   |-----        |   | -----          |
     \i = n + 1    /   \i = n        /   \i = n - 1       /

          /  m       \
          |-----     |
          | \        |
          |  )       |
        + | /    x(i)|
          |-----     |
          \i = n     /

# No need to introduce this many intermediates,
# as `combminus` solved it above.
&amp;gt; s2_a := Sum(x(i), i = n .. m-1):
&amp;gt; s2_b := Sum(x(i), i = n+1 .. m-1):
&amp;gt; s2_c := Sum(x(i), i = n+1 .. m):

&amp;gt; value(combine(s3-s2_c)
&amp;gt;       +combine(s2_c-s2_b)
&amp;gt;       +combine(s2_b-s2_a)
&amp;gt;       +combine(s2_a-s1));

               x(m) + x(m + 1) - x(n - 1) - x(n)

# Another example.
&amp;gt; s1 := Sum(x(i), i = n-1 .. m+1):
&amp;gt; s3 := Sum(x(i), i = n .. m-1):

&amp;gt; value(combine(s3-s1));

               /  m + 1         \   /m - 1     \
               | -----          |   |-----     |
               |  \             |   | \        |
               |   )            |   |  )       |
               |  /      (-x(i))| + | /    x(i)|
               | -----          |   |-----     |
               \i = n - 1       /   \i = n     /

&amp;gt; combminus(s3,s1);

                  -x(m) - x(m + 1) - x(n - 1)
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;It can get trickier, if there are more "mismatches" at the range ends. A procedure can be constructed which uses a single intermediate that seems to do the trick (in at least some more cases).&lt;/p&gt;
&lt;pre&gt;&amp;gt; combminus:=proc(s::specfunc(anything,Sum),t::specfunc(anything,Sum))
&amp;gt;    local temp;
&amp;gt;    if op(1,s) = op(1,t) then
&amp;gt;       temp:=Sum(op(1,s),i=op(1,rhs(op(2,s)))..op(2,rhs(op(2,t))));
&amp;gt;       value(combine(s-temp)+combine(temp-t));
&amp;gt;    else
&amp;gt;       s-t;
&amp;gt;    end if;
&amp;gt; end proc:


&amp;gt; s1 := Sum(x(i), i = n-1 .. m-1):
&amp;gt; s3 := Sum(x(i), i = n+1 .. m+1):

&amp;gt; value(combine(s3-s1));

              /  m - 1         \   /  m + 1      \
              | -----          |   | -----       |
              |  \             |   |  \          |
              |   )            |   |   )         |
              |  /      (-x(i))| + |  /      x(i)|
              | -----          |   | -----       |
              \i = n - 1       /   \i = n + 1    /

&amp;gt; combminus(s3,s1);

               x(m) + x(m + 1) - x(n - 1) - x(n)

# The single intermediate s2 (as in DuncanA's Answer) does not suffice alone.
# (Not that anyone has claimed it would, of course.)
&amp;gt; s2 := Sum(x(i), i = n .. m):

&amp;gt; value(combine(s3-s2)
&amp;gt;       +combine(s2-s1));

     /  m + 1      \   /  m          \   /  m - 1         \
     | -----       |   |-----        |   | -----          |
     |  \          |   | \           |   |  \             |
     |   )         |   |  )          |   |   )            |
     |  /      x(i)| + | /    (-x(i))| + |  /      (-x(i))|
     | -----       |   |-----        |   | -----          |
     \i = n + 1    /   \i = n        /   \i = n - 1       /

          /  m       \
          |-----     |
          | \        |
          |  )       |
        + | /    x(i)|
          |-----     |
          \i = n     /

# No need to introduce this many intermediates,
# as `combminus` solved it above.
&amp;gt; s2_a := Sum(x(i), i = n .. m-1):
&amp;gt; s2_b := Sum(x(i), i = n+1 .. m-1):
&amp;gt; s2_c := Sum(x(i), i = n+1 .. m):

&amp;gt; value(combine(s3-s2_c)
&amp;gt;       +combine(s2_c-s2_b)
&amp;gt;       +combine(s2_b-s2_a)
&amp;gt;       +combine(s2_a-s1));

               x(m) + x(m + 1) - x(n - 1) - x(n)

# Another example.
&amp;gt; s1 := Sum(x(i), i = n-1 .. m+1):
&amp;gt; s3 := Sum(x(i), i = n .. m-1):

&amp;gt; value(combine(s3-s1));

               /  m + 1         \   /m - 1     \
               | -----          |   |-----     |
               |  \             |   | \        |
               |   )            |   |  )       |
               |  /      (-x(i))| + | /    x(i)|
               | -----          |   |-----     |
               \i = n - 1       /   \i = n     /

&amp;gt; combminus(s3,s1);

                  -x(m) - x(m + 1) - x(n - 1)
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>99975</guid>
      <pubDate>Wed, 08 Dec 2010 02:12:27 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>It works, thanks!</title>
      <link>http://www.mapleprimes.com/questions/99927-How-To-Substract-Two-Sums?ref=Feed:MaplePrimes:How to substract two Sums:Comments#comment99956</link>
      <itunes:summary>&lt;p&gt;It works, thanks!&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;It works, thanks!&lt;/p&gt;</description>
      <guid>99956</guid>
      <pubDate>Tue, 07 Dec 2010 20:18:29 Z</pubDate>
      <itunes:author>alabax</itunes:author>
      <author>alabax</author>
    </item>
  </channel>
</rss>