U
    0e{!                     @  s   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 d dlZG dd deZG d	d
 d
eeZG dd deeZG dd deeZG dd deeZee_ee_ee_ee_ee_e e_dS )    )annotations)BasisDependentBasisDependentAddBasisDependentMulBasisDependentZero)SPow)
AtomicExpr)ImmutableDenseMatrixNc                   @  s   e Zd ZU dZdZded< ded< ded< ded< ded< d	ed
< edd Zdd Zdd Z	eje	_dd Z
dd Ze
je_dddZdd ZdS )Dyadicz
    Super class for all Dyadic-classes.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Dyadic_tensor
    .. [2] Kane, T., Levinson, D. Dynamics Theory and Applications. 1985
           McGraw-Hill

    g      *@ztype[Dyadic]
_expr_type	_mul_func	_add_func
_zero_func
_base_func
DyadicZerozeroc                 C  s   | j S )z
        Returns the components of this dyadic in the form of a
        Python dictionary mapping BaseDyadic instances to the
        corresponding measure numbers.

        )_componentsself r   7/tmp/pip-unpacked-wheel-_6tpq7m6/sympy/vector/dyadic.py
components!   s    
zDyadic.componentsc                 C  s   t jj}t|tr|jS t||rf|j}| j D ].\}}|jd 	|}||| |jd  7 }q2|S t|t
rt
j}| j D ]\\}}	|j D ]H\}
}|jd 	|
jd }|jd |
jd }|||	 | | 7 }qq|S tdtt| d dS )a  
        Returns the dot product(also called inner product) of this
        Dyadic, with another Dyadic or Vector.
        If 'other' is a Dyadic, this returns a Dyadic. Else, it returns
        a Vector (unless an error is encountered).

        Parameters
        ==========

        other : Dyadic/Vector
            The other Dyadic or Vector to take the inner product with

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> D1 = N.i.outer(N.j)
        >>> D2 = N.j.outer(N.j)
        >>> D1.dot(D2)
        (N.i|N.j)
        >>> D1.dot(N.j)
        N.i

           r   z!Inner product is not defined for z and Dyadics.N)sympyvectorVector
isinstancer   r   r   itemsargsdotr   outer	TypeErrorstrtype)r   otherr   ZoutveckvZvect_dotoutdyadZk1Zv1Zk2Zv2Zouter_productr   r   r   r    -   s,    



z
Dyadic.dotc                 C  s
   |  |S Nr    r   r%   r   r   r   __and__]   s    zDyadic.__and__c                 C  s   t jj}||jkrtjS t||rltj}| j D ]4\}}|jd 	|}|jd 
|}||| 7 }q2|S ttt|d d dS )a  
        Returns the cross product between this Dyadic, and a Vector, as a
        Vector instance.

        Parameters
        ==========

        other : Vector
            The Vector that we are crossing this Dyadic with

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> d = N.i.outer(N.i)
        >>> d.cross(N.j)
        (N.i|N.k)

        r   r   z not supported for zcross with dyadicsN)r   r   r   r   r   r   r   r   r   crossr!   r"   r#   r$   )r   r%   r   r(   r&   r'   Zcross_productr!   r   r   r   r-   b   s    

zDyadic.crossc                 C  s
   |  |S r)   )r-   r+   r   r   r   __xor__   s    zDyadic.__xor__Nc                   s,    dkr| t  fdd|D ddS )a%  
        Returns the matrix form of the dyadic with respect to one or two
        coordinate systems.

        Parameters
        ==========

        system : CoordSys3D
            The coordinate system that the rows and columns of the matrix
            correspond to. If a second system is provided, this
            only corresponds to the rows of the matrix.
        second_system : CoordSys3D, optional, default=None
            The coordinate system that the columns of the matrix correspond
            to.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> v = N.i + 2*N.j
        >>> d = v.outer(N.i)
        >>> d.to_matrix(N)
        Matrix([
        [1, 0, 0],
        [2, 0, 0],
        [0, 0, 0]])
        >>> from sympy import Symbol
        >>> q = Symbol('q')
        >>> P = N.orient_new_axis('P', q, N.k)
        >>> d.to_matrix(N, P)
        Matrix([
        [  cos(q),   -sin(q), 0],
        [2*cos(q), -2*sin(q), 0],
        [       0,         0, 0]])

        Nc                   s&   g | ]} D ]}|  |qqS r   r*   ).0ijsecond_systemr   r   r   
<listcomp>   s     z$Dyadic.to_matrix.<locals>.<listcomp>   )MatrixZreshape)r   systemr3   r   r2   r   	to_matrix   s    ' zDyadic.to_matrixc                 C  sF   t | trt |trtdn$t | tr:t| t|tjS tddS )z' Helper for division involving dyadics zCannot divide two dyadicszCannot divide by a dyadicN)r   r   r"   	DyadicMulr   r   ZNegativeOne)Zoner%   r   r   r   _div_helper   s
    

zDyadic._div_helper)N)__name__
__module____qualname____doc___op_priority__annotations__propertyr   r    r,   r-   r.   r8   r:   r   r   r   r   r      s$   

0$
-r   c                      s0   e Zd ZdZ fddZdd Zdd Z  ZS )
BaseDyadicz9
    Class to denote a base dyadic tensor component.
    c                   s   t jj}t jj}t jj}t|||fr4t|||fs>tdn||jksR||jkrXtjS t	 
| ||}||_d|_|tji|_|j|_d|j d |j d |_d|j d |j d |_|S )	Nz1BaseDyadic cannot be composed of non-base vectorsr   (|)z\left(z
{\middle|}z\right))r   r   r   
BaseVector
VectorZeror   r"   r   r   super__new___base_instance_measure_numberr   ZOner   _sys_pretty_form_latex_form)clsZvector1Zvector2r   rF   rG   obj	__class__r   r   rI      s2    
zBaseDyadic.__new__c                 C  s$   d || jd || jd S )Nz({}|{})r   r   format_printr   r   printerr   r   r   	_sympystr   s     zBaseDyadic._sympystrc                 C  s$   d || jd || jd S )NzBaseDyadic({}, {})r   r   rS   rV   r   r   r   
_sympyrepr   s     zBaseDyadic._sympyrepr)r;   r<   r=   r>   rI   rX   rY   __classcell__r   r   rQ   r   rB      s   rB   c                   @  s0   e Zd ZdZdd Zedd Zedd ZdS )	r9   z% Products of scalars and BaseDyadics c                 O  s   t j| f||}|S r)   )r   rI   rO   r   optionsrP   r   r   r   rI      s    zDyadicMul.__new__c                 C  s   | j S )z) The BaseDyadic involved in the product. )rJ   r   r   r   r   base_dyadic   s    zDyadicMul.base_dyadicc                 C  s   | j S )zU The scalar expression involved in the definition of
        this DyadicMul.
        )rK   r   r   r   r   measure_number   s    zDyadicMul.measure_numberN)r;   r<   r=   r>   rI   rA   r]   r^   r   r   r   r   r9      s   
r9   c                   @  s    e Zd ZdZdd Zdd ZdS )	DyadicAddz Class to hold dyadic sums c                 O  s   t j| f||}|S r)   )r   rI   r[   r   r   r   rI      s    zDyadicAdd.__new__c                   s6   t | j }|jdd d d fdd|D S )Nc                 S  s   | d   S )Nr   )__str__)xr   r   r   <lambda>      z%DyadicAdd._sympystr.<locals>.<lambda>)keyz + c                 3  s    | ]\}}  || V  qd S r)   )rU   )r/   r&   r'   rW   r   r   	<genexpr>  s     z&DyadicAdd._sympystr.<locals>.<genexpr>)listr   r   sortjoin)r   rW   r   r   re   r   rX     s    zDyadicAdd._sympystrN)r;   r<   r=   r>   rI   rX   r   r   r   r   r_      s   r_   c                   @  s$   e Zd ZdZdZdZdZdd ZdS )r   z'
    Class to denote a zero dyadic
    g333333*@z(0|0)z#(\mathbf{\hat{0}}|\mathbf{\hat{0}})c                 C  s   t | }|S r)   )r   rI   )rO   rP   r   r   r   rI     s    
zDyadicZero.__new__N)r;   r<   r=   r>   r?   rM   rN   rI   r   r   r   r   r   
  s
   r   )
__future__r   Zsympy.vector.basisdependentr   r   r   r   Z
sympy.corer   r   Zsympy.core.exprr	   Zsympy.matrices.immutabler
   r6   Zsympy.vectorr   r   rB   r9   r_   r   r   r   r   r   r   r   r   r   r   r   <module>   s"    8'