
    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y)    Permutation)symbolsMatrix)
variationsrotate_leftc              #   Z   K   t        t        |       |       D ]  }t        |        yw)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     S/var/www/openai/venv/lib/python3.12/site-packages/sympy/combinatorics/generators.py	symmetricr      s(      58Q'$ (s   )+c              #      K   t        t        |             }t        |       D ]  }t        |       t        |d      } yw)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:     " uQx.C1X##q! s   ?Ac              #   x   K   t        t        |       |       D ]  }t        |      }|j                  s|   yw)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   -   s3      58Q'99G (s   0::c              #   x  K   | dk(  rt        ddg       t        ddg       y| dk(  r=t        g d       t        g d       t        g d       t        g d       yt        t        |             }t        |       D ].  }t        |       t        |ddd	          t        |d      }0 yw)
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     ( 	Av1a&!!1a&!!	
a,'','','',''58nqAc""c$B$i((c1%C s   B8B:c                      g dg dg dg dg dg dg} | D cg c]0  }t        |D cg c]  }|D cg c]  }|dz
  	 c} c}}d	      2 c}}}S c c}w c c}}w c c}}}w )
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"      .   r/   ))r)   r1      r<   )r-         r9   )r"   r(   +   r2   )r$      *   r4   )r!      r7   r.   ))r(   r0       rD   )r,         rB   )r   &   rA   r1   )r#   $   -   r?   )r!   r'   0   r>   ))r'   r/   r8   rH   )r+   r;   '   rI   )r   r&   r=   rE   )r   r6   /   rF   )r   r3   rK   r0   ))r7   rA   rK   r=   )rC   rJ   rM   r:   )r3   r<   rD   rH   )r5   r@   rG   rL   )r2   r>   rE   r8   r   rK   )sizer   )axxir   s       r   rubik_cube_generatorsrR   b   sr    
						-	A NOOQKq9q,A!a%,q9CQOO,9Os&   A 	AAAA AA 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 ]@  }g }t         dz        D ]  }|j                  |       |dz  } t	          |      |   <   B dfd	}g t        t        d dz  z              }	t         dz
        D ]  }
 |
        |         ||
         |d      |	k(  sJ          t         dz
        D ]'  }
 |
        |         |                  ||
       )  |         |d      |	k(  sJ           |         |        t         dz
        D ]C  }
 |
                          |         |                  |         |         ||
       E                    |         |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                 2    |    j                  |z
        S Ncolfr   facesr   s     r   getrzrubik.<locals>.getr       Qx||AE""    c                 2    |    j                  |dz
        S Nr   rV   rY   r   rZ   s     r   getlzrubik.<locals>.getl   r\   r]   c                 2    |    j                  |dz
        S r_   rowr`   s     r   getuzrubik.<locals>.getu   r\   r]   c                 2    |    j                  |z
        S rU   rc   rX   s     r   getdzrubik.<locals>.getd   r\   r]   c                 :    t        d|      |    d d |z
  f<   y r_   r   rY   r   srZ   r   s      r   setrzrubik.<locals>.setr   !    #Aq!_aAEr]   c                 :    t        d|      |    d d |dz
  f<   y r_   r   ri   s      r   setlzrubik.<locals>.setl   rl   r]   c                 :    t        d|      |    |dz
  d d f<   y r_   r   ri   s      r   setuzrubik.<locals>.setu   !    #Aq!_aQr]   c                 :    t        d|      |    |z
  d d f<   y r_   r   ri   s      r   setdzrubik.<locals>.setd   rq   r]   r   c                     t        |      D ]T  }|    }g }t              D ]-  }t        dz
  dd      D ]  }|j                  |||f           / t        |      | <   V y )Nr   r   )r   appendr   )Fr_facervcrZ   r   s         r   cwzrubik.<locals>.cw   sl    qA8DB1Xq1ub"-AIId1a4j) .  aB'E!H r]   c                      | d       y Nr    )rv   r|   s    r   ccwzrubik.<locals>.ccw   s    
1ar]   c                 L   t        |      D ]  }| dk(  r 	       | dz  }  |       } | t         |                     | t        t         |                           | t         
|                     | t        t        |                   | dz  }  y )Nr   r   )r   r   reversed)r   rw   rx   tempDrv   LRUr|   rg   ra   r[   re   rs   rn   rk   rp   s       r   fcwzrubik.<locals>.fcw   s    qAAv1FA1:DAtDAJ'(AtHT!QZ012AtDAJ'(AtHTN+,FA r]   c                      | d       y r~   r   )r   r   s    r   fccwzrubik.<locals>.fccw   s    Aq	r]   c                    	 t        |       D ]T  } 
        	        
          } 
          <    
          <    
          <   |<   V y rU   r   rw   rx   tBr   rv   r   r   r   r   r|   rZ   s      r   FCWzrubik.<locals>.FCW   st    qAqEFqEaAqEQxE!HqEQxE!HqEQxE!HE!H r]   c                        d       y r~   r   )r   s   r   FCCWzrubik.<locals>.FCCW   
    Ar]   c                    	 t        |       D ]4  } 
        	          }   <      <      <   |<   6 y rU   r   r   s      r   UCWzrubik.<locals>.UCW   sX    qAqEFaAQxE!HQxE!HQxE!HE!H r]   c                        d       y r~   r   )r   s   r   UCCWzrubik.<locals>.UCCW   r   r]   zU, F, R, B, L, Dr   r"   c                 |    g }D ]  }|j                  |           | r|S j                  t        |             y rU   )extendru   r   )showr   rY   rZ   gnamess      r   r   zrubik.<locals>.perm   s:    AHHU1X H	Q r]   )r   )r   )
ValueErrorr   r   ru   r   r   )!r   r   r   r   countfirY   rO   r   Ir   r   r   rv   r   r   r   r   r   r   r|   rZ   r   r   rg   ra   r[   re   r   rs   rn   rk   rp   s!   `          @@@@@@@@@@@@@@@@@@@@@@r   rubikr   w   s     	1u899####----(
 
 
  
  ''9::Aq!Q1u EEAhq!tAHHUOQJE  "!Q?eBi ! 	AU1QT6]A 1q5\AQ  7a<< E1q5\A 	Q  	F7a<< EFF1q5\A 	Q " EEF7a<<Hr]   N) sympy.combinatorics.permutationsr   sympy.core.symbolr   sympy.matricesr   sympy.utilities.iterablesr   r	   r   r   r   r   rR   r   r   r]   r   <module>r      s2    8 % ! = "."!&HP*wr]   