def test_math_functions(): dort('sin(37)', sympy.sin(37)) dort('cos(38)', sympy.cos(38)) dort('tan(38)', sympy.tan(38)) dort('sec(39)', sympy.sec(39)) dort('csc(40)', sympy.csc(40)) dort('cot(41)', sympy.cot(41)) dort('asin(42)', sympy.asin(42)) dort('acos(43)', sympy.acos(43)) dort('atan(44)', sympy.atan(44)) dort('asec(45)', sympy.asec(45)) dort('acsc(46)', sympy.acsc(46)) dort('acot(47)', sympy.acot(47)) dort('sind(37)', sympy.sin(37 * sympy.pi / sympy.Number(180))) dort('cosd(38)', sympy.cos(38 * sympy.pi / sympy.Number(180))) dort('tand(38)', sympy.tan(38 * sympy.pi / sympy.Number(180))) dort('secd(39)', sympy.sec(39 * sympy.pi / sympy.Number(180))) dort('cscd(40)', sympy.csc(40 * sympy.pi / sympy.Number(180))) dort('cotd(41)', sympy.cot(41 * sympy.pi / sympy.Number(180))) dort('asind(42)', sympy.asin(42) * sympy.Number(180) / sympy.pi) dort('acosd(43)', sympy.acos(43) * sympy.Number(180) / sympy.pi) dort('atand(44)', sympy.atan(44) * sympy.Number(180) / sympy.pi) dort('asecd(45)', sympy.asec(45) * sympy.Number(180) / sympy.pi) dort('acscd(46)', sympy.acsc(46) * sympy.Number(180) / sympy.pi) dort('acotd(47)', sympy.acot(47) * sympy.Number(180) / sympy.pi) dort('sinh(4)', sympy.sinh(4)) dort('cosh(5)', sympy.cosh(5)) dort('tanh(6)', sympy.tanh(6)) dort('asinh(4)', sympy.asinh(4)) dort('acosh(5)', sympy.acosh(5)) dort('atanh(6)', sympy.atanh(6)) dort('int(E)', int(sympy.E)) dort('int(-E)', int(-sympy.E))
def test_invert_real(): x = Symbol('x', real=True) x = Dummy(real=True) n = Symbol('n') d = Dummy() assert solveset(abs(x) - n, x) == solveset(abs(x) - d, x) == EmptySet() n = Symbol('n', real=True) assert invert_real(x + 3, y, x) == (x, FiniteSet(y - 3)) assert invert_real(x * 3, y, x) == (x, FiniteSet(y / 3)) assert invert_real(exp(x), y, x) == (x, FiniteSet(log(y))) assert invert_real(exp(3 * x), y, x) == (x, FiniteSet(log(y) / 3)) assert invert_real(exp(x + 3), y, x) == (x, FiniteSet(log(y) - 3)) assert invert_real(exp(x) + 3, y, x) == (x, FiniteSet(log(y - 3))) assert invert_real(exp(x) * 3, y, x) == (x, FiniteSet(log(y / 3))) assert invert_real(log(x), y, x) == (x, FiniteSet(exp(y))) assert invert_real(log(3 * x), y, x) == (x, FiniteSet(exp(y) / 3)) assert invert_real(log(x + 3), y, x) == (x, FiniteSet(exp(y) - 3)) assert invert_real(Abs(x), y, x) == (x, FiniteSet(-y, y)) assert invert_real(2**x, y, x) == (x, FiniteSet(log(y) / log(2))) assert invert_real(2**exp(x), y, x) == (x, FiniteSet(log(log(y) / log(2)))) assert invert_real(x**2, y, x) == (x, FiniteSet(sqrt(y), -sqrt(y))) assert invert_real(x**Rational(1, 2), y, x) == (x, FiniteSet(y**2)) raises(ValueError, lambda: invert_real(x, x, x)) raises(ValueError, lambda: invert_real(x**pi, y, x)) raises(ValueError, lambda: invert_real(S.One, y, x)) assert invert_real(x**31 + x, y, x) == (x**31 + x, FiniteSet(y)) assert invert_real(Abs(x**31 + x + 1), y, x) == (x**31 + x, FiniteSet(-y - 1, y - 1)) assert invert_real(tan(x), y, x) == \ (x, imageset(Lambda(n, n*pi + atan(y)), S.Integers)) assert invert_real(tan(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + atan(y))), S.Integers)) assert invert_real(cot(x), y, x) == \ (x, imageset(Lambda(n, n*pi + acot(y)), S.Integers)) assert invert_real(cot(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + acot(y))), S.Integers)) assert invert_real(tan(tan(x)), y, x) == \ (tan(x), imageset(Lambda(n, n*pi + atan(y)), S.Integers)) x = Symbol('x', positive=True) assert invert_real(x**pi, y, x) == (x, FiniteSet(y**(1 / pi)))
def test_invert_real(): x = Symbol('x', real=True) x = Dummy(real=True) n = Symbol('n') d = Dummy() assert solveset(abs(x) - n, x) == solveset(abs(x) - d, x) == EmptySet() n = Symbol('n', real=True) assert invert_real(x + 3, y, x) == (x, FiniteSet(y - 3)) assert invert_real(x*3, y, x) == (x, FiniteSet(y / 3)) assert invert_real(exp(x), y, x) == (x, FiniteSet(log(y))) assert invert_real(exp(3*x), y, x) == (x, FiniteSet(log(y) / 3)) assert invert_real(exp(x + 3), y, x) == (x, FiniteSet(log(y) - 3)) assert invert_real(exp(x) + 3, y, x) == (x, FiniteSet(log(y - 3))) assert invert_real(exp(x)*3, y, x) == (x, FiniteSet(log(y / 3))) assert invert_real(log(x), y, x) == (x, FiniteSet(exp(y))) assert invert_real(log(3*x), y, x) == (x, FiniteSet(exp(y) / 3)) assert invert_real(log(x + 3), y, x) == (x, FiniteSet(exp(y) - 3)) assert invert_real(Abs(x), y, x) == (x, FiniteSet(-y, y)) assert invert_real(2**x, y, x) == (x, FiniteSet(log(y)/log(2))) assert invert_real(2**exp(x), y, x) == (x, FiniteSet(log(log(y)/log(2)))) assert invert_real(x**2, y, x) == (x, FiniteSet(sqrt(y), -sqrt(y))) assert invert_real(x**Rational(1, 2), y, x) == (x, FiniteSet(y**2)) raises(ValueError, lambda: invert_real(x, x, x)) raises(ValueError, lambda: invert_real(x**pi, y, x)) raises(ValueError, lambda: invert_real(S.One, y, x)) assert invert_real(x**31 + x, y, x) == (x**31 + x, FiniteSet(y)) assert invert_real(Abs(x**31 + x + 1), y, x) == (x**31 + x, FiniteSet(-y - 1, y - 1)) assert invert_real(tan(x), y, x) == \ (x, imageset(Lambda(n, n*pi + atan(y)), S.Integers)) assert invert_real(tan(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + atan(y))), S.Integers)) assert invert_real(cot(x), y, x) == \ (x, imageset(Lambda(n, n*pi + acot(y)), S.Integers)) assert invert_real(cot(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + acot(y))), S.Integers)) assert invert_real(tan(tan(x)), y, x) == \ (tan(x), imageset(Lambda(n, n*pi + atan(y)), S.Integers)) x = Symbol('x', positive=True) assert invert_real(x**pi, y, x) == (x, FiniteSet(y**(1/pi)))
def test_acot(): x = Symbol('x') r = Symbol('r', real=True) assert acot(oo) == 0 assert acot(1) == pi/4 assert acot(0) == pi/2 assert acot(x).diff(x) == -1/(1+x**2) assert acot(r).is_real == True
def test_trig_functions(self, printer, x): # Trig functions assert printer.doprint(sp.acos(x)) == 'acos(x)' assert printer.doprint(sp.acosh(x)) == 'acosh(x)' assert printer.doprint(sp.asin(x)) == 'asin(x)' assert printer.doprint(sp.asinh(x)) == 'asinh(x)' assert printer.doprint(sp.atan(x)) == 'atan(x)' assert printer.doprint(sp.atanh(x)) == 'atanh(x)' assert printer.doprint(sp.ceiling(x)) == 'ceil(x)' assert printer.doprint(sp.cos(x)) == 'cos(x)' assert printer.doprint(sp.cosh(x)) == 'cosh(x)' assert printer.doprint(sp.exp(x)) == 'exp(x)' assert printer.doprint(sp.factorial(x)) == 'factorial(x)' assert printer.doprint(sp.floor(x)) == 'floor(x)' assert printer.doprint(sp.log(x)) == 'log(x)' assert printer.doprint(sp.sin(x)) == 'sin(x)' assert printer.doprint(sp.sinh(x)) == 'sinh(x)' assert printer.doprint(sp.tan(x)) == 'tan(x)' assert printer.doprint(sp.tanh(x)) == 'tanh(x)' # extra trig functions assert printer.doprint(sp.sec(x)) == '1 / cos(x)' assert printer.doprint(sp.csc(x)) == '1 / sin(x)' assert printer.doprint(sp.cot(x)) == '1 / tan(x)' assert printer.doprint(sp.asec(x)) == 'acos(1 / x)' assert printer.doprint(sp.acsc(x)) == 'asin(1 / x)' assert printer.doprint(sp.acot(x)) == 'atan(1 / x)' assert printer.doprint(sp.sech(x)) == '1 / cosh(x)' assert printer.doprint(sp.csch(x)) == '1 / sinh(x)' assert printer.doprint(sp.coth(x)) == '1 / tanh(x)' assert printer.doprint(sp.asech(x)) == 'acosh(1 / x)' assert printer.doprint(sp.acsch(x)) == 'asinh(1 / x)' assert printer.doprint(sp.acoth(x)) == 'atanh(1 / x)'
def test_atan_rewrite(): assert atan(x).rewrite(log) == I*log((1 - I*x)/(1 + I*x))/2 assert atan(x).rewrite(asin) == (-asin(1/sqrt(x**2 + 1)) + pi/2)*sqrt(x**2)/x assert atan(x).rewrite(acos) == sqrt(x**2)*acos(1/sqrt(x**2 + 1))/x assert atan(x).rewrite(acot) == acot(1/x) assert atan(x).rewrite(asec) == sqrt(x**2)*asec(sqrt(x**2 + 1))/x assert atan(x).rewrite(acsc) == (-acsc(sqrt(x**2 + 1)) + pi/2)*sqrt(x**2)/x
def test_explicit_latex(self): test_cases = [ ('0x', Mul(0, x, evaluate=False)), ('0 = 0', Eq(0, 0)), ('0 = 1', Eq(0, 1)), ('10x = 10x', Eq(10 * x, 10 * x)), (r'\sin ^ { - 1 } ( x )', asin(x)), (r'\cos^{-1}x', acos(x)), (r'\tan^ {-1 }x', atan(x)), (r'\cot^ {-1 }x', acot(x)), (r'\sinh^{-1}(x)', asinh(x)), (r'\sqrt{-1}', I), (r'\exp{x}', exp(x)), (r'\exp(x)', exp(x)), ('e^{x}', E**x), ] failed_tests = [] for s_l_expr, expr in test_cases: l_expr = process_sympy(s_l_expr) equiv = equivalent(expr, l_expr) if not equiv: print '%s %s' % (s_l_expr, 'PASSED' if equiv else 'FAILED') failed_tests.append((s_l_expr, l_expr)) print 'sympy: %s\nlatex: %s\n' % (expr, l_expr) if failed_tests: print len(failed_tests), 'failed test cases' assert len(failed_tests) == 0
def test_asin_rewrite(): assert asin(x).rewrite(log) == -I*log(I*x + sqrt(1 - x**2)) assert asin(x).rewrite(atan) == 2*atan(x/(1 + sqrt(1 - x**2))) assert asin(x).rewrite(acos) == S.Pi/2 - acos(x) assert asin(x).rewrite(acot) == 2*acot((sqrt(-x**2 + 1) + 1)/x) assert asin(x).rewrite(asec) == -asec(1/x) + pi/2 assert asin(x).rewrite(acsc) == acsc(1/x)
def eval(cls, arg): from sympy import acot arg = sympify(arg) if arg.is_Number: if arg is S.NaN: return S.NaN elif arg is S.Infinity: return S.Zero elif arg is S.NegativeInfinity: return S.Zero elif arg is S.Zero: return S.Pi*S.ImaginaryUnit / 2 elif arg is S.One: return S.Infinity elif arg is S.NegativeOne: return S.NegativeInfinity elif arg.is_negative: return -cls(-arg) else: if arg is S.ComplexInfinity: return S.Zero i_coeff = arg.as_coefficient(S.ImaginaryUnit) if i_coeff is not None: return -S.ImaginaryUnit * acot(i_coeff) else: if _coeff_isneg(arg): return -cls(-arg)
def test_conv7(): x = Symbol("x") y = Symbol("y") assert sin(x/3) == sin(sympy.Symbol("x") / 3) assert cos(x/3) == cos(sympy.Symbol("x") / 3) assert tan(x/3) == tan(sympy.Symbol("x") / 3) assert cot(x/3) == cot(sympy.Symbol("x") / 3) assert csc(x/3) == csc(sympy.Symbol("x") / 3) assert sec(x/3) == sec(sympy.Symbol("x") / 3) assert asin(x/3) == asin(sympy.Symbol("x") / 3) assert acos(x/3) == acos(sympy.Symbol("x") / 3) assert atan(x/3) == atan(sympy.Symbol("x") / 3) assert acot(x/3) == acot(sympy.Symbol("x") / 3) assert acsc(x/3) == acsc(sympy.Symbol("x") / 3) assert asec(x/3) == asec(sympy.Symbol("x") / 3) assert sin(x/3)._sympy_() == sympy.sin(sympy.Symbol("x") / 3) assert sin(x/3)._sympy_() != sympy.cos(sympy.Symbol("x") / 3) assert cos(x/3)._sympy_() == sympy.cos(sympy.Symbol("x") / 3) assert tan(x/3)._sympy_() == sympy.tan(sympy.Symbol("x") / 3) assert cot(x/3)._sympy_() == sympy.cot(sympy.Symbol("x") / 3) assert csc(x/3)._sympy_() == sympy.csc(sympy.Symbol("x") / 3) assert sec(x/3)._sympy_() == sympy.sec(sympy.Symbol("x") / 3) assert asin(x/3)._sympy_() == sympy.asin(sympy.Symbol("x") / 3) assert acos(x/3)._sympy_() == sympy.acos(sympy.Symbol("x") / 3) assert atan(x/3)._sympy_() == sympy.atan(sympy.Symbol("x") / 3) assert acot(x/3)._sympy_() == sympy.acot(sympy.Symbol("x") / 3) assert acsc(x/3)._sympy_() == sympy.acsc(sympy.Symbol("x") / 3) assert asec(x/3)._sympy_() == sympy.asec(sympy.Symbol("x") / 3)
def test_conv7(): x = Symbol("x") y = Symbol("y") assert sin(x / 3) == sin(sympy.Symbol("x") / 3) assert cos(x / 3) == cos(sympy.Symbol("x") / 3) assert tan(x / 3) == tan(sympy.Symbol("x") / 3) assert cot(x / 3) == cot(sympy.Symbol("x") / 3) assert csc(x / 3) == csc(sympy.Symbol("x") / 3) assert sec(x / 3) == sec(sympy.Symbol("x") / 3) assert asin(x / 3) == asin(sympy.Symbol("x") / 3) assert acos(x / 3) == acos(sympy.Symbol("x") / 3) assert atan(x / 3) == atan(sympy.Symbol("x") / 3) assert acot(x / 3) == acot(sympy.Symbol("x") / 3) assert acsc(x / 3) == acsc(sympy.Symbol("x") / 3) assert asec(x / 3) == asec(sympy.Symbol("x") / 3) assert sin(x / 3)._sympy_() == sympy.sin(sympy.Symbol("x") / 3) assert sin(x / 3)._sympy_() != sympy.cos(sympy.Symbol("x") / 3) assert cos(x / 3)._sympy_() == sympy.cos(sympy.Symbol("x") / 3) assert tan(x / 3)._sympy_() == sympy.tan(sympy.Symbol("x") / 3) assert cot(x / 3)._sympy_() == sympy.cot(sympy.Symbol("x") / 3) assert csc(x / 3)._sympy_() == sympy.csc(sympy.Symbol("x") / 3) assert sec(x / 3)._sympy_() == sympy.sec(sympy.Symbol("x") / 3) assert asin(x / 3)._sympy_() == sympy.asin(sympy.Symbol("x") / 3) assert acos(x / 3)._sympy_() == sympy.acos(sympy.Symbol("x") / 3) assert atan(x / 3)._sympy_() == sympy.atan(sympy.Symbol("x") / 3) assert acot(x / 3)._sympy_() == sympy.acot(sympy.Symbol("x") / 3) assert acsc(x / 3)._sympy_() == sympy.acsc(sympy.Symbol("x") / 3) assert asec(x / 3)._sympy_() == sympy.asec(sympy.Symbol("x") / 3)
def eval(cls, arg): from sympy import acot arg = sympify(arg) if arg.is_Number: if arg is S.NaN: return S.NaN elif arg is S.Infinity: return S.Zero elif arg is S.NegativeInfinity: return S.Zero elif arg is S.Zero: return S.Pi * S.ImaginaryUnit / 2 elif arg is S.One: return S.Infinity elif arg is S.NegativeOne: return S.NegativeInfinity elif arg.is_negative: return -cls(-arg) else: if arg is S.ComplexInfinity: return S.Zero i_coeff = arg.as_coefficient(S.ImaginaryUnit) if i_coeff is not None: return -S.ImaginaryUnit * acot(i_coeff) else: if _coeff_isneg(arg): return -cls(-arg)
def test_asin_rewrite(): assert asin(x).rewrite(log) == -I * log(I * x + sqrt(1 - x**2)) assert asin(x).rewrite(atan) == 2 * atan(x / (1 + sqrt(1 - x**2))) assert asin(x).rewrite(acos) == S.Pi / 2 - acos(x) assert asin(x).rewrite(acot) == 2 * acot((sqrt(-x**2 + 1) + 1) / x) assert asin(x).rewrite(asec) == -asec(1 / x) + pi / 2 assert asin(x).rewrite(acsc) == acsc(1 / x)
def test_cot(): assert cot(nan) == nan assert cot.nargs == FiniteSet(1) assert cot(oo*I) == -I assert cot(-oo*I) == I assert cot(0) == zoo assert cot(2*pi) == zoo assert cot(acot(x)) == x assert cot(atan(x)) == 1 / x assert cot(asin(x)) == sqrt(1 - x**2) / x assert cot(acos(x)) == x / sqrt(1 - x**2) assert cot(atan2(y, x)) == x/y assert cot(pi*I) == -coth(pi)*I assert cot(-pi*I) == coth(pi)*I assert cot(-2*I) == coth(2)*I assert cot(pi) == cot(2*pi) == cot(3*pi) assert cot(-pi) == cot(-2*pi) == cot(-3*pi) assert cot(pi/2) == 0 assert cot(-pi/2) == 0 assert cot(5*pi/2) == 0 assert cot(7*pi/2) == 0 assert cot(pi/3) == 1/sqrt(3) assert cot(-2*pi/3) == 1/sqrt(3) assert cot(pi/4) == S.One assert cot(-pi/4) == -S.One assert cot(17*pi/4) == S.One assert cot(-3*pi/4) == S.One assert cot(pi/6) == sqrt(3) assert cot(-pi/6) == -sqrt(3) assert cot(7*pi/6) == sqrt(3) assert cot(-5*pi/6) == sqrt(3) assert cot(x*I) == -coth(x)*I assert cot(k*pi*I) == -coth(k*pi)*I assert cot(r).is_real is True assert cot(a).is_algebraic is None assert cot(na).is_algebraic is False assert cot(10*pi/7) == cot(3*pi/7) assert cot(11*pi/7) == -cot(3*pi/7) assert cot(-11*pi/7) == cot(3*pi/7) assert cot(x).is_finite is None assert cot(r).is_finite is None i = Symbol('i', imaginary=True) assert cot(i).is_finite is True assert cot(x).subs(x, 3*pi) == zoo
def __new__(cls, arg): obj = acot(arg) if arg.is_real: assumptions = {'real': True} ass_copy = assumptions.copy() obj._assumptions = StdFactKB(assumptions) obj._assumptions._generator = ass_copy return obj
def test_tan(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert tan(nan) == nan assert tan(oo * I) == I assert tan(-oo * I) == -I assert tan(0) == 0 assert tan(atan(x)) == x assert tan(asin(x)) == x / sqrt(1 - x**2) assert tan(acos(x)) == sqrt(1 - x**2) / x assert tan(acot(x)) == 1 / x assert tan(atan2(y, x)) == y / x assert tan(pi * I) == tanh(pi) * I assert tan(-pi * I) == -tanh(pi) * I assert tan(-2 * I) == -tanh(2) * I assert tan(pi) == 0 assert tan(-pi) == 0 assert tan(2 * pi) == 0 assert tan(-2 * pi) == 0 assert tan(-3 * 10**73 * pi) == 0 assert tan(pi / 2) == zoo assert tan(3 * pi / 2) == zoo assert tan(pi / 3) == sqrt(3) assert tan(-2 * pi / 3) == sqrt(3) assert tan(pi / 4) == S.One assert tan(-pi / 4) == -S.One assert tan(17 * pi / 4) == S.One assert tan(-3 * pi / 4) == S.One assert tan(pi / 6) == 1 / sqrt(3) assert tan(-pi / 6) == -1 / sqrt(3) assert tan(7 * pi / 6) == 1 / sqrt(3) assert tan(-5 * pi / 6) == 1 / sqrt(3) assert tan(x * I) == tanh(x) * I assert tan(k * pi) == 0 assert tan(17 * k * pi) == 0 assert tan(k * pi * I) == tanh(k * pi) * I assert tan(r).is_real == True assert tan(10 * pi / 7) == tan(3 * pi / 7) assert tan(11 * pi / 7) == -tan(3 * pi / 7) assert tan(-11 * pi / 7) == tan(3 * pi / 7)
def test_tan(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert tan(nan) == nan assert tan(oo*I) == I assert tan(-oo*I) == -I assert tan(0) == 0 assert tan(atan(x)) == x assert tan(asin(x)) == x / sqrt(1 - x**2) assert tan(acos(x)) == sqrt(1 - x**2) / x assert tan(acot(x)) == 1 / x assert tan(atan2(y, x)) == y/x assert tan(pi*I) == tanh(pi)*I assert tan(-pi*I) == -tanh(pi)*I assert tan(-2*I) == -tanh(2)*I assert tan(pi) == 0 assert tan(-pi) == 0 assert tan(2*pi) == 0 assert tan(-2*pi) == 0 assert tan(-3*10**73*pi) == 0 assert tan(pi/2) == zoo assert tan(3*pi/2) == zoo assert tan(pi/3) == sqrt(3) assert tan(-2*pi/3) == sqrt(3) assert tan(pi/4) == S.One assert tan(-pi/4) == -S.One assert tan(17*pi/4) == S.One assert tan(-3*pi/4) == S.One assert tan(pi/6) == 1/sqrt(3) assert tan(-pi/6) == -1/sqrt(3) assert tan(7*pi/6) == 1/sqrt(3) assert tan(-5*pi/6) == 1/sqrt(3) assert tan(x*I) == tanh(x)*I assert tan(k*pi) == 0 assert tan(17*k*pi) == 0 assert tan(k*pi*I) == tanh(k*pi)*I assert tan(r).is_real is True assert tan(10*pi/7) == tan(3*pi/7) assert tan(11*pi/7) == -tan(3*pi/7) assert tan(-11*pi/7) == tan(3*pi/7)
def test_as_leading_term_issue_5272(): assert sin(x).as_leading_term(x) == x assert cos(x).as_leading_term(x) == 1 assert tan(x).as_leading_term(x) == x assert cot(x).as_leading_term(x) == 1 / x assert asin(x).as_leading_term(x) == x assert acos(x).as_leading_term(x) == x assert atan(x).as_leading_term(x) == x assert acot(x).as_leading_term(x) == x
def test_tan(): assert tan(nan) == nan assert tan.nargs == FiniteSet(1) assert tan(oo*I) == I assert tan(-oo*I) == -I assert tan(0) == 0 assert tan(atan(x)) == x assert tan(asin(x)) == x / sqrt(1 - x**2) assert tan(acos(x)) == sqrt(1 - x**2) / x assert tan(acot(x)) == 1 / x assert tan(atan2(y, x)) == y/x assert tan(pi*I) == tanh(pi)*I assert tan(-pi*I) == -tanh(pi)*I assert tan(-2*I) == -tanh(2)*I assert tan(pi) == 0 assert tan(-pi) == 0 assert tan(2*pi) == 0 assert tan(-2*pi) == 0 assert tan(-3*10**73*pi) == 0 assert tan(pi/2) == zoo assert tan(3*pi/2) == zoo assert tan(pi/3) == sqrt(3) assert tan(-2*pi/3) == sqrt(3) assert tan(pi/4) == S.One assert tan(-pi/4) == -S.One assert tan(17*pi/4) == S.One assert tan(-3*pi/4) == S.One assert tan(pi/6) == 1/sqrt(3) assert tan(-pi/6) == -1/sqrt(3) assert tan(7*pi/6) == 1/sqrt(3) assert tan(-5*pi/6) == 1/sqrt(3) assert tan(x*I) == tanh(x)*I assert tan(k*pi) == 0 assert tan(17*k*pi) == 0 assert tan(k*pi*I) == tanh(k*pi)*I assert tan(r).is_real is True assert tan(0, evaluate=False).is_algebraic assert tan(a).is_algebraic is None assert tan(na).is_algebraic is False assert tan(10*pi/7) == tan(3*pi/7) assert tan(11*pi/7) == -tan(3*pi/7) assert tan(-11*pi/7) == tan(3*pi/7)
def test_as_leading_term_issue2173(): assert sin(x).as_leading_term(x) == x assert cos(x).as_leading_term(x) == 1 assert tan(x).as_leading_term(x) == x assert cot(x).as_leading_term(x) == 1/x assert asin(x).as_leading_term(x) == x assert acos(x).as_leading_term(x) == x assert atan(x).as_leading_term(x) == x assert acot(x).as_leading_term(x) == x
def test_as_leading_term_issue2173(): x = Symbol('x') assert sin(x).as_leading_term(x) == x assert cos(x).as_leading_term(x) == 1 assert tan(x).as_leading_term(x) == x assert cot(x).as_leading_term(x) == 1 / x assert asin(x).as_leading_term(x) == x assert acos(x).as_leading_term(x) == x assert atan(x).as_leading_term(x) == x assert acot(x).as_leading_term(x) == x
def test_acos_rewrite(): assert acos(x).rewrite(log) == pi/2 + I*log(I*x + sqrt(1 - x**2)) assert acos(x).rewrite(atan) == \ atan(sqrt(1 - x**2)/x) + (pi/2)*(1 - x*sqrt(1/x**2)) assert acos(0).rewrite(atan) == S.Pi/2 assert acos(0.5).rewrite(atan) == acos(0.5).rewrite(log) assert acos(x).rewrite(asin) == S.Pi/2 - asin(x) assert acos(x).rewrite(acot) == -2*acot((sqrt(-x**2 + 1) + 1)/x) + pi/2 assert acos(x).rewrite(asec) == asec(1/x) assert acos(x).rewrite(acsc) == -acsc(1/x) + pi/2
def test_cot(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert cot(nan) == nan assert cot(oo*I) == -I assert cot(-oo*I) == I assert cot(0) == zoo assert cot(2*pi) == zoo assert cot(acot(x)) == x assert cot(atan(x)) == 1 / x assert cot(asin(x)) == sqrt(1 - x**2) / x assert cot(acos(x)) == x / sqrt(1 - x**2) assert cot(atan2(y, x)) == x/y assert cot(pi*I) == -coth(pi)*I assert cot(-pi*I) == coth(pi)*I assert cot(-2*I) == coth(2)*I assert cot(pi) == cot(2*pi) == cot(3*pi) assert cot(-pi) == cot(-2*pi) == cot(-3*pi) assert cot(pi/2) == 0 assert cot(-pi/2) == 0 assert cot(5*pi/2) == 0 assert cot(7*pi/2) == 0 assert cot(pi/3) == 1/sqrt(3) assert cot(-2*pi/3) == 1/sqrt(3) assert cot(pi/4) == S.One assert cot(-pi/4) == -S.One assert cot(17*pi/4) == S.One assert cot(-3*pi/4) == S.One assert cot(pi/6) == sqrt(3) assert cot(-pi/6) == -sqrt(3) assert cot(7*pi/6) == sqrt(3) assert cot(-5*pi/6) == sqrt(3) assert cot(x*I) == -coth(x)*I assert cot(k*pi*I) == -coth(k*pi)*I assert cot(r).is_real is True assert cot(10*pi/7) == cot(3*pi/7) assert cot(11*pi/7) == -cot(3*pi/7) assert cot(-11*pi/7) == cot(3*pi/7)
def test_inverses(): raises(AttributeError, lambda: sin(x).inverse()) raises(AttributeError, lambda: cos(x).inverse()) assert tan(x).inverse() == atan assert cot(x).inverse() == acot raises(AttributeError, lambda: csc(x).inverse()) raises(AttributeError, lambda: sec(x).inverse()) assert asin(x).inverse() == sin assert acos(x).inverse() == cos assert atan(x).inverse() == tan assert acot(x).inverse() == cot
def test_cot(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert cot(nan) == nan assert cot(oo * I) == -I assert cot(-oo * I) == I assert cot(0) == zoo assert cot(2 * pi) == zoo assert cot(acot(x)) == x assert cot(atan(x)) == 1 / x assert cot(asin(x)) == sqrt(1 - x**2) / x assert cot(acos(x)) == x / sqrt(1 - x**2) assert cot(atan2(y, x)) == x / y assert cot(pi * I) == -coth(pi) * I assert cot(-pi * I) == coth(pi) * I assert cot(-2 * I) == coth(2) * I assert cot(pi) == cot(2 * pi) == cot(3 * pi) assert cot(-pi) == cot(-2 * pi) == cot(-3 * pi) assert cot(pi / 2) == 0 assert cot(-pi / 2) == 0 assert cot(5 * pi / 2) == 0 assert cot(7 * pi / 2) == 0 assert cot(pi / 3) == 1 / sqrt(3) assert cot(-2 * pi / 3) == 1 / sqrt(3) assert cot(pi / 4) == S.One assert cot(-pi / 4) == -S.One assert cot(17 * pi / 4) == S.One assert cot(-3 * pi / 4) == S.One assert cot(pi / 6) == sqrt(3) assert cot(-pi / 6) == -sqrt(3) assert cot(7 * pi / 6) == sqrt(3) assert cot(-5 * pi / 6) == sqrt(3) assert cot(x * I) == -coth(x) * I assert cot(k * pi * I) == -coth(k * pi) * I assert cot(r).is_real == True assert cot(10 * pi / 7) == cot(3 * pi / 7) assert cot(11 * pi / 7) == -cot(3 * pi / 7) assert cot(-11 * pi / 7) == cot(3 * pi / 7)
def test_acot_rewrite(): assert acot(x).rewrite(log) == I*log((x - I)/(x + I))/2 assert acot(x).rewrite(asin) == x*(-asin(sqrt(-x**2)/sqrt(-x**2 - 1)) + pi/2)*sqrt(x**(-2)) assert acot(x).rewrite(acos) == x*sqrt(x**(-2))*acos(sqrt(-x**2)/sqrt(-x**2 - 1)) assert acot(x).rewrite(atan) == atan(1/x) assert acot(x).rewrite(asec) == x*sqrt(x**(-2))*asec(sqrt((x**2 + 1)/x**2)) assert acot(x).rewrite(acsc) == x*(-acsc(sqrt((x**2 + 1)/x**2)) + pi/2)*sqrt(x**(-2))
def test_tan(): assert tan(nan) == nan assert tan(oo * I) == I assert tan(-oo * I) == -I assert tan(0) == 0 assert tan(atan(x)) == x assert tan(asin(x)) == x / sqrt(1 - x**2) assert tan(acos(x)) == sqrt(1 - x**2) / x assert tan(acot(x)) == 1 / x assert tan(atan2(y, x)) == y / x assert tan(pi * I) == tanh(pi) * I assert tan(-pi * I) == -tanh(pi) * I assert tan(-2 * I) == -tanh(2) * I assert tan(pi) == 0 assert tan(-pi) == 0 assert tan(2 * pi) == 0 assert tan(-2 * pi) == 0 assert tan(-3 * 10**73 * pi) == 0 assert tan(pi / 2) == zoo assert tan(3 * pi / 2) == zoo assert tan(pi / 3) == sqrt(3) assert tan(-2 * pi / 3) == sqrt(3) assert tan(pi / 4) == S.One assert tan(-pi / 4) == -S.One assert tan(17 * pi / 4) == S.One assert tan(-3 * pi / 4) == S.One assert tan(pi / 6) == 1 / sqrt(3) assert tan(-pi / 6) == -1 / sqrt(3) assert tan(7 * pi / 6) == 1 / sqrt(3) assert tan(-5 * pi / 6) == 1 / sqrt(3) assert tan(x * I) == tanh(x) * I assert tan(k * pi) == 0 assert tan(17 * k * pi) == 0 assert tan(k * pi * I) == tanh(k * pi) * I assert tan(r).is_real is True assert tan(10 * pi / 7) == tan(3 * pi / 7) assert tan(11 * pi / 7) == -tan(3 * pi / 7) assert tan(-11 * pi / 7) == tan(3 * pi / 7)
def test_cot(): assert cot(nan) == nan assert cot.nargs == FiniteSet(1) assert cot(oo*I) == -I assert cot(-oo*I) == I assert cot(0) == zoo assert cot(2*pi) == zoo assert cot(acot(x)) == x assert cot(atan(x)) == 1 / x assert cot(asin(x)) == sqrt(1 - x**2) / x assert cot(acos(x)) == x / sqrt(1 - x**2) assert cot(atan2(y, x)) == x/y assert cot(pi*I) == -coth(pi)*I assert cot(-pi*I) == coth(pi)*I assert cot(-2*I) == coth(2)*I assert cot(pi) == cot(2*pi) == cot(3*pi) assert cot(-pi) == cot(-2*pi) == cot(-3*pi) assert cot(pi/2) == 0 assert cot(-pi/2) == 0 assert cot(5*pi/2) == 0 assert cot(7*pi/2) == 0 assert cot(pi/3) == 1/sqrt(3) assert cot(-2*pi/3) == 1/sqrt(3) assert cot(pi/4) == S.One assert cot(-pi/4) == -S.One assert cot(17*pi/4) == S.One assert cot(-3*pi/4) == S.One assert cot(pi/6) == sqrt(3) assert cot(-pi/6) == -sqrt(3) assert cot(7*pi/6) == sqrt(3) assert cot(-5*pi/6) == sqrt(3) assert cot(x*I) == -coth(x)*I assert cot(k*pi*I) == -coth(k*pi)*I assert cot(r).is_real is True assert cot(10*pi/7) == cot(3*pi/7) assert cot(11*pi/7) == -cot(3*pi/7) assert cot(-11*pi/7) == cot(3*pi/7)
def test_conv7b(): x = sympy.Symbol("x") y = sympy.Symbol("y") assert sympify(sympy.sin(x/3)) == sin(Symbol("x") / 3) assert sympify(sympy.sin(x/3)) != cos(Symbol("x") / 3) assert sympify(sympy.cos(x/3)) == cos(Symbol("x") / 3) assert sympify(sympy.tan(x/3)) == tan(Symbol("x") / 3) assert sympify(sympy.cot(x/3)) == cot(Symbol("x") / 3) assert sympify(sympy.csc(x/3)) == csc(Symbol("x") / 3) assert sympify(sympy.sec(x/3)) == sec(Symbol("x") / 3) assert sympify(sympy.asin(x/3)) == asin(Symbol("x") / 3) assert sympify(sympy.acos(x/3)) == acos(Symbol("x") / 3) assert sympify(sympy.atan(x/3)) == atan(Symbol("x") / 3) assert sympify(sympy.acot(x/3)) == acot(Symbol("x") / 3) assert sympify(sympy.acsc(x/3)) == acsc(Symbol("x") / 3) assert sympify(sympy.asec(x/3)) == asec(Symbol("x") / 3)
def test_conv7b(): x = sympy.Symbol("x") y = sympy.Symbol("y") assert sympify(sympy.sin(x / 3)) == sin(Symbol("x") / 3) assert sympify(sympy.sin(x / 3)) != cos(Symbol("x") / 3) assert sympify(sympy.cos(x / 3)) == cos(Symbol("x") / 3) assert sympify(sympy.tan(x / 3)) == tan(Symbol("x") / 3) assert sympify(sympy.cot(x / 3)) == cot(Symbol("x") / 3) assert sympify(sympy.csc(x / 3)) == csc(Symbol("x") / 3) assert sympify(sympy.sec(x / 3)) == sec(Symbol("x") / 3) assert sympify(sympy.asin(x / 3)) == asin(Symbol("x") / 3) assert sympify(sympy.acos(x / 3)) == acos(Symbol("x") / 3) assert sympify(sympy.atan(x / 3)) == atan(Symbol("x") / 3) assert sympify(sympy.acot(x / 3)) == acot(Symbol("x") / 3) assert sympify(sympy.acsc(x / 3)) == acsc(Symbol("x") / 3) assert sympify(sympy.asec(x / 3)) == asec(Symbol("x") / 3)
def test_acsc(): assert acsc(nan) == nan assert acsc(1) == pi/2 assert acsc(-1) == -pi/2 assert acsc(oo) == 0 assert acsc(-oo) == 0 assert acsc(zoo) == 0 assert acsc(x).diff(x) == -1/(x**2*sqrt(1 - 1/x**2)) assert acsc(x).as_leading_term(x) == log(x) assert acsc(x).rewrite(log) == -I*log(sqrt(1 - 1/x**2) + I/x) assert acsc(x).rewrite(asin) == asin(1/x) assert acsc(x).rewrite(acos) == -acos(1/x) + pi/2 assert acsc(x).rewrite(atan) == (-atan(sqrt(x**2 - 1)) + pi/2)*sqrt(x**2)/x assert acsc(x).rewrite(acot) == (-acot(1/sqrt(x**2 - 1)) + pi/2)*sqrt(x**2)/x assert acsc(x).rewrite(asec) == -asec(x) + pi/2
def test_asec(): z = Symbol('z', zero=True) assert asec(z) == nan assert asec(nan) == nan assert asec(1) == 0 assert asec(-1) == pi assert asec(oo) == pi/2 assert asec(-oo) == pi/2 assert asec(zoo) == pi/2 assert asec(x).diff(x) == 1/(x**2*sqrt(1 - 1/x**2)) assert asec(x).as_leading_term(x) == log(x) assert asec(x).rewrite(log) == I*log(sqrt(1 - 1/x**2) + I/x) + pi/2 assert asec(x).rewrite(asin) == -asin(1/x) + pi/2 assert asec(x).rewrite(acos) == acos(1/x) assert asec(x).rewrite(atan) == (2*atan(x + sqrt(x**2 - 1)) - pi/2)*sqrt(x**2)/x assert asec(x).rewrite(acot) == (2*acot(x - sqrt(x**2 - 1)) - pi/2)*sqrt(x**2)/x assert asec(x).rewrite(acsc) == -acsc(x) + pi/2
def test_branch_cuts(): assert limit(asin(I * x + 2), x, 0) == pi - asin(2) assert limit(asin(I * x + 2), x, 0, '-') == asin(2) assert limit(asin(I * x - 2), x, 0) == -asin(2) assert limit(asin(I * x - 2), x, 0, '-') == -pi + asin(2) assert limit(acos(I * x + 2), x, 0) == -acos(2) assert limit(acos(I * x + 2), x, 0, '-') == acos(2) assert limit(acos(I * x - 2), x, 0) == acos(-2) assert limit(acos(I * x - 2), x, 0, '-') == 2 * pi - acos(-2) assert limit(atan(x + 2 * I), x, 0) == I * atanh(2) assert limit(atan(x + 2 * I), x, 0, '-') == -pi + I * atanh(2) assert limit(atan(x - 2 * I), x, 0) == pi - I * atanh(2) assert limit(atan(x - 2 * I), x, 0, '-') == -I * atanh(2) assert limit(atan(1 / x), x, 0) == pi / 2 assert limit(atan(1 / x), x, 0, '-') == -pi / 2 assert limit(atan(x), x, oo) == pi / 2 assert limit(atan(x), x, -oo) == -pi / 2 assert limit(acot(x + S(1) / 2 * I), x, 0) == pi - I * acoth(S(1) / 2) assert limit(acot(x + S(1) / 2 * I), x, 0, '-') == -I * acoth(S(1) / 2) assert limit(acot(x - S(1) / 2 * I), x, 0) == I * acoth(S(1) / 2) assert limit(acot(x - S(1) / 2 * I), x, 0, '-') == -pi + I * acoth(S(1) / 2) assert limit(acot(x), x, 0) == pi / 2 assert limit(acot(x), x, 0, '-') == -pi / 2 assert limit(asec(I * x + S(1) / 2), x, 0) == asec(S(1) / 2) assert limit(asec(I * x + S(1) / 2), x, 0, '-') == -asec(S(1) / 2) assert limit(asec(I * x - S(1) / 2), x, 0) == 2 * pi - asec(-S(1) / 2) assert limit(asec(I * x - S(1) / 2), x, 0, '-') == asec(-S(1) / 2) assert limit(acsc(I * x + S(1) / 2), x, 0) == acsc(S(1) / 2) assert limit(acsc(I * x + S(1) / 2), x, 0, '-') == pi - acsc(S(1) / 2) assert limit(acsc(I * x - S(1) / 2), x, 0) == -pi + acsc(S(1) / 2) assert limit(acsc(I * x - S(1) / 2), x, 0, '-') == -acsc(S(1) / 2) assert limit(log(I * x - 1), x, 0) == I * pi assert limit(log(I * x - 1), x, 0, '-') == -I * pi assert limit(log(-I * x - 1), x, 0) == -I * pi assert limit(log(-I * x - 1), x, 0, '-') == I * pi assert limit(sqrt(I * x - 1), x, 0) == I assert limit(sqrt(I * x - 1), x, 0, '-') == -I assert limit(sqrt(-I * x - 1), x, 0) == -I assert limit(sqrt(-I * x - 1), x, 0, '-') == I assert limit(cbrt(I * x - 1), x, 0) == (-1)**(S(1) / 3) assert limit(cbrt(I * x - 1), x, 0, '-') == -(-1)**(S(2) / 3) assert limit(cbrt(-I * x - 1), x, 0) == -(-1)**(S(2) / 3) assert limit(cbrt(-I * x - 1), x, 0, '-') == (-1)**(S(1) / 3)
def test_sin(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert sin(nan) == nan assert sin(oo * I) == oo * I assert sin(-oo * I) == -oo * I assert sin(oo).args[0] == oo assert sin(0) == 0 assert sin(asin(x)) == x assert sin(atan(x)) == x / sqrt(1 + x**2) assert sin(acos(x)) == sqrt(1 - x**2) assert sin(acot(x)) == 1 / (sqrt(1 + 1 / x**2) * x) assert sin(pi * I) == sinh(pi) * I assert sin(-pi * I) == -sinh(pi) * I assert sin(-2 * I) == -sinh(2) * I assert sin(pi) == 0 assert sin(-pi) == 0 assert sin(2 * pi) == 0 assert sin(-2 * pi) == 0 assert sin(-3 * 10**73 * pi) == 0 assert sin(7 * 10**103 * pi) == 0 assert sin(pi / 2) == 1 assert sin(-pi / 2) == -1 assert sin(5 * pi / 2) == 1 assert sin(7 * pi / 2) == -1 assert sin(pi / 3) == S.Half * sqrt(3) assert sin(-2 * pi / 3) == -S.Half * sqrt(3) assert sin(pi / 4) == S.Half * sqrt(2) assert sin(-pi / 4) == -S.Half * sqrt(2) assert sin(17 * pi / 4) == S.Half * sqrt(2) assert sin(-3 * pi / 4) == -S.Half * sqrt(2) assert sin(pi / 6) == S.Half assert sin(-pi / 6) == -S.Half assert sin(7 * pi / 6) == -S.Half assert sin(-5 * pi / 6) == -S.Half assert sin(1 * pi / 5) == sqrt((5 - sqrt(5)) / 8) assert sin(2 * pi / 5) == sqrt((5 + sqrt(5)) / 8) assert sin(3 * pi / 5) == sin(2 * pi / 5) assert sin(4 * pi / 5) == sin(1 * pi / 5) assert sin(6 * pi / 5) == -sin(1 * pi / 5) assert sin(8 * pi / 5) == -sin(2 * pi / 5) assert sin(-1273 * pi / 5) == -sin(2 * pi / 5) assert sin(104 * pi / 105) == sin(pi / 105) assert sin(106 * pi / 105) == -sin(pi / 105) assert sin(-104 * pi / 105) == -sin(pi / 105) assert sin(-106 * pi / 105) == sin(pi / 105) assert sin(x * I) == sinh(x) * I assert sin(k * pi) == 0 assert sin(17 * k * pi) == 0 assert sin(k * pi * I) == sinh(k * pi) * I assert sin(r).is_real == True assert isinstance(sin(re(x) - im(y)), sin) == True assert isinstance(sin(-re(x) + im(y)), sin) == False
def test_invert_real(): x = Dummy(real=True) n = Symbol('n') minus_n = Intersection(Interval(-oo, 0), FiniteSet(-n)) plus_n = Intersection(Interval(0, oo), FiniteSet(n)) assert solveset(abs(x) - n, x, S.Reals) == Union(minus_n, plus_n) n = Symbol('n', real=True) assert invert_real(x + 3, y, x) == (x, FiniteSet(y - 3)) assert invert_real(x*3, y, x) == (x, FiniteSet(y / 3)) assert invert_real(exp(x), y, x) == (x, FiniteSet(log(y))) assert invert_real(exp(3*x), y, x) == (x, FiniteSet(log(y) / 3)) assert invert_real(exp(x + 3), y, x) == (x, FiniteSet(log(y) - 3)) assert invert_real(exp(x) + 3, y, x) == (x, FiniteSet(log(y - 3))) assert invert_real(exp(x)*3, y, x) == (x, FiniteSet(log(y / 3))) assert invert_real(log(x), y, x) == (x, FiniteSet(exp(y))) assert invert_real(log(3*x), y, x) == (x, FiniteSet(exp(y) / 3)) assert invert_real(log(x + 3), y, x) == (x, FiniteSet(exp(y) - 3)) minus_y = Intersection(Interval(-oo, 0), FiniteSet(-y)) plus_y = Intersection(Interval(0, oo), FiniteSet(y)) assert invert_real(Abs(x), y, x) == (x, Union(minus_y, plus_y)) assert invert_real(2**x, y, x) == (x, FiniteSet(log(y)/log(2))) assert invert_real(2**exp(x), y, x) == (x, FiniteSet(log(log(y)/log(2)))) assert invert_real(x**2, y, x) == (x, FiniteSet(sqrt(y), -sqrt(y))) assert invert_real(x**Rational(1, 2), y, x) == (x, FiniteSet(y**2)) raises(ValueError, lambda: invert_real(x, x, x)) raises(ValueError, lambda: invert_real(x**pi, y, x)) raises(ValueError, lambda: invert_real(S.One, y, x)) assert invert_real(x**31 + x, y, x) == (x**31 + x, FiniteSet(y)) y_1 = Intersection(Interval(-1, oo), FiniteSet(y - 1)) y_2 = Intersection(Interval(-oo, -1), FiniteSet(-y - 1)) assert invert_real(Abs(x**31 + x + 1), y, x) == (x**31 + x, Union(y_1, y_2)) assert invert_real(sin(x), y, x) == \ (x, imageset(Lambda(n, n*pi + (-1)**n*asin(y)), S.Integers)) assert invert_real(sin(exp(x)), y, x) == \ (x, imageset(Lambda(n, log((-1)**n*asin(y) + n*pi)), S.Integers)) assert invert_real(csc(x), y, x) == \ (x, imageset(Lambda(n, n*pi + (-1)**n*acsc(y)), S.Integers)) assert invert_real(csc(exp(x)), y, x) == \ (x, imageset(Lambda(n, log((-1)**n*acsc(y) + n*pi)), S.Integers)) assert invert_real(cos(x), y, x) == \ (x, Union(imageset(Lambda(n, 2*n*pi + acos(y)), S.Integers), \ imageset(Lambda(n, 2*n*pi - acos(y)), S.Integers))) assert invert_real(cos(exp(x)), y, x) == \ (x, Union(imageset(Lambda(n, log(2*n*pi + acos(y))), S.Integers), \ imageset(Lambda(n, log(2*n*pi - acos(y))), S.Integers))) assert invert_real(sec(x), y, x) == \ (x, Union(imageset(Lambda(n, 2*n*pi + asec(y)), S.Integers), \ imageset(Lambda(n, 2*n*pi - asec(y)), S.Integers))) assert invert_real(sec(exp(x)), y, x) == \ (x, Union(imageset(Lambda(n, log(2*n*pi + asec(y))), S.Integers), \ imageset(Lambda(n, log(2*n*pi - asec(y))), S.Integers))) assert invert_real(tan(x), y, x) == \ (x, imageset(Lambda(n, n*pi + atan(y)), S.Integers)) assert invert_real(tan(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + atan(y))), S.Integers)) assert invert_real(cot(x), y, x) == \ (x, imageset(Lambda(n, n*pi + acot(y)), S.Integers)) assert invert_real(cot(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + acot(y))), S.Integers)) assert invert_real(tan(tan(x)), y, x) == \ (tan(x), imageset(Lambda(n, n*pi + atan(y)), S.Integers)) x = Symbol('x', positive=True) assert invert_real(x**pi, y, x) == (x, FiniteSet(y**(1/pi))) # Test for ``set_h`` containing information about the domain n = Dummy('n') x = Symbol('x') h1 = Intersection(Interval(-3, oo), FiniteSet(a + b - 3), imageset(Lambda(n, -n + a - 3), Interval(-oo, 0))) h2 = Intersection(Interval(-oo, -3), FiniteSet(-a + b - 3), imageset(Lambda(n, n - a - 3), Interval(0, oo))) h3 = Intersection(Interval(-3, oo), FiniteSet(a - b - 3), imageset(Lambda(n, -n + a - 3), Interval(0, oo))) h4 = Intersection(Interval(-oo, -3), FiniteSet(-a - b - 3), imageset(Lambda(n, n - a - 3), Interval(-oo, 0))) assert invert_real(Abs(Abs(x + 3) - a) - b, 0, x) == (x, Union(h1, h2, h3, h4))
def test_aseries_trig(): assert cancel( gruntz(1 / log(atan(x)), x, oo) - 1 / (log(pi) + log(S.Half))) == 0 assert gruntz(1 / acot(x), x, -oo) is -oo
def test_invert_real(): x = Symbol('x', real=True) y = Symbol('y') n = Symbol('n') def ireal(x, s=S.Reals): return Intersection(s, x) minus_n = Intersection(Interval(-oo, 0), FiniteSet(-n)) plus_n = Intersection(Interval(0, oo), FiniteSet(n)) assert solveset(abs(x) - n, x, S.Reals) == Union(minus_n, plus_n) assert invert_real(exp(x), y, x) == (x, ireal(FiniteSet(log(y)))) y = Symbol('y', positive=True) n = Symbol('n', real=True) assert invert_real(x + 3, y, x) == (x, FiniteSet(y - 3)) assert invert_real(x * 3, y, x) == (x, FiniteSet(y / 3)) assert invert_real(exp(x), y, x) == (x, FiniteSet(log(y))) assert invert_real(exp(3 * x), y, x) == (x, FiniteSet(log(y) / 3)) assert invert_real(exp(x + 3), y, x) == (x, FiniteSet(log(y) - 3)) assert invert_real(exp(x) + 3, y, x) == (x, ireal(FiniteSet(log(y - 3)))) assert invert_real(exp(x) * 3, y, x) == (x, FiniteSet(log(y / 3))) assert invert_real(log(x), y, x) == (x, FiniteSet(exp(y))) assert invert_real(log(3 * x), y, x) == (x, FiniteSet(exp(y) / 3)) assert invert_real(log(x + 3), y, x) == (x, FiniteSet(exp(y) - 3)) minus_y = Intersection(Interval(-oo, 0), FiniteSet(-y)) plus_y = Intersection(Interval(0, oo), FiniteSet(y)) assert invert_real(Abs(x), y, x) == (x, Union(minus_y, plus_y)) assert invert_real(2**x, y, x) == (x, FiniteSet(log(y) / log(2))) assert invert_real(2**exp(x), y, x) == (x, ireal(FiniteSet(log(log(y) / log(2))))) assert invert_real(x**2, y, x) == (x, FiniteSet(sqrt(y), -sqrt(y))) assert invert_real(x**Rational(1, 2), y, x) == (x, FiniteSet(y**2)) raises(ValueError, lambda: invert_real(x, x, x)) raises(ValueError, lambda: invert_real(x**pi, y, x)) raises(ValueError, lambda: invert_real(S.One, y, x)) assert invert_real(x**31 + x, y, x) == (x**31 + x, FiniteSet(y)) y_1 = Intersection(Interval(-1, oo), FiniteSet(y - 1)) y_2 = Intersection(Interval(-oo, -1), FiniteSet(-y - 1)) assert invert_real(Abs(x**31 + x + 1), y, x) == (x**31 + x, Union(y_1, y_2)) assert invert_real(sin(x), y, x) == \ (x, imageset(Lambda(n, n*pi + (-1)**n*asin(y)), S.Integers)) assert invert_real(sin(exp(x)), y, x) == \ (x, imageset(Lambda(n, log((-1)**n*asin(y) + n*pi)), S.Integers)) assert invert_real(csc(x), y, x) == \ (x, imageset(Lambda(n, n*pi + (-1)**n*acsc(y)), S.Integers)) assert invert_real(csc(exp(x)), y, x) == \ (x, imageset(Lambda(n, log((-1)**n*acsc(y) + n*pi)), S.Integers)) assert invert_real(cos(x), y, x) == \ (x, Union(imageset(Lambda(n, 2*n*pi + acos(y)), S.Integers), \ imageset(Lambda(n, 2*n*pi - acos(y)), S.Integers))) assert invert_real(cos(exp(x)), y, x) == \ (x, Union(imageset(Lambda(n, log(2*n*pi + acos(y))), S.Integers), \ imageset(Lambda(n, log(2*n*pi - acos(y))), S.Integers))) assert invert_real(sec(x), y, x) == \ (x, Union(imageset(Lambda(n, 2*n*pi + asec(y)), S.Integers), \ imageset(Lambda(n, 2*n*pi - asec(y)), S.Integers))) assert invert_real(sec(exp(x)), y, x) == \ (x, Union(imageset(Lambda(n, log(2*n*pi + asec(y))), S.Integers), \ imageset(Lambda(n, log(2*n*pi - asec(y))), S.Integers))) assert invert_real(tan(x), y, x) == \ (x, imageset(Lambda(n, n*pi + atan(y)), S.Integers)) assert invert_real(tan(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + atan(y))), S.Integers)) assert invert_real(cot(x), y, x) == \ (x, imageset(Lambda(n, n*pi + acot(y)), S.Integers)) assert invert_real(cot(exp(x)), y, x) == \ (x, imageset(Lambda(n, log(n*pi + acot(y))), S.Integers)) assert invert_real(tan(tan(x)), y, x) == \ (tan(x), imageset(Lambda(n, n*pi + atan(y)), S.Integers)) x = Symbol('x', positive=True) assert invert_real(x**pi, y, x) == (x, FiniteSet(y**(1 / pi))) # Test for ``set_h`` containing information about the domain n = Dummy('n') x = Symbol('x') h1 = Intersection(Interval(-oo, -3), FiniteSet(-a + b - 3), imageset(Lambda(n, n - a - 3), Interval(0, oo))) h2 = Intersection(Interval(-3, oo), FiniteSet(a - b - 3), imageset(Lambda(n, -n + a - 3), Interval(0, oo))) assert invert_real(Abs(Abs(x + 3) - a) - b, 0, x) == (x, Union(h1, h2))
def test_sin(): x, y = symbols('x y') assert sin.nargs == FiniteSet(1) assert sin(nan) == nan assert sin(oo*I) == oo*I assert sin(-oo*I) == -oo*I assert sin(oo).args[0] == oo assert sin(0) == 0 assert sin(asin(x)) == x assert sin(atan(x)) == x / sqrt(1 + x**2) assert sin(acos(x)) == sqrt(1 - x**2) assert sin(acot(x)) == 1 / (sqrt(1 + 1 / x**2) * x) assert sin(atan2(y, x)) == y / sqrt(x**2 + y**2) assert sin(pi*I) == sinh(pi)*I assert sin(-pi*I) == -sinh(pi)*I assert sin(-2*I) == -sinh(2)*I assert sin(pi) == 0 assert sin(-pi) == 0 assert sin(2*pi) == 0 assert sin(-2*pi) == 0 assert sin(-3*10**73*pi) == 0 assert sin(7*10**103*pi) == 0 assert sin(pi/2) == 1 assert sin(-pi/2) == -1 assert sin(5*pi/2) == 1 assert sin(7*pi/2) == -1 ne = symbols('ne', integer=True, even=False) e = symbols('e', even=True) assert sin(pi*ne/2) == (-1)**(ne/2 - S.Half) assert sin(pi*k/2).func == sin assert sin(pi*e/2) == 0 assert sin(pi*k) == 0 assert sin(pi*k).subs(k, 3) == sin(pi*k/2).subs(k, 6) # issue 8298 assert sin(pi/3) == S.Half*sqrt(3) assert sin(-2*pi/3) == -S.Half*sqrt(3) assert sin(pi/4) == S.Half*sqrt(2) assert sin(-pi/4) == -S.Half*sqrt(2) assert sin(17*pi/4) == S.Half*sqrt(2) assert sin(-3*pi/4) == -S.Half*sqrt(2) assert sin(pi/6) == S.Half assert sin(-pi/6) == -S.Half assert sin(7*pi/6) == -S.Half assert sin(-5*pi/6) == -S.Half assert sin(1*pi/5) == sqrt((5 - sqrt(5)) / 8) assert sin(2*pi/5) == sqrt((5 + sqrt(5)) / 8) assert sin(3*pi/5) == sin(2*pi/5) assert sin(4*pi/5) == sin(1*pi/5) assert sin(6*pi/5) == -sin(1*pi/5) assert sin(8*pi/5) == -sin(2*pi/5) assert sin(-1273*pi/5) == -sin(2*pi/5) assert sin(pi/8) == sqrt((2 - sqrt(2))/4) assert sin(104*pi/105) == sin(pi/105) assert sin(106*pi/105) == -sin(pi/105) assert sin(-104*pi/105) == -sin(pi/105) assert sin(-106*pi/105) == sin(pi/105) assert sin(x*I) == sinh(x)*I assert sin(k*pi) == 0 assert sin(17*k*pi) == 0 assert sin(k*pi*I) == sinh(k*pi)*I assert sin(r).is_real is True assert sin(0, evaluate=False).is_algebraic assert sin(a).is_algebraic is None assert sin(na).is_algebraic is False q = Symbol('q', rational=True) assert sin(pi*q).is_algebraic qn = Symbol('qn', rational=True, nonzero=True) assert sin(qn).is_rational is False assert sin(q).is_rational is None # issue 8653 assert isinstance(sin( re(x) - im(y)), sin) is True assert isinstance(sin(-re(x) + im(y)), sin) is False for d in list(range(1, 22)) + [60, 85]: for n in xrange(0, d*2 + 1): x = n*pi/d e = abs( float(sin(x)) - sin(float(x)) ) assert e < 1e-12
def test_cos(): x, y = symbols('x y') assert cos.nargs == FiniteSet(1) assert cos(nan) == nan assert cos(oo*I) == oo assert cos(-oo*I) == oo assert cos(0) == 1 assert cos(acos(x)) == x assert cos(atan(x)) == 1 / sqrt(1 + x**2) assert cos(asin(x)) == sqrt(1 - x**2) assert cos(acot(x)) == 1 / sqrt(1 + 1 / x**2) assert cos(atan2(y, x)) == x / sqrt(x**2 + y**2) assert cos(pi*I) == cosh(pi) assert cos(-pi*I) == cosh(pi) assert cos(-2*I) == cosh(2) assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos((-3*10**73 + 1)*pi/2) == 0 assert cos((7*10**103 + 1)*pi/2) == 0 n = symbols('n', integer=True, even=False) e = symbols('e', even=True) assert cos(pi*n/2) == 0 assert cos(pi*e/2) == (-1)**(e/2) assert cos(pi) == -1 assert cos(-pi) == -1 assert cos(2*pi) == 1 assert cos(5*pi) == -1 assert cos(8*pi) == 1 assert cos(pi/3) == S.Half assert cos(-2*pi/3) == -S.Half assert cos(pi/4) == S.Half*sqrt(2) assert cos(-pi/4) == S.Half*sqrt(2) assert cos(11*pi/4) == -S.Half*sqrt(2) assert cos(-3*pi/4) == -S.Half*sqrt(2) assert cos(pi/6) == S.Half*sqrt(3) assert cos(-pi/6) == S.Half*sqrt(3) assert cos(7*pi/6) == -S.Half*sqrt(3) assert cos(-5*pi/6) == -S.Half*sqrt(3) assert cos(1*pi/5) == (sqrt(5) + 1)/4 assert cos(2*pi/5) == (sqrt(5) - 1)/4 assert cos(3*pi/5) == -cos(2*pi/5) assert cos(4*pi/5) == -cos(1*pi/5) assert cos(6*pi/5) == -cos(1*pi/5) assert cos(8*pi/5) == cos(2*pi/5) assert cos(-1273*pi/5) == -cos(2*pi/5) assert cos(pi/8) == sqrt((2 + sqrt(2))/4) assert cos(104*pi/105) == -cos(pi/105) assert cos(106*pi/105) == -cos(pi/105) assert cos(-104*pi/105) == -cos(pi/105) assert cos(-106*pi/105) == -cos(pi/105) assert cos(x*I) == cosh(x) assert cos(k*pi*I) == cosh(k*pi) assert cos(r).is_real is True assert cos(0, evaluate=False).is_algebraic assert cos(a).is_algebraic is None assert cos(na).is_algebraic is False q = Symbol('q', rational=True) assert cos(pi*q).is_algebraic assert cos(2*pi/7).is_algebraic assert cos(k*pi) == (-1)**k assert cos(2*k*pi) == 1 for d in list(range(1, 22)) + [60, 85]: for n in xrange(0, 2*d + 1): x = n*pi/d e = abs( float(cos(x)) - cos(float(x)) ) assert e < 1e-12
def test_acot(): x = Symbol('x') r = Symbol('r', real=True) assert acot(nan) == nan assert acot(-oo) == 0 assert acot(oo) == 0 assert acot(1) == pi / 4 assert acot(0) == pi / 2 assert acot(sqrt(3) / 3) == pi / 3 assert acot(1 / sqrt(3)) == pi / 3 assert acot(-1 / sqrt(3)) == -pi / 3 assert acot(x).diff(x) == -1 / (1 + x**2) assert acot(r).is_real == True assert acot(I * pi) == -I * acoth(pi) assert acot(-2 * I) == I * acoth(2)
def test_aseries_trig(): assert cancel(gruntz(1/log(atan(x)), x, oo) - 1/(log(pi) + log(S(1)/2))) == 0 assert gruntz(1/acot(x), x, -oo) == -oo
def test_acot_rewrite(): x = Symbol('x') assert acot(x).rewrite(log) == I * log((x - I) / (x + I)) / 2
def test_acot_rewrite(): assert acot(x).rewrite(log) == I*log((x - I)/(x + I))/2
def test_cos(): x, y = symbols('x y') assert cos(nan) == nan assert cos(oo*I) == oo assert cos(-oo*I) == oo assert cos(0) == 1 assert cos(acos(x)) == x assert cos(atan(x)) == 1 / sqrt(1 + x**2) assert cos(asin(x)) == sqrt(1 - x**2) assert cos(acot(x)) == 1 / sqrt(1 + 1 / x**2) assert cos(atan2(y, x)) == x / sqrt(x**2 + y**2) assert cos(pi*I) == cosh(pi) assert cos(-pi*I) == cosh(pi) assert cos(-2*I) == cosh(2) assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos((-3*10**73 + 1)*pi/2) == 0 assert cos((7*10**103 + 1)*pi/2) == 0 assert cos(pi) == -1 assert cos(-pi) == -1 assert cos(2*pi) == 1 assert cos(5*pi) == -1 assert cos(8*pi) == 1 assert cos(pi/3) == S.Half assert cos(-2*pi/3) == -S.Half assert cos(pi/4) == S.Half*sqrt(2) assert cos(-pi/4) == S.Half*sqrt(2) assert cos(11*pi/4) == -S.Half*sqrt(2) assert cos(-3*pi/4) == -S.Half*sqrt(2) assert cos(pi/6) == S.Half*sqrt(3) assert cos(-pi/6) == S.Half*sqrt(3) assert cos(7*pi/6) == -S.Half*sqrt(3) assert cos(-5*pi/6) == -S.Half*sqrt(3) assert cos(1*pi/5) == (sqrt(5) + 1)/4 assert cos(2*pi/5) == (sqrt(5) - 1)/4 assert cos(3*pi/5) == -cos(2*pi/5) assert cos(4*pi/5) == -cos(1*pi/5) assert cos(6*pi/5) == -cos(1*pi/5) assert cos(8*pi/5) == cos(2*pi/5) assert cos(-1273*pi/5) == -cos(2*pi/5) assert cos(pi/8) == sqrt((2 + sqrt(2))/4) assert cos(104*pi/105) == -cos(pi/105) assert cos(106*pi/105) == -cos(pi/105) assert cos(-104*pi/105) == -cos(pi/105) assert cos(-106*pi/105) == -cos(pi/105) assert cos(x*I) == cosh(x) assert cos(k*pi*I) == cosh(k*pi) assert cos(r).is_real is True assert cos(k*pi) == (-1)**k assert cos(2*k*pi) == 1 for d in range(1, 22) + [60, 85]: for n in xrange(0, 2*d + 1): x = n*pi/d e = abs( float(cos(x)) - cos(float(x)) ) assert e < 1e-12
def test_acot(): x = Symbol('x') r = Symbol('r', real=True) assert acot(nan) == nan assert acot(-oo) == 0 assert acot(oo) == 0 assert acot(1) == pi/4 assert acot(0) == pi/2 assert acot(sqrt(3)/3) == pi/3 assert acot(1/sqrt(3)) == pi/3 assert acot(-1/sqrt(3)) == -pi/3 assert acot(x).diff(x) == -1/(1+x**2) assert acot(r).is_real == True assert acot(I*pi) == -I*acoth(pi) assert acot(-2*I) == I*acoth(2)
def test_cos(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert cos(nan) == nan assert cos(oo*I) == oo assert cos(-oo*I) == oo assert cos(0) == 1 assert cos(acos(x)) == x assert cos(atan(x)) == 1 / sqrt(1 + x**2) assert cos(asin(x)) == sqrt(1 - x**2) assert cos(acot(x)) == 1 / sqrt(1 + 1 / x**2) assert cos(pi*I) == cosh(pi) assert cos(-pi*I) == cosh(pi) assert cos(-2*I) == cosh(2) assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos(pi/2) == 0 assert cos(-pi/2) == 0 assert cos((-3*10**73+1)*pi/2) == 0 assert cos((7*10**103+1)*pi/2) == 0 assert cos(pi) == -1 assert cos(-pi) == -1 assert cos(2*pi)==1 assert cos(5*pi) == -1 assert cos(8*pi) == 1 assert cos(pi/3) == S.Half assert cos(-2*pi/3) == -S.Half assert cos(pi/4) == S.Half*sqrt(2) assert cos(-pi/4) == S.Half*sqrt(2) assert cos(11*pi/4) == -S.Half*sqrt(2) assert cos(-3*pi/4) == -S.Half*sqrt(2) assert cos(pi/6) == S.Half*sqrt(3) assert cos(-pi/6) == S.Half*sqrt(3) assert cos(7*pi/6) == -S.Half*sqrt(3) assert cos(-5*pi/6) == -S.Half*sqrt(3) assert cos(1*pi/5) == (sqrt(5) + 1)/4 assert cos(2*pi/5) == (sqrt(5) - 1)/4 assert cos(3*pi/5) == -cos(2*pi/5) assert cos(4*pi/5) == -cos(1*pi/5) assert cos(6*pi/5) == -cos(1*pi/5) assert cos(8*pi/5) == cos(2*pi/5) assert cos(-1273*pi/5) == -cos(2*pi/5) assert cos(104*pi/105) == -cos(pi/105) assert cos(106*pi/105) == -cos(pi/105) assert cos(-104*pi/105) == -cos(pi/105) assert cos(-106*pi/105) == -cos(pi/105) assert cos(x*I) == cosh(x) assert cos(k*pi*I) == cosh(k*pi) assert cos(r).is_real == True
def test_sin(): x, y = symbols('x,y') r = Symbol('r', real=True) k = Symbol('k', integer=True) assert sin(nan) == nan assert sin(oo*I) == oo*I assert sin(-oo*I) == -oo*I assert sin(oo).args[0] == oo assert sin(0) == 0 assert sin(asin(x)) == x assert sin(atan(x)) == x / sqrt(1 + x**2) assert sin(acos(x)) == sqrt(1 - x**2) assert sin(acot(x)) == 1 / (sqrt(1 + 1 / x**2) * x) assert sin(pi*I) == sinh(pi)*I assert sin(-pi*I) == -sinh(pi)*I assert sin(-2*I) == -sinh(2)*I assert sin(pi) == 0 assert sin(-pi) == 0 assert sin(2*pi) == 0 assert sin(-2*pi) == 0 assert sin(-3*10**73*pi) == 0 assert sin(7*10**103*pi) == 0 assert sin(pi/2) == 1 assert sin(-pi/2) == -1 assert sin(5*pi/2) == 1 assert sin(7*pi/2) == -1 assert sin(pi/3) == S.Half*sqrt(3) assert sin(-2*pi/3) == -S.Half*sqrt(3) assert sin(pi/4) == S.Half*sqrt(2) assert sin(-pi/4) == -S.Half*sqrt(2) assert sin(17*pi/4) == S.Half*sqrt(2) assert sin(-3*pi/4) == -S.Half*sqrt(2) assert sin(pi/6) == S.Half assert sin(-pi/6) == -S.Half assert sin(7*pi/6) == -S.Half assert sin(-5*pi/6) == -S.Half assert sin(1*pi/5) == sqrt((5 - sqrt(5)) / 8) assert sin(2*pi/5) == sqrt((5 + sqrt(5)) / 8) assert sin(3*pi/5) == sin(2*pi/5) assert sin(4*pi/5) == sin(1*pi/5) assert sin(6*pi/5) == -sin(1*pi/5) assert sin(8*pi/5) == -sin(2*pi/5) assert sin(-1273*pi/5) == -sin(2*pi/5) assert sin(104*pi/105) == sin(pi/105) assert sin(106*pi/105) == -sin(pi/105) assert sin(-104*pi/105) == -sin(pi/105) assert sin(-106*pi/105) == sin(pi/105) assert sin(x*I) == sinh(x)*I assert sin(k*pi) == 0 assert sin(17*k*pi) == 0 assert sin(k*pi*I) == sinh(k*pi)*I assert sin(r).is_real == True
def test_sin(): x, y = symbols('x y') assert sin(nan) == nan assert sin(oo*I) == oo*I assert sin(-oo*I) == -oo*I assert sin(oo).args[0] == oo assert sin(0) == 0 assert sin(asin(x)) == x assert sin(atan(x)) == x / sqrt(1 + x**2) assert sin(acos(x)) == sqrt(1 - x**2) assert sin(acot(x)) == 1 / (sqrt(1 + 1 / x**2) * x) assert sin(atan2(y, x)) == y / sqrt(x**2 + y**2) assert sin(pi*I) == sinh(pi)*I assert sin(-pi*I) == -sinh(pi)*I assert sin(-2*I) == -sinh(2)*I assert sin(pi) == 0 assert sin(-pi) == 0 assert sin(2*pi) == 0 assert sin(-2*pi) == 0 assert sin(-3*10**73*pi) == 0 assert sin(7*10**103*pi) == 0 assert sin(pi/2) == 1 assert sin(-pi/2) == -1 assert sin(5*pi/2) == 1 assert sin(7*pi/2) == -1 assert sin(pi/3) == S.Half*sqrt(3) assert sin(-2*pi/3) == -S.Half*sqrt(3) assert sin(pi/4) == S.Half*sqrt(2) assert sin(-pi/4) == -S.Half*sqrt(2) assert sin(17*pi/4) == S.Half*sqrt(2) assert sin(-3*pi/4) == -S.Half*sqrt(2) assert sin(pi/6) == S.Half assert sin(-pi/6) == -S.Half assert sin(7*pi/6) == -S.Half assert sin(-5*pi/6) == -S.Half assert sin(1*pi/5) == sqrt((5 - sqrt(5)) / 8) assert sin(2*pi/5) == sqrt((5 + sqrt(5)) / 8) assert sin(3*pi/5) == sin(2*pi/5) assert sin(4*pi/5) == sin(1*pi/5) assert sin(6*pi/5) == -sin(1*pi/5) assert sin(8*pi/5) == -sin(2*pi/5) assert sin(-1273*pi/5) == -sin(2*pi/5) assert sin(pi/8) == sqrt((2 - sqrt(2))/4) assert sin(104*pi/105) == sin(pi/105) assert sin(106*pi/105) == -sin(pi/105) assert sin(-104*pi/105) == -sin(pi/105) assert sin(-106*pi/105) == sin(pi/105) assert sin(x*I) == sinh(x)*I assert sin(k*pi) == 0 assert sin(17*k*pi) == 0 assert sin(k*pi*I) == sinh(k*pi)*I assert sin(r).is_real is True assert isinstance(sin( re(x) - im(y)), sin) is True assert isinstance(sin(-re(x) + im(y)), sin) is False for d in range(1, 22) + [60, 85]: for n in xrange(0, d*2 + 1): x = n*pi/d e = abs( float(sin(x)) - sin(float(x)) ) assert e < 1e-12
def test_acot_rewrite(): x = Symbol('x') assert acot(x).rewrite(log) == I*log((x - I)/(x + I))/2
def test_acot(): assert acot(nan) == nan assert acot.nargs == FiniteSet(1) assert acot(-oo) == 0 assert acot(oo) == 0 assert acot(1) == pi/4 assert acot(0) == pi/2 assert acot(sqrt(3)/3) == pi/3 assert acot(1/sqrt(3)) == pi/3 assert acot(-1/sqrt(3)) == -pi/3 assert acot(x).diff(x) == -1/(1 + x**2) assert acot(r).is_real is True assert acot(I*pi) == -I*acoth(pi) assert acot(-2*I) == I*acoth(2) assert acot(x).is_positive is None assert acot(r).is_positive is True assert acot(p).is_positive is True assert acot(I).is_positive is False