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.Mon, 26 Nov 2012 16:48:26 +0100Double sumhttps://ask.sagemath.org/question/9566/double-sum/Hello,
I would like SAGE to compute a double sum like $\sum\limits_{1\le a\le n}\sum\limits_{1\le b\le n} \max(a,b)$. The result is strange :
f(n)=sum(sum(max(a,b),b,1,n),a,1,n)
SAGE tells me that f(2) is 6.
But it is rather 7 (unless i am very tired).
Thank you for your advices :-)
PierreMon, 26 Nov 2012 15:41:27 +0100https://ask.sagemath.org/question/9566/double-sum/Answer by kcrisman for <p>Hello,</p>
<p>I would like SAGE to compute a double sum like $\sum\limits_{1\le a\le n}\sum\limits_{1\le b\le n} \max(a,b)$. The result is strange :</p>
<pre><code>f(n)=sum(sum(max(a,b),b,1,n),a,1,n)
</code></pre>
<p>SAGE tells me that f(2) is 6.
But it is rather 7 (unless i am very tired).</p>
<p>Thank you for your advices :-)</p>
<p>Pierre</p>
https://ask.sagemath.org/question/9566/double-sum/?answer=14300#post-id-14300In this case you may want to try `max_symbolic`. Try `max(a,b)` by itself and see what you get - maybe `a`?Mon, 26 Nov 2012 16:29:34 +0100https://ask.sagemath.org/question/9566/double-sum/?answer=14300#post-id-14300Answer by PB for <p>Hello,</p>
<p>I would like SAGE to compute a double sum like $\sum\limits_{1\le a\le n}\sum\limits_{1\le b\le n} \max(a,b)$. The result is strange :</p>
<pre><code>f(n)=sum(sum(max(a,b),b,1,n),a,1,n)
</code></pre>
<p>SAGE tells me that f(2) is 6.
But it is rather 7 (unless i am very tired).</p>
<p>Thank you for your advices :-)</p>
<p>Pierre</p>
https://ask.sagemath.org/question/9566/double-sum/?answer=14301#post-id-14301Thank you. You are right : max(a,b) gives me a. I used max_symbolic instead, I get no error, but SAGE can't simplify the double sum.Mon, 26 Nov 2012 16:48:26 +0100https://ask.sagemath.org/question/9566/double-sum/?answer=14301#post-id-14301