ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 14 Jul 2017 11:45:02 +0200Why am I getting a wrong answer for this sum?https://ask.sagemath.org/question/38230/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/2*k^2 - 1/2*k
Doesn't look good. What am I doing wrong?Thu, 13 Jul 2017 14:39:00 +0200https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/Comment by mforets for <p>I'm trying to simplify a sum with some minima in it. I started with this.</p>
<blockquote>
<p>sum(i, i, 0, min(k-1, la+lb))</p>
<p>1/2<em>k^2 - 1/2</em>k</p>
</blockquote>
<p>Doesn't look good. What am I doing wrong?</p>
https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?comment=38236#post-id-38236probably 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).Thu, 13 Jul 2017 17:46:07 +0200https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?comment=38236#post-id-38236Comment by simon for <p>I'm trying to simplify a sum with some minima in it. I started with this.</p>
<blockquote>
<p>sum(i, i, 0, min(k-1, la+lb))</p>
<p>1/2<em>k^2 - 1/2</em>k</p>
</blockquote>
<p>Doesn't look good. What am I doing wrong?</p>
https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?comment=38253#post-id-38253Want to add that as an answer?Fri, 14 Jul 2017 09:20:18 +0200https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?comment=38253#post-id-38253Answer by mforets for <p>I'm trying to simplify a sum with some minima in it. I started with this.</p>
<blockquote>
<p>sum(i, i, 0, min(k-1, la+lb))</p>
<p>1/2<em>k^2 - 1/2</em>k</p>
</blockquote>
<p>Doesn't look good. What am I doing wrong?</p>
https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?answer=38256#post-id-38256(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](http://doc.sagemath.org/html/en/reference/functions/sage/functions/min_max.html), and there is some work on updating that section in ticket [#11258](https://trac.sagemath.org/ticket/11258).Fri, 14 Jul 2017 11:45:02 +0200https://ask.sagemath.org/question/38230/why-am-i-getting-a-wrong-answer-for-this-sum/?answer=38256#post-id-38256