+
    i\4              	       d   R t ^ RIHt ^ RIHt ^ RI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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 t' ! R R]4      t(R t)R t*R t+R t,]],]]*3t-]! ]! R ]! ]-!  4      4      t.R t/R t0R t1R t2R t3R# )z'Implementation of the Kronecker product)reduce)prod)Mulsympify)adjoint)
ShapeError)
MatrixExpr)	transpose)Identity)
MatrixBase)canon	condition
distributedo_oneexhaustflattentypedunpack)	bottom_up)sift)MatAdd)MatMul)MatPowc                     V '       g   \        R4      h\        V 4      ^8X  d
   V ^ ,          # \        V !  P                  4       # )a  
The Kronecker product of two or more arguments.

This computes the explicit Kronecker product for subclasses of
``MatrixBase`` i.e. explicit matrices. Otherwise, a symbolic
``KroneckerProduct`` object is returned.


Examples
========

For ``MatrixSymbol`` arguments a ``KroneckerProduct`` object is returned.
Elements of this matrix can be obtained by indexing, or for MatrixSymbols
with known dimension the explicit matrix can be obtained with
``.as_explicit()``

>>> from sympy import kronecker_product, MatrixSymbol
>>> A = MatrixSymbol('A', 2, 2)
>>> B = MatrixSymbol('B', 2, 2)
>>> kronecker_product(A)
A
>>> kronecker_product(A, B)
KroneckerProduct(A, B)
>>> kronecker_product(A, B)[0, 1]
A[0, 0]*B[0, 1]
>>> kronecker_product(A, B).as_explicit()
Matrix([
    [A[0, 0]*B[0, 0], A[0, 0]*B[0, 1], A[0, 1]*B[0, 0], A[0, 1]*B[0, 1]],
    [A[0, 0]*B[1, 0], A[0, 0]*B[1, 1], A[0, 1]*B[1, 0], A[0, 1]*B[1, 1]],
    [A[1, 0]*B[0, 0], A[1, 0]*B[0, 1], A[1, 1]*B[0, 0], A[1, 1]*B[0, 1]],
    [A[1, 0]*B[1, 0], A[1, 0]*B[1, 1], A[1, 1]*B[1, 0], A[1, 1]*B[1, 1]]])

For explicit matrices the Kronecker product is returned as a Matrix

>>> from sympy import Matrix, kronecker_product
>>> sigma_x = Matrix([
... [0, 1],
... [1, 0]])
...
>>> Isigma_y = Matrix([
... [0, 1],
... [-1, 0]])
...
>>> kronecker_product(sigma_x, Isigma_y)
Matrix([
[ 0, 0,  0, 1],
[ 0, 0, -1, 0],
[ 0, 1,  0, 0],
[-1, 0,  0, 0]])

See Also
========
    KroneckerProduct

z$Empty Kronecker product is undefined)	TypeErrorlenKroneckerProductdoit)matricess   *ڄ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/matrices/expressions/kronecker.pykronecker_productr       s>    p >??
8}{*//11    c                      a a ] tR t^Vt oRtRtRR/V 3R llt]R 4       tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tRtVtV ;t# )r   aZ  
The Kronecker product of two or more arguments.

The Kronecker product is a non-commutative product of matrices.
Given two matrices of dimension (m, n) and (s, t) it produces a matrix
of dimension (m s, n t).

This is a symbolic object that simply stores its argument without
evaluating it. To actually compute the product, use the function
``kronecker_product()`` or call the ``.doit()`` or  ``.as_explicit()``
methods.

>>> from sympy import KroneckerProduct, MatrixSymbol
>>> A = MatrixSymbol('A', 5, 5)
>>> B = MatrixSymbol('B', 5, 5)
>>> isinstance(KroneckerProduct(A, B), KroneckerProduct)
True
Tcheckc                 < \        \        \        V4      4      p\        ;QJ d    R  V 4       F  '       d   K   RM	  RM! R  V 4       4      '       dh   \	        \        R V 4       4      4      p\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   VP                  4       # V# V'       d
   \        V!   \        SV `$  ! V .VO5!  # )c              3   8   "   T F  qP                   x  K  	  R # 5iN)is_Identity.0as   & r   	<genexpr>+KroneckerProduct.__new__.<locals>.<genexpr>m   s     +d}}d   FTc              3   8   "   T F  qP                   x  K  	  R # 5ir&   )rowsr(   s   & r   r+   r,   n   s     51r-   c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir&   
isinstancer   r(   s   & r   r+   r,   o   s     ;d:a,,d   )
listmapr   allr
   r   as_explicitvalidatesuper__new__)clsr#   argsret	__class__s   &$* r   r:   KroneckerProduct.__new__k   s    C&'3+d+333+d+++45556Cs;d;sss;d;;;((
dOws*T**r!   c                    V P                   ^ ,          P                  w  rV P                   R,           F'  pWP                  ,          pW#P                  ,          pK)  	  W3# )    :   NN)r<   shaper/   cols)selfr/   rD   mats   &   r   rC   KroneckerProduct.shapex   sM    YYq\''
99R==CHHDHHD ! |r!   c                    ^p\        V P                  4       FA  p\        WP                  4      w  r\        W%P                  4      w  r'WEWg3,          ,          pKC  	  V# rB   )reversedr<   divmodr/   rD   )rE   ijkwargsresultrF   mns   &&&,    r   _entryKroneckerProduct._entry   sO    DII&C!XX&DA!XX&DA!$iF ' r!   c                r    \        \        \        \        V P                  4      4      !  P                  4       # r&   )r   r4   r5   r   r<   r   rE   s   &r   _eval_adjointKroneckerProduct._eval_adjoint   s&    c'499&=!>?DDFFr!   c                    \        V P                   Uu. uF  qP                  4       NK  	  up!  P                  4       # u upi r&   )r   r<   	conjugater   )rE   r*   s   & r   _eval_conjugate KroneckerProduct._eval_conjugate   s0    !CA++-!CDIIKK!Cs   ?c                r    \        \        \        \        V P                  4      4      !  P                  4       # r&   )r   r4   r5   r	   r<   r   rU   s   &r   _eval_transpose KroneckerProduct._eval_transpose   s&    c)TYY&?!@AFFHHr!   c                h    ^RI H p \        V P                   Uu. uF
  q!! V4      NK  	  up!  # u upi )rB   )trace)r`   r   r<   )rE   r`   r*   s   &  r   _eval_traceKroneckerProduct._eval_trace   s*     tyy1y!U1Xy1221s   /c                ^   ^RI HpHp \        ;QJ d&    R V P                   4       F  '       d   K   RM	  RM! R V P                   4       4      '       g	   V! V 4      # V P
                  p\        V P                   Uu. uF!  qA! V4      W4P
                  ,          ,          NK#  	  up!  # u upi )rB   )detDeterminantc              3   8   "   T F  qP                   x  K  	  R # 5ir&   	is_squarer(   s   & r   r+   5KroneckerProduct._eval_determinant.<locals>.<genexpr>   s     2	1;;	r-   FT)determinantrd   re   r6   r<   r/   r   )rE   rd   re   rP   r*   s   &    r   _eval_determinant"KroneckerProduct._eval_determinant   su    1s2		2sss2		222t$$II;ASVah'';<<;s   >'B*c                     \        V P                   Uu. uF  qP                  4       NK  	  up!  # u upi   \         d    ^ RIHp T! T 4      u # i ; i)rA   )Inverse)r   r<   inverser   "sympy.matrices.expressions.inversern   )rE   r*   rn   s   &  r   _eval_inverseKroneckerProduct._eval_inverse   sH    	!#499%E9aiik9%EFF%E 	!B4= 	!s   7 27 7 AAc                   \        V\        4      ;'       d    V P                  VP                  8H  ;'       d    \        V P                  4      \        VP                  4      8H  ;'       dq    \
        ;QJ d:    R \        V P                  VP                  4       4       F  '       d   K   R# 	  R# ! R \        V P                  VP                  4       4       4      # )a  Determine whether two matrices have the same Kronecker product structure

Examples
========

>>> from sympy import KroneckerProduct, MatrixSymbol, symbols
>>> m, n = symbols(r'm, n', integer=True)
>>> A = MatrixSymbol('A', m, m)
>>> B = MatrixSymbol('B', n, n)
>>> C = MatrixSymbol('C', m, m)
>>> D = MatrixSymbol('D', n, n)
>>> KroneckerProduct(A, B).structurally_equal(KroneckerProduct(C, D))
True
>>> KroneckerProduct(A, B).structurally_equal(KroneckerProduct(D, C))
False
>>> KroneckerProduct(A, B).structurally_equal(C)
False
c              3   X   "   T F   w  rVP                   VP                   8H  x  K"  	  R # 5ir&   rC   r)   r*   bs   &  r   r+   6KroneckerProduct.structurally_equal.<locals>.<genexpr>   s!     T9Sv177*9S   (*FT)r2   r   rC   r   r<   r6   ziprE   others   &&r   structurally_equal#KroneckerProduct.structurally_equal   s    ( 5"23 U UJJ%++-U U		Nc%**o5U U CTTYY

9STCC	V 	V TTYY

9STT	Vr!   c                   \        V\        4      ;'       d    V P                  VP                  8H  ;'       d    \	        V P
                  4      \	        VP
                  4      8H  ;'       dq    \        ;QJ d:    R \        V P
                  VP
                  4       4       F  '       d   K   R# 	  R# ! R \        V P
                  VP
                  4       4       4      # )a  Determine whether two matrices have the appropriate structure to bring matrix
multiplication inside the KroneckerProdut

Examples
========
>>> from sympy import KroneckerProduct, MatrixSymbol, symbols
>>> m, n = symbols(r'm, n', integer=True)
>>> A = MatrixSymbol('A', m, n)
>>> B = MatrixSymbol('B', n, m)
>>> KroneckerProduct(A, B).has_matching_shape(KroneckerProduct(B, A))
True
>>> KroneckerProduct(A, B).has_matching_shape(KroneckerProduct(A, B))
False
>>> KroneckerProduct(A, B).has_matching_shape(A)
False
c              3   X   "   T F   w  rVP                   VP                  8H  x  K"  	  R # 5ir&   )rD   r/   rv   s   &  r   r+   6KroneckerProduct.has_matching_shape.<locals>.<genexpr>   s!     R7QVa!&&(7Qry   FT)r2   r   rD   r/   r   r<   r6   rz   r{   s   &&r   has_matching_shape#KroneckerProduct.has_matching_shape   s    " 5"23 S SII+S S		Nc%**o5S S CRs499ejj7QRCC	T 	T Rs499ejj7QRR	Tr!   c                x    \        \        \        \        \	        \        \
        4      /4      4      ! V 4      4      # r&   )r   r   r   r   r   r   )rE   hintss   &,r   _eval_expand_kroneckerproduct.KroneckerProduct._eval_expand_kroneckerproduct   s,    uU$4jAQSY6Z#[\]^bcddr!   c                    V P                  V4      '       dI   V P                  ! \        V P                  VP                  4       UUu. uF  w  r#W#,           NK  	  upp!  # W,           # u uppi r&   )r}   r>   rz   r<   rE   r|   r*   rw   s   &&  r   _kronecker_addKroneckerProduct._kronecker_add   sV    ""5))>>DIIuzz8R#S8RfqAEE8R#STT< $T   A(
c                    V P                  V4      '       dI   V P                  ! \        V P                  VP                  4       UUu. uF  w  r#W#,          NK  	  upp!  # W,          # u uppi r&   )r   r>   rz   r<   r   s   &&  r   _kronecker_mulKroneckerProduct._kronecker_mul   sV    ""5))>>c$))UZZ6P#Q6PFQACC6P#QRR< $Rr   c                    VP                  R R4      pV'       d,   V P                   Uu. uF  q3P                  ! R/ VB NK  	  ppMV P                  p\        \	        V!  4      # u upi )deepT )getr<   r   canonicalizer   )rE   r   r   argr<   s   &,   r   r   KroneckerProduct.doit   sX    yy&15;#HH%u%D;D99D,d344 <s   A$r   )__name__
__module____qualname____firstlineno____doc__is_KroneckerProductr:   propertyrC   rR   rV   rZ   r]   ra   rk   rq   r}   r   r   r   r   r   __static_attributes____classdictcell____classcell__)r>   __classdict__s   @@r   r   r   V   s~     $ +$ +  GLI3=!V2T,e  5 5r!   r   c                      \         ;QJ d    R  V  4       F  '       d   K   RM	  RM! R  V  4       4      '       g   \        R4      hR# )c              3   8   "   T F  qP                   x  K  	  R # 5ir&   )	is_Matrix)r)   r   s   & r   r+   validate.<locals>.<genexpr>   s     -}}r-   FTz Mix of Matrix and Scalar symbolsN)r6   r   )r<   s   *r   r8   r8      s4    3--333----:;; .r!   c                    . p. pV P                    FK  pVP                  4       w  rEVP                  V4       VP                  \        P
                  ! V4      4       KM  	  \	        V!  pV^8w  d   V\        V!  ,          # V # rI   )r<   args_cncextendappendr   
_from_argsr   )kronc_partnc_partr   cncs   &     r   extract_commutativer      sp    FGyyas~~b)* 
 &\F{&000Kr!   c            	        \         ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       g   \        R\        V 4      ,          4      hV R,          p\        V RR 4       F  pVP                  pVP
                  p\        V4       F  pWWT,          ,          ,          p\        V^,
          4       F5  pVP                  WWT,          V,           ^,           ,          ,          4      pK7  	  V^ 8X  d   TpKn  XP                  V4      pK  	  XpK  	  \        V R R7      P                  p	\        W4      '       d   V# V	! V4      # )	a  Compute the Kronecker product of a sequence of SymPy Matrices.

This is the standard Kronecker product of matrices [1].

Parameters
==========

matrices : tuple of MatrixBase instances
    The matrices to take the Kronecker product of.

Returns
=======

matrix : MatrixBase
    The Kronecker product matrix.

Examples
========

>>> from sympy import Matrix
>>> from sympy.matrices.expressions.kronecker import (
... matrix_kronecker_product)

>>> m1 = Matrix([[1,2],[3,4]])
>>> m2 = Matrix([[1,0],[0,1]])
>>> matrix_kronecker_product(m1, m2)
Matrix([
[1, 0, 2, 0],
[0, 1, 0, 2],
[3, 0, 4, 0],
[0, 3, 0, 4]])
>>> matrix_kronecker_product(m2, m1)
Matrix([
[1, 2, 0, 0],
[3, 4, 0, 0],
[0, 0, 1, 2],
[0, 0, 3, 4]])

References
==========

.. [1] https://en.wikipedia.org/wiki/Kronecker_product
c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir&   r1   r)   rP   s   & r   r+   +matrix_kronecker_product.<locals>.<genexpr>-  s     ;(Qz!Z(((r3   FTz&Sequence of Matrices expected, got: %sNc                     V P                   # r&   )_class_priority)Ms   &r   <lambda>*matrix_kronecker_product.<locals>.<lambda>I  s
    a.?.?r!   )key)r6   r   reprrJ   r/   rD   rangerow_joincol_joinmaxr>   r2   )
r   matrix_expansionrF   r/   rD   rL   startrM   nextMatrixClasss
   *         r   matrix_kronecker_productr      s   Z 3;(;333;(;;;4tH~E
 	

  |"&xxxx tA$[0E4!8_$!a%88 % Av}}U+   % '( h$?@JJK"00+,,r!   c                     \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       g   V # \        V P                  !  # )c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir&   r1   r   s   & r   r+   -explicit_kronecker_product.<locals>.<genexpr>R  s     <)Qz!Z(()r3   FT)r6   r<   r   )r   s   &r   explicit_kronecker_productr   P  s?    3<$))<333<$))<<<#TYY//r!   c                 "    \        V \        4      # r&   )r2   r   )xs   &r   r   r   ]  s    :a9I+Jr!   c                     \        V \        4      '       dA   \        ;QJ d    . R  V P                   4       F  NK  	  5# ! R  V P                   4       4      # R# )c              3   8   "   T F  qP                   x  K  	  R # 5ir&   ru   r(   s   & r   r+   &_kronecker_dims_key.<locals>.<genexpr>c  s     0iWWir-   rA   )r2   r   tupler<   exprs   &r   _kronecker_dims_keyr   a  s?    $())u0dii0u0u0dii000r!   c                    \        V P                  \        4      pVP                  RR4      pV'       g   V # VP	                  4        Uu. uF  p\        R V4      NK  	  ppV'       g
   \        V!  # \        V!  V,           # u upi )rA   Nc                 $    V P                  V4      # r&   )r   )r   ys   &&r   r   #kronecker_mat_add.<locals>.<lambda>n  s    !1!1!!4r!   r   )r   r<   r   popvaluesr   r   )r   r<   nonkronsgroupkronss   &    r   kronecker_mat_addr   h  s~    		./Dxxd#H ++-)' 4e<' 
 ) u~u~(()s   	Bc                 Z   V P                  4       w  r^ pV\        V4      ^,
          8  dr   W#V^,            w  rE\        V\        4      '       dD   \        V\        4      '       d.   VP	                  V4      W#&   VP                  V^,           4       K}  V^,          pK  V\        V!  ,          # r   )as_coeff_matricesr   r2   r   r   r   r   )r   factorr   rL   ABs   &     r   kronecker_mat_mulr   w  s    --/F	A
c(ma
!A#a)**z!=M/N/N**1-HKLL1FA&(###r!   c           	         \        V P                  \        4      '       d   \        ;QJ d0    R  V P                  P                   4       F  '       d   K   RM%	  RM!! R  V P                  P                   4       4      '       dA   \        V P                  P                   Uu. uF  p\        WP                  4      NK  	  up!  # V # u upi )c              3   8   "   T F  qP                   x  K  	  R # 5ir&   rg   r(   s   & r   r+   $kronecker_mat_pow.<locals>.<genexpr>  s     6[Nq{{Nr-   FT)r2   baser   r6   r<   r   exp)r   r*   s   & r   kronecker_mat_powr     sz    $))-..336[DIINN6[3336[DIINN6[3[3[tyy~~!N~!&HH"5~!NOO "Os    Cc                    R p\        \        \        \        V\        \        \
        \        \        \        \        /4      4      4      4      4      pV! V 4      p\        VRR4      pVe   V! 4       # V# )a  Combine KronekeckerProduct with expression.

If possible write operations on KroneckerProducts of compatible shapes
as a single KroneckerProduct.

Examples
========

>>> from sympy.matrices.expressions import combine_kronecker
>>> from sympy import MatrixSymbol, KroneckerProduct, symbols
>>> m, n = symbols(r'm, n', integer=True)
>>> A = MatrixSymbol('A', m, n)
>>> B = MatrixSymbol('B', n, m)
>>> combine_kronecker(KroneckerProduct(A, B)*KroneckerProduct(B, A))
KroneckerProduct(A*B, B*A)
>>> combine_kronecker(KroneckerProduct(A, B)+KroneckerProduct(B.T, A.T))
KroneckerProduct(A + B.T, B + A.T)
>>> C = MatrixSymbol('C', n, n)
>>> D = MatrixSymbol('D', m, m)
>>> combine_kronecker(KroneckerProduct(C, D)**m)
KroneckerProduct(C**m, D**m)
c                 \    \        V \        4      ;'       d    V P                  \        4      # r&   )r2   r   hasr   r   s   &r   haskron"combine_kronecker.<locals>.haskron  s!    $
+JJ9I0JJr!   r   N)r   r   r   r   r   r   r   r   r   r   getattr)r   r   rulerO   r   s   &    r   combine_kroneckerr     su    .K ')GU&&&(.) * + 	,-D
 $ZF664(Dvr!   N)4r   	functoolsr   mathr   
sympy.corer   r   sympy.functionsr   sympy.matrices.exceptionsr   "sympy.matrices.expressions.matexprr   $sympy.matrices.expressions.transposer	   "sympy.matrices.expressions.specialr
   sympy.matrices.matrixbaser   sympy.strategiesr   r   r   r   r   r   r   r   sympy.strategies.traverser   sympy.utilitiesr   mataddr   matmulr   matpowr   r    r   r8   r   r   r   rulesr   r   r   r   r   r   r   r!   r   <module>r     s    -   # # 0 9 : 7 0K K K /     =2@R5z R5j<M-`0 
	#			
 y!J!'1 2)$ $r!   