ó
¡¼™\c           @  s¦   d  d l  m Z m Z d  d l m Z 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(   iÿÿÿÿ(   t   print_functiont   division(   t   Permutation(   t   range(   t   symbols(   t   Matrix(   t
   variationst   rotate_leftc         c  s5   x. t  t t |  ƒ ƒ |  ƒ D] } t | ƒ Vq Wd S(   sH  
    Generates the symmetric group of order n, Sn.

    Examples
    ========

    >>> from sympy.combinatorics.permutations import Permutation
    >>> Permutation.print_cyclic = True
    >>> 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   t   listR   R   (   t   nt   perm(    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt	   symmetric
   s    "c         c  sG   t  t |  ƒ ƒ } x. t |  ƒ D]  } t | ƒ Vt | d ƒ } q Wd S(   sw  
    Generates the cyclic group of order n, Cn.

    Examples
    ========

    >>> from sympy.combinatorics.permutations import Permutation
    >>> Permutation.print_cyclic = True
    >>> 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
    i   N(   R   R   R   R   (   R	   t   gent   i(    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   cyclic   s    c         c  sG   x@ t  t t |  ƒ ƒ |  ƒ D]# } t | ƒ } | j r | Vq q Wd S(   s6  
    Generates the alternating group of order n, An.

    Examples
    ========

    >>> from sympy.combinatorics.permutations import Permutation
    >>> Permutation.print_cyclic = True
    >>> from sympy.combinatorics.generators import alternating
    >>> list(alternating(3))
    [(2), (0 1 2), (0 2 1)]
    N(   R   R   R   R   t   is_even(   R	   R
   t   p(    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   alternating4   s    "	c         c  sû   |  d k r1 t  d d g ƒ Vt  d d g ƒ VnÆ |  d k rœ t  d d d d g ƒ Vt  d d d d g ƒ Vt  d d d d g ƒ Vt  d d d d g ƒ Vn[ t t |  ƒ ƒ } xF t |  ƒ D]8 } t  | ƒ Vt  | d d d … ƒ Vt | d ƒ } q» Wd S(   s=  
    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.permutations import Permutation
    >>> Permutation.print_cyclic = True
    >>> 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
    i   i    i   i   Niÿÿÿÿ(   R   R   R   R   (   R	   R   R   (    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   dihedralG   s    c          C  s¿   d2 d3 d4 d5 d6 g d7 d8 d9 d: d; g d< d= d> d? d@ g dA dB dC dD dE g dF dG dH dI dJ g dK dL dM dN dO g g }  g  |  D]B } t  g  | D]# } g  | D] } | d ^ q– ^ q‰ d1 d. ƒ^ qy S(P   so   Return the permutations of the 3x3 Rubik's cube, see
    http://www.gap-system.org/Doc/Examples/rubik.html
    i   i   i   i   i   i   i   i   i	   i!   i   i   i
   i"   i   i   i   i#   i   i   i   i   i   i   i   i)   i(   i   i,   i%   i   i.   i   i   i   i+   i   i*   i   i    i   i   i&   i$   i-   i0   i'   i/   t   size(   i   i   i   i   (   i   i   i   i   (   i	   i!   i   i   (   i
   i"   i   i   (   i   i#   i   i   (   i	   i   i   i   (   i
   i   i   i   (   i   i   i)   i(   (   i   i   i,   i%   (   i   i   i.   i#   (   i   i   i   i   (   i   i   i   i   (   i   i   i+   i   (   i   i   i*   i   (   i   i   i)   i   (   i   i   i    i   (   i   i   i   i   (   i   i&   i+   i   (   i   i$   i-   i   (   i   i!   i0   i   (   i!   i#   i(   i&   (   i"   i%   i'   i$   (   i   i	   i.   i    (   i   i   i/   i   (   i   i   i0   i   (   i)   i+   i0   i.   (   i*   i-   i/   i,   (   i   i   i   i&   (   i   i   i   i'   (   i   i   i    i(   (   R   (   t   at   xt   xiR   (    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   rubik_cube_generatorsm   s    	c           s°  ˆ d k  r t  d ƒ ‚ n  ‡
 ‡ 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 ƒ \ ‰ ‰ ‰ ‰  ‰ ‰ ‰ i  ‰
 d } xf t d ƒ D]X } g  } x/ t ˆ d ƒ D] } | j | ƒ | d 7} qÛWt ˆ ˆ | ƒ ˆ
 ˆ | <q¾Wd ‡
 ‡ ‡ f d † } g  ‰ t t d ˆ d ƒ ƒ }	 x3 t ˆ d ƒ D]! }
 ˆ |
 ƒ | ƒ  | |
 ƒ qcW| d ƒ |	 k s t ‚ ˆ ƒ  xA t ˆ d ƒ D]/ }
 ˆ |
 ƒ | ƒ  | ƒ  ˆ ƒ  | |
 ƒ q¸W| ƒ  | d ƒ |	 k s
t ‚ ˆ ƒ  | ƒ  | ƒ  x] t ˆ d ƒ D]K }
 ˆ |
 ƒ ˆ ƒ  ˆ ƒ  | ƒ  | ƒ  ˆ ƒ  | ƒ  | ƒ  | |
 ƒ q0Wˆ ƒ  ˆ ƒ  | ƒ  | d ƒ |	 k s¬t ‚ ˆ S(   s)  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.
    i   s   dimension of cube must be > 1c           s   ˆ  |  j  ˆ | ƒ S(   N(   t   col(   t   fR   (   t   facesR	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   getr   s    c           s   ˆ  |  j  | d ƒ S(   Ni   (   R   (   R   R   (   R   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   getl’   s    c           s   ˆ  |  j  | d ƒ S(   Ni   (   t   row(   R   R   (   R   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   getu•   s    c           s   ˆ  |  j  ˆ | ƒ S(   N(   R   (   R   R   (   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   getd˜   s    c           s.   t  ˆ d | ƒ ˆ  |  d  d  … ˆ | f <d  S(   Ni   (   R   (   R   R   t   s(   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   setr›   s    c           s.   t  ˆ d | ƒ ˆ  |  d  d  … | d f <d  S(   Ni   (   R   (   R   R   R    (   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   setlž   s    c           s.   t  d ˆ | ƒ ˆ  |  | d d  d  … f <d  S(   Ni   (   R   (   R   R   R    (   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   setu¡   s    c           s.   t  d ˆ | ƒ ˆ  |  ˆ | d  d  … f <d  S(   Ni   (   R   (   R   R   R    (   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   setd¤   s    i   c           s   x‰ t  | ƒ D]{ } ˆ  |  } g  } xL t  ˆ ƒ D]> } x5 t  ˆ d d d ƒ D] } | j | | | f ƒ qM Wq0 Wt ˆ ˆ | ƒ ˆ  |  <q Wd  S(   Ni   iÿÿÿÿ(   R   t   appendR   (   t   Ft   rt   _t   facet   rvt   c(   R   R	   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   cw¨   s    
c           s   ˆ  |  d ƒ d  S(   Ni   (    (   R&   (   R,   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   ccw±   s    c      	     sÖ   xÏ t  | ƒ D]Á } |  d k r, ˆ ˆ ƒ n  |  d 7}  ˆ ˆ |  ƒ } ˆ ˆ |  t ˆ	 ˆ  |  ƒ ƒ ƒ ˆ ˆ  |  t t ˆ ˆ |  ƒ ƒ ƒ ƒ ˆ ˆ |  t ˆ ˆ |  ƒ ƒ ƒ ˆ
 ˆ |  t t | ƒ ƒ ƒ |  d 8}  q Wd  S(   Ni    i   (   R   R   t   reversed(   R   R'   R(   t   temp(   t   DR&   t   Lt   Rt   UR,   R   R   R   R   R$   R"   R!   R#   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   fcw·   s    
%c           s   ˆ  |  d ƒ d  S(   Ni   (    (   R   (   R4   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   fccwÃ   s    c           s•   xŽ t  |  ƒ D]€ } ˆ ˆ ƒ ˆ ˆ  ƒ ˆ ˆ ƒ ˆ ˆ } ˆ ˆ ƒ ˆ ˆ ˆ ˆ <ˆ ˆ ƒ ˆ ˆ ˆ ˆ <ˆ ˆ ƒ ˆ ˆ ˆ ˆ <| ˆ ˆ <q Wd  S(   N(   R   (   R'   R(   t   t(	   t   BR0   R&   R1   R2   R3   R-   R,   R   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   FCWÇ   s    






c             s   ˆ  d ƒ d  S(   Ni   (    (    (   R8   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   FCCWÕ   s    c           sm   xf t  |  ƒ D]X } ˆ ˆ ƒ ˆ ˆ ƒ ˆ ˆ } ˆ ˆ ˆ ˆ <ˆ ˆ  ˆ ˆ <ˆ ˆ ˆ ˆ  <| ˆ ˆ <q Wd  S(   N(   R   (   R'   R(   R6   (	   R7   R0   R&   R1   R2   R3   R-   R,   R   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   UCWÙ   s    


c             s   ˆ  d ƒ d  S(   Ni   (    (    (   R:   (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   UCCWã   s    s   U, F, R, B, L, Di    i   c           sI   g  } x ˆ D] } | j  ˆ  | ƒ q W|  r2 | Sˆ j t | ƒ ƒ d  S(   N(   t   extendR%   R   (   t   showR   R   (   R   t   gt   names(    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyR
   ö   s    (   t
   ValueErrorR   R   R%   R   R   t   AssertionError(   R	   R5   R9   R;   t   countt   fiR   R   R
   t   IR   (    (   R7   R0   R&   R8   R1   R2   R3   R:   R-   R,   R   R4   R>   R   R   R   R   R	   R?   R$   R"   R!   R#   s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   rubik‚   s|    		9**
"	


N(   t
   __future__R    R   t    sympy.combinatorics.permutationsR   t   sympy.core.compatibilityR   t   sympy.core.symbolR   t   sympy.matricesR   t   sympy.utilities.iterablesR   R   R   R   R   R   R   RE   (    (    (    s=   lib/python2.7/site-packages/sympy/combinatorics/generators.pyt   <module>   s   				&	