9.1 Mathematical constants

Module: sage.functions.constants

Mathematical constants

The following standard mathematical constants are defined in Sage, along with support for coercing them into GAP, GP/PARI, KASH, Maxima, Mathematica, Maple, Octave, and Singular:

sage: pi
pi
sage: e             # base of the natural logarithm
e
sage: NaN           # Not a number
NaN
sage: golden_ratio
golden_ratio
sage: log2          # natural logarithm of the real number 2
log2
sage: euler_gamma   # Euler's gamma constant
euler_gamma
sage: catalan       # the Catalon constant
catalan
sage: khinchin      # Khinchin's constant
khinchin
sage: twinprime
twinprime
sage: merten
merten
sage: brun
brun

Support for coercion into the various systems means that if, e.g., you want to create $ \pi$ in Maxima and Singular, you don't have to figure out the special notation for each system. You just type the following:

sage: pi.str()
'3.14159265358979'
sage: maxima(pi)
%pi
sage: singular(pi)
3.14159265358979
sage: gap(pi)
3.14159265358979
sage: gp(pi)
3.141592653589793238462643383     # 32-bit
3.1415926535897932384626433832795028842   # 64-bit
sage: pari(pi)
3.141592653589793238462643383     # 32-bit
3.1415926535897932384626433832795028842   # 64-bit
sage: kash(pi)                    # optional
3.14159265358979323846264338328
sage: mathematica(pi)             # optional
Pi
sage: maple(pi)                   # optional
Pi
sage: octave(pi)                  # optional
3.14159

Arithmetic operations with constants also yield constants, which can be coerced into other systems or evaluated.

sage: a = pi + e*4/5; a
pi + 4*e/5
sage: maxima(a)
%pi+4*%e/5
sage: RealField(15)(a)           # 15 *bits* of precision
5.316
sage: gp(a)             
5.316218116357029426750873360              # 32-bit
5.3162181163570294267508733603616328824    # 64-bit
sage: print mathematica(a)                     # optional
 4 E
 --- + Pi
  5

Decimal expansions of constants

We can obtain floating point approximations to each of these constants by coercing into the real field with given precision. For example, to 200 decimal places we have the following:

sage: R = RealField(200); R
Real Field with 200 bits of precision

sage: R(pi)
3.1415926535897932384626433832795028841971693993751058209749

sage: R(e)
2.7182818284590452353602874713526624977572470936999595749670

sage: R(NaN)
NaN

sage: R(golden_ratio)
1.6180339887498948482045868343656381177203091798057628621354

sage: R(log2)
0.69314718055994530941723212145817656807550013436025525412068

sage: R(euler_gamma)
0.57721566490153286060651209008240243104215933593992359880577

sage: R(catalan)
0.91596559417721901505460351493238411077414937428167213426650

sage: R(khinchin)
2.6854520010653064453097148354817956938203822939944629530512

Arithmetic with constants

sage: f = I*(e+1); f
(e + 1)*I
sage: f^2
-(e + 1)^2

sage: pp = pi+pi; pp
2*pi
sage: R(pp)
6.2831853071795864769252867665590057683943387987502116419499

sage: s = (1 + e^pi); s
e^pi + 1
sage: R(s)
24.140692632779269005729086367948547380266106242600211993445
sage: R(s-1)
23.140692632779269005729086367948547380266106242600211993445

sage: l = (1-log2)/(1+log2); l
(1 - log(2))/(log(2) + 1)
sage: R(l)
0.18123221829928249948761381864650311423330609774776013488056

sage: pim = maxima(pi)
sage: maxima.eval('fpprec : 100')
'100'
sage: pim.bfloat()
3.1415926535897932384626433832795028841971693993751058209749445923078164062
86208998628034825342117068b0

Author Log:

TESTS: Coercion of each constant to the RQDF:

sage: RQDF(e)
2.718281828459045235360287471352662497757247093699959574966967630
sage: RQDF(pi)
3.141592653589793238462643383279502884197169399375105820974944590
sage: RQDF(e)
2.718281828459045235360287471352662497757247093699959574966967630
sage: RQDF(I)
Traceback (most recent call last):
...
TypeError
sage: RQDF(golden_ratio)
1.618033988749894848204586834365638117720309179805762862135448623
sage: RQDF(log2)
0.693147180559945309417232121458176568075500134360255254120680009
sage: RQDF(euler_gamma)
0.577215664901532860606512090082402431042159335939923598805767234
sage: RQDF(catalan)
0.915965594177219015054603514932384110774149374281672134266498119
sage: RQDF(khinchin)
2.685452001065306445309714835481795693820382293994462953051152345
sage: RQDF(twinprime)
0.660161815846869573927812110014555778432623360284733413319448422
sage: RQDF(merten)
0.261497212847642783755426838608695859051566648261199206192064212
sage: RQDF(brun)
Traceback (most recent call last):
...
NotImplementedError: Brun's constant only available up to 41 bits

Coercing the sum of a bunch of the constants to many different floating point rings:

sage: a = pi + e + golden_ratio + log2 + euler_gamma + catalan + khinchin + twinprime + merten; a
twinprime + merten + khinchin + euler_gamma + catalan + log(2) + pi + e +
(sqrt(5) + 1)/2
sage: parent(a)
Symbolic Ring
sage: RQDF(a)
13.27134794019724931009881919957581394087110682000307481783297119
sage: RR(a)
13.2713479401972
sage: RealField(212)(a)
13.2713479401972493100988191995758139408711068200030748178329712
sage: RealField(230)(a)
13.271347940197249310098819199575813940871106820003074817832971189555
sage: CC(a)
13.2713479401972
sage: CDF(a)
13.2713479402
sage: ComplexField(230)(a)
13.271347940197249310098819199575813940871106820003074817832971189555
sage: RDF(a)
13.2713479402

Class: Brun

class Brun
Brun's constant is the sum of reciprocals of odd twin primes.

It is not known to very high precision; calculating the number using twin primes up to $ 10^{16}$ (Sebah 2002) gives the number $ 1.9021605831040$ .

sage: float(brun)
       1.902160583104
       sage: R = RealField(41); R
       Real Field with 41 bits of precision
       sage: R(brun)
       1.90216058310
Brun( self)

sage: loads(dumps(brun))
brun

Functions: floor

floor( self)

Return the floor of self.

sage: brun.floor()
1

Special Functions: __float__,$ \,$ __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(brun)
1.902160583104

_mpfr_( self, R)

sage: RealField(53)(brun)
Traceback (most recent call last):
...
NotImplementedError: Brun's constant only available up to 41 bits
sage: RealField(41)(brun)
1.90216058310

_real_double_( self, R)

sage: RDF(brun)
1.9021605831

_real_rqdf_( self, R)

sage: RealField(53)(brun)
Traceback (most recent call last):
...
NotImplementedError: Brun's constant only available up to 41 bits

_repr_( self, [simplify=True])

sage: brun._repr_()
'brun'
sage: repr(brun)
'brun'

Class: Catalan

class Catalan
A number appaering in combinatorics defined as the Dirichlet beta function evaluated at the number 2.

sage: catalan^2 + merten
merten + catalan^2
Catalan( self)

sage: loads(dumps(catalan))
catalan

Functions: floor

floor( self)

Return the floor of self.

sage: catalan.floor()
0

Special Functions: __float__,$ \,$ __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(catalan)
0.91596559417721901

_mpfr_( self, R)

sage: RealField(100)(catalan)
0.91596559417721901505460351493
sage: catalan._mpfr_(RealField(100))
0.91596559417721901505460351493

_real_double_( self, R)

We coerce to the real double field:

sage: RDF(catalan)      
0.915965594177

_real_rqdf_( self, R)

sage: RQDF(catalan)
0.915965594177219015054603514932384110774149374281672134266498119

_repr_( self, [simplify=True])

sage: repr(catalan)
'catalan'
sage: catalan._repr_(catalan)
'catalan'

Class: Constant

class Constant
Constant( self, [conversions=], [parent=Symbolic Ring])

Functions: floor,$ \,$ number_of_arguments,$ \,$ substitute,$ \,$ variables

floor( self)

Returns the floor of self.

sage: pi.floor()
3
sage: e.floor()
2
sage: golden_ratio.floor()
1
sage: log2.floor()
0

number_of_arguments( self)

Returns the number of arguments of self. For constants, this is just zero.

sage: type(pi)
<class 'sage.functions.constants.Pi'>
sage: pi.number_of_arguments()
0
sage: e.number_of_arguments()
0

substitute( self)

Substitute values into self. For constants, this just returns self.

sage: pi.substitute(x=3)
pi
sage: pi.substitute(3)
pi
sage: pi.substitute(4, x=4)
pi

variables( self)

Return a list of the variables of self. For constants, this is the empty list.

sage: pi.variables()
[]
sage: e.variables()
[]

Special Functions: __abs__,$ \,$ __call__,$ \,$ __eq__,$ \,$ __ge__,$ \,$ __gt__,$ \,$ __init__,$ \,$ __le__,$ \,$ __lt__,$ \,$ __ne__,$ \,$ __pow__,$ \,$ _add_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _div_,$ \,$ _fast_float_,$ \,$ _has_op,$ \,$ _interface_is_cached_,$ \,$ _latex_,$ \,$ _maxima_,$ \,$ _mul_,$ \,$ _neg_,$ \,$ _real_double_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _ser,$ \,$ _sub_

__abs__( self)

Returns the absolute value of self.

sage: abs(pi)
pi

__call__( self)

Call self as a function. Since self is a constant function, this just returns self.

sage: pi(2,3,4)
pi
sage: pi(pi)
pi

__eq__( self, right)

sage: solve(pi == 2*x)
[x == pi/2]
sage: solve(cos(x^2) == pi)
[x == -sqrt(arccos(pi)), x == sqrt(arccos(pi))]

__ge__( self, right)

sage: type(pi>=3)
<class 'sage.calculus.equations.SymbolicEquation'>
sage: bool(pi>=3)
True

__gt__( self, right)

sage: type(pi>3)
<class 'sage.calculus.equations.SymbolicEquation'>
sage: bool(pi>3)
True

__le__( self, right)

sage: pi <= 3
pi <= 3
sage: type(pi<=3)
<class 'sage.calculus.equations.SymbolicEquation'>
sage: bool(pi<=3)
False

__lt__( self, right)

sage: pi < 3
pi < 3
sage: type(pi<3)
<class 'sage.calculus.equations.SymbolicEquation'>
sage: bool(pi<3)
False

__ne__( self, right)

sage: type(pi != 3)
<class 'sage.calculus.equations.SymbolicEquation'>
sage: bool(pi != 3)
True

__pow__( self, right)

sage: a = pi^pi; a
pi^pi
sage: map(type, a._operands)
[<class 'sage.calculus.calculus.SymbolicConstant'>,
 <class 'sage.calculus.calculus.SymbolicConstant'>]

_add_( self, right)

sage: I + 2
I + 2
sage: a = I+I
sage: map(type, a._operands)
[<class 'sage.calculus.calculus.SymbolicConstant'>,
 <class 'sage.calculus.calculus.SymbolicConstant'>]

_complex_double_( self, R)

sage: pi._complex_double_(CDF)
3.14159265359

_complex_mpfr_field_( self, R)

sage: pi._complex_mpfr_field_(ComplexField(53))
3.14159265358979
sage: pi._complex_mpfr_field_(ComplexField(200))
3.1415926535897932384626433832795028841971693993751058209749

_div_( self, right)

sage: a = I / pi; a
I/pi
sage: map(type, a._operands)
[<class 'sage.calculus.calculus.SymbolicConstant'>,
 <class 'sage.calculus.calculus.SymbolicConstant'>]

_has_op( self, x)

Check whether or not self contains the operation x. Since self is a constant, this is always False.

sage: pi._has_op(operator.add)
False

_interface_is_cached_( self)

Return False, since coercion of functions to interfaces is not cached.

We do not cache coercions of functions to interfaces, since the precision of the interface may change.

sage: gp(pi)
3.141592653589793238462643383              # 32-bit
3.1415926535897932384626433832795028842    # 64-bit
sage: old_prec = gp.set_precision(100)
sage: gp(pi)
3.1415926535897932384626433832795028841971693993751058209749445923078164062
86208998628034825342117068
sage: _ = gp.set_precision(old_prec)
sage: gp(pi)
3.141592653589793238462643383              # 32-bit
3.1415926535897932384626433832795028842    # 64-bit

_latex_( self)

Return the LaTeXrepresentation of self.

sage: catalan._latex_()
'\\text{catalan}'

_maxima_( self, [session=None])

Returns self as a maxima object.

sage: pi._maxima_()
%pi

_mul_( self, right)

sage: a = I * pi; a
I*pi
sage: map(type, a._operands)
[<class 'sage.calculus.calculus.SymbolicConstant'>,
 <class 'sage.calculus.calculus.SymbolicConstant'>]

_neg_( self)

Returns the negation of self.

sage: -pi
-1*pi
sage: -e
-1*e

_real_double_( self, R)

sage: pi._real_double_(RDF)
3.14159265359

_recursive_sub( self, kwds)

Recursively substitute values into self. For constants, this just returns self.

sage: pi._recursive_sub({x:3})
pi

_recursive_sub_over_ring( self, kwds, ring)

Recursively substitute values into self over a ring. For constants, this just returns ring(self).

sage: pi._recursive_sub_over_ring({x:3}, RDF)
3.14159265359

_ser( self)

Returns self as an element of SymbolicRing.

sage: s = pi._ser(); s
pi
sage: type(s)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: s.parent()
Symbolic Ring

_sub_( self, right)

sage: a = I - pi; a
I - pi
sage: map(type, a._operands)
[<class 'sage.calculus.calculus.SymbolicConstant'>,
 <class 'sage.calculus.calculus.SymbolicConstant'>]

Class: Constant_arith

class Constant_arith
Constant_arith( self, x, y, op)

Special Functions: __init__

Class: Constant_gen

class Constant_gen
Constant_gen( self, x)

Special Functions: __call__,$ \,$ __init__,$ \,$ __repr__

Class: E

class E
The base of the natural logarithm.

sage: RR(e)
2.71828182845905
sage: R = RealField(200); R
Real Field with 200 bits of precision
sage: R(e)
2.7182818284590452353602874713526624977572470936999595749670
sage: em = 1 + e^(1-e); em
e^(1 - e) + 1
sage: R(em)
1.1793740787340171819619895873183164984596816017589156131574
sage: maxima(e).float()
2.718281828459045
sage: t = mathematica(e)               # optional
sage: t                                # optional
E
sage: float(t)                         # optional
2.7182818284590451
E( self)

sage: bool( e == loads(dumps(e)) )
True

Functions: floor

floor( self)

Returns the floor of self.

sage: e.floor()
2

Special Functions: __float__,$ \,$ __init__,$ \,$ _latex_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(e)
2.7182818284590451
sage: e.__float__()
2.7182818284590451

_latex_( self)

sage: e._latex_()
'e'
sage: latex(e)
e

_mpfr_( self, R)

sage: e._mpfr_(RealField(100))
2.7182818284590452353602874714

_real_double_( self, R)

sage: e._real_double_(RDF)
2.71828182846

_real_rqdf_( self, R)

sage: RQDF = RealQuadDoubleField ()
sage: RQDF.e()
2.718281828459045235360287471352662497757247093699959574966967630

_repr_( self, [simplify=True])

sage: repr(e)
'e'
sage: e._repr_()
'e'

Class: EulerGamma

class EulerGamma
The limiting difference between the harmonic series and the natural logarithm.

sage: R = RealField()
sage: R(euler_gamma)
0.577215664901533
sage: R = RealField(200); R
Real Field with 200 bits of precision
sage: R(euler_gamma)
0.57721566490153286060651209008240243104215933593992359880577
sage: eg = euler_gamma + euler_gamma; eg
2*euler_gamma
sage: R(eg)
1.1544313298030657212130241801648048620843186718798471976115
EulerGamma( self)

sage: loads(dumps(euler_gamma))
euler_gamma

Functions: floor

floor( self)

Return the floor of self.

sage: euler_gamma.floor()
0

Special Functions: __init__,$ \,$ _latex_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

_latex_( self)

sage: euler_gamma._latex_()
'\gamma'
sage: latex(euler_gamma)
\gamma

_mpfr_( self, R)

sage: RealField(100)(euler_gamma)
0.57721566490153286060651209008
sage: euler_gamma._mpfr_(RealField(100))
0.57721566490153286060651209008

_real_double_( self, R)

sage: RDF(euler_gamma)
0.577215664902

_real_rqdf_( self, R)

sage: RQDF(euler_gamma)
0.577215664901532860606512090082402431042159335939923598805767234
sage: euler_gamma._real_rqdf_(RQDF)
0.577215664901532860606512090082402431042159335939923598805767234

_repr_( self, [simplify=True])

sage: repr(euler_gamma)
'euler_gamma'
sage: euler_gamma._repr_()
'euler_gamma'

Class: GoldenRatio

class GoldenRatio
The number (1+sqrt(5))/2

sage: gr = golden_ratio
sage: RR(gr)
1.61803398874989
sage: R = RealField(200)
sage: R(gr)
1.6180339887498948482045868343656381177203091798057628621354
sage: grm = maxima(golden_ratio);grm
(sqrt(5)+1)/2
sage: grm + grm
sqrt(5)+1
sage: float(grm + grm)
3.2360679774997898
GoldenRatio( self)

sage: loads(dumps(golden_ratio))
golden_ratio

Functions: minpoly

minpoly( self, [bits=None], [degree=None], [epsilon=0])

sage: golden_ratio.minpoly()
x^2 - x - 1

Special Functions: __float__,$ \,$ __init__,$ \,$ _algebraic_,$ \,$ _latex_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(golden_ratio)
1.6180339887498949
sage: golden_ratio.__float__()
1.6180339887498949

_algebraic_( self, field)

sage: golden_ratio._algebraic_(QQbar)
[1.6180339887498946 .. 1.6180339887498950]
sage: QQbar(golden_ratio)
[1.6180339887498946 .. 1.6180339887498950]

_latex_( self)

sage: latex(golden_ratio)
\phi
sage: golden_ratio._latex_()
'\phi'

_mpfr_( self, R)

sage: golden_ratio._mpfr_(RealField(100))
1.6180339887498948482045868344
sage: RealField(100)(golden_ratio)
1.6180339887498948482045868344

_real_double_( self, R)

sage: RDF(golden_ratio)
1.61803398875

_real_rqdf_( self, R)

sage: golden_ratio._real_rqdf_(RQDF)
1.618033988749894848204586834365638117720309179805762862135448623
sage: RQDF(golden_ratio)
1.618033988749894848204586834365638117720309179805762862135448623

_repr_( self, [simplify=True])

sage: repr(golden_ratio)
'golden_ratio'
sage: golden_ratio._repr_()
'golden_ratio'

Class: I_class

class I_class
The formal square root of -1.

sage: I
I
sage: I^2
-1
sage: float(I)
Traceback (most recent call last):
...
TypeError
sage: gp(I)
I
sage: RR(I)
Traceback (most recent call last):
...
TypeError
sage: C = ComplexField(200); C
Complex Field with 200 bits of precision
sage: C(I)
1.0000000000000000000000000000000000000000000000000000000000*I
sage: z = I + I; z
2*I
sage: C(z)
2.0000000000000000000000000000000000000000000000000000000000*I
sage: maxima(2*I)
2*%i
sage: 1e8*I
1.00000000000000e8*I
I_class( self)

sage: bool(I == loads(dumps(I)))
True

Functions: floor,$ \,$ minpoly

floor( self)

sage: I.floor()
Traceback (most recent call last):
...
TypeError

minpoly( self, [bits=None], [degree=None], [epsilon=0])

sage: I.minpoly()
x^2 + 1

Special Functions: __abs__,$ \,$ __complex__,$ \,$ __float__,$ \,$ __init__,$ \,$ _algebraic_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _latex_,$ \,$ _mathml_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__abs__( self)

sage: abs(I)
1
sage: I.__abs__()
1

__complex__( self)

sage: complex(I)
1j

__float__( self)

sage: float(I)
Traceback (most recent call last):
...
TypeError

_algebraic_( self, field)

sage: QQbar(I)
1*I

_complex_double_( self, C)

sage: I._complex_double_(CDF)
1.0*I

_complex_mpfr_field_( self, R)

sage: I._complex_mpfr_field_(ComplexField(53))
1.00000000000000*I

_latex_( self)

sage: I._latex_()
'i'
sage: latex(I)
i

_mathml_( self)

sage: I._mathml_()
'<mi>\&i;</mi>'
sage: mathml(I)
<mi>\&i;</mi>

_mpfr_( self, R)

sage: I._mpfr_(RealField(53))
Traceback (most recent call last):
...
TypeError

_real_double_( self, R)

sage: I._mpfr_(RealField(53))
Traceback (most recent call last):
...
TypeError

_real_rqdf_( self, R)

sage: I._real_rqdf_(RQDF)
Traceback (most recent call last):
...
TypeError

_repr_( self, [simplify=True])

sage: repr(I)
'I'

Class: Khinchin

class Khinchin
The geometric mean of the continued fraction expansion of any (almost any) real number.

sage: float(khinchin)
2.6854520010653062
sage: khinchin.str(100)
'2.6854520010653064453097148355'
sage: m = mathematica(khinchin); m             # optional
Khinchin
sage: m.N(200)                                 # optional
2.6854520010653064453097148354817956938203822939944629530511523455572188595
371520028011411749318476979951534659052880900828976777164109630517925334832
5966838185231542133211949962603932852204481940961807          # 32-bit
2.6854520010653064453097148354817956938203822939944629530511523455572188595
371520028011411749318476979951534659052880900828976777164109630517925334832
596683818523154213321194996260393285220448194096181                # 64-bit
Khinchin( self)

sage: loads(dumps(khinchin))
khinchin

Functions: floor

floor( self)

Returns the floor of self.

sage: khinchin.floor()
2

Special Functions: __float__,$ \,$ __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(khinchin)
2.6854520010653062

_mpfr_( self, R)

sage: RealField(100)(khinchin)
2.6854520010653064453097148355
sage: RealField(20000)(khinchin)
Traceback (most recent call last):
...
NotImplementedError: Khinchin's constant only available up to 3005 bits

_real_double_( self, R)

sage: RDF(khinchin)
2.68545200107

_real_rqdf_( self, R)

sage: RQDF(khinchin)
2.685452001065306445309714835481795693820382293994462953051152345

_repr_( self, [simplify=True])

sage: repr(khinchin)
'khinchin'
sage: khinchin._repr_()
'khinchin'

Class: Log2

class Log2
The natural logarithm of the real number 2.

sage: log2
log2
sage: float(log2)
0.69314718055994529
sage: RR(log2)
0.693147180559945
sage: R = RealField(200); R
Real Field with 200 bits of precision
sage: R(log2)
0.69314718055994530941723212145817656807550013436025525412068
sage: l = (1-log2)/(1+log2); l
(1 - log(2))/(log(2) + 1)
sage: R(l)
0.18123221829928249948761381864650311423330609774776013488056
sage: maxima(log2)
log(2)
sage: maxima(log2).float()
.6931471805599453
sage: gp(log2)
0.6931471805599453094172321215             # 32-bit
0.69314718055994530941723212145817656807   # 64-bit
Log2( self)

sage: loads(dumps(log2))
log2

Functions: floor

floor( self)

Returns the floor of self.

sage: log2.floor()
0

Special Functions: __float__,$ \,$ __init__,$ \,$ _latex_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(log2)
0.69314718055994529
sage: log2.__float__()
0.69314718055994529

_latex_( self)

sage: log2._latex_()
'\log(2)'
sage: latex(log2)
\log(2)

_mpfr_( self, R)

sage: RealField(100)(log2)
0.69314718055994530941723212146
sage: log2._mpfr_(RealField(100))
0.69314718055994530941723212146

_real_double_( self, R)

sage: RDF(log2)
0.69314718056

_real_rqdf_( self, R)

sage: RQDF(log2)
0.693147180559945309417232121458176568075500134360255254120680009

_repr_( self, [simplify=True])

sage: repr(log2)
'log2'
sage: log2._repr_()
'log2'

Class: Merten

class Merten
The Merten constant is related to the Twin Primes constant and appears in Merten's second theorem.

sage: float(merten)
0.26149721284764277
sage: R=RealField(200);R
Real Field with 200 bits of precision
sage: R(merten)
0.26149721284764278375542683860869585905156664826119920619206
Merten( self)

sage: loads(dumps(merten))
merten

Functions: floor

floor( self)

Returns the floor of self.

sage: merten.floor()
0

Special Functions: __float__,$ \,$ __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(merten)
0.26149721284764277

_mpfr_( self, R)

sage: RealField(1000)(merten)
Traceback (most recent call last):
...
NotImplementedError: Merten's constant only available up to 320 bits
sage: RealField(320)(merten)
0.2614972128476427837554268386086958590515666482611992061920642139249245108
97368209714142631434247

_real_double_( self, R)

sage: RDF(merten)
0.261497212848

_real_rqdf_( self, R)

sage: RQDF(merten)
0.261497212847642783755426838608695859051566648261199206192064212

_repr_( self, [simplify=True])

sage: merten._repr_()
'merten'
sage: repr(merten)
'merten'

Class: NotANumber

class NotANumber
Not a Number
NotANumber( self)

sage: loads(dumps(NaN))
NaN

Special Functions: __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

_mpfr_( self, R)

sage: NaN._mpfr_(RealField(53))
NaN
sage: type(_)
<type 'sage.rings.real_mpfr.RealNumber'>

_real_double_( self, R)

sage: RDF(NaN)
nan

_real_rqdf_( self, R)

sage: RQDF(NaN)
'NaN'

_repr_( self, [simplify=True])

sage: repr(NaN)
'NaN'
sage: NaN._repr_()
'NaN'

Class: Pi

class Pi
The ratio of a circle's circumference to its diameter.

sage: pi
pi
sage: float(pi)
3.1415926535897931
sage: gp(pi)
3.141592653589793238462643383            # 32-bit
3.1415926535897932384626433832795028842  # 64-bit
sage: RR(pi)
3.14159265358979
sage: R = RealField(200); R
Real Field with 200 bits of precision
sage: R(pi)
3.1415926535897932384626433832795028841971693993751058209749
sage: pp = pi+pi; pp
2*pi
sage: R(pp)
6.2831853071795864769252867665590057683943387987502116419499
sage: maxima(pi)
%pi
sage: maxima(pi).float()
3.141592653589793
Pi( self)

sage: bool(pi == loads(dumps(pi)))
True

Functions: floor

floor( self)

Returns the floor of self.

sage: pi.floor()
3

Special Functions: __float__,$ \,$ __init__,$ \,$ _latex_,$ \,$ _mathml_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(pi)
3.1415926535897931

_latex_( self)

sage: pi._latex_()
'\pi'
sage: latex(pi)
\pi

_mathml_( self)

sage: pi._mathml_()
'<mi>\&pi;</mi>'
sage: mathml(pi)
<mi>\&pi;</mi>

_mpfr_( self, R)

sage: pi._mpfr_(RealField(100))
3.1415926535897932384626433833

_real_double_( self, R)

sage: pi._real_double_(RDF)
3.14159265359

_real_rqdf_( self, R)

sage: pi._real_rqdf_(RQDF)
3.141592653589793238462643383279502884197169399375105820974944590

_repr_( self, [simplify=True])

sage: repr(pi)
'pi'

Class: TwinPrime

class TwinPrime
The Twin Primes constant is defined as $ \prod 1 - 1/(p-1)^2$ for primes $ p > 2$ .

sage: float(twinprime)
       0.66016181584686962
       sage: R=RealField(200);R
       Real Field with 200 bits of precision
       sage: R(twinprime)
       0.66016181584686957392781211001455577843262336028473341331945
TwinPrime( self)

sage: loads(dumps(twinprime))
twinprime

Functions: floor

floor( self)

Returns the floor of self.

sage: twinprime.floor()
0

Special Functions: __float__,$ \,$ __init__,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_

__float__( self)

sage: float(twinprime)
0.66016181584686962

_mpfr_( self, R)

sage: RealField(100)(twinprime)
0.66016181584686957392781211001
sage: RealField(20000)(twinprime)
Traceback (most recent call last):
...
NotImplementedError: Twin Prime constant only available up to 3011 bits

_real_double_( self, R)

sage: RDF(twinprime)
0.660161815847

_real_rqdf_( self, R)

sage: RQDF(twinprime)
0.660161815846869573927812110014555778432623360284733413319448422

_repr_( self, [simplify=True])

sage: repr(twinprime)
'twinprime'
sage: twinprime._repr_()
'twinprime'

See About this document... for information on suggesting changes.