U
    —9%eº   ã                   @   sn   d dl mZ d dlmZ d dlmZ ejZdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )é    )ÚDirectProduct)ÚPermutationGroup)ÚPermutationc                  G   sR   g }d}d}| D ]"}||7 }||9 }|  t|ƒ¡ q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)Zcyclic_ordersÚgroupsÚdegreeÚorderÚsizeÚG© r   ú_/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/combinatorics/named_groups.pyÚAbelianGroup   s    !r   c                 C   sæ   | dkrt tdgƒgƒS tt| ƒƒ}|d |d |d   |d< |d< |d< |}| d rvttd| ƒƒ}| d¡ |}n(ttd| ƒƒ}| d¡ | dd¡ |}||g}||krº|dd… }t dd„ |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                 S   s   g | ]}t |ƒ‘qS r   )Ú_af_new)Ú.0Úar   r   r   Ú
<listcomp>p   s     z$AlternatingGroup.<locals>.<listcomp>F)ZdupsT)r   r   ÚlistÚranger   ÚinsertÚ set_alternating_group_propertiesZ_is_alt)Únr   Úgen1Úgen2Zgensr   r   r   r   ÚAlternatingGroup8   s(    &(

r   c                 C   sN   |dk rd| _ d| _nd| _ d| _|dk r2d| _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   r   r   r   r   w   s    r   c                 C   s\   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
   r&   )r   r   Úgenr   r   r   r   r   ˆ   s    


r   c                 C   sæ   | dkrt tddgƒgƒS | dkrTt tddddgƒtddddgƒtddddgƒgƒS ttd| ƒƒ}| d¡ t|ƒ}tt| ƒƒ}| ¡  t|ƒ}t ||gƒ}| | d @ dkr´d|_nd|_d|_d|_	d|_
| |_d|_d|  |_|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   é   TF)r   r   r   r   r   r   Úreverser#   r&   r   r$   r	   r%   r
   )r   r   r   r   r   r   r   r   ÚDihedralGroupµ   s0    ) ÿ

r+   c                 C   s¦   | dkrt tdgƒgƒ}nv| dkr6t tddgƒgƒ}nZttd| ƒƒ}| d¡ t|ƒ}tt| ƒƒ}|d |d  |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_propertiesZ_is_sym)r   r   r   r   r   r   r   r   ÚSymmetricGroupù   s    '
r-   c                 C   sR   |dk rd| _ d| _nd| _ d| _|dk r2d| _nd| _|| _d| _|dk| _dS )z+Set known properties of a symmetric group. r)   TFr!   )r   r)   Nr"   r'   r   r   r   r,   1  s    r,   c                 C   s(   ddl m} | dkrtdƒ‚t|| ƒƒS )z—Return 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)Zsympy.combinatorics.generatorsr.   Ú
ValueErrorr   )r   r.   r   r   r   Ú
RubikGroupB  s    r0   N)Z$sympy.combinatorics.group_constructsr   Zsympy.combinatorics.perm_groupsr   Z sympy.combinatorics.permutationsr   r   r   r   r   r   r+   r-   r,   r0   r   r   r   r   Ú<module>   s   0?-D8