# when sagecell run show(),the result only above top 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.simplify_full()),show(q.simplify_full()),show(q.simplify_full()),show(q.simplify_full())


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

edit retag close merge delete

Sort by » oldest newest most voted

I disagree: the output consists, in this order, of the simplified q, ..., q, 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 to q. Finally, when the tuple is constructed, it is displayed. Since, by this time, the side-effects of the 'show(...)' commands have already caused q to q 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 = ...],
None,
None,
None,
None)


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)
print(q)
for s in q: show(s.simplify_full())

more

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