ó
    ‰*£hr  ã                   ót   • S SK Jr  S SKJr  S SKJr  SSKJr  SSKJ	r	J
r
Jr   " S S\5      r " S	 S
\5      rg)é    )ÚS)Ú_sympify)ÚKroneckerDeltaé   )Ú
MatrixExpr)Ú
ZeroMatrixÚIdentityÚ	OneMatrixc                   óx   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       rS r	S r
S rS	 r\=rrS
 rS rSrU =r$ )ÚPermutationMatrixé	   a)  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                 ó˜   >• SSK Jn  [        U5      n[        X5      (       d  [	        SR                  U5      5      e[        TU ]  X5      $ )Nr   ©ÚPermutationz({} must be a SymPy Permutation instance.)Ú sympy.combinatorics.permutationsr   r   Ú
isinstanceÚ
ValueErrorÚformatÚsuperÚ__new__)ÚclsÚpermr   Ú	__class__s      €Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/matrices/expressions/permutation.pyr   ÚPermutationMatrix.__new__;   sH   ø€ Ý@ä˜‹~ˆÜ˜$×,Ñ,ÜØ:×AÑAÀ$ÓGóIð Iô ‰w‰˜sÓ)Ð)ó    c                 ó:   • U R                   S   R                  nX4$ ©Nr   )ÚargsÚsize)Úselfr    s     r   ÚshapeÚPermutationMatrix.shapeE   s   € à�y‰y˜‰|× Ñ ˆØˆ|Ðr   c                 ó4   • U R                   S   R                  $ r   )r   Úis_Identity©r!   s    r   r%   ÚPermutationMatrix.is_IdentityJ   s   € à�y‰y˜‰|×'Ñ'Ð'r   c                 óR   • U R                   (       a  [        U R                  5      $ U $ )N)r%   r	   Úrows)r!   Úhintss     r   ÚdoitÚPermutationMatrix.doitN   s   € Ø××Ü˜DŸI™IÓ&Ð&Øˆr   c                 óV   • U R                   S   n[        UR                  U5      U5      $ r   )r   r   Úapply)r!   ÚiÚjÚkwargsr   s        r   Ú_entryÚPermutationMatrix._entryS   s$   € Ø�y‰y˜‰|ˆÜ˜dŸj™j¨›m¨QÓ/Ð/r   c                 óT   • [        U R                  S   U-  5      R                  5       $ r   )r   r   r+   )r!   Úexps     r   Ú_eval_powerÚPermutationMatrix._eval_powerW   s#   € Ü  §¡¨1¡°Ñ!4Ó5×:Ñ:Ó<Ð<r   c                 ó8   • [        U R                  S   S-  5      $ )Nr   éÿÿÿÿ)r   r   r&   s    r   Ú_eval_inverseÚPermutationMatrix._eval_inverseZ   s   € Ü  §¡¨1¡°Ñ!3Ó4Ð4r   c                 ó    • U R                   S   R                  5       nUS:X  a  [        R                  $ US:X  a  [        R                  $ [
        e)Nr   r   r9   )r   Ú	signaturer   ÚOneÚNegativeOneÚNotImplementedError)r!   Úsigns     r   Ú_eval_determinantÚ#PermutationMatrix._eval_determinant_   s?   € Ø�y‰y˜‰|×%Ñ%Ó'ˆØ�1‹9Ü—5‘5ˆLØ�R‹ZÜ—=‘=Ð Ü!Ð!r   c                 óV  • SSK Jn  SSKJn  U R                  S   nUR
                  n/ nSu  p‰n
SnU Hó  n[        U5      n[        U5      nU(       d.  US-   X�-   :”  a  SnU/nUn	Un
M6  UR                  U/5        X�-  nMN  Xé:”  aR  US-   XŠ-   U-   :X  a+  WR                  U5        UR                  U5        SnUS-   nMŒ  Un	WR                  U5        X­-  n
M¥  U	S-   XŠ-   U-   :X  a+  WR                  U5        UR                  U5        SnU	S-   nMÞ  WR                  U5        X­-  n
Mõ     Sn/ nU Hm  n/ nSnU H7  nU Vs/ s H  nUU-
  PM
     nnUR                  U5        U[        U5      -  nM9     UU-  nU" U5      n[        U5      nUR                  U5        Mo     U" U6 $ s  snf )Nr   r   r   )ÚBlockDiagMatrix)r   r   r   FT)
r   r   ÚblockmatrixrE   r   Úfull_cyclic_formÚlenÚmaxÚappendr   )r!   r   r1   r   rE   r   rG   Úcycles_picksÚaÚbÚcÚflagÚcycleÚlÚmÚtempÚpÚpickÚ
new_cyclesr/   Ú	new_cycleÚmats                         r   Ú _eval_rewrite_as_BlockDiagMatrixÚ2PermutationMatrix._eval_rewrite_as_BlockDiagMatrixg   sÑ  € Ý@Ý0à�y‰y˜‰|ˆØ×0Ñ0Ðàˆð ‰ˆˆaØˆÛ%ˆEÜ�E“
ˆAÜ�E“
ˆAæØ�q‘5˜1™5“=Ø�DØ!˜7�DØ�AØ’Aà ×'Ñ'¨¨Ô0Ø‘F’Að “5Ø˜1‘u ¡¨¡	Ó)ØŸ™ EÔ*Ø$×+Ñ+¨DÔ1Ø$˜Ø˜a™Cšà˜ØŸ™ EÔ*Ø™šà˜1‘u ¡¨¡	Ó)ØŸ™ EÔ*Ø$×+Ñ+¨DÔ1Ø$˜Ø˜a™CšàŸ™ EÔ*Ø™šñC &ðH ˆØˆÛ ˆDØˆJØˆAÛ�Ù,1Ó2ªE q˜Q œU©E�	Ð2Ø×!Ñ! )Ô,Ø”S˜“Z‘’ñ ð �‰FˆAÙ˜zÓ*ˆDÜ# DÓ)ˆCØ�K‰K˜Öñ !ñ  Ð%Ð%ùò 3s   Å F&© )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úpropertyr"   r%   r+   r2   r6   r:   Ú_eval_transposeÚ_eval_adjointrB   rY   Ú__static_attributes__Ú__classcell__©r   s   @r   r   r   	   se   ø† ñ/õb*ð ñó ðð ñ(ó ð(òò
0ò=ò5ð '4Ð3€O�mò"÷>&ð >&r   r   c                   ól   ^ • \ rS rSrSr\R                  4U 4S jjrS	S jr\	S 5       r
S rS rSrU =r$ )
ÚMatrixPermuteé¨   aæ  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                 ó8  >• SSK Jn  [        U5      nUR                  (       d  [	        SR                  U5      5      e[        U5      n[        U[        5      (       a  UR                  S   n[        X$5      (       d  [	        SR                  U5      5      e[        U5      nUS;  a  [	        S5      eUR                  U   nXRR                  :w  a   UR                  U5      n[        TU ]5  XX#5      $ ! [         a    [	        SR                  X!U5      5      ef = f)Nr   r   z#{} must be a SymPy matrix instance.z>{} must be a SymPy Permutation or a PermutationMatrix instance)r   r   z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   Ú	is_Matrixr   r   r   r   r   r"   r    Úresizer   r   )r   rX   r   Úaxisr   Úmat_sizer   s         €r   r   ÚMatrixPermute.__new__Ü   s  ø€ Ý@ä�s‹mˆØ�}�}ÜØ5×<Ñ<¸TÓBóDð Dô ˜‹~ˆÜ�dÔ-×.Ñ.Ø—9‘9˜Q‘<ˆDä˜$×,Ñ,Üðß!™6 $›<ó)ð )ô ˜‹~ˆØ�vÓÜÐ7Ó8Ð8à—9‘9˜T‘?ˆØ—y‘yÓ ð.Ø—{‘{ 8Ó,�ô ‰w‰˜s¨Ó4Ð4øô ó .Ü ð/÷ ‘V˜D tÓ,ó	.ð .ð.ús   ÃC3 Ã3&Dc                 ó$  • U R                   u  p4nU(       a(  UR                  " SSU0UD6nUR                  " SSU0UD6nUR                  (       a  U$ UR                  (       a?  U[        R                  L a  [        U5      $ U[        R                  L a  [        US-  5      $ [        U[        [        45      (       a  U$ [        U[        5      (       a<  UR                   S   U:X  a)  [        UR                   S   XCR                   S   -  U5      $ U $ )NÚdeepr9   é   r   r   r[   )r   r+   r%   r   ÚZeror   r>   r   r   r
   rh   )r!   rq   r*   rX   r   rm   s         r   r+   ÚMatrixPermute.doitþ   sÝ   € ØŸ)™)‰ˆ�4æØ—(’(Ñ. Ð.¨Ñ.ˆCØ—9’9Ñ0 $Ð0¨%Ñ0ˆDà××ØˆJà�?�?Ø”q—v‘vŠ~Ü(¨Ó.Ð.ØœŸ™’Ü(¨¨r©Ó2Ð2ä�cœJ¬	Ð2×3Ñ3ØˆJä�cœ=×)Ñ)¨c¯h©h°q©k¸TÓ.AÜ  §¡¨!¡¨d·X±X¸a±[Ñ.@À$ÓGÐGàˆr   c                 ó4   • U R                   S   R                  $ r   )r   r"   r&   s    r   r"   ÚMatrixPermute.shape  s   € à�y‰y˜‰|×!Ñ!Ð!r   c                 óŽ   • U R                   u  pEnUS:X  a  XER                  U5      U4   $ US:X  a  XAUR                  U5      4   $ g )Nr   r   )r   r.   )r!   r/   r0   r1   rX   r   rm   s          r   r2   ÚMatrixPermute._entry  sN   € ØŸ)™)‰ˆ�4à�1‹9Ø—z‘z !“} aÐ'Ñ(Ð(Ø�Q‹YØ˜$Ÿ*™* Q›-Ð'Ñ(Ð(ð r   c                 óè   • SSK Jn  U R                  u  pEnUR                  SS5      nU(       a  UR	                  U5      nUS:X  a  U" [        U5      U5      $ US:X  a  U" U[        US-  5      5      $ g )Nr   )ÚMatMulrq   Tr   r9   )Úmatmulrz   r   ÚgetÚrewriter   )r!   r   r1   rz   rX   r   rm   rq   s           r   Ú_eval_rewrite_as_MatMulÚ%MatrixPermute._eval_rewrite_as_MatMul"  sp   € Ý"àŸ)™)‰ˆ�4à�z‰z˜& $Ó'ˆæØ—+‘+˜fÓ%ˆCà�1‹9ÙÔ+¨DÓ1°3Ó7Ð7Ø�Q‹YÙ˜#Ô0°°r±Ó:Ó;Ð;ð r   r[   )T)r\   r]   r^   r_   r`   r   rs   r   r+   ra   r"   r2   r~   rd   re   rf   s   @r   rh   rh   ¨   s@   ø† ñ2ðf &'§V¡V÷  5ôDð0 ñ"ó ð"ò)÷<ð <r   rh   N)Ú
sympy.corer   Úsympy.core.sympifyr   Úsympy.functionsr   Úmatexprr   Úspecialr   r	   r
   r   rh   r[   r   r   Ú<module>r…      s4   ðÝ Ý 'Ý *å ß 4Ñ 4ô\&˜
ô \&ô~G<�Jõ G<r   