def _eval_expand_complex(self, *args): if isinstance(self.exp, Basic.Integer): re, im = self.base.as_real_imag() base = re + S.ImaginaryUnit * im return (base**self.exp)._eval_expand_basic(*args) elif isinstance(self.exp, Basic.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() r = Basic.sqrt(re**2 + im**2) t = Basic.atan(im / re) if im == 0 and re == -1: t = S.Pi rp, tp = r**self.exp, t*self.exp return rp*Basic.cos(tp) + rp*Basic.sin(tp)*S.ImaginaryUnit else: return S.Re(self) + S.ImaginaryUnit*S.Im(self)