Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 def _eval_is_real(self):
     real_b = self.base.is_real
     if real_b is None:
         return
     real_e = self.exp.is_real
     if real_e is None:
         return
     if real_b and real_e:
         if self.base.is_positive:
             return True
         else:   # negative or zero (or positive)
             if self.exp.is_integer:
                 return True
             elif self.base.is_negative:
                 if self.exp.is_Rational:
                     return False
     im_b = self.base.is_imaginary
     im_e = self.exp.is_imaginary
     if im_b:
         if self.exp.is_integer:
             if self.exp.is_even:
                 return True
             elif self.exp.is_odd:
                 return False
         elif (self.exp in [S.ImaginaryUnit, -S.ImaginaryUnit] and
               self.base in [S.ImaginaryUnit, -S.ImaginaryUnit]):
             return True
         elif self.exp.is_Add:
             c, a = self.exp.as_coeff_Add()
             if c and c.is_Integer:
                 return C.Mul(
                     self.base**c, self.base**a, evaluate=False).is_real
     if real_b and im_e:
         if self.base is S.NegativeOne:
             return True
         c = self.exp.coeff(S.ImaginaryUnit)
         if c:
             ok = (c*C.log(self.base)/S.Pi).is_Integer
             if ok is not None:
                 return ok