def _eval_power(self, other, terms=False): # n n n # (-3 + y) -> (-1) * (3 - y) # # If terms=True then return the arguments that should be # multiplied together rather than multiplying them. # # At present, as_coeff_terms return +/-1 but the # following should work even if that changes. if Basic.keep_sign: return None rv = None c, t = self.as_coeff_mul() if c.is_negative and not other.is_integer: if c is not S.NegativeOne and self.is_positive: coeff = C.Pow(-c, other) assert len(t) == 1, 't' b = -t[0] rv = (coeff, C.Pow(b, other)) elif c is not S.One: coeff = C.Pow(c, other) assert len(t) == 1, 't' b = t[0] rv = (coeff, C.Pow(b, other)) if not rv or terms: return rv else: return C.Mul(*rv)
def _create_evalf_table(): global evalf_table evalf_table = { C.Symbol: evalf_symbol, C.Dummy: evalf_symbol, C.Float: lambda x, prec, options: (x._mpf_, None, prec, None), C.Rational: lambda x, prec, options: (from_rational(x.p, x.q, prec), None, prec, None), C.Integer: lambda x, prec, options: (from_int(x.p, prec), None, prec, None), C.Zero: lambda x, prec, options: (None, None, prec, None), C.One: lambda x, prec, options: (fone, None, prec, None), C.Half: lambda x, prec, options: (fhalf, None, prec, None), C.Pi: lambda x, prec, options: (mpf_pi(prec), None, prec, None), C.Exp1: lambda x, prec, options: (mpf_e(prec), None, prec, None), C.ImaginaryUnit: lambda x, prec, options: (None, fone, None, prec), C.NegativeOne: lambda x, prec, options: (fnone, None, prec, None), C.NaN : lambda x, prec, options: (fnan, None, prec, None), C.exp: lambda x, prec, options: evalf_pow(C.Pow(S.Exp1, x.args[0], evaluate=False), prec, options), C.cos: evalf_trig, C.sin: evalf_trig, C.Add: evalf_add, C.Mul: evalf_mul, C.Pow: evalf_pow, C.log: evalf_log, C.atan: evalf_atan, C.Abs: evalf_abs, C.re: evalf_re, C.im: evalf_im, C.floor: evalf_floor, C.ceiling: evalf_ceiling, C.Integral: evalf_integral, C.Sum: evalf_sum, C.Piecewise: evalf_piecewise, C.bernoulli: evalf_bernoulli, }