On Wed, Mar 24, 2010 at 11:09 AM, Ondrej Certik <ond...@certik.cz> wrote: > On Wed, Mar 24, 2010 at 11:01 AM, Freddie Witherden > <fred...@witherden.org> wrote: >> Hi all, >> >> After a discussion on IRC I am interested if there is any way to evaluate >> sums of the form: >> >>>>> B = [ Symbols, expressions, ... ] >>>>> Sum(n*B[n]*Sqrt(B[n]), (n, 0, len(b)-1)) >> >> I ask because the project I am currently working on is based heavily around >> sums of this form: >> sum(sum(sum(sum(B[i]*A[i,j]*A[j,k]*A[k,l]*C[l],l,1,s),k,1,s),j,1,s),i,1,s) = >> 1/120 >> >> where s, A[i,j] (matrix) and C[i] (vector) are evaluate to Real numbers with >> just B[i] being Symbols (so the result of the above expression is an >> equation of the form x1*B[1] + x2*B[2] + ... + xn*B[n] with xn being Reals >> (of course in Python the indices would be slightly different). >> >> Can anyone think of a clean way to evaluate these sorts of sums? (Extra >> points if you know where such sums arise in practise ;) >> >> Currently my workflow is: >> 1) Use Python to generate the sums; >> 2) Evaluate using Maxima; >> 3) Paste back into a Python script, parse with regex, solve. > > Can you paste your whole code so that we can try it? So your problem > is that some (complicated?) sums can't be evaluated in sympy, but it > works in maxima? > > Paste the exact expressions, let's see what can be done.
Ok, after chatting at IRC a bit, here are the examples of expressions in maxima, that you need to work in sympy: sum(sum(sum(sum(B[i1]*A[i1,i2]*A[i2,i3]*A[i3,i4]*C[i4]^1, i4, 1, i3), i3, 1, i2), i2, 1, i1), i1, 1, s) - 1/120 sum(sum(sum(B[i1]*A[i1,i2]*A[i2,i3]*C[i3]^2, i3, 1, i2), i2, 1, i1), i1, 1, s) - 1/60 sum(sum(sum(B[i1]*A[i1,i2]*C[i2]^1*A[i2,i3]*C[i3]^1, i3, 1, i2), i2, 1, i1), i1, 1, s) - 1/40 sum(sum(sum(B[i1]*C[i1]^1*A[i1,i2]*A[i2,i3]*C[i3]^1, i3, 1, i2), i2, 1, i1), i1, 1, s) - 1/30 sum(sum(B[i1]*A[i1,i2]*C[i2]^3, i2, 1, i1), i1, 1, s) - 1/20 sum(sum(B[i1]*C[i1]^1*A[i1,i2]*C[i2]^2, i2, 1, i1), i1, 1, s) - 1/15 sum(sum(sum(B[i1]*A[i1,i2]*C[i2]^1*A[i1,i3]*C[i3]^1, i3, 1, i1), i2, 1, i1), i1, 1, s) - 1/20 sum(sum(B[i1]*C[i1]^2*A[i1,i2]*C[i2]^1, i2, 1, i1), i1, 1, s) - 1/10 sum(B[i1]*C[i1]^4, i1, 1, s) - 1/5 e.g.: (%i1) s : 17; (%o1) 17 (%i2) sum(B[i1]*C[i1]^4, i1, 1, s) - 1/5; 4 4 4 4 4 4 4 (%o2) B C + B C + B C + B C + B C + B C + B C 17 17 16 16 15 15 14 14 13 13 12 12 11 11 4 4 4 4 4 4 4 4 4 + B C + B C + B C + B C + B C + B C + B C + B C + B C 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 4 1 + B C - - 1 1 5 Yes, this should be possible. Ondrej -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.