Ask Your Question
2

Using multiple lines of pari/gp code in a Sage notebook

asked 2018-03-25 22:58:41 +0100

RuudH gravatar image

I am struggling to get multiple lines of pari/gp code working in a Jupyter Sage notebook.

When I enter:

%%gp
for(x=1,10,print(x))

it all works fine, however when I for instance write:

%%gp
for(x=1,10,{
    print(x);
})

the system just 'hangs' and doesn't return any output. The same issue occurs in the Cocalc Sage cloud environment. I also tried 'pari/gp in your browser' and there it works fine.

Am I doing something wrong or isn't the multi-line pari/gp option supported in Sage?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-25 23:25:32 +0100

slelievre gravatar image

updated 2018-04-01 18:56:18 +0100

Why not use the PARI/GP kernel for Jupyter?

To install it on top of your Sage installation,

$ sage -i pari_jupyter

and then you can select it when creating a Jupyter worksheet.

Likewise, you can install the GAP, R and Singular kernels for Jupyter:

$ sage -i gap_jupyter
$ sage -i r_jupyter
$ sage -i singular_jupyter
edit flag offensive delete link more

Comments

Thanks for your response! I will try that out, but would appreciate some coaching. I have installed Sage/Jupyter notebook on a MAC and am not sure where exactly I have to type the command $ sage -i pari_jupyter. Is this on the command prompt (Terminal)?

RuudH gravatar imageRuudH ( 2018-03-26 15:50:29 +0100 )edit

Yes. Type that in the terminal. It will work if you made it so that typing sage in the terminal launches Sage.

Otherwise, in the terminal, first do cd /path/to/sagedir, replacing /path/to/sagedir by the actual path to the folder containing your Sage installation.

Depending whether you installed the "app" version or the "non-app" version, and assuming you placed it in the general Applications folder for your mac, this might be for instance /Applications/SageMath or /Applications/SageMath.app/Contents/Resources/.

Then do the same commands as in the answer above, but with ./sage instead of sage. (And don't type the $, it's just supposed to represent the prompt you get in the terminal).

Or you could run, from a running Sage (in Jupyter or other):

!sage -i pari_jupyter
slelievre gravatar imageslelievre ( 2018-03-26 16:20:03 +0100 )edit

@slelievre. Thanks for the detailed explanation. I have followed the instructions but unfortunately end up with an error (see screenshot attached). It seems that the limit.h file can't be found on my machine. Do you have an idea on how to resolve this? https://ibb.co/g2UZ77

RuudH gravatar imageRuudH ( 2018-03-27 12:56:04 +0100 )edit

You need to install Apple's command-line tools for macOS. See

It should just be a matter of running the following in a terminal window:

$ xcode-select --install

(again, don't type the $).

slelievre gravatar imageslelievre ( 2018-03-28 15:00:33 +0100 )edit

You're a star, @slelievre! It works perfectly and performs exactly as I wanted. In a dedicated pari-file the loops now function properly. I would have never figured this out myself.

RuudH gravatar imageRuudH ( 2018-03-29 00:27:26 +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: 2018-03-25 22:58:41 +0100

Seen: 665 times

Last updated: Apr 01 '18