
    g{!                    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 )    )annotations)BasisDependentBasisDependentAddBasisDependentMulBasisDependentZero)SPow)
AtomicExpr)ImmutableDenseMatrixNc                      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             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      *@ztype[Dyadic]
_expr_type	_mul_func	_add_func
_zero_func
_base_func
DyadicZerozeroc                    | 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    O/var/www/html/ai-engine/env/lib/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   r   r   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   r:   zDyadic.crossb   s    , $FK;v&& 		2kG--// % %1 !q	 6 6q	661u9$NCU,,/DD01 2 2 2r   c                ,    |                      |          S r5   )r:   r7   s     r   __xor__zDyadic.__xor__   s    zz%   r   Nc                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  r6   ).0ijsecond_systemr   s      r   
<listcomp>z$Dyadic.to_matrix.<locals>.<listcomp>   sO     & & &a$& &aquuT{{q)) & & & &r      )Matrixreshape)r   systemrD   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   r5   )__name__
__module____qualname____doc___op_priority__annotations__propertyr   r$   r8   r:   r=   rJ   rO   r@   r   r   r   r      s        
 
 L	  	  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   rm   rp   s     r   
_sympyreprzBaseDyadic._sympyrepr   sF    #**NN49Q<(('..1*F*FH H 	Hr   )rP   rQ   rR   rS   r`   rr   rt   __classcell__)rk   s   @r   rX   rX      sj             2H H HH H H H H H Hr   rX   c                  D    e Zd ZdZd Zed             Zed             ZdS )rL   z% Products of scalars and BaseDyadics c                0    t          j        | g|R i |}|S r5   )r   r`   rg   r#   optionsrj   s       r   r`   zDyadicMul.__new__   '    '>d>>>g>>
r   c                    | j         S )z) The BaseDyadic involved in the product. )ra   r   s    r   base_dyadiczDyadicMul.base_dyadic   s     ""r   c                    | j         S )zU The scalar expression involved in the definition of
        this DyadicMul.
        )rb   r   s    r   measure_numberzDyadicMul.measure_number   s    
 ##r   N)rP   rQ   rR   rS   r`   rV   r|   r~   r@   r   r   rL   rL      s_        //   # # X# $ $ X$ $ $r   rL   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 r5   )r   r`   rx   s       r   r`   zDyadicAdd.__new__   rz   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 r5   )ro   )rA   r+   r,   rq   s      r   	<genexpr>z&DyadicAdd._sympystr.<locals>.<genexpr>  s7      BBDAq'..Q//BBBBBBr   )listr   r"   sortjoin)r   rq   r"   s    ` r   rr   zDyadicAdd._sympystr  s]    T_**,,--

//
000zzBBBBEBBBBBBr   N)rP   rQ   rR   rS   r`   rr   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 )r   z'
    Class to denote a zero dyadic
    g333333*@z(0|0)z#(\mathbf{\hat{0}}|\mathbf{\hat{0}})c                .    t          j        |           }|S r5   )r   r`   )rg   rj   s     r   r`   zDyadicZero.__new__  s     (--
r   N)rP   rQ   rR   rS   rT   re   rf   r`   r@   r   r   r   r   
  s>          LL8K    r   r   )
__future__r   sympy.vector.basisdependentr   r   r   r   
sympy.corer   r	   sympy.core.exprr
   sympy.matrices.immutabler   rG   sympy.vectorr   r   rX   rL   r   r   r   r   r   r   r   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   