[docs]classPow(Expr):is_Pow=True__slots__=['is_commutative']@cacheitdef__new__(cls,b,e,evaluate=True):fromsympy.functions.elementary.exponentialimportexp_polar# don't optimize "if e==0; return 1" here; it's better to handle that# in the calling routine so this doesn't get calledb=_sympify(b)e=_sympify(e)ifevaluate:ifeisS.Zero:returnS.OneelifeisS.One:returnbelifS.NaNin(b,e):ifbisS.One:# already handled e == 0 abovereturnS.OnereturnS.NaNelse:# recognize base as Eifnote.is_AtomandbisnotS.Exp1andb.funcisnotexp_polar:fromsympyimportnumer,denom,log,sign,im,factor_termsc,ex=factor_terms(e,sign=False).as_coeff_Mul()den=denom(ex)ifden.funcislogandden.args[0]==b:returnS.Exp1**(c*numer(ex))elifden.is_Add:s=sign(im(b))ifs.is_Numberandsandden== \
log(-factor_terms(b,sign=False))+s*S.ImaginaryUnit*S.Pi:returnS.Exp1**(c*numer(ex))obj=b._eval_power(e)ifobjisnotNone:returnobjobj=Expr.__new__(cls,b,e)obj.is_commutative=(b.is_commutativeande.is_commutative)returnobj@propertydefbase(self):returnself._args[0]@propertydefexp(self):returnself._args[1]@classmethoddefclass_key(cls):return3,2,cls.__name__def_eval_power(self,other):fromsympy.functions.elementary.exponentialimportlogb,e=self.as_base_exp()b_nneg=b.is_nonnegativeifb.is_realandnotb_nnegande.is_even:b=abs(b)b_nneg=True# Special case for when b is nan. See pull req 1714 for detailsifbisS.NaN:smallarg=(abs(e)<=S.Zero)else:smallarg=(abs(e)<=abs(S.Pi/log(b)))if(other.is_Rationalandother.q==2ande.is_realisFalseandsmallargisFalse):return-Pow(b,e*other)if(other.is_integerore.is_realand(b_nnegorabs(e)<1)ore.is_realisFalseandsmallargisTrueorb.is_polar):returnPow(b,e*other)def_eval_is_even(self):ifself.exp.is_integerandself.exp.is_positive:returnself.base.is_evendef_eval_is_positive(self):ifself.base.is_positive:ifself.exp.is_real:returnTrueelifself.base.is_negative:ifself.exp.is_even:returnTrueifself.exp.is_odd:returnFalseelifself.base.is_nonpositive:ifself.exp.is_odd:returnFalsedef_eval_is_negative(self):ifself.base.is_negative:ifself.exp.is_odd:returnTrueifself.exp.is_even:returnFalseelifself.base.is_positive:ifself.exp.is_real:returnFalseelifself.base.is_nonnegative:ifself.exp.is_real:returnFalseelifself.base.is_nonpositive:ifself.exp.is_even:returnFalseelifself.base.is_real:ifself.exp.is_even:returnFalsedef_eval_is_integer(self):b,e=self.argsc1=b.is_integerc2=e.is_integerifc1isNoneorc2isNone:returnNoneifnotc1ande.is_nonnegative:# rat**nonnegreturnFalseifc1andc2:# int**intife.is_nonnegativeore.is_positive:returnTrueifself.exp.is_negative:returnFalseifc1ande.is_negativeande.is_bounded:# int**negreturnFalseifb.is_Numberande.is_Number:# int**nonneg or rat**?check=Pow(*self.args)returncheck.is_Integerdef_eval_is_real(self):real_b=self.base.is_realifreal_bisNone:returnreal_e=self.exp.is_realifreal_eisNone:returnifreal_bandreal_e:ifself.base.is_positive:returnTrueelse:# negative or zero (or positive)ifself.exp.is_integer:returnTrueelifself.base.is_negative:ifself.exp.is_Rational:returnFalseim_b=self.base.is_imaginaryim_e=self.exp.is_imaginaryifim_b:ifself.exp.is_integer:ifself.exp.is_even:returnTrueelifself.exp.is_odd:returnFalseelif(self.expin[S.ImaginaryUnit,-S.ImaginaryUnit]andself.basein[S.ImaginaryUnit,-S.ImaginaryUnit]):returnTrueelifself.exp.is_Add:c,a=self.exp.as_coeff_Add()ifcandc.is_Integer:returnC.Mul(self.base**c,self.base**a,evaluate=False).is_realifreal_bandim_e:ifself.baseisS.NegativeOne:returnTruec=self.exp.coeff(S.ImaginaryUnit)ifc:ok=(c*C.log(self.base)/S.Pi).is_IntegerifokisnotNone:returnokdef_eval_is_odd(self):ifself.exp.is_integer:ifself.exp.is_positive:returnself.base.is_oddelifself.exp.is_nonnegativeandself.base.is_odd:returnTruedef_eval_is_bounded(self):ifself.exp.is_negative:ifself.base.is_infinitesimal:returnFalseifself.base.is_unbounded:returnTruec1=self.base.is_boundedifc1isNone:returnc2=self.exp.is_boundedifc2isNone:returnifc1andc2:ifself.exp.is_nonnegativeorself.base.is_nonzero:returnTruedef_eval_is_polar(self):returnself.base.is_polardef_eval_subs(self,old,new):ifold.funcisself.funcandself.base==old.base:coeff1,terms1=self.exp.as_independent(C.Symbol,as_Add=False)coeff2,terms2=old.exp.as_independent(C.Symbol,as_Add=False)ifterms1==terms2:pow=coeff1/coeff2ok=False# True if int(pow) == pow OR self.base.is_positivetry:pow=as_int(pow)ok=TrueexceptValueError:ok=self.base.is_positiveifok:# issue 2081returnPow(new,pow)# (x**(6*y)).subs(x**(3*y),z)->z**2ifold.funcisC.expandself.exp.is_realandself.base.is_positive:coeff1,terms1=old.args[0].as_independent(C.Symbol,as_Add=False)# we can only do this when the base is positive AND the exponent# is realcoeff2,terms2=(self.exp*C.log(self.base)).as_independent(C.Symbol,as_Add=False)ifterms1==terms2:pow=coeff1/coeff2ifpow==int(pow)orself.base.is_positive:returnPow(new,pow)# (2**x).subs(exp(x*log(2)), z) -> z

def_eval_adjoint(self):fromsympy.functions.elementary.complexesimportadjointi,p=self.exp.is_integer,self.base.is_positiveifi:returnadjoint(self.base)**self.expifp:returnself.base**adjoint(self.exp)ifiisFalseandpisFalse:expanded=expand_complex(self)ifexpanded!=self:returnadjoint(expanded)def_eval_conjugate(self):fromsympy.functions.elementary.complexesimportconjugateasci,p=self.exp.is_integer,self.base.is_positiveifi:returnc(self.base)**self.expifp:returnself.base**c(self.exp)ifiisFalseandpisFalse:expanded=expand_complex(self)ifexpanded!=self:returnc(expanded)def_eval_transpose(self):fromsympy.functions.elementary.complexesimporttransposei,p=self.exp.is_integer,self.base.is_complexifp:returnself.base**self.expifi:returntranspose(self.base)**self.expifiisFalseandpisFalse:expanded=expand_complex(self)ifexpanded!=self:returntranspose(expanded)def_eval_expand_power_exp(self,**hints):"""a**(n+m) -> a**n*a**m"""b=self.basee=self.expife.is_Addande.is_commutative:expr=[]forxine.args:expr.append(Pow(self.base,x))returnMul(*expr)returnPow(b,e)def_eval_expand_power_base(self,**hints):"""(a*b)**n -> a**n * b**n"""force=hints.get('force',False)b=self.basee=self.expifnotb.is_Mul:returnselfcargs,nc=b.args_cnc(split_1=False)# expand each term - this is top-level-only# expansion but we have to watch out for things# that don't have an _eval_expand methodifnc:nc=[i._eval_expand_power_base(**hints)ifhasattr(i,'_eval_expand_power_base')elseiforiinnc]ife.is_Integer:ife.is_positive:rv=Mul(*nc*e)else:rv=1/Mul(*nc*-e)ifcargs:rv*=Mul(*cargs)**ereturnrvifnotcargs:returnPow(Mul(*nc),e,evaluate=False)nc=[Mul(*nc)]# sift the commutative basesdefpred(x):ifxisS.ImaginaryUnit:returnS.ImaginaryUnitpolar=x.is_polarifpolar:returnTrueifpolarisNone:returnfuzzy_bool(x.is_nonnegative)sifted=sift(cargs,pred)nonneg=sifted[True]other=sifted[None]neg=sifted[False]imag=sifted[S.ImaginaryUnit]ifimag:I=S.ImaginaryUniti=len(imag)%4ifi==0:passelifi==1:other.append(I)elifi==2:ifneg:nonn=-neg.pop()ifnonnisnotS.One:nonneg.append(nonn)else:neg.append(S.NegativeOne)else:ifneg:nonn=-neg.pop()ifnonnisnotS.One:nonneg.append(nonn)else:neg.append(S.NegativeOne)other.append(I)delimag# bring out the bases that can be separated from the baseifforceore.is_integer:# treat all commutatives the same and put nc in othercargs=nonneg+neg+otherother=ncelse:# 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 doneassertnote.is_Integer# handle negatives by making them all positive and putting# the residual -1 in otheriflen(neg)>1:o=S.Oneifnototherandneg[0].is_Number:o*=neg.pop(0)iflen(neg)%2:o=-oforninneg:nonneg.append(-n)ifoisnotS.One:other.append(o)elifnegandother:ifneg[0].is_Numberandneg[0]isnotS.NegativeOne:other.append(S.NegativeOne)nonneg.append(-neg[0])else:other.extend(neg)else:other.extend(neg)delnegcargs=nonnegother+=ncrv=S.Oneifcargs:rv*=Mul(*[Pow(b,e,evaluate=False)forbincargs])ifother:rv*=Pow(Mul(*other),e,evaluate=False)returnrvdef_eval_expand_multinomial(self,**hints):"""(a+b+..) ** n -> a**n + n*a**(n-1)*b + .., n is nonzero integer"""base,exp=self.argsresult=selfifexp.is_Rationalandexp.p>0andbase.is_Add:ifnotexp.is_Integer:n=Integer(exp.p//exp.q)ifnotn:returnresultelse:radical,result=Pow(base,exp-n),[]expanded_base_n=Pow(base,n)ifexpanded_base_n.is_Pow:expanded_base_n= \
expanded_base_n._eval_expand_multinomial()forterminAdd.make_args(expanded_base_n):result.append(term*radical)returnAdd(*result)n=int(exp)ifbase.is_commutative:order_terms,other_terms=[],[]forbinbase.args:ifb.is_Order:order_terms.append(b)else:other_terms.append(b)iforder_terms:# (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)ifn==2:returnexpand_multinomial(f**n,deep=False)+n*f*oelse:g=expand_multinomial(f**(n-1),deep=False)returnexpand_mul(f*g,deep=False)+n*g*oifbase.is_number:# Efficiently expand expressions of the form (a + b*I)**n# where 'a' and 'b' are real numbers and 'n' is integer.a,b=base.as_real_imag()ifa.is_Rationalandb.is_Rational:ifnota.is_Integer:ifnotb.is_Integer:k=Pow(a.q*b.q,n)a,b=a.p*b.q,a.q*b.pelse:k=Pow(a.q,n)a,b=a.p,a.q*belifnotb.is_Integer:k=Pow(b.q,n)a,b=a*b.q,b.pelse:k=1a,b,c,d=int(a),int(b),1,0whilen:ifn&1:c,d=a*c-b*d,b*c+a*dn-=1a,b=a*a-b*b,2*a*bn//=2I=S.ImaginaryUnitifk==1:returnc+I*delse:returnInteger(c)/k+I*d/kp=other_terms# (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:fromsympyimportmultinomial_coefficientsfromsympy.polys.polyutilsimportbasic_from_dictexpansion_dict=multinomial_coefficients(len(p),n)# in our example: {(3, 0): 1, (1, 2): 3, (0, 3): 1, (2, 1): 3}# and now construct the expression.returnbasic_from_dict(expansion_dict,*p)else:ifn==2:returnAdd(*[f*gforfinbase.argsforginbase.args])else:multi=(base**(n-1))._eval_expand_multinomial()ifmulti.is_Add:returnAdd(*[f*gforfinbase.argsforginmulti.args])else:# XXX can this ever happen if base was an Add?returnAdd(*[f*multiforfinbase.args])elif(exp.is_Rationalandexp.p<0andbase.is_Addandabs(exp.p)>exp.q):return1/Pow(base,-exp)._eval_expand_multinomial()elifexp.is_Addandbase.is_Number:# a + b a b# n --> n n , where n, a, b are Numberscoeff,tail=S.One,S.Zeroforterminexp.args:ifterm.is_Number:coeff*=Pow(base,term)else:tail+=termreturncoeff*Pow(base,tail)else:returnresultdefas_real_imag(self,deep=True,**hints):fromsympy.polys.polytoolsimportpolyifself.exp.is_Integer:exp=self.expre,im=self.base.as_real_imag(deep=deep)ifnotim:returnself,S.Zeroa,b=symbols('a b',cls=Dummy)ifexp>=0:ifre.is_Numberandim.is_Number:# We can be more efficient in this caseexpr=expand_multinomial(self.base**exp)returnexpr.as_real_imag()expr=poly((a+b)**exp)# a = re, b = im; expr = (a + b*I)**expelse:mag=re**2+im**2re,im=re/mag,-im/magifre.is_Numberandim.is_Number:# We can be more efficient in this caseexpr=expand_multinomial((re+im*S.ImaginaryUnit)**-exp)returnexpr.as_real_imag()expr=poly((a+b)**-exp)# Terms with even b powers will be realr=[iforiinexpr.terms()ifnoti[0][1]%2]re_part=Add(*[cc*a**aa*b**bbfor(aa,bb),ccinr])# Terms with odd b powers will be imaginaryr=[iforiinexpr.terms()ifi[0][1]%4==1]im_part1=Add(*[cc*a**aa*b**bbfor(aa,bb),ccinr])r=[iforiinexpr.terms()ifi[0][1]%4==3]im_part3=Add(*[cc*a**aa*b**bbfor(aa,bb),ccinr])return(re_part.subs({a:re,b:S.ImaginaryUnit*im}),im_part1.subs({a:re,b:im})+im_part3.subs({a:re,b:-im}))elifself.exp.is_Rational:# NOTE: 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.re,im=self.base.as_real_imag(deep=deep)r=Pow(Pow(re,2)+Pow(im,2),S.Half)t=C.atan2(im,re)rp,tp=Pow(r,self.exp),t*self.expreturn(rp*C.cos(tp),rp*C.sin(tp))else:ifdeep:hints['complex']=Falseexpanded=self.expand(deep,**hints)ifhints.get('ignore')==expanded:returnNoneelse:return(C.re(expanded),C.im(expanded))else:return(C.re(self),C.im(self))def_eval_derivative(self,s):dbase=self.base.diff(s)dexp=self.exp.diff(s)returnself*(dexp*C.log(self.base)+dbase*self.exp/self.base)def_eval_evalf(self,prec):base,exp=self.as_base_exp()base=base._evalf(prec)ifnotexp.is_Integer:exp=exp._evalf(prec)ifexp<0andbase.is_numberandbase.is_realisFalse:base=base.conjugate()/(base*base.conjugate())._evalf(prec)exp=-expreturnPow(base,exp).expand()returnPow(base,exp)def_eval_is_polynomial(self,syms):ifself.exp.has(*syms):returnFalseifself.base.has(*syms):returnself.base._eval_is_polynomial(syms)and \
self.exp.is_Integerand \
self.exp>=0else:returnTruedef_eval_is_rational(self):p=self.func(*self.as_base_exp())# in case it's unevaluatedifnotp.is_Pow:returnp.is_rationalb,e=p.as_base_exp()ife.is_Rationalandb.is_Rational:# we didn't check that e is not an Integer# because Rational**Integer autosimplifiesreturnFalseife.is_integer:returnb.is_rationaldef_eval_is_rational_function(self,syms):ifself.exp.has(*syms):returnFalseifself.base.has(*syms):returnself.base._eval_is_rational_function(syms)and \
self.exp.is_Integerelse:returnTruedef_eval_is_algebraic_expr(self,syms):ifself.exp.has(*syms):returnFalseifself.base.has(*syms):returnself.base._eval_is_algebraic_expr(syms)and \
self.exp.is_Rationalelse:returnTruedefas_numer_denom(self):ifnotself.is_commutative:returnself,S.Onebase,exp=self.as_base_exp()n,d=base.as_numer_denom()# this should be the same as ExpBase.as_numer_denom wrt# exponent handlingneg_exp=exp.is_negativeifnotneg_expandnot(-exp).is_negative:neg_exp=_coeff_isneg(exp)int_exp=exp.is_integer# 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.ifnot(d.is_realorint_exp):n=based=S.Onednonpos=d.is_nonpositiveifdnonpos:n,d=-n,-delifdnonposisNoneandnotint_exp:n=based=S.Oneifneg_exp:n,d=d,nexp=-expreturnPow(n,exp),Pow(d,exp)defmatches(self,expr,repl_dict={},old=False):expr=_sympify(expr)# special case, pattern = 1 and expr.exp can match to 0ifexprisS.One:d=repl_dict.copy()d=self.exp.matches(S.Zero,d)ifdisnotNone:returndb,e=expr.as_base_exp()# special case numbersb,se=self.as_base_exp()ifsb.is_Symbolandse.is_Integerandexpr:ife.is_rational:returnsb.matches(b**(e/se),repl_dict)returnsb.matches(expr**(1/se),repl_dict)d=repl_dict.copy()d=self.base.matches(b,d)ifdisNone:returnNoned=self.exp.xreplace(d).matches(e,d)ifdisNone:returnExpr.matches(self,expr,repl_dict)returnddef_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).fromsympyimportpowsimp,collect,exp,log,O,ceilingb,e=self.argsife.is_Integer:ife>0:# positive integer powers are easy to expand, e.g.:# sin(x)**4 = (x-x**3/3+...)**4 = ...returnexpand_multinomial(Pow(b._eval_nseries(x,n=n,logx=logx),e),deep=False)elifeisS.NegativeOne:# 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"b=b._eval_nseries(x,n=n,logx=logx)prefactor=b.as_leading_term(x)# express "rest" as: rest = 1 + k*x**l + ... + O(x**n)rest=expand_mul((b-prefactor)/prefactor)ifrest==0:# if prefactor == w**4 + x**2*w**4 + 2*x*w**4, we need to# factor the w**4 out using collect:return1/collect(prefactor,x)ifrest.is_Order:return1/prefactor+rest/prefactorn2=rest.getn()ifn2isnotNone:n=n2# remove the O - powering this is slowiflogxisnotNone:rest=rest.removeO()k,l=rest.leadterm(x)ifl.is_Rationalandl>0:passelifl.is_numberandl>0:l=l.evalf()else:raiseNotImplementedError()terms=[1/prefactor]forminxrange(1,ceiling(n/l)):new_term=terms[-1]*(-rest)ifnew_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)# Append O(...), we know the order.ifn2isNoneorlogxisnotNone:terms.append(O(x**n))returnpowsimp(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:denominator=(b**(-e))._eval_nseries(x,n=n,logx=logx)if1/denominator==self:returnself# now we have a type 1/f(x), that we know how to expandreturn(1/denominator)._eval_nseries(x,n=n,logx=logx)ife.has(Symbol):returnexp(e*log(b))._eval_nseries(x,n=n,logx=logx)# see if the base is as simple as possiblebx=bwhilebx.is_Powandbx.exp.is_Rational:bx=bx.baseifbx==x:returnself# work for b(x)**e where e is not an Integer and does not contain x# and hopefully has no other symbolsdefe2int(e):"""return the integer value (if possible) of e and a flag indicating whether it is bounded or not."""n=e.limit(x,0)unbounded=n.is_unboundedifnotunbounded:# XXX was int or floor intended? int used to behave like floor# so int(-Rational(1, 2)) returned -1 rather than int's 0try:n=int(n)exceptTypeError:#well, the n is something more complicated (like 1+log(2))try:n=int(n.evalf())+1# XXX why is 1 being added?exceptTypeError:pass# hope that base allows this to be resolvedn=_sympify(n)returnn,unboundedorder=O(x**n,x)ei,unbounded=e2int(e)b0=b.limit(x,0)ifunboundedand(b0isS.Oneorb0.has(Symbol)):# XXX what orderifb0isS.One:resid=(b-1)ifresid.is_positive:returnS.Infinityelifresid.is_negative:returnS.ZeroraiseValueError('cannot determine sign of %s'%resid)returnb0**eiif(b0isS.Zeroorb0.is_unbounded):ifunboundedisnotFalse:returnb0**e# XXX what orderifnotei.is_number:# if not, how will we proceed?raiseValueError('expecting numerical exponent but got %s'%ei)nuse=n-eiife.is_realande.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=C.Order(lt,x).getn()nuse=ceiling(n-cf*(e-1))exceptNotImplementedError:passbs=b._eval_nseries(x,n=nuse,logx=logx)terms=bs.removeO()ifterms.is_Add:bs=termslt=terms.as_leading_term(x)# bs -> lt + rest -> lt*(1 + (bs/lt - 1))return((Pow(lt,e)*Pow((bs/lt).expand(),e).nseries(x,n=nuse,logx=logx)).expand()+order)ifbs.is_Add:fromsympyimportO# So, bs + O() == termsc=Dummy('c')res=[]forarginbs.args:ifarg.is_Order:arg=c*arg.exprres.append(arg)bs=Add(*res)rv=(bs**e).series(x).subs(c,O(1))rv+=orderreturnrvrv=bs**eifterms!=bs:rv+=orderreturnrv# either b0 is bounded but neither 1 nor 0 or e is unbounded# b -> b0 + (b-b0) -> b0 * (1 + (b/b0-1))o2=order*(b0**-e)z=(b/b0-1)o=O(z,x)#r = self._compute_oseries3(z, o2, self.taylor_term)ifoisS.Zerooro2isS.Zero:unbounded=Trueelse:ifo.expr.is_number:e2=log(o2.expr*x)/log(x)else:e2=log(o2.expr)/log(o.expr)n,unbounded=e2int(e2)ifunbounded:# requested accuracy gives infinite series,# order is probably non-polynomial e.g. O(exp(-1/x), x).r=1+zelse:l=[]g=Noneforiinxrange(n+2):g=self.taylor_term(i,z,g)g=g.nseries(x,n=n,logx=logx)l.append(g)r=Add(*l)returnr*b0**e+orderdef_eval_as_leading_term(self,x):ifnotself.exp.has(x):returnPow(self.base.as_leading_term(x),self.exp)returnC.exp(self.exp*C.log(self.base)).as_leading_term(x)@cacheitdeftaylor_term(self,n,x,*previous_terms):# of (1+x)**eifn<0:returnS.Zerox=_sympify(x)returnC.binomial(self.exp,n)*Pow(x,n)def_sage_(self):returnself.args[0]._sage_()**self.args[1]._sage_()