def _eval_rewrite_as_besseli(self, z): ot = Rational(1, 3) tt = Rational(2, 3) a = C.Pow(z, Rational(3, 2)) if re(z).is_positive: return ot*sqrt(z) * (besseli(-ot, tt*a) - besseli(ot, tt*a)) else: return ot*(C.Pow(a, ot)*besseli(-ot, tt*a) - z*C.Pow(a, -ot)*besseli(ot, tt*a))
def _eval_rewrite_as_besseli(self, z): ot = Rational(1, 3) tt = Rational(2, 3) a = C.Pow(z, Rational(3, 2)) if re(z).is_positive: return sqrt(z)/sqrt(3) * (besseli(-ot, tt*a) + besseli(ot, tt*a)) else: b = C.Pow(a, ot) c = C.Pow(a, -ot) return sqrt(ot)*(b*besseli(-ot, tt*a) + z*c*besseli(ot, tt*a))
def _eval_rewrite_as_besseli(self, z): ot = Rational(1, 3) tt = Rational(2, 3) a = tt * C.Pow(z, Rational(3, 2)) if re(z).is_positive: return z/sqrt(3) * (besseli(-tt, a) + besseli(tt, a)) else: a = C.Pow(z, Rational(3, 2)) b = C.Pow(a, tt) c = C.Pow(a, -tt) return sqrt(ot) * (b*besseli(-tt, tt*a) + z**2*c*besseli(tt, tt*a))
def _print_Pow(self, expr): base = self._print(expr.base) if ('_' in base or '^' in base) and 'cdot' not in base: mode = True else: mode = False # Treat x**Rational(1,n) as special case if expr.exp.is_Rational and abs(expr.exp.p) == 1 and expr.exp.q != 1: expq = expr.exp.q if expq == 2: tex = r"\sqrt{%s}" % base elif self._settings['itex']: tex = r"\root{%d}{%s}" % (expq, base) else: tex = r"\sqrt[%d]{%s}" % (expq, base) if expr.exp.is_negative: return r"\frac{1}{%s}" % tex else: return tex elif self._settings['fold_frac_powers'] \ and expr.exp.is_Rational \ and expr.exp.q != 1: base, p, q = self._print(expr.base), expr.exp.p, expr.exp.q if mode: return r"{\lp %s \rp}^{%s/%s}" % (base, p, q) else: return r"%s^{%s/%s}" % (base, p, q) elif expr.exp.is_Rational and expr.exp.is_negative and expr.base.is_Function: # Things like 1/x return r"\frac{%s}{%s}" % \ (1, self._print(C.Pow(expr.base, -expr.exp))) else: if expr.base.is_Function: return self._print(expr.base, self._print(expr.exp)) else: if expr.is_commutative and expr.exp == -1: """ solves issue 4129 As Mul always simplify 1/x to x**-1 The objective is achieved with this hack first we get the latex for -1 * expr, which is a Mul expression """ tex = self._print(S.NegativeOne * expr).strip() # the result comes with a minus and a space, so we remove if tex[:1] == "-": return tex[1:].strip() if self._needs_brackets(expr.base): tex = r"\left(%s\right)^{%s}" else: if mode: tex = r"{\lp %s \rp}^{%s}" else: tex = r"%s^{%s}" return tex % (self._print(expr.base), self._print(expr.exp))
def mypowsimp(expr): def find_double_pow(expr): for sub in preorder_traversal(expr): if isinstance(sub, C.Pow) and isinstance(sub.base, C.Pow): return sub while True: sub = find_double_pow(expr) if sub is None: break expr = expr.subs(sub, C.Pow(sub.base.base, sub.exp*sub.base.exp)) return expr
def _eval_rewrite_as_besselj(self, z): ot = Rational(1, 3) tt = Rational(2, 3) a = C.Pow(-z, Rational(3, 2)) if re(z).is_negative: return ot * sqrt(-z) * (besselj(-ot, tt * a) + besselj(ot, tt * a))
def _eval_rewrite_as_besselj(self, z): tt = Rational(2, 3) a = tt * C.Pow(-z, Rational(3, 2)) if re(z).is_negative: return -z / sqrt(3) * (besselj(-tt, a) + besselj(tt, a))
def _eval_rewrite_as_besselj(self, z): tt = Rational(2, 3) a = C.Pow(-z, Rational(3, 2)) if re(z).is_negative: return z / 3 * (besselj(-tt, tt * a) - besselj(tt, tt * a))