Ask Your Question

Using Sage plotting capability on data from PARI/GP

asked 2018-02-08 05:49:41 -0500

RuudH gravatar image

I am trying to plot data in Sage that is generated by a function in PARI/GP, however keep getting type errors.

I use this simple example to illustrate the point:


This gives the correct output 1.6449340668482264364724151666460251892 and appears to be a 'normal' floating point number that I can indeed multiply/add with.

However, when I try the following:


It keeps coming back with

TypeError: Error executing code in GP

I have studied most of the (limited) info on the Pari/GP interface and did read that PARI/GP always returns a string. I therefore tried to convert the returned value into a float, int etc., however nothing works. I very likely do something wrong (or not allowed) and would be grateful for any advice on what could be the issue here (esp. since f(2) gives the correct numerical floating point result).


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-02-08 13:06:09 -0500

slelievre gravatar image

The workaround here is to use a lambda expression.

This is a very general trick for any plotting problem where there are problems with the function or expression.

Using the following should get you the plot you want.

sage: plot(lambda x: f(x), (2, 6))
edit flag offensive delete link more


Many thanks! This works very well indeed. I had seen the use of the lambda before, but never related it to calls with PARI/GP objects.

RuudH gravatar imageRuudH ( 2018-02-08 13:10:46 -0500 )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


Asked: 2018-02-08 05:49:41 -0500

Seen: 27 times

Last updated: Feb 08