XCas sum limit confusion - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: XCas sum limit confusion ( /thread-15503.html) |

XCas sum limit confusion - Albert Chan - 08-26-2020 07:48 PM
Quote:Discrete sum (with 2 or 4 arguments return then sum from a to b if a<=bAbove 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" RE: XCas sum limit confusion - Albert Chan - 08-26-2020 09:58 PM
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 ? |