
    Ed}                         d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
mZ d dlmZ d dlmZmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$  G d de          Z%dS )    )Rational)S)	conjugateimresign)explog)sqrt)acoscossinatan2)trigsimp	integrate)MutableDenseMatrix)sympify_sympify)Expr)	fuzzy_notfuzzy_or)prec_to_dpsc                      e Zd ZdZdZdZd6dZed             Zed             Z	ed	             Z
ed
             Zed             Zed             Zed             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed             Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(ed&             Z)d' Z*d7d)Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2ed1             Z3d2 Z4d3 Z5d4 Z6d5 Z7d(S )8
QuaternionaJ  Provides basic quaternion operations.
    Quaternion objects can be instantiated as Quaternion(a, b, c, d)
    as in (a + b*i + c*j + d*k).

    Examples
    ========

    >>> from sympy import Quaternion
    >>> q = Quaternion(1, 2, 3, 4)
    >>> q
    1 + 2*i + 3*j + 4*k

    Quaternions over complex fields can be defined as :

    >>> from sympy import Quaternion
    >>> from sympy import symbols, I
    >>> x = symbols('x')
    >>> q1 = Quaternion(x, x**3, x, x**2, real_field = False)
    >>> q2 = Quaternion(3 + 4*I, 2 + 5*I, 0, 7 + 8*I, real_field = False)
    >>> q1
    x + x**3*i + x*j + x**2*k
    >>> q2
    (3 + 4*I) + (2 + 5*I)*i + 0*j + (7 + 8*I)*k

    References
    ==========

    .. [1] http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/
    .. [2] https://en.wikipedia.org/wiki/Quaternion

    g      &@Fr   Tc                    t          t          ||||f          \  }}}}t          d ||||fD                       rt          d          t	          j        | ||||          }||_        ||_        ||_        ||_	        ||_
        |S )Nc              3   (   K   | ]}|j         d u V  dS )FN)is_commutative).0is     9lib/python3.11/site-packages/sympy/algebras/quaternion.py	<genexpr>z%Quaternion.__new__.<locals>.<genexpr>8   s*      ??Qq5(??????    z arguments have to be commutative)mapr   any
ValueErrorr   __new___a_b_c_d_real_field)clsabcd
real_fieldobjs          r!   r'   zQuaternion.__new__5   s    1aA,//
1a??1aA,????? 		?@@@,sAq!Q//CCFCFCFCF(COJr#   c                     | j         S N)r(   selfs    r!   r.   zQuaternion.aC   	    wr#   c                     | j         S r5   )r)   r6   s    r!   r/   zQuaternion.bG   r8   r#   c                     | j         S r5   )r*   r6   s    r!   r0   zQuaternion.cK   r8   r#   c                     | j         S r5   )r+   r6   s    r!   r1   zQuaternion.dO   r8   r#   c                     | j         S r5   )r,   r6   s    r!   r2   zQuaternion.real_fieldS   s    r#   c                    |\  }}}t          |dz  |dz  z   |dz  z             }||z  ||z  ||z  }}}t          |t          j        z            }t	          |t          j        z            }||z  }	||z  }
||z  } | ||	|
|          S )a  Returns a rotation quaternion given the axis and the angle of rotation.

        Parameters
        ==========

        vector : tuple of three numbers
            The vector representation of the given axis.
        angle : number
            The angle by which axis is rotated (in radians).

        Returns
        =======

        Quaternion
            The normalized rotation quaternion calculated from the given axis and the angle of rotation.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import pi, sqrt
        >>> q = Quaternion.from_axis_angle((sqrt(3)/3, sqrt(3)/3, sqrt(3)/3), 2*pi/3)
        >>> q
        1/2 + 1/2*i + 1/2*j + 1/2*k

           )r   r   r   Halfr   )r-   vectoranglexyznormsr.   r/   r0   r1   s               r!   from_axis_anglezQuaternion.from_axis_angleW   s    8 	AqAqD1a4K!Q$&''Xq4xTqAEEE s1aAr#   c                    |                                 t          dd          z  }t          ||d         z   |d         z   |d         z             dz  }t          ||d         z   |d         z
  |d         z
            dz  }t          ||d         z
  |d         z   |d         z
            dz  }t          ||d         z
  |d         z
  |d         z             dz  }|t          |d         |d         z
            z  }|t          |d	         |d
         z
            z  }|t          |d         |d         z
            z  }t	          ||||          S )a  Returns the equivalent quaternion of a matrix. The quaternion will be normalized
        only if the matrix is special orthogonal (orthogonal and det(M) = 1).

        Parameters
        ==========

        M : Matrix
            Input matrix to be converted to equivalent quaternion. M must be special
            orthogonal (orthogonal and det(M) = 1) for the quaternion to be normalized.

        Returns
        =======

        Quaternion
            The quaternion equivalent to given matrix.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import Matrix, symbols, cos, sin, trigsimp
        >>> x = symbols('x')
        >>> M = Matrix([[cos(x), -sin(x), 0], [sin(x), cos(x), 0], [0, 0, 1]])
        >>> q = trigsimp(Quaternion.from_rotation_matrix(M))
        >>> q
        sqrt(2)*sqrt(cos(x) + 1)/2 + 0*i + 0*j + sqrt(2 - 2*cos(x))*sign(sin(x))/2*k

              )r   r   )rI   rI   )r>   r>   r>   )r>   rI   )rI   r>   )r   r>   )r>   r   )rI   r   )r   rI   )detr   r   r   r   )r-   MabsQr.   r/   r0   r1   s          r!   from_rotation_matrixzQuaternion.from_rotation_matrix   s?   > uuwwA&$!D')AdG344q8$!D')AdG344q8$!D')AdG344q8$!D')AdG344q8QtWqw&'''QtWqw&'''QtWqw&'''!Q1%%%r#   c                 ,    |                      |          S r5   addr7   others     r!   __add__zQuaternion.__add__       xxr#   c                 ,    |                      |          S r5   rP   rR   s     r!   __radd__zQuaternion.__radd__   rU   r#   c                 2    |                      |dz            S NrP   rR   s     r!   __sub__zQuaternion.__sub__   s    xxb!!!r#   c                 H    |                      | t          |                    S r5   _generic_mulr   rR   s     r!   __mul__zQuaternion.__mul__   s      x777r#   c                 H    |                      t          |          |           S r5   r]   rR   s     r!   __rmul__zQuaternion.__rmul__   s      %$777r#   c                 ,    |                      |          S r5   )pow)r7   ps     r!   __pow__zQuaternion.__pow__   s    xx{{r#   c                 V    t          | j         | j         | j         | j                   S r5   )r   r(   r)   r*   r1   r6   s    r!   __neg__zQuaternion.__neg__   s&    47(TWHtwh@@@r#   c                 ,    | t          |          dz  z  S rY   r   rR   s     r!   __truediv__zQuaternion.__truediv__   s    gennb(((r#   c                 ,    t          |          | dz  z  S rY   ri   rR   s     r!   __rtruediv__zQuaternion.__rtruediv__   s    u~~b((r#   c                      | j         | S r5   r   r7   argss     r!   _eval_IntegralzQuaternion._eval_Integral   s    t~t$$r#   c                 j                         dd            | j        fd| j        D              S )NevaluateTc                 *    g | ]} |j         i S  )diff)r   r.   kwargssymbolss     r!   
<listcomp>z#Quaternion.diff.<locals>.<listcomp>   s*    JJJ!61675f55JJJr#   )
setdefaultfuncro   )r7   rw   rv   s    ``r!   ru   zQuaternion.diff   sC    *d+++tyJJJJJ	JJJKKr#   c                     | }t          |          }t          |t                    s|j        rM|j        rFt          t          |          |j        z   t          |          |j        z   |j	        |j
                  S |j        r)t          |j        |z   |j        |j	        |j
                  S t          d          t          |j        |j        z   |j        |j        z   |j	        |j	        z   |j
        |j
        z             S )a  Adds quaternions.

        Parameters
        ==========

        other : Quaternion
            The quaternion to add to current (self) quaternion.

        Returns
        =======

        Quaternion
            The resultant quaternion after adding self to other

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import symbols
        >>> q1 = Quaternion(1, 2, 3, 4)
        >>> q2 = Quaternion(5, 6, 7, 8)
        >>> q1.add(q2)
        6 + 8*i + 10*j + 12*k
        >>> q1 + 5
        6 + 2*i + 3*j + 4*k
        >>> x = symbols('x', real = True)
        >>> q1.add(x)
        (x + 1) + 2*i + 3*j + 4*k

        Quaternions over complex fields :

        >>> from sympy import Quaternion
        >>> from sympy import I
        >>> q3 = Quaternion(3 + 4*I, 2 + 5*I, 0, 7 + 8*I, real_field = False)
        >>> q3.add(2 + 3*I)
        (5 + 7*I) + (2 + 5*I)*i + 0*j + (7 + 8*I)*k

        z<Only commutative expressions can be added with a Quaternion.)r   
isinstancer   r2   
is_complexr   r.   r   r/   r0   r1   r   r&   )r7   rS   q1q2s       r!   rQ   zQuaternion.add   s    N U^^ "j)) 	a} a a!"R&&24-B"$bdKKK" a!"$)RT24>>> !_```"$+rtbd{BD24KDB! " " 	"r#   c                 H    |                      | t          |                    S )a  Multiplies quaternions.

        Parameters
        ==========

        other : Quaternion or symbol
            The quaternion to multiply to current (self) quaternion.

        Returns
        =======

        Quaternion
            The resultant quaternion after multiplying self with other

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import symbols
        >>> q1 = Quaternion(1, 2, 3, 4)
        >>> q2 = Quaternion(5, 6, 7, 8)
        >>> q1.mul(q2)
        (-60) + 12*i + 30*j + 24*k
        >>> q1.mul(2)
        2 + 4*i + 6*j + 8*k
        >>> x = symbols('x', real = True)
        >>> q1.mul(x)
        x + 2*x*i + 3*x*j + 4*x*k

        Quaternions over complex fields :

        >>> from sympy import Quaternion
        >>> from sympy import I
        >>> q3 = Quaternion(3 + 4*I, 2 + 5*I, 0, 7 + 8*I, real_field = False)
        >>> q3.mul(2 + 3*I)
        (2 + 3*I)*(3 + 4*I) + (2 + 3*I)*(2 + 5*I)*i + 0*j + (2 + 3*I)*(7 + 8*I)*k

        r]   rR   s     r!   mulzQuaternion.mul  s!    N   x777r#   c                    t          | t                    st          |t                    s| |z  S t          | t                    s|j        r6| j        r/t          t	          |           t          |           dd          |z  S | j        r2t          | |j        z  | |j        z  | |j	        z  | |j
        z            S t          d          t          |t                    s| j        r6|j        r/| t          t	          |          t          |          dd          z  S |j        r2t          || j        z  || j        z  || j	        z  || j
        z            S t          d          t          | j         |j        z  | j	        |j	        z  z
  | j
        |j
        z  z
  | j        |j        z  z   | j        |j        z  | j	        |j
        z  z   | j
        |j	        z  z
  | j        |j        z  z   | j         |j
        z  | j	        |j        z  z   | j
        |j        z  z   | j        |j	        z  z   | j        |j	        z  | j	        |j        z  z
  | j
        |j        z  z   | j        |j
        z  z             S )an  Generic multiplication.

        Parameters
        ==========

        q1 : Quaternion or symbol
        q2 : Quaternion or symbol

        It is important to note that if neither q1 nor q2 is a Quaternion,
        this function simply returns q1 * q2.

        Returns
        =======

        Quaternion
            The resultant quaternion after multiplying q1 and q2

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import Symbol, S
        >>> q1 = Quaternion(1, 2, 3, 4)
        >>> q2 = Quaternion(5, 6, 7, 8)
        >>> Quaternion._generic_mul(q1, q2)
        (-60) + 12*i + 30*j + 24*k
        >>> Quaternion._generic_mul(q1, S(2))
        2 + 4*i + 6*j + 8*k
        >>> x = Symbol('x', real = True)
        >>> Quaternion._generic_mul(q1, x)
        x + 2*x*i + 3*x*j + 4*x*k

        Quaternions over complex fields :

        >>> from sympy import I
        >>> q3 = Quaternion(3 + 4*I, 2 + 5*I, 0, 7 + 8*I, real_field = False)
        >>> Quaternion._generic_mul(q3, 2 + 3*I)
        (2 + 3*I)*(3 + 4*I) + (2 + 3*I)*(2 + 5*I)*i + 0*j + (2 + 3*I)*(7 + 8*I)*k

        r   zAOnly commutative expressions can be multiplied with a Quaternion.)r|   r   r2   r}   r   r   r   r.   r/   r0   r1   r&   )r~   r   s     r!   r^   zQuaternion._generic_mul/  s=   V "j)) 	*R2L2L 	7N "j)) 	f} f f!"R&&"R&&!Q77"<<" f!"rt)R"$YRT	29MMM !deee "j)) 	f} f fJr"vvr"vvq!<<<<" f!"rt)R"$YRT	29MMM !deee24%*rtBDy0249<rtBDyH$rt)bd24i/"$rt);bd24iG4%*rtBDy0249<rtBDyH$rt)bd24i/"$rt);bdRTkIK K 	Kr#   c                 X    | }t          |j        |j         |j         |j                   S )z(Returns the conjugate of the quaternion.)r   r.   r/   r0   r1   r7   qs     r!   _eval_conjugatezQuaternion._eval_conjugatet  s)    !#tacTAC4000r#   c                     | }t          t          |j        dz  |j        dz  z   |j        dz  z   |j        dz  z                       S )z#Returns the norm of the quaternion.r>   )r   r   r.   r/   r0   r1   r   s     r!   rE   zQuaternion.normy  sE     HQS!Vac1f_qsAv5Q>??@@@r#   c                 :    | }|d|                                 z  z  S )z.Returns the normalized form of the quaternion.rI   )rE   r   s     r!   	normalizezQuaternion.normalize  s    AaffhhJr#   c                     | }|                                 st          d          t          |          d|                                 dz  z  z  S )z&Returns the inverse of the quaternion.z6Cannot compute inverse for a quaternion with zero normrI   r>   )rE   r&   r   r   s     r!   inversezQuaternion.inverse  sH    vvxx 	WUVVV||q1}--r#   c                     t          |          }| }|dk    r|                                S d}|j        st          S |dk     r|                                | }}|dk    r|dz  dk    r||z  }|dz  }||z  }|dk    |S )a  Finds the pth power of the quaternion.

        Parameters
        ==========

        p : int
            Power to be applied on quaternion.

        Returns
        =======

        Quaternion
            Returns the p-th power of the current quaternion.
            Returns the inverse if p = -1.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q.pow(4)
        668 + (-224)*i + (-336)*j + (-448)*k

        rZ   rI   r   r>   )r   r   
is_IntegerNotImplemented)r7   rd   r   ress       r!   rc   zQuaternion.pow  s    2 AJJ7 	99;;| 	"!!q5 	#99;;qA!e 	1uz #g1AAA !e 	 
r#   c                    | }t          |j        dz  |j        dz  z   |j        dz  z             }t	          |j                  t          |          z  }t	          |j                  t          |          z  |j        z  |z  }t	          |j                  t          |          z  |j        z  |z  }t	          |j                  t          |          z  |j        z  |z  }t          ||||          S )a  Returns the exponential of q (e^q).

        Returns
        =======

        Quaternion
            Exponential of q (e^q).

        Examples
        ========

        >>> from sympy import Quaternion
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q.exp()
        E*cos(sqrt(29))
        + 2*sqrt(29)*E*sin(sqrt(29))/29*i
        + 3*sqrt(29)*E*sin(sqrt(29))/29*j
        + 4*sqrt(29)*E*sin(sqrt(29))/29*k

        r>   )	r   r/   r0   r1   r	   r.   r   r   r   )r7   r   vector_normr.   r/   r0   r1   s          r!   r	   zQuaternion.exp  s    , 136ACF?QS!V344HHs;'''HHs;'''!#-;HHs;'''!#-;HHs;'''!#-;!Q1%%%r#   c                    | }t          |j        dz  |j        dz  z   |j        dz  z             }|                                }t          |          }|j        t          |j        |z            z  |z  }|j        t          |j        |z            z  |z  }|j        t          |j        |z            z  |z  }t          ||||          S )ae  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

        r>   )	r   r/   r0   r1   rE   lnr   r.   r   )r7   r   r   q_normr.   r/   r0   r1   s           r!   _lnzQuaternion._ln  s      136ACF?QS!V344vJJC$qsV|$$${2C$qsV|$$${2C$qsV|$$${2!Q1%%%r#   c                 V    t          |          t          fd| j        D              S )a  Returns the floating point approximations (decimal numbers) of the quaternion.

        Returns
        =======

        Quaternion
            Floating point approximations of quaternion(self)

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import sqrt
        >>> q = Quaternion(1/sqrt(1), 1/sqrt(2), 1/sqrt(3), 1/sqrt(4))
        >>> q.evalf()
        1.00000000000000
        + 0.707106781186547*i
        + 0.577350269189626*j
        + 0.500000000000000*k

        c                 <    g | ]}|                                S ))n)evalf)r   argnprecs     r!   rx   z*Quaternion._eval_evalf.<locals>.<listcomp>  s'    DDD3CIII..DDDr#   )r   r   ro   )r7   precr   s     @r!   _eval_evalfzQuaternion._eval_evalf  s4    , D!!DDDD$)DDDEEr#   c                     | }|                                 \  }}t                              |||z            }||                                |z  z  S )aY  Computes the pth power in the cos-sin form.

        Parameters
        ==========

        p : int
            Power to be applied on quaternion.

        Returns
        =======

        Quaternion
            The p-th power in the cos-sin form.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q.pow_cos_sin(4)
        900*cos(4*acos(sqrt(30)/30))
        + 1800*sqrt(29)*sin(4*acos(sqrt(30)/30))/29*i
        + 2700*sqrt(29)*sin(4*acos(sqrt(30)/30))/29*j
        + 3600*sqrt(29)*sin(4*acos(sqrt(30)/30))/29*k

        )to_axis_angler   rG   rE   )r7   rd   r   vrA   r   s         r!   pow_cos_sinzQuaternion.pow_cos_sin  sL    < __&&
E''1u955QVVXXq[!!r#   c           	          t          t          | j        g|R  t          | j        g|R  t          | j        g|R  t          | j        g|R            S )a  Computes integration of quaternion.

        Returns
        =======

        Quaternion
            Integration of the quaternion(self) with the given variable.

        Examples
        ========

        Indefinite Integral of quaternion :

        >>> from sympy import Quaternion
        >>> from sympy.abc import x
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q.integrate(x)
        x + 2*x*i + 3*x*j + 4*x*k

        Definite integral of quaternion :

        >>> from sympy import Quaternion
        >>> from sympy.abc import x
        >>> q = Quaternion(1, 2, 3, 4)
        >>> q.integrate((x, 1, 5))
        4 + 8*i + 12*j + 16*k

        )r   r   r.   r/   r0   r1   rn   s     r!   r   zQuaternion.integrate0  sj    < )DF2T222Idf4Lt4L4L4L#DF2T222Idf4Lt4L4L4LN N 	Nr#   c                 :   t          |t                    r(t                              |d         |d                   }n|                                }|t          d| d         | d         | d                   z  t          |          z  }|j        |j        |j        fS )a  Returns the coordinates of the point pin(a 3 tuple) after rotation.

        Parameters
        ==========

        pin : tuple
            A 3-element tuple of coordinates of a point which needs to be
            rotated.
        r : Quaternion or tuple
            Axis and angle of rotation.

            It's important to note that when r is a tuple, it must be of the form
            (axis, angle)

        Returns
        =======

        tuple
            The coordinates of the point after rotation.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import symbols, trigsimp, cos, sin
        >>> x = symbols('x')
        >>> q = Quaternion(cos(x/2), 0, 0, sin(x/2))
        >>> trigsimp(Quaternion.rotate_point((1, 1, 1), q))
        (sqrt(2)*cos(x + pi/4), sqrt(2)*sin(x + pi/4), 1)
        >>> (axis, angle) = q.to_axis_angle()
        >>> trigsimp(Quaternion.rotate_point((1, 1, 1), (axis, angle)))
        (sqrt(2)*cos(x + pi/4), sqrt(2)*sin(x + pi/4), 1)

        r   rI   r>   )	r|   tupler   rG   r   r   r/   r0   r1   )pinrr   pouts       r!   rotate_pointzQuaternion.rotate_pointQ  s    H a 	**1Q4166AA A:aQQQ8889Q<<G''r#   c                 v   | }|j         j        r|dz  }|                                }t          dt	          |j                   z            }t          d|j         |j         z  z
            }t          |j        |z            }t          |j        |z            }t          |j        |z            }|||f}||f}|S )a  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

        rZ   r>   rI   )	r.   is_negativer   r   r   r   r/   r0   r1   )	r7   r   rA   rF   rB   rC   rD   r   ts	            r!   r   zQuaternion.to_axis_angle~  s    * 3? 	BAKKMMT!#YY'' QSWQS1WQS1WQS1W1IJr#   Nc           	         | }|                                 dz  }dd|z  |j        dz  |j        dz  z   z  z
  }d|z  |j        |j        z  |j        |j        z  z
  z  }d|z  |j        |j        z  |j        |j        z  z   z  }d|z  |j        |j        z  |j        |j        z  z   z  }dd|z  |j        dz  |j        dz  z   z  z
  }d|z  |j        |j        z  |j        |j        z  z
  z  }	d|z  |j        |j        z  |j        |j        z  z
  z  }
d|z  |j        |j        z  |j        |j        z  z   z  }dd|z  |j        dz  |j        dz  z   z  z
  }|st          |||g|||	g|
||gg          S |\  }}}|||z  z
  ||z  z
  ||z  z
  }|||z  z
  ||z  z
  ||	z  z
  }|||
z  z
  ||z  z
  ||z  z
  }dx}x}}d}t          ||||g|||	|g|
|||g||||gg          S )a  Returns the equivalent rotation transformation matrix of the quaternion
        which represents rotation about the origin if v is not passed.

        Parameters
        ==========

        v : tuple or None
            Default value: None

        Returns
        =======

        tuple
            Returns the equivalent rotation transformation matrix of the quaternion
            which represents rotation about the origin if v is not passed.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import symbols, trigsimp, cos, sin
        >>> x = symbols('x')
        >>> q = Quaternion(cos(x/2), 0, 0, sin(x/2))
        >>> trigsimp(q.to_rotation_matrix())
        Matrix([
        [cos(x), -sin(x), 0],
        [sin(x),  cos(x), 0],
        [     0,       0, 1]])

        Generates a 4x4 transformation matrix (used for rotation about a point
        other than the origin) if the point(v) is passed as an argument.

        Examples
        ========

        >>> from sympy import Quaternion
        >>> from sympy import symbols, trigsimp, cos, sin
        >>> x = symbols('x')
        >>> q = Quaternion(cos(x/2), 0, 0, sin(x/2))
        >>> trigsimp(q.to_rotation_matrix((1, 1, 1)))
         Matrix([
        [cos(x), -sin(x), 0,  sin(x) - cos(x) + 1],
        [sin(x),  cos(x), 0, -sin(x) - cos(x) + 1],
        [     0,       0, 1,                    0],
        [     0,       0, 0,                    1]])

        rI   r>   r   )rE   r0   r1   r/   r.   Matrix)r7   r   r   rF   m00m01m02m10m11m12m20m21m22rB   rC   rD   m03m13m23m30m31m32m33s                          r!   to_rotation_matrixzQuaternion.to_rotation_matrix  sL   b FFHHbL!A#qsAvQ''c13qs7QSW$%c13qs7QSW$%c13qs7QSW$%!A#qsAvQ''c13qs7QSW$%c13qs7QSW$%c13qs7QSW$%!A#qsAvQ'' 	GCc?S#sOc3_MNNN IQ1ae)ae#ae+Cae)ae#ae+Cae)ae#ae+CC#CCc3/#sC1ES#.c30DF G G Gr#   c                     | j         S )am  Returns scalar part($\mathbf{S}(q)$) of the quaternion q.

        Explanation
        ===========

        Given a quaternion $q = a + bi + cj + dk$, returns $\mathbf{S}(q) = a$.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(4, 8, 13, 12)
        >>> q.scalar_part()
        4

        )r.   r6   s    r!   scalar_partzQuaternion.scalar_part  s    $ vr#   c                 D    t          d| j        | j        | j                  S )a  
        Returns vector part($\mathbf{V}(q)$) of the quaternion q.

        Explanation
        ===========

        Given a quaternion $q = a + bi + cj + dk$, returns $\mathbf{V}(q) = bi + cj + dk$.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(1, 1, 1, 1)
        >>> q.vector_part()
        0 + 1*i + 1*j + 1*k

        >>> q = Quaternion(4, 8, 13, 12)
        >>> q.vector_part()
        0 + 8*i + 13*j + 12*k

        r   )r   r/   r0   r1   r6   s    r!   vector_partzQuaternion.vector_part  s    . !TVTVTV444r#   c                     |                                                                  }t          d|j        |j        |j                  S )a  
        Returns the axis($\mathbf{Ax}(q)$) of the quaternion.

        Explanation
        ===========

        Given a quaternion $q = a + bi + cj + dk$, returns $\mathbf{Ax}(q)$  i.e., the versor of the vector part of that quaternion
        equal to $\mathbf{U}[\mathbf{V}(q)]$.
        The axis is always an imaginary unit with square equal to $-1 + 0i + 0j + 0k$.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(1, 1, 1, 1)
        >>> q.axis()
        0 + sqrt(3)/3*i + sqrt(3)/3*j + sqrt(3)/3*k

        See Also
        ========

        vector_part

        r   )r   r   r   r/   r0   r1   )r7   axiss     r!   r   zQuaternion.axis!  s;    2 !!++--!TVTVTV444r#   c                     | j         j        S )a  
        Returns true if the quaternion is pure, false if the quaternion is not pure
        or returns none if it is unknown.

        Explanation
        ===========

        A pure quaternion (also a vector quaternion) is a quaternion with scalar
        part equal to 0.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(0, 8, 13, 12)
        >>> q.is_pure()
        True

        See Also
        ========
        scalar_part

        )r.   is_zeror6   s    r!   is_purezQuaternion.is_pure>  s    2 v~r#   c                 4    |                                  j        S )a  
        Returns true if the quaternion is a zero quaternion or false if it is not a zero quaternion
        and None if the value is unknown.

        Explanation
        ===========

        A zero quaternion is a quaternion with both scalar part and
        vector part equal to 0.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(1, 0, 0, 0)
        >>> q.is_zero_quaternion()
        False

        >>> q = Quaternion(0, 0, 0, 0)
        >>> q.is_zero_quaternion()
        True

        See Also
        ========
        scalar_part
        vector_part

        )rE   r   r6   s    r!   is_zero_quaternionzQuaternion.is_zero_quaternionY  s    < yy{{""r#   c                     t          |                                                                 |                                           S )a  
        Returns the angle of the quaternion measured in the real-axis plane.

        Explanation
        ===========

        Given a quaternion $q = a + bi + cj + dk$ where a, b, c and d
        are real numbers, returns the angle of the quaternion given by

        .. math::
            angle := atan2(\sqrt{b^2 + c^2 + d^2}, {a})

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(1, 4, 4, 4)
        >>> q.angle()
        atan(4*sqrt(3))

        )r   r   rE   r   r6   s    r!   rA   zQuaternion.angley  s8    . T%%'',,..0@0@0B0BCCCr#   c                 v   |                                  s|                                 rt          d          t          |                                 |                                z
                                   |                                 |                                z                                    g          S )aS  
        Returns True if the transformation arcs represented by the input quaternions happen in the same plane.

        Explanation
        ===========

        Two quaternions are said to be coplanar (in this arc sense) when their axes are parallel.
        The plane of a quaternion is the one normal to its axis.

        Parameters
        ==========

        other : a Quaternion

        Returns
        =======

        True : if the planes of the two quaternions are the same, apart from its orientation/sign.
        False : if the planes of the two quaternions are not the same, apart from its orientation/sign.
        None : if plane of either of the quaternion is unknown.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q1 = Quaternion(1, 4, 4, 4)
        >>> q2 = Quaternion(3, 8, 8, 8)
        >>> Quaternion.arc_coplanar(q1, q2)
        True

        >>> q1 = Quaternion(2, 8, 13, 12)
        >>> Quaternion.arc_coplanar(q1, q2)
        False

        See Also
        ========

        vector_coplanar
        is_pure

        z)Neither of the given quaternions can be 0)r   r&   r   r   rR   s     r!   arc_coplanarzQuaternion.arc_coplanar  s    T ##%% 	J5+C+C+E+E 	JHIII$))++

4HHJJTYY[[[`[e[e[g[gMgL{L{L}L}~r#   c                    t          |                                          sBt          |                                          s!t          |                                          rt          d          t          |j        |j        |j        g|j        |j        |j        g|j        |j        |j        gg                                          }|j        S )a  
        Returns True if the axis of the pure quaternions seen as 3D vectors
        q1, q2, and q3 are coplanar.

        Explanation
        ===========

        Three pure quaternions are vector coplanar if the quaternions seen as 3D vectors are coplanar.

        Parameters
        ==========

        q1 : a pure Quaternion.
        q2 : a pure Quaternion.
        q3 : a pure Quaternion.

        Returns
        =======

        True : if the axis of the pure quaternions seen as 3D vectors
        q1, q2, and q3 are coplanar.
        False : if the axis of the pure quaternions seen as 3D vectors
        q1, q2, and q3 are not coplanar.
        None : if the axis of the pure quaternions seen as 3D vectors
        q1, q2, and q3 are coplanar is unknown.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q1 = Quaternion(0, 4, 4, 4)
        >>> q2 = Quaternion(0, 8, 8, 8)
        >>> q3 = Quaternion(0, 24, 24, 24)
        >>> Quaternion.vector_coplanar(q1, q2, q3)
        True

        >>> q1 = Quaternion(0, 8, 16, 8)
        >>> q2 = Quaternion(0, 8, 3, 12)
        >>> Quaternion.vector_coplanar(q1, q2, q3)
        False

        See Also
        ========

        axis
        is_pure

        "The given quaternions must be pure)	r   r   r&   r   r/   r0   r1   rK   r   )r-   r~   r   q3rL   s        r!   vector_coplanarzQuaternion.vector_coplanar  s    f RZZ\\"" 	Ci

&=&= 	C2::<<AXAX 	CABBBRT24&rtRT(:RT24<NOPPTTVVyr#   c                     t          |                                           s!t          |                                          rt          d          | |z  || z  z
                                  S )a  
        Returns True if the two pure quaternions seen as 3D vectors are parallel.

        Explanation
        ===========

        Two pure quaternions are called parallel when their vector product is commutative which
        implies that the quaternions seen as 3D vectors have same direction.

        Parameters
        ==========

        other : a Quaternion

        Returns
        =======

        True : if the two pure quaternions seen as 3D vectors are parallel.
        False : if the two pure quaternions seen as 3D vectors are not parallel.
        None : if the two pure quaternions seen as 3D vectors are parallel is unknown.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(0, 4, 4, 4)
        >>> q1 = Quaternion(0, 8, 8, 8)
        >>> q.parallel(q1)
        True

        >>> q1 = Quaternion(0, 8, 13, 12)
        >>> q.parallel(q1)
        False

        z%The provided quaternions must be purer   r   r&   r   rR   s     r!   parallelzQuaternion.parallel  sd    J T\\^^$$ 	F	%--//(B(B 	FDEEEU
U4Z';;===r#   c                     t          |                                           s!t          |                                          rt          d          | |z  || z  z                                   S )a|  
        Returns the orthogonality of two quaternions.

        Explanation
        ===========

        Two pure quaternions are called orthogonal when their product is anti-commutative.

        Parameters
        ==========

        other : a Quaternion

        Returns
        =======

        True : if the two pure quaternions seen as 3D vectors are orthogonal.
        False : if the two pure quaternions seen as 3D vectors are not orthogonal.
        None : if the two pure quaternions seen as 3D vectors are orthogonal is unknown.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(0, 4, 4, 4)
        >>> q1 = Quaternion(0, 8, 8, 8)
        >>> q.orthogonal(q1)
        False

        >>> q1 = Quaternion(0, 2, 2, 0)
        >>> q = Quaternion(0, 2, -2, 0)
        >>> q.orthogonal(q1)
        True

        r   r   rR   s     r!   
orthogonalzQuaternion.orthogonal%  sd    J T\\^^$$ 	C	%--//(B(B 	CABBBU
U4Z';;===r#   c                 T    |                                  |                                 z  S )a  
        Returns the index vector of the quaternion.

        Explanation
        ===========

        Index vector is given by $\mathbf{T}(q)$ multiplied by $\mathbf{Ax}(q)$ where $\mathbf{Ax}(q)$ is the axis of the quaternion q,
        and mod(q) is the $\mathbf{T}(q)$ (magnitude) of the quaternion.

        Returns
        =======

        Quaternion: representing index vector of the provided quaternion.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(2, 4, 2, 4)
        >>> q.index_vector()
        0 + 4*sqrt(10)/3*i + 2*sqrt(10)/3*j + 4*sqrt(10)/3*k

        See Also
        ========

        axis
        norm

        )rE   r   r6   s    r!   index_vectorzQuaternion.index_vectorO  s    > yy{{TYY[[((r#   c                 D    t          |                                           S )aj  
        Returns the natural logarithm of the norm(magnitude) of the quaternion.

        Examples
        ========

        >>> from sympy.algebras.quaternion import Quaternion
        >>> q = Quaternion(2, 4, 2, 4)
        >>> q.mensor()
        log(2*sqrt(10))
        >>> q.norm()
        2*sqrt(10)

        See Also
        ========

        norm

        )r   rE   r6   s    r!   mensorzQuaternion.mensorp  s    * $))++r#   )r   r   r   r   Tr5   )8__name__
__module____qualname____doc___op_priorityr   r'   propertyr.   r/   r0   r1   r2   classmethodrG   rN   rT   rW   r[   r_   ra   re   rg   rj   rl   rp   ru   rQ   r   staticmethodr^   r   rE   r   r   rc   r	   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r   r   r   r   r   rt   r#   r!   r   r      s        > LN      X   X   X   X     X  ( ( [(T )& )& [)&V    " " "8 8 88 8 8  A A A) ) )) ) )% % %L L L4" 4" 4"l'8 '8 '8R BK BK \BKH1 1 1
A A A     . . ., , ,\& & &>& & &4F F F2!" !" !"FN N NB *( *( \*(X& & &PLG LG LG LG\  (5 5 525 5 5:  6# # #@D D D4-@ -@ -@^ 6 6 [6p(> (> (>T(> (> (>T) ) )B    r#   r   N)&sympy.core.numbersr   sympy.core.singletonr   $sympy.functions.elementary.complexesr   r   r   r   &sympy.functions.elementary.exponentialr	   r
   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   r   sympy.simplify.trigsimpr   sympy.integrals.integralsr   sympy.matrices.denser   r   sympy.core.sympifyr   r   sympy.core.exprr   sympy.core.logicr   r   mpmath.libmp.libmpfr   r   rt   r#   r!   <module>r      sc   ' ' ' ' ' ' " " " " " " J J J J J J J J J J J J C C C C C C C C 9 9 9 9 9 9 L L L L L L L L L L L L , , , , , , / / / / / / = = = = = = 0 0 0 0 0 0 0 0             0 0 0 0 0 0 0 0 + + + + + +t t t t t t t t t tr#   