K ibOddlmZddlmZddlmZmZddlmZddl m Z m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZmZmZmZdd lmZddl m!Z!m"Z"m#Z#ddl$m%Z%GddeZ&dZ'de'egiejPe&<Gdde&e Z)Gddee&Z*Gddee&Z+Gddee&Z,Gdde&Z-Gdde Z.d Z/d!Z0e&e&_1e+e&_2e*e&_3e,e&_4e)e&_5e,e&_6y")#) annotations)product)AddBasic) StdFactKB) AtomicExprExpr)Pow)S)default_sort_key)sympifysqrt)ImmutableDenseMatrix)BasisDependentZeroBasisDependentBasisDependentMulBasisDependentAdd) CoordSys3D)Dyadic BaseDyadic DyadicAdd) VectorKindcHeZdZUdZdZdZdZded<ded<ded<ded <ded <d ed <eZ d ed<e dZ dZ dZ dZdZdZeje_dZdZeje_dZddZe dZdZeje_dZdZdZy) 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 VectorZerozerorkindc|jS)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} ) _componentsselfs Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/vector/vector.py componentszVector.components(s&ct||zS)z7 Returns the magnitude of this vector. rr&s r( magnitudezVector.magnitude=sD4K  r*c(||jz S)z@ Returns the normalized version of this vector. )r,r&s r( normalizezVector.normalizeCsdnn&&&r*cP||z }|j|}|jdS)aM Check if ``self`` and ``other`` are identically equal vectors. Explanation =========== Checks if two vector expressions are equal for all possible values of the symbols present in the expressions. Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy.abc import x, y >>> from sympy import pi >>> C = CoordSys3D('C') Compare vectors that are equal or not: >>> C.i.equals(C.j) False >>> C.i.equals(C.i) True These two vectors are equal if `x = y` but are not identically equal as expressions since for some values of `x` and `y` they are unequal: >>> v1 = x*C.i + C.j >>> v2 = y*C.i + C.j >>> v1.equals(v1) True >>> v1.equals(v2) False Vectors from different coordinate systems can be compared: >>> D = C.orient_new_axis('D', pi/2, C.i) >>> D.j.equals(C.j) False >>> D.j.equals(C.k) True Parameters ========== other: Vector The other vector expression to compare with. Returns ======= ``True``, ``False`` or ``None``. A return value of ``True`` indicates that the two vectors are identically equal. A return value of ``False`` indicates that they are not. In some cases it is not possible to determine if the two vectors are identically equal and ``None`` is returned. See Also ======== sympy.core.expr.Expr.equals r)dotequals)r'otherdiff diff_mag2s r(r1z Vector.equalsIs,~e|HHTN ""r*ct|trttrtjStj}|j j D];\}}|jdj}|||z|jdzz }=|Sddl m }t||tfstt|dzdzt||rfd}|St|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"ddlm}||S)Nr)directional_derivative)sympy.vector.functionsr9)fieldr9r's r(r9z*Vector.dot..directional_derivativesI-eT::r*) isinstancerr!rr"r)itemsargsr0sympy.vector.deloperatorr7 TypeErrorstr)r'r2outveckvvect_dotr7r9s` r(r0z Vector.dotsP eV $$ +{{"[[F((..0 3166!9==.(Q,22 3M0%#v/CJ)GG*+, , eS ! ;* )4r*c$|j|SNr0r'r2s r(__and__zVector.__and__sxxr*cjt|trt|trtjStj}|jj D]I\}}|j |jd}|j|jd}|||zz }K|St ||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) rr6) r<rr!r"r)r=crossr>outer)r'r2outdyadrCrD cross_productrMs r(rLz Vector.crosss@ eV $$ +{{"kkG((..0 %1 $ 166!9 5 %++AFF1I61u9$ %NT5!!r*c$|j|SrGrLrIs r(__xor__zVector.__xor__zz%  r*c t|ts tdt|tst|trtj St |jj|jjDcgc]\\}}\}}||zt||z}}}}}t|Scc}}}}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) r<rr@r!rr"rr)r=rr)r'r2k1v1k2v2r>s r(rMz Vector.outers.%(?@ @z*5*-;;  4??002E4D4D4J4J4LMOO3E8BXb"bJr2..OO$Os "B< c|jtjr"|rtjStjS|r#|j ||j |z S|j ||j |z |zS)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 )r1rr"r Zeror0)r'r2scalars r( projectionzVector.projection$sg$ ;;v{{ ##166 4 4 88E?TXXd^3 388E?TXXd^3d: :r*c6ddlm}t|tr/tj tj tj fSt t||j}t|Dcgc]}|j|c}Scc}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.operatorsr^r<r!r rZnextiter base_vectorstupler0)r'r^base_vecis r( _projectionszVector._projections>si, > dJ 'FFAFFAFF+ +/567DDF84adhhqk4554s7Bc$|j|SrG)rMrIs r(__or__z Vector.__or__ZrSr*cxt|jDcgc]}|j|c}Scc}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]]) )Matrixrbr0)r'systemunit_vecs r( to_matrixzVector.to_matrix_s:4**,.htxx)./ /.s7ci}|jjD]B\}}|j|jtj ||zz||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)r=getrkrr")r'partsvectmeasures r(separatezVector.separate|s](!__224 2MD'"'))DKK"E"&.#1E$++  2 r*ct|trt|tr tdt|trB|tjk(r t dt |t|tjStd)z( Helper for division involving vectors. zCannot divide two vectorszCannot divide a vector by zeroz#Invalid division involving a vector) r<rr@r rZ ValueError VectorMulr NegativeOne)oner2s r( _div_helperzVector._div_helpersf c6 "z%'@78 8 V $ !ABBS#eQ]]";< <AB Br*N)F)__name__ __module__ __qualname____doc__ is_scalar is_Vector _op_priority__annotations__rr#propertyr)r,r.r1r0rJrLrRrMr\rfrhrmrsryr*r(rrs IIL !|D*#   (! ' A#F< |kkGO*"X!mmGO" H;4666!]]FN/:4 Cr*rcfd}|S)Nctti}g}|jD].}t|jt s|j |0|tk(rt|jdSy)NF)deep)r VectorAddr>r<r#rappenddoit)expr vec_classvectorstermclss r(_postprocessorz)get_postprocessor.._postprocessorsl)$S) II %D$))Z0t$ %  !g&+++7 7 "r*r)rrs` r(get_postprocessorrs8 r*rcVeZdZdZdfd ZedZdZdZedZ dZ xZ S) BaseVectorz) Class to denote a base vector. cF|dj|}|dj|}t|}t|}|tddvr tdt |t s t d|j|}t|%|t||}||_ |tji|_ tj|_|jdz|z|_d|z|_||_||_||f|_d d i}t)||_||_|S) Nzx{}zx_{}rzindex must be 0, 1 or 2zsystem should be a CoordSys3D. commutativeT)formatrArangerur<rr@ _vector_namessuper__new__r _base_instanceOner%_measure_number_name _pretty_form _latex_form_system_idr _assumptions_sys) rindexrk pretty_str latex_strnameobj assumptions __class__s r(rzBaseVector.__new__s  e,J   e,I_  N a #67 7&*-;< <##E*goc1U8V4 ,eeLL3&-  ?# &/$d+ $[1  r*c|jSrG)rr&s r(rkzBaseVector.systems ||r*c|jSrG)r)r'printers r( _sympystrzBaseVector._sympystrs zzr*ch|j\}}|j|dz|j|zS)Nr)r_printr)r'rrrks r( _sympyreprzBaseVector._sympyreprs3 v~~f%+f.B.B5.IIIr*c|hSrGrr&s r( free_symbolszBaseVector.free_symbolss v r*c|SrGrr&s r(_eval_conjugatezBaseVector._eval_conjugates r*)NN) rzr{r|r}rrrkrrrr __classcell__)rs@r(rrsF !FJr*rceZdZdZdZdZy)rz2 Class to denote sum of Vector instances. c8tj|g|i|}|SrG)rrrr>optionsrs r(rzVectorAdd.__new__!''>d>g> r*c6d}t|jj}|jd|D]T\}}|j }|D]:}||j vs|j ||z}||j |dzz }<V|ddS)Nrc(|djS)Nr)__str__)xs r(z%VectorAdd._sympystr..s1r*keyz + )listrsr=sortrbr)r) r'rret_strr=rkrq base_vectsr temp_vects r(rzVectorAdd._sympystrsT]]_**,- / 0! ALFD,,.J A' $ 2Q 6Iw~~i85@@G A A s|r*N)rzr{r|r}rrrr*r(rrs r*rc6eZdZdZdZedZedZy)rvz> Class to denote products of scalars and BaseVectors. c8tj|g|i|}|SrG)rrrs r(rzVectorMul.__new__ rr*c|jS)z) The BaseVector involved in the product. )rr&s r( base_vectorzVectorMul.base_vectors"""r*c|jS)zU The scalar expression involved in the definition of this VectorMul. )rr&s r(measure_numberzVectorMul.measure_numbers ###r*N)rzr{r|r}rrrrrr*r(rvrvs4##$$r*rvc"eZdZdZdZdZdZdZy)r!z' Class to denote a zero vector g333333(@0z\mathbf{\hat{0}}c0tj|}|SrG)rr)rrs r(rzVectorZero.__new__%s ((- r*N)rzr{r|r}rrrrrr*r(r!r!sLL%Kr*r!ceZdZdZdZdZy)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 ct|}t|}t|t|kDr t|| Stj|||}||_||_|SrG)r r rr r_expr1_expr2rexpr1expr2rs r(rz Cross.__new__<s\ E "%5e%< <%'' 'll3u-   r*c Bt|j|jSrG)rLrrr'hintss r(rz Cross.doitFsT[[$++..r*Nrzr{r|r}rrrr*r(rr*s"/r*rceZdZdZdZdZy)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 ct|}t|}t||gt\}}tj|||}||_||_|S)Nr)r sortedr r rrrrs r(rz Dot.__new__^sNuen2BC ull3u-   r*c Bt|j|jSrG)r0rrrs r(rzDot.doitgs4;; ,,r*Nrrr*r(rrJs&-r*rcttr(tjfdjDSttr(tjfdjDStt rtt rĉj j k(rjd}jd}||k(rtjShdj||hj}|dzdz|k(rdnd}|j j|zSddl m } |j }t|Stt"stt"rtjStt$r>t't)j*j-\}} | t|zStt$r>t't)j*j-\} } | t| zSt!S#t$rt!cYSwxYw) 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 c36K|]}t|ywrGrQ.0revect2s r( zcross..|s!Fa%5/!Fc36K|]}t|ywrGrQrrevect1s r(rzcross..~s!Fa%q/!Frr>rr6r6rexpress)r<rrfromiterr>rrrr" differencepoprb functionsrrLrurr!rvr`rar)r=) rrn1n2n3signrrDrVm1rXm2s `` r(rLrLks %!!!F5::!FFF%!!!F5::!FFF%$E:)F :: #ABABRx{{"$$b"X.335Bq&A+1"D //1"55 5& #uzz*AE? "%$ 5*(E{{%#d5++11345B%E"""%#d5++11345B%r"""   '& & 's8H//IIcttr(tjfdjDSttr(tjfdjDSttrtttrdj j k(r%k(rt jSt jSddl m } |j }t|Sttsttrt jSttr>t!t#j$j'\}}|t|zSttr>t!t#j$j'\}}|t|zStS#t$rtcYSwxYw)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 c36K|]}t|ywrGrHrs r(rzdot..s>aC5M>rc36K|]}t|ywrGrHrs r(rzdot..s>aCqM>rr6r)r<rrr>rrr rrZrrr0rurr!rvr`rar)r=)rrrrDrVrrXrs`` r(r0r0sn %||>5::>>>%||>5::>>>%$E:)F :: #!UN155 6 6& !uzz*Aua= %$ 5*(Evv %#d5++11345B#b%.  %#d5++11345B#eR.  ue  %ue$ $ %sGG'&G'N)7 __future__r itertoolsr sympy.corerrsympy.core.assumptionsrsympy.core.exprrr sympy.core.powerr sympy.core.singletonr sympy.core.sortingr sympy.core.sympifyr (sympy.functions.elementary.miscellaneousrsympy.matrices.immutablerrjsympy.vector.basisdependentrrrrsympy.vector.coordsysrectrsympy.vector.dyadicrrrsympy.vector.kindrrr"_constructor_postprocessor_mappingrrrvr!rrrLr0rrrrr r"rr*r(rs "!,, "/&9C::0==(KC^KC^  c " #4((099x!6,$!6$, #V /F/@-$-B-`'Tl r*