# plotting prime_pi

Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?


----------------------------------------------------------------------
| Sage Version 4.5.1, Release Date: 2010-07-19                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: plot(prime_pi(x),3,10)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/dept/finotti/<ipython console=""> in <module>()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/functions/prime_pi.so in sage.functions.prime_pi.PrimePi.__call__ (sage/functions/prime_pi.c:1064)()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__int__ (sage/symbolic/expression.cpp:4171)()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.n (sage/symbolic/expression.cpp:17042)()

TypeError: cannot evaluate symbolic expression numerically


It seems wot work fine with real input


sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171


Thanks,

Luis

edit retag close merge delete

Sort by ยป oldest newest most voted

Essentially, prime_pi has its own plotting method, so you need to do

sage: plot(prime_pi, 50,100)


You can see this at

sage: prime_pi?


However, you are right that it should play nicely with other plotting syntax, which is why we have the ticket here tracking this issue.

more

list_plot([(x,prime_pi(x)) for x in xrange(3,10+1)])

more

Yes, you should be able to plot prime_pi, using just the code you tried! Unfortunately it seems that plot can not always figure out what to evaluate, so you have to help it a little, using a lambda function:

sage: plot(lambda x: prime_pi(x),3,10)


or, equivalently,

sage: f = lambda x: prime_pi(x)
sage: plot(f,3,10)


There have been a number of similar problems with similar solutions mentioned on this site . . . maybe eventually someone will extend plot so that the code you tried first will work. At least in the meantime someone could change the error message to suggest trying lambda functions . . .

Also, could you tell us where you read about the plot function? It could be very useful to include an example like this somewhere that people will find it :)

more

In this case, no lambda needed - see below. Niles, maybe you want to fix this ticket? :)

( 2010-09-07 04:42:03 -0600 )edit

ha! I certainly *want* to . . .

( 2010-09-07 04:45:25 -0600 )edit