
    g                      h    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
 Zd ZdS )    )DirectProduct)PermutationGroup)Permutationc                      g }d}d}| D ].}||z  }||z  }|                     t          |                     /t          | }d|_        ||_        ||_        |S )a  
    Returns the direct product of cyclic groups with the given orders.

    Explanation
    ===========

    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.named_groups import AbelianGroup
    >>> AbelianGroup(3, 4)
    PermutationGroup([
            (6)(0 1 2),
            (3 4 5 6)])
    >>> _.is_group
    True

    See Also
    ========

    DirectProduct

    References
    ==========

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

    r      T)appendCyclicGroupr   _is_abelian_degree_order)cyclic_ordersgroupsdegreeordersizeGs         \/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/combinatorics/named_groups.pyAbelianGroupr      sv    B FFE ) )$k$''((((vAAMAIAHH    c                 `   | dv rt          t          dg          g          S t          t          |                     }|d         |d         |d         c|d<   |d<   |d<   |}| dz  r5t          t          d|                     }|                    d           |}nJt          t          d|                     }|                    d           |                    dd           |}||g}||k    r
|dd         }t          d |D             d          }t          || |            d	|_        |S )
a=  
    Generates the alternating group on ``n`` elements as a permutation group.

    Explanation
    ===========

    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"

    )r      r   r   r   Nc                 ,    g | ]}t          |          S  )_af_new).0as     r   
<listcomp>z$AlternatingGroup.<locals>.<listcomp>p   s    333'!**333r   F)dupsT)r   r   listranger   insert set_alternating_group_properties_is_alt)nr   gen1gen2gensr   s         r   AlternatingGroupr(   8   s6   L 	F{{aS!1!1 2333U1XXAtQqT1Q4AaD!A$!D1u q!	q!		A$<Dt||BQBx33d333%@@@A$Q1---AIHr   c                     |dk     rd| _         d| _        nd| _         d| _        |dk     rd| _        nd| _        || _        d| _        d| _        dS )z.Set known properties of an alternating group.    TF   Nr
   _is_nilpotent_is_solvabler   _is_transitive_is_dihedralr   r$   r   s      r   r"   r"   w   s\    1uu1uuAIAANNNr   c                    t          t          d|                     }|                    d           t          |          }t	          |g          }d|_        d|_        d|_        | |_        d|_	        | |_
        | dk    |_        |S )a  
    Generates the cyclic group of order ``n`` as a permutation group.

    Explanation
    ===========

    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

    r   r   Tr   )r   r    r   r   r   r
   r-   r.   r   r/   r   r0   )r$   r   genr   s       r   r	   r	      s}    < 	U1a[[AHHQKKK
!**C#AAMAOANAIAAH1fANHr   c                    | dk    rt          t          ddg          g          S | dk    r?t          t          g d          t          g d          t          g d          g          S t          t          d|                     }|                    d           t          |          }t          t          |                     }|                                 t          |          }t          ||g          }| | dz
  z  dk    rd|_        nd|_        d|_        d|_	        d|_
        | |_        d|_        d| z  |_        |S )	a  
    Generates the dihedral group `D_n` as a permutation group.

    Explanation
    ===========

    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

    r   r   r   )r   r      r   )r   r5   r   r   )r5   r   r   r   TF)r   r   r   r    r   r   reverser-   r0   r
   r.   r   r/   r   )r$   r   r%   r&   r   s        r   DihedralGroupr7      s:   R 	AvvaV!4!4 5666Avv\\\!:!:<<<((+lll*C*C!E F F 	F 	U1a[[AHHQKKK1::DU1XXAIIKKK1::D$&&AAaCyA~~ANAMANAIAsAHHr   c                    | dk    rt          t          dg          g          }n| dk    r t          t          ddg          g          }nt          t          d|                     }|                    d           t          |          }t          t          |                     }|d         |d         c|d<   |d<   t          |          }t          ||g          }t          || |            d|_        |S )aL  
    Generates the symmetric group on ``n`` elements as a permutation group.

    Explanation
    ===========

    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

    r   r   r   T)r   r   r   r    r   r   set_symmetric_group_properties_is_sym)r$   r   r   r%   r&   s        r   SymmetricGroupr;      s    N 	Avvk1#../00	
ak1a&11233q!	qzzqNNqT1Q4
!adqzzdD\**"1a+++AIHr   c                     |dk     rd| _         d| _        nd| _         d| _        |dk     rd| _        nd| _        || _        d| _        |dv | _        dS )z+Set known properties of a symmetric group. r5   TFr+   )r   r5   Nr,   r1   s      r   r9   r9   1  s`    1uu1uuAIA6kANNNr   c                 h    ddl m} | dk    rt          d          t           ||                     S )zReturn a group of Rubik's cube generators

    >>> from sympy.combinatorics.named_groups import RubikGroup
    >>> RubikGroup(2).is_group
    True
    r   )rubikr   z(Invalid cube. n has to be greater than 1)sympy.combinatorics.generatorsr>   
ValueErrorr   )r$   r>   s     r   
RubikGrouprA   B  sD     544444AvvCDDDEE!HH%%%r   N)$sympy.combinatorics.group_constructsr   sympy.combinatorics.perm_groupsr    sympy.combinatorics.permutationsr   r   r   r(   r"   r	   r7   r;   r9   rA   r   r   r   <module>rE      s    > > > > > > < < < < < < 8 8 8 8 8 8

- - -`< < <~  "* * *ZA A AH5 5 5p# # #"
& 
& 
& 
& 
&r   