+
    ir                     v    ^ RI Ht ^ RIHt ^ RIHt ^RIHt ^RIH	t	H
t
Ht  ! R R]4      t ! R R	]4      tR
# )    )S)_sympify)KroneckerDelta)
MatrixExpr)
ZeroMatrixIdentity	OneMatrixc                      a a ] tR t^	t oRtV 3R lt]R 4       t]R 4       tR t	R t
R tR t];ttR	 tR
 tRtVtV ;t# )PermutationMatrixa)  A Permutation Matrix

Parameters
==========

perm : Permutation
    The permutation the matrix uses.

    The size of the permutation determines the matrix size.

    See the documentation of
    :class:`sympy.combinatorics.permutations.Permutation` for
    the further information of how to create a permutation object.

Examples
========

>>> from sympy import Matrix, PermutationMatrix
>>> from sympy.combinatorics import Permutation

Creating a permutation matrix:

>>> p = Permutation(1, 2, 0)
>>> P = PermutationMatrix(p)
>>> P = P.as_explicit()
>>> P
Matrix([
[0, 1, 0],
[0, 0, 1],
[1, 0, 0]])

Permuting a matrix row and column:

>>> M = Matrix([0, 1, 2])
>>> Matrix(P*M)
Matrix([
[1],
[2],
[0]])

>>> Matrix(M.T*P)
Matrix([[2, 0, 1]])

See Also
========

sympy.combinatorics.permutations.Permutation
c                   < ^ RI Hp \        V4      p\        W4      '       g   \	        RP                  V4      4      h\        SV `  W4      # )r   Permutationz({} must be a SymPy Permutation instance.) sympy.combinatorics.permutationsr   r   
isinstance
ValueErrorformatsuper__new__)clspermr   	__class__s   && چ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/matrices/expressions/permutation.pyr   PermutationMatrix.__new__;   sH    @~$,,:AA$GI I ws))    c                B    V P                   ^ ,          P                  pW3# r   )argssize)selfr   s   & r   shapePermutationMatrix.shapeE   s    yy|  |r   c                <    V P                   ^ ,          P                  # r   )r   is_Identityr   s   &r   r#   PermutationMatrix.is_IdentityJ   s    yy|'''r   c                T    V P                   '       d   \        V P                  4      # V # )N)r#   r   rows)r   hintss   &,r   doitPermutationMatrix.doitN   s"    DII&&r   c                ^    V P                   ^ ,          p\        VP                  V4      V4      # r   )r   r   apply)r   ijkwargsr   s   &&&, r   _entryPermutationMatrix._entryS   s$    yy|djjmQ//r   c                d    \        V P                  ^ ,          V,          4      P                  4       # r   )r   r   r)   )r   exps   &&r   _eval_powerPermutationMatrix._eval_powerW   s#     1!45::<<r   c                H    \        V P                  ^ ,          R,          4      # r   )r   r   r$   s   &r   _eval_inversePermutationMatrix._eval_inverseZ   s     1!344r   c                    V P                   ^ ,          P                  4       pV^8X  d   \        P                  # VR8X  d   \        P                  # \
        hr7   )r   	signaturer   OneNegativeOneNotImplementedError)r   signs   & r   _eval_determinant#PermutationMatrix._eval_determinant_   s?    yy|%%'1955LRZ== !!r   c                   ^ RI Hp ^RIHp V P                  ^ ,          pVP
                  p. p^ ^ ^ rpRpV EF.  p\        V4      p\        V4      pV'       g<   V^,           W,           8  d   RpV.pTp	Tp
KA  VP                  V.4       W,          pK]  W8  dh   V^,           W,           V,           8X  d0   XP                  V4       VP                  V4       RpV^,           pK  Tp	XP                  V4       W,          p
K  V	^,           W,           V,           8X  d1   XP                  V4       VP                  V4       RpV	^,           pEK  XP                  V4       W,          p
EK1  	  ^ p. pV Fx  p. p^ pV F>  pV Uu. uF  pVV,
          NK  	  ppVP                  V4       V\        V4      ,          pK@  	  VV,          pV! V4      p\        V4      pVP                  V4       Kz  	  V! V!  # u upi )r   r   )BlockDiagMatrixFT)
r   r   blockmatrixrD   r   full_cyclic_formlenmaxappendr   )r   r   r/   r   rD   r   rF   cycles_picksabcflagcyclelmtempppick
new_cyclesr-   	new_cyclemats   &*,                   r    _eval_rewrite_as_BlockDiagMatrix2PermutationMatrix._eval_rewrite_as_BlockDiagMatrixg   s   @0yy|00 Qa%EE
AE
Aq515=D!7DAA ''0FA 51u	)E*$++D1$aCE*1u	)E*$++D1$aCE*C &H  DJA,12EqQUUE	2!!),SZ  FAz*D#D)CKK ! %% 3s    G2 )__name__
__module____qualname____firstlineno____doc__r   propertyr    r#   r)   r0   r4   r9   _eval_transpose_eval_adjointrA   rX   __static_attributes____classdictcell____classcell__r   __classdict__s   @@r   r   r   	   sg     /b*   ( (
0=5 '43Om">& >&r   r   c                   v   a a ] tR t^t oRt]P                  3V 3R lltRR lt]	R 4       t
R tR tRtVtV ;t# )	MatrixPermutea  Symbolic representation for permuting matrix rows or columns.

Parameters
==========

perm : Permutation, PermutationMatrix
    The permutation to use for permuting the matrix.
    The permutation can be resized to the suitable one,

axis : 0 or 1
    The axis to permute alongside.
    If `0`, it will permute the matrix rows.
    If `1`, it will permute the matrix columns.

Notes
=====

This follows the same notation used in
:meth:`sympy.matrices.matrixbase.MatrixBase.permute`.

Examples
========

>>> from sympy import Matrix, MatrixPermute
>>> from sympy.combinatorics import Permutation

Permuting the matrix rows:

>>> p = Permutation(1, 2, 0)
>>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> B = MatrixPermute(A, p, axis=0)
>>> B.as_explicit()
Matrix([
[4, 5, 6],
[7, 8, 9],
[1, 2, 3]])

Permuting the matrix columns:

>>> B = MatrixPermute(A, p, axis=1)
>>> B.as_explicit()
Matrix([
[2, 3, 1],
[5, 6, 4],
[8, 9, 7]])

See Also
========

sympy.matrices.matrixbase.MatrixBase.permute
c                T  < ^ RI Hp \        V4      pVP                  '       g   \	        RP                  V4      4      h\        V4      p\        V\        4      '       d   VP                  ^ ,          p\        W$4      '       g   \	        RP                  V4      4      h\        V4      pVR9  d   \	        R4      hVP                  V,          pWRP                  8w  d    VP                  V4      p\        SV `5  WW#4      #   \         d    \	        RP                  Y!T4      4      hi ; i)r   r   z#{} must be a SymPy matrix instance.z>{} must be a SymPy Permutation or a PermutationMatrix instancezThe axis must be 0 or 1.zsSize does not match between the permutation {} and the matrix {} threaded over the axis {} and cannot be converted.)r      )r   r   r   	is_Matrixr   r   r   r   r   r    r   resizer   r   )r   rW   r   axisr   mat_sizer   s   &&&&  r   r   MatrixPermute.__new__   s   @sm}}}5<<TBD D ~d-..99Q<D$,,!6$<) ) ~v78899T?yy .{{8, ws44  . / VDt,	. ..s   D   'D'c                \   V P                   w  r4pV'       d)   VP                  ! RR V/VB pVP                  ! RR V/VB pVP                  '       d   V# VP                  '       dF   V\        P                  J d   \        V4      # V\        P                  J d   \        VR,          4      # \        V\        \        34      '       d   V# \        V\        4      '       dN   VP                   ^,          V8X  d6   \        VP                   ^ ,          WCP                   ^,          ,          V4      # V # )deeprZ   r8   )r   r)   r#   r   Zeror   r=   r   r   r	   ri   )r   rr   r(   rW   r   rn   s   &&,   r   r)   MatrixPermute.doit   s    ))4((...C990$0%0DJ???qvv~(..(r22cJ	233Jc=))chhqkT.A !dXXa[.@$GGr   c                <    V P                   ^ ,          P                  # r   )r   r    r$   s   &r   r    MatrixPermute.shape  s    yy|!!!r   c                    V P                   w  rEpV^ 8X  d   WEP                  V4      V3,          # V^8X  d   WAVP                  V4      3,          # R# )r   N)r   r,   )r   r-   r.   r/   rW   r   rn   s   &&&,   r   r0   MatrixPermute._entry  sN    ))419zz!}a'((QY$**Q-'(( r   c                    ^RI Hp V P                  w  rEpVP                  RR4      pV'       d   VP	                  V4      pV^ 8X  d   V! \        V4      V4      # V^8X  d   V! V\        VR,          4      4      # R# )rk   )MatMulrr   TNr8   )matmulrz   r   getrewriter   )r   r   r/   rz   rW   r   rn   rr   s   &*,     r   _eval_rewrite_as_MatMul%MatrixPermute._eval_rewrite_as_MatMul"  sp    "))4zz&$'++f%C19+D1377QY#0r:;; r   rZ   )T)r[   r\   r]   r^   r_   r   rs   r   r)   r`   r    r0   r~   rc   rd   re   rf   s   @@r   ri   ri      sB     2f &'VV  5D0 " ")< <r   ri   N)
sympy.corer   sympy.core.sympifyr   sympy.functionsr   matexprr   specialr   r   r	   r   ri   rZ   r   r   <module>r      s4     ' *  4 4\&
 \&~G<J G<r   