ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 27 Feb 2019 11:08:30 -0600No output when documentation say it should behttp://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/Hi all,
Consider http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html
The very last command of this web page is
sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the `torsion_form` definition, over all 3 cells.
DanielFri, 08 Feb 2019 13:36:30 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/Comment by Iguananaut for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45398#post-id-45398I think the Sage doctest runner does use some tricks to output the value of the last statement in loops. I'm not exactly sure how that works. I think it might be this: every time you run a line of code in Python that is an expression, its value gets stored in a special variable `_`. So like:
sage: 1 == 1
True
sage: _ == True
True
sage: 2 + 2
4
sage: _ == 4
True
sage: _ # the previous line was an expression so _ has been updated again
True
sage: _ is True
True
I think the doctest runner and/or the Sage command shell might do a trick with capturing the value of `_` and displaying it, but I'm not exactly sure how that works. But it leads to slightly deceptive doc examples like this since this is *not* normal behavior in Python or the NotebookSat, 09 Feb 2019 05:05:13 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45398#post-id-45398Comment by tmonteil for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45395#post-id-45395OK I, do not have winows with me, let me just add the windows tag so that inerested people can focus on that.Sat, 09 Feb 2019 04:13:27 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45395#post-id-45395Comment by danielvolinski for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45393#post-id-45393Cont.
sage: nab.torsion_form(1)[:]
sage: ch_basis = M.automorphism_field()
sage: ch_basis[1,1], ch_basis[2,2], ch_basis[3,3] = y, z, x
sage: e = M.default_frame().new_frame(ch_basis, 'e')
sage: e[1][:], e[2][:], e[3][:]
sage: ef = e.coframe()
sage: ef[1][:], ef[2][:], ef[3][:]
sage: nab.torsion_form(1, e)
sage: nab.torsion_form(1, e).comp(e)[:]
sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
No outputSat, 09 Feb 2019 01:40:47 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45393#post-id-45393Comment by danielvolinski for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45392#post-id-45392Sage version is 8.4, Windows Native on a 64bit machine, installed from SageMath-8.4-Installer-v0.4.1.exe
I did not compile Sage by myself.
I use Jupyter Notebook.
I don't use the command line.
I did not get any errors. I just got no output at all
sage: M = Manifold(3, 'M', start_index=1)
sage: c_xyz.<x,y,z> = M.chart()
sage: nab = M.affine_connection('nabla', r'\nabla')
sage: nab[1,1,1], nab[1,1,2], nab[1,1,3] = x*y*z, x^2, -y*z
sage: nab[1,2,3], nab[1,3,1], nab[1,3,2] = -x^3, y^2*z, y^2-x^2
sage: nab[2,1,1], nab[2,1,2], nab[2,2,1] = z^2, x*y*z^2, -x^2
sage: nab[2,3,1], nab[2,3,3], nab[3,1,2] = x^2+y^2+z^2, y^2-z^2, x*y+z^2
sage: nab[3,2,1], nab[3,2,2], nab[3,3,3] = x*y+z, z^3 -y^2, x*z^2 - z*y^2
sage: nab.torsion_form(1)Sat, 09 Feb 2019 01:37:47 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45392#post-id-45392Comment by tmonteil for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45379#post-id-45379It works for me (Sage 8.7.beta3, complied on Debian jessie 64bit, run from the command line).
Could you please give us some informations so that someone can try to reproduce your problem:
- which version of Sage did you use ?
- which OS ?
- did you install Sage from the binaries, and which ones ?
- did you compile Sage yourself ?
- which notebook did you use (Sage notebook or jupyter notebook) ?
- did you use the command line ?
- which commands did you type precisely to get the error ?
- which error message did you get ?
- ... ?Fri, 08 Feb 2019 17:27:30 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45379#post-id-45379Answer by Iguananaut for <p>Hi all,</p>
<p>Consider <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/differentiable/affine_connection.html">http://doc.sagemath.org/html/en/refer...</a>
The very last command of this web page is</p>
<pre><code>sage: for i in M.irange():
nab.torsion_form(i, e) == ef[i].exterior_derivative() + \
sum(nab.connection_form(i,j,e).wedge(ef[j]) for j in M.irange())
</code></pre>
<p>The output of this command should be: True, True, True, but I get no output at all.
In order to duplicate you should include also the previous commands beginning from the <code>torsion_form</code> definition, over all 3 cells.</p>
<p>Daniel</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?answer=45396#post-id-45396Just use `print()` around the last line in the loop, or append the results to a list and show that. I don't think the Notebook works in such a way w.r.t. in output from loops, since technically the `for` loop has no output. It's just expressions that have a single value that are output normally.Sat, 09 Feb 2019 04:47:33 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?answer=45396#post-id-45396Comment by danielvolinski for <p>Just use <code>print()</code> around the last line in the loop, or append the results to a list and show that. I don't think the Notebook works in such a way w.r.t. in output from loops, since technically the <code>for</code> loop has no output. It's just expressions that have a single value that are output normally.</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45560#post-id-45560Thanks, I understand.Wed, 27 Feb 2019 11:08:30 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45560#post-id-45560Comment by eric_g for <p>Just use <code>print()</code> around the last line in the loop, or append the results to a list and show that. I don't think the Notebook works in such a way w.r.t. in output from loops, since technically the <code>for</code> loop has no output. It's just expressions that have a single value that are output normally.</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45400#post-id-45400I fully agree: the doctest should be written with a `print()` in the loop, or even better (more pythonic), using `all()` instead of a `for` loop.Sat, 09 Feb 2019 07:11:20 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45400#post-id-45400Comment by Iguananaut for <p>Just use <code>print()</code> around the last line in the loop, or append the results to a list and show that. I don't think the Notebook works in such a way w.r.t. in output from loops, since technically the <code>for</code> loop has no output. It's just expressions that have a single value that are output normally.</p>
http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45397#post-id-45397Here are some exercises you can try to better understand this. An example of an expression would be something like `1 == 2`. Try entering just `1 == 2` into a cell and running it. The expression has a value (`False`) so that is shown as the output. Now try running something like
for _ in range(3):
1 == 1
1 == 2
What is the value of *this* expression? Trick question: it's not an expression, it's a "statement" consisting of multiple expressions and possibly other statements. It doesn't have a value. So nothing is displayed when you run it. The `==` expressions get evaluated but the results just go up in smoke. To use them they'd have to be stored in variables or at the very least `print()`ed to see them.Sat, 09 Feb 2019 04:57:51 -0600http://ask.sagemath.org/question/45375/no-output-when-documentation-say-it-should-be/?comment=45397#post-id-45397