cls) |
algebraic_dependence,
log,
pari_object
These methods are defined as follows:
n, [flag=False], [make_integral=0]) |
Try to find a polynomial of degree at most n having this real number x as an approximate root.
The polynomial that is obtained is not necessarily "correct", and it's not even guaranteed to be irreducible. One can check the closeness either by evaluation or by computing the roots of the polynomial given by algdep.
INPUT: n -- positive integer flag -- 0 (default): Use a variant of the LLL algorithm due to Hastard, Lagarias, and Schnorr (STACS 1986). If the precision is too low, the routine may enter an infinite loop. >0: Use a standard LLL algorithm, where the flag is a precision, which should be between 0.5 and 1.0 times the number of decimal digits to which x was computed. OUTPUT: A polynomial over the reals. If make_integral is True, instead try to return a polynomial over the integers.
IMPLEMENTATION: Call PARI's algdep function. Note that the default real precision of PARI is used, not the precision of this real number.
EXAMPLE: We compute the minimal polynomial of sqrt(2):
sage: import real_field, math sage: R = real_field.RealField() sage: a = R(math.sqrt(2)) sage: a.algebraic_dependence(2) x^2 - 2
Here we compute the real number 123/456, which is not in lowest terms, and find the minimal polynomial, which is a polynomial of degree 1.
sage: a = R('123/456') sage: a 0.269736842105263157895 sage: a.algebraic_dependence(1) 152.0*x - 41.0 sage: a.algebraic_dependence(1, make_integral=True) 152*x - 41 sage: 41/152.0 0.26973684210526316
) |
Return the logarithm of self.
) |
Instances of class RealNumber also have the following special methods:
right) |
Return self + right.
sage: RealNumber_mpf('2/3') + RealNumber_decimal(0.333) 0.999666666666666666667
other) |
Compare self and other.
In comparisons numeric types, e.g., int, long, float, and those derived from Element, are converted to a RealNumber (if it is on the left), to the precision of the number on the left.
sage: R = RealNumber_mpf sage: R('2/3') < 1 True sage: R('1/3') > 0.1 True sage: R('1/3') > RealNumber_decimal(0.1) True sage: R('1/3') == R('0.3333333333333333') False
Strings are not numeric, so they are not converted.
sage: R(1) == '1' False
right) |
Return the quotient self / right.
sage: R = RealField_mpf() sage: R(1) / R(3) 0.333333333333333333333
) |
Return the coercion of self to a Python float.
sage: R = RealField_mpf()
sage: pi = R.pi(200); pi 3.1415926535897932384626433832795028841971693993751058209749445 9230782 sage: float(pi) 3.1415926535897931
) |
Return the coercion of self to a Python int. This is the integer part of self.
sage: R = RealField_mpf()
» pi = R.pi(200); pi 3.14159265358979323846264338327950288419716939937510582097494459230782 » int(pi) 3
If the real number is too large to fit in a Python int, it is coerced to a Python long (note the L below):
sage: int(R(141592653589793238462643383279502)) 141592653589793238462643383279502L
Note that int is not "rounding". It simply takes the integer part of the decimal expansion, including the sign:
sage: int(R(-0.8)) 0 sage: int(R(0.8)) 0 sage: int(R(-2.3)) -2
) |
Return the inverse of self.
sage: R = RealField_mpf()
sage: pi = R.pi(); pi 3.14159265358979323846 sage: ~pi # the additive inverse 0.318309886183790671538
Division by zero raises a ....
sage: ~R(0) Traceback (most recent call last): ... ZeroDivisionError: inverse of 0 not defined
) |
Return the coercion of self to a Python long.
sage: R = RealField_mpf()
» pi = R.pi(200); pi 3.14159265358979323846264338327950288419716939937510582097494459230782 » long(pi) 3L
Note that int is not "rounding". It simply takes the integer part of the decimal expansion, including the sign:
sage: long(R(-0.8)) 0L sage: long(R(0.8)) 0L sage: long(R(-2.3)) -2L
right) |
Return the product of self and right.
If right is not a RealNumber, an attempt is made to coerce self and right into a common parent.
sage: R = RealField_mpf() sage: pi = R.pi() sage: A = pi * 25; A 78.5398163397448309615 sage: isinstance(A, real_number.RealNumber_mpf) True
In this example, a string is automatically coerced to a real number.
sage: pi * '2.01' 6.31460123371548440927
Of course two strings don't coerce to RealNumber's:
sage: '3.14' * '2.01' Traceback (most recent call last): ... TypeError: can't multiply sequence by non-int
) |
Return the negative of self.
sage: x = RealNumber_mpf('1.23456') sage: -x -1.23456
See About this document... for information on suggesting changes.