Ask Your Question

No output when documentation say it should be

asked 2019-02-08 20:36:30 +0200

danielvolinski gravatar image

updated 2019-02-09 11:12:52 +0200

tmonteil gravatar image

Hi all,

Consider 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.


edit retag flag offensive close merge delete



It 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 ?
  • ... ?
tmonteil gravatar imagetmonteil ( 2019-02-09 00:27:30 +0200 )edit

Sage 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 ...
danielvolinski gravatar imagedanielvolinski ( 2019-02-09 08:37:47 +0200 )edit


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 output

danielvolinski gravatar imagedanielvolinski ( 2019-02-09 08:40:47 +0200 )edit

OK I, do not have winows with me, let me just add the windows tag so that inerested people can focus on that.

tmonteil gravatar imagetmonteil ( 2019-02-09 11:13:27 +0200 )edit

I 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
sage: _ == True
sage: 2 + 2
sage: _ == 4
sage: _  # the previous line was an expression so _ has been updated again
sage: _ is 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 Notebook

Iguananaut gravatar imageIguananaut ( 2019-02-09 12:05:13 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-09 11:47:33 +0200

Iguananaut gravatar image

updated 2019-02-09 12:08:08 +0200

Just 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.

edit flag offensive delete link more


Here 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.

Iguananaut gravatar imageIguananaut ( 2019-02-09 11:57:51 +0200 )edit

I 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.

eric_g gravatar imageeric_g ( 2019-02-09 14:11:20 +0200 )edit

Thanks, I understand.

danielvolinski gravatar imagedanielvolinski ( 2019-02-27 18:08:30 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-02-08 20:36:30 +0200

Seen: 483 times

Last updated: Feb 08 '19