+
    i<                        ^ RI HtHt ^ RIHt ^ RIHtHtHt ^ RI	H
t
Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHtHtHtHtHtHt ^ R	IHt ^ R
IHt ^ RIH t  ^ RI!H"t# ^RI$H%t% ^RI&H't' ^RI(H)t) ^RI*H*t* ^RI+H,t, ^RI-H.t.H/t/H0t0H1t1  ! R R]']4      t2]
Pf                  ! ]]23]24       R t4R t5R t6R t7R t8R t9R t:R t;R t<]<]5]7];]9]]! R 4      ]6]8]]:3t=]! ]! ]2]! ]=!  /4      4      t>R t?R  t@]@]R&   R!# )"    )askQ)handlers_dict)BasicsympifyS)mulMul)NumberIntegerDummy)adjoint)rm_idunpacktypedflattenexhaustdo_onenew)NonInvertibleMatrixError)
MatrixBase)sympy_deprecation_warning)validate_matmul_integer)Inverse)
MatrixExpr)MatPow)	transpose)PermutationMatrix)
ZeroMatrixIdentityGenericIdentity	OneMatrixc                      a a ] tR t^t oRtRt]! 4       tRRRRRR/R lt]	R	 4       t
]R
 4       tRR ltR tR tV 3R ltR tR tR tR tR tR tRR ltR tRtVtV ;t# )MatMulz
A product of matrix expressions

Examples
========

>>> from sympy import MatMul, MatrixSymbol
>>> A = MatrixSymbol('A', 5, 4)
>>> B = MatrixSymbol('B', 4, 3)
>>> C = MatrixSymbol('C', 3, 6)
>>> MatMul(A, B, C)
A*B*C
TevaluateFcheckN_sympifyc                 a  V'       g   S P                   # \        \        V 3R  lV4      4      pV'       d   \        \        \        V4      4      p\
        P                  ! S .VO5!  pVP                  4       w  rgVe   \        RRRR7       VRJd
   \        V!   V'       g   V# V'       d   S P                  V4      # V# )c                 "   < SP                   V 8g  # N)identity)iclss   &ځ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/matrices/expressions/matmul.py<lambda> MatMul.__new__.<locals>.<lambda>0   s    S\\Q%6    zaPassing check to MatMul is deprecated and the check argument will be removed in a future version.z1.11z,remove-check-argument-from-matrix-operations)deprecated_since_versionactive_deprecations_targetF)r,   listfiltermapr   r   __new__as_coeff_matricesr   validate	_evaluate)r.   r&   r'   r(   argsobjfactormatricess   f$$$*   r/   r8   MatMul.__new__*   s    << F6=>GT*+DmmC'$'002%s)/+Y[
 h M==%%
r2   c                    \        V4      # r+   )canonicalize)r.   exprs   &&r/   r;   MatMul._evaluateJ   s    D!!r2   c                    V P                    Uu. uF  qP                  '       g   K  VNK  	  ppV^ ,          P                  VR,          P                  3# u upi )r   )r<   	is_Matrixrowscols)selfargr?   s   &  r/   shapeMatMul.shapeN   sD    #'99>9CCC9>  (2,"3"344 ?s
   AAc                >  a ^ RI Hp ^ RIHo V P	                  4       w  rg\        V4      ^8X  d   Wg^ ,          W3,          ,          # R.\        V4      ^,           ,          pR.\        V4      ^,
          ,          p	W^ &   W(R&   R p
VP                  RV
! 4       4      p\        ^\        V4      4       F  p\        V4      W&   K  	  \        VRR 4       F!  w  rVP                  ^,          ^,
          W&   K#  	  \        V4       UUu. uF,  w  rVP                  W,          W^,           ,          VR7      NK.  	  ppp\        P                  ! V4      p\        ;QJ d    V3R lV 4       F  '       g   K   RM	  R	M! V3R lV 4       4      '       d   RpWe! V.\        V^R ^ .\        V	4      ,          V	4      O5!  ,          p\        ;QJ d    R
 V	 4       F  '       g   K   RM	  R	M! R
 V	 4       4      '       g   R	pV'       d   VP!                  4       # T# u uppi )r   )Sum)ImmutableMatrixNc               3   N   "   ^p  \        RV ,          4      x  V ^,          p K   5i)   zi_%ir   )counters    r/   fMatMul._entry.<locals>.fb   s&     GFW,--1   #%dummy_generator)rW   c              3   D   <"   T F  qP                  S4      x  K  	  R # 5ir+   )has).0vrP   s   & r/   	<genexpr> MatMul._entry.<locals>.<genexpr>q   s     8x!uu_%%xs    TFc              3   N   "   T F  p\        V\        \        34      x  K  	  R # 5ir+   )
isinstancer   int)rZ   r[   s   & r/   r\   r]   y   s     E*Q:a'300*rV   rF   )sympy.concrete.summationsrO   sympy.matrices.immutablerP   r9   lengetrangenext	enumeraterL   _entryr
   fromiteranyzipdoit)rJ   r-   jexpandkwargsrO   coeffr?   indices
ind_rangesrT   rW   rK   expr_in_sumresultrP   s   &&&&,          @r/   rh   MatMul._entryS   s   1<002x=AA;qt,,,&#h-!+,VS]Q./

	 !**%6<q#h-(Ao.GJ )  ".FAIIaL1,JM /hqrzh{|h{^d^_CJJwz7Q3<JYh{|ll8,38x83338x888FsWQr]QCJ$7D  sE*EsssE*EEEF &v{{}2F2 }s   2Hc                   V P                    Uu. uF  qP                  '       d   K  VNK  	  ppV P                    Uu. uF  qP                  '       g   K  VNK  	  pp\        V!  pVP                  R J d   \	        R4      hWC3# u upi u upi )Fz3noncommutative scalars in MatMul are not supported.)r<   rG   r
   is_commutativeNotImplementedError)rJ   xscalarsr?   rp   s   &    r/   r9   MatMul.as_coeff_matrices}   sq    "ii;i{{11i;#yy8y!KKAAy8W5(%&[\\ <8s   BBB	B	c                <    V P                  4       w  rV\        V!  3# r+   )r9   r%   )rJ   rp   r?   s   &  r/   as_coeff_mmulMatMul.as_coeff_mmul   s"    002fh'''r2   c                N   < \         \        V `
  ! R/ VB pV P                  V4      # N )superr%   rn   r;   )rJ   ro   expanded	__class__s   &, r/   rn   MatMul.expand   s&    -77~~h''r2   c           	         V P                  4       w  r\        V.VRRR1,           Uu. uF  p\        V4      NK  	  upO5!  P                  4       # u upi )aP  Transposition of matrix multiplication.

Notes
=====

The following rules are applied.

Transposition for matrix multiplied with another matrix:
`\left(A B\right)^{T} = B^{T} A^{T}`

Transposition for matrix multiplied with scalar:
`\left(c A\right)^{T} = c A^{T}`

References
==========

.. [1] https://en.wikipedia.org/wiki/Transpose
NrF   )r9   r%   r   rl   )rJ   rp   r?   rK   s   &   r/   _eval_transposeMatMul._eval_transpose   sT    & 002@/7"~>~Ys^~>@@D	G>s   A
c                    \        V P                  R R R1,           Uu. uF  p\        V4      NK  	  up!  P                  4       # u upi )NrF   )r%   r<   r   rl   )rJ   rK   s   & r/   _eval_adjointMatMul._eval_adjoint   s8    		$B$@@AFFHH@s   Ac                |    V P                  4       w  rV^8w  d#   ^RIHp W! VP                  4       4      ,          # R# )rR   )traceN)r}   r   rl   )rJ   r>   mmulr   s   &   r/   _eval_traceMatMul._eval_trace   s7    ))+Q;$E$))+... r2   c           	         ^ RI Hp V P                  4       w  r#\        V!  pW P                  ,          \        \        \        W4      4      !  ,          # )r   )Determinant)&sympy.matrices.expressions.determinantr   r9   only_squaresrH   r
   r5   r7   )rJ   r   r>   r?   square_matricess   &    r/   _eval_determinantMatMul._eval_determinant   sA    F113&1yy 3S-N(O#PPPr2   c                   \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       d3   \        R V P                  RRR1,           4       !  P                  4       # \	        V 4      # )c              3   j   "   T F)  p\        V\        4      '       g   K  VP                  x  K+  	  R # 5ir+   )r_   r   	is_squarerZ   rK   s   & r/   r\   'MatMul._eval_inverse.<locals>.<genexpr>   s     Q	ZZ5P}s}}	s   33FTc              3      "   T F4  p\        V\        4      '       d   VP                  4       MVR,          x  K6  	  R# 5i)rR   NrF   )r_   r   inverser   s   & r/   r\   r      s2      . ",C!<!<#r'I.s   <>NrF   )allr<   r%   rl   r   )rJ   s   &r/   _eval_inverseMatMul._eval_inverse   sf    3Q		Q333Q		QQQ #yy2  df	
 t}r2   c                  a SP                  R R4      pV'       dH   \        ;QJ d!    . V3R lV P                   4       F  NK  	  5M! V3R lV P                   4       4      pMV P                  p\        \	        V!  4      pV# )deepTc              3   F   <"   T F  qP                   ! R/ SB x  K  	  R # 5ir   )rl   )rZ   rK   hintss   & r/   r\   MatMul.doit.<locals>.<genexpr>   s     @is*E*is   !)rd   tupler<   rB   r%   )rJ   r   r   r<   rC   s   &l   r/   rl   MatMul.doit   sZ    yy&5@dii@55@dii@@D99D FDM*r2   c           	        V P                    Uu. uF  qDP                  '       g   K  VNK  	  ppV P                    Uu. uF  qDP                  '       d   K  VNK  	  ppV'       d   \        V4      p\        V4      pV'       df   V'       d^   \        V4      V8w  dN   \	        R V Uu. uF0  p\        V P                   4      P                  V4      ^8  g   K.  VNK2  	  up,          4      hWV.# u upi u upi u upi )z"repeated commutative arguments: %s)r<   rw   rc   set
ValueErrorr5   count)	rJ   csetwarnro   ry   coeff_ccoeff_ncclencis	   &&&,     r/   args_cncMatMul.args_cnc   s    "ii<i+;+;11i<#yyAy!0@0@AAyAw<D'lGW!5 !E/6!Xw$tyy/:O:OPR:SVW:W""w!X"Y Z Z"" =A "Ys!   C+C+C0C0%+C5
C5
c           	     2   ^RI Hp \        V P                  4       UUu. uF   w  r4VP	                  V4      '       g   K  VNK"  	  ppp. pV EF;  pV P                  RV pV P                  V^,           R p	V	'       d   \
        P                  V	4      p
M\        V P                  ^,          4      p
V'       dW   \
        P                  \        V4       Uu. uF,  q3P                  '       d   V! V4      P                  4       MTNK.  	  up4      pM\        V P                  ^ ,          4      pV P                  V,          P                  V4      pV F6  pVP                  V4       VP                  V
4       VP                  V4       K8  	  EK>  	  V# u uppi u upi )rR   )	TransposeN)r   r   rg   r<   rY   r%   ri   r!   rL   reversedrG   rl   _eval_derivative_matrix_linesappend_firstappend_secondappend)rJ   ry   r   r-   rK   
with_x_indlinesind	left_args
right_args	right_matleft_revds   &&           r/   r   $MatMul._eval_derivative_matrix_lines   s4   (&/		&:I&:FAcggajaa&:
IC		$3I3q56*J"OOJ7	$TZZ]3	!??_ghq_r+s_rZ[;;;IaL,=,=,?TU,U_r+st#DJJqM2		#<<Q?Ax(	*Q  & + J ,ts   FF2F
r   T)FT)__name__
__module____qualname____firstlineno____doc__	is_MatMulr"   r,   r8   classmethodr;   propertyrL   rh   r9   r}   rn   r   r   r   r   r   rl   r   r   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r/   r%   r%      s      I HU $  @ " " 5 5(3T((G.I/Q		# r2   r%   c                  R    V ^ ,          ^8X  d
   V R,          p \        \        .V O5!  # )r   rR   NN)r   r%   )r<   s   *r/   newmulr      s&    Aw!|Bxvr2   c                 d   \         ;QJ d&    R  V P                   4       F  '       g   K   RM	  RM! R  V P                   4       4      '       d]   V P                   Uu. uF  qP                  '       g   K  VNK  	  pp\        V^ ,          P                  VR,          P
                  4      # V # u upi )c              3      "   T F9  pVP                   ;'       g!    VP                  ;'       d    VP                  x  K;  	  R # 5ir+   )is_zerorG   is_ZeroMatrixr   s   & r/   r\   any_zeros.<locals>.<genexpr>   s8      ,"*3 ;;??3==>>S->->?"*s   AAATFrF   )rj   r<   rG   r    rH   rI   )r	   rK   r?   s   &  r/   	any_zerosr      s    
s ,"%((,sss ,"%((, , ,#&88=8C}}CC8=(1+**HRL,=,=>>J >s   B-5B-c                   \         ;QJ d&    R V P                   4       F  '       g   K   RM	  RM! R V P                   4       4      '       g   V # . pV P                  ^ ,          pV P                  R,           FX  p\        V\        \        34      '       d'   \        V\        \        34      '       d   W#,          pKE  VP                  V4       TpKZ  	  VP                  V4       \        V!  # )a7  Merge explicit MatrixBase arguments

>>> from sympy import MatrixSymbol, Matrix, MatMul, pprint
>>> from sympy.matrices.expressions.matmul import merge_explicit
>>> A = MatrixSymbol('A', 2, 2)
>>> B = Matrix([[1, 1], [1, 1]])
>>> C = Matrix([[1, 2], [3, 4]])
>>> X = MatMul(A, B, C)
>>> pprint(X)
  [1  1] [1  2]
A*[    ]*[    ]
  [1  1] [3  4]
>>> pprint(merge_explicit(X))
  [4  6]
A*[    ]
  [4  6]

>>> X = MatMul(B, A, C)
>>> pprint(X)
[1  1]   [1  2]
[    ]*A*[    ]
[1  1]   [3  4]
>>> pprint(merge_explicit(X))
[1  1]   [1  2]
[    ]*A*[    ]
[1  1]   [3  4]
c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir+   )r_   r   r   s   & r/   r\   !merge_explicit.<locals>.<genexpr>  s     Bksz#z**ks   TFr   )rj   r<   r_   r   r   r   r%   )matmulnewargslastrK   s   &   r/   merge_explicitr      s    8 3BfkkB333BfkkBBBG;;q>D{{2cJ/00ZzSYFZ5[5[:DNN4 D  NN47r2   c                    V P                   ! 4       w  r\        R 4      ! V4      pW28w  d   \        V.VP                  O5!  # V # )zRemove Identities from a MatMul

This is a modified version of sympy.strategies.rm_id.
This is necessary because MatMul may contain both MatrixExprs and Exprs
as args.

See Also
========

sympy.strategies.rm_id
c                     V P                   R J # r   )is_Identityry   s   &r/   r0   remove_ids.<locals>.<lambda>6  s    Q]]d2r2   )r}   r   r   r<   )r	   r>   r   rt   s   &   r/   
remove_idsr   '  sB     $$&LF23D9F~f+v{{++
r2   c                 T    V P                   ! 4       w  rV^8w  d   \        V.VO5!  # V # rR   )r9   r   )r	   r>   r?   s   &  r/   factor_in_frontr   <  s/    ,,.F{f(x((Jr2   c                   V P                   ! 4       w  rV^ ,          .p\        ^\        V4      4       EF  pVR,          pW$,          p\        V\        4      '       d   \        VP
                  \        4      '       d_   VP
                  P                  p\        V4      p\        V4      W8) R 8X  d+   VRV)  \        VP                  ^ ,          4      .,           pK  \        V\        4      '       d   \        VP
                  \        4      '       dz   VP
                  P                  p	\        V	4      p\        V	4      W$WH,            8X  dA   \        VP                  ^ ,          4      p
WR&   \        WDV,           4       F  pWV&   K	  	  EKX  VP                  R8X  g   VP                  R8X  d   VP                  V4       EK  \        V\        4      '       d   VP                  w  rMT\        P                  r\        V\        4      '       d   VP                  w  rMT\        P                  rW8X  d+   W,           p\        VV4      P!                  RR7      VR&   EK*  \        V\"        4      '       gG    VP%                  4       pVe2   VV8X  d+   W,
          p\        VV4      P!                  RR7      VR&   EK  VP                  V4       EK  	  \)        V.VO5!  #   \&         d    Rp Lgi ; i)zCombine consecutive powers with the same base into one, e.g.
$$A \times A^2 \Rightarrow A^3$$

This also cancels out the possible matrix inverses using the
knowledgebase of :class:`~.Inverse`, e.g.,
$$ Y \times X \times X^{-1} \Rightarrow Y $$
NF)r   rF   )r9   re   rc   r_   r   rK   r%   r<   r5   r!   rL   r   r   r   r   Onerl   r   r   r   r   )r	   r>   r<   new_argsr-   ABBargslAargsr,   rm   A_baseA_expB_baseB_expnew_exp
B_base_invs   &                 r/   combine_powersr   B  sQ    ((*LFQyH1c$i RLGa!!j&?&?EEJJEE
AE{hrsm+#CaR=HQWWQZ,@+AAa!!j&?&?EEJJEE
AE{dQSk)#AGGAJ/'qA#A&G ';;%1;;%#7OOAa  FFMFEquuEa  FFMFEquuEmG!&'277U7CHRLFJ//"#^^-
 %&J*>-%fg6;;;Ga !d &$8$$ , "!
"s   4KK,+K,c                   V P                   p\        V4      pV^8  d   V # V^ ,          .p\        ^V4       F  pVR,          pW,          p\        V\        4      '       dS   \        V\        4      '       d=   VP                   ^ ,          pVP                   ^ ,          p\	        Wx,          4      VR&   K|  VP                  V4       K  	  \        V!  # )zGRefine products of permutation matrices as the products of cycles.
    rF   )r<   rc   re   r_   r   r   r%   )	r	   r<   r   rt   r-   r   r   cycle_1cycle_2s	   &        r/   combine_permutationsr     s     88DD	A1u
1gYF1a[2JGa*++q+,,ffQiGffQiG*7+<=F2JMM!  6?r2   c                   V P                   ! 4       w  rV^ ,          .pVR,           F  pVR,          p\        V\        4      '       d   \        V\        4      '       g   VP                  V4       KK  VP	                  4        VP                  \        VP
                  ^ ,          VP
                  ^,          4      4       WP
                  ^,          ,          pK  	  \        V.VO5!  # )z^
Combine products of OneMatrix

e.g. OneMatrix(2, 3) * OneMatrix(3, 4) -> 3 * OneMatrix(2, 4)
r   rF   )r9   r_   r#   r   poprL   r   )r	   r>   r<   r   r   r   s   &     r/   combine_one_matricesr     s     ((*LFQyH"XXRL!Y''z!Y/G/GOOA	!''!*aggaj9:''!*  &$8$$r2   c           
     <   V P                   p\        V4      ^8X  d   ^RIHp V^ ,          P                  '       d_   V^,          P
                  '       dF   T! V^ ,          P                    Uu. uF#  p\        W1^,          4      P                  4       NK%  	  up!  # V^,          P                  '       d`   V^ ,          P
                  '       dG   T! V^,          P                    Uu. uF$  p\        V^ ,          V4      P                  4       NK&  	  up!  # V # u upi u upi )zb
Simplify MatMul expressions but distributing
rational term to MatMul.

e.g. 2*(A+B) -> 2*A + 2*B
)MatAdd)r<   rc   mataddr  	is_MatAddis_Rationalr%   rl   )r	   r<   r  mats   &   r/   distribute_monomr    s     88D
4yA~"7a!4!4!447<<P<CF3Q0557<PQQ7a!4!4!447<<P<CF47C0557<PQQJ QPs   ,)D#*Dc                     V ^8H  # r   r   r   s   &r/   r0   r0     s    klpqkqr2   c            	     T   V ^ ,          P                   V R,          P                  8w  d   \        R4      h. p^ p\        V 4       F`  w  r4VP                  W,          P                   8X  g   K(  VP	                  \        WV^,            !  P                  4       4       V^,           pKb  	  V# )z'factor matrices only if they are squarez!Invalid matrices being multipliedrF   )rH   rI   RuntimeErrorrg   r   r%   rl   )r?   outstartr-   Ms   *    r/   r   r     s    {8B<,,,>??
CE(#66X_)))JJvxac2388:;aCE $ Jr2   c                   . p. pV P                    F9  pVP                  '       d   VP                  V4       K(  VP                  V4       K;  	  V^ ,          pVR,           F  pWeP                  8X  dE   \	        \
        P                  ! V4      V4      '       d   \        VP                  ^ ,          4      pKW  WeP                  4       8X  dE   \	        \
        P                  ! V4      V4      '       d   \        VP                  ^ ,          4      pK  VP                  V4       TpK  	  VP                  V4       \        V!  # )z
>>> from sympy import MatrixSymbol, Q, assuming, refine
>>> X = MatrixSymbol('X', 2, 2)
>>> expr = X * X.T
>>> print(expr)
X*X.T
>>> with assuming(Q.orthogonal(X)):
...     print(refine(expr))
I
r   )r<   rG   r   Tr   r   
orthogonalr!   rL   	conjugateunitaryr%   )rC   assumptionsr   exprargsr<   r   rK   s   &&     r/   refine_MatMulr    s     GH		>>>OOD!NN4 	  A;D||&&=Sc!2K@@CIIaL)DNN$$QYYs^[)I)ICIIaL)DNN4 D  NN47r2   N)Asympy.assumptions.askr   r   sympy.assumptions.refiner   
sympy.corer   r   r   sympy.core.mulr	   r
   sympy.core.numbersr   r   sympy.core.symbolr   sympy.functionsr   sympy.strategiesr   r   r   r   r   r   r   sympy.matrices.exceptionsr   sympy.matrices.matrixbaser   sympy.utilities.exceptionsr   !sympy.matrices.expressions._shaper   r:   r   r   matexprr   matpowr   r   permutationr   specialr    r!   r"   r#   r%   register_handlerclassr   r   r   r   r   r   r   r   r  rulesrB   r   r  r   r2   r/   <module>r(     s    ( 2 ( ( # . # #   > 0 @ Q      * E ESZ Sj   3- 0
(T*=%~,%(" i-A>SY[`aq[rOW.B	D uffen567
D (h r2   