ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 13 Feb 2012 14:36:28 +0100Is n() the same as N() if not why nothttps://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/I am trying to use Sage as a simple numerical calculator but sometimes have to fight with more advanced features, things I think are number are not. I starting using n() to fix this up, but in some cases it did not work. Bug big N N() did. Is this the way it is supposed to be ( if so why ). Identical commands ( symbols..... ) except for capitilization seems like a bad idea. Here is the code:
# Is n() the same as N() if not why not
xll = 1. / ( pi * ( 2. ^ .5 ) )
xll = 22. * 2
print "xll is of type", type( xll )
print ""
print "Big N next"
print N( ll )
print ""
print "Little n next"
print n( xll )
produced output:
xll is of type <type 'sage.rings.real_mpfr.RealNumber'>
Big N next
0.0000120042175487614
Little N next
Traceback (click to the left of this block for traceback) ...
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callableTue, 17 Jan 2012 18:29:55 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/Answer by Laurent Claessens for <p>I am trying to use Sage as a simple numerical calculator but sometimes have to fight with more advanced features, things I think are number are not. I starting using n() to fix this up, but in some cases it did not work. Bug big N N() did. Is this the way it is supposed to be ( if so why ). Identical commands ( symbols..... ) except for capitilization seems like a bad idea. Here is the code:</p>
<pre><code># Is n() the same as N() if not why not
xll = 1. / ( pi * ( 2. ^ .5 ) )
xll = 22. * 2
print "xll is of type", type( xll )
print ""
print "Big N next"
print N( ll )
print ""
print "Little n next"
print n( xll )
</code></pre>
<p>produced output:</p>
<pre><code>xll is of type <type 'sage.rings.real_mpfr.RealNumber'>
Big N next
0.0000120042175487614
Little N next
Traceback (click to the left of this block for traceback) ...
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?answer=13138#post-id-13138As far as the style is concerned, when you want to print the values of some variables for debug purposes, instead of
print "Value of a next"
print a
you can write
print "Value of a: ",a
It's easier to read (my opinion).Wed, 18 Jan 2012 02:11:57 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?answer=13138#post-id-13138Comment by John Palmieri for <p>As far as the style is concerned, when you want to print the values of some variables for debug purposes, instead of</p>
<pre><code>print "Value of a next"
print a
</code></pre>
<p>you can write</p>
<pre><code>print "Value of a: ",a
</code></pre>
<p>It's easier to read (my opinion).</p>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20505#post-id-20505Or: print "Value of a: %s" % aWed, 18 Jan 2012 11:01:21 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20505#post-id-20505Comment by russ_hensel for <p>As far as the style is concerned, when you want to print the values of some variables for debug purposes, instead of</p>
<pre><code>print "Value of a next"
print a
</code></pre>
<p>you can write</p>
<pre><code>print "Value of a: ",a
</code></pre>
<p>It's easier to read (my opinion).</p>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20292#post-id-20292Right, is there a similar thing you can do with show()?Mon, 13 Feb 2012 14:36:28 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20292#post-id-20292Answer by DSM for <p>I am trying to use Sage as a simple numerical calculator but sometimes have to fight with more advanced features, things I think are number are not. I starting using n() to fix this up, but in some cases it did not work. Bug big N N() did. Is this the way it is supposed to be ( if so why ). Identical commands ( symbols..... ) except for capitilization seems like a bad idea. Here is the code:</p>
<pre><code># Is n() the same as N() if not why not
xll = 1. / ( pi * ( 2. ^ .5 ) )
xll = 22. * 2
print "xll is of type", type( xll )
print ""
print "Big N next"
print N( ll )
print ""
print "Little n next"
print n( xll )
</code></pre>
<p>produced output:</p>
<pre><code>xll is of type <type 'sage.rings.real_mpfr.RealNumber'>
Big N next
0.0000120042175487614
Little N next
Traceback (click to the left of this block for traceback) ...
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?answer=13136#post-id-13136n() *is* N() -- they're different names for exactly the same function, so they'll give exactly the same answers.. at least if n and N are still what they started as.
Could you cut and paste the output that shows they're different? Usually when something like this happens, either (1) a function has been replaced, say because someone typed "n = something_or_other", or (2) there's a simple typo.
(BTW, your code confuses me a little-- you assign to `xll` twice but print `N(ll)`, where ll is never defined.)
UPDATE: Thanks for posting the traceback. [Although it's not the output from the code you posted -- the capitalization in 'Little n next' is different between the two, so you must've changed something.]
The traceback makes it clear that my guess #1 was right: you've accidentally set n, little n, to a real number. Type "print n" to see what the number is. The error message is saying that a RealLiteral can't be called (which makes sense, it's not really a function.)
For example:
sage: n(pi)
3.14159265358979
sage: n = 3.45
sage: n(pi)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
[...]
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
Tue, 17 Jan 2012 18:50:24 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?answer=13136#post-id-13136Comment by DSM for <p>n() <em>is</em> N() -- they're different names for exactly the same function, so they'll give exactly the same answers.. at least if n and N are still what they started as.</p>
<p>Could you cut and paste the output that shows they're different? Usually when something like this happens, either (1) a function has been replaced, say because someone typed "n = something_or_other", or (2) there's a simple typo.</p>
<p>(BTW, your code confuses me a little-- you assign to <code>xll</code> twice but print <code>N(ll)</code>, where ll is never defined.)</p>
<p>UPDATE: Thanks for posting the traceback. [Although it's not the output from the code you posted -- the capitalization in 'Little n next' is different between the two, so you must've changed something.]</p>
<p>The traceback makes it clear that my guess #1 was right: you've accidentally set n, little n, to a real number. Type "print n" to see what the number is. The error message is saying that a RealLiteral can't be called (which makes sense, it's not really a function.)</p>
<p>For example:</p>
<pre><code>sage: n(pi)
3.14159265358979
sage: n = 3.45
sage: n(pi)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
[...]
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20480#post-id-20480@russ_hensel: Great! You can accept the answer by clicking the checkmark (on the top left hand side of this answer.)Fri, 20 Jan 2012 15:21:52 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20480#post-id-20480Comment by russ_hensel for <p>n() <em>is</em> N() -- they're different names for exactly the same function, so they'll give exactly the same answers.. at least if n and N are still what they started as.</p>
<p>Could you cut and paste the output that shows they're different? Usually when something like this happens, either (1) a function has been replaced, say because someone typed "n = something_or_other", or (2) there's a simple typo.</p>
<p>(BTW, your code confuses me a little-- you assign to <code>xll</code> twice but print <code>N(ll)</code>, where ll is never defined.)</p>
<p>UPDATE: Thanks for posting the traceback. [Although it's not the output from the code you posted -- the capitalization in 'Little n next' is different between the two, so you must've changed something.]</p>
<p>The traceback makes it clear that my guess #1 was right: you've accidentally set n, little n, to a real number. Type "print n" to see what the number is. The error message is saying that a RealLiteral can't be called (which makes sense, it's not really a function.)</p>
<p>For example:</p>
<pre><code>sage: n(pi)
3.14159265358979
sage: n = 3.45
sage: n(pi)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
[...]
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20481#post-id-20481This was exactly right, redefinition of n() --- I will look out for this sort of thing in the future, thanksFri, 20 Jan 2012 14:58:45 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20481#post-id-20481Comment by russ_hensel for <p>n() <em>is</em> N() -- they're different names for exactly the same function, so they'll give exactly the same answers.. at least if n and N are still what they started as.</p>
<p>Could you cut and paste the output that shows they're different? Usually when something like this happens, either (1) a function has been replaced, say because someone typed "n = something_or_other", or (2) there's a simple typo.</p>
<p>(BTW, your code confuses me a little-- you assign to <code>xll</code> twice but print <code>N(ll)</code>, where ll is never defined.)</p>
<p>UPDATE: Thanks for posting the traceback. [Although it's not the output from the code you posted -- the capitalization in 'Little n next' is different between the two, so you must've changed something.]</p>
<p>The traceback makes it clear that my guess #1 was right: you've accidentally set n, little n, to a real number. Type "print n" to see what the number is. The error message is saying that a RealLiteral can't be called (which makes sense, it's not really a function.)</p>
<p>For example:</p>
<pre><code>sage: n(pi)
3.14159265358979
sage: n = 3.45
sage: n(pi)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
[...]
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20513#post-id-20513My formatting is messed up, is there a code tag -- I will lookTue, 17 Jan 2012 19:29:44 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20513#post-id-20513Comment by russ_hensel for <p>n() <em>is</em> N() -- they're different names for exactly the same function, so they'll give exactly the same answers.. at least if n and N are still what they started as.</p>
<p>Could you cut and paste the output that shows they're different? Usually when something like this happens, either (1) a function has been replaced, say because someone typed "n = something_or_other", or (2) there's a simple typo.</p>
<p>(BTW, your code confuses me a little-- you assign to <code>xll</code> twice but print <code>N(ll)</code>, where ll is never defined.)</p>
<p>UPDATE: Thanks for posting the traceback. [Although it's not the output from the code you posted -- the capitalization in 'Little n next' is different between the two, so you must've changed something.]</p>
<p>The traceback makes it clear that my guess #1 was right: you've accidentally set n, little n, to a real number. Type "print n" to see what the number is. The error message is saying that a RealLiteral can't be called (which makes sense, it's not really a function.)</p>
<p>For example:</p>
<pre><code>sage: n(pi)
3.14159265358979
sage: n = 3.45
sage: n(pi)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
[...]
TypeError: 'sage.rings.real_mpfr.RealLiteral' object is not callable
</code></pre>
https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20514#post-id-20514two versions of xll to see if some detail of calc was problemTue, 17 Jan 2012 18:57:47 +0100https://ask.sagemath.org/question/8635/is-n-the-same-as-n-if-not-why-not/?comment=20514#post-id-20514