
    sgE                       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        y)     )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y)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    F/var/www/html/venv/lib/python3.12/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                (    | | j                         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
                  j                         D ];  \  }}|j                  d   j                         }|||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-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 3166!9==.(Q,223 M0%#v/CJ)GG*+ , , eS!; *)4r'   c                $    | j                  |      S Nr6   r$   r:   s     r%   __and__zVector.__and__   s    xxr'   c                j   t        |t              rt        | t              rt        j                  S t        j                  }|j                  j                         D ]I  \  }}| j                  |j                  d         }|j                  |j                  d         }|||z  z  }K |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$$
+{{"kkG((..0 %1 $

166!9 5%++AFF1I61u9$% NT5!!r'   c                $    | j                  |      S r@   rE   rB   s     r%   __xor__zVector.__xor__       zz%  r'   c                   t        |t              st        d      t        | t              st        |t              rt        j
                  S t        | j                  j                         |j                  j                               D cg c]  \  \  }}\  }}||z  t        ||      z   }}}}}t        | S c c}}}}w )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 product)r3   r   r8   r   r   r    r   r&   r4   r   r   )r$   r:   k1v1k2v2r5   s          r%   rF   zVector.outer   s    . %(?@@z*5*-;;
 4??002E4D4D4J4J4LMO O3E8BXb"bJr2.. O O $Os   "B<
c                   | j                  t        j                        r"|rt        j                  S t        j                  S |r#| j                  |      | j                  |       z  S | j                  |      | j                  |       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   sg    $ ;;v{{##1664488E?TXXd^3388E?TXXd^3d::r'   c                6   ddl m} t        | t              r/t        j
                  t        j
                  t        j
                  fS t        t         ||                   j                         }t        |D cg c]  }| j                  |       c}      S c c}w )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_systems)sympy.vector.operatorsrX   r3   r   r
   rT   nextiterbase_vectorstupler6   )r$   rX   base_vecis       r%   _projectionszVector._projections   si    , 	>dJ'FFAFFAFF++/567DDF84adhhqk4554s   7Bc                $    | j                  |      S r@   )rF   rB   s     r%   __or__zVector.__or__  rL   r'   c                x    t        |j                         D cg c]  }| j                  |       c}      S c c}w )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]])

        )Matrixr\   r6   )r$   systemunit_vecs      r%   	to_matrixzVector.to_matrix  s:    4 **,.htxx) . / 	/ .s   7c                    i }| j                   j                         D ]B  \  }}|j                  |j                  t        j
                        ||z  z   ||j                  <   D |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   getre   r   r    )r$   partsvectmeasures       r%   separatezVector.separate6  s]    ( !__224 	2MD'"'))DKK"E"&.#1E$++	2 r'   c                   t        | t              rt        |t              rt        d      t        | t              rB|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
   rT   
ValueError	VectorMulr	   NegativeOne)oner:   s     r%   _div_helperzVector._div_helperP  sf    c6"z%'@788V$ !ABBS#eQ]]";<<ABBr'   N)F)__name__
__module____qualname____doc__	is_scalar	is_Vector_op_priority__annotations__propertyr&   r)   r+   r6   rC   rE   rK   rF   rV   r`   rb   rg   rm   rs    r'   r%   r   r      s     IIL
   (!'< | kkGO*"X! mmGO" H;4 6 66! ]]FN/:4	Cr'   r   c                  P     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.

    c                F   |dj                  |      }|dj                  |      }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   rangero   r3   r   r8   _vector_namessuper__new__r
   _base_instanceOner"   _measure_number_name_pretty_form_latex_form_system_idr   _assumptions_sys)	clsindexre   
pretty_str	latex_strnameobjassumptions	__class__s	           r%   r   zBaseVector.__new__b  s   e,Je,I_
	N	a#677&*-;<<##E*goc1U8V4 ,eeLL3&-	
?#&/$d+$[1
 
r'   c                    | j                   S r@   )r   r#   s    r%   re   zBaseVector.system  s    ||r'   c                    | j                   S r@   )r   )r$   printers     r%   	_sympystrzBaseVector._sympystr  s    zzr'   c                h    | j                   \  }}|j                  |      dz   |j                  |   z   S )Nr   )r   _printr   )r$   r   r   re   s       r%   
_sympyreprzBaseVector._sympyrepr  s3    v~~f%+f.B.B5.IIIr'   c                    | hS r@   r}   r#   s    r%   free_symbolszBaseVector.free_symbols  s	    vr'   )NN)rt   ru   rv   rw   r   r|   re   r   r   r   __classcell__)r   s   @r%   r   r   \  sA    
!F  J  r'   r   c                      e Zd ZdZd Zd Zy)	VectorAddz2
    Class to denote sum of Vector instances.
    c                8    t        j                  | g|i |}|S r@   )r   r   r   r5   optionsr   s       r%   r   zVectorAdd.__new__  !    ''>d>g>
r'   c                6   d}t        | j                         j                               }|j                  d        |D ]T  \  }}|j	                         }|D ]:  }||j
                  v s| j
                  |   |z  }||j                  |      dz   z  }< V |d d S )Nr   c                (    | d   j                         S )Nr   )__str__)xs    r%   <lambda>z%VectorAdd._sympystr.<locals>.<lambda>  s    1 r'   keyz + )listrm   r4   sortr\   r&   r   )	r$   r   ret_strr4   re   rk   
base_vectsr   	temp_vects	            r%   r   zVectorAdd._sympystr  s    T]]_**,-

/
0! 	ALFD,,.J A' $ 2Q 6Iw~~i85@@GA	A s|r'   N)rt   ru   rv   rw   r   r   r}   r'   r%   r   r     s    
r'   r   c                  6    e Zd ZdZd Zed        Zed        Zy)rp   z>
    Class to denote products of scalars and BaseVectors.
    c                8    t        j                  | g|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)rt   ru   rv   rw   r   r|   r   r   r}   r'   r%   rp   rp     s4     # # $ $r'   rp   c                  "    e Zd ZdZdZdZdZd Zy)r   z'
    Class to denote a zero vector
    g333333(@0z\mathbf{\hat{0}}c                0    t        j                  |       }|S r@   )r   r   )r   r   s     r%   r   zVectorZero.__new__  s     ((-
r'   N)rt   ru   rv   rw   rz   r   r   r   r}   r'   r%   r   r     s     LL%Kr'   r   c                      e Zd ZdZd Zd Zy)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        |      kD  rt        ||       S t        j                  | ||      }||_        ||_        |S r@   )r   r   r   r   r   _expr1_expr2r   expr1expr2r   s       r%   r   zCross.__new__  s\    E"%5e%<<%'''ll3u-


r'   c                B    t        | j                  | j                        S r@   )rE   r   r   r$   hintss     r%   doitz
Cross.doit  s    T[[$++..r'   Nrt   ru   rv   rw   r   r   r}   r'   r%   r   r     s    "/r'   r   c                      e Zd ZdZd Zd Zy)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__  sN    uen2BCull3u-


r'   c                B    t        | j                  | j                        S r@   )r6   r   r   r   s     r%   r   zDot.doit  s    4;;,,r'   Nr   r}   r'   r%   r   r     s    &-r'   r   c                    t         t              r(t        j                  fd j                  D              S t        t              r(t        j                   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j                  ||h      j                         }|dz   dz  |k(  rdnd}| j                  j                         |   z  S ddlm} 	  | j                        }t        |      S t         t"              st        t"              rt        j                  S t         t$              r>t'        t)         j*                  j-                                     \  }}	|	t        |      z  S t        t$              r>t'        t)        j*                  j-                                     \  }
}|t         |
      z  S t!               S # t        $ r t!               cY S w xY w)	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  6   K   | ]  }t        |        y wr@   rJ   .0r_   vect2s     r%   	<genexpr>zcross.<locals>.<genexpr>!  s     !Fa%5/!F   c              3  6   K   | ]  }t        |        y wr@   rJ   r   r_   vect1s     r%   r   zcross.<locals>.<genexpr>#  s     !Fa%q/!Fr   r   >   r   r-      r-   r   express)r3   r   r   fromiterr5   r   r   r   r    
differencepopr\   	functionsr   rE   ro   r   r   rp   rZ   r[   r&   r4   )r   r   n1n2n3signr   r=   rO   m1rQ   m2s   ``          r%   rE   rE     s     %!!!F5::!FFF%!!!F5::!FFF%$E:)F::#ABABRx{{"$$b"X.335Bq&A+1"D

//1"555&	#uzz*A E?"%$
5*(E{{%#d5++11345B%E"""%#d5++11345B%r"""  	'&&	's   8H/ /IIc                    t         t              r(t        j                  fd j                  D              S t        t              r(t        j                   fdj                  D              S t         t              rtt        t              rd j
                  j
                  k(  r% k(  rt        j                  S t        j                  S ddl	m
} 	  | j
                        }t         |      S t         t              st        t              rt        j                  S t         t              r>t!        t#         j$                  j'                                     \  }}|t        |      z  S t        t              r>t!        t#        j$                  j'                                     \  }}|t         |      z  S t               S # t        $ r t               cY S w xY w)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  6   K   | ]  }t        |        y wr@   rA   r   s     r%   r   zdot.<locals>.<genexpr>Q  s     >aC5M>r   c              3  6   K   | ]  }t        |        y wr@   rA   r   s     r%   r   zdot.<locals>.<genexpr>S  s     >aCqM>r   r-   r   )r3   r   r   r5   r   r   r
   r   rT   r   r   r6   ro   r   r   rp   rZ   r[   r&   r4   )r   r   r   r=   rO   r   rQ   r   s   ``      r%   r6   r6   @  sn     %||>5::>>>%||>5::>>>%$E:)F::#!UN15566&	!uzz*A ua= %$
5*(Evv%#d5++11345B#b%.  %#d5++11345B#eR.  ue  	%ue$$	%s   G G'&G'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   rd   sympy.vector.basisdependentr   r   r   r   sympy.vector.coordsysrectr   sympy.vector.dyadicr   r   r   r   r   r   rp   r   r   r   rE   r6   r   r   r   r   r   r    r}   r'   r%   <module>r      s    "   , ,   " / & 9 C: : 0 = =FC^ FCR
6 6r!6 ,$!6 $,#V /F /@-$ -B-`'T      lr'   