
    Xh7                     ^    d dl mZ d dlmZ d dlmZ d dlmZmZ d Z	d Z
d Zd Zd	 Zd
 ZdS )    Permutation)symbolsMatrix)
variationsrotate_leftc              #   d   K   d t          t          |           |           D             E d{V  dS )z
    Generates the symmetric group of order n, Sn.

    Examples
    ========

    >>> from sympy.combinatorics.generators import symmetric
    >>> list(symmetric(3))
    [(2), (1 2), (2)(0 1), (0 1 2), (0 2 1), (0 2)]
    c              3   4   K   | ]}t          |          V  d S Nr   ).0perms     p/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/combinatorics/generators.py	<genexpr>zsymmetric.<locals>.<genexpr>   s*      FFdD!!FFFFFF    N)r   range)ns    r   	symmetricr      sE       GFjq1.E.EFFFFFFFFFFFFr   c              #      K   t          t          |                     }t          |           D ]#}t          |          V  t          |d          }$dS )a  
    Generates the cyclic group of order n, Cn.

    Examples
    ========

    >>> from sympy.combinatorics.generators import cyclic
    >>> list(cyclic(5))
    [(4), (0 1 2 3 4), (0 2 4 1 3),
     (0 3 1 4 2), (0 4 3 2 1)]

    See Also
    ========

    dihedral
       N)listr   r   r	   r   genis      r   cyclicr      s]      " uQxx..C1XX " "##q!!" "r   c              #   ~   K   t          t          |           |           D ]}t          |          }|j        r|V  dS )z
    Generates the alternating group of order n, An.

    Examples
    ========

    >>> from sympy.combinatorics.generators import alternating
    >>> list(alternating(3))
    [(2), (0 1 2), (0 2 1)]
    N)r   r   r   is_even)r   r   ps      r   alternatingr   ,   sR       588Q''  9 	GGG r   c              #     K   | dk    r(t          ddg          V  t          ddg          V  dS | dk    rNt          g d          V  t          g d          V  t          g d          V  t          g d          V  dS t          t          |                     }t          |           D ]=}t          |          V  t          |ddd	                   V  t          |d          }>dS )
a  
    Generates the dihedral group of order 2n, Dn.

    The result is given as a subgroup of Sn, except for the special cases n=1
    (the group S2) and n=2 (the Klein 4-group) where that's not possible
    and embeddings in S2 and S4 respectively are given.

    Examples
    ========

    >>> from sympy.combinatorics.generators import dihedral
    >>> list(dihedral(3))
    [(2), (0 2), (0 1 2), (1 2), (0 2 1), (2)(0 1)]

    See Also
    ========

    cyclic
    r   r      )r   r   r!      )r   r   r"   r!   )r!   r"   r   r   )r"   r!   r   r   N)r   r   r   r	   r   s      r   dihedralr$   =   s)     ( 	Avv1a&!!!!!1a&!!!!!!!	
a,,,''''',,,''''',,,''''',,,'''''''588nnq 	& 	&Ac"""""c$$B$i(((((c1%%CC	& 	&r   c                  B    g dg dg dg dg dg dg} d | D             S )zpReturn the permutations of the 3x3 Rubik's cube, see
    https://www.gap-system.org/Doc/Examples/rubik.html
    ))r   r"         )r!            )	   !         )
   "         )   #         ))r+   r3         )r/            )r   r.   )   (   )r*      ,   %   )r'      .   r4   ))r.   r6      rA   )r2         r>   )r'   r-   +   r7   )r)      *   r9   )r&      r<   r3   ))r-   r5       rI   )r1         rG   )r"   &   rF   r6   )r(   $   -   rD   )r&   r,   0   rC   ))r,   r4   r=   rM   )r0   r@   '   rN   )r"   r+   rB   rJ   )r!   r;   /   rK   )r   r8   rP   r5   ))r<   rF   rP   rB   )rH   rO   rR   r?   )r8   rA   rI   rM   )r:   rE   rL   rQ   )r7   rC   rJ   r=   c                 D    g | ]}t          d  |D             d          S )c                 &    g | ]}d  |D             S )c                     g | ]}|d z
  S r    )r   r   s     r   
<listcomp>z?rubik_cube_generators.<locals>.<listcomp>.<listcomp>.<listcomp>s   s    ,,,A!a%,,,r   rW   )r   xis     r   rX   z4rubik_cube_generators.<locals>.<listcomp>.<listcomp>s   s'    999,,,,,999r   rP   )sizer   )r   xs     r   rX   z)rubik_cube_generators.<locals>.<listcomp>s   s4    OOOK99q999CCCOOOr   rW   )as    r   rubik_cube_generatorsr]   a   sz    
	 	 		 	 		 	 		 	 		 	 		- 	- 	-	A POQOOOOr   c                 |      dk     rt          d           fdfdfd fd fd fd fd	  fd
d fd	fdd fd	fd}df	d	fd}df	d	fd}t          d          x\  i d}t          d          D ]M}g }t           dz            D ]}|                    |           |dz  }t	            |          |         <   Ndfd	}g t          t          d dz  z                      }	t           dz
            D ]"}
 |
            |              ||
           # |d          |	k    sJ               t           dz
            D ]6}
 |
            |              |                            ||
           7 |              |d          |	k    sJ                |              |             t           dz
            D ]^}
 |
                                        |              |                            |              |              ||
           _                             |              |d          |	k    sJ S )a)  Return permutations for an nxn Rubik's cube.

    Permutations returned are for rotation of each of the slice
    from the face up to the last face for each of the 3 sides (in this order):
    front, right and bottom. Hence, the first n - 1 permutations are for the
    slices from the front.
    r!   zdimension of cube must be > 1c                 @    |                               |z
            S r   colfr   facesr   s     r   getrzrubik.<locals>.getr       Qx||AE"""r   c                 @    |                               |dz
            S Nr   r`   rc   r   rd   s     r   getlzrubik.<locals>.getl   rf   r   c                 @    |                               |dz
            S rh   rowri   s     r   getuzrubik.<locals>.getu   rf   r   c                 @    |                               |z
            S r   rl   rb   s     r   getdzrubik.<locals>.getd   rf   r   c                 J    t          d|          |          d d |z
  f<   d S rh   r   rc   r   srd   r   s      r   setrzrubik.<locals>.setr   -    #Aq!__aAEr   c                 J    t          d|          |          d d |dz
  f<   d S rh   r   rr   s      r   setlzrubik.<locals>.setl   ru   r   c                 J    t          d|          |          |dz
  d d f<   d S rh   r   rr   s      r   setuzrubik.<locals>.setu   -    #Aq!__aQr   c                 J    t          d|          |          |z
  d d f<   d S rh   r   rr   s      r   setdzrubik.<locals>.setd   rz   r   r   c                     t          |          D ]f}|          }g }t                    D ]6}t          dz
  dd          D ]}|                    |||f                     7t          |          | <   gd S )Nr   r#   )r   appendr   )Fr_facervcrd   r   s         r   cwzrubik.<locals>.cw   s    q 	( 	(A8DB1XX * *q1ub"-- * *AIId1a4j))))*aB''E!HH	( 	(r   c                       | d           d S Nr"   rW   )r   r   s    r   ccwzrubik.<locals>.ccw   s    
1ar   c                    t          |          D ]}| dk    r 	           | dz  }  |           } | t           |                                 | t          t           |                                           | t           
|                                 | t          t          |                               | dz  } d S )Nr   r   )r   r   reversed)r   r   r   tempDr   LRUr   rp   rj   re   rn   r|   rw   rt   ry   s       r   fcwzrubik.<locals>.fcw   s    q 		 		AAvv1FA41::DDAtDDAJJ''(((DAtHTT!QZZ0011222DAtDDAJJ''(((DAtHTNN++,,,FAA		 		r   c                       | d           d S r   rW   )r   r   s    r   fccwzrubik.<locals>.fccw   s    Aq					r   c                   	 t          |           D ]r} 
            	            
                    } 
                    <    
                    <    
                    <   |<   sd S r   r   r   r   tBr   r   r   r   r   r   r   rd   s      r   FCWzrubik.<locals>.FCW   s    q 	 	ABqEEECFFFBqEEEaABqEEEQxE!HBqEEEQxE!HBqEEEQxE!HE!HH	 	r   c                        d           d S r   rW   )r   s   r   FCCWzrubik.<locals>.FCCW       Ar   c                    	 t          |           D ]F} 
            	                    }         <            <            <   |<   Gd S r   r   r   s      r   UCWzrubik.<locals>.UCW   sw    q 	 	ABqEEECFFFaAQxE!HQxE!HQxE!HE!HH	 	r   c                        d           d S r   rW   )r   s   r   UCCWzrubik.<locals>.UCCW   r   r   zU, F, R, B, L, Dr   r'   c                     g }D ]}|                     |                    | r|S                     t          |                     d S r   )extendr~   r   )showr   rc   rd   gnamess      r   r   zrubik.<locals>.perm   s[     	 	AHHU1X 	H	Q     r   rV   )r   )
ValueErrorr   r   r~   r   r   )!r   r   r   r   countfirc   r\   r   Ir   r   r   r   r   r   r   r   r   r   r   rd   r   r   rp   rj   re   rn   r   r|   rw   rt   ry   s!   `          @@@@@@@@@@@@@@@@@@@@@@r   rubikr   v   s)    	1uu8999# # # # # ## # # # ## # # # ## # # # # #- - - - - -- - - - - -- - - - - -- - - - - -( ( ( ( ( ( (    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                                      
  ''9:::Aq!Q1u EEAhh + +q!t 	 	AHHUOOOQJEE!!Q??eBi! ! ! ! ! ! ! ! 	AU1QT6]]A 1q5\\  AQ477a<<<< CEEE1q5\\ 	 	A 	QDFFF477a<<<< CEEEDFFFDFFF1q5\\  A 	QCEEECEEEDFFF477a<<<<Hr   N) sympy.combinatorics.permutationsr   sympy.core.symbolr   sympy.matricesr   sympy.utilities.iterablesr   r	   r   r   r   r$   r]   r   rW   r   r   <module>r      s    8 8 8 8 8 8 % % % % % % ! ! ! ! ! ! = = = = = = = =G G G" " ".  "!& !& !&HP P P*w w w w wr   