o
    §ƒð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  ó   | 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   ú•/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-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   r   r   ÚitemsÚargsÚdotr   ÚouterÚ	TypeErrorÚstrÚtype)r   Úotherr   ÚoutvecÚkÚvÚvect_dotÚoutdyadÚk1Úv1Úk2Úv2Ú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)   Úcross_productr"   r   r   r   r7   b   s   

ÿzDyadic.crossc                 C  r1   r2   )r7   r4   r   r   r   Ú__xor__†   r6   zDyadic.__xor__Nc                   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   r3   )Ú.0ÚiÚj©Úsecond_systemr   r   r   Ú
<listcomp>µ   s    ÿz$Dyadic.to_matrix.<locals>.<listcomp>é   )ÚMatrixÚreshape)r   Úsystemr>   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   ÚNegativeOne)Úoner&   r   r   r   Ú_div_helper¸   s
   
zDyadic._div_helperr2   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_op_priorityÚ__annotations__Úpropertyr   r!   r5   r7   r9   rD   rH   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ƒ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\left(z
{\middle|}z\right))r   r   r   Ú
BaseVectorÚ
VectorZeror   r#   r   r   ÚsuperÚ__new__Ú_base_instanceÚ_measure_numberr   ÚOner   Ú_sysÚ_pretty_formÚ_latex_form)ÚclsÚvector1Úvector2r   rT   rU   Úobj©Ú	__class__r   r   rW   Ç   s2   ÿÿÿÿÿzBaseDyadic.__new__c                 C  ó$   d  | | jd ¡| | jd ¡¡S )Nz({}|{})r   r   ©ÚformatÚ_printr    ©r   Úprinterr   r   r   Ú	_sympystrà   ó   ÿzBaseDyadic._sympystrc                 C  rd   )NzBaseDyadic({}, {})r   r   re   rh   r   r   r   Ú
_sympyreprä   rk   zBaseDyadic._sympyrepr)rI   rJ   rK   rL   rW   rj   rl   Ú__classcell__r   r   rb   r   rP   Â   s
    rP   c                   @  s0   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdS )	rE   z% Products of scalars and BaseDyadics c                 O  ó   t j| g|¢R i |¤Ž}|S r2   )r   rW   ©r^   r    Úoptionsra   r   r   r   rW   ì   ó   zDyadicMul.__new__c                 C  r   )z) The BaseDyadic involved in the product. )rX   r   r   r   r   Úbase_dyadicð   s   zDyadicMul.base_dyadicc                 C  r   )zU The scalar expression involved in the definition of
        this DyadicMul.
        )rY   r   r   r   r   Úmeasure_numberõ   s   zDyadicMul.measure_numberN)rI   rJ   rK   rL   rW   rO   rr   rs   r   r   r   r   rE   é   s    
rE   c                   @  s    e Zd ZdZdd„ Zdd„ ZdS )Ú	DyadicAddz Class to hold dyadic sums c                 O  rn   r2   )r   rW   ro   r   r   r   rW      rq   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 r2   )rg   )r:   r(   r)   ©ri   r   r   Ú	<genexpr>  s   €  z&DyadicAdd._sympystr.<locals>.<genexpr>)Úlistr   r   ÚsortÚjoin)r   ri   r   r   ry   r   rj     s   zDyadicAdd._sympystrN)rI   rJ   rK   rL   rW   rj   r   r   r   r   rt   ý   s    rt   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 r2   )r   rW   )r^   ra   r   r   r   rW     s   
zDyadicZero.__new__N)rI   rJ   rK   rL   rM   r\   r]   rW   r   r   r   r   r   
  s    r   )Ú
__future__r   Úsympy.vector.basisdependentr   r   r   r   Ú
sympy.corer   r   Úsympy.core.exprr	   Úsympy.matrices.immutabler
   rA   Úsympy.vectorr   r   rP   rE   rt   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s$     8'