
    g9                     ^    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              #   l   K   t          t          |           |           D ]}t          |          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)]
    N)r   ranger   )nperms     Z/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/combinatorics/generators.py	symmetricr      sH       588Q''    $       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'   r/         )r+            )r   r*   )   (   )r&      ,   %   )r#      .   r0   ))r*   r2      r=   )r.         r:   )r#   r)   +   r3   )r%      *   r5   )r"      r8   r/   ))r)   r1       rE   )r-         rC   )r   &   rB   r2   )r$   $   -   r@   )r"   r(   0   r?   ))r(   r0   r9   rI   )r,   r<   '   rJ   )r   r'   r>   rF   )r   r7   /   rG   )r   r4   rL   r1   ))r8   rB   rL   r>   )rD   rK   rN   r;   )r4   r=   rE   rI   )r6   rA   rH   rM   )r3   r?   rF   r9   c                 D    g | ]}t          d  |D             d          S )c                 &    g | ]}d  |D             S )c                     g | ]}|d z
  S r    ).0r   s     r   
<listcomp>z?rubik_cube_generators.<locals>.<listcomp>.<listcomp>.<listcomp>t   s    ,,,A!a%,,,r   rS   )rT   xis     r   rU   z4rubik_cube_generators.<locals>.<listcomp>.<listcomp>t   s'    999,,,,,999r   rL   )sizer   )rT   xs     r   rU   z)rubik_cube_generators.<locals>.<listcomp>t   s4    OOOK99q999CCCOOOr   rS   )as    r   rubik_cube_generatorsrZ   b   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 Ncolfr   facesr   s     r   getrzrubik.<locals>.getr       Qx||AE"""r   c                 @    |                               |dz
            S Nr   r^   ra   r   rb   s     r   getlzrubik.<locals>.getl   rd   r   c                 @    |                               |dz
            S rf   rowrg   s     r   getuzrubik.<locals>.getu   rd   r   c                 @    |                               |z
            S r]   rj   r`   s     r   getdzrubik.<locals>.getd   rd   r   c                 J    t          d|          |          d d |z
  f<   d S rf   r   ra   r   srb   r   s      r   setrzrubik.<locals>.setr   -    #Aq!__aAEr   c                 J    t          d|          |          d d |dz
  f<   d S rf   r   rp   s      r   setlzrubik.<locals>.setl   rs   r   c                 J    t          d|          |          |dz
  d d f<   d S rf   r   rp   s      r   setuzrubik.<locals>.setu   -    #Aq!__aQr   c                 J    t          d|          |          |z
  d d f<   d S rf   r   rp   s      r   setdzrubik.<locals>.setd   rx   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crb   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   rS   )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   rn   rh   rc   rl   rz   ru   rr   rw   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   rS   )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   rb   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   rS   )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   rS   )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   ra   rb   gnamess      r   r   zrubik.<locals>.perm   s[     	 	AHHU1X 	H	Q     r   rR   )r   )
ValueErrorr   r   r|   r   r   )!r   r   r   r   countfira   rY   r   Ir   r   r   r}   r   r   r   r   r   r   r   rb   r   r   rn   rh   rc   rl   r   rz   ru   rr   rw   s!   `          @@@@@@@@@@@@@@@@@@@@@@r   rubikr   w   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    rZ   r   rS   r   r   <module>r      s    8 8 8 8 8 8 % % % % % % ! ! ! ! ! ! = = = = = = = =     " " ".  "!& !& !&HP P P*w w w w wr   