def test_hyper_as_trig(): from sympy.simplify.fu import _osborne as o, _osbornei as i, TR12 eq = sinh(x)**2 + cosh(x)**2 t, f = hyper_as_trig(eq) assert f(fu(t)) == cosh(2*x) e, f = hyper_as_trig(tanh(x + y)) assert f(TR12(e)) == (tanh(x) + tanh(y))/(tanh(x)*tanh(y) + 1) d = Dummy() assert o(sinh(x), d) == I*sin(x*d) assert o(tanh(x), d) == I*tan(x*d) assert o(coth(x), d) == cot(x*d)/I assert o(cosh(x), d) == cos(x*d) assert o(sech(x), d) == sec(x*d) assert o(csch(x), d) == csc(x*d)/I for func in (sinh, cosh, tanh, coth, sech, csch): h = func(pi) assert i(o(h, d), d) == h # /!\ the _osborne functions are not meant to work # in the o(i(trig, d), d) direction so we just check # that they work as they are supposed to work assert i(cos(x*y + z), y) == cosh(x + z*I) assert i(sin(x*y + z), y) == sinh(x + z*I)/I assert i(tan(x*y + z), y) == tanh(x + z*I)/I assert i(cot(x*y + z), y) == coth(x + z*I)*I assert i(sec(x*y + z), y) == sech(x + z*I) assert i(csc(x*y + z), y) == csch(x + z*I)*I
def test_simplifications(): x = Symbol('x') assert sinh(asinh(x)) == x assert sinh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) assert sinh(atanh(x)) == x/sqrt(1 - x**2) assert sinh(acoth(x)) == 1/(sqrt(x - 1) * sqrt(x + 1)) assert cosh(asinh(x)) == sqrt(1 + x**2) assert cosh(acosh(x)) == x assert cosh(atanh(x)) == 1/sqrt(1 - x**2) assert cosh(acoth(x)) == x/(sqrt(x - 1) * sqrt(x + 1)) assert tanh(asinh(x)) == x/sqrt(1 + x**2) assert tanh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) / x assert tanh(atanh(x)) == x assert tanh(acoth(x)) == 1/x assert coth(asinh(x)) == sqrt(1 + x**2)/x assert coth(acosh(x)) == x/(sqrt(x - 1) * sqrt(x + 1)) assert coth(atanh(x)) == 1/x assert coth(acoth(x)) == x assert csch(asinh(x)) == 1/x assert csch(acosh(x)) == 1/(sqrt(x - 1) * sqrt(x + 1)) assert csch(atanh(x)) == sqrt(1 - x**2)/x assert csch(acoth(x)) == sqrt(x - 1) * sqrt(x + 1) assert sech(asinh(x)) == 1/sqrt(1 + x**2) assert sech(acosh(x)) == 1/x assert sech(atanh(x)) == sqrt(1 - x**2) assert sech(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)/x
def test_sech_rewrite(): x = Symbol("x") assert sech(x).rewrite(exp) == 1 / (exp(x) / 2 + exp(-x) / 2) == sech(x).rewrite("tractable") assert sech(x).rewrite(sinh) == I / sinh(x + I * pi / 2) tanh_half = tanh(S.Half * x) ** 2 assert sech(x).rewrite(tanh) == (1 - tanh_half) / (1 + tanh_half) coth_half = coth(S.Half * x) ** 2 assert sech(x).rewrite(coth) == (coth_half - 1) / (coth_half + 1)
def test_derivs(): x = Symbol('x') assert coth(x).diff(x) == -sinh(x)**(-2) assert sinh(x).diff(x) == cosh(x) assert cosh(x).diff(x) == sinh(x) assert tanh(x).diff(x) == -tanh(x)**2 + 1 assert csch(x).diff(x) == -coth(x)*csch(x) assert sech(x).diff(x) == -tanh(x)*sech(x) assert acoth(x).diff(x) == 1/(-x**2 + 1) assert asinh(x).diff(x) == 1/sqrt(x**2 + 1) assert acosh(x).diff(x) == 1/sqrt(x**2 - 1) assert atanh(x).diff(x) == 1/(-x**2 + 1)
def test_sign_assumptions(): p = Symbol('p', positive=True) n = Symbol('n', negative=True) assert sinh(n).is_negative is True assert sinh(p).is_positive is True assert cosh(n).is_positive is True assert cosh(p).is_positive is True assert tanh(n).is_negative is True assert tanh(p).is_positive is True assert csch(n).is_negative is True assert csch(p).is_positive is True assert sech(n).is_positive is True assert sech(p).is_positive is True assert coth(n).is_negative is True assert coth(p).is_positive is True
def test_rewrite_trigh(): # if this import passes then the test below should also pass from sympy import sech assert solveset_real(sinh(x) + sech(x), x) == FiniteSet( 2*atanh(-S.Half + sqrt(5)/2 - sqrt(-2*sqrt(5) + 2)/2), 2*atanh(-S.Half + sqrt(5)/2 + sqrt(-2*sqrt(5) + 2)/2), 2*atanh(-sqrt(5)/2 - S.Half + sqrt(2 + 2*sqrt(5))/2), 2*atanh(-sqrt(2 + 2*sqrt(5))/2 - sqrt(5)/2 - S.Half))
def test_real_assumptions(): z = Symbol('z', real=False) assert sinh(z).is_real is None assert cosh(z).is_real is None assert tanh(z).is_real is None assert sech(z).is_real is None assert csch(z).is_real is None assert coth(z).is_real is None
def test_rewrite_trigh(): # if this import passes then the test below should also pass from sympy import sech assert solveset_real(sinh(x) + sech(x), x) == FiniteSet( 2 * atanh(-S.Half + sqrt(5) / 2 - sqrt(-2 * sqrt(5) + 2) / 2), 2 * atanh(-S.Half + sqrt(5) / 2 + sqrt(-2 * sqrt(5) + 2) / 2), 2 * atanh(-sqrt(5) / 2 - S.Half + sqrt(2 + 2 * sqrt(5)) / 2), 2 * atanh(-sqrt(2 + 2 * sqrt(5)) / 2 - sqrt(5) / 2 - S.Half))
def test_asech(): x = Symbol('x') assert asech(-x) == asech(-x) # values at fixed points assert asech(1) == 0 assert asech(-1) == pi*I assert asech(0) == oo assert asech(2) == I*pi/3 assert asech(-2) == 2*I*pi / 3 # at infinites assert asech(oo) == I*pi/2 assert asech(-oo) == I*pi/2 assert asech(zoo) == nan assert asech(I) == log(1 + sqrt(2)) - I*pi/2 assert asech(-I) == log(1 + sqrt(2)) + I*pi/2 assert asech(sqrt(2) - sqrt(6)) == 11*I*pi / 12 assert asech(sqrt(2 - 2/sqrt(5))) == I*pi / 10 assert asech(-sqrt(2 - 2/sqrt(5))) == 9*I*pi / 10 assert asech(2 / sqrt(2 + sqrt(2))) == I*pi / 8 assert asech(-2 / sqrt(2 + sqrt(2))) == 7*I*pi / 8 assert asech(sqrt(5) - 1) == I*pi / 5 assert asech(1 - sqrt(5)) == 4*I*pi / 5 assert asech(-sqrt(2*(2 + sqrt(2)))) == 5*I*pi / 8 # properties # asech(x) == acosh(1/x) assert asech(sqrt(2)) == acosh(1/sqrt(2)) assert asech(2/sqrt(3)) == acosh(sqrt(3)/2) assert asech(2/sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2))/2) assert asech(S(2)) == acosh(1/S(2)) # asech(x) == I*acos(1/x) # (Note: the exact formula is asech(x) == +/- I*acos(1/x)) assert asech(-sqrt(2)) == I*acos(-1/sqrt(2)) assert asech(-2/sqrt(3)) == I*acos(-sqrt(3)/2) assert asech(-S(2)) == I*acos(-S.Half) assert asech(-2/sqrt(2)) == I*acos(-sqrt(2)/2) # sech(asech(x)) / x == 1 assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1 assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1 assert (sech(asech(sqrt(2 + 2/sqrt(5)))) / (sqrt(2 + 2/sqrt(5)))).simplify() == 1 assert (sech(asech(-sqrt(2 + 2/sqrt(5)))) / (-sqrt(2 + 2/sqrt(5)))).simplify() == 1 assert (sech(asech(sqrt(2*(2 + sqrt(2))))) / (sqrt(2*(2 + sqrt(2))))).simplify() == 1 assert expand_mul(sech(asech((1 + sqrt(5)))) / ((1 + sqrt(5)))) == 1 assert expand_mul(sech(asech((-1 - sqrt(5)))) / ((-1 - sqrt(5)))) == 1 assert expand_mul(sech(asech((-sqrt(6) - sqrt(2)))) / ((-sqrt(6) - sqrt(2)))) == 1 # numerical evaluation assert str(asech(5*I).n(6)) == '0.19869 - 1.5708*I' assert str(asech(-5*I).n(6)) == '0.19869 + 1.5708*I'
def perpendicular(Perpendicular): if Perpendicular != 'EckartPure': return '''\n\ndouble ''' + Perpendicular + '''_::DerivativeY(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).diff(Y).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';} double ''' + Perpendicular + '''_::DerivativeY2(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).diff(Y, 2).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';} double ''' + Perpendicular + '''_::DerivativeYX(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).diff(X).diff(Y).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';}''' return ''
def MultiDimensionalSecant(self, *args): assert len(args) >= 2 assert len(args) % 2 == 0 variables = int(len(args) / 2) offset = 2 + 3 * variables variable_objects = [] equation_objects = [] for i, e in enumerate(args): if i % 2 == 0: variable_objects.append(e) else: equation_objects.append(e) for x_string in equation_objects: if isinstance(x_string, dict): raise NotImplementedError( "At this time multi-variable functions do not support composition." ) sub_eq = 1 j = 2 for x in variable_objects: sub_eq *= Equation.tf_secant_h(self.w[self._wc + j] * x + self.w[self._wc + j + 1]) j += 2 eq = self.w[self._wc] * (sub_eq + self.w[self._wc + 1]) syms = get_symbols(1, offset + variables + 1) sub_equation_string = 1 j = 2 for i in range(len(equation_objects)): sub_equation_string *= sech(syms[j] * syms[-1 * (i + 1)] + syms[j + 1]) j += 2 equation_string = syms[0] * (sub_equation_string + syms[1]) parameters_list = [] for i, j in enumerate(equation_objects): parameters_list.append([j, syms[-1 * (i + 1)]]) parameters_list += [[self.w[self._wc + i], syms[i]] for i in range(offset)] return { "equation": eq, "parameters": parameters_list, "symbolic": equation_string, "offset": offset }
def test_complex(): a, b = symbols('a,b', real=True) z = a + b*I for func in [sinh, cosh, tanh, coth, sech, csch]: assert func(z).conjugate() == func(a - b*I) for deep in [True, False]: assert sinh(z).expand( complex=True, deep=deep) == sinh(a)*cos(b) + I*cosh(a)*sin(b) assert cosh(z).expand( complex=True, deep=deep) == cosh(a)*cos(b) + I*sinh(a)*sin(b) assert tanh(z).expand(complex=True, deep=deep) == sinh(a)*cosh( a)/(cos(b)**2 + sinh(a)**2) + I*sin(b)*cos(b)/(cos(b)**2 + sinh(a)**2) assert coth(z).expand(complex=True, deep=deep) == sinh(a)*cosh( a)/(sin(b)**2 + sinh(a)**2) - I*sin(b)*cos(b)/(sin(b)**2 + sinh(a)**2) assert csch(z).expand(complex=True, deep=deep) == cos(b) * sinh(a) / (sin(b)**2\ *cosh(a)**2 + cos(b)**2 * sinh(a)**2) - I*sin(b) * cosh(a) / (sin(b)**2\ *cosh(a)**2 + cos(b)**2 * sinh(a)**2) assert sech(z).expand(complex=True, deep=deep) == cos(b) * cosh(a) / (sin(b)**2\ *sinh(a)**2 + cos(b)**2 * cosh(a)**2) - I*sin(b) * sinh(a) / (sin(b)**2\ *sinh(a)**2 + cos(b)**2 * cosh(a)**2)
def test_sech_series(): x = Symbol('x') assert sech(x).series(x, 0, 10) == \ 1 - x**2/2 + 5*x**4/24 - 61*x**6/720 + 277*x**8/8064 + O(x**10)
def test_sech(): x, y = symbols('x, y') k = Symbol('k', integer=True) n = Symbol('n', positive=True) assert sech(nan) == nan assert sech(zoo) == nan assert sech(oo) == 0 assert sech(-oo) == 0 assert sech(0) == 1 assert sech(-1) == sech(1) assert sech(-x) == sech(x) assert sech(pi * I) == sec(pi) assert sech(-pi * I) == sec(pi) assert sech(-2**1024 * E) == sech(2**1024 * E) assert sech(pi * I / 2) == zoo assert sech(-pi * I / 2) == zoo assert sech((-3 * 10**73 + 1) * pi * I / 2) == zoo assert sech((7 * 10**103 + 1) * pi * I / 2) == zoo assert sech(pi * I) == -1 assert sech(-pi * I) == -1 assert sech(5 * pi * I) == -1 assert sech(8 * pi * I) == 1 assert sech(pi * I / 3) == 2 assert sech(-2 * pi * I / 3) == -2 assert sech(pi * I / 4) == sqrt(2) assert sech(-pi * I / 4) == sqrt(2) assert sech(5 * pi * I / 4) == -sqrt(2) assert sech(-5 * pi * I / 4) == -sqrt(2) assert sech(pi * I / 6) == 2 / sqrt(3) assert sech(-pi * I / 6) == 2 / sqrt(3) assert sech(7 * pi * I / 6) == -2 / sqrt(3) assert sech(-5 * pi * I / 6) == -2 / sqrt(3) assert sech(pi * I / 105) == 1 / cos(pi / 105) assert sech(-pi * I / 105) == 1 / cos(pi / 105) assert sech(x * I) == 1 / cos(x) assert sech(k * pi * I) == 1 / cos(k * pi) assert sech(17 * k * pi * I) == 1 / cos(17 * k * pi) assert sech(n).is_real is True
{return ''' + sympy.ccode( eckart(Perpendicular).diff(X).diff(Y).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';}''' return '' for Perpendicular in Perpendiculars.keys(): print('''#include<cmath> #include"''' + Perpendicular[0].lower() + Perpendicular[1:] + '''.h" double ''' + Perpendicular + '''_::Potential(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';} double ''' + Perpendicular + '''_::Derivative(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).diff(X).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';} double ''' + Perpendicular + '''_::Derivative2(double const X,double const Y)const&noexcept {return ''' + sympy.ccode( eckart(Perpendicular).diff(X, 2).subs( sympy.sech(BarrierWidth * X)**2, 1 - sympy.tanh(BarrierWidth * X)**2)) + ''';}''' +
def test_sech(): x, y = symbols("x, y") k = Symbol("k", integer=True) n = Symbol("n", positive=True) assert sech(nan) is nan assert sech(zoo) is nan assert sech(oo) == 0 assert sech(-oo) == 0 assert sech(0) == 1 assert sech(-1) == sech(1) assert sech(-x) == sech(x) assert sech(pi * I) == sec(pi) assert sech(-pi * I) == sec(pi) assert sech(-(2 ** 1024) * E) == sech(2 ** 1024 * E) assert sech(pi * I / 2) is zoo assert sech(-pi * I / 2) is zoo assert sech((-3 * 10 ** 73 + 1) * pi * I / 2) is zoo assert sech((7 * 10 ** 103 + 1) * pi * I / 2) is zoo assert sech(pi * I) == -1 assert sech(-pi * I) == -1 assert sech(5 * pi * I) == -1 assert sech(8 * pi * I) == 1 assert sech(pi * I / 3) == 2 assert sech(pi * I * Rational(-2, 3)) == -2 assert sech(pi * I / 4) == sqrt(2) assert sech(-pi * I / 4) == sqrt(2) assert sech(pi * I * Rational(5, 4)) == -sqrt(2) assert sech(pi * I * Rational(-5, 4)) == -sqrt(2) assert sech(pi * I / 6) == 2 / sqrt(3) assert sech(-pi * I / 6) == 2 / sqrt(3) assert sech(pi * I * Rational(7, 6)) == -2 / sqrt(3) assert sech(pi * I * Rational(-5, 6)) == -2 / sqrt(3) assert sech(pi * I / 105) == 1 / cos(pi / 105) assert sech(-pi * I / 105) == 1 / cos(pi / 105) assert sech(x * I) == 1 / cos(x) assert sech(k * pi * I) == 1 / cos(k * pi) assert sech(17 * k * pi * I) == 1 / cos(17 * k * pi) assert sech(n).is_real is True
def test_issue_11254a(): assert not integrate(sech(x), (x, 0, 1)).has(Integral)
def eckart(Perpendicular): return BarrierHeight * sympy.sech( BarrierWidth * X)**2 + (1 + Couple * sympy.sech(BarrierWidth * X)**2 ) * Perpendiculars[Perpendicular]
sp.tan(num) # tangente sp.cot(num) # cotangente sp.sec(num) # secante sp.csc(num) # cosecante sp.asin(num) # Arcoseno sp.acos(num) # Arcocoseno sp.atan(num) # Arcotangente sp.atan2(catetoY, catetoX) # Arcotangente de un triangulo segun los catetos (Angulo) sp.acot(num) # Arcocotangente sp.asec(num) # Arcosecante sp.acsc(num) # Arcocosecante # Funciones hiperbólicas (Angulos en radianes) sp.sinh(num) # Seno sp.cosh(num) # Coseno sp.tanh(num) # tangente sp.coth(num) # cotangente sp.sech(num) # secante sp.csch(num) # cosecante sp.asinh(num) # Arcoseno sp.acosh(num) # Arcocoseno sp.atanh(num) # Arcotangente sp.acoth(num) # Arcocotangente sp.asech(num) # Arcosecante sp.acsch(num) # Arcocosecante # Combinatoria sp.factorial(num) # Factorial sp.functions.combinatorial.numbers.nP(num1, num2) # Permutación sp.functions.combinatorial.numbers.nC(num1, num2) # Combinación
def test_sech_fdiff(): x = Symbol('x') raises(ArgumentIndexError, lambda: sech(x).fdiff(2))
def test_sech(): x, y = symbols('x, y') k = Symbol('k', integer=True) n = Symbol('n', positive=True) assert sech(nan) == nan assert sech(zoo) == nan assert sech(oo) == 0 assert sech(-oo) == 0 assert sech(0) == 1 assert sech(-1) == sech(1) assert sech(-x) == sech(x) assert sech(pi*I) == sec(pi) assert sech(-pi*I) == sec(pi) assert sech(-2**1024 * E) == sech(2**1024 * E) assert sech(pi*I/2) == zoo assert sech(-pi*I/2) == zoo assert sech((-3*10**73 + 1)*pi*I/2) == zoo assert sech((7*10**103 + 1)*pi*I/2) == zoo assert sech(pi*I) == -1 assert sech(-pi*I) == -1 assert sech(5*pi*I) == -1 assert sech(8*pi*I) == 1 assert sech(pi*I/3) == 2 assert sech(-2*pi*I/3) == -2 assert sech(pi*I/4) == sqrt(2) assert sech(-pi*I/4) == sqrt(2) assert sech(5*pi*I/4) == -sqrt(2) assert sech(-5*pi*I/4) == -sqrt(2) assert sech(pi*I/6) == 2/sqrt(3) assert sech(-pi*I/6) == 2/sqrt(3) assert sech(7*pi*I/6) == -2/sqrt(3) assert sech(-5*pi*I/6) == -2/sqrt(3) assert sech(pi*I/105) == 1/cos(pi/105) assert sech(-pi*I/105) == 1/cos(pi/105) assert sech(x*I) == 1/cos(x) assert sech(k*pi*I) == 1/cos(k*pi) assert sech(17*k*pi*I) == 1/cos(17*k*pi) assert sech(n).is_real is True
def test_sech(): x, y = symbols('x, y') k = Symbol('k', integer=True) n = Symbol('n', positive=True) assert sech(nan) is nan assert sech(zoo) is nan assert sech(oo) == 0 assert sech(-oo) == 0 assert sech(0) == 1 assert sech(-1) == sech(1) assert sech(-x) == sech(x) assert sech(pi * I) == sec(pi) assert sech(-pi * I) == sec(pi) assert sech(-2**1024 * E) == sech(2**1024 * E) assert sech(pi * I / 2) is zoo assert sech(-pi * I / 2) is zoo assert sech((-3 * 10**73 + 1) * pi * I / 2) is zoo assert sech((7 * 10**103 + 1) * pi * I / 2) is zoo assert sech(pi * I) == -1 assert sech(-pi * I) == -1 assert sech(5 * pi * I) == -1 assert sech(8 * pi * I) == 1 assert sech(pi * I / 3) == 2 assert sech(pi * I * Rational(-2, 3)) == -2 assert sech(pi * I / 4) == sqrt(2) assert sech(-pi * I / 4) == sqrt(2) assert sech(pi * I * Rational(5, 4)) == -sqrt(2) assert sech(pi * I * Rational(-5, 4)) == -sqrt(2) assert sech(pi * I / 6) == 2 / sqrt(3) assert sech(-pi * I / 6) == 2 / sqrt(3) assert sech(pi * I * Rational(7, 6)) == -2 / sqrt(3) assert sech(pi * I * Rational(-5, 6)) == -2 / sqrt(3) assert sech(pi * I / 105) == 1 / cos(pi / 105) assert sech(-pi * I / 105) == 1 / cos(pi / 105) assert sech(x * I) == 1 / cos(x) assert sech(k * pi * I) == 1 / cos(k * pi) assert sech(17 * k * pi * I) == 1 / cos(17 * k * pi) assert sech(n).is_real is True assert expand_trig(sech(x + y)) == 1 / (cosh(x) * cosh(y) + sinh(x) * sinh(y))