Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Short answer: You probably need to use %%gp instead of %gp.

Explanations:

The behavior depends on the front-end you are using:

  • If you use the Ipython shell (running in a terminal),

    • typing %gpswitches to GP and you can use GP in a standard manner. The same thing occurs if you run SageMath using sage -gp.
    • typing %%gp allows you to write several lines of Pari/GP. (A final blank line is needed to evaluate the previous lines.)
  • If you use Jupyter notebooks, you have two options:

    • %gp <command> (on a single line) executes <command> from Pari/GP (example: %gp primepi(123456))
    • %%gp as the first line of a cell turns the cell into a Pari/GP cell (in the same way basically as %%gp in the Ipython shell).
  • If you use the old Sage notebook, you can turn a cell into a Pari/GP cell by using %gp on its first line. This is the same as the second option for Jupyter notebooks, but with one % instead of %%. You cannot use %%gp in this case.

As far as I understand, Cocalc's choice is to mimic the behavior of the old Sage notebook.

Examples of use in Jupyter notebooks:

%gp primepi(123456)
11601

or

%%gp
n = primepi(123456)
n + 1
11601
11602