
    gE                       d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZmZmZ d dlmZ d dlm Z m!Z!m"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' G d de#          Z( G d de
          Z)d Z*d Z+e#e#_,        e&e#_-        e%e#_.        e'e#_/        e$e#_0         e'            e#_1        dS )     )annotations)product)Add)	StdFactKB)
AtomicExprExpr)Pow)S)default_sort_key)sympifysqrt)ImmutableDenseMatrix)BasisDependentZeroBasisDependentBasisDependentMulBasisDependentAdd)
CoordSys3D)Dyadic
BaseDyadic	DyadicAddc                     e Zd ZU dZdZ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d Zd Zej        e_        d Zd Zej        e_        d ZddZed             Zd Zej        e_        d Zd Zd ZdS )Vectorz
    Super class for all Vector classes.
    Ideally, neither this class nor any of its subclasses should be
    instantiated by the user.
    FTg      (@ztype[Vector]
_expr_type	_mul_func	_add_func
_zero_func
_base_func
VectorZerozeroc                    | j         S )a  
        Returns the components of this vector in the form of a
        Python dictionary mapping BaseVector instances to the
        corresponding measure numbers.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v.components
        {C.i: 3, C.j: 4, C.k: 5}

        )_componentsselfs    O/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/vector/vector.py
componentszVector.components%   s    &     c                &    t          | | z            S )z7
        Returns the magnitude of this vector.
        r   r#   s    r%   	magnitudezVector.magnitude:   s     D4K   r'   c                0    | |                                  z  S )z@
        Returns the normalized version of this vector.
        )r)   r#   s    r%   	normalizezVector.normalize@   s     dnn&&&&r'   c                    t          |t                    rt           t                    rt          j        S t          j        }|j                                        D ];\  }}|j        d                                        }|||z  |j        d         z  z  }<|S ddl	m
} t          ||t          f          s"t          t          |          dz   dz             t          ||          r fd}|S t           |          S )aN  
        Returns the dot product of this Vector, either with another
        Vector, or a Dyadic, or a Del operator.
        If 'other' is a Vector, returns the dot product scalar (SymPy
        expression).
        If 'other' is a Dyadic, the dot product is returned as a Vector.
        If 'other' is an instance of Del, returns the directional
        derivative operator as a Python function. If this function is
        applied to a scalar expression, it returns the directional
        derivative of the scalar field wrt this Vector.

        Parameters
        ==========

        other: Vector/Dyadic/Del
            The Vector or Dyadic we are dotting with, or a Del operator .

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, Del
        >>> C = CoordSys3D('C')
        >>> delop = Del()
        >>> C.i.dot(C.j)
        0
        >>> C.i & C.i
        1
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v.dot(C.k)
        5
        >>> (C.i & delop)(C.x*C.y*C.z)
        C.y*C.z
        >>> d = C.i.outer(C.i)
        >>> C.i.dot(d)
        C.i

        r      )Delz is not a vector, dyadic or zdel operatorc                (    ddl m}  ||           S )Nr   )directional_derivative)sympy.vector.functionsr0   )fieldr0   r$   s     r%   r0   z*Vector.dot.<locals>.directional_derivative}   s(    IIIIII--eT:::r'   )
isinstancer   r   r   r    r&   itemsargsdotsympy.vector.deloperatorr.   	TypeErrorstr)r$   otheroutveckvvect_dotr.   r0   s   `       r%   r6   z
Vector.dotF   s'   P eV$$ 	$
++ #{"[F(..00 3 316!9==..(Q,22M000000%#v// 	,CJJ)GG*+ , , , eS!! 	*; ; ; ; ; *)4r'   c                ,    |                      |          S Nr6   r$   r:   s     r%   __and__zVector.__and__   s    xxr'   c                x   t          |t                    rt          | t                    rt          j        S t          j        }|j                                        D ]M\  }}|                     |j        d                   }|                    |j        d                   }|||z  z  }N|S t          | |          S )a  
        Returns the cross product of this Vector with another Vector or
        Dyadic instance.
        The cross product is a Vector, if 'other' is a Vector. If 'other'
        is a Dyadic, this returns a Dyadic instance.

        Parameters
        ==========

        other: Vector/Dyadic
            The Vector or Dyadic we are crossing with.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> C.i.cross(C.j)
        C.k
        >>> C.i ^ C.i
        0
        >>> v = 3*C.i + 4*C.j + 5*C.k
        >>> v ^ C.i
        5*C.j + (-4)*C.k
        >>> d = C.i.outer(C.i)
        >>> C.j.cross(d)
        (-1)*(C.k|C.i)

        r   r-   )	r3   r   r   r    r&   r4   crossr5   outer)r$   r:   outdyadr<   r=   cross_productrF   s          r%   rE   zVector.cross   s    @ eV$$ 	$
++ #{"kG(..00 % %1 $

16!9 5 5%++AF1I661u9$NT5!!!r'   c                ,    |                      |          S r@   rE   rB   s     r%   __xor__zVector.__xor__       zz%   r'   c                X   t          |t                    st          d          t          | t                    st          |t                    rt          j        S d t          | j                                        |j                                                  D             }t          | S )a  
        Returns the outer product of this vector with another, in the
        form of a Dyadic instance.

        Parameters
        ==========

        other : Vector
            The Vector with respect to which the outer product is to
            be computed.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> N = CoordSys3D('N')
        >>> N.i.outer(N.j)
        (N.i|N.j)

        z!Invalid operand for outer productc                L    g | ]!\  \  }}\  }}||z  t          ||          z  "S  )r   ).0k1v1k2v2s        r%   
<listcomp>z Vector.outer.<locals>.<listcomp>   sJ     O O O3E8BXb"bJr2... O O Or'   )
r3   r   r8   r   r   r    r   r&   r4   r   )r$   r:   r5   s      r%   rF   zVector.outer   s    . %(( 	?@@@z** 	5*--	;O O4?0022E4D4J4J4L4LMMO O O $r'   c                *   |                      t          j                  r|rt          j        nt          j        S |r+|                     |          |                     |           z  S |                     |          |                     |           z  | z  S )a  
        Returns the vector or scalar projection of the 'other' on 'self'.

        Examples
        ========

        >>> from sympy.vector.coordsysrect import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> i, j, k = C.base_vectors()
        >>> v1 = i + j + k
        >>> v2 = 3*i + 4*j
        >>> v1.projection(v2)
        7/3*C.i + 7/3*C.j + 7/3*C.k
        >>> v1.projection(v2, scalar=True)
        7/3

        )equalsr   r    r
   Zeror6   )r$   r:   scalars      r%   
projectionzVector.projection   sx    $ ;;v{## 	5#41664 	;88E??TXXd^^3388E??TXXd^^3d::r'   c                $    ddl m} t           t                    r#t          j        t          j        t          j        fS t          t           |                                                               }t           fd|D                       S )a  
        Returns the components of this vector but the output includes
        also zero values components.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, Vector
        >>> C = CoordSys3D('C')
        >>> v1 = 3*C.i + 4*C.j + 5*C.k
        >>> v1._projections
        (3, 4, 5)
        >>> v2 = C.x*C.y*C.z*C.i
        >>> v2._projections
        (C.x*C.y*C.z, 0, 0)
        >>> v3 = Vector.zero
        >>> v3._projections
        (0, 0, 0)
        r   )_get_coord_systemsc                :    g | ]}                     |          S rO   rA   )rP   ir$   s     r%   rU   z'Vector._projections.<locals>.<listcomp>  s#    444adhhqkk444r'   )
sympy.vector.operatorsr\   r3   r   r
   rX   nextiterbase_vectorstuple)r$   r\   base_vecs   `  r%   _projectionszVector._projections   s    , 	>=====dJ'' 	,FAFAF++//556677DDFF44448444555r'   c                ,    |                      |          S r@   )rF   rB   s     r%   __or__zVector.__or__  rL   r'   c                ^     t           fd|                                D                       S )a  
        Returns the matrix form of this vector with respect to the
        specified coordinate system.

        Parameters
        ==========

        system : CoordSys3D
            The system wrt which the matrix form is to be computed

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> C = CoordSys3D('C')
        >>> from sympy.abc import a, b, c
        >>> v = a*C.i + b*C.j + c*C.k
        >>> v.to_matrix(C)
        Matrix([
        [a],
        [b],
        [c]])

        c                :    g | ]}                     |          S rO   rA   )rP   unit_vecr$   s     r%   rU   z$Vector.to_matrix.<locals>.<listcomp>3  s1     . . .htxx)) . . .r'   )Matrixrb   )r$   systems   ` r%   	to_matrixzVector.to_matrix  sI    4  . . . .**,,. . . / / 	/r'   c                    i }| j                                         D ]8\  }}|                    |j        t          j                  ||z  z   ||j        <   9|S )a  
        The constituents of this vector in different coordinate systems,
        as per its definition.

        Returns a dict mapping each CoordSys3D to the corresponding
        constituent Vector.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> R1 = CoordSys3D('R1')
        >>> R2 = CoordSys3D('R2')
        >>> v = R1.i + R2.i
        >>> v.separate() == {R1: R1.i, R2: R2.i}
        True

        )r&   r4   getrl   r   r    )r$   partsvectmeasures       r%   separatezVector.separate6  s\    ( !_2244 	2 	2MD'"'))DK"E"E"&.#1E$+r'   c                J   t          | t                    r$t          |t                    rt          d          t          | t                    rG|t          j        k    rt          d          t          | t          |t          j                            S t          d          )z( Helper for division involving vectors. zCannot divide two vectorszCannot divide a vector by zeroz#Invalid division involving a vector)	r3   r   r8   r
   rX   
ValueError	VectorMulr	   NegativeOne)oner:   s     r%   _div_helperzVector._div_helperP  s    c6"" 	Cz%'@'@ 	C7888V$$ 	C !ABBBS#eQ]";";<<<ABBBr'   N)F)__name__
__module____qualname____doc__	is_scalar	is_Vector_op_priority__annotations__propertyr&   r)   r+   r6   rC   rE   rK   rF   rZ   re   rg   rm   rs   ry   rO   r'   r%   r   r      s          IIL    X (! ! !' ' '<  <  < |   kGO*" *" *"X! ! ! mGO"  "  " H; ; ; ;4 6 6 X66! ! ! ]FN/ / /:  4	C 	C 	C 	C 	Cr'   r   c                  \     e Zd ZdZd fd	Zed             Zd Zd Zed             Z	 xZ
S )	
BaseVectorz)
    Class to denote a base vector.

    Nc                   |d                     |          }|d                     |          }t          |          }t          |          }|t          dd          vrt          d          t	          |t
                    st          d          |j        |         }t                      	                    | t          |          |          }||_        |t          j        i|_        t          j        |_        |j        dz   |z   |_        d|z   |_        ||_        ||_        ||f|_        d	d
i}t)          |          |_        ||_        |S )Nzx{}zx_{}r      zindex must be 0, 1 or 2zsystem should be a CoordSys3D. commutativeT)formatr9   rangeru   r3   r   r8   _vector_namessuper__new__r
   _base_instanceOner"   _measure_number_name_pretty_form_latex_form_system_idr   _assumptions_sys)	clsindexrl   
pretty_str	latex_strnameobjassumptions	__class__s	           r%   r   zBaseVector.__new__b  s5   e,,Je,,I__
	NN	a##6777&*-- 	=;<<<#E*ggooc1U88V44 ,eL3&-	
?#&/$d+$[11
 
r'   c                    | j         S r@   )r   r#   s    r%   rl   zBaseVector.system  s
    |r'   c                    | j         S r@   )r   )r$   printers     r%   	_sympystrzBaseVector._sympystr  s
    zr'   c                b    | j         \  }}|                    |          dz   |j        |         z   S )Nr   )r   _printr   )r$   r   r   rl   s       r%   
_sympyreprzBaseVector._sympyrepr  s1    v~~f%%+f.B5.IIIr'   c                    | hS r@   rO   r#   s    r%   free_symbolszBaseVector.free_symbols  s	    vr'   )NN)rz   r{   r|   r}   r   r   rl   r   r   r   __classcell__)r   s   @r%   r   r   \  s         
! ! ! ! ! !F   X  J J J   X    r'   r   c                      e Zd ZdZd Zd ZdS )	VectorAddz2
    Class to denote sum of Vector instances.
    c                0    t          j        | g|R i |}|S r@   )r   r   r   r5   optionsr   s       r%   r   zVectorAdd.__new__  '    '>d>>>g>>
r'   c                X   d}t          |                                                                           }|                    d            |D ]R\  }}|                                }|D ]6}||j        v r+| j        |         |z  }||                    |          dz   z  }7S|d d         S )Nr   c                6    | d                                          S )Nr   )__str__)xs    r%   <lambda>z%VectorAdd._sympystr.<locals>.<lambda>  s    1 r'   keyz + )listrs   r4   sortrb   r&   r   )	r$   r   ret_strr4   rl   rq   
base_vectsr   	temp_vects	            r%   r   zVectorAdd._sympystr  s    T]]__**,,--

//
000! 	A 	ALFD,,..J A A'' $ 2Q 6Iw~~i885@@GA ss|r'   N)rz   r{   r|   r}   r   r   rO   r'   r%   r   r     s<           
 
 
 
 
r'   r   c                  D    e Zd ZdZd Zed             Zed             ZdS )rv   z>
    Class to denote products of scalars and BaseVectors.
    c                0    t          j        | g|R i |}|S r@   )r   r   r   s       r%   r   zVectorMul.__new__  r   r'   c                    | j         S )z) The BaseVector involved in the product. )r   r#   s    r%   base_vectorzVectorMul.base_vector  s     ""r'   c                    | j         S )zU The scalar expression involved in the definition of
        this VectorMul.
        )r   r#   s    r%   measure_numberzVectorMul.measure_number  s    
 ##r'   N)rz   r{   r|   r}   r   r   r   r   rO   r'   r%   rv   rv     sc            # # X# $ $ X$ $ $r'   rv   c                  $    e Zd ZdZdZdZdZd ZdS )r   z'
    Class to denote a zero vector
    g333333(@0z\mathbf{\hat{0}}c                .    t          j        |           }|S r@   )r   r   )r   r   s     r%   r   zVectorZero.__new__  s     (--
r'   N)rz   r{   r|   r}   r   r   r   r   rO   r'   r%   r   r     s>          LL%K    r'   r   c                      e Zd ZdZd Zd ZdS )Crossa  
    Represents unevaluated Cross product.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Cross
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> Cross(v1, v2)
    Cross(R.i + R.j + R.k, R.x*R.i + R.y*R.j + R.z*R.k)
    >>> Cross(v1, v2).doit()
    (-R.y + R.z)*R.i + (R.x - R.z)*R.j + (-R.x + R.y)*R.k

    c                    t          |          }t          |          }t          |          t          |          k    rt          ||           S t          j        | ||          }||_        ||_        |S r@   )r   r   r   r   r   _expr1_expr2r   expr1expr2r   s       r%   r   zCross.__new__  sm    E""%5e%<%<<<%''''l3u--


r'   c                6    t          | j        | j                  S r@   )rE   r   r   r$   hintss     r%   doitz
Cross.doit  s    T[$+...r'   Nrz   r{   r|   r}   r   r   rO   r'   r%   r   r     s<         "  / / / / /r'   r   c                      e Zd ZdZd Zd ZdS )Dota  
    Represents unevaluated Dot product.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Dot
    >>> from sympy import symbols
    >>> R = CoordSys3D('R')
    >>> a, b, c = symbols('a b c')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = a * R.i + b * R.j + c * R.k
    >>> Dot(v1, v2)
    Dot(R.i + R.j + R.k, a*R.i + b*R.j + c*R.k)
    >>> Dot(v1, v2).doit()
    a + b + c

    c                    t          |          }t          |          }t          ||gt                    \  }}t          j        | ||          }||_        ||_        |S )Nr   )r   sortedr   r   r   r   r   r   s       r%   r   zDot.__new__  sY    uen2BCCCul3u--


r'   c                6    t          | j        | j                  S r@   )r6   r   r   r   s     r%   r   zDot.doit  s    4;,,,r'   Nr   rO   r'   r%   r   r     s<         &  - - - - -r'   r   c                     t           t                    r+t                              fd j        D                       S t          t                    r+t                               fdj        D                       S t           t
                    rt          t
                    r j        j        k    r j        d         }j        d         }||k    rt          j        S h d	                    ||h          
                                }|dz   dz  |k    rdnd}| j                                        |         z  S ddlm} 	  | j                  }t          |          S # t          $ r t!                     cY S w xY wt           t"                    st          t"                    rt          j        S t           t$                    rIt'          t)           j                                                            \  }}	|	t          |          z  S t          t$                    rIt'          t)          j                                                            \  }
}|t           |
          z  S t!                     S )	a^  
    Returns cross product of two vectors.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector.vector import cross
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> cross(v1, v2)
    (-R.y + R.z)*R.i + (R.x - R.z)*R.j + (-R.x + R.y)*R.k

    c              3  8   K   | ]}t          |          V  d S r@   rJ   rP   r^   vect2s     r%   	<genexpr>zcross.<locals>.<genexpr>!  s+      !F!Fa%5//!F!F!F!F!F!Fr'   c              3  8   K   | ]}t          |          V  d S r@   rJ   rP   r^   vect1s     r%   r   zcross.<locals>.<genexpr>#  s+      !F!Fa%q//!F!F!F!F!F!Fr'   r   >   r   r-      r-   r   express)r3   r   r   fromiterr5   r   r   r   r    
differencepoprb   	functionsr   rE   ru   r   r   rv   r`   ra   r&   r4   )r   r   n1n2n3signr   r=   rR   m1rT   m2s   ``          r%   rE   rE     s     % G!!!F!F!F!F5:!F!F!FFFF% G!!!F!F!F!F5:!F!F!FFFF%$$ #E:)F)F #:##ABABRxx{"''$$b"X..3355Bq&A++11"D
//11"555&&&&&&	#uz**A E??"  	' 	' 	'&&&&&	' %$$ 
5*(E(E {%## #d5+11334455B%E""""%## #d5+11334455B%r""""s   E. .F
Fc                2    t           t                    r%t          j        fd j        D                       S t          t                    r%t          j         fdj        D                       S t           t                    rt          t                    rv j        j        k    r k    rt          j        nt          j        S ddl	m
} 	  | j                  }t           |          S # t          $ r t                     cY S w xY wt           t                    st          t                    rt          j        S t           t                    rIt!          t#           j                                                            \  }}|t          |          z  S t          t                    rIt!          t#          j                                                            \  }}|t           |          z  S t                     S )a2  
    Returns dot product of two vectors.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector.vector import dot
    >>> R = CoordSys3D('R')
    >>> v1 = R.i + R.j + R.k
    >>> v2 = R.x * R.i + R.y * R.j + R.z * R.k
    >>> dot(v1, v2)
    R.x + R.y + R.z

    c              3  8   K   | ]}t          |          V  d S r@   rA   r   s     r%   r   zdot.<locals>.<genexpr>Q  s+      >>aC5MM>>>>>>r'   c              3  8   K   | ]}t          |          V  d S r@   rA   r   s     r%   r   zdot.<locals>.<genexpr>S  s+      >>aCqMM>>>>>>r'   r-   r   )r3   r   r   r5   r   r   r
   r   rX   r   r   r6   ru   r   r   rv   r`   ra   r&   r4   )r   r   r   r=   rR   r   rT   r   s   ``      r%   r6   r6   @  s     % ?|>>>>5:>>>>>>% ?|>>>>5:>>>>>>%$$ 	!E:)F)F 	!:##!UNN1556&&&&&&	!uz**A ua==   	% 	% 	%ue$$$$$	% %$$ 
5*(E(E v%## !d5+11334455B#b%..  %## !d5+11334455B#eR..  ues   C7 7DDN)2
__future__r   	itertoolsr   sympy.core.addr   sympy.core.assumptionsr   sympy.core.exprr   r   sympy.core.powerr	   sympy.core.singletonr
   sympy.core.sortingr   sympy.core.sympifyr   (sympy.functions.elementary.miscellaneousr   sympy.matrices.immutabler   rk   sympy.vector.basisdependentr   r   r   r   sympy.vector.coordsysrectr   sympy.vector.dyadicr   r   r   r   r   r   rv   r   r   r   rE   r6   r   r   r   r   r   r    rO   r'   r%   <module>r      s   " " " " " "             , , , , , , , , , , , , , ,             " " " " " " / / / / / / & & & & & & 9 9 9 9 9 9 C C C C C C: : : : : : : : : : : : 0 0 0 0 0 0 = = = = = = = = = =FC FC FC FC FC^ FC FC FCR
6 6 6 6 6 6 6 6r    !6   ,$ $ $ $ $!6 $ $ $,    #V   / / / / /F / / /@- - - - -$ - - -B- - -`' ' 'T      jllr'   