How to combine two sums and factor out a common element expression?

Viewed 125

Here's the initial premise: two sums s1 and s2 are added; the sum element expressions have a common factor a[n].

s1: sum(r1[m,q]*b[m,n]*a[n],n,0,N)$
s2: sum(r2[m,q]*c[m,n]*a[n],n,0,N)$
s1+s2;

I expect the sums to be combined and the common element expression a[n] factored out:

s12: sum(a[n]*(r1[m,q]*b[m,n]+r2[m,q]*c[m,n]),n,0,N);

However, I'm unable to make Maxima produce such contraction. The most simplification I was able to obtain was using sumcontract(s1+s2) and it results in two sums without the common element being factored out:

r1[m,q]*sum(b[m,n]*a[n], n,0,N) + r2[m,q]*sum(c[m,n]*a[n], n,0,N);

How to make Maxima produce the factored out expression from s1+s2 as in s12 above?

NOTE: If we remove the r1 and r2, then the factor(sumcontract(s1+s2)) indeed results in the expected s12 expression. However, with both present, it results in two sums and does not factor out the a[n] as mentioned.

1 Answers

How about this. I've applied sumcontract, intosum, and factor.

(%i1) s1: sum(r1[m,q]*b[m,n]*a[n],n,0,N)$

(%i2) s2: sum(r2[m,q]*c[m,n]*a[n],n,0,N)$

(%i3) s1 + s2;
                  N                       N
                 ====                    ====
                 \                       \
(%o3)     r2      >    c     a  + r1      >    b     a
            m, q /      m, n  n     m, q /      m, n  n
                 ====                    ====
                 n = 0                   n = 0
(%i4) intosum (%);
           N                       N
          ====                    ====
          \                       \
(%o4)      >    c     r2     a  +  >    b     r1     a
          /      m, n   m, q  n   /      m, n   m, q  n
          ====                    ====
          n = 0                   n = 0
(%i5) sumcontract (%);
             N
            ====
            \
(%o5)        >    (c     r2     a  + b     r1     a )
            /       m, n   m, q  n    m, n   m, q  n
            ====
            n = 0
(%i6) factor (%);
              N
             ====
             \
(%o6)         >    (c     r2     + b     r1    ) a
             /       m, n   m, q    m, n   m, q   n
             ====
             n = 0

In this, intosum is pushing constant factors back into the sum.

Related