Post Reply 
XCas sum limit confusion
08-26-2020, 07:48 PM
Post: #1
XCas sum limit confusion
Quote:Discrete sum (with 2 or 4 arguments return then sum from a to b if a<=b
or of the opposite of the sum from b+1 to a-1 if a>b+1 or 0 if a=b+1)
or the discrete primitive or sum of the elements of a list or a sequence.

sum(Expr,Var,VarMin(a),VarMax(b),[VarStep(p)])
Above quote is from XCas help screen for sum()

Why the convoluted swapping of limit with aboved logic ?
And, why swapped limit changed to b+1 to a-1, and not b to a ?

Some confusing examples:

XCas> sum(k, k, 1, 5)       // = 1+2+3+4+5 = 15
XCas> sum(k, k, 5, 1)       // = -sum(k, k, 2, 4) = -(2+3+4) = -9. OK, but don't know why

XCas> sum(k, k, 5, 1, 1)   // got 15 ? somehow, step flipped to -1, instead of swapping limits.

XCas> sum(k, k, 5.1, 1)    // got -14.0 ? expected -sum(k, k, 2, 4.1) = -(2+3+4) = -9

Missing step is not equivalent to default step=1

XCas> factor(sum(k, k, a, b))   // (b+a)*(b-a+1)/2
XCas> sum(k, k, a, b, 1)          // "Unable to sort boundaries a,b Error: Bad Argument Value"
Find all posts by this user
Quote this message in a reply
08-26-2020, 09:58 PM (This post was last modified: 11-23-2020 07:24 PM by Albert Chan.)
Post: #2
RE: XCas sum limit confusion
This may explain the reason for (a,b) → (b+1,a-1), if a>b+1
Say, we have a function F(x) = sum(f(t), t=-inf .. x-1)

If a ≤ b, S1 = sum(f(t), t=a .. b) = F(b+1) - F(a)

If a > b, we could flip the limit, just like doing integrals.

S2 = - sum(f(t), t=b .. a) = -(F(a+1) - F(b)) = F(b) - F(a+1)

But, S1 != -S2. To aim for symmetry, we shift the limit a bit:

S2 = - sum(f(t), t=b+1 .. a-1) = F(a) - F(b+1) = -S1

Sympy Gamma:  Sum(k, (k, 5, 1)) = -(2 + 3 + 4) = -9
But, the cure maybe worse than the disease.

Mathematica also does closed end limit, but generated a list. (conceptually)
If the list is empty, there is nothing to sum.
We lost the symmetry, but it is simple to understand.

Mathematica:     Sum(k, (k, 5, 1)) = 0

Open-ended sum is very elegant:

S1 = sum(f(t), t = a .. b-1) = F(b) - F(a)
S2 = sum(f(t), t = b .. a-1) = F(a) - F(b)

We got nice symmetry, without worrying a, b sort order.

Also of interest: Should array indices start at 0 or 1 ?
Find all posts by this user
Quote this message in a reply
09-02-2023, 12:54 PM
Post: #3
RE: XCas sum limit confusion
For the same reason, product limits behave exactly the same as sum.

Cas> Pochhammer(a,n) := product((a+j), j, 0, n-1)
Cas> Pochhammer(a, 0)      → 1
Cas> Pochhammer(0, 0)      → 1

When limits get switched, "opposite" for sum negated equivalent to product reciprocal.

Pochhammer(a, -|n|) = product((a+j), j, 0, -|n|-1) = 1/product((a+j), j, -|n|, -1)

Cas> Pochhammer(a, 3)      → a*(a+1)*(a+2)
Cas> Pochhammer(a, -3)     → 1/((a-1)*(a-2)*(a-3))
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)