B
    ™‘[£   ã               @   sØ   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dd„ Zee_ee_ee_ee_ee_ee_eƒ e_dS )é    )ÚBasisDependentÚBasisDependentAddÚBasisDependentMulÚBasisDependentZero)ÚSÚPow)Ú
AtomicExpr)ÚImmutableMatrixNc               @   sZ   e 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S )ÚDyadiczä
    Super class for all Dyadic-classes.

    References
    ==========

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

    g      *@c             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   ú2lib/python3.7/site-packages/sympy/vector/dyadic.pyÚ
components   s    
zDyadic.componentsc             C   s
  t jj}t|tƒr|jS t||ƒrj|j}x<| j ¡ D ].\}}|jd  	|¡}||| |jd  7 }q4W |S t|t
ƒrît
j}xn| j ¡ D ]`\}}	xV|j ¡ D ]H\}
}|jd  	|
jd ¡}|jd  |
jd ¡}|||	 | | 7 }qšW q†W |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   Ú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
   |   |¡S )N)r   )r   r   r   r   r   Ú__and__T   s    zDyadic.__and__c             C   sŒ   t jj}||jkrtjS t||ƒrptj}xB| j ¡ D ]4\}}|jd  	|¡}|jd  
|¡}||| 7 }q4W |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"   Y   s    

zDyadic.crossc             C   s
   |   |¡S )N)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   Úsystemr'   r   )r'   r   r   Ú	to_matrix‚   s    'zDyadic.to_matrix)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_op_priorityÚpropertyr   r   r!   r"   r#   r,   r   r   r   r   r
   	   s   0$r
   c                   s2   e Zd ZdZ‡ fdd„Zddd„ZeZe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	t
| ƒ | ||¡}||_d|_|tdƒ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
   Úsuperr3   Ú__new__Ú_base_instanceÚ_measure_numberr   r   Ú_sysÚ_pretty_formÚ_latex_form)ÚclsZvector1Zvector2r   r7   r8   Úobj)Ú	__class__r   r   r:   µ   s     
zBaseDyadic.__new__Nc             C   s(   dt | jd ƒ d t | jd ƒ d S )Nr4   r   r5   r   r6   )r   r   )r   Úprinterr   r   r   Ú__str__Î   s    zBaseDyadic.__str__)N)	r-   r.   r/   r0   r:   rD   Ú	_sympystrZ
_sympyreprÚ__classcell__r   r   )rB   r   r3   °   s
   
r3   c               @   s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	Ú	DyadicMulz% Products of scalars and BaseDyadics c             O   s   t j| f|ž|Ž}|S )N)r   r:   )r@   r   ÚoptionsrA   r   r   r   r:   Ø   s    zDyadicMul.__new__c             C   s   | j S )z) The BaseDyadic involved in the product. )r;   )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.
        )r<   )r   r   r   r   Úmeasure_numberá   s    zDyadicMul.measure_numberN)r-   r.   r/   r0   r:   r2   rI   rJ   r   r   r   r   rG   Õ   s   rG   c               @   s*   e Zd ZdZdd„ Zddd„ZeZeZdS )Ú	DyadicAddz Class to hold dyadic sums c             O   s   t j| f|ž|Ž}|S )N)r   r:   )r@   r   rH   rA   r   r   r   r:   ì   s    zDyadicAdd.__new__Nc             C   sZ   d}t | j ¡ ƒ}|jdd„ d x*|D ]"\}}|| }|| |¡d 7 }q(W |d d… S )NÚ c             S   s   | d   ¡ S )Nr   )rD   )Úxr   r   r   Ú<lambda>ó   s    z#DyadicAdd.__str__.<locals>.<lambda>)Úkeyz + éýÿÿÿ)Úlistr   r   ÚsortrD   )r   rC   Zret_strr   r   r   Z	temp_dyadr   r   r   rD   ð   s    zDyadicAdd.__str__)N)r-   r.   r/   r0   r:   rD   Ú__repr__rE   r   r   r   r   rK   é   s
   
	rK   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 )N)r   r:   )r@   rA   r   r   r   r:     s    
zDyadicZero.__new__N)r-   r.   r/   r0   r1   r>   r?   r:   r   r   r   r   rT   ý   s
   rT   c             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   rG   r   r   ZNegativeOne)Zoner   r   r   r   Ú	_dyad_div  s
    

rU   )Zsympy.vector.basisdependentr   r   r   r   Z
sympy.corer   r   Zsympy.core.exprr   r   r	   r*   Zsympy.vectorr
   r3   rG   rK   rT   rU   Z
_expr_typeZ	_mul_funcZ	_add_funcZ
_zero_funcZ
_base_funcZ_div_helperr   r   r   r   r   Ú<module>   s$    (%
