U
    ZÊ¹j{!  ã                   @  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   úR/var/www/html/bwave/python/venv/lib/python3.8/site-packages/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
ƒrât
j}| j ¡ D ]\\}}	|j ¡ D ]H\}
}|jd  	|
jd ¡}|jd  |
jd ¡}|||	 | | 7 }q’q€|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)Ú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   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._sympystrc                 C  s$   d  | | jd ¡| | jd ¡¡S )NzBaseDyadic({}, {})r   r   rT   rW   r   r   r   Ú
_sympyreprä   s     ÿzBaseDyadic._sympyrepr)r<   r=   r>   r?   rJ   rY   rZ   Ú__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 )	r9   z% Products of scalars and BaseDyadics c                 O  s   t j| f|ž|Ž}|S r)   )r   rJ   ©rP   r   ÚoptionsrQ   r   r   r   rJ   ì   s    zDyadicMul.__new__c                 C  s   | j S )z) The BaseDyadic involved in the product. )rK   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.
        )rL   r   r   r   r   Úmeasure_numberõ   s    zDyadicMul.measure_numberN)r<   r=   r>   r?   rJ   rB   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   rJ   r\   r   r   r   rJ      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)   )rV   )r/   r&   r'   ©rX   r   r   Ú	<genexpr>  s     z&DyadicAdd._sympystr.<locals>.<genexpr>)Úlistr   r   ÚsortÚjoin)r   rX   r   r   rf   r   rY     s    zDyadicAdd._sympystrN)r<   r=   r>   r?   rJ   rY   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   rJ   )rP   rQ   r   r   r   rJ     s    
zDyadicZero.__new__N)r<   r=   r>   r?   r@   rN   rO   rJ   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   rC   r9   r`   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s"    8'