예제 #1
0
    def _ln(self):
        """Returns the natural logarithm of the quaternion (_ln(q)).

        Examples
        ========

        >>> from sympy import Quaternion
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q._ln()
        log(sqrt(30))
        + 2*sqrt(29)*acos(sqrt(30)/30)/29*i
        + 3*sqrt(29)*acos(sqrt(30)/30)/29*j
        + 4*sqrt(29)*acos(sqrt(30)/30)/29*k

        """
        # _ln(q) = _ln||q|| + v/||v||*arccos(a/||q||)
        q = self
        vector_norm = sqrt(q.b**2 + q.c**2 + q.d**2)
        q_norm = q.norm()
        a = ln(q_norm)
        b = q.b * acos(q.a / q_norm) / vector_norm
        c = q.c * acos(q.a / q_norm) / vector_norm
        d = q.d * acos(q.a / q_norm) / vector_norm

        return Quaternion(a, b, c, d)
예제 #2
0
def test_quaternion_conversions():
    q1 = Quaternion(1, 2, 3, 4)

    assert q1.to_axis_angle() == ((2 * sqrt(29)/29,
                                   3 * sqrt(29)/29,
                                   4 * sqrt(29)/29),
                                   2 * acos(sqrt(30)/30))

    assert q1.to_rotation_matrix() == Matrix([[Rational(-2, 3), Rational(2, 15), Rational(11, 15)],
                                              [Rational(2, 3), Rational(-1, 3), Rational(2, 3)],
                                              [Rational(1, 3), Rational(14, 15), Rational(2, 15)]])

    assert q1.to_rotation_matrix((1, 1, 1)) == Matrix([[Rational(-2, 3), Rational(2, 15), Rational(11, 15), Rational(4, 5)],
                                                       [Rational(2, 3), Rational(-1, 3), Rational(2, 3), S.Zero],
                                                       [Rational(1, 3), Rational(14, 15), Rational(2, 15), Rational(-2, 5)],
                                                       [S.Zero, S.Zero, S.Zero, S.One]])

    theta = symbols("theta", real=True)
    q2 = Quaternion(cos(theta/2), 0, 0, sin(theta/2))

    assert trigsimp(q2.to_rotation_matrix()) == Matrix([
                                               [cos(theta), -sin(theta), 0],
                                               [sin(theta),  cos(theta), 0],
                                               [0,           0,          1]])

    assert q2.to_axis_angle() == ((0, 0, sin(theta/2)/Abs(sin(theta/2))),
                                   2*acos(cos(theta/2)))

    assert trigsimp(q2.to_rotation_matrix((1, 1, 1))) == Matrix([
               [cos(theta), -sin(theta), 0, sin(theta) - cos(theta) + 1],
               [sin(theta),  cos(theta), 0, -sin(theta) - cos(theta) + 1],
               [0,           0,          1,  0],
               [0,           0,          0,  1]])
예제 #3
0
def test_heurisch_trigonometric():
    assert heurisch(sin(x), x) == -cos(x)
    assert heurisch(pi * sin(x) + 1, x) == x - pi * cos(x)

    assert heurisch(cos(x), x) == sin(x)
    assert heurisch(tan(x), x) in [
        log(1 + tan(x)**2) / 2,
        log(tan(x) + I) + I * x,
        log(tan(x) - I) - I * x,
    ]

    assert heurisch(sin(x) * sin(y), x) == -cos(x) * sin(y)
    assert heurisch(sin(x) * sin(y), y) == -cos(y) * sin(x)

    # gives sin(x) in answer when run via setup.py and cos(x) when run via py.test
    assert heurisch(sin(x) * cos(x), x) in [sin(x)**2 / 2, -cos(x)**2 / 2]
    assert heurisch(cos(x) / sin(x), x) == log(sin(x))

    assert heurisch(x * sin(7 * x), x) == sin(7 * x) / 49 - x * cos(7 * x) / 7
    assert heurisch(
        1 / pi / 4 * x**2 * cos(x),
        x) == 1 / pi / 4 * (x**2 * sin(x) - 2 * sin(x) + 2 * x * cos(x))

    assert heurisch(acos(x/4) * asin(x/4), x) == 2*x - (sqrt(16 - x**2))*asin(x/4) \
        + (sqrt(16 - x**2))*acos(x/4) + x*asin(x/4)*acos(x/4)

    assert heurisch(sin(x) / (cos(x)**2 + 1),
                    x) == -atan(cos(x))  #fixes issue 13723
    assert heurisch(1 / (cos(x) + 2),
                    x) == 2 * sqrt(3) * atan(sqrt(3) * tan(x / 2) / 3) / 3
    assert heurisch(
        2 * sin(x) * cos(x) / (sin(x)**4 + 1),
        x) == atan(sqrt(2) * sin(x) - 1) - atan(sqrt(2) * sin(x) + 1)

    assert heurisch(1 / cosh(x), x) == 2 * atan(tanh(x / 2))
예제 #4
0
def test_issue_2850():
    assert manualintegrate(asin(x)*log(x), x) == -x*asin(x) - sqrt(-x**2 + 1) \
            + (x*asin(x) + sqrt(-x**2 + 1))*log(x) - Integral(sqrt(-x**2 + 1)/x, x)
    assert manualintegrate(acos(x)*log(x), x) == -x*acos(x) + sqrt(-x**2 + 1) + \
        (x*acos(x) - sqrt(-x**2 + 1))*log(x) + Integral(sqrt(-x**2 + 1)/x, x)
    assert manualintegrate(atan(x)*log(x), x) == -x*atan(x) + (x*atan(x) - \
            log(x**2 + 1)/2)*log(x) + log(x**2 + 1)/2 + Integral(log(x**2 + 1)/x, x)/2
예제 #5
0
def test_ode_solutions():
    # only a few examples here, the rest will be tested in the actual dsolve tests
    assert constant_renumber(constantsimp(C1*exp(2*x) + exp(x)*(C2 + C3), [C1, C2, C3])) == \
        constant_renumber(C1*exp(x) + C2*exp(2*x))
    assert constant_renumber(
        constantsimp(Eq(f(x),
                        I * C1 * sinh(x / 3) + C2 * cosh(x / 3)),
                     [C1, C2])) == constant_renumber(
                         Eq(f(x),
                            C1 * sinh(x / 3) + C2 * cosh(x / 3)))
    assert constant_renumber(constantsimp(Eq(f(x), acos((-C1)/cos(x))), [C1])) == \
        Eq(f(x), acos(C1/cos(x)))
    assert constant_renumber(
        constantsimp(Eq(log(f(x) / C1) + 2 * exp(x / f(x)), 0),
                     [C1])) == Eq(log(C1 * f(x)) + 2 * exp(x / f(x)), 0)
    assert constant_renumber(constantsimp(Eq(log(x*sqrt(2)*sqrt(1/x)*sqrt(f(x))
        /C1) + x**2/(2*f(x)**2), 0), [C1])) == \
        Eq(log(C1*sqrt(x)*sqrt(f(x))) + x**2/(2*f(x)**2), 0)
    assert constant_renumber(constantsimp(Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(x/C1) -
        cos(f(x)/x)*exp(-f(x)/x)/2, 0), [C1])) == \
        Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(C1*x) - cos(f(x)/x)*
           exp(-f(x)/x)/2, 0)
    assert constant_renumber(constantsimp(Eq(-Integral(-1/(sqrt(1 - u2**2)*u2),
        (u2, _a, x/f(x))) + log(f(x)/C1), 0), [C1])) == \
        Eq(-Integral(-1/(u2*sqrt(1 - u2**2)), (u2, _a, x/f(x))) +
        log(C1*f(x)), 0)
    assert [constantsimp(i, [C1]) for i in [Eq(f(x), sqrt(-C1*x + x**2)), Eq(f(x), -sqrt(-C1*x + x**2))]] == \
        [Eq(f(x), sqrt(x*(C1 + x))), Eq(f(x), -sqrt(x*(C1 + x)))]
예제 #6
0
def test_function__eval_nseries():
    n = Symbol('n')

    assert sin(x)._eval_nseries(x, 2, None) == x + O(x**2)
    assert sin(x + 1)._eval_nseries(x, 2, None) == x*cos(1) + sin(1) + O(x**2)
    assert sin(pi*(1 - x))._eval_nseries(x, 2, None) == pi*x + O(x**2)
    assert acos(1 - x**2)._eval_nseries(x, 2, None) == sqrt(2)*sqrt(x**2) + O(x**2)
    assert polygamma(n, x + 1)._eval_nseries(x, 2, None) == \
        polygamma(n, 1) + polygamma(n + 1, 1)*x + O(x**2)
    raises(PoleError, lambda: sin(1/x)._eval_nseries(x, 2, None))
    assert acos(1 - x)._eval_nseries(x, 2, None) == sqrt(2)*sqrt(x) + sqrt(2)*x**(S(3)/2)/12 + O(x**2)
    assert acos(1 + x)._eval_nseries(x, 2, None) == sqrt(2)*sqrt(-x) + sqrt(2)*(-x)**(S(3)/2)/12 + O(x**2)
    assert loggamma(1/x)._eval_nseries(x, 0, None) == \
        log(x)/2 - log(x)/x - 1/x + O(1, x)
    assert loggamma(log(1/x)).nseries(x, n=1, logx=y) == loggamma(-y)

    # issue 6725:
    assert expint(Rational(3, 2), -x)._eval_nseries(x, 5, None) == \
        2 - 2*sqrt(pi)*sqrt(-x) - 2*x + x**2 + x**3/3 + x**4/12 + 4*I*x**(S(3)/2)*sqrt(-x)/3 + \
        2*I*x**(S(5)/2)*sqrt(-x)/5 + 2*I*x**(S(7)/2)*sqrt(-x)/21 + O(x**5)
    assert sin(sqrt(x))._eval_nseries(x, 3, None) == \
        sqrt(x) - x**Rational(3, 2)/6 + x**Rational(5, 2)/120 + O(x**3)

    # issue 19065:
    s1 = f(x,y).series(y, n=2)
    assert {i.name for i in s1.atoms(Symbol)} == {'x', 'xi', 'y'}
    xi = Symbol('xi')
    s2 = f(xi, y).series(y, n=2)
    assert {i.name for i in s2.atoms(Symbol)} == {'xi', 'xi0', 'y'}
예제 #7
0
def test_angle_between():
    a = Point(1, 2, 3, 4)
    b = a.orthogonal_direction
    o = a.origin
    assert feq(Line.angle_between(Line(Point(0, 0), Point(1, 1)),
                                  Line(Point(0, 0), Point(5, 0))).evalf(), pi.evalf() / 4)
    assert Line(a, o).angle_between(Line(b, o)) == pi / 2
    z = Point3D(0, 0, 0)
    assert Line3D.angle_between(Line3D(z, Point3D(1, 1, 1)),
                                Line3D(z, Point3D(5, 0, 0))) == acos(sqrt(3) / 3)
    # direction of points is used to determine angle
    assert Line3D.angle_between(Line3D(z, Point3D(1, 1, 1)),
                                Line3D(Point3D(5, 0, 0), z)) == acos(-sqrt(3) / 3)
예제 #8
0
    def _set_inv_trans_equations(curv_coord_name):
        """
        Store information about inverse transformation equations for
        pre-defined coordinate systems.

        Parameters
        ==========

        curv_coord_name : str
            Name of coordinate system

        """
        if curv_coord_name == 'cartesian':
            return lambda x, y, z: (x, y, z)

        if curv_coord_name == 'spherical':
            return lambda x, y, z: (
                sqrt(x**2 + y**2 + z**2),
                acos(z/sqrt(x**2 + y**2 + z**2)),
                atan2(y, x)
            )
        if curv_coord_name == 'cylindrical':
            return lambda x, y, z: (
                sqrt(x**2 + y**2),
                atan2(y, x),
                z
            )
        raise ValueError('Wrong set of parameters.'
                         'Type of coordinate system is defined')
예제 #9
0
def test_Dimension_functions():
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(cos(length)))
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(acos(angle)))
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(atan2(length, time)))
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(log(length)))
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(log(100, length)))
    raises(TypeError,
           lambda: dimsys_SI.get_dimensional_dependencies(log(length, 10)))

    assert dimsys_SI.get_dimensional_dependencies(pi) == {}

    assert dimsys_SI.get_dimensional_dependencies(cos(1)) == {}
    assert dimsys_SI.get_dimensional_dependencies(cos(angle)) == {}

    assert dimsys_SI.get_dimensional_dependencies(atan2(length, length)) == {}

    assert dimsys_SI.get_dimensional_dependencies(
        log(length / length, length / length)) == {}

    assert dimsys_SI.get_dimensional_dependencies(Abs(length)) == {length: 1}
    assert dimsys_SI.get_dimensional_dependencies(Abs(length / length)) == {}

    assert dimsys_SI.get_dimensional_dependencies(sqrt(-1)) == {}
예제 #10
0
def test_random():
    random.seed(42)
    a = random.random()
    random.seed(42)
    Symbol('z').is_finite
    b = random.random()
    assert a == b

    got = set()
    for i in range(2):
        random.seed(28)
        m0, m1 = symbols('m_0 m_1', real=True)
        _ = acos(-m0 / m1)
        got.add(random.uniform(0, 1))
    assert len(got) == 1

    random.seed(10)
    y = 0
    for i in range(4):
        y += sin(random.uniform(-10, 10) * x)
    random.seed(10)
    z = 0
    for i in range(4):
        z += sin(random.uniform(-10, 10) * x)
    assert y == z
예제 #11
0
def test_create_new():
    a = CoordSys3D('a')
    c = a.create_new('c', transformation='spherical')
    assert c._parent == a
    assert c.transformation_to_parent() == \
           (c.r*sin(c.theta)*cos(c.phi), c.r*sin(c.theta)*sin(c.phi), c.r*cos(c.theta))
    assert c.transformation_from_parent() == \
           (sqrt(a.x**2 + a.y**2 + a.z**2), acos(a.z/sqrt(a.x**2 + a.y**2 + a.z**2)), atan2(a.y, a.x))
예제 #12
0
def test_manualintegrate_trig_substitution():
    assert manualintegrate(sqrt(16*x**2 - 9)/x, x) == \
        Piecewise((sqrt(16*x**2 - 9) - 3*acos(3/(4*x)),
                   And(x < Rational(3, 4), x > Rational(-3, 4))))
    assert manualintegrate(1/(x**4 * sqrt(25-x**2)), x) == \
        Piecewise((-sqrt(-x**2/25 + 1)/(125*x) -
                   (-x**2/25 + 1)**(3*S.Half)/(15*x**3), And(x < 5, x > -5)))
    assert manualintegrate(x**7/(49*x**2 + 1)**(3 * S.Half), x) == \
        ((49*x**2 + 1)**(5*S.Half)/28824005 -
         (49*x**2 + 1)**(3*S.Half)/5764801 +
         3*sqrt(49*x**2 + 1)/5764801 + 1/(5764801*sqrt(49*x**2 + 1)))
예제 #13
0
def test_numpy_numexpr():
    if not numpy:
        skip("numpy not installed.")
    if not numexpr:
        skip("numexpr not installed.")
    a, b, c = numpy.random.randn(3, 128, 128)
    # ensure that numpy and numexpr return same value for complicated expression
    expr = sin(x) + cos(y) + tan(z)**2 + Abs(z-y)*acos(sin(y*z)) + \
           Abs(y-z)*acosh(2+exp(y-x))- sqrt(x**2+I*y**2)
    npfunc = lambdify((x, y, z), expr, modules='numpy')
    nefunc = lambdify((x, y, z), expr, modules='numexpr')
    assert numpy.allclose(npfunc(a, b, c), nefunc(a, b, c))
예제 #14
0
def test_roots_cubic():
    assert roots_cubic(Poly(2 * x**3, x)) == [0, 0, 0]
    assert roots_cubic(Poly(x**3 - 3 * x**2 + 3 * x - 1, x)) == [1, 1, 1]

    # valid for arbitrary y (issue 21263)
    r = root(y, 3)
    assert roots_cubic(Poly(x**3 - y, x)) == [
        r, r * (-S.Half + sqrt(3) * I / 2), r * (-S.Half - sqrt(3) * I / 2)
    ]
    # simpler form when y is negative
    assert roots_cubic(Poly(x**3 - -1, x)) == \
        [-1, S.Half - I*sqrt(3)/2, S.Half + I*sqrt(3)/2]
    assert roots_cubic(Poly(2*x**3 - 3*x**2 - 3*x - 1, x))[0] == \
         S.Half + 3**Rational(1, 3)/2 + 3**Rational(2, 3)/2
    eq = -x**3 + 2 * x**2 + 3 * x - 2
    assert roots(eq, trig=True, multiple=True) == \
           roots_cubic(Poly(eq, x), trig=True) == [
        Rational(2, 3) + 2*sqrt(13)*cos(acos(8*sqrt(13)/169)/3)/3,
        -2*sqrt(13)*sin(-acos(8*sqrt(13)/169)/3 + pi/6)/3 + Rational(2, 3),
        -2*sqrt(13)*cos(-acos(8*sqrt(13)/169)/3 + pi/3)/3 + Rational(2, 3),
        ]
예제 #15
0
def test_bisectors():
    p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
    p = Polygon(Point(0, 0), Point(2, 0), Point(1, 1), Point(0, 3))
    q = Polygon(Point(1, 0), Point(2, 0), Point(3, 3), Point(-1, 5))
    poly = Polygon(Point(3, 4), Point(0, 0), Point(8, 7), Point(-1, 1),
                   Point(19, -19))
    t = Triangle(p1, p2, p3)
    assert t.bisectors()[p2] == Segment(Point(1, 0), Point(0, sqrt(2) - 1))
    assert p.bisectors()[Point2D(0, 3)] == Ray2D(Point2D(0, 3), \
        Point2D(sin(acos(2*sqrt(5)/5)/2), 3 - cos(acos(2*sqrt(5)/5)/2)))
    assert q.bisectors()[Point2D(-1, 5)] == \
        Ray2D(Point2D(-1, 5), Point2D(-1 + sqrt(29)*(5*sin(acos(9*sqrt(145)/145)/2) + \
        2*cos(acos(9*sqrt(145)/145)/2))/29, sqrt(29)*(-5*cos(acos(9*sqrt(145)/145)/2) + \
        2*sin(acos(9*sqrt(145)/145)/2))/29 + 5))
    assert poly.bisectors()[Point2D(-1, 1)] == Ray2D(Point2D(-1, 1), \
        Point2D(-1 + sin(acos(sqrt(26)/26)/2 + pi/4), 1 - sin(-acos(sqrt(26)/26)/2 + pi/4)))
예제 #16
0
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)
예제 #17
0
파일: plane.py 프로젝트: jcrist/sympy
    def angle_between(self, o):
        """Angle between the plane and other geometric entity.

        Parameters
        ==========

        LinearEntity3D, Plane.

        Returns
        =======

        angle : angle in radians

        Notes
        =====

        This method accepts only 3D entities as it's parameter, but if you want
        to calculate the angle between a 2D entity and a plane you should
        first convert to a 3D entity by projecting onto a desired plane and
        then proceed to calculate the angle.

        Examples
        ========

        >>> from sympy import Point3D, Line3D, Plane
        >>> a = Plane(Point3D(1, 2, 2), normal_vector=(1, 2, 3))
        >>> b = Line3D(Point3D(1, 3, 4), Point3D(2, 2, 2))
        >>> a.angle_between(b)
        -asin(sqrt(21)/6)

        """
        from sympy.geometry.line3d import LinearEntity3D

        if isinstance(o, LinearEntity3D):
            a = Matrix(self.normal_vector)
            b = Matrix(o.direction_ratio)
            c = a.dot(b)
            d = sqrt(sum([i ** 2 for i in self.normal_vector]))
            e = sqrt(sum([i ** 2 for i in o.direction_ratio]))
            return asin(c / (d * e))
        if isinstance(o, Plane):
            a = Matrix(self.normal_vector)
            b = Matrix(o.normal_vector)
            c = a.dot(b)
            d = sqrt(sum([i ** 2 for i in self.normal_vector]))
            e = sqrt(sum([i ** 2 for i in o.normal_vector]))
            return acos(c / (d * e))
예제 #18
0
    def angle_between(self, o):
        """Angle between the plane and other geometric entity.

        Parameters
        ==========

        LinearEntity3D, Plane.

        Returns
        =======

        angle : angle in radians

        Notes
        =====

        This method accepts only 3D entities as it's parameter, but if you want
        to calculate the angle between a 2D entity and a plane you should
        first convert to a 3D entity by projecting onto a desired plane and
        then proceed to calculate the angle.

        Examples
        ========

        >>> from sympy import Point3D, Line3D, Plane
        >>> a = Plane(Point3D(1, 2, 2), normal_vector=(1, 2, 3))
        >>> b = Line3D(Point3D(1, 3, 4), Point3D(2, 2, 2))
        >>> a.angle_between(b)
        -asin(sqrt(21)/6)

        """
        from sympy.geometry.line import LinearEntity3D

        if isinstance(o, LinearEntity3D):
            a = Matrix(self.normal_vector)
            b = Matrix(o.direction_ratio)
            c = a.dot(b)
            d = sqrt(sum([i**2 for i in self.normal_vector]))
            e = sqrt(sum([i**2 for i in o.direction_ratio]))
            return asin(c / (d * e))
        if isinstance(o, Plane):
            a = Matrix(self.normal_vector)
            b = Matrix(o.normal_vector)
            c = a.dot(b)
            d = sqrt(sum([i**2 for i in self.normal_vector]))
            e = sqrt(sum([i**2 for i in o.normal_vector]))
            return acos(c / (d * e))
예제 #19
0
def test_fps__hyper():
    f = sin(x)
    assert fps(f, x).truncate() == x - x**3/6 + x**5/120 + O(x**6)

    f = cos(x)
    assert fps(f, x).truncate() == 1 - x**2/2 + x**4/24 + O(x**6)

    f = exp(x)
    assert fps(f, x).truncate() == \
        1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)

    f = atan(x)
    assert fps(f, x).truncate() == x - x**3/3 + x**5/5 + O(x**6)

    f = exp(acos(x))
    assert fps(f, x).truncate() == \
        (exp(pi/2) - x*exp(pi/2) + x**2*exp(pi/2)/2 - x**3*exp(pi/2)/3 +
         5*x**4*exp(pi/2)/24 - x**5*exp(pi/2)/6 + O(x**6))

    f = exp(acosh(x))
    assert fps(f, x).truncate() == I + x - I*x**2/2 - I*x**4/8 + O(x**6)

    f = atan(1/x)
    assert fps(f, x).truncate() == pi/2 - x + x**3/3 - x**5/5 + O(x**6)

    f = x*atan(x) - log(1 + x**2) / 2
    assert fps(f, x, rational=False).truncate() == x**2/2 - x**4/12 + O(x**6)

    f = log(1 + x)
    assert fps(f, x, rational=False).truncate() == \
        x - x**2/2 + x**3/3 - x**4/4 + x**5/5 + O(x**6)

    f = airyai(x**2)
    assert fps(f, x).truncate() == \
        (3**Rational(5, 6)*gamma(Rational(1, 3))/(6*pi) -
         3**Rational(2, 3)*x**2/(3*gamma(Rational(1, 3))) + O(x**6))

    f = exp(x)*sin(x)
    assert fps(f, x).truncate() == x + x**2 + x**3/3 - x**5/30 + O(x**6)

    f = exp(x)*sin(x)/x
    assert fps(f, x).truncate() == 1 + x + x**2/3 - x**4/30 - x**5/90 + O(x**6)

    f = sin(x) * cos(x)
    assert fps(f, x).truncate() == x - 2*x**3/3 + 2*x**5/15 + O(x**6)
예제 #20
0
    def angle_between(l1, l2):
        """The angle formed between the two linear entities.

        Parameters
        ==========

        l1 : LinearEntity
        l2 : LinearEntity

        Returns
        =======

        angle : angle in radians

        Notes
        =====

        From the dot product of vectors v1 and v2 it is known that:

            ``dot(v1, v2) = |v1|*|v2|*cos(A)``

        where A is the angle formed between the two vectors. We can
        get the directional vectors of the two lines and readily
        find the angle between the two using the above formula.

        See Also
        ========

        is_perpendicular

        Examples
        ========

        >>> from sympy import Point3D, Line3D
        >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
        >>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
        >>> l1.angle_between(l2)
        acos(-sqrt(2)/3)

        """
        v1 = l1.p2 - l1.p1
        v2 = l2.p2 - l2.p1
        return acos(v1.dot(v2)/(abs(v1)*abs(v2)))
예제 #21
0
파일: line3d.py 프로젝트: helpin/sympy
    def angle_between(l1, l2):
        """The angle formed between the two linear entities.

        Parameters
        ==========

        l1 : LinearEntity
        l2 : LinearEntity

        Returns
        =======

        angle : angle in radians

        Notes
        =====

        From the dot product of vectors v1 and v2 it is known that:

            ``dot(v1, v2) = |v1|*|v2|*cos(A)``

        where A is the angle formed between the two vectors. We can
        get the directional vectors of the two lines and readily
        find the angle between the two using the above formula.

        See Also
        ========

        is_perpendicular

        Examples
        ========

        >>> from sympy import Point3D, Line3D
        >>> p1, p2, p3 = Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(-1, 2, 0)
        >>> l1, l2 = Line3D(p1, p2), Line3D(p2, p3)
        >>> l1.angle_between(l2)
        acos(-sqrt(2)/3)

        """
        v1 = l1.p2 - l1.p1
        v2 = l2.p2 - l2.p1
        return acos(v1.dot(v2) / (abs(v1) * abs(v2)))
예제 #22
0
def test_quaternion_functions():
    q = Quaternion(w, x, y, z)
    q1 = Quaternion(1, 2, 3, 4)
    q0 = Quaternion(0, 0, 0, 0)

    assert conjugate(q) == Quaternion(w, -x, -y, -z)
    assert q.norm() == sqrt(w**2 + x**2 + y**2 + z**2)
    assert q.normalize() == Quaternion(w, x, y, z) / sqrt(w**2 + x**2 + y**2 + z**2)
    assert q.inverse() == Quaternion(w, -x, -y, -z) / (w**2 + x**2 + y**2 + z**2)
    assert q.inverse() == q.pow(-1)
    raises(ValueError, lambda: q0.inverse())
    assert q.pow(2) == Quaternion(w**2 - x**2 - y**2 - z**2, 2*w*x, 2*w*y, 2*w*z)
    assert q**(2) == Quaternion(w**2 - x**2 - y**2 - z**2, 2*w*x, 2*w*y, 2*w*z)
    assert q1.pow(-2) == Quaternion(Rational(-7, 225), Rational(-1, 225), Rational(-1, 150), Rational(-2, 225))
    assert q1**(-2) == Quaternion(Rational(-7, 225), Rational(-1, 225), Rational(-1, 150), Rational(-2, 225))
    assert q1.pow(-0.5) == NotImplemented
    raises(TypeError, lambda: q1**(-0.5))

    assert q1.exp() == \
    Quaternion(E * cos(sqrt(29)),
               2 * sqrt(29) * E * sin(sqrt(29)) / 29,
               3 * sqrt(29) * E * sin(sqrt(29)) / 29,
               4 * sqrt(29) * E * sin(sqrt(29)) / 29)
    assert q1._ln() == \
    Quaternion(log(sqrt(30)),
               2 * sqrt(29) * acos(sqrt(30)/30) / 29,
               3 * sqrt(29) * acos(sqrt(30)/30) / 29,
               4 * sqrt(29) * acos(sqrt(30)/30) / 29)

    assert q1.pow_cos_sin(2) == \
    Quaternion(30 * cos(2 * acos(sqrt(30)/30)),
               60 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29,
               90 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29,
               120 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29)

    assert diff(Quaternion(x, x, x, x), x) == Quaternion(1, 1, 1, 1)

    assert integrate(Quaternion(x, x, x, x), x) == \
    Quaternion(x**2 / 2, x**2 / 2, x**2 / 2, x**2 / 2)

    assert Quaternion.rotate_point((1, 1, 1), q1) == (S.One / 5, 1, S(7) / 5)
    n = Symbol('n')
    raises(TypeError, lambda: q1**n)
    n = Symbol('n', integer=True)
    raises(TypeError, lambda: q1**n)
예제 #23
0
    def to_axis_angle(self):
        """Returns the axis and angle of rotation of a quaternion

        Returns
        =======

        tuple
            Tuple of (axis, angle)

        Examples
        ========

        >>> from sympy import Quaternion
        >>> q = Quaternion(1, 1, 1, 1)
        >>> (axis, angle) = q.to_axis_angle()
        >>> axis
        (sqrt(3)/3, sqrt(3)/3, sqrt(3)/3)
        >>> angle
        2*pi/3

        """
        q = self
        if q.a.is_negative:
            q = q * -1

        q = q.normalize()
        angle = trigsimp(2 * acos(q.a))

        # Since quaternion is normalised, q.a is less than 1.
        s = sqrt(1 - q.a * q.a)

        x = trigsimp(q.b / s)
        y = trigsimp(q.c / s)
        z = trigsimp(q.d / s)

        v = (x, y, z)
        t = (v, angle)

        return t
예제 #24
0
def test_intrinsic_math1_codegen():
    # not included: log10
    from sympy.core.evalf import N
    from sympy.functions import ln
    from sympy.functions.elementary.exponential import log
    from sympy.functions.elementary.hyperbolic import (cosh, sinh, tanh)
    from sympy.functions.elementary.integers import (ceiling, floor)
    from sympy.functions.elementary.miscellaneous import sqrt
    from sympy.functions.elementary.trigonometric import (acos, asin, atan,
                                                          cos, sin, tan)
    name_expr = [
        ("test_fabs", abs(x)),
        ("test_acos", acos(x)),
        ("test_asin", asin(x)),
        ("test_atan", atan(x)),
        ("test_cos", cos(x)),
        ("test_cosh", cosh(x)),
        ("test_log", log(x)),
        ("test_ln", ln(x)),
        ("test_sin", sin(x)),
        ("test_sinh", sinh(x)),
        ("test_sqrt", sqrt(x)),
        ("test_tan", tan(x)),
        ("test_tanh", tanh(x)),
    ]
    numerical_tests = []
    for name, expr in name_expr:
        for xval in 0.2, 0.5, 0.8:
            expected = N(expr.subs(x, xval))
            numerical_tests.append((name, (xval, ), expected, 1e-14))
    for lang, commands in valid_lang_commands:
        if lang.startswith("C"):
            name_expr_C = [("test_floor", floor(x)), ("test_ceil", ceiling(x))]
        else:
            name_expr_C = []
        run_test("intrinsic_math1", name_expr + name_expr_C, numerical_tests,
                 lang, commands)
예제 #25
0
파일: test_args.py 프로젝트: Visheshk/sympy
def test_sympy__functions__elementary__trigonometric__acos():
    from sympy.functions.elementary.trigonometric import acos
    assert _test_args(acos(2))
예제 #26
0
def test_transformation_equations():

    x, y, z = symbols('x y z')
    # Str
    a = CoordSys3D('a',
                   transformation='spherical',
                   variable_names=["r", "theta", "phi"])
    r, theta, phi = a.base_scalars()

    assert r == a.r
    assert theta == a.theta
    assert phi == a.phi

    raises(AttributeError, lambda: a.x)
    raises(AttributeError, lambda: a.y)
    raises(AttributeError, lambda: a.z)

    assert a.transformation_to_parent() == (r * sin(theta) * cos(phi),
                                            r * sin(theta) * sin(phi),
                                            r * cos(theta))
    assert a.lame_coefficients() == (1, r, r * sin(theta))
    assert a.transformation_from_parent_function()(
        x, y, z) == (sqrt(x**2 + y**2 + z**2),
                     acos((z) / sqrt(x**2 + y**2 + z**2)), atan2(y, x))
    a = CoordSys3D('a',
                   transformation='cylindrical',
                   variable_names=["r", "theta", "z"])
    r, theta, z = a.base_scalars()
    assert a.transformation_to_parent() == (r * cos(theta), r * sin(theta), z)
    assert a.lame_coefficients() == (1, a.r, 1)
    assert a.transformation_from_parent_function()(x, y,
                                                   z) == (sqrt(x**2 + y**2),
                                                          atan2(y, x), z)

    a = CoordSys3D('a', 'cartesian')
    assert a.transformation_to_parent() == (a.x, a.y, a.z)
    assert a.lame_coefficients() == (1, 1, 1)
    assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)

    # Variables and expressions

    # Cartesian with equation tuple:
    x, y, z = symbols('x y z')
    a = CoordSys3D('a', ((x, y, z), (x, y, z)))
    a._calculate_inv_trans_equations()
    assert a.transformation_to_parent() == (a.x1, a.x2, a.x3)
    assert a.lame_coefficients() == (1, 1, 1)
    assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)
    r, theta, z = symbols("r theta z")

    # Cylindrical with equation tuple:
    a = CoordSys3D('a', [(r, theta, z), (r * cos(theta), r * sin(theta), z)],
                   variable_names=["r", "theta", "z"])
    r, theta, z = a.base_scalars()
    assert a.transformation_to_parent() == (r * cos(theta), r * sin(theta), z)
    assert a.lame_coefficients() == (
        sqrt(sin(theta)**2 + cos(theta)**2),
        sqrt(r**2 * sin(theta)**2 + r**2 * cos(theta)**2), 1
    )  # ==> this should simplify to (1, r, 1), tests are too slow with `simplify`.

    # Definitions with `lambda`:

    # Cartesian with `lambda`
    a = CoordSys3D('a', lambda x, y, z: (x, y, z))
    assert a.transformation_to_parent() == (a.x1, a.x2, a.x3)
    assert a.lame_coefficients() == (1, 1, 1)
    a._calculate_inv_trans_equations()
    assert a.transformation_from_parent_function()(x, y, z) == (x, y, z)

    # Spherical with `lambda`
    a = CoordSys3D(
        'a',
        lambda r, theta, phi:
        (r * sin(theta) * cos(phi), r * sin(theta) * sin(phi), r * cos(theta)),
        variable_names=["r", "theta", "phi"])
    r, theta, phi = a.base_scalars()
    assert a.transformation_to_parent() == (r * sin(theta) * cos(phi),
                                            r * sin(phi) * sin(theta),
                                            r * cos(theta))
    assert a.lame_coefficients() == (
        sqrt(
            sin(phi)**2 * sin(theta)**2 + sin(theta)**2 * cos(phi)**2 +
            cos(theta)**2),
        sqrt(r**2 * sin(phi)**2 * cos(theta)**2 + r**2 * sin(theta)**2 +
             r**2 * cos(phi)**2 * cos(theta)**2),
        sqrt(r**2 * sin(phi)**2 * sin(theta)**2 +
             r**2 * sin(theta)**2 * cos(phi)**2)
    )  # ==> this should simplify to (1, r, sin(theta)*r), `simplify` is too slow.

    # Cylindrical with `lambda`
    a = CoordSys3D('a',
                   lambda r, theta, z: (r * cos(theta), r * sin(theta), z),
                   variable_names=["r", "theta", "z"])
    r, theta, z = a.base_scalars()
    assert a.transformation_to_parent() == (r * cos(theta), r * sin(theta), z)
    assert a.lame_coefficients() == (
        sqrt(sin(theta)**2 + cos(theta)**2),
        sqrt(r**2 * sin(theta)**2 + r**2 * cos(theta)**2), 1
    )  # ==> this should simplify to (1, a.x, 1)

    raises(
        TypeError, lambda: CoordSys3D('a',
                                      transformation={
                                          x: x * sin(y) * cos(z),
                                          y: x * sin(y) * sin(z),
                                          z: x * cos(y)
                                      }))
예제 #27
0
def test_quaternion_functions():
    q = Quaternion(w, x, y, z)
    q1 = Quaternion(1, 2, 3, 4)
    q0 = Quaternion(0, 0, 0, 0)

    assert conjugate(q) == Quaternion(w, -x, -y, -z)
    assert q.norm() == sqrt(w**2 + x**2 + y**2 + z**2)
    assert q.normalize() == Quaternion(w, x, y,
                                       z) / sqrt(w**2 + x**2 + y**2 + z**2)
    assert q.inverse() == Quaternion(w, -x, -y,
                                     -z) / (w**2 + x**2 + y**2 + z**2)
    assert q.inverse() == q.pow(-1)
    raises(ValueError, lambda: q0.inverse())
    assert q.pow(2) == Quaternion(w**2 - x**2 - y**2 - z**2, 2 * w * x,
                                  2 * w * y, 2 * w * z)
    assert q**(2) == Quaternion(w**2 - x**2 - y**2 - z**2, 2 * w * x,
                                2 * w * y, 2 * w * z)
    assert q1.pow(-2) == Quaternion(Rational(-7, 225), Rational(-1, 225),
                                    Rational(-1, 150), Rational(-2, 225))
    assert q1**(-2) == Quaternion(Rational(-7, 225), Rational(-1, 225),
                                  Rational(-1, 150), Rational(-2, 225))
    assert q1.pow(-0.5) == NotImplemented
    raises(TypeError, lambda: q1**(-0.5))

    assert q1.exp() == \
    Quaternion(E * cos(sqrt(29)),
               2 * sqrt(29) * E * sin(sqrt(29)) / 29,
               3 * sqrt(29) * E * sin(sqrt(29)) / 29,
               4 * sqrt(29) * E * sin(sqrt(29)) / 29)
    assert q1._ln() == \
    Quaternion(log(sqrt(30)),
               2 * sqrt(29) * acos(sqrt(30)/30) / 29,
               3 * sqrt(29) * acos(sqrt(30)/30) / 29,
               4 * sqrt(29) * acos(sqrt(30)/30) / 29)

    assert q1.pow_cos_sin(2) == \
    Quaternion(30 * cos(2 * acos(sqrt(30)/30)),
               60 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29,
               90 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29,
               120 * sqrt(29) * sin(2 * acos(sqrt(30)/30)) / 29)

    assert diff(Quaternion(x, x, x, x), x) == Quaternion(1, 1, 1, 1)

    assert integrate(Quaternion(x, x, x, x), x) == \
    Quaternion(x**2 / 2, x**2 / 2, x**2 / 2, x**2 / 2)

    assert Quaternion.rotate_point((1, 1, 1), q1) == (S.One / 5, 1, S(7) / 5)
    n = Symbol('n')
    raises(TypeError, lambda: q1**n)
    n = Symbol('n', integer=True)
    raises(TypeError, lambda: q1**n)

    assert Quaternion(22, 23, 55, 8).scalar_part() == 22
    assert Quaternion(w, x, y, z).scalar_part() == w

    assert Quaternion(22, 23, 55, 8).vector_part() == Quaternion(0, 23, 55, 8)
    assert Quaternion(w, x, y, z).vector_part() == Quaternion(0, x, y, z)

    assert q1.axis() == Quaternion(0, 2 * sqrt(29) / 29, 3 * sqrt(29) / 29,
                                   4 * sqrt(29) / 29)
    assert q1.axis().pow(2) == Quaternion(-1, 0, 0, 0)
    assert q0.axis().scalar_part() == 0
    assert q.axis() == Quaternion(0, x / sqrt(x**2 + y**2 + z**2),
                                  y / sqrt(x**2 + y**2 + z**2),
                                  z / sqrt(x**2 + y**2 + z**2))

    assert q0.is_pure() == True
    assert q1.is_pure() == False
    assert Quaternion(0, 0, 0, 3).is_pure() == True
    assert Quaternion(0, 2, 10, 3).is_pure() == True
    assert Quaternion(w, 2, 10, 3).is_pure() == None

    assert q1.angle() == atan(sqrt(29))
    assert q.angle() == atan2(sqrt(x**2 + y**2 + z**2), w)

    assert Quaternion.arc_coplanar(q1, Quaternion(2, 4, 6, 8)) == True
    assert Quaternion.arc_coplanar(q1, Quaternion(1, -2, -3, -4)) == True
    assert Quaternion.arc_coplanar(q1, Quaternion(1, 8, 12, 16)) == True
    assert Quaternion.arc_coplanar(q1, Quaternion(1, 2, 3, 4)) == True
    assert Quaternion.arc_coplanar(q1, Quaternion(w, 4, 6, 8)) == True
    assert Quaternion.arc_coplanar(q1, Quaternion(2, 7, 4, 1)) == False
    assert Quaternion.arc_coplanar(q1, Quaternion(w, x, y, z)) == None
    raises(ValueError, lambda: Quaternion.arc_coplanar(q1, q0))

    assert Quaternion.vector_coplanar(Quaternion(0, 8, 12, 16),
                                      Quaternion(0, 4, 6, 8),
                                      Quaternion(0, 2, 3, 4)) == True
    assert Quaternion.vector_coplanar(Quaternion(0, 0, 0, 0),
                                      Quaternion(0, 4, 6, 8),
                                      Quaternion(0, 2, 3, 4)) == True
    assert Quaternion.vector_coplanar(Quaternion(0, 8, 2, 6),
                                      Quaternion(0, 1, 6, 6),
                                      Quaternion(0, 0, 3, 4)) == False
    assert Quaternion.vector_coplanar(Quaternion(0, 1, 3, 4),
                                      Quaternion(0, 4, w, 6),
                                      Quaternion(0, 6, 8, 1)) == None
    raises(ValueError,
           lambda: Quaternion.vector_coplanar(q0, Quaternion(0, 4, 6, 8), q1))

    assert Quaternion(0, 1, 2, 3).parallel(Quaternion(0, 2, 4, 6)) == True
    assert Quaternion(0, 1, 2, 3).parallel(Quaternion(0, 2, 2, 6)) == False
    assert Quaternion(0, 1, 2, 3).parallel(Quaternion(w, x, y, 6)) == None
    raises(ValueError, lambda: q0.parallel(q1))

    assert Quaternion(0, 1, 2, 3).orthogonal(Quaternion(0, -2, 1, 0)) == True
    assert Quaternion(0, 2, 4, 7).orthogonal(Quaternion(0, 2, 2, 6)) == False
    assert Quaternion(0, 2, 4, 7).orthogonal(Quaternion(w, x, y, 6)) == None
    raises(ValueError, lambda: q0.orthogonal(q1))

    assert q1.index_vector() == Quaternion(0, 2 * sqrt(870) / 29,
                                           3 * sqrt(870) / 29,
                                           4 * sqrt(870) / 29)
    assert Quaternion(0, 3, 9, 4).index_vector() == Quaternion(0, 3, 9, 4)

    assert Quaternion(4, 3, 9, 4).mensor() == log(sqrt(122))
    assert Quaternion(3, 3, 0, 2).mensor() == log(sqrt(22))

    assert q0.is_zero_quaternion() == True
    assert q1.is_zero_quaternion() == False
    assert Quaternion(w, 0, 0, 0).is_zero_quaternion() == None
예제 #28
0
###############################################################################
R3 = Manifold('R^3', 3)  # type: Any

R3_origin = Patch('origin', R3)  # type: Any

x, y, z = symbols('x y z', real=True)
rho, psi, r, theta, phi = symbols('rho psi r theta phi', nonnegative=True)

relations_3d = {
    ('rectangular', 'cylindrical'): [(x, y, z),
                                     (sqrt(x**2 + y**2), atan2(y, x), z)],
    ('cylindrical', 'rectangular'): [(rho, psi, z),
                                     (rho * cos(psi), rho * sin(psi), z)],
    ('rectangular', 'spherical'): [(x, y, z),
                                   (sqrt(x**2 + y**2 + z**2),
                                    acos(z / sqrt(x**2 + y**2 + z**2)),
                                    atan2(y, x))],
    ('spherical', 'rectangular'):
    [(r, theta, phi),
     (r * sin(theta) * cos(phi), r * sin(theta) * sin(phi), r * cos(theta))],
    ('cylindrical', 'spherical'):
    [(rho, psi, z), (sqrt(rho**2 + z**2), acos(z / sqrt(rho**2 + z**2)), psi)],
    ('spherical', 'cylindrical'): [(r, theta, phi),
                                   (r * sin(theta), phi, r * cos(theta))],
}

R3_r = CoordSystem('rectangular', R3_origin, (x, y, z),
                   relations_3d)  # type: Any
R3_c = CoordSystem('cylindrical', R3_origin, (rho, psi, z),
                   relations_3d)  # type: Any
R3_s = CoordSystem('spherical', R3_origin, (r, theta, phi),
예제 #29
0
def test_issue_13575():
    assert limit(acos(erfi(x)), x, 1) == acos(erfi(S.One))
예제 #30
0
def test_smallest_angle():
    a = Line(Point(1, 1), Point(1, 2))
    b = Line(Point(1, 1), Point(2, 3))
    assert a.smallest_angle_between(b) == acos(2 * sqrt(5) / 5)
예제 #31
0
파일: test_args.py 프로젝트: 101man/sympy
def test_sympy__functions__elementary__trigonometric__acos():
    from sympy.functions.elementary.trigonometric import acos
    assert _test_args(acos(2))
예제 #32
0
def test_issue_17421():
    assert N(acos(-I + acosh(cosh(cosh(1) + I)))) == 1.0 * I
예제 #33
0
def test_asech():
    x = Symbol('x')

    assert unchanged(asech, -x)

    # values at fixed points
    assert asech(1) == 0
    assert asech(-1) == pi * I
    assert asech(0) is oo
    assert asech(2) == I * pi / 3
    assert asech(-2) == 2 * I * pi / 3
    assert asech(nan) is nan

    # at infinites
    assert asech(oo) == I * pi / 2
    assert asech(-oo) == I * pi / 2
    assert asech(zoo) == I * AccumBounds(-pi / 2, pi / 2)

    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(2) == acosh(S.Half)

    # 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(Rational(-1, 2))
    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'