<s> from __future__ import print_function , division <EOL> from sympy . core . singleton import S <EOL> from sympy . core . function import Function <EOL> from sympy . core import Add <EOL> from sympy . core . evalf import get_integer_part , PrecisionExhausted <EOL> from sympy . core . numbers import Integer <EOL> from sympy . core . relational import Gt , Lt , Ge , Le <EOL> from sympy . core . symbol import Symbol <EOL> class RoundFunction ( Function ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , arg ) : <EOL> from sympy import im <EOL> if arg . is_integer : <EOL> return arg <EOL> if arg . is_imaginary or ( S . ImaginaryUnit * arg ) . is_real : <EOL> i = im ( arg ) <EOL> if not i . has ( S . ImaginaryUnit ) : <EOL> return cls ( i ) * S . ImaginaryUnit <EOL> return cls ( arg , evaluate = False ) <EOL> v = cls . _eval_number ( arg ) <EOL> if v is not None : <EOL> return v <EOL> ipart = npart = spart = S . Zero <EOL> terms = Add . make_args ( arg ) <EOL> for t in terms : <EOL> if t . is_integer or ( t . is_imaginary and im ( t ) . is_integer ) : <EOL> ipart += t <EOL> elif t . has ( Symbol ) : <EOL> spart += t <EOL> else : <EOL> npart += t <EOL> if not ( npart or spart ) : <EOL> return ipart <EOL> if npart and ( <EOL> not spart or <EOL> npart . is_real and ( spart . is_imaginary or ( S . ImaginaryUnit * spart ) . is_real ) or <EOL> npart . is_imaginary and spart . is_real ) : <EOL> try : <EOL> r , i = get_integer_part ( <EOL> npart , cls . _dir , { } , return_ints = True ) <EOL> ipart += Integer ( r ) + Integer ( i ) * S . ImaginaryUnit <EOL> npart = S . Zero <EOL> except ( PrecisionExhausted , NotImplementedError ) : <EOL> pass <EOL> spart += npart <EOL> if not spart : <EOL> return ipart <EOL> elif spart . is_imaginary or ( S . ImaginaryUnit * spart ) . is_real : <EOL> return ipart + cls ( im ( spart ) , evaluate = False ) * S . ImaginaryUnit <EOL> else : <EOL> return ipart + cls ( spart , evaluate = False ) <EOL> def _eval_is_finite ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] . is_finite <EOL> def _eval_is_real ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] . is_real <EOL> def _eval_is_integer ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] . is_real <EOL> class floor ( RoundFunction ) : <EOL> """<STR_LIT>""" <EOL> _dir = - <NUM_LIT:1> <EOL> @ classmethod <EOL> def _eval_number ( cls , arg ) : <EOL> if arg . is_Number : <EOL> if arg . is_Rational : <EOL> return Integer ( arg . p // arg . q ) <EOL> elif arg . is_Float : <EOL> return Integer ( int ( arg . floor ( ) ) ) <EOL> else : <EOL> return arg <EOL> if arg . is_NumberSymbol : <EOL> return arg . approximation_interval ( Integer ) [ <NUM_LIT:0> ] <EOL> def _eval_nseries ( self , x , n , logx ) : <EOL> r = self . subs ( x , <NUM_LIT:0> ) <EOL> args = self . args [ <NUM_LIT:0> ] <EOL> args0 = args . subs ( x , <NUM_LIT:0> ) <EOL> if args0 == r : <EOL> direction = ( args - args0 ) . leadterm ( x ) [ <NUM_LIT:0> ] <EOL> if direction . is_positive : <EOL> return r <EOL> else : <EOL> return r - <NUM_LIT:1> <EOL> else : <EOL> return r <EOL> def __le__ ( self , other ) : <EOL> if self . args [ <NUM_LIT:0> ] == other and other . is_real : <EOL> return S . true <EOL> return Le ( self , other , evaluate = False ) <EOL> def __gt__ ( self , other ) : <EOL> if self . args [ <NUM_LIT:0> ] == other and other . is_real : <EOL> return S . false <EOL> return Gt ( self , other , evaluate = False ) <EOL> class ceiling ( RoundFunction ) : <EOL> """<STR_LIT>""" <EOL> _dir = <NUM_LIT:1> <EOL> @ classmethod <EOL> def _eval_number ( cls , arg ) : <EOL> if arg . is_Number : <EOL> if arg . is_Rational : <EOL> return - Integer ( - arg . p // arg . q ) <EOL> elif arg . is_Float : <EOL> return Integer ( int ( arg . ceiling ( ) ) ) <EOL> else : <EOL> return arg <EOL> if arg . is_NumberSymbol : <EOL> return arg . approximation_interval ( Integer ) [ <NUM_LIT:1> ] <EOL> def _eval_nseries ( self , x , n , logx ) : <EOL> r = self . subs ( x , <NUM_LIT:0> ) <EOL> args = self . args [ <NUM_LIT:0> ] <EOL> args0 = args . subs ( x , <NUM_LIT:0> ) <EOL> if args0 == r : <EOL> direction = ( args - args0 ) . leadterm ( x ) [ <NUM_LIT:0> ] <EOL> if direction . is_positive : <EOL> return r + <NUM_LIT:1> <EOL> else : <EOL> return r <EOL> else : <EOL> return r <EOL> def __lt__ ( self , other ) : <EOL> if self . args [ <NUM_LIT:0> ] == other and other . is_real : <EOL> return S . false <EOL> return Lt ( self , other , evaluate = False ) <EOL> def __ge__ ( self , other ) : <EOL> if self . args [ <NUM_LIT:0> ] == other and other . is_real : <EOL> return S . true <EOL> return Ge ( self , other , evaluate = False ) <EOL> class frac ( Function ) : <EOL> r"""<STR_LIT>""" <EOL> @ classmethod <EOL> def eval ( cls , arg ) : <EOL> from sympy import AccumBounds , im <EOL> def _eval ( arg ) : <EOL> if arg is S . Infinity or arg is S . NegativeInfinity : <EOL> return AccumBounds ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> if arg . is_integer : <EOL> return S . Zero <EOL> if arg . is_number : <EOL> if arg is S . NaN : <EOL> return S . NaN <EOL> elif arg is S . ComplexInfinity : <EOL> return None <EOL> else : <EOL> return arg - floor ( arg ) <EOL> return cls ( arg , evaluate = False ) <EOL> terms = Add . make_args ( arg ) <EOL> real , imag = S . Zero , S . Zero <EOL> for t in terms : <EOL> if t . is_imaginary or ( S . ImaginaryUnit * t ) . is_real : <EOL> i = im ( t ) <EOL> if not i . has ( S . ImaginaryUnit ) : <EOL> imag += i <EOL> else : <EOL> real += t <EOL> else : <EOL> real += t <EOL> real = _eval ( real ) <EOL> imag = _eval ( imag ) <EOL> return real + S . ImaginaryUnit * imag <EOL> def _eval_rewrite_as_floor ( self , arg ) : <EOL> return arg - floor ( arg ) </s>
