Ask Your Question

when sagecell run show(),the result only above top

asked 2014-07-24 06:36:25 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

var('k a b c d');q=solve(k*x^4+a*x^3+b*x^2+c*x+d==0,x);q,show(q[0].simplify_full()),show(q[1].simplify_full()),show(q[2].simplify_full()),show(q[3].simplify_full())

show(q[3].simplify_full()) is the last command,but the result appear the toppest

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-07-24 09:06:12 -0500

I disagree: the output consists, in this order, of the simplified q[0], ..., q[3], followed by the 5-tuple (q, (), (), (), ()).

Here is what happens when you run the command in your question.

Your command consists in 3 instructions.

  • The first instruction defines variables k, a, b, c, d.

  • The second instruction defines q.

  • The third and last instruction is a 5-tuple, let us analyse this 5-tuple.

    • The first element in the tuple is q

    • The 2nd to 5th elements in the tuple are 'show(...)'.

A command such as 'show(...)' has a side-effect (show the object) and a return value, which is (). (In this case, of course, the "side-effect" is what you are most interested in.)

So while constructing the 5-tuple, the last 4 elements of the 5-tuple produce side-effects, and this is why in the output you first see the 4 displayed equations q[0] to q[3]. Finally, when the tuple is constructed, it is displayed. Since, by this time, the side-effects of the 'show(...)' commands have already caused q[0] to q[3] to be displayed, the tuple itself is printed last. You can observe that this is a tuple consisting of the list q as its first entry, followed by 4 times '()' (the results of the 'show(...)' commands).

([x == ..., x == ..., x = ..., x = ...],

For the output you were aiming to get, I would suggest the following input in the Sage Cell Server.

var('k a b c d')
q = solve(k*x^4+a*x^3+b*x^2+c*x+d==0,x)
for s in q: show(s.simplify_full())
edit flag offensive delete link more


you are master! I donnot know programming languages,but I read side-effect from WIKI,almost know meanings. thank you very much!

cjsh gravatar imagecjsh ( 2014-07-25 05:30:27 -0500 )edit

@cjsh: Thank you! Side-note: for thank-you notes, use comments to the answers, rather than new answers.

slelievre gravatar imageslelievre ( 2014-07-25 08:06:40 -0500 )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: 2014-07-24 06:36:25 -0500

Seen: 86 times

Last updated: Jul 25 '14