n(xxx) - bits or digits of precision?!

200 views
Skip to first unread message

Dima Pasechnik

unread,
Mar 12, 2016, 1:26:50 PM3/12/16
to sage-support
sage: pi.n?
Docstring:
   Return a numerical approximation this symbolic expression as either
   a real or complex number with at least the requested number of bits
   or digits of precision.

this is clearly ambiguous; can it be clarified?
(it bites e.g. if one wants to create meaningful doctests, such as on #18888)

Volker Braun

unread,
Mar 12, 2016, 2:47:46 PM3/12/16
to sage-support
Whats ambiguous?

The call signature is missing, thats a bug. Ideally it would be documented in an INPUT block.

Dima Pasechnik

unread,
Mar 12, 2016, 3:11:56 PM3/12/16
to sage-support, Matthias Koeppe


On Saturday, March 12, 2016 at 7:47:46 PM UTC, Volker Braun wrote:
Whats ambiguous?

 (decimal) digits or bits?

a part of my confusion comes from a puzzling (OSX-specific) error on #18888.

A Mathematica object has .n() and .N(), and they are not synonyms.
(n() is Sage's method, N() is Mathematica's method).

However it seems that on OSX N() acts as n(), I don't understand why. Some case-insensitive stuff, I guess.

Volker Braun

unread,
Mar 12, 2016, 3:46:59 PM3/12/16
to sage-support, mko...@ucdavis.edu
Default is bits, the digits= keyword argument its for decimal digits instead. 

Signature: pi.n(self, prec=None, digits=None, algorithm=None):
Docstring:
   Return a numerical approximation this symbolic expression as either
   a real or complex number with at least the requested number of bits
   or digits of precision.

   EXAMPLES:

      sage: sin(x).subs(x=5).n()
      -0.958924274663138
      sage: sin(x).subs(x=5).n(100)
      -0.95892427466313846889315440616
      sage: sin(x).subs(x=5).n(digits=50)
      -0.95892427466313846889315440615599397335246154396460
Reply all
Reply to author
Forward
0 new messages