K izF`ddlmZmZmZddlmZddlmZddl m Z dgZ GddeeZ dZ y) )sympifyAddImmutableMatrix) EvalfMixin) Printable) prec_to_dpsDyadicceZdZdZdZdZedZdZeZ dZ e Z dZ e Z dZd Zd Zd Zd Zd ZdZdZdZdZeZddZddZdZdZdZdZdZdZ dZ!y)r ayA Dyadic object. See: https://en.wikipedia.org/wiki/Dyadic_tensor Kane, T., Levinson, D. Dynamics Theory and Applications. 1985 McGraw-Hill A more powerful way to represent a rigid body's inertia. While it is more complex, by choosing Dyadic components to be in body fixed basis vectors, the resulting matrix is equivalent to the inertia tensor. Fcg|_|dk(rg}t|dk7rd}t|jD]\}}t|ddt|j|dk(s4t|ddt|j|dk(sb|j|d|ddz|dd|ddf|j|<|j |dd}n|dk7r2|jj |d|j |dt|dk7rd}|t|jkr|j|ddk(|j|ddk(z|j|ddk(zr-|jj |j||dz}|dz }|t|jkryy)a2 Just like Vector's init, you should not call this unless creating a zero dyadic. zd = Dyadic(0) Stores a Dyadic as a list of lists; the inner list has the measure number and the two unit vectors; the outerlist holds each unique unit vector pair. rN)argslen enumeratestrremoveappend)selfinlistaddedivs a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/vector/dyadic.py__init__zDyadic.__init__s Q;F&kQE!$)), 11&#diil1o*>>VAYq\*c$))A,q/.BB$(IIaLOfQil$B$*1IaL&)A,$@DIIaLMM&),E z   + fQi(&kQ #dii. 1aA%$))A,q/Q*>?YYq\!_)+   1.Q FA #dii. ctS)zReturns the class Dyadic. )r rs rfuncz Dyadic.func@s  rc\t|}t|j|jzS)zThe add operator for Dyadic. ) _check_dyadicr rrothers r__add__zDyadic.__add__Es$e$dii%**,--rct|j}t|}tt |D]}|||dz||d||df||<!t |S)aMultiplies the Dyadic by a sympifyable expression. Parameters ========== other : Sympafiable The scalar to multiply this Dyadic with Examples ======== >>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> d = outer(N.x, N.x) >>> 5 * d 5*(N.x|N.x) rr r )listrrrangerr )rr"newlistrs r__mul__zDyadic.__mul__Lsn&tyy/s7|$ )A'!*Q-/A!!*Q-)GAJ )grcddlm}m}t|trxt |}t d}|j D]Q}|j D]@}||d|dz|dj|dz|dj|dzz }BS|S||}|d}|j D]%}||d|dz|dj|zz }'|S)aThe inner product operator for a Dyadic and a Dyadic or Vector. Parameters ========== other : Dyadic or Vector The other Dyadic or Vector to take the inner product with Examples ======== >>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> D1 = outer(N.x, N.y) >>> D2 = outer(N.y, N.y) >>> D1.dot(D2) (N.x|N.y) >>> D1.dot(N.y) N.x r)Vector _check_vectorr r ) sympy.physics.vector.vectorr*r+ isinstancer r rdotouter)rr"r*r+olrv2s rr.z Dyadic.doths, F eV $!%(EBYY Q**QB!A$A,!A$((2a5/:adjjA>OPPBQ Q "%(EBYY 6adQqTkQqTXXe_55 6 rc*|jd|z S)z0Divides the Dyadic by a sympifyable expression. r )r(r!s r __truediv__zDyadic.__truediv__s||AI&&rc |dk(r td}t|}|jgk(r|jgk(ry|jgk(s|jgk(ryt|jt|jk(S)z[Tests for equality. Is currently weak; needs stronger comparison testing rTF)r r rsetr!s r__eq__z Dyadic.__eq__sk A:1IEe$ IIO%**"2ii2o5::#3499~UZZ00rc||k( SNr!s r__ne__z Dyadic.__ne__s5=  rc |dzSNr9rs r__neg__zDyadic.__neg__s byrc"|j}t|dk(r tdSg}|D]"}|ddk(r?|jd|j |dzdz|j |dzK|ddk(r?|jd|j |dzdz|j |dz|ddk7s|j |d}t |dt rd|z}|jd r|dd}d}nd}|j||z|j |dzdz|j |dz%d j|}|jdr|d d}|S|jd r|dd}|S) Nrr  + z\otimes r r= - (%s)- ) rrrr_printr-r startswithjoinrprinterarr0rarg_str str_startoutstrs r_latexz Dyadic._latexs YY r7a<q6M  >Atqy %'..1"66D!..1./01 %!..1./%&"..1./0 1!..1.adC($w.G%%c*%abkG %I %I )g-qt0DD%&(/qt(<=>- >0   U #ABZF   s #ABZF rc2|Gfdd}|S)NceZdZdZfdZy)Dyadic._pretty..Fakerc j j} }t|dk(r tdS jrdnd}g}|D]3}|ddk(r:|j d|j |d||j |dgF|ddk(r:|j d|j |d||j |dg|ddk7st |dtr&|j|djd}n|j |d}|jd r|dd}d} nd} |j | |d |j |d||j |dg6d j|} | jdr| d d} | S| jd r| dd} | S) Nru⊗|r r@r r=rArCrFrDrE) rrr _use_unicodeextenddoprintr-rrGparensrHrI) rrkwargsrLmppbarr0rrMrNrOerKs rrenderz#Dyadic._pretty..Fake.rendersVVr7a<q6M-4-A-A)s6Atqy 5"%++ad"3"%"%++ad"3#56 1 5"%++ad"3"%"%++ad"3#561%adC0&)jj !!'&&,fhq'2G'*kk!A$&7G"--c2&-abkG(-I(-I 9gs"%++ad"3"%"%++ad"3#5696B$$U+#ABZF &&s+#ABZF rN)__name__ __module__ __qualname__baseliner^)r]rKsrFakerSs H- rrcr9)rrKrcr]s ` @r_prettyzDyadic._prettys 0 0 bv rcd|z|zSr<r9r!s r__rsub__zDyadic.__rsub__sT U""rc4|j}t|dk(r|jdSg}|D]%}|ddk(rB|jd|j|dzdz|j|dzdzN|ddk(rB|jd|j|dzdz|j|dzdz|ddk7s|j|d}t |dt rd |z}|dd k(r|dd }d }nd }|j||zdz|j|dzdz|j|dzdz(dj |}|jd r|dd }|S|jdr|dd }|S)zPrinting method. rr z + (rUr )r=z - (rBrCNrAr@z*(rDrErF)rrrGrr-rrIrHrJs r _sympystrzDyadic._sympystrs YY r7a<>>!$ $  >!A$#77#=!..1./14561 &7>>!A$#77#=!..1./14561!..1.adC($w.G1:$%abkG %I %I )g-4!..1./ 'qt 457:;<) <.   U #ABZF   s #ABZF rc*|j|dzS)zThe subtraction operator. r=)r#r!s r__sub__zDyadic.__sub__*s||EBJ''rcddlm}||}td}|jD]1}||d|dj |dj |zz }3|S)aReturns the dyadic resulting from the dyadic vector cross product: Dyadic x Vector. Parameters ========== other : Vector Vector to cross with. Examples ======== >>> from sympy.physics.vector import ReferenceFrame, outer, cross >>> N = ReferenceFrame('N') >>> d = outer(N.x, N.x) >>> cross(d, N.y) (N.x|N.z) r)r+r r )r,r+r rr/cross)rr"r+r0rs rrmz Dyadic.cross.s_$ >e$ AY ;A !A$!A$**adjj&79: :B ; rNc"ddlm}||||S)aExpresses this Dyadic in alternate frame(s) The first frame is the list side expression, the second frame is the right side; if Dyadic is in form A.x|B.y, you can express it in two different frames. If no second frame is given, the Dyadic is expressed in only one frame. Calls the global express function Parameters ========== frame1 : ReferenceFrame The frame to express the left side of the Dyadic in frame2 : ReferenceFrame If provided, the frame to express the right side of the Dyadic in Examples ======== >>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> N = ReferenceFrame('N') >>> q = dynamicsymbols('q') >>> B = N.orientnew('B', 'Axis', [q, N.z]) >>> d = outer(N.x, N.x) >>> d.express(B, N) cos(q)*(B.x|N.x) - sin(q)*(B.y|N.x) r)express)sympy.physics.vector.functionsro)rframe1frame2ros rrozDyadic.expressJs@ ;tVV,,rc ||}t|Dcgc])}|D]"}|j|j|$+c}}jddScc}}w)aReturns the matrix form of the dyadic with respect to one or two reference frames. Parameters ---------- reference_frame : ReferenceFrame The reference frame that the rows and columns of the matrix correspond to. If a second reference frame is provided, this only corresponds to the rows of the matrix. second_reference_frame : ReferenceFrame, optional, default=None The reference frame that the columns of the matrix correspond to. Returns ------- matrix : ImmutableMatrix, shape(3,3) The matrix that gives the 2D tensor form. Examples ======== >>> from sympy import symbols, trigsimp >>> from sympy.physics.vector import ReferenceFrame >>> from sympy.physics.mechanics import inertia >>> Ixx, Iyy, Izz, Ixy, Iyz, Ixz = symbols('Ixx, Iyy, Izz, Ixy, Iyz, Ixz') >>> N = ReferenceFrame('N') >>> inertia_dyadic = inertia(N, Ixx, Iyy, Izz, Ixy, Iyz, Ixz) >>> inertia_dyadic.to_matrix(N) Matrix([ [Ixx, Ixy, Ixz], [Ixy, Iyy, Iyz], [Ixz, Iyz, Izz]]) >>> beta = symbols('beta') >>> A = N.orientnew('A', 'Axis', (beta, N.x)) >>> trigsimp(inertia_dyadic.to_matrix(A)) Matrix([ [ Ixx, Ixy*cos(beta) + Ixz*sin(beta), -Ixy*sin(beta) + Ixz*cos(beta)], [ Ixy*cos(beta) + Ixz*sin(beta), Iyy*cos(2*beta)/2 + Iyy/2 + Iyz*sin(2*beta) - Izz*cos(2*beta)/2 + Izz/2, -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2], [-Ixy*sin(beta) + Ixz*cos(beta), -Iyy*sin(2*beta)/2 + Iyz*cos(2*beta) + Izz*sin(2*beta)/2, -Iyy*cos(2*beta)/2 + Iyy/2 - Iyz*sin(2*beta) + Izz*cos(2*beta)/2 + Izz/2]]) rE)Matrixr.reshape)rreference_framesecond_reference_framerjs r to_matrixzDyadic.to_matrixmsbV " )%4 "?.a,.qquuT{q).).//6wq!} =.s.A c t|jDcgc]*}t|djdi||d|dfg,c}tdScc}w)z(Calls .doit() on each term in the Dyadicrr r r9)sumrr doit)rhintsrs rr|z Dyadic.doits^!YY(YQqTYY//1qt<=>()/4 4(/Ac ddlm}|||S)aTake the time derivative of this Dyadic in a frame. This function calls the global time_derivative method Parameters ========== frame : ReferenceFrame The frame to take the time derivative in Examples ======== >>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols >>> from sympy.physics.vector import init_vprinting >>> init_vprinting(pretty_print=False) >>> N = ReferenceFrame('N') >>> q = dynamicsymbols('q') >>> B = N.orientnew('B', 'Axis', [q, N.z]) >>> d = outer(N.x, N.x) >>> d.dt(B) - q'*(N.y|N.x) - q'*(N.x|N.y) r)time_derivative)rpr)rframers rdtz Dyadic.dts2 CtU++rctd}|jD]+}|t|dj|d|dfgz }-|S)zReturns a simplified Dyadic.rr r )r rsimplify)routrs rrzDyadic.simplifysNQi ;A 6AaDMMOQqT1Q489: :C ; rc t|jDcgc]*}t|dj|i||d|dfg,c}tdScc}w)a5Substitution on the Dyadic. Examples ======== >>> from sympy.physics.vector import ReferenceFrame >>> from sympy import Symbol >>> N = ReferenceFrame('N') >>> s = Symbol('s') >>> a = s*(N.x|N.x) >>> a.subs({s: 2}) 2*(N.x|N.x) rr r )r{rr subs)rrrZrs rrz Dyadic.subssb !YY(YQqTYY771qtDEF()/4 4(r~ct|s tdtd}|jD]#\}}}||||j |zz }%|S)z/Apply a function to each component of a Dyadic.z`f` must be callable.r)callable TypeErrorr rr/)rfrabcs r applyfunczDyadic.applyfuncsW{34 4Qiyy 'GAq! 1Q41771:& &C ' rc|js|Sg}t|}|jD]?}t|}|dj||d<|j t |At |S)Nr)n)rrr%evalfrtupler )rprecnew_argsdpsr new_inlists r _eval_evalfzDyadic._eval_evalfsoyyK$ii /FfJ"1IOOcO2JqM OOE*- . /hrcg}|jD]>}t|}|dj||d<|jt |@t |S)a Replace occurrences of objects within the measure numbers of the Dyadic. Parameters ========== rule : dict-like Expresses a replacement rule. Returns ======= Dyadic Result of the replacement. Examples ======== >>> from sympy import symbols, pi >>> from sympy.physics.vector import ReferenceFrame, outer >>> N = ReferenceFrame('N') >>> D = outer(N.x, N.x) >>> x, y, z = symbols('x y z') >>> ((1 + x*y) * D).xreplace({x: pi}) (pi*y + 1)*(N.x|N.x) >>> ((1 + x*y) * D).xreplace({x: pi, y: 2}) (1 + 2*pi)*(N.x|N.x) Replacements occur only if an entire node in the expression tree is matched: >>> ((x*y + z) * D).xreplace({x*y: pi}) (z + pi)*(N.x|N.x) >>> ((x*y*z) * D).xreplace({x*y: pi}) x*y*z*(N.x|N.x) r)rr%xreplacerrr )rrulerrrs rrzDyadic.xreplaces\Pii /FfJ&qM2248JqM OOE*- . /hrr8)"r_r`ra__doc__ is_numberrpropertyrr#__radd__r(__rmul__r.__and__r3r6r:r>rPrdrfrirkrm__xor__roryr|rrrrrrr9rrr r s I$L. H4H"JG'1 !"H4l#"H(4G!-F/=b4 ,84&  - rc<t|ts td|S)NzA Dyadic must be supplied)r-r r)r"s rr r s eV $344 LrN)sympyrrrrtsympy.core.evalfrsympy.printing.defaultsrmpmath.libmp.libmpfr__all__r r r9rrrs399'-+ *P Y P fr