Module: sage.rings.real_double
Double Precision Real Numbers
We create the real double vector space of dimension
:
sage: V = RDF^3; V Vector space of dimension 3 over Real Double Field
Notice that this space is unique.
sage: V is RDF^3 True sage: V is FreeModule(RDF, 3) True sage: V is VectorSpace(RDF, 3) True
Also, you can instantly create a space of large dimension.
sage: V = RDF^10000
Module-level Functions
) |
Return the unique instance of the Real Double Field.
sage: RealDoubleField() is RealDoubleField() True
) |
) |
Returns True if x is the field of real double precision numbers.
sage: from sage.rings.real_double import is_RealDoubleField sage: is_RealDoubleField(RDF) True sage: is_RealDoubleField(RealField(53)) False
) |
) |
) |
Class: RealDoubleElement
Functions: abs,
acosh,
agm,
algdep,
algebraic_dependency,
arccos,
arcsin,
arcsinh,
arctan,
arctanh,
ceil,
ceiling,
cos,
cosh,
coth,
csch,
cube_root,
erf,
exp,
exp10,
exp2,
floor,
frac,
gamma,
hypot,
imag,
integer_part,
is_infinity,
is_NaN,
is_negative_infinity,
is_positive_infinity,
is_square,
log,
log10,
log2,
logpi,
multiplicative_order,
NaN,
nan,
nth_root,
parent,
prec,
real,
restrict_angle,
round,
sech,
sign,
sin,
sincos,
sinh,
sqrt,
str,
tan,
tanh,
trunc,
zeta
) |
Returns the absolute value of self.
sage: RDF(1e10).abs() 10000000000.0 sage: RDF(-1e10).abs() 10000000000.0
) |
Returns the hyperbolic inverse cosine of this number
sage: q = RDF.pi()/2 sage: i = q.cosh() ; i 2.50917847866 sage: abs(i.acosh()-q) < 1e-15 True
) |
Return the arithmetic-geometric mean of self and other. The
arithmetic-geometric mean is the common limit of the sequences
and
, where
is self,
is other,
is the arithmetic mean of
and
, and
is the geometric mean of u_n and v_n. If any operand
is negative, the return value is
NaN
.
sage: a = RDF(1.5) sage: b = RDF(2.3) sage: a.agm(b) 1.87864845581
The arithmetic-geometric always lies between the geometric and arithmetic mean.
sage: sqrt(a*b) < a.agm(b) < (a+b)/2 True
) |
Returns a polynomial of degree at most
which is approximately
satisfied by this number. Note that the returned polynomial
need not be irreducible, and indeed usually won't be if this number
is a good approximation to an algebraic number of degree less than
.
ALGORITHM: Uses the PARI C-library algdep command.
sage: r = RDF(2).sqrt(); r 1.41421356237 sage: r.algdep(5) x^2 - 2
) |
Returns a polynomial of degree at most
which is approximately
satisfied by this number. Note that the returned polynomial
need not be irreducible, and indeed usually won't be if this number
is a good approximation to an algebraic number of degree less than
.
ALGORITHM: Uses the PARI C-library algdep command.
sage: r = sqrt(RDF(2)); r 1.41421356237 sage: r.algdep(5) x^2 - 2
) |
Returns the inverse cosine of this number
sage: q = RDF.pi()/3 sage: i = q.cos() sage: i.arccos() == q True
) |
Returns the inverse sine of this number
sage: q = RDF.pi()/5 sage: i = q.sin() sage: i.arcsin() == q True
) |
Returns the hyperbolic inverse sine of this number
sage: q = RDF.pi()/2 sage: i = q.sinh() ; i 2.30129890231 sage: abs(i.arcsinh()-q) < 1e-15 True
) |
Returns the inverse tangent of this number
sage: q = RDF.pi()/5 sage: i = q.tan() sage: i.arctan() == q True
) |
Returns the hyperbolic inverse tangent of this number
sage: q = RDF.pi()/2 sage: i = q.tanh() ; i 0.917152335667 sage: i.arctanh() - q # output is random, depending on arch. -4.4408920985e-16
) |
Returns the ceiling of this number
Output: integer
sage: RDF(2.99).ceil() 3 sage: RDF(2.00).ceil() 2 sage: RDF(-5/2).ceil() -2
) |
Returns the ceiling of this number
Output: integer
sage: RDF(2.99).ceil() 3 sage: RDF(2.00).ceil() 2 sage: RDF(-5/2).ceil() -2
) |
Returns the cosine of this number
sage: t=RDF.pi()/2 sage: t.cos() 6.12323399574e-17
) |
Returns the hyperbolic cosine of this number
sage: q = RDF.pi()/12 sage: q.cosh() 1.0344656401
) |
This function returns the hyperbolic cotangent.
sage: RDF(pi).coth() 1.0037418732 sage: CDF(pi).coth() 1.0037418732
) |
This function returns the hyperbolic cosecant.
sage: RDF(pi).csch() 0.08658953753 sage: CDF(pi).csch() 0.08658953753
) |
Return the cubic root (defined over the real numbers) of self.
sage: r = RDF(125.0); r.cube_root() 5.0 sage: r = RDF(-119.0) sage: r.cube_root()^3 - r # output is random, depending on arch. 0.0
) |
Returns the value of the error function on self.
sage: RDF(6).erf() 1.0
) |
Returns
sage: r = RDF(0.0) sage: r.exp() 1.0
sage: r = RDF('32.3') sage: a = r.exp(); a 1.06588847275e+14 sage: a.log() 32.3
sage: r = RDF('-32.3') sage: r.exp() 9.3818445885e-15
sage: RDF(1000).exp() inf
) |
Returns
sage: r = RDF(0.0) sage: r.exp10() 1.0
sage: r = RDF(32.0) sage: r.exp10() 1e+32
sage: r = RDF(-32.3) sage: r.exp10() 5.01187233627e-33
) |
Returns
sage: r = RDF(0.0) sage: r.exp2() 1.0
sage: r = RDF(32.0) sage: r.exp2() 4294967296.0
sage: r = RDF(-32.3) sage: r.exp2() 1.89117248253e-10
) |
Returns the floor of this number
sage: RDF(2.99).floor() 2 sage: RDF(2.00).floor() 2 sage: RDF(-5/2).floor() -3
) |
frac returns a real number > -1 and < 1. it satisfies the relation: x = x.trunc() + x.frac()
sage: RDF(2.99).frac() 0.99 sage: RDF(2.50).frac() 0.5 sage: RDF(-2.79).frac() -0.79
) |
The Euler gamma function. Return gamma of self.
sage: RDF(6).gamma() 120.0 sage: RDF(1.5).gamma() 0.886226925453
) |
Computes the value
in such a way as to avoid overflow.
sage: x = RDF(4e300); y = RDF(3e300); sage: x.hypot(y) 5e+300 sage: sqrt(x^2+y^2) # overflow inf
) |
Returns the imaginary part of this number. (hint: it's zero.)
sage: a = RDF(3) sage: a.imag() 0.0
) |
If in decimal this number is written n.defg, returns n.
sage: r = RDF('-1.6') sage: a = r.integer_part(); a -1 sage: type(a) <type 'sage.rings.integer.Integer'>
) |
sage: a = RDF(2); b = RDF(0) sage: (a/b).is_infinity() True sage: (b/a).is_infinity() False
) |
sage: RDF(1).is_NaN() False sage: a = RDF(0)/RDF(0) sage: a.is_NaN() True
) |
sage: a = RDF(2)/RDF(0) sage: a.is_negative_infinity() False sage: a = RDF(-3)/RDF(0) sage: a.is_negative_infinity() True
) |
sage: a = RDF(1)/RDF(0) sage: a.is_positive_infinity() True sage: a = RDF(-1)/RDF(0) sage: a.is_positive_infinity() False
) |
Returns whether or not this number is a square in this field. For the real numbers, this is True if and only if self is non-negative.
sage: RDF(3.5).is_square() True sage: RDF(0).is_square() True sage: RDF(-4).is_square() False
) |
sage: RDF(2).log() 0.69314718056 sage: RDF(2).log(2) 1.0 sage: RDF(2).log(pi) 0.605511561398 sage: RDF(2).log(10) 0.301029995664 sage: RDF(2).log(1.5) 1.70951129135 sage: RDF(0).log() -inf sage: RDF(-1).log() nan
) |
Returns log to the base 10 of self
sage: r = RDF('16.0'); r.log10() 1.20411998266 sage: r.log() / RDF(log(10)) 1.20411998266 sage: r = RDF('39.9'); r.log10() 1.60097289569
) |
Returns log to the base 2 of self
sage: r = RDF(16.0) sage: r.log2() 4.0
sage: r = RDF(31.9); r.log2() 4.99548451888
) |
Returns log to the base pi of self
sage: r = RDF(16); r.logpi() 2.42204624559 sage: r.log() / RDF(log(pi)) 2.42204624559 sage: r = RDF('39.9'); r.logpi() 3.22030233461
) |
Returns
such that
= 1.
Only
have finite multiplicative_order order.
sage: RDF(1).multiplicative_order() 1 sage: RDF(-1).multiplicative_order() 2 sage: RDF(3).multiplicative_order() +Infinity
) |
sage: RDF.NaN() nan
) |
sage: RDF.nan() nan
) |
Returns the
root of self.
Input:
The output is complex if self is negative and n is even.
sage: r = RDF(-125.0); r.nth_root(3) -5.0 sage: r.nth_root(5) -2.6265278044 sage: RDF(-2).nth_root(5)^5 -2.0 sage: RDF(-1).nth_root(5)^5 -1.0 sage: RDF(3).nth_root(10)^10 3.0 sage: RDF(-1).nth_root(2) 6.12323399574e-17 + 1.0*I sage: RDF(-1).nth_root(4) 0.707106781187 + 0.707106781187*I
) |
Return the real double field, which is the parent of self.
sage: a = RDF(2.3) sage: a.parent() Real Double Field sage: parent(a) Real Double Field
) |
Returns the precision of this number (to be more similar to RealNumber). Always returns 53.
sage: RDF(0).prec() 53
) |
Returns itself - we're already real.
sage: a = RDF(3) sage: a.real() 3.0
) |
Returns a number congruent to self mod
that lies in the interval
.
Specifically, it is the unique
such that
for some
.
sage: RDF(pi).restrict_angle() 3.14159265359 sage: RDF(pi + 1e-10).restrict_angle() -3.14159265349 sage: RDF(1+10^10*pi).restrict_angle() 0.9999977606...
) |
Given real number x, rounds up if fractional part is greater than .5, rounds down if fractional part is lesser than .5.
sage: RDF(0.49).round() 0.0 sage: RDF(0.51).round() 1.0
) |
This function returns the hyperbolic secant.
sage: RDF(pi).sech() 0.0862667383341 sage: CDF(pi).sech() 0.0862667383341
) |
Returns -1,0, or 1 if self is negative, zero, or positive; respectively.
Examples:
sage: RDF(-1.5).sign() -1 sage: RDF(0).sign() 0 sage: RDF(2.5).sign() 1
) |
Returns the sine of this number
sage: RDF(2).sin() 0.909297426826
) |
Returns a pair consisting of the sine and cosine.
sage: t = RDF.pi()/6 sage: t.sincos() (0.5, 0.866025403784)
) |
Returns the hyperbolic sine of this number
sage: q = RDF.pi()/12 sage: q.sinh() 0.264800227602
) |
The square root function.
Input:
sage: r = RDF(4.0) sage: r.sqrt() 2.0 sage: r.sqrt()^2 == r True
sage: r = RDF(4344) sage: r.sqrt() 65.9090282131 sage: r.sqrt()^2 - r # random low order bits 0.0
sage: r = RDF(-2.0) sage: r.sqrt() 1.41421356237*I
sage: RDF(2).sqrt(all=True) [1.41421356237, -1.41421356237] sage: RDF(0).sqrt(all=True) [0.0] sage: RDF(-2).sqrt(all=True) [1.41421356237*I, -1.41421356237*I]
) |
Return string representation of self.
sage: a = RDF('4.5'); a.str() '4.5' sage: a = RDF('49203480923840.2923904823048'); a.str() '4.92034809238e+13' sage: a = RDF(1)/RDF(0); a.str() 'inf' sage: a = -RDF(1)/RDF(0); a.str() '-inf' sage: a = RDF(0)/RDF(0); a.str() 'nan'
) |
Returns the tangent of this number
sage: q = RDF.pi()/3 sage: q.tan() 1.73205080757 sage: q = RDF.pi()/6 sage: q.tan() 0.57735026919
) |
Returns the hyperbolic tangent of this number
sage: q = RDF.pi()/12 sage: q.tanh() 0.255977789246
) |
Truncates this number (returns integer part).
sage: RDF(2.99).trunc() 2.0 sage: RDF(-2.00).trunc() -2.0 sage: RDF(0.00).trunc() 0.0
) |
Return the Riemann zeta function evaluated at this real number.
Note: PARI is vastly more efficient at computing the Riemann zeta function. See the example below for how to use it.
sage: RDF(2).zeta() 1.64493406685 sage: RDF.pi()^2/6 1.64493406685 sage: RDF(-2).zeta() # slightly random-ish arch dependent output -2.37378795339e-18 sage: RDF(1).zeta() inf
Special Functions: __abs__,
__complex__,
__copy__,
__eq__,
__float__,
__ge__,
__gt__,
__init__,
__int__,
__invert__,
__le__,
__long__,
__lshift__,
__lt__,
__ne__,
__neg__,
__pow__,
__reduce__,
__repr__,
__rlshift__,
__rpow__,
__rrshift__,
__rshift__,
_complex_double_,
_complex_mpfr_field_,
_im_gens_,
_interface_init_,
_latex_,
_pari_,
_rpy_
) |
Returns the absolute value of self.
sage: abs(RDF(1.5)) 1.5 sage: abs(RDF(-1.5)) 1.5
) |
sage: a = 2303 sage: RDF(a) 2303.0 sage: complex(RDF(a)) (2303+0j)
) |
Return copy of self, which since self is immutable, is just self.
sage: r = RDF('-1.6') sage: r.__copy__() is r True
) |
Return self as a python float.
sage: float(RDF(1.5)) 1.5 sage: type(float(RDF(1.5))) <type 'float'>
) |
Returns integer truncation of this real number.
sage: int(RDF(2.99)) 2 sage: int(RDF(-2.99)) -2
) |
Compute the multiplicative inverse of self.
sage: a = RDF(-1.5)*RDF(2.5) sage: a.__invert__() -0.266666666667 sage: ~a -0.266666666667
) |
Returns long integer truncation of this real number.
sage: int(RDF(10e15)) 10000000000000000L # 32-bit 10000000000000000 # 64-bit sage: long(RDF(2^100)) == 2^100 True
) |
LShifting a double is not supported; nor is lshifting a RealDoubleElement.
) |
Negates a real number.
sage: -RDF('-1.5') 1.5
) |
sage: a = RDF(-2.7) sage: loads(dumps(a)) == a True
) |
Return print version of self.
sage: a = RDF(2); a 2.0 sage: a^2 4.0
) |
RShifting a double is not supported; nor is rshifting a RealDoubleElement.
) |
sage: CDF(RDF(1/3)) 0.333333333333
) |
sage: a = RDF(1/3) sage: CC(a) 0.333333333333333 sage: a._complex_mpfr_field_(CC) 0.333333333333333
If we coerce to a higher-precision field the extra bits appear random; they are actualy 0's in base 2.
sage: a._complex_mpfr_field_(ComplexField(100)) 0.33333333333333331482961625625 sage: a._complex_mpfr_field_(ComplexField(100)).str(2) '0.010101010101010101010101010101010101010101010101010101000000000000000000 00000000000000000000000000000'
) |
) |
Returns self formatted as a string, suitable as input to another computer algebra system. (This is the default function used for exporting to other computer algebra systems.)
sage: s1 = RDF(sin(1)); s1 0.841470984808 sage: s1._interface_init_() '0.8414709848078965' sage: s1 == RDF(gp(s1)) True
) |
sage: RDF(2e-100)._latex_() '2 \times 10^{-100}'
) |
sage: RDF(1.5)._pari_() 1.5000000000000000000
) |
Returns self.__float__() for rpy to convert into the appropriate R object.
sage: n = RDF(2.0) sage: n._rpy_() 2.0 sage: type(n._rpy_()) <type 'float'>
Class: RealDoubleField_class
sage: RR == RDF False sage: RDF == RealDoubleField() # RDF is the shorthand True
Functions: algebraic_closure,
characteristic,
construction,
euler_constant,
factorial,
gen,
is_atomic_repr,
is_exact,
is_finite,
log2,
name,
nan,
NaN,
ngens,
pi,
prec,
random_element,
zeta
) |
Returns the algebraic closure of self, ie, the complex double field.
sage: RDF.algebraic_closure() Complex Double Field
) |
Returns 0, since the field of real numbers has characteristic 0.
sage: RDF.characteristic() 0
) |
Returns the functorial construction of self, namely, completion of
the rational numbers with respect to the prime at
.
Also preserves other information that makes this field unique (i.e. the Real Double Field).
sage: c, S = RDF.construction(); S Rational Field sage: RDF == c(S) True
) |
Returns Euler's gamma constant to double precision
sage: RDF.euler_constant() 0.577215664902
) |
Return the factorial of the integer n as a real number.
sage: RDF.factorial(100) 9.33262154439e+157
) |
Return the generator of the real double field.
sage: RDF.0 1.0 sage: RDF.gens() (1.0,)
) |
Returns True, to signify that elements of this field print without sums, so parenthesis aren't required, e.g., in coefficients of polynomials.
sage: RDF.is_atomic_repr() True
) |
Returns False, because doubles are not exact.
sage: RDF.is_exact() False
) |
Returns False, since the field of real numbers is not finite. Technical note: There exists an upper bound on the double representation.
sage: RDF.is_finite() False
) |
Returns log(2) to the precision of this field.
sage: RDF.log2() 0.69314718056 sage: RDF(2).log() 0.69314718056
) |
sage: RDF.nan() nan
) |
sage: RDF.NaN() nan
) |
Returns pi to double-precision.
sage: RDF.pi() 3.14159265359 sage: RDF.pi().sqrt()/2 0.886226925453
) |
Return the precision of this real double field (to be more similar to RealField). Always returns 53.
sage: RDF.prec() 53
) |
Return a random element of this real double field in the interval [min, max].
sage: RDF.random_element() 0.736945423566 sage: RDF.random_element(min=100, max=110) 102.815947352
) |
Return an
-th root of unity in the real field,
if one exists, or raise a ValueError otherwise.
sage: RDF.zeta() -1.0 sage: RDF.zeta(1) 1.0 sage: RDF.zeta(5) Traceback (most recent call last): ... ValueError: No 5th root of unity in self
Special Functions: __call__,
__cmp__,
__init__,
__repr__,
_latex_
) |
Create a real double using x.
sage: RDF(1) 1.0 sage: RDF(2/3) 0.666666666667
A TypeError is raised if the coercion doesn't make sense:
sage: RDF(QQ['x'].0) Traceback (most recent call last): ... TypeError: cannot coerce nonconstant polynomial to float
One can convert back and forth between double precision real numbers and higher-precision ones, though of course there may be loss of precision:
sage: a = RealField(200)(2).sqrt(); a 1.4142135623730950488016887242096980785696718753769480731767 sage: b = RDF(a); b 1.41421356237 sage: a.parent()(b) 1.4142135623730951454746218587388284504413604736328125000000 sage: a.parent()(b) == b True sage: b == RR(a) True
) |
Print out this real double field.
sage: RealDoubleField() Real Double Field sage: RDF Real Double Field
) |
Class: ToRDF
Special Functions: __init__,
_repr_type
) |
See About this document... for information on suggesting changes.