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.Sat, 01 Feb 2020 00:39:40 +0100Simple question on displaying summationhttps://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/Hi,
I'm defining a few summation functions for displaying and evaluating later, but I don't understand how to do it.
So, I'm looking at the basic Sage Quick Reference and I see under Arithmetic:
sum(f(i) for i in (k..n))
But when I try to make it symbolic to show, like something simple like this:
var('i,n')
f(n)=sum(i for i in (0..n))
show(f)
But then I get
TypeError: unable to simplify to float approximation
Which makes me think its trying to evaluate the sum rather than make it a symbolic expression. Then I ran across "symbolic_sum" somewhere, but I can't find any documentation about it now...
Any suggestions?
Erik
Fri, 31 Jan 2020 02:01:14 +0100https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/Answer by dazedANDconfused for <p>Hi,</p>
<p>I'm defining a few summation functions for displaying and evaluating later, but I don't understand how to do it.</p>
<p>So, I'm looking at the basic Sage Quick Reference and I see under Arithmetic:
sum(f(i) for i in (k..n))</p>
<p>But when I try to make it symbolic to show, like something simple like this:</p>
<pre><code>var('i,n')
f(n)=sum(i for i in (0..n))
show(f)
</code></pre>
<p>But then I get</p>
<pre><code>TypeError: unable to simplify to float approximation
</code></pre>
<p>Which makes me think its trying to evaluate the sum rather than make it a symbolic expression. Then I ran across "symbolic_sum" somewhere, but I can't find any documentation about it now...</p>
<p>Any suggestions?</p>
<p>Erik</p>
https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?answer=49720#post-id-49720If you want a symbolic sum you have 2 choices that I know of. First, using `sum`:
k, n = var('k,n')
f=sum(k, k, 0, n)
f.show()
The output, running in a [SageCellServer](https://sagecell.sagemath.org/) is shown below:
![image description](/upfiles/15804380829459793.jpg)
You can find the documentation [here](http://doc.sagemath.org/html/en/reference/misc/sage/misc/functional.html?highlight=symbolic_sum).
If you use `symbolic_sum`, documented [here](http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html), then you could try:
from sage.calculus.calculus import symbolic_sum
var('i,n')
f=symbolic_sum(i, i, 0, n)
f.show()
The output is:
![image description](/upfiles/15804375002147521.jpg)Fri, 31 Jan 2020 03:25:28 +0100https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?answer=49720#post-id-49720Comment by erikblue for <p>If you want a symbolic sum you have 2 choices that I know of. First, using <code>sum</code>:</p>
<pre><code>k, n = var('k,n')
f=sum(k, k, 0, n)
f.show()
</code></pre>
<p>The output, running in a <a href="https://sagecell.sagemath.org/">SageCellServer</a> is shown below:</p>
<p><img alt="image description" src="/upfiles/15804380829459793.jpg"></p>
<p>You can find the documentation <a href="http://doc.sagemath.org/html/en/reference/misc/sage/misc/functional.html?highlight=symbolic_sum">here</a>.</p>
<p>If you use <code>symbolic_sum</code>, documented <a href="http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html">here</a>, then you could try:</p>
<pre><code>from sage.calculus.calculus import symbolic_sum
var('i,n')
f=symbolic_sum(i, i, 0, n)
f.show()
</code></pre>
<p>The output is:
<img alt="image description" src="/upfiles/15804375002147521.jpg"></p>
https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?comment=49733#post-id-49733Ok thanks for the answer. I guess if I want to display it in pretty summation notation I will need to use LaTeX. Glad I wasn't missing anything.Fri, 31 Jan 2020 18:36:36 +0100https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?comment=49733#post-id-49733Comment by dazedANDconfused for <p>If you want a symbolic sum you have 2 choices that I know of. First, using <code>sum</code>:</p>
<pre><code>k, n = var('k,n')
f=sum(k, k, 0, n)
f.show()
</code></pre>
<p>The output, running in a <a href="https://sagecell.sagemath.org/">SageCellServer</a> is shown below:</p>
<p><img alt="image description" src="/upfiles/15804380829459793.jpg"></p>
<p>You can find the documentation <a href="http://doc.sagemath.org/html/en/reference/misc/sage/misc/functional.html?highlight=symbolic_sum">here</a>.</p>
<p>If you use <code>symbolic_sum</code>, documented <a href="http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html">here</a>, then you could try:</p>
<pre><code>from sage.calculus.calculus import symbolic_sum
var('i,n')
f=symbolic_sum(i, i, 0, n)
f.show()
</code></pre>
<p>The output is:
<img alt="image description" src="/upfiles/15804375002147521.jpg"></p>
https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?comment=49738#post-id-49738I don't think that can be done using just Sage. When I combine LaTeX and Sage, I do it as a document using the `sagetex` package in LaTeX. The CTAN documentation is [here](https://ctan.org/pkg/sagetex).Sat, 01 Feb 2020 00:39:40 +0100https://ask.sagemath.org/question/49719/simple-question-on-displaying-summation/?comment=49738#post-id-49738