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.Thu, 31 Dec 2020 10:20:53 +0100Difference of comportment between notebook and Sagecellhttps://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/ This command has not the same result in `Sage Cells` and in a notebook of sagemath 9.2. The first is the good one.
@interact(layout={'top': [['ABCD','ABDC','ACBD','ADBC','EFGH'],['BACD','BADC','BCAD','BCDA','GEFH']]})
def _(ABCD=0, ABDC=0, ACBD=0,ADBC=0,BACD=0,BADC=0,BCAD=0,BCDA=0,EFGH=0,GEFH=0):
print(ABCD+ABDC+ACBD+ACBD)
A connex question
@interact(layout={'top': [['ABCD','ABDC','ACBD','ADBC','EFGH'],['BACD','BADC','BCAD','BCDA','GEFH']]})
def _(ABCD=0, ABDC=0, ACBD=0,ADBC=0,BACD=0,BADC=0,BCAD=0,BCDA=0,EFGH=0,GEFH=0):
A = list([ABCD,ACBD,ADBC,EFGH,BACD,BADC,BCAD,BCDA,GEFH])
return A
add(_())
evaluate to 0 without waiting for input. Why ? and how to obtain the good behaviour ?Tue, 29 Dec 2020 23:03:45 +0100https://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/Answer by Emmanuel Charpentier for <p>This command has not the same result in <code>Sage Cells</code> and in a notebook of sagemath 9.2. The first is the good one.</p>
<pre><code>@interact(layout={'top': [['ABCD','ABDC','ACBD','ADBC','EFGH'],['BACD','BADC','BCAD','BCDA','GEFH']]})
def _(ABCD=0, ABDC=0, ACBD=0,ADBC=0,BACD=0,BADC=0,BCAD=0,BCDA=0,EFGH=0,GEFH=0):
print(ABCD+ABDC+ACBD+ACBD)
</code></pre>
<p>A connex question</p>
<pre><code>@interact(layout={'top': [['ABCD','ABDC','ACBD','ADBC','EFGH'],['BACD','BADC','BCAD','BCDA','GEFH']]})
def _(ABCD=0, ABDC=0, ACBD=0,ADBC=0,BACD=0,BADC=0,BCAD=0,BCDA=0,EFGH=0,GEFH=0):
A = list([ABCD,ACBD,ADBC,EFGH,BACD,BADC,BCAD,BCDA,GEFH])
return A
add(_())
</code></pre>
<p>evaluate to 0 without waiting for input. Why ? and how to obtain the good behaviour ?</p>
https://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/?answer=55014#post-id-55014`Sage`'s [`interacts`](https://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/interact.html) are a `Sage`-specific-customization of `ipywidgets.interact`. Their behavior is, as far as I know, documented only for the Jupyter notebook.
Ran in a 9.3.beta5 notebook, your code gives the expected result. Ran in sagecell, the presentation is cosmetically duifferent (you get number cells instead of sliders), but the result is the same (i. e. ABCD+ABDC+2*ACBD).
What did you expect exactly ?
Second question : an interact does not wait for input : it paints and activates controls, comutes the result as a functin of the (default) values of these inputs and returns it. Whenever one of the inputs changes as a result of an end-user action, the resulting value is recomputed and returned. Mos common case : the return value is a graphic, which is redisplayed.
All of this is [documented](https://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/interact.html) and [tutorialized](https://doc.sagemath.org/html/en/prep/Quickstarts/Interact.html).
sage: r.library("fortunes")
sage: r.fortune("'WTFM'")
This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
-- Barry Rowlingson
R-help (October 2003)
Wed, 30 Dec 2020 20:53:51 +0100https://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/?answer=55014#post-id-55014Comment by Cyrille for <p><code>Sage</code>'s <a href="https://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/interact.html"><code>interacts</code></a> are a <code>Sage</code>-specific-customization of <code>ipywidgets.interact</code>. Their behavior is, as far as I know, documented only for the Jupyter notebook.</p>
<p>Ran in a 9.3.beta5 notebook, your code gives the expected result. Ran in sagecell, the presentation is cosmetically duifferent (you get number cells instead of sliders), but the result is the same (i. e. ABCD+ABDC+2*ACBD).</p>
<p>What did you expect exactly ?</p>
<p>Second question : an interact does not wait for input : it paints and activates controls, comutes the result as a functin of the (default) values of these inputs and returns it. Whenever one of the inputs changes as a result of an end-user action, the resulting value is recomputed and returned. Mos common case : the return value is a graphic, which is redisplayed.</p>
<p>All of this is <a href="https://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/interact.html">documented</a> and <a href="https://doc.sagemath.org/html/en/prep/Quickstarts/Interact.html">tutorialized</a>.</p>
<pre><code>sage: r.library("fortunes")
sage: r.fortune("'WTFM'")
This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
-- Barry Rowlingson
R-help (October 2003)
</code></pre>
https://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/?comment=55020#post-id-55020What I expect is the sagecell presentation. The idea is to help student to enter information.Thu, 31 Dec 2020 10:20:53 +0100https://ask.sagemath.org/question/54998/difference-of-comportment-between-notebook-and-sagecell/?comment=55020#post-id-55020