3

I have the following Maxima code:

m:sum(x[i],i,1,N)/N;

and then I want to calculate $m^2$.

m2:m^2, sumexpand;

Then I get double summation:

sum(sum(x[i1]*x[i2],i1,1,N),i2,1,N)/N^2

What I want to achieve is to expand it into the two sums.

The first one is sum(x[i]^2,i,1,N) and the second is the rest over non-equal indices. How should I do that? How should I do that with arbitrary power of m?

Thiyagu
  • 17,362
  • 5
  • 42
  • 79
0x2207
  • 878
  • 1
  • 6
  • 20

1 Answers1

5

sum is not declared linear by default; you can declare it linear and resimplify. Note that to get the expected effect, you have to declare the noun form of sum.

(%i1) m:sum(x[i],i,1,N)/N;
                                    N
                                   ====
                                   \
                                    >    x
                                   /      i
                                   ====
                                   i = 1
(%o1)                              --------
                                      N
(%i2) m2:m^2, sumexpand;
                              N      N
                             ====   ====
                             \      \
                              >      >     x   x
                             /      /       i1  i2
                             ====   ====
                             i1 = 1 i2 = 1
(%o2)                        ---------------------
                                       2
                                      N
(%i3) declare (nounify(sum), linear);
(%o3)                                done
(%i4) ''%o2;
                              N           N
                             ====        ====
                             \           \
                            ( >     x  )  >     x
                             /       i1  /       i2
                             ====        ====
                             i1 = 1      i2 = 1
(%o4)                       -----------------------
                                       2
                                      N
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48