Comment #29 on issue 3128 by someb...@bluewin.ch: Sum and Product manipulations
http://code.google.com/p/sympy/issues/detail?id=3128

An explicit case is when a(k)=k-2, b(k)=2-k, n=4.

a(k) := k - 2
b(k) := 2 - k
n \in [0, 1, 2, 3, 4]

Lets make a table:

[(k-2, 2-k) for k in range(5)]
[(-2, 2), (-1, 1), (0, 0), (1, -1), (2, -2)]

Next, compute all the elments for each subset Sk(n):

[ Sum(1, (i, k-2, 2-k)).doit() for k in range(5)]
[5, 3, 1, -1, -3]

And compute the cummulative set M(n):

[ Sum(1, (i, k-2, 2-k), (k, 0, n)).doit() for n in range(5)]
[5, 8, 9, 8, 5]



In the following figure, the "*" denote elements being part of S(n)
and the "." are elements not part of S(n).

        -2   -1    0    1    2
N:    -- o -- o -- o -- o -- o --
n = 0 -- * -- * -- * -- * -- * --
n = 1 -- . -- * -- * -- * -- . --
n = 2 -- . -- . -- * -- . -- . --
n = 3 -- . -- x -- x -- x -- . --
n = 4 -- x -- x -- x -- x -- x --

The elements "x" would be selected if we assume the set notation:

[a(k), b(k)] == {a(k), a(k+1), ..., b(k-1), b(k)}  <=>  a(k) < b(k)
[a(k), b(k)] == {a(k)}                             <=>  a(k) = b(k)
[b(k), a(k)] == [a(k), b(k)]                            otherwise

and we have the "full set" independent of the relative order of a(k) and b(k).

In that case the partial sums Sk(n) would read:

[5, 3, 1, 3, 5]

and the cummulative sums M(n):

[5, 8, 9, 12, 17]

To get this, we have to assume that Sum(f(i), (i, a, b)) == Sum(f(i), (i, b, a)).
This is not what Karr defines and hence his results are not really "wrong".



In case we take another set notation, namely:

[a(k), b(k)] == {a(k), a(k+1), ..., b(k-1), b(k)}  <=>  a(k) < b(k)
[a(k), b(k)] == {a(k)}                             <=>  a(k) = b(k)
[a(k), b(k)] == {}                                 <=>  a(k) > b(k)

then all is perfectly fine. Again we start with the table:

        -2   -1    0    1    2
N:    -- o -- o -- o -- o -- o --
n = 0 -- * -- * -- * -- * -- * --
n = 1 -- . -- * -- * -- * -- . --
n = 2 -- . -- . -- * -- . -- . --
n = 3 -- . -- x -- x -- x -- . --
n = 4 -- x -- x -- x -- x -- x --

the first 3 rows are all ok, we can count the number of element of Sk(n)
(number of * on each line) by this sum:

Sk = Sum(1, (i, k-2, 2-k)).doit()
Sk
-2*k + 5

Sk.subs(k,0)
5
Sk.subs(k,1)
3
Sk.subs(k,2)
1

However, for the next two rows we arrive at these intermediate sums.
We could either trust sympy and compute their values:

Sum(1, (i, 1, -1)).doit()
-1
Sum(1, (i, 2, -2)).doit()
-3

It is obvious that this (even in absolute value) does NOT count the
number of "x" on the fourth and fifth row.

If we do not trust sympy then according to Karrs definition we can
to swap limits and obtain:

S3 = Sum(1, (i, 1, -1))
reverse_order(S3, i)
Sum(-1, (i, 0, 0))
_.doit()
-1

S4 = Sum(1, (i, 2, -2))
reverse_order(S4, i)
Sum(-1, (i, -1, 1))
_.doit()
-3

By this swap we implicitely modify the table:

        -2   -1    0    1    2
N:    -- o -- o -- o -- o -- o --
n = 0 -- * -- * -- * -- * -- * --
n = 1 -- . -- * -- * -- * -- . --
n = 2 -- . -- . -- * -- . -- . --
n = 3 -- . -- . -- + -- . -- . --
n = 4 -- . -- + -- + -- + -- . --

and now count correctly the number of "+" signs. This explains why the
original sequence Sk as well as M is correct.



If we extend the table by one row we find:

        -2   -1    0    1    2
N:    -- o -- o -- o -- o -- o --
n = 0 -- * -- * -- * -- * -- * --
n = 1 -- . -- * -- * -- * -- . --
n = 2 -- . -- . -- * -- . -- . --
n = 3 -- . -- . -- + -- . -- . --
n = 4 -- . -- + -- + -- + -- . --
n = 5 -- + -- + -- + -- + -- + --

And finally that M(n) is [5, 8, 9, 8, 5, 0] for n = [0, 1, 2, 3, 4, 5].

Compare this also to the continuous case:

Sk = integrate(1, (x, k-2, 2-k))
Sk
-2*k + 4
M = integrate(Sk, (k, 0, 4))
M
0

Clearly, the two "triangles" cancel out.

Sk = Sum(1, (x, k-2, 2-k))
M = Sum(Sk, (k, 0, 5)).doit()
M
0



It all depends on what we onderstand by subsets of integers specified by their
"boundary" elements only.


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy-issues+unsubscr...@googlegroups.com.
To post to this group, send email to sympy-issues@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to