Home | Trees | Index | Help |
|
---|
Package sage :: Package rings :: Module real_number :: Class RealNumber |
|
object
--+ |Element
--+ | RealNumber
RealNumber_decimal
,
RealNumber_mpf
Method Summary | |
---|---|
__init__(self,
cls)
| |
__abs__(self)
| |
Return self + right. | |
Compare self and other. | |
Return the quotient self / right. | |
Return the coercion of self to a Python float. | |
Return the coercion of self to a Python int. | |
Return the inverse of self. | |
Return the coercion of self to a Python long. | |
Return the product of self and right. | |
Return the negative of self. | |
__pos__(self)
| |
__pow__(self,
right)
| |
__radd__(self,
left)
| |
__rdiv__(self,
left)
| |
__repr__(self)
| |
__rmul__(self,
left)
| |
__rsub__(self,
left)
| |
__sub__(self,
right)
| |
Try to find a polynomial of degree at most n having this real number x as an approximate root. | |
arg(self)
| |
imag(self)
| |
Return the logarithm of self. | |
order(self)
| |
prec(self)
| |
real(self)
| |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Property Summary | |
---|---|
pari_object : PARI real associated to this real number |
Method Details |
---|
__add__(self,
right)
Return self + right. EXAMPLES:
|
__cmp__(self,
other)
|
__div__(self, right)Return the quotient self / right. EXAMPLES:>>> R = RealField_mpf() >>> R(1) / R(3) 0.333333333333333333333 |
__float__(self)Return the coercion of self to a Python float. EXAMPLES: >>> R = RealField_mpf() >> pi = R.pi(200); pi 3.14159265358979323846264338327950288419716939937510582097494459230782 >> float(pi) 3.1415926535897931 |
__int__(self)Return the coercion of self to a Python int. This is the integer part of self. EXAMPLES: >>> 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): >>> int(R(141592653589793238462643383279502)) 141592653589793238462643383279502L Note that int is not "rounding". It simply takes the integer part of the decimal expansion, including the sign: >>> int(R(-0.8)) 0 >>> int(R(0.8)) 0 >>> int(R(-2.3)) -2 |
__invert__(self)Return the inverse of self. EXAMPLES: >>> R = RealField_mpf() >> pi = R.pi(); pi 3.14159265358979323846 >> ~pi # the additive inverse 0.318309886183790671538 Division by zero raises a .... >>> ~R(0) Traceback (most recent call last): ... ZeroDivisionError: inverse of 0 not defined |
__long__(self)Return the coercion of self to a Python long. EXAMPLES: >>> 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: >>> long(R(-0.8)) 0L >>> long(R(0.8)) 0L >>> long(R(-2.3)) -2L |
__mul__(self, 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. EXAMPLES:>>> R = RealField_mpf() >>> pi = R.pi() >>> A = pi * 25; A 78.5398163397448309615 >>> isinstance(A, real_number.RealNumber_mpf) TrueIn this example, a string is automatically coerced to a real number. >>> pi * '2.01' 6.31460123371548440927Of course two strings don't coerce to RealNumber's: >>> '3.14' * '2.01' Traceback (most recent call last): ... TypeError: can't multiply sequence by non-int |
__neg__(self)Return the negative of self. EXAMPLES:>>> x = RealNumber_mpf('1.23456') >>> -x -1.23456 |
algebraic_dependence(self, n, flag=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 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): >>> import real_field, math >>> R = real_field.RealField() >>> a = R(math.sqrt(2)) >>> 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. >>> a = R('123/456') >>> a 0.269736842105263157895 >>> a.algebraic_dependence(1) 152*x - 41 >>> 41/152.0 0.26973684210526316 |
log(self)Return the logarithm of self. IMPORTANT WARNING: Currently the computation is done by converting the number to a float and using the standard library function. Thus there is precision loss! |
Property Details |
---|
pari_objectPARI real associated to this real number |
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Jun 24 17:58:45 2005 | http://epydoc.sf.net |