(self, expt)
return result
Tries to do some simplifications on self**expt

        Returns None if no further simplifications can be done

        When exponent is a fraction (so we have for example a square root),
        we try to find a simpler representation by factoring the argument
        up to factors of 2**15, e.g.

          - sqrt(4) becomes 2
          - sqrt(-4) becomes 2*I
          - (2**(3+7)*3**(6+7))**Rational(1,7) becomes 6*18**(3/7)

        Further simplification would require a special call to factorint on
        the argument which is not done here for sake of speed.
Tries to do some simplifications on self**expt
Tries to do some simplifications on self ** expt
def _eval_power(self, expt):
        """
        Tries to do some simplifications on self**expt

        Returns None if no further simplifications can be done

        When exponent is a fraction (so we have for example a square root),
        we try to find a simpler representation by factoring the argument
        up to factors of 2**15, e.g.

          - sqrt(4) becomes 2
          - sqrt(-4) becomes 2*I
          - (2**(3+7)*3**(6+7))**Rational(1,7) becomes 6*18**(3/7)

        Further simplification would require a special call to factorint on
        the argument which is not done here for sake of speed.

        """
        from sympy import perfect_power

        if expt is S.Infinity:
            if self.p > S.One:
                return S.Infinity
            # cases -1, 0, 1 are done in their respective classes
            return S.Infinity + S.ImaginaryUnit*S.Infinity
        if expt is S.NegativeInfinity:
            return Rational(1, self)**S.Infinity
        if not isinstance(expt, Number):
            # simplify when expt is even
            # (-2)**k --> 2**k
            if self.is_negative and expt.is_even:
                return (-self)**expt
        if not isinstance(expt, Rational):
            return
        if expt is S.Half and self.is_negative:
            # we extract I for this special case since everyone is doing so
            return S.ImaginaryUnit*Pow(-self, expt)
        if expt.is_negative:
            # invert base and change sign on exponent
            ne = -expt
            if self.is_negative:
                if expt.q != 1:
                    return -(S.NegativeOne)**((expt.p % expt.q) /
                            S(expt.q))*Rational(1, -self)**ne
                else:
                    return (S.NegativeOne)**ne*Rational(1, -self)**ne
            else:
                return Rational(1, self.p)**ne
        # see if base is a perfect root, sqrt(4) --> 2
        x, xexact = integer_nthroot(abs(self.p), expt.q)
        if xexact:
            # if it's a perfect root we've finished
            result = Integer(x**abs(expt.p))
            if self.is_negative:
                result *= S.NegativeOne**expt
            return result

        # The following is an algorithm where we collect perfect roots
        # from the factors of base.

        # if it's not an nth root, it still might be a perfect power
        b_pos = int(abs(self.p))
        p = perfect_power(b_pos)
        if p is not False:
            dict = {p[0]: p[1]}
        else:
            dict = Integer(self).factors(limit=2**15)

        # now process the dict of factors
        if self.is_negative:
            dict[-1] = 1
        out_int = 1  # integer part
        out_rad = 1  # extracted radicals
        sqr_int = 1
        sqr_gcd = 0
        sqr_dict = {}
        for prime, exponent in dict.items():
            exponent *= expt.p
            # remove multiples of expt.q: (2**12)**(1/10) -> 2*(2**2)**(1/10)
            div_e, div_m = divmod(exponent, expt.q)
            if div_e > 0:
                out_int *= prime**div_e
            if div_m > 0:
                # see if the reduced exponent shares a gcd with e.q
                # (2**2)**(1/10) -> 2**(1/5)
                g = igcd(div_m, expt.q)
                if g != 1:
                    out_rad *= Pow(prime, Rational(div_m//g, expt.q//g))
                else:
                    sqr_dict[prime] = div_m
        # identify gcd of remaining powers
        for p, ex in sqr_dict.items():
            if sqr_gcd == 0:
                sqr_gcd = ex
            else:
                sqr_gcd = igcd(sqr_gcd, ex)
                if sqr_gcd == 1:
                    break
        for k, v in sqr_dict.items():
            sqr_int *= k**(v//sqr_gcd)
        if sqr_int == self and out_int == 1 and out_rad == 1:
            result = None
        else:
            result = out_int*out_rad*Pow(sqr_int, Rational(sqr_gcd, expt.q))
        return result
def _eval_power ( self , expt ) : from sympy import perfect_power if expt is S . Infinity : if self . p > S . One : return S . Infinity # cases -1, 0, 1 are done in their respective classes return S . Infinity + S . ImaginaryUnit * S . Infinity if expt is S . NegativeInfinity : return Rational ( 1 , self ) ** S . Infinity if not isinstance ( expt , Number ) : # simplify when expt is even # (-2)**k --> 2**k if self . is_negative and expt . is_even : return ( - self ) ** expt if not isinstance ( expt , Rational ) : return if expt is S . Half and self . is_negative : # we extract I for this special case since everyone is doing so return S . ImaginaryUnit * Pow ( - self , expt ) if expt . is_negative : # invert base and change sign on exponent ne = - expt if self . is_negative : if expt . q != 1 : return - ( S . NegativeOne ) ** ( ( expt . p % expt . q ) / S ( expt . q ) ) * Rational ( 1 , - self ) ** ne else : return ( S . NegativeOne ) ** ne * Rational ( 1 , - self ) ** ne else : return Rational ( 1 , self . p ) ** ne # see if base is a perfect root, sqrt(4) --> 2 x , xexact = integer_nthroot ( abs ( self . p ) , expt . q ) if xexact : # if it's a perfect root we've finished result = Integer ( x ** abs ( expt . p ) ) if self . is_negative : result *= S . NegativeOne ** expt return result # The following is an algorithm where we collect perfect roots # from the factors of base. # if it's not an nth root, it still might be a perfect power b_pos = int ( abs ( self . p ) ) p = perfect_power ( b_pos ) if p is not False : dict = { p [ 0 ] : p [ 1 ] } else : dict = Integer ( self ) . factors ( limit = 2 ** 15 ) # now process the dict of factors if self . is_negative : dict [ - 1 ] = 1 out_int = 1 # integer part out_rad = 1 # extracted radicals sqr_int = 1 sqr_gcd = 0 sqr_dict = { } for prime , exponent in dict . items ( ) : exponent *= expt . p # remove multiples of expt.q: (2**12)**(1/10) -> 2*(2**2)**(1/10) div_e , div_m = divmod ( exponent , expt . q ) if div_e > 0 : out_int *= prime ** div_e if div_m > 0 : # see if the reduced exponent shares a gcd with e.q # (2**2)**(1/10) -> 2**(1/5) g = igcd ( div_m , expt . q ) if g != 1 : out_rad *= Pow ( prime , Rational ( div_m // g , expt . q // g ) ) else : sqr_dict [ prime ] = div_m # identify gcd of remaining powers for p , ex in sqr_dict . items ( ) : if sqr_gcd == 0 : sqr_gcd = ex else : sqr_gcd = igcd ( sqr_gcd , ex ) if sqr_gcd == 1 : break for k , v in sqr_dict . items ( ) : sqr_int *= k ** ( v // sqr_gcd ) if sqr_int == self and out_int == 1 and out_rad == 1 : result = None else : result = out_int * out_rad * Pow ( sqr_int , Rational ( sqr_gcd , expt . q ) ) return result