
    wg{!                    ,   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_        y)    )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y)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    X/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/vector/dyadic.py
componentszDyadic.components!   s         c                ,   t         j                  j                  }t        |t              r|j
                  S t        ||      rf|j
                  }| j                  j                         D ];  \  }}|j                  d   j                  |      }|||z  |j                  d   z  z  }= |S t        |t              rt        j
                  }| j                  j                         D ]  \  }}	|j                  j                         D ]i  \  }
}|j                  d   j                  |
j                  d         }|j                  d   j                  |
j                  d         }|||	z  |z  |z  z  }k  |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-   st   6 $$e/0;;v&[[F--/ 3166!9==/(Q,223 Mv&kkG////1 BB#..446 BFB!wwqz~~bggaj9H$&GGAJ$4$4RWWQZ$@Mx"}r1MAAGBB
 N?U,-/>? @ @r   c                $    | j                  |      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        ||      rxt        j                  }| j                  j                         D ]I  \  }}|j                  d   j                  |      }|j                  d   j                  |      }|||z  z  }K |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   r9   zDyadic.crossb   s    , $$FKK;;v&kkG--/ %1 !q	 6q	61u9$% NCU,/DD01 2 2r   c                $    | j                  |      S r5   )r9   r6   s     r   __xor__zDyadic.__xor__   s    zz%  r   Nc           
         ||}t        |D cg c])  }|D ]"  }|j                  |       j                  |      $ + c}}      j                  dd      S c c}}w )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]])

           )Matrixr$   reshape)r   systemsecond_systemijs        r   	to_matrixzDyadic.to_matrix   sa    N  "M6 &a$&aquuT{q) &) & ''.wq!}	5 &s   .A
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   sO    c6"z%'@788V$S#eQ]]";<<788r   r5   )__name__
__module____qualname____doc___op_priority__annotations__propertyr   r$   r7   r9   r<   rE   rJ    r   r   r   r      s    
 L
	  	 .@` kkGO"2H! mmGO+5Z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                x   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    rY   rZ   obj	__class__s          r   r\   zBaseDyadic.__new__   s!   $$\\,,
\\,,
'J
#;<wZ(@A & ' ' #w&++'=;;goc7G4 ,<<'"6"66<$112478$w':'::]J"../1;< 
r   c                    dj                  |j                  | j                  d         |j                  | j                  d               S )Nz({}|{})r   r   format_printr#   r   printers     r   	_sympystrzBaseDyadic._sympystr   s>    NN499Q<('..1*FH 	Hr   c                    dj                  |j                  | j                  d         |j                  | j                  d               S )NzBaseDyadic({}, {})r   r   ri   rl   s     r   
_sympyreprzBaseDyadic._sympyrepr   s>    #**NN499Q<('..1*FH 	Hr   )rK   rL   rM   rN   r\   rn   rp   __classcell__)rg   s   @r   rT   rT      s    2HHr   rT   c                  6    e Zd ZdZd Zed        Zed        Zy)rG   z% Products of scalars and BaseDyadics c                8    t        j                  | g|i |}|S r5   )r   r\   rc   r#   optionsrf   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)rK   rL   rM   rN   r\   rQ   rx   rz   rR   r   r   rG   rG      s2    / # # $ $r   rG   c                      e Zd ZdZd Zd Zy)	DyadicAddz Class to hold dyadic sums c                8    t        j                  | g|i |}|S r5   )r   r\   rt   s       r   r\   zDyadicAdd.__new__   rv   r   c                    t        | j                  j                               }|j                  d        dj	                  fd|D              S )Nc                (    | d   j                         S )Nr   )__str__)xs    r   <lambda>z%DyadicAdd._sympystr.<locals>.<lambda>  s    1 r   )keyz + c              3  L   K   | ]  \  }}j                  ||z          y wr5   )rk   ).0r+   r,   rm   s      r   	<genexpr>z&DyadicAdd._sympystr.<locals>.<genexpr>  s"     BDAq'..Q/Bs   !$)listr   r"   sortjoin)r   rm   r"   s    ` r   rn   zDyadicAdd._sympystr  s>    T__**,-

/
0zzBEBBBr   N)rK   rL   rM   rN   r\   rn   rR   r   r   r|   r|      s    %Cr   r|   c                  "    e Zd ZdZdZdZdZd Zy)r   z'
    Class to denote a zero dyadic
    g333333*@z(0|0)z#(\mathbf{\hat{0}}|\mathbf{\hat{0}})c                0    t        j                  |       }|S r5   )r   r\   )rc   rf   s     r   r\   zDyadicZero.__new__  s     ((-
r   N)rK   rL   rM   rN   rO   ra   rb   r\   rR   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   r?   sympy.vectorr   r   rT   rG   r|   r   r   r   r   r   r   r   rR   r   r   <module>r      s    "P P  & C t9^ t9n$H $HN$!6 $(
C!6 
C#V       lr   