Ask Your Question
0

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

asked 2014-07-24 13:36:25 +0200

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
2

answered 2014-07-24 16:06:12 +0200

slelievre gravatar image

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 = ...],
 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())
edit flag offensive delete link more

Comments

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 12:30:27 +0200 )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 15:06:40 +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

Stats

Asked: 2014-07-24 13:36:25 +0200

Seen: 287 times

Last updated: Jul 25 '14