ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 25 Jul 2014 15:06:40 +0200when sagecell run show(),the result only above tophttps://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/
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 Thu, 24 Jul 2014 13:36:25 +0200https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/Answer by slelievre for <pre><code>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())
</code></pre>
<p>show(q[3].simplify_full()) is the last command,but the result appear the toppest </p>
https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?answer=23569#post-id-23569I 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())
Thu, 24 Jul 2014 16:06:12 +0200https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?answer=23569#post-id-23569Comment by cjsh for <p>I disagree: the output consists, in this order, of the simplified q[0], ..., q[3], followed by the 5-tuple (q, (), (), (), ()).</p>
<p>Here is what happens when you run the command in your question.</p>
<p>Your command consists in 3 instructions.</p>
<ul>
<li><p>The first instruction defines variables k, a, b, c, d.</p></li>
<li><p>The second instruction defines q.</p></li>
<li><p>The third and last instruction is a 5-tuple, let us analyse this 5-tuple.</p>
<ul>
<li><p>The first element in the tuple is q</p></li>
<li><p>The 2nd to 5th elements in the tuple are 'show(...)'.</p></li>
</ul></li>
</ul>
<p>A command such as 'show(...)' has a side-effect (show the object) and a return value, which is <code>()</code>.
(In this case, of course, the "side-effect" is what you are most interested in.)</p>
<p>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).</p>
<pre><code>([x == ..., x == ..., x = ..., x = ...],
None,
None,
None,
None)
</code></pre>
<p>For the output you were aiming to get, I would suggest the following input in the Sage Cell Server.</p>
<pre><code>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())
</code></pre>
https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?comment=23577#post-id-23577you are master!
I donnot know programming languages,but I read side-effect from WIKI,almost know meanings.
thank you very much!Fri, 25 Jul 2014 12:30:27 +0200https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?comment=23577#post-id-23577Comment by slelievre for <p>I disagree: the output consists, in this order, of the simplified q[0], ..., q[3], followed by the 5-tuple (q, (), (), (), ()).</p>
<p>Here is what happens when you run the command in your question.</p>
<p>Your command consists in 3 instructions.</p>
<ul>
<li><p>The first instruction defines variables k, a, b, c, d.</p></li>
<li><p>The second instruction defines q.</p></li>
<li><p>The third and last instruction is a 5-tuple, let us analyse this 5-tuple.</p>
<ul>
<li><p>The first element in the tuple is q</p></li>
<li><p>The 2nd to 5th elements in the tuple are 'show(...)'.</p></li>
</ul></li>
</ul>
<p>A command such as 'show(...)' has a side-effect (show the object) and a return value, which is <code>()</code>.
(In this case, of course, the "side-effect" is what you are most interested in.)</p>
<p>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).</p>
<pre><code>([x == ..., x == ..., x = ..., x = ...],
None,
None,
None,
None)
</code></pre>
<p>For the output you were aiming to get, I would suggest the following input in the Sage Cell Server.</p>
<pre><code>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())
</code></pre>
https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?comment=23582#post-id-23582@cjsh: Thank you! Side-note: for thank-you notes, use comments to the answers, rather than new answers.Fri, 25 Jul 2014 15:06:40 +0200https://ask.sagemath.org/question/23562/when-sagecell-run-showthe-result-only-above-top/?comment=23582#post-id-23582