ó
¡¼™\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
 e j Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d S(   iÿÿÿÿ(   t   print_functiont   division(   t   DirectProduct(   t   PermutationGroup(   t   Permutation(   t   rangec          G  su   g  } d } d } x5 |  D]- } | | 7} | | 9} | j  t | ƒ ƒ q Wt | Œ  } t | _ | | _ | | _ | S(   sê  
    Returns the direct product of cyclic groups with the given orders.

    According to the structure theorem for finite abelian groups ([1]),
    every finite abelian group can be written as the direct product of
    finitely many cyclic groups.

    Examples
    ========

    >>> from sympy.combinatorics import Permutation
    >>> Permutation.print_cyclic = True
    >>> from sympy.combinatorics.named_groups import AbelianGroup
    >>> AbelianGroup(3, 4)
    PermutationGroup([
            (6)(0 1 2),
            (3 4 5 6)])
    >>> _.is_group
    True

    See Also
    ========

    DirectProduct

    References
    ==========

    .. [1] http://groupprops.subwiki.org/wiki/Structure_theorem_for_finitely_generated_abelian_groups

    i    i   (   t   appendt   CyclicGroupR   t   Truet   _is_abeliant   _degreet   _order(   t   cyclic_orderst   groupst   degreet   ordert   sizet   G(    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt   AbelianGroup   s     

			c         C  s–  |  d k r" t  t d g ƒ g ƒ St t |  ƒ ƒ } | d | d | d | d <| d <| d <| } |  d r› t t d |  ƒ ƒ } | j d ƒ | } n8 t t d |  ƒ ƒ } | j d ƒ | j d d ƒ | } | | g } | | k rø | d  } n  t  g  | D] } t | ƒ ^ qd t ƒ} |  d k  rDt | _	 t | _
 n t | _	 t | _
 |  d k  rnt | _ n	 t | _ |  | _ t | _ t | _ | S(   s  
    Generates the alternating group on ``n`` elements as a permutation group.

    For ``n > 2``, the generators taken are ``(0 1 2), (0 1 2 ... n-1)`` for
    ``n`` odd
    and ``(0 1 2), (1 2 ... n-1)`` for ``n`` even (See [1], p.31, ex.6.9.).
    After the group is generated, some of its basic properties are set.
    The cases ``n = 1, 2`` are handled separately.

    Examples
    ========

    >>> from sympy.combinatorics.named_groups import AlternatingGroup
    >>> G = AlternatingGroup(4)
    >>> G.is_group
    True
    >>> a = list(G.generate_dimino())
    >>> len(a)
    12
    >>> all(perm.is_even for perm in a)
    True

    See Also
    ========

    SymmetricGroup, CyclicGroup, DihedralGroup

    References
    ==========

    [1] Armstrong, M. "Groups and Symmetry"

    i   i   i    t   dupsi   i   (   i   i   (   R   R   t   listR   R   t   insertt   _af_newt   FalseR   R	   t   _is_nilpotentt   _is_solvableR
   t   _is_transitivet   _is_alt(   t   nt   at   gen1t   gen2t   gensR   (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt   AlternatingGroup:   s:    #,
	+							c         C  sw   t  t d |  ƒ ƒ } | j d ƒ t | ƒ } t | g ƒ } t | _ t | _ t | _ |  | _	 t | _
 |  | _ | S(   sš  
    Generates the cyclic group of order ``n`` as a permutation group.

    The generator taken is the ``n``-cycle ``(0 1 2 ... n-1)``
    (in cycle notation). After the group is generated, some of its basic
    properties are set.

    Examples
    ========

    >>> from sympy.combinatorics.named_groups import CyclicGroup
    >>> G = CyclicGroup(6)
    >>> G.is_group
    True
    >>> G.order()
    6
    >>> list(G.generate_schreier_sims(af=True))
    [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 0], [2, 3, 4, 5, 0, 1],
    [3, 4, 5, 0, 1, 2], [4, 5, 0, 1, 2, 3], [5, 0, 1, 2, 3, 4]]

    See Also
    ========

    SymmetricGroup, DihedralGroup, AlternatingGroup

    i   i    (   R   R   R   R   R   R   R	   R   R   R
   R   R   (   R   R   t   genR   (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyR      s    						c         C  s@  |  d k r% t  t d d g ƒ g ƒ S|  d k rz t  t d d d d g ƒ t d d d d g ƒ t d d d d g ƒ g ƒ St t d |  ƒ ƒ } | j d ƒ t | ƒ } t t |  ƒ ƒ } | j ƒ  t | ƒ } t  | | g ƒ } |  |  d @d k rt | _ n	 t	 | _ t	 | _
 t | _ |  | _ t | _ d |  | _ | S(   s\  
    Generates the dihedral group `D_n` as a permutation group.

    The dihedral group `D_n` is the group of symmetries of the regular
    ``n``-gon. The generators taken are the ``n``-cycle ``a = (0 1 2 ... n-1)``
    (a rotation of the ``n``-gon) and ``b = (0 n-1)(1 n-2)...``
    (a reflection of the ``n``-gon) in cycle rotation. It is easy to see that
    these satisfy ``a**n = b**2 = 1`` and ``bab = ~a`` so they indeed generate
    `D_n` (See [1]). After the group is generated, some of its basic properties
    are set.

    Examples
    ========

    >>> from sympy.combinatorics.named_groups import DihedralGroup
    >>> G = DihedralGroup(5)
    >>> G.is_group
    True
    >>> a = list(G.generate_dimino())
    >>> [perm.cyclic_form for perm in a]
    [[], [[0, 1, 2, 3, 4]], [[0, 2, 4, 1, 3]],
    [[0, 3, 1, 4, 2]], [[0, 4, 3, 2, 1]], [[0, 4], [1, 3]],
    [[1, 4], [2, 3]], [[0, 1], [2, 4]], [[0, 2], [3, 4]],
    [[0, 3], [1, 2]]]

    See Also
    ========

    SymmetricGroup, CyclicGroup, AlternatingGroup

    References
    ==========

    [1] https://en.wikipedia.org/wiki/Dihedral_group

    i   i    i   i   (   R   R   R   R   R   R   t   reverseR   R   R   R	   R   R
   R   R   (   R   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt   DihedralGroupª   s*    &1
					c         C  s?  |  d k r' t  t d g ƒ g ƒ } n¥ |  d k rQ t  t d d g ƒ g ƒ } n{ t t d |  ƒ ƒ } | j d ƒ t | ƒ } t t |  ƒ ƒ } | d | d | d <| d <t | ƒ } t  | | g ƒ } |  d k  rí t | _ t | _ n t	 | _ t	 | _ |  d k  rt | _
 n	 t	 | _
 |  | _ t | _ t | _ | S(   s+  
    Generates the symmetric group on ``n`` elements as a permutation group.

    The generators taken are the ``n``-cycle
    ``(0 1 2 ... n-1)`` and the transposition ``(0 1)`` (in cycle notation).
    (See [1]). After the group is generated, some of its basic properties
    are set.

    Examples
    ========

    >>> from sympy.combinatorics.named_groups import SymmetricGroup
    >>> G = SymmetricGroup(4)
    >>> G.is_group
    True
    >>> G.order()
    24
    >>> list(G.generate_schreier_sims(af=True))
    [[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1], [3, 1, 2, 0], [0, 2, 3, 1],
    [1, 3, 0, 2], [2, 0, 1, 3], [3, 2, 0, 1], [0, 3, 1, 2], [1, 0, 2, 3],
    [2, 1, 3, 0], [3, 0, 1, 2], [0, 1, 3, 2], [1, 2, 0, 3], [2, 3, 1, 0],
    [3, 1, 0, 2], [0, 2, 1, 3], [1, 3, 2, 0], [2, 0, 3, 1], [3, 2, 1, 0],
    [0, 3, 2, 1], [1, 0, 3, 2], [2, 1, 0, 3], [3, 0, 2, 1]]

    See Also
    ========

    CyclicGroup, DihedralGroup, AlternatingGroup

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Symmetric_group#Generators_and_relations

    i   i    i   i   i   (   R   R   R   R   R   R   R   R	   R   R   R   R
   R   t   _is_sym(   R   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt   SymmetricGroupê   s.    $							c         C  s;   d d l  m } |  d k r+ t d ƒ ‚ n  t | |  ƒ ƒ S(   s—   Return a group of Rubik's cube generators

    >>> from sympy.combinatorics.named_groups import RubikGroup
    >>> RubikGroup(2).is_group
    True
    iÿÿÿÿ(   t   rubiki   s(   Invalid cube. n has to be greater than 1(   t   sympy.combinatorics.generatorsR'   t
   ValueErrorR   (   R   R'   (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt
   RubikGroup*  s    N(   t
   __future__R    R   t$   sympy.combinatorics.group_constructsR   t   sympy.combinatorics.perm_groupsR   t    sympy.combinatorics.permutationsR   t   sympy.core.compatibilityR   R   R   R!   R   R$   R&   R*   (    (    (    s?   lib/python2.7/site-packages/sympy/combinatorics/named_groups.pyt   <module>   s   		/	G	)	@	@