Ask Your Question
0

Difference of comportment between notebook and Sagecell

asked 2020-12-29 23:03:45 +0100

Cyrille gravatar image

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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-12-30 20:53:51 +0100

Emmanuel Charpentier gravatar image

Sage's interacts 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 and tutorialized.

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)
edit flag offensive delete link more

Comments

What I expect is the sagecell presentation. The idea is to help student to enter information.

Cyrille gravatar imageCyrille ( 2020-12-31 10:20:53 +0100 )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: 2020-12-29 23:03:45 +0100

Seen: 515 times

Last updated: Dec 30 '20