<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> from sympy . polys . domains . field import Field <EOL> from sympy . polys . domains . simpledomain import SimpleDomain <EOL> from sympy . polys . domains . characteristiczero import CharacteristicZero <EOL> from sympy . polys . domains . mpelements import MPContext <EOL> from sympy . polys . polyerrors import DomainError , CoercionFailed <EOL> from sympy . core . numbers import Float <EOL> from sympy . utilities import public <EOL> @ public <EOL> class RealField ( Field , CharacteristicZero , SimpleDomain ) : <EOL> """<STR_LIT>""" <EOL> rep = '<STR_LIT>' <EOL> is_RealField = is_RR = True <EOL> is_Exact = False <EOL> is_Numerical = True <EOL> has_assoc_Ring = False <EOL> has_assoc_Field = True <EOL> _default_precision = <NUM_LIT> <EOL> @ property <EOL> def has_default_precision ( self ) : <EOL> return self . precision == self . _default_precision <EOL> @ property <EOL> def precision ( self ) : <EOL> return self . _context . prec <EOL> @ property <EOL> def dps ( self ) : <EOL> return self . _context . dps <EOL> @ property <EOL> def tolerance ( self ) : <EOL> return self . _context . tolerance <EOL> def __init__ ( self , prec = _default_precision , dps = None , tol = None ) : <EOL> context = MPContext ( prec , dps , tol ) <EOL> context . _parent = self <EOL> self . _context = context <EOL> self . dtype = context . mpf <EOL> self . zero = self . dtype ( <NUM_LIT:0> ) <EOL> self . one = self . dtype ( <NUM_LIT:1> ) <EOL> def __eq__ ( self , other ) : <EOL> return ( isinstance ( other , RealField ) <EOL> and self . precision == other . precision <EOL> and self . tolerance == other . tolerance ) <EOL> def __hash__ ( self ) : <EOL> return hash ( ( self . __class__ . __name__ , self . dtype , self . precision , self . tolerance ) ) <EOL> def to_sympy ( self , element ) : <EOL> """<STR_LIT>""" <EOL> return Float ( element , self . dps ) <EOL> def from_sympy ( self , expr ) : <EOL> """<STR_LIT>""" <EOL> number = expr . evalf ( n = self . dps ) <EOL> if number . is_Number : <EOL> return self . dtype ( number ) <EOL> else : <EOL> raise CoercionFailed ( "<STR_LIT>" % expr ) <EOL> def from_ZZ_python ( self , element , base ) : <EOL> return self . dtype ( element ) <EOL> def from_QQ_python ( self , element , base ) : <EOL> return self . dtype ( element . numerator ) / element . denominator <EOL> def from_ZZ_gmpy ( self , element , base ) : <EOL> return self . dtype ( int ( element ) ) <EOL> def from_QQ_gmpy ( self , element , base ) : <EOL> return self . dtype ( int ( element . numerator ) ) / int ( element . denominator ) <EOL> def from_RealField ( self , element , base ) : <EOL> if self == base : <EOL> return element <EOL> else : <EOL> return self . dtype ( element ) <EOL> def from_ComplexField ( self , element , base ) : <EOL> if not element . imag : <EOL> return self . dtype ( element . real ) <EOL> def to_rational ( self , element , limit = True ) : <EOL> """<STR_LIT>""" <EOL> return self . _context . to_rational ( element , limit ) <EOL> def get_ring ( self ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> def get_exact ( self ) : <EOL> """<STR_LIT>""" <EOL> from sympy . polys . domains import QQ <EOL> return QQ <EOL> def gcd ( self , a , b ) : <EOL> """<STR_LIT>""" <EOL> return self . one <EOL> def lcm ( self , a , b ) : <EOL> """<STR_LIT>""" <EOL> return a * b <EOL> def almosteq ( self , a , b , tolerance = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _context . almosteq ( a , b , tolerance ) </s>
