sage magics reference

216 views
Skip to first unread message

ph h

unread,
Feb 21, 2022, 12:12:09 AM2/21/22
to sage-devel
Hi,


%auto
f(x)=x^3+1
@interact
def _(c=(1/3,(-1,1))):
    P=plot(f,(x,-1,1))
    fprime=derivative(f,x)
    L(x)=fprime(c)*(x-c)+f(c)
    Q=plot(L,(x,-1,1),color="red", linestyle="--")
    show(P+Q+point((c,f(c)), pointsize=40, color='red'),ymin=0,ymax=2)

There was an error:

UsageError: Line magic function `%auto` not found.

`lsmagic` gives this:

𝙰𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎 𝚕𝚒𝚗𝚎 𝚖𝚊𝚐𝚒𝚌𝚜:
%𝚊𝚕𝚒𝚊𝚜  %𝚊𝚕𝚒𝚊𝚜⎯𝚖𝚊𝚐𝚒𝚌  %𝚊𝚝𝚝𝚊𝚌𝚑  %𝚊𝚞𝚝𝚘𝚊𝚠𝚊𝚒𝚝  %𝚊𝚞𝚝𝚘𝚌𝚊𝚕𝚕  %𝚊𝚞𝚝𝚘𝚖𝚊𝚐𝚒𝚌  %𝚊𝚞𝚝𝚘𝚜𝚊𝚟𝚎  %𝚊𝚡𝚒𝚘𝚖  %𝚋𝚘𝚘𝚔𝚖𝚊𝚛𝚔  %𝚌𝚊𝚝  %𝚌𝚍  %𝚌𝚕𝚎𝚊𝚛  %𝚌𝚘𝚕𝚘𝚛𝚜  %𝚌𝚘𝚗𝚍𝚊  %𝚌𝚘𝚗𝚏𝚒𝚐  %𝚌𝚘𝚗𝚗𝚎𝚌𝚝⎯𝚒𝚗𝚏𝚘  %𝚌𝚙  %𝚌𝚛𝚞𝚗  %𝚍𝚎𝚋𝚞𝚐  %𝚍𝚑𝚒𝚜𝚝  %𝚍𝚒𝚛𝚜  %𝚍𝚒𝚜𝚙𝚕𝚊𝚢  %𝚍𝚘𝚌𝚝𝚎𝚜𝚝⎯𝚖𝚘𝚍𝚎  %𝚎𝚍  %𝚎𝚍𝚒𝚝  %𝚎𝚗𝚟  %𝚏𝚛𝚒𝚌𝚊𝚜  %𝚐𝚊𝚙  %𝚐𝚊𝚙𝟹  %𝚐𝚒𝚊𝚌  %𝚐𝚙  %𝚐𝚞𝚒  %𝚑𝚒𝚜𝚝  %𝚑𝚒𝚜𝚝𝚘𝚛𝚢  %𝚒𝚕𝚘𝚊𝚍  %𝚔𝚊𝚜𝚑  %𝚔𝚒𝚕𝚕𝚋𝚐𝚜𝚌𝚛𝚒𝚙𝚝𝚜  %𝚕𝚍𝚒𝚛  %𝚕𝚎𝚜𝚜  %𝚕𝚏  %𝚕𝚒𝚎  %𝚕𝚒𝚜𝚙  %𝚕𝚔  %𝚕𝚕  %𝚕𝚘𝚊𝚍  %𝚕𝚘𝚊𝚍⎯𝚎𝚡𝚝  %𝚕𝚘𝚊𝚍𝚙𝚢  %𝚕𝚘𝚐𝚘𝚏𝚏  %𝚕𝚘𝚐𝚘𝚗  %𝚕𝚘𝚐𝚜𝚝𝚊𝚛𝚝  %𝚕𝚘𝚐𝚜𝚝𝚊𝚝𝚎  %𝚕𝚘𝚐𝚜𝚝𝚘𝚙  %𝚕𝚜  %𝚕𝚜𝚖𝚊𝚐𝚒𝚌  %𝚕𝚡  %𝚖𝚊𝚌𝚊𝚞𝚕𝚊𝚢𝟸  %𝚖𝚊𝚌𝚛𝚘  %𝚖𝚊𝚐𝚒𝚌  %𝚖𝚊𝚐𝚖𝚊  %𝚖𝚊𝚗  %𝚖𝚊𝚙𝚕𝚎  %𝚖𝚊𝚝𝚑𝚎𝚖𝚊𝚝𝚒𝚌𝚊  %𝚖𝚊𝚝𝚑𝚒𝚌𝚜  %𝚖𝚊𝚝𝚕𝚊𝚋  %𝚖𝚊𝚝𝚙𝚕𝚘𝚝𝚕𝚒𝚋  %𝚖𝚊𝚡𝚒𝚖𝚊  %𝚖𝚔𝚍𝚒𝚛  %𝚖𝚘𝚛𝚎  %𝚖𝚞𝚙𝚊𝚍  %𝚖𝚟  %𝚖𝚠𝚛𝚊𝚗𝚔  %𝚗𝚘𝚝𝚎𝚋𝚘𝚘𝚔  %𝚘𝚌𝚝𝚊𝚟𝚎  %𝚙𝚊𝚐𝚎  %𝚙𝚊𝚜𝚝𝚎𝚋𝚒𝚗  %𝚙𝚍𝚋  %𝚙𝚍𝚎𝚏  %𝚙𝚍𝚘𝚌  %𝚙𝚏𝚒𝚕𝚎  %𝚙𝚒𝚗𝚏𝚘  %𝚙𝚒𝚗𝚏𝚘𝟸  %𝚙𝚒𝚙  %𝚙𝚘𝚕𝚢𝚖𝚊𝚔𝚎  %𝚙𝚘𝚙𝚍  %𝚙𝚙𝚛𝚒𝚗𝚝  %𝚙𝚛𝚎𝚌𝚒𝚜𝚒𝚘𝚗  %𝚙𝚛𝚞𝚗  %𝚙𝚜𝚎𝚊𝚛𝚌𝚑  %𝚙𝚜𝚘𝚞𝚛𝚌𝚎  %𝚙𝚞𝚜𝚑𝚍  %𝚙𝚠𝚍  %𝚙𝚢𝚌𝚊𝚝  %𝚙𝚢𝚕𝚊𝚋  %𝚚𝚝𝚌𝚘𝚗𝚜𝚘𝚕𝚎  %𝚚𝚞𝚒𝚌𝚔𝚛𝚎𝚏  %𝚛  %𝚛𝚎𝚌𝚊𝚕𝚕  %𝚛𝚎𝚑𝚊𝚜𝚑𝚡  %𝚛𝚎𝚕𝚘𝚊𝚍⎯𝚎𝚡𝚝  %𝚛𝚎𝚙  %𝚛𝚎𝚛𝚞𝚗  %𝚛𝚎𝚜𝚎𝚝  %𝚛𝚎𝚜𝚎𝚝⎯𝚜𝚎𝚕𝚎𝚌𝚝𝚒𝚟𝚎  %𝚛𝚖  %𝚛𝚖𝚍𝚒𝚛  %𝚛𝚞𝚗  %𝚛𝚞𝚗𝚏𝚒𝚕𝚎  %𝚜𝚊𝚐𝚎𝟶  %𝚜𝚊𝚟𝚎  %𝚜𝚌  %𝚜𝚌𝚒𝚕𝚊𝚋  %𝚜𝚎𝚝⎯𝚎𝚗𝚟  %𝚜𝚒𝚗𝚐𝚞𝚕𝚊𝚛  %𝚜𝚝𝚘𝚛𝚎  %𝚜𝚡  %𝚜𝚢𝚜𝚝𝚎𝚖  %𝚝𝚋  %𝚝𝚒𝚖𝚎  %𝚝𝚒𝚖𝚎𝚒𝚝  %𝚞𝚗𝚊𝚕𝚒𝚊𝚜  %𝚞𝚗𝚕𝚘𝚊𝚍⎯𝚎𝚡𝚝  %𝚠𝚑𝚘  %𝚠𝚑𝚘⎯𝚕𝚜  %𝚠𝚑𝚘𝚜  %𝚡𝚍𝚎𝚕  %𝚡𝚖𝚘𝚍𝚎

𝙰𝚟𝚊𝚒𝚕𝚊𝚋𝚕𝚎 𝚌𝚎𝚕𝚕 𝚖𝚊𝚐𝚒𝚌𝚜:
%%!  %%𝙷𝚃𝙼𝙻  %%𝚂𝚅𝙶  %%𝚊𝚡𝚒𝚘𝚖  %%𝚋𝚊𝚜𝚑  %%𝚌𝚊𝚙𝚝𝚞𝚛𝚎  %%𝚌𝚢𝚝𝚑𝚘𝚗  %%𝚍𝚎𝚋𝚞𝚐  %%𝚏𝚒𝚕𝚎  %%𝚏𝚘𝚛𝚝𝚛𝚊𝚗  %%𝚏𝚛𝚒𝚌𝚊𝚜  %%𝚐𝚊𝚙  %%𝚐𝚊𝚙𝟹  %%𝚐𝚒𝚊𝚌  %%𝚐𝚙  %%𝚑𝚝𝚖𝚕  %%𝚓𝚊𝚟𝚊𝚜𝚌𝚛𝚒𝚙𝚝  %%𝚓𝚜  %%𝚔𝚊𝚜𝚑  %%𝚕𝚊𝚝𝚎𝚡  %%𝚕𝚒𝚎  %%𝚕𝚒𝚜𝚙  %%𝚖𝚊𝚌𝚊𝚞𝚕𝚊𝚢𝟸  %%𝚖𝚊𝚐𝚖𝚊  %%𝚖𝚊𝚙𝚕𝚎  %%𝚖𝚊𝚛𝚔𝚍𝚘𝚠𝚗  %%𝚖𝚊𝚝𝚑𝚎𝚖𝚊𝚝𝚒𝚌𝚊  %%𝚖𝚊𝚝𝚑𝚒𝚌𝚜  %%𝚖𝚊𝚝𝚕𝚊𝚋  %%𝚖𝚊𝚡𝚒𝚖𝚊  %%𝚖𝚞𝚙𝚊𝚍  %%𝚖𝚠𝚛𝚊𝚗𝚔  %%𝚘𝚌𝚝𝚊𝚟𝚎  %%𝚙𝚎𝚛𝚕  %%𝚙𝚘𝚕𝚢𝚖𝚊𝚔𝚎  %%𝚙𝚛𝚞𝚗  %%𝚙𝚢𝚙𝚢  %%𝚙𝚢𝚝𝚑𝚘𝚗  %%𝚙𝚢𝚝𝚑𝚘𝚗𝟸  %%𝚙𝚢𝚝𝚑𝚘𝚗𝟹  %%𝚛  %%𝚛𝚞𝚋𝚢  %%𝚜𝚊𝚐𝚎𝟶  %%𝚜𝚌𝚒𝚕𝚊𝚋  %%𝚜𝚌𝚛𝚒𝚙𝚝  %%𝚜𝚑  %%𝚜𝚒𝚗𝚐𝚞𝚕𝚊𝚛  %%𝚜𝚟𝚐  %%𝚜𝚡  %%𝚜𝚢𝚜𝚝𝚎𝚖  %%𝚝𝚒𝚖𝚎  %%𝚝𝚒𝚖𝚎𝚒𝚝  %%𝚠𝚛𝚒𝚝𝚎𝚏𝚒𝚕𝚎

𝙰𝚞𝚝𝚘𝚖𝚊𝚐𝚒𝚌 𝚒𝚜 𝙾𝙽, % 𝚙𝚛𝚎𝚏𝚒𝚡 𝙸𝚂 𝙽𝙾𝚃 𝚗𝚎𝚎𝚍𝚎𝚍 𝚏𝚘𝚛 𝚕𝚒𝚗𝚎 𝚖𝚊𝚐𝚒𝚌𝚜.

Please help me to understand the function of '%auto' (is there a reference for sage 'magics' ?). Is '%auto' a line magic or cell magic or something else?

Thank you for your help.

Regards,

phiho


Nils Bruin

unread,
Feb 22, 2022, 12:30:53 PM2/22/22
to sage-devel
On Sunday, 20 February 2022 at 21:12:09 UTC-8 hohoa...@gmail.com wrote:

Please help me to understand the function of '%auto' (is there a reference for sage 'magics' ?). Is '%auto' a line magic or cell magic or something else?

The very same documentation that contains the example you reference also has an explanation right below it:

"""
A very sharp-eyed reader will also have noticed that the previous cell had %auto at the very top, and that it was not necessary to evaluate the cell to use it.

  • The command %auto allows us to have a cell, especially an interactive one, all loaded up as soon as we start - particularly convenient for a classroom situation.

  • Such instructions are called percent directives . Most are documented in the notebook help one can access at the top of any worksheet

"""
Unfortunately, as you can see from the `lsmagics`, this "percent directive" does not exist any more. I suspect it was part of the *old* sage notebook and was not ported to the new jupyter notebooks that sagemath uses now. The fact that it's referred to as a "percent directive" instead of a cell magic (as you can see from the description, it should be a cell magic and hence be spelled with "%%" if it were something for a jupyter notebook) is also an indication. It should probably be removed from the documentation

As to why it wasn't ported: it may not fit easily in the architecture of jupyter notebooks and/or there may be notebook extensions that can already do this through some other mechanism. If it were provided, it should be done on the level of the python3 Ipython kernel, of which the sagemath kernel is a derivative.

William Stein

unread,
Feb 22, 2022, 12:40:34 PM2/22/22
to sage-devel
Harald and I have also looked into this same problem:

https://github.com/sagemathinc/cocalc/issues/4698

Right at the very beginning of implementing the Sage notebook in 2007,
there were several minimal features/requirements that I thought were
absolutely critical
for anybody to actually use this thing seriously for math research, including:

- ability to start computations running, close your browser, and come
back and see the output
- %auto cells to initialize everything

It seems like these are both not available in Jupyter yet, at least by
default. The first is due to some deep design decision they made in
the architecture of the backend server (which has pros and cons), that
they will hopefully finally fix in the next year. I don't know why
auto magics aren't implemented, since it shouldn't be difficult, and
solves many problems. I'll definitely do it for cocalc-jupyter soon,
and it's done for sage worksheets still, of course.


> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/06751199-e292-4fc5-93f5-1f6566e8926dn%40googlegroups.com.



--
William (http://wstein.org)

ph h

unread,
Feb 22, 2022, 6:44:31 PM2/22/22
to sage-...@googlegroups.com
Hello List,

Thank you so much for your clarification and insight

I am looking forward to using that special magic with sage in the future.

Best regards,

phiho


Reply all
Reply to author
Forward
0 new messages