def _eval_expand_trig(self, **hints): arg = self.args[0] if arg.is_Add: from sympy import symmetric_poly n = len(arg.args) TX = [ tanh(x, evaluate=False)._eval_expand_trig() for x in arg.args ] p = [0, 0] # [den, num] for i in range(n + 1): p[i % 2] += symmetric_poly(i, TX) return p[1] / p[0] elif arg.is_Mul: from sympy.functions.combinatorial.numbers import nC coeff, terms = arg.as_coeff_Mul() if coeff.is_Integer and coeff > 1: n = [] d = [] T = tanh(terms) for k in range(1, coeff + 1, 2): n.append(nC(range(coeff), k) * T**k) for k in range(0, coeff + 1, 2): d.append(nC(range(coeff), k) * T**k) return Add(*n) / Add(*d) return tanh(arg)
def _eval_expand_trig(self, **hints): arg = self.args[0] x = None if arg.is_Add: from sympy import symmetric_poly n = len(arg.args) TX = [] for x in arg.args: tx = tan(x, evaluate=False)._eval_expand_trig() TX.append(tx) Yg = numbered_symbols('Y') Y = [ Yg.next() for i in xrange(n) ] p = [0,0] for i in xrange(n+1): p[1-i%2] += symmetric_poly(i,Y)*(-1)**((i%4)//2) return (p[0]/p[1]).subs(zip(Y,TX)) else: coeff, terms = arg.as_coeff_Mul(rational=True) if coeff.is_Integer and coeff > 1: I = S.ImaginaryUnit z = C.Symbol('dummy',real=True) P = ((1+I*z)**coeff).expand() return (C.im(P)/C.re(P)).subs([(z,tan(terms))]) return tan(arg)
def _eval_expand_trig(self, **hints): arg = self.args[0] x = None if arg.is_Add: from sympy import symmetric_poly n = len(arg.args) TX = [] for x in arg.args: tx = tan(x, evaluate=False)._eval_expand_trig() TX.append(tx) Yg = numbered_symbols('Y') Y = [Yg.next() for i in xrange(n)] p = [0, 0] for i in xrange(n + 1): p[1 - i % 2] += symmetric_poly(i, Y) * (-1)**((i % 4) // 2) return (p[0] / p[1]).subs(zip(Y, TX)) else: coeff, terms = arg.as_coeff_Mul(rational=True) if coeff.is_Integer and coeff > 1: I = S.ImaginaryUnit z = C.Symbol('dummy', real=True) P = ((1 + I * z)**coeff).expand() return (C.im(P) / C.re(P)).subs([(z, tan(terms))]) return tan(arg)
def _eval_expand_trig(self, **hints): arg = self.args[0] x = None if arg.is_Add: from sympy import symmetric_poly n = len(arg.args) CX = [] for x in arg.args: cx = cot(x, evaluate=False)._eval_expand_trig() CX.append(cx) Yg = numbered_symbols("Y") Y = [Yg.next() for i in xrange(n)] p = [0, 0] for i in xrange(n, -1, -1): p[(n - i) % 2] += symmetric_poly(i, Y) * (-1) ** (((n - i) % 4) // 2) return (p[0] / p[1]).subs(zip(Y, CX)) else: coeff, terms = arg.as_coeff_Mul(rational=True) if coeff.is_Integer and coeff > 1: I = S.ImaginaryUnit z = C.Symbol("dummy", real=True) P = ((z + I) ** coeff).expand() return (C.re(P) / C.im(P)).subs([(z, cot(terms))]) return cot(arg)