o
    8Va!                     @   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 )    )Type)BasisDependentBasisDependentAddBasisDependentMulBasisDependentZero)SPow)
AtomicExpr)ImmutableMatrixNc                   @   sz   e Zd ZdZdZdZdZdZdZdZ	dZ
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      *@Nc                 C      | 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   5/usr/lib/python3/dist-packages/sympy/vector/dyadic.py
components!   s   
zDyadic.componentsc                 C   s   t jj}t|tr|jS t||r3|j}| j D ]\}}|jd 	|}||| |jd  7 }q|S t|t
rqt
j}| j D ].\}}	|j D ]$\}
}|jd 	|
jd }|jd |
jd }|||	 | | 7 }qIq@|S tdtt| d )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.)sympyvectorVector
isinstancer   zeror   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 Nr   r   r    r   r   r   __and__]      
zDyadic.__and__c                 C   s   t jj}||jkrtjS t||r6tj}| j D ]\}}|jd 	|}|jd 
|}||| 7 }q|S ttt|d d )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 dyadics)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   r$   r%   )r*   r'   r   r   r   __xor__   r)   zDyadic.__xor__c                    s,    du 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   systemr0   r   r/   r   	to_matrix   s
   'zDyadic.to_matrixc                 C   s@   t | trt |trtdt | trt| t|tjS td)z' Helper for division involving dyadics zCannot divide two dyadicszCannot divide by a dyadic)r   r   r   	DyadicMulr   r   ZNegativeOne)Zoner    r   r   r   _div_helper   s
   
zDyadic._div_helperr%   )__name__
__module____qualname____doc___op_priority
_expr_type	_mul_func	_add_func
_zero_func
_base_funcr   propertyr   r   r(   r*   r+   r5   r7   r   r   r   r   r      s&    
0$
-r   c                       s(   e Zd ZdZ f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rt|||fstd||jks(||jkr+t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{|})r   r   r   
BaseVector
VectorZeror   r   r   r   super__new___base_instance_measure_numberr   ZOner   _sys_pretty_form_latex_form)clsZvector1Zvector2r   rG   rH   obj	__class__r   r   rJ      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._sympystr)r8   r9   r:   r;   rJ   rW   __classcell__r   r   rR   r   rC      s    rC   c                   @   s0   e Zd ZdZdd Zedd Zedd ZdS )	r6   z% Products of scalars and BaseDyadics c                 O      t j| g|R i |}|S r%   )r   rJ   rP   r   optionsrQ   r   r   r   rJ         zDyadicMul.__new__c                 C   r   )z) The BaseDyadic involved in the product. )rK   r   r   r   r   base_dyadic   s   zDyadicMul.base_dyadicc                 C   r   )zU The scalar expression involved in the definition of
        this DyadicMul.
        )rL   r   r   r   r   measure_number   s   zDyadicMul.measure_numberN)r8   r9   r:   r;   rJ   rB   r]   r^   r   r   r   r   r6      s    
r6   c                   @   s    e Zd ZdZdd Zdd ZdS )	DyadicAddz Class to hold dyadic sums c                 O   rY   r%   )r   rJ   rZ   r   r   r   rJ      r\   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>  s    z%DyadicAdd._sympystr.<locals>.<lambda>)keyz + c                 3   s"    | ]\}}  || V  qd S r%   )rU   )r,   r!   r"   rV   r   r   	<genexpr>  s     z&DyadicAdd._sympystr.<locals>.<genexpr>)listr   r   sortjoin)r   rV   r   r   rd   r   rW      s   zDyadicAdd._sympystrN)r8   r9   r:   r;   rJ   rW   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 )
DyadicZeroz'
    Class to denote a zero dyadic
    g333333*@z(0|0)z#(\mathbf{\hat{0}}|\mathbf{\hat{0}})c                 C   s   t | }|S r%   )r   rJ   )rP   rQ   r   r   r   rJ     s   
zDyadicZero.__new__N)r8   r9   r:   r;   r<   rN   rO   rJ   r   r   r   r   ri     s    ri   )typingr   Zsympy.vector.basisdependentr   r   r   r   Z
sympy.corer   r   Zsympy.core.exprr	   r   r
   r3   Zsympy.vectorr   rC   r6   r_   ri   r=   r>   r?   r@   rA   r   r   r   r   r   <module>   s$     8#