
    \hzF                     `    S SK JrJrJr  S SKJr  S SKJr  S SK	J
r
  S/r " S S\\5      rS rg)	    )sympifyAddImmutableMatrix)
EvalfMixin)	Printable)prec_to_dpsDyadicc                       \ rS rSrSrSrS r\S 5       rS r	\	r
S r\rS r\rS	 rS
 rS rS rS rS rS rS rS rS r\rSS jrSS jrS rS rS rS rS r S r!S r"Sr#g)r	      a]  A 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.

Fc                    / U l         US:X  a  / n[        U5      S:w  Ga  Sn[        U R                   5       H  u  p4[        US   S   5      [        U R                   U   S   5      :X  d  M5  [        US   S   5      [        U R                   U   S   5      :X  d  Me  U R                   U   S   US   S   -   US   S   US   S   4U R                   U'   UR	                  US   5        Sn  O   US:w  a2  U R                   R                  US   5        UR	                  US   5        [        U5      S:w  a  GM  SnU[        U R                   5      :  a  U R                   U   S   S:H  U R                   U   S   S:H  -  U R                   U   S   S:H  -  (       a-  U R                   R	                  U R                   U   5        US-  nUS-  nU[        U R                   5      :  a  M  gg)z
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.

r         N)argslen	enumeratestrremoveappend)selfinlistaddedivs        S/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/vector/dyadic.py__init__Dyadic.__init__   s    	Q;F&kQE!$)),1&#diil1o*>>VAYq\*c$))A,q/.BB$(IIaLOfQil$B$*1IaL&)A,$@DIIaLMM&),E - z		  +fQi( &kQ #dii. 1aA%$))A,q/Q*>?YYq\!_)+		  1.QFA #dii.     c                     [         $ )zReturns the class Dyadic. )r	   r   s    r   funcDyadic.func@   s	     r   c                 \    [        U5      n[        U R                  UR                  -   5      $ )zThe add operator for Dyadic. )_check_dyadicr	   r   r   others     r   __add__Dyadic.__add__E   s$    e$dii%**,--r   c                     [        U R                  5      n[        U5      n[        [	        U5      5       H  nXU   S   -  X#   S   X#   S   4X#'   M     [        U5      $ )a%  Multiplies 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)

r   r   r   )listr   r   ranger   r	   )r   r%   newlistr   s       r   __mul__Dyadic.__mul__L   sa    & tyy/s7|$A!*Q-/A!*Q-)GJ % gr   c                    SSK JnJn  [        U[        5      (       a{  [        U5      n[	        S5      nU R                   HS  nUR                   H@  nXES   US   -  US   R                  US   5      -  US   R                  US   5      -  -  nMB     MU     U$ U" U5      nU" S5      nU R                   H%  nXES   US   -  US   R                  U5      -  -  nM'     U$ )az  The 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/   r0   
isinstancer	   r#   r   dotouter)r   r%   r/   r0   olr   v2s          r   r3   
Dyadic.doth   s    , 	FeV$$!%(EBYY**BA$A,!A$((2a5/:adjjA>OPPB %  		 "%(EBYYdQqTkQqTXXe_55 	r   c                 *    U R                  SU-  5      $ )z0Divides the Dyadic by a sympifyable expression. r   )r,   r$   s     r   __truediv__Dyadic.__truediv__   s    ||AI&&r   c                    US:X  a  [        S5      n[        U5      nU R                  / :X  a  UR                  / :X  a  gU R                  / :X  d  UR                  / :X  a  g[        U R                  5      [        UR                  5      :H  $ )zKTests for equality.

Is currently weak; needs stronger comparison testing

r   TF)r	   r#   r   setr$   s     r   __eq__Dyadic.__eq__   sk     A:1IEe$IIO%**"2ii2o5::#3499~UZZ00r   c                     X:X  + $ N r$   s     r   __ne__Dyadic.__ne__   s      r   c                     U S-  $ NrA   r   s    r   __neg__Dyadic.__neg__   s    byr   c                 Z   U R                   n[        U5      S:X  a  [        S5      $ / nU GH2  nUS   S:X  a@  UR                  SUR	                  US   5      -   S-   UR	                  US   5      -   5        MM  US   S:X  a@  UR                  SUR	                  US   5      -   S-   UR	                  US   5      -   5        M  US   S:w  d  M  UR	                  US   5      n[        US   [        5      (       a  SU-  nUR                  S	5      (       a  USS  nSnOSnUR                  Xe-   UR	                  US   5      -   S-   UR	                  US   5      -   5        GM5     S
R                  U5      nUR                  S5      (       a  USS  nU$ UR                  S5      (       a  USS  nU$ )Nr   r    + z\otimes r   rF    - (%s)-     )	r   r   r   r   _printr2   r   
startswithjoinr   printerarr5   r   arg_str	str_startoutstrs           r   _latexDyadic._latex   s   YYr7a<q6MAtqy		%'..1"66D!..1./ 0 1		%!..1./%& "..1./ 0 1!..1.adC(($w.G%%c**%abkG %I %I		)-qt0DD%&(/qt(<= >- 0 U##ABZF  s##ABZFr   c                 4   ^^ U m " UU4S jS5      nU" 5       $ )Nc                   (   > \ rS rSrSrU U4S jrSrg)Dyadic._pretty.<locals>.Fake   r   c                   > TR                   nTn[        U5      S:X  a  [        S5      $ TR                  (       a  SOSn/ nU GHC  nUS   S:X  a;  UR	                  SUR                  US   5      UUR                  US   5      /5        MH  US   S:X  a;  UR	                  SUR                  US   5      UUR                  US   5      /5        M  US   S:w  d  M  [        US   [        5      (       a&  UR                  US   5      R                  5       S   nOUR                  US   5      nUR                  S	5      (       a  USS  nSn	OSn	UR	                  XS
UR                  US   5      UUR                  US   5      /5        GMF     SR                  U5      n
U
R                  S5      (       a  U
SS  n
U
$ U
R                  S
5      (       a  U
SS  n
U
$ )Nr   u   ⊗|r   rJ   r   rF   rK   rM   rP   rN   rO   )r   r   r   _use_unicodeextenddoprintr2   r   rQ   parensrR   rS   )r   r   kwargsrV   mppbarr5   r   rW   rX   rY   erU   s              r   render#Dyadic._pretty.<locals>.Fake.render   s   VVr7a<q6M-4-A-A)sAtqy		5"%++ad"3"%"%++ad"3#5 6 1		5"%++ad"3"%"%++ad"3#5 6 1%adC00&)jj !!'&&,fhq'2G '*kk!A$&7G"--c22&-abkG(-I(-I		9s"%++ad"3"%"%++ad"3#5 69 B $$U++#ABZF  &&s++#ABZFr   rA   N)__name__
__module____qualname____firstlineno__baselinerj   __static_attributes__)ri   rU   s   r   Faker^      s    H- -r   rr   rA   )r   rU   rr   ri   s    ` @r   _prettyDyadic._pretty   s    0	 0	b vr   c                     SU -  U-   $ rE   rA   r$   s     r   __rsub__Dyadic.__rsub__  s    T	U""r   c                 d   U R                   n[        U5      S:X  a  UR                  S5      $ / nU GH1  nUS   S:X  aC  UR                  SUR                  US   5      -   S-   UR                  US   5      -   S-   5        MP  US   S:X  aC  UR                  SUR                  US   5      -   S-   UR                  US   5      -   S-   5        M  US   S:w  d  M  UR                  US   5      n[	        US   [
        5      (       a  S	U-  nUS   S
:X  a  USS nSnOSnUR                  Xe-   S-   UR                  US   5      -   S-   UR                  US   5      -   S-   5        GM4     SR                  U5      nUR                  S5      (       a  USS nU$ UR                  S5      (       a  USS nU$ )zPrinting method. r   r   z + (ra   r   )rF   z - (rL   rM   NrK   rJ   z*(rN   rO   rP   )r   r   rQ   r   r2   r   rS   rR   rT   s           r   	_sympystrDyadic._sympystr  s   YYr7a<>>!$$Atqy		&7>>!A$#77#=!..1./145 6 1		&7>>!A$#77#=!..1./145 6 1!..1.adC(($w.G1:$%abkG %I %I		)-4!..1./ 'qt 457:; <) . U##ABZF  s##ABZFr   c                 *    U R                  US-  5      $ )zThe subtraction operator. rF   )r&   r$   s     r   __sub__Dyadic.__sub__*  s    ||EBJ''r   c                     SSK Jn  U" U5      n[        S5      nU R                   H1  nX4S   US   R	                  US   R                  U5      5      -  -  nM3     U$ )a:  Returns 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   )r0   r   r   )r1   r0   r	   r   r4   cross)r   r%   r0   r5   r   s        r   r   Dyadic.cross.  sX    $ 	>e$AYAA$!A$**adjj&79::B 	r   Nc                      SSK Jn  U" XU5      $ )ag  Expresses 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.functionsr   )r   frame1frame2r   s       r   r   Dyadic.expressJ  s    @ 	;tV,,r   c           
          Uc  Un[        U VVs/ s H,  nU  H"  oCR                  U 5      R                  U5      PM$     M.     snn5      R                  SS5      $ s  snnf )ai  Returns 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]])

rO   )Matrixr3   reshape)r   reference_framesecond_reference_framer   js        r   	to_matrixDyadic.to_matrixm  sd    V ")%4"? .?a, HIuuT{q), *? . //6wq!}	= .s   3A
c                     [        U R                   Vs/ s H+  n[        US   R                  " S0 UD6US   US   4/5      PM-     sn[        S5      5      $ s  snf )z(Calls .doit() on each term in the Dyadicr   r   r   rA   )sumr   r	   doit)r   hintsr   s      r   r   Dyadic.doit  sa    !YY(& QqTYY//1qt<=>&()/4 	4 (   2Ac                     SSK Jn  U" X5      $ )a'  Take 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)r   r   )r   framer   s      r   dt	Dyadic.dt  s    2 	Ct++r   c                     [        S5      nU R                   H,  nU[        US   R                  5       US   US   4/5      -  nM.     U$ )zReturns a simplified Dyadic.r   r   r   )r	   r   simplify)r   outr   s      r   r   Dyadic.simplify  sI    QiA6AaDMMOQqT1Q489::C 
r   c                     [        U R                   Vs/ s H+  n[        US   R                  " U0 UD6US   US   4/5      PM-     sn[        S5      5      $ s  snf )zSubstitution 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)

r   r   r   )r   r   r	   subs)r   r   rf   r   s       r   r   Dyadic.subs  se      !YY(& QqTYY771qtDEF&()/4 	4 (r   c                     [        U5      (       d  [        S5      e[        S5      nU R                   H"  u  p4nX!" U5      UR	                  U5      -  -  nM$     U$ )z/Apply a function to each component of a Dyadic.z`f` must be callable.r   )callable	TypeErrorr	   r   r4   )r   fr   abcs         r   	applyfuncDyadic.applyfunc  sR    {{344QiyyGA!1Q41771:&&C !
r   c                     U R                   (       d  U $ / n[        U5      nU R                    H=  n[        U5      nUS   R                  US9US'   UR	                  [        U5      5        M?     [        U5      $ )Nr   )n)r   r   r)   evalfr   tupler	   )r   precnew_argsdpsr   
new_inlists         r   _eval_evalfDyadic._eval_evalf  sj    yyK$iiFfJ"1IOOcO2JqMOOE*-.   hr   c                     / nU R                    H?  n[        U5      nUS   R                  U5      US'   UR                  [	        U5      5        MA     [        U5      $ )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   )r   r)   xreplacer   r   r	   )r   ruler   r   r   s        r   r   Dyadic.xreplace  sW    P iiFfJ&qM2248JqMOOE*-.   hr   )r   r@   )$rl   rm   rn   ro   __doc__	is_numberr   propertyr    r&   __radd__r,   __rmul__r3   __and__r9   r=   rB   rG   rZ   rs   rv   rz   r}   r   __xor__r   r   r   r   r   r   r   r   r   rq   rA   r   r   r	   r	      s    
 I$L  .
 H4 H"J G'1 !"H4l#"H(4 G!-F/=b4
,84&	 - r   c                 F    [        U [        5      (       d  [        S5      eU $ )NzA Dyadic must be supplied)r2   r	   r   )r%   s    r   r#   r#     s     eV$$344Lr   N)sympyr   r   r   r   sympy.core.evalfr   sympy.printing.defaultsr   mpmath.libmp.libmpfr   __all__r	   r#   rA   r   r   <module>r      s3    9 9 ' - + *P Y
 P fr   