# Why am I getting a wrong answer for this sum?

I'm trying to simplify a sum with some minima in it. I started with this.

sum(i, i, 0, min(k-1, la+lb))

1/2k^2 - 1/2k

Doesn't look good. What am I doing wrong?

edit retag close merge delete

probably you want to use min_symbolic: the top-level min function that you are calling refers to Python's built-in min (which is ok for numeric values).

Sort by » oldest newest most voted

(extended comment)

probably you want to use min_symbolic: the top-level min function that you are calling refers to Python's built-in min (which is ok for numeric values).

in this case i get:

sage: var('i, k, la, lb')
(i, k, la, lb)
sage: sum(i, i, 0, min_symbolic(k-1, la+lb))
1/2*min(k - 1, la + lb)^2 + 1/2*min(k - 1, la + lb)


(of course you could have just substituted in $n(n+1)/2$ for $n=\text{min_symbolic}(k-1, la+lb)$).

PS: it's in the reference manual as Symbolic Maximum and Minimum, and there is some work on updating that section in ticket #11258.

more