Ask Your Question
2

No output when documentation say it should be

asked 6 years ago

danielvolinski gravatar image

updated 6 years ago

tmonteil gravatar image

Hi all,

Consider http://doc.sagemath.org/html/en/refer... 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.

Daniel

Preview: (hide)

Comments

1

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 ( 6 years ago )

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 ...
(more)
danielvolinski gravatar imagedanielvolinski ( 6 years ago )

Cont.

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 ( 6 years ago )

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 ( 6 years ago )

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
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 Notebook

Iguananaut gravatar imageIguananaut ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 6 years ago

Iguananaut gravatar image

updated 6 years ago

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.

Preview: (hide)
link

Comments

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 ( 6 years ago )
1

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 ( 6 years ago )

Thanks, I understand.

danielvolinski gravatar imagedanielvolinski ( 6 years ago )

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

Stats

Asked: 6 years ago

Seen: 742 times

Last updated: Feb 08 '19