ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 07 Sep 2010 04:45:25 -0500plotting prime_pihttp://ask.sagemath.org/question/7673/plotting-prime_pi/Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?
<pre><code>
----------------------------------------------------------------------
| 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
</code></pre>
It seems wot work fine with real input
<pre><code>
sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171
</code></pre>
Thanks,
LuisTue, 07 Sep 2010 04:32:48 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/Answer by kcrisman for <p>Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?</p>
<pre><code>
----------------------------------------------------------------------
| 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
</code></pre>
<p>It seems wot work fine with real input</p>
<pre><code>
sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171
</code></pre>
<p>Thanks,</p>
<p>Luis</p>
http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11628#post-id-11628Essentially, `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][1] tracking this issue.
[1]: http://trac.sagemath.org/sage_trac/ticket/6876Tue, 07 Sep 2010 04:41:24 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11628#post-id-11628Answer by ccanonc for <p>Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?</p>
<pre><code>
----------------------------------------------------------------------
| 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
</code></pre>
<p>It seems wot work fine with real input</p>
<pre><code>
sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171
</code></pre>
<p>Thanks,</p>
<p>Luis</p>
http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11629#post-id-11629list\_plot([(x,prime_pi(x)) for x in xrange(3,10+1)])Tue, 07 Sep 2010 04:42:18 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11629#post-id-11629Answer by niles for <p>Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?</p>
<pre><code>
----------------------------------------------------------------------
| 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
</code></pre>
<p>It seems wot work fine with real input</p>
<pre><code>
sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171
</code></pre>
<p>Thanks,</p>
<p>Luis</p>
http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11627#post-id-11627Yes, 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 :)Tue, 07 Sep 2010 04:40:29 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/?answer=11627#post-id-11627Comment by kcrisman for <p>Yes, you <strong>should</strong> be able to plot <code>prime_pi</code>, using just the code you tried! Unfortunately it seems that <code>plot</code> can not always figure out what to evaluate, so you have to help it a little, using a lambda function:</p>
<pre><code>sage: plot(lambda x: prime_pi(x),3,10)
</code></pre>
<p>or, equivalently,</p>
<pre><code>sage: f = lambda x: prime_pi(x)
sage: plot(f,3,10)
</code></pre>
<p>There have been a number of similar problems with similar solutions mentioned on this site . . . maybe eventually someone will extend <code>plot</code> 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 . . .</p>
<p>Also, could you tell us where you read about the <code>plot</code> function? It could be very useful to include an example like this somewhere that people will find it :)</p>
http://ask.sagemath.org/question/7673/plotting-prime_pi/?comment=22700#post-id-22700In this case, no lambda needed - see below. Niles, maybe you want to fix this ticket? :)Tue, 07 Sep 2010 04:42:03 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/?comment=22700#post-id-22700Comment by niles for <p>Yes, you <strong>should</strong> be able to plot <code>prime_pi</code>, using just the code you tried! Unfortunately it seems that <code>plot</code> can not always figure out what to evaluate, so you have to help it a little, using a lambda function:</p>
<pre><code>sage: plot(lambda x: prime_pi(x),3,10)
</code></pre>
<p>or, equivalently,</p>
<pre><code>sage: f = lambda x: prime_pi(x)
sage: plot(f,3,10)
</code></pre>
<p>There have been a number of similar problems with similar solutions mentioned on this site . . . maybe eventually someone will extend <code>plot</code> 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 . . .</p>
<p>Also, could you tell us where you read about the <code>plot</code> function? It could be very useful to include an example like this somewhere that people will find it :)</p>
http://ask.sagemath.org/question/7673/plotting-prime_pi/?comment=22699#post-id-22699ha! I certainly *want* to . . .Tue, 07 Sep 2010 04:45:25 -0500http://ask.sagemath.org/question/7673/plotting-prime_pi/?comment=22699#post-id-22699