
    g                         d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZ d
 Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#dS )    )Permutation)	unchanged)Matrix)MatMulBlockDiagMatrixDeterminantInverse)MatrixSymbol)
ZeroMatrix	OneMatrixIdentity)MatrixPermutePermutationMatrix)raises)Symbolc                  b   t          ddg          } t          t          |           sJ t          t          d            t          |                                           t          ddgddgg          k    sJ t          t          |           t          ddd          z  t                    sJ d S )N   r   c                       t          d          S )Nr   r      )r        m/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/matrices/expressions/tests/test_permutation.py<lambda>z.test_PermutationMatrix_basic.<locals>.<lambda>   s    0;; r   Ar   )
r   r   r   r   
ValueErroras_explicitr   
isinstancer
   r   ps    r   test_PermutationMatrix_basicr!      s    QFA&*****
:;;<<<Q++--!Q!Q8H1I1IIIII'**<Q+B+BBFKKKKKKKr   c                     t          g d          } t          |           }t          g dg dg dg          }||z                                  |                                |z  k    sJ ||z                                  ||                                z  k    sJ t          t          g d                    }t          t          g d                    }t          t          g d                    }||z  |k    sJ d S )Nr   r   r   r   )         )         )r   r   r   )r   r   r   )r   r   r   r   )r    PMP1P2P3s         r   test_PermutationMatrix_matmulr/      s    IIIA!A			999iii011AaC!--//!"33333aC!AMMOO"33333	;yyy11	2	2B	;yyy11	2	2B	;yyy11	2	2Bb5B;;;;;;r   c                      t          g d          } t          |           }t          g d          }t          |          }|dz  |k    sJ |dz  t          d          k    sJ d S )Nr#   r   r   r   r   r$   )r   r   r   )p1r,   p2r-   s       r   test_PermutationMatrix_matpowr4   #   sp    	YYY		B	2		B	YYY		B	2		Bq5B;;;;q5HQKKr   c                      t          ddg          } t          |           j        sJ t          ddg          } t          |           j        rJ d S )Nr   r   )r   r   is_Identityr   s    r   test_PermutationMatrix_identityr7   ,   sX    QFAQ++++QFA ##//////r   c                     t          t          g d                    } t          |                                           dk    sJ t          t          g d                    } t          |                                           dk    sJ t          t          g d                    } t          |                                           dk    sJ d S )Nr   r   )r   r   r   r1   )r   r   r   doitr*   s    r   "test_PermutationMatrix_determinantr<   4   s    +iii0011Aq>>  A%%%%+iii0011Aq>>  B&&&&+iii0011Aq>>  A%%%%%%r   c                      t          t          ddd                    } t          |                                           t          t          ddd                    k    sJ d S )Nr   r   r   )r   r   r	   r:   r;   s    r   test_PermutationMatrix_inverser>   =   sW    +aA..//A1::?? 1+aA2F2F G GGGGGGGr   c            	         t          t          g d                    } t          t          dg                    }|                     t                    t          ||||||          k    sJ t          t          g d                    } t          t          dd                    }|                     t                    t          |||||          k    sJ t          t          g d                    } |                     t                    t          |||          k    sJ t          t          g d                    } t          t          g d                    }|                     t                    t          |||          k    sJ t          t          g d                    } t          t          g d	                    }|                     t                    t          |||          k    sJ t            t          dd
          dd          dd                    } |                     t                    t          |           k    sJ d S )N)r   r   r   r$   r%   r&   r   )r   r   r$   r   r%   r&   r   )r   r   r$   r   r&   r%   )r   r%   r$   r   r   r&   )r$   r   r   r   )r   r%   r   r$   r   r&   )r$   r   r   r   r$   r%   r   r&   )r   r   rewriter   )r*   P0P10P3210P3120s        r   .test_PermutationMatrix_rewrite_BlockDiagMatrixrE   B   sX   +&8&8&899::A	;s++	,	,B99_%%BBB//0 0 0 0 	+&8&8&899::A
K1--
.
.C99_%%BR,,- - - - 	+&8&8&899::A99_%%S#&&' ' ' ' 	+&8&8&899::Ak,,,7788E99_%%E2&&' ' ' ' 	+&8&8&899::Ak,,,7788E99_%%E2&&' ' ' ' 	1++a++Aq11!Q7788A99_%%););;;;;;;r   c                     t          dd          t                    } t          ddd          t          t          fd           t          t          fd           t          |           t                    k    sJ t          t          fd           t          ddd	          t                    t                    k    sJ t          ddd          t          t          fd
           d S )Nr   r   r   r   c                  >    t          t          d                     S Nxr   r   r   s   r   r   z+test_MartrixPermute_basic.<locals>.<lambda>d   s    }VC[[!<< r   c                  >    t           t          d                    S rH   rJ   )r   s   r   r   z+test_MartrixPermute_basic.<locals>.<lambda>e   s    }Qs<< r   c                  &    t           d          S )Nr   r   )r   r    s   r   r   z+test_MartrixPermute_basic.<locals>.<lambda>h   s    }Q155 r   r$   sizec                  $    t                     S )NrM   )r   pps   r   r   z+test_MartrixPermute_basic.<locals>.<lambda>m   s    }Q33 r   )r   r   r
   r   r   r   )r*   r   r    rQ   s    @@@r   test_MartrixPermute_basicrR   _   s   AqA!AS!QA
:<<<<===
:<<<<===A-1"5"55555
:55555666	Q	"	"	"BB=A#6#66666	Q1		B
:3333344444r   c                  ~    t          dd          } t          ddd          }t          ||           j        dk    sJ d S )Nr   r   r   r   r$   )r   r$   )r   r
   r   shaper    r   s     r   test_MatrixPermute_shaperV   p   sF    AqAS!QAA$......r   c                  j   t          ddd          } t          ddd          }|                                }t          || d                                          |                    | d          k    sJ t          || d                                          |                    | d          k    sJ d S )	Nr   r   r   r   r$   rows)orientationcols)r   r
   r   r   permute)r    r   AAs      r   test_MatrixPermute_explicitr]   v   s    Aq!AS!QA	
BAq!!--//


1&
))* * * *Aq!!--//


1&
))* * * * * *r   c                     t          ddd          } t          ddd          }t          || d                              t                                                    t          || d                                          k    sJ t          || d                              t                                                    t          || d                                          k    sJ d S )Nr   r   r   r   r$   )r   r
   r   r@   r   r   rU   s     r   !test_MatrixPermute_rewrite_MatMulr_      s    Aq!AS!QAAq!!))&11==??aA**,,- - - -Aq!!))&11==??aA**,,- - - - - -r   c                      t          ddd          } t          ddd          }t          ||                                           t          ||           k    sJ t          dd          } t          ddd          }t          ||                                                                           t          ||                                           k    sJ t          ddd          } t          d          }t          || d                                                                          t          || d                                          k    sJ t          || d                                                                          t          || d                                          k    sJ t          dd          }t          ||                                           |k    sJ t          dd          }t          ||                                           |k    sJ t          ddd          }t          dddd          }t          dddd          }t          t          ||d          |d          }|                                |                                                                k    sJ t          t          ||d          |d          }|                                |                                                                k    sJ d S )Nr   r   r   r   r$   rN   r%   )r   r
   r   r:   r   r   r   r   )r    r   r2   r3   exprs        r   test_MatrixPermute_doitrb      s   Aq!AS!QAA##%%q!)<)<<<<<AAAS!QAA##%%1133a''))* * * * 	Aq!AAAq!!&&((4466aA**,,- - - -Aq!!&&((4466aA**,,- - - - 	1aAA##%%****!QAA##%%****S!QA	Q1a	 	 B	Q1a	 	 Bq"a00"a88D!8!8!:!:::::q"a00"a88D!8!8!:!:::::::r   N)$sympy.combinatoricsr   sympy.core.exprr   sympy.matricesr   sympy.matrices.expressionsr   r   r   r	   "sympy.matrices.expressions.matexprr
   "sympy.matrices.expressions.specialr   r   r   &sympy.matrices.expressions.permutationr   r   sympy.testing.pytestr   sympy.core.symbolr   r!   r/   r4   r7   r<   r>   rE   rR   rV   r]   r_   rb   r   r   r   <module>rl      s   + + + + + + % % % % % % ! ! ! ! ! !2 2 2 2 2 2 2 2 2 2 2 2 ; ; ; ; ; ; N N N N N N N N N N% % % % % % % % ' ' ' ' ' ' $ $ $ $ $ $L L L
 
 
     0 0 0& & &H H H
< < <:5 5 5"/ / /* * *- - -; ; ; ; ;r   