
    Ed!                     R   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e          Z G d	 d
ee          Z G d dee          Z G d dee          Z G 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)ImmutableDenseMatrixNc                       e Zd ZdZdZdZdZdZdZdZ	dZ
ed             Zd Zd Zej        e_        d Zd Zej        e_        dd	Z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                     | 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selfs    3lib/python3.11/site-packages/sympy/vector/dyadic.py
componentszDyadic.components!   s         c                     t           j        j        }t          |t                    r|j        S t          ||          r^|j        }| j                                        D ];\  }}|j        d         	                    |          }|||z  |j        d         z  z  }<|S t          |t                    rt          j        }| j                                        D ]\  }}	|j                                        D ]i\  }
}|j        d         	                    |
j        d                   }|j        d                             |
j        d                   }|||	z  |z  |z  z  }j|S t          dt          t          |                    z   dz             )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   outveckvvect_dotoutdyadk1v1k2v2outer_products                r   r   z
Dyadic.dot-   s   6 $e/00 	@;v&& 	@[F--// 3 316!9==//(Q,22Mv&& 
	@kG///11 B BB#.4466 B BFB!wqz~~bgaj99H$&GAJ$4$4RWQZ$@$@Mx"}r1MAAGGB N?U,,-/>? @ @ @r   c                 ,    |                      |          S Nr   r   r#   s     r   __and__zDyadic.__and__]   s    xxr   c                    t           j        j        }||j        k    rt          j        S t          ||          rut          j        }| j                                        D ]M\  }}|j        d         	                    |          }|j        d         
                    |          }|||z  z  }N|S t          t          t          |                    dz   dz             )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   s           r   r4   zDyadic.crossb   s    , $FK 	2;v&& 		2kG--// % %1 !q	 6 6q	661u9$NCU,,/DD01 2 2 2r   c                 ,    |                      |          S r/   )r4   r1   s     r   __xor__zDyadic.__xor__   s    zz%   r   c                 n     |t           f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                 j    g | ]/}D ]*}|                                                    |          +0S  r0   ).0ijsecond_systemr   s      r   
<listcomp>z$Dyadic.to_matrix.<locals>.<listcomp>   sO     & & &a$& &aquuT{{q)) & & & &r      )Matrixreshape)r   systemr>   s   ` `r   	to_matrixzDyadic.to_matrix   s]    N  	#"M & & & & &6 & & & ' ''.wq!}}	5r   c                    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#   s     r   _div_helperzDyadic._div_helper   sq    c6"" 	9z%'@'@ 	97888V$$ 	9S#eQ]";";<<<7888r   r/   )__name__
__module____qualname____doc___op_priority
_expr_type	_mul_func	_add_func
_zero_func
_base_funcr   propertyr   r   r2   r4   r7   rD   rI   r:   r   r   r   r      s        
 
 LJIIJJD	  	  X	 .@ .@ .@`   kGO"2 "2 "2H! ! ! mGO+5 +5 +5 +5Z9 9 9 9 9r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )
BaseDyadicz9
    Class to denote a base dyadic tensor component.
    c                 ,   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        z   dz   |j        z   dz   |_        d|j        z   dz   |j        z   dz   |_        |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   r[   r\   obj	__class__s          r   r^   zBaseDyadic.__new__   s"   $\,
\,
'J
#;<< 	wZ(@AA	 & ' ' ' # 	w&+'= 	;ggooc7G44 ,<'"66<$12478$w'::]J"./1;< 
r   c                     d                     |                    | j        d                   |                    | j        d                             S )Nz({}|{})r   r   format_printr   r   printers     r   	_sympystrzBaseDyadic._sympystr   sF    NN49Q<(('..1*F*FH H 	Hr   c                     d                     |                    | j        d                   |                    | j        d                             S )NzBaseDyadic({}, {})r   r   rk   rn   s     r   
_sympyreprzBaseDyadic._sympyrepr   sF    #**NN49Q<(('..1*F*FH H 	Hr   )rJ   rK   rL   rM   r^   rp   rr   __classcell__)ri   s   @r   rV   rV      sj             2H H HH H H H H H Hr   rV   c                   D    e Zd ZdZd Zed             Zed             ZdS )rF   z% Products of scalars and BaseDyadics c                 0    t          j        | g|R i |}|S r/   )r   r^   re   r   optionsrh   s       r   r^   zDyadicMul.__new__   '    '>d>>>g>>
r   c                     | j         S )z) The BaseDyadic involved in the product. )r_   r   s    r   base_dyadiczDyadicMul.base_dyadic   s     ""r   c                     | j         S )zU The scalar expression involved in the definition of
        this DyadicMul.
        )r`   r   s    r   measure_numberzDyadicMul.measure_number   s    
 ##r   N)rJ   rK   rL   rM   r^   rT   rz   r|   r:   r   r   rF   rF      s_        //   # # X# $ $ X$ $ $r   rF   c                       e Zd ZdZd Zd ZdS )	DyadicAddz Class to hold dyadic sums c                 0    t          j        | g|R i |}|S r/   )r   r^   rv   s       r   r^   zDyadicAdd.__new__   rx   r   c                     t          | j                                                  }|                    d            d                    fd|D                       S )Nc                 6    | d                                          S )Nr   )__str__)xs    r   <lambda>z%DyadicAdd._sympystr.<locals>.<lambda>  s    1 r   )keyz + c              3   N   K   | ]\  }}                     ||z            V   d S r/   )rm   )r;   r%   r&   ro   s      r   	<genexpr>z&DyadicAdd._sympystr.<locals>.<genexpr>  s7      BBDAq'..Q//BBBBBBr   )listr   r   sortjoin)r   ro   r   s    ` r   rp   zDyadicAdd._sympystr  s]    T_**,,--

//
000zzBBBBEBBBBBBr   N)rJ   rK   rL   rM   r^   rp   r:   r   r   r~   r~      s=        %%  C C C C Cr   r~   c                   $    e Zd ZdZdZdZdZd ZdS )
DyadicZeroz'
    Class to denote a zero dyadic
    g333333*@z(0|0)z#(\mathbf{\hat{0}}|\mathbf{\hat{0}})c                 .    t          j        |           }|S r/   )r   r^   )re   rh   s     r   r^   zDyadicZero.__new__  s     (--
r   N)rJ   rK   rL   rM   rN   rc   rd   r^   r:   r   r   r   r   
  s>          LL8K    r   r   )typingr   sympy.vector.basisdependentr   r   r   r   
sympy.corer   r	   sympy.core.exprr
   sympy.matrices.immutabler   rA   sympy.vectorr   r   rV   rF   r~   r   rO   rP   rQ   rR   rS   r   r:   r   r   <module>r      s        P P P P P P P P P P P P         & & & & & & C C C C C C    t9 t9 t9 t9 t9^ t9 t9 t9n$H $H $H $H $H $H $H $HN$ $ $ $ $!6 $ $ $(
C 
C 
C 
C 
C!6 
C 
C 
C    #V         jllr   