# plotting prime_pi

 1 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/ in () /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 asked Sep 07 '10 finotti 51 ● 3 ● 6

 4 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. posted Sep 07 '10 kcrisman 6784 ● 14 ● 67 ● 152
 0 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 :) posted Sep 07 '10 niles 3429 ● 5 ● 41 ● 94 http://nilesjohnson.net/ In this case, no lambda needed - see below. Niles, maybe you want to fix this ticket? :) kcrisman (Sep 07 '10) ha! I certainly *want* to . . . niles (Sep 07 '10)
 0 list_plot([(x,prime_pi(x)) for x in xrange(3,10+1)]) posted Sep 07 '10 ccanonc 477 ● 3 ● 15 ● 32

[hide preview]