o
    oh{!                     @  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   g/var/www/html/construction_image-detection-poc/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'