Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
from __future__ import print_function, division
from math import log as _log
from .sympify import _sympify from .cache import cacheit from .singleton import S from .expr import Expr from .evalf import PrecisionExhausted from .function import (_coeff_isneg, expand_complex, expand_multinomial, expand_mul) from .logic import fuzzy_bool, fuzzy_not from .compatibility import as_int, range from .evaluate import global_evaluate from sympy.utilities.iterables import sift
from mpmath.libmp import sqrtrem as mpmath_sqrtrem
from math import sqrt as _sqrt
def isqrt(n): """Return the largest integer less than or equal to sqrt(n).""" if n < 17984395633462800708566937239552: return int(_sqrt(n)) return integer_nthroot(int(n), 2)[0]
def integer_nthroot(y, n): """ Return a tuple containing x = floor(y**(1/n)) and a boolean indicating whether the result is exact (that is, whether x**n == y).
Examples ========
>>> from sympy import integer_nthroot >>> integer_nthroot(16, 2) (4, True) >>> integer_nthroot(26, 2) (5, False)
To simply determine if a number is a perfect square, the is_square function should be used:
>>> from sympy.ntheory.primetest import is_square >>> is_square(26) False
See Also ======== sympy.ntheory.primetest.is_square """ raise ValueError("y must be nonnegative") raise ValueError("n must be positive") return y, True # Get initial estimate for Newton's method. Care must be taken to # avoid overflow except OverflowError: exp = _log(y, 2)/n if exp > 53: shift = int(exp - 53) guess = int(2.0**(exp - shift) + 1) << shift else: guess = int(2.0**exp) # Newton iteration xprev, x = -1, guess while 1: t = x**(n - 1) xprev, x = x, ((n - 1)*x + y//t)//n if abs(x - xprev) < 2: break else: # Compensate
class Pow(Expr): """ Defines the expression x**y as "x raised to a power y"
Singleton definitions involving (0, 1, -1, oo, -oo, I, -I):
+--------------+---------+-----------------------------------------------+ | expr | value | reason | +==============+=========+===============================================+ | z**0 | 1 | Although arguments over 0**0 exist, see [2]. | +--------------+---------+-----------------------------------------------+ | z**1 | z | | +--------------+---------+-----------------------------------------------+ | (-oo)**(-1) | 0 | | +--------------+---------+-----------------------------------------------+ | (-1)**-1 | -1 | | +--------------+---------+-----------------------------------------------+ | S.Zero**-1 | zoo | This is not strictly true, as 0**-1 may be | | | | undefined, but is convenient in some contexts | | | | where the base is assumed to be positive. | +--------------+---------+-----------------------------------------------+ | 1**-1 | 1 | | +--------------+---------+-----------------------------------------------+ | oo**-1 | 0 | | +--------------+---------+-----------------------------------------------+ | 0**oo | 0 | Because for all complex numbers z near | | | | 0, z**oo -> 0. | +--------------+---------+-----------------------------------------------+ | 0**-oo | zoo | This is not strictly true, as 0**oo may be | | | | oscillating between positive and negative | | | | values or rotating in the complex plane. | | | | It is convenient, however, when the base | | | | is positive. | +--------------+---------+-----------------------------------------------+ | 1**oo | nan | Because there are various cases where | | 1**-oo | | lim(x(t),t)=1, lim(y(t),t)=oo (or -oo), | | 1**zoo | | but lim( x(t)**y(t), t) != 1. See [3]. | +--------------+---------+-----------------------------------------------+ | (-1)**oo | nan | Because of oscillations in the limit. | | (-1)**(-oo) | | | +--------------+---------+-----------------------------------------------+ | oo**oo | oo | | +--------------+---------+-----------------------------------------------+ | oo**-oo | 0 | | +--------------+---------+-----------------------------------------------+ | (-oo)**oo | nan | | | (-oo)**-oo | | | +--------------+---------+-----------------------------------------------+ | oo**I | nan | oo**e could probably be best thought of as | | (-oo)**I | | the limit of x**e for real x as x tends to | | | | oo. If e is I, then the limit does not exist | | | | and nan is used to indicate that. | +--------------+---------+-----------------------------------------------+ | oo**(1+I) | zoo | If the real part of e is positive, then the | | (-oo)**(1+I) | | limit of abs(x**e) is oo. So the limit value | | | | is zoo. | +--------------+---------+-----------------------------------------------+ | oo**(-1+I) | 0 | If the real part of e is negative, then the | | -oo**(-1+I) | | limit is 0. | +--------------+---------+-----------------------------------------------+
Because symbolic computations are more flexible that floating point calculations and we prefer to never return an incorrect answer, we choose not to conform to all IEEE 754 conventions. This helps us avoid extra test-case code in the calculation of limits.
See Also ========
sympy.core.numbers.Infinity sympy.core.numbers.NegativeInfinity sympy.core.numbers.NaN
References ==========
.. [1] http://en.wikipedia.org/wiki/Exponentiation .. [2] http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero .. [3] http://en.wikipedia.org/wiki/Indeterminate_forms
""" is_Pow = True
__slots__ = ['is_commutative']
@cacheit def __new__(cls, b, e, evaluate=None):
# Only perform autosimplification if exponent or base is a Symbol or number e.is_integer and _coeff_isneg(b): return S.NaN return S.NaN else: # recognize base as E s = sign(im(b)) if s.is_Number and s and den == \ log(-factor_terms(b, sign=False)) + s*S.ImaginaryUnit*S.Pi: return S.Exp1**(c*numer(ex))
@property def base(self):
@property def exp(self):
@classmethod def class_key(cls): return 3, 2, cls.__name__
def _eval_refine(self, assumptions): from sympy.assumptions.ask import ask, Q b, e = self.as_base_exp() if ask(Q.integer(e), assumptions) and _coeff_isneg(b): if ask(Q.even(e), assumptions): return Pow(-b, e) elif ask(Q.odd(e), assumptions): return -Pow(-b, e)
def _eval_power(self, other): return (b**e)**other # let __new__ handle it
s = 1 # helper functions =========================== """Return True if the exponent has a literal 2 as the denominator, else None.""" return True """Return ``e`` evaluated to a Number with 2 significant digits, else None.""" try: rv = e.evalf(2, strict=True) if rv.is_Number: return rv except PrecisionExhausted: pass # =================================================== # we need _half(other) with constant floor or # floor(S.Half - e*arg(b)/2/pi) == 0
# handle -1 as special case # floor arg. is 1/2 + arg(b)/2/pi return S.NegativeOne**other*Pow(-b, e*other) return Pow(b.conjugate()/Abs(b)**2, other) b = abs(im(b))*S.ImaginaryUnit
s = 1 # floor = 0 s = 1 # floor = 0 S.Half - e*arg(b)/(2*S.Pi))) s = sign(s) else: else: # e.is_real is False requires: # _half(other) with constant floor or # floor(S.Half - im(e*log(b))/2/pi) == 0 try: s = exp(2*S.ImaginaryUnit*S.Pi*other* floor(S.Half - im(e*log(b))/2/S.Pi)) # be careful to test that s is -1 or 1 b/c sign(I) == I: # so check that s is real if s.is_real and _n2(sign(s) - s) == 0: s = sign(s) else: s = None except PrecisionExhausted: s = None
def _eval_is_even(self):
def _eval_is_positive(self): if self.base.is_nonnegative: return True return True return False if self.exp.is_odd: return False if self.exp.is_integer: m = self.exp % 4 if m.is_zero: return True if m.is_integer and m.is_zero is False: return False if self.exp.is_imaginary: return log(self.base).is_imaginary
def _eval_is_negative(self): return True if self.exp.is_even: return False
def _eval_is_zero(self): if self.exp.is_positive: return True elif self.exp.is_nonpositive: return False if (1 - abs(self.base)).is_positive: return self.exp.is_positive elif (1 - abs(self.base)).is_negative: return self.exp.is_negative else: # when self.base.is_zero is None
def _eval_is_integer(self): return False # rat**nonneg return True return False
def _eval_is_real(self): return self.exp.is_imaginary return else: if self.exp.is_even: return True elif self.exp.is_odd: return False return True c, a = self.exp.as_coeff_Add() if c and c.is_Integer: return Mul( self.base**c, self.base**a, evaluate=False).is_real if self.base is S.NegativeOne: return True c = self.exp.coeff(S.ImaginaryUnit) if c: ok = (c*log(self.base)/S.Pi).is_Integer if ok is not None: return ok
def _eval_is_complex(self):
def _eval_is_imaginary(self): odd = self.exp.is_odd if odd is not None: return odd return
imlog = log(self.base).is_imaginary if imlog is not None: return False # I**i -> real; (2*I)**i -> complex ==> not imaginary
else: else:
def _eval_is_odd(self): return True
def _eval_is_finite(self): return False return True
def _eval_is_prime(self): return self.base.is_prime
""" a Power will be non-prime only if both base and exponent are greater than 1 """ if (self.base-1).is_positive or (self.exp-1).is_positive: return False
def _eval_is_polar(self):
def _eval_subs(self, old, new): """Return bool, pow where, if bool is True, then the exponent of Pow `old` will combine with `pow` so the substitution is valid, otherwise bool will be False,
cti are the coefficient and terms of an exponent of self or old In this _eval_subs routine a change like (b**(2*x)).subs(b**x, y) will give y**2 since (b**x)**2 == b**(2*x); if that equality does not hold then the substitution should not occur so `bool` will be False. """ except ValueError: combines = Pow._eval_power( Pow(*old.as_base_exp(), evaluate=False), pow) is not None
# issue 10829: (4**x - 3*y + 2).subs(2**x, y) -> y**2 - 3*y + 2 l = log(self.base, old.base) if l.is_Number: return Pow(new, l)
# issue 5180: (x**(6*y)).subs(x**(3*y),z)->z**2 else: # b**(6*x+a).subs(b**(3*x), y) -> y**2 * b**a # exp(exp(x) + exp(x**2)).subs(exp(exp(x)), w) -> w * exp(exp(x**2))
Symbol, as_Add=False) return self.func(new, pow) # (2**x).subs(exp(x*log(2)), z) -> z
def as_base_exp(self): """Return base and exp of self.
If base is 1/Integer, then return Integer, -exp. If this extra processing is not needed, the base and exp properties will give the raw arguments
Examples ========
>>> from sympy import Pow, S >>> p = Pow(S.Half, 2, evaluate=False) >>> p.as_base_exp() (2, -2) >>> p.args (1/2, 2)
"""
def _eval_adjoint(self): from sympy.functions.elementary.complexes import adjoint i, p = self.exp.is_integer, self.base.is_positive if i: return adjoint(self.base)**self.exp if p: return self.base**adjoint(self.exp) if i is False and p is False: expanded = expand_complex(self) if expanded != self: return adjoint(expanded)
def _eval_conjugate(self):
def _eval_transpose(self): from sympy.functions.elementary.complexes import transpose i, p = self.exp.is_integer, self.base.is_complex if p: return self.base**self.exp if i: return transpose(self.base)**self.exp if i is False and p is False: expanded = expand_complex(self) if expanded != self: return transpose(expanded)
def _eval_expand_power_exp(self, **hints): """a**(n+m) -> a**n*a**m"""
def _eval_expand_power_base(self, **hints): """(a*b)**n -> a**n * b**n"""
# expand each term - this is top-level-only # expansion but we have to watch out for things # that don't have an _eval_expand method nc = [i._eval_expand_power_base(**hints) if hasattr(i, '_eval_expand_power_base') else i for i in nc]
if e.is_Integer: if e.is_positive: rv = Mul(*nc*e) else: rv = 1/Mul(*nc*-e) if cargs: rv *= Mul(*cargs)**e return rv
if not cargs: return self.func(Mul(*nc), e, evaluate=False)
nc = [Mul(*nc)]
# sift the commutative bases return True pass elif i == 2: if neg: nonn = -neg.pop() if nonn is not S.One: nonneg.append(nonn) else: neg.append(S.NegativeOne) else: if neg: nonn = -neg.pop() if nonn is not S.One: nonneg.append(nonn) else: neg.append(S.NegativeOne) other.append(I)
# bring out the bases that can be separated from the base
# treat all commutatives the same and put nc in other cargs = nonneg + neg + other other = nc else: # this is just like what is happening automatically, except # that now we are doing it for an arbitrary exponent for which # no automatic expansion is done
# handle negatives by making them all positive and putting # the residual -1 in other other.append(o) else: else:
def _eval_expand_multinomial(self, **hints): """(a+b+..) ** n -> a**n + n*a**(n-1)*b + .., n is nonzero integer"""
else: radical, result = self.func(base, exp - n), []
expanded_base_n = self.func(base, n) if expanded_base_n.is_Pow: expanded_base_n = \ expanded_base_n._eval_expand_multinomial() for term in Add.make_args(expanded_base_n): result.append(term*radical)
return Add(*result)
order_terms.append(b) else:
# (f(x) + O(x^n))^m -> f(x)^m + m*f(x)^{m-1} *O(x^n) f = Add(*other_terms) o = Add(*order_terms)
if n == 2: return expand_multinomial(f**n, deep=False) + n*f*o else: g = expand_multinomial(f**(n - 1), deep=False) return expand_mul(f*g, deep=False) + n*g*o
# Efficiently expand expressions of the form (a + b*I)**n # where 'a' and 'b' are real numbers and 'n' is integer.
if not a.is_Integer: if not b.is_Integer: k = self.func(a.q * b.q, n) a, b = a.p*b.q, a.q*b.p else: k = self.func(a.q, n) a, b = a.p, a.q*b elif not b.is_Integer: k = self.func(b.q, n) a, b = a*b.q, b.p else: k = 1
a, b, c, d = int(a), int(b), 1, 0
while n: if n & 1: c, d = a*c - b*d, b*c + a*d n -= 1 a, b = a*a - b*b, 2*a*b n //= 2
I = S.ImaginaryUnit
if k == 1: return c + I*d else: return Integer(c)/k + I*d/k
# (x+y)**3 -> x**3 + 3*x**2*y + 3*x*y**2 + y**3 # in this particular example: # p = [x,y]; n = 3 # so now it's easy to get the correct result -- we get the # coefficients first: # in our example: {(3, 0): 1, (1, 2): 3, (0, 3): 1, (2, 1): 3} # and now construct the expression. else: if n == 2: return Add(*[f*g for f in base.args for g in base.args]) else: multi = (base**(n - 1))._eval_expand_multinomial() if multi.is_Add: return Add(*[f*g for f in base.args for g in multi.args]) else: # XXX can this ever happen if base was an Add? return Add(*[f*multi for f in base.args]) abs(exp.p) > exp.q): # a + b a b # n --> n n , where n, a, b are Numbers
else:
else:
def as_real_imag(self, deep=True, **hints):
if re.is_Number and im.is_Number: # We can be more efficient in this case expr = expand_multinomial(self.base**exp) return expr.as_real_imag()
expr = poly( (a + b)**exp) # a = re, b = im; expr = (a + b*I)**exp else: # We can be more efficient in this case
# Terms with even b powers will be real # Terms with odd b powers will be imaginary
im_part1.subs({a: re, b: im}) + im_part3.subs({a: re, b: -im}))
return self, S.Zero
# XXX: This is not totally correct since for x**(p/q) with # x being imaginary there are actually q roots, but # only a single one is returned from here.
else:
else: else: return (re(self), im(self))
def _eval_derivative(self, s):
def _eval_evalf(self, prec):
def _eval_is_polynomial(self, syms):
self.exp.is_Integer and (self.exp >= 0)) else:
def _eval_is_rational(self): # we didn't check that e is not an Integer # because Rational**Integer autosimplifies return True
def _eval_is_algebraic(self): return True if ((fuzzy_not(self.base.is_zero) and fuzzy_not((self.base - 1).is_zero)) or self.base.is_integer is False or self.base.is_irrational): return self.exp.is_rational
def _eval_is_rational_function(self, syms): if self.exp.has(*syms): return False
if self.base.has(*syms): return self.base._eval_is_rational_function(syms) and \ self.exp.is_Integer else: return True
def _eval_is_algebraic_expr(self, syms): if self.exp.has(*syms): return False
if self.base.has(*syms): return self.base._eval_is_algebraic_expr(syms) and \ self.exp.is_Rational else: return True
def as_numer_denom(self): return self, S.One # this should be the same as ExpBase.as_numer_denom wrt # exponent handling # the denominator cannot be separated from the numerator if # its sign is unknown unless the exponent is an integer, e.g. # sqrt(a/b) != sqrt(a)/sqrt(b) when a=1 and b=-1. But if the # denominator is negative the numerator and denominator can # be negated and the denominator (now positive) separated. n, d = -n, -d n = base d = S.One
def matches(self, expr, repl_dict={}, old=False):
# special case, pattern = 1 and expr.exp can match to 0
# make sure the expression to be matched is an Expr return None
# special case number if e.is_rational: return sb.matches(b**(e/se), repl_dict) return sb.matches(expr**(1/se), repl_dict)
return None
return Expr.matches(self, expr, repl_dict)
def _eval_nseries(self, x, n, logx): # NOTE! This function is an important part of the gruntz algorithm # for computing limits. It has to return a generalized power # series with coefficients in C(log, log(x)). In more detail: # It has to return an expression # c_0*x**e_0 + c_1*x**e_1 + ... (finitely many terms) # where e_i are numbers (not necessarily integers) and c_i are # expressions involving only numbers, the log function, and log(x). # positive integer powers are easy to expand, e.g.: # sin(x)**4 = (x-x**3/3+...)**4 = ... logx=logx), e), deep=False) # this is also easy to expand using the formula: # 1/(1 + x) = 1 - x + x**2 - x**3 ... # so we need to rewrite base to the form "1+x"
else: cf = 1
# express "rest" as: rest = 1 + k*x**l + ... + O(x**n)
return 1/prefactor + rest/prefactor + O(x**n, x)
pass l = l.evalf() # if prefactor == w**4 + x**2*w**4 + 2*x*w**4, we need to # factor the w**4 out using collect: else: raise NotImplementedError() else: raise NotImplementedError()
if cf < 0: cf = S.One/abs(cf)
try: dn = Order(1/prefactor, x).getn() if dn and dn < 0: pass else: dn = 0 except NotImplementedError: dn = 0
terms = [1/prefactor] for m in range(1, ceiling((n - dn + 1)/l*cf)): new_term = terms[-1]*(-rest) if new_term.is_Pow: new_term = new_term._eval_expand_multinomial( deep=False) else: new_term = expand_mul(new_term, deep=False) terms.append(new_term) terms.append(O(x**n, x)) return powsimp(Add(*terms), deep=True, combine='exp') else: # negative powers are rewritten to the cases above, for # example: # sin(x)**(-4) = 1/( sin(x)**4) = ... # and expand the denominator: # now we have a type 1/f(x), that we know how to expand return (1/denominator)._eval_nseries(x, n=n, logx=logx)
if e.has(Symbol): return exp(e*log(b))._eval_nseries(x, n=n, logx=logx)
# see if the base is as simple as possible bx = b while bx.is_Pow and bx.exp.is_Rational: bx = bx.base if bx == x: return self
# work for b(x)**e where e is not an Integer and does not contain x # and hopefully has no other symbols
def e2int(e): """return the integer value (if possible) of e and a flag indicating whether it is bounded or not.""" n = e.limit(x, 0) infinite = n.is_infinite if not infinite: # XXX was int or floor intended? int used to behave like floor # so int(-Rational(1, 2)) returned -1 rather than int's 0 try: n = int(n) except TypeError: #well, the n is something more complicated (like 1+log(2)) try: n = int(n.evalf()) + 1 # XXX why is 1 being added? except TypeError: pass # hope that base allows this to be resolved n = _sympify(n) return n, infinite
order = O(x**n, x) ei, infinite = e2int(e) b0 = b.limit(x, 0) if infinite and (b0 is S.One or b0.has(Symbol)): # XXX what order if b0 is S.One: resid = (b - 1) if resid.is_positive: return S.Infinity elif resid.is_negative: return S.Zero raise ValueError('cannot determine sign of %s' % resid)
return b0**ei
if (b0 is S.Zero or b0.is_infinite): if infinite is not False: return b0**e # XXX what order
if not ei.is_number: # if not, how will we proceed? raise ValueError( 'expecting numerical exponent but got %s' % ei)
nuse = n - ei
if e.is_real and e.is_positive: lt = b.as_leading_term(x)
# Try to correct nuse (= m) guess from: # (lt + rest + O(x**m))**e = # lt**e*(1 + rest/lt + O(x**m)/lt)**e = # lt**e + ... + O(x**m)*lt**(e - 1) = ... + O(x**n) try: cf = Order(lt, x).getn() nuse = ceiling(n - cf*(e - 1)) except NotImplementedError: pass
bs = b._eval_nseries(x, n=nuse, logx=logx) terms = bs.removeO() if terms.is_Add: bs = terms lt = terms.as_leading_term(x)
# bs -> lt + rest -> lt*(1 + (bs/lt - 1)) return ((self.func(lt, e) * self.func((bs/lt).expand(), e).nseries( x, n=nuse, logx=logx)).expand() + order)
if bs.is_Add: from sympy import O # So, bs + O() == terms c = Dummy('c') res = [] for arg in bs.args: if arg.is_Order: arg = c*arg.expr res.append(arg) bs = Add(*res) rv = (bs**e).series(x).subs(c, O(1, x)) rv += order return rv
rv = bs**e if terms != bs: rv += order return rv
# either b0 is bounded but neither 1 nor 0 or e is infinite # b -> b0 + (b-b0) -> b0 * (1 + (b/b0-1)) o2 = order*(b0**-e) z = (b/b0 - 1) o = O(z, x) if o is S.Zero or o2 is S.Zero: infinite = True else: if o.expr.is_number: e2 = log(o2.expr*x)/log(x) else: e2 = log(o2.expr)/log(o.expr) n, infinite = e2int(e2) if infinite: # requested accuracy gives infinite series, # order is probably non-polynomial e.g. O(exp(-1/x), x). r = 1 + z else: l = [] g = None for i in range(n + 2): g = self._taylor_term(i, z, g) g = g.nseries(x, n=n, logx=logx) l.append(g) r = Add(*l) return expand_mul(r*b0**e) + order
def _eval_as_leading_term(self, x): return exp(self.exp * log(self.base)).as_leading_term(x)
@cacheit def _taylor_term(self, n, x, *previous_terms): # of (1+x)**e from sympy import binomial return binomial(self.exp, n) * self.func(x, n)
def _sage_(self): return self.args[0]._sage_()**self.args[1]._sage_()
def as_content_primitive(self, radical=False, clear=True): """Return the tuple (R, self/R) where R is the positive Rational extracted from self.
Examples ========
>>> from sympy import sqrt >>> sqrt(4 + 4*sqrt(2)).as_content_primitive() (2, sqrt(1 + sqrt(2))) >>> sqrt(3 + 3*sqrt(2)).as_content_primitive() (1, sqrt(3)*sqrt(1 + sqrt(2)))
>>> from sympy import expand_power_base, powsimp, Mul >>> from sympy.abc import x, y
>>> ((2*x + 2)**2).as_content_primitive() (4, (x + 1)**2) >>> (4**((1 + y)/2)).as_content_primitive() (2, 4**(y/2)) >>> (3**((1 + y)/2)).as_content_primitive() (1, 3**((y + 1)/2)) >>> (3**((5 + y)/2)).as_content_primitive() (9, 3**((y + 1)/2)) >>> eq = 3**(2 + 2*x) >>> powsimp(eq) == eq True >>> eq.as_content_primitive() (9, 3**(2*x)) >>> powsimp(Mul(*_)) 3**(2*x + 2)
>>> eq = (2 + 2*x)**y >>> s = expand_power_base(eq); s.is_Mul, s (False, (2*x + 2)**y) >>> eq.as_content_primitive() (1, (2*(x + 1))**y) >>> s = expand_power_base(_[1]); s.is_Mul, s (True, 2**y*(x + 1)**y)
See docstring of Expr.as_content_primitive for more examples. """
#e #= ce*pe #= ce*(h + t) #= ce*h + ce*t #=> self #= b**(ce*h)*b**(ce*t) #= b**(cehp/cehq)*b**(ce*t) #= b**(iceh+r/cehq)*b**(ce*t) #= b**(iceh)*b**(r/cehq)*b**(ce*t) #= b**(iceh)*b**(ce*t + r/cehq) # b**e = (h*t)**e = h**e*t**e = c*m*t**e # return the following, not return c, m*Pow(t, e) # which would change Pow into Mul; we let sympy # decide what to do by using the unevaluated Mul, e.g # should it stay as sqrt(2 + 2*sqrt(5)) or become # sqrt(2)*sqrt(1 + sqrt(5))
def is_constant(self, *wrt, **flags): expr = expr.simplify() new = b**e if new != expr: return new.is_constant() if econ: return True bz = b.equals(0) if bz is False: return False return None
def _eval_difference_delta(self, n, step): b, e = self.args if e.has(n) and not b.has(n): new_e = e.subs(n, n + step) return (b**(new_e - e) - 1) * self
from .add import Add from .numbers import Integer from .mul import Mul, _keep_coeff from .symbol import Symbol, Dummy, symbols |