Ipython notebook and interaction with Maxima

122 views
Skip to first unread message

Emmanuel Charpentier

unread,
May 4, 2015, 10:17:10 AM5/4/15
to sage-s...@googlegroups.com
Dear list,

I noticed an annoyance in the IPython notebook (I mean Sage's Ipython notebook, not IPython ° %load_ext sage...). a line magic %maxima exists, but seems to open an interactiove contol woth Maxima, that one cannot exit of.

What I'd like to have is somthing close to the %%R cell magic offered by %rmagic (which, BTW, uses rpy2, which is not available directly) : the text of the cell is sent to R and the (last) answer is printed out.

I have created a first approximation of what I'd like to have in the attached IPython worksheet. Il scans a (multiline) text, splits it on semicolons, replaces all whitespace by a single space, sends it line by line to maxima and records the answers, which are in fine returned.

What do you think ?

HTH,
--
Emmanuel Charpentier
Interactions avec Maxima dans le notebook IPython.ipynb

Volker Braun

unread,
May 4, 2015, 10:35:53 AM5/4/15
to sage-s...@googlegroups.com
I also noticed that ctrl-d doesn't work (probably captured by the browser) so interactive subshells can't be left. This ought to be a general IPython notebook question, but I don't know the answer.

As you said, IPython distinguishes single percent = line, and double precent = cell magics. 

IMHO we should do as little processing on the cell magic as possible. Why muck around with whitespace, what if somebody wants to work with a Maxima string containing multiple consecutive spaces, etc. Same for semicolons. Just require valid Maxima input in a %%maxima cell.

Emmanuel Charpentier

unread,
May 4, 2015, 3:40:33 PM5/4/15
to sage-s...@googlegroups.com
Mucking around with whitespace is necessary with the current version of the maxima() function : something here doesn't like to receive empty lines. Furthermore, Maxima grammar, a bit Lisp-like (minus parentheses), doesn't differentiate betw een quantities of whitespace (in other words, it isn't Python :-). So it was simpler to condensate all this whitespace.Of course, the present version will have problems for example with strings containing semicolons...

Some comments below :


Le lundi 4 mai 2015 16:35:53 UTC+2, Volker Braun a écrit :
I also noticed that ctrl-d doesn't work (probably captured by the browser) so interactive subshells can't be left.

Confirmed:-(. Ditto for %r. But in this case, %%R works better (not perfectly : it only returns the *last* printed output only (but all graphs. Go figure...).
 
This ought to be a general IPython notebook question, but I don't know the answer.

Neither do I:-(.

As you said, IPython distinguishes single percent = line, and double precent = cell magics. 

IMHO we should do as little processing on the cell magic as possible. Why muck around with whitespace, what if somebody wants to work with a Maxima string containing multiple consecutive spaces, etc. Same for semicolons. Just require valid Maxima input in a %%maxima cell.

Meaning we need either a Maxima lexer/parser before calling maxima() or a better way yo treat Maxima answers to incorrect or incomplete response. Non-trivial in both cases.

I plan to muck around the command-line version to see how it behaves in this respect (but when ?). Maybe also the code fpr the (cell-)magic %r and %maxima of the Sage notebook, which do The Right Thin (TM)  (if I can make head or tail of the code...).

HTH,
--
Emmanuel Charpentier
Reply all
Reply to author
Forward
0 new messages