U
    9%eE                     @   s>  d Z ddlmZ ddlmZ ddlZddlmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ G dd	 d	eZG d
d deZG dd deZG dd deZG dd deZG dd de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$d% Zd&d' Z d(d) Z!d*d+ Z"d,d- Z#d.d/ Z$d0d1d2d3Z%dS )4aS  
Construct transitive subgroups of symmetric groups, useful in Galois theory.

Besides constructing instances of the :py:class:`~.PermutationGroup` class to
represent the transitive subgroups of $S_n$ for small $n$, this module provides
*names* for these groups.

In some applications, it may be preferable to know the name of a group,
rather than receive an instance of the :py:class:`~.PermutationGroup`
class, and then have to do extra work to determine which group it is, by
checking various properties.

Names are instances of ``Enum`` classes defined in this module. With a name in
hand, the name's ``get_perm_group`` method can then be used to retrieve a
:py:class:`~.PermutationGroup`.

The names used for groups in this module are taken from [1].

References
==========

.. [1] Cohen, H. *A Course in Computational Algebraic Number Theory*.

    )defaultdict)EnumN)SymmetricGroupAlternatingGroupCyclicGroupDihedralGroupset_symmetric_group_properties set_alternating_group_properties)PermutationGroup)Permutationc                   @   s   e Zd ZdZdZdd ZdS )S1TransitiveSubgroupsz3
    Names for the transitive subgroups of S1.
    S1c                 C   s   t dS )N   r   self r   Y/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/combinatorics/galois.pyget_perm_group,   s    z$S1TransitiveSubgroups.get_perm_groupN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   &   s   r   c                   @   s   e Zd ZdZdZdd ZdS )S2TransitiveSubgroupsz3
    Names for the transitive subgroups of S2.
    S2c                 C   s   t dS )N   r   r   r   r   r   r   6   s    z$S2TransitiveSubgroups.get_perm_groupN)r   r   r   r   r   r   r   r   r   r   r   0   s   r   c                   @   s    e Zd ZdZdZdZdd ZdS )S3TransitiveSubgroupsz3
    Names for the transitive subgroups of S3.
    A3S3c                 C   s(   | t jkrtdS | t jkr$tdS d S )N   )r   r   r   r   r   r   r   r   r   r   A   s    

z$S3TransitiveSubgroups.get_perm_groupN)r   r   r   r   r   r   r   r   r   r   r   r   :   s   r   c                   @   s,   e Zd ZdZdZdZdZdZdZdd Z	d	S )
S4TransitiveSubgroupsz3
    Names for the transitive subgroups of S4.
    C4VD4A4S4c                 C   s\   | t jkrtdS | t jkr"t S | t jkr4tdS | t jkrFtdS | t j	krXt
dS d S )N   )r    r!   r   r"   
four_groupr#   r   r$   r   r%   r   r   r   r   r   r   R   s    




z$S4TransitiveSubgroups.get_perm_groupN)
r   r   r   r   r!   r"   r#   r$   r%   r   r   r   r   r   r    H   s   r    c                   @   s,   e Zd ZdZdZdZdZdZdZdd Z	d	S )
S5TransitiveSubgroupsz3
    Names for the transitive subgroups of S5.
    C5D5M20A5S5c                 C   s\   | t jkrtdS | t jkr$tdS | t jkr4t S | t jkrFtdS | t jkrXt	dS d S )N   )
r(   r)   r   r*   r   r+   r,   r   r-   r   r   r   r   r   r   i   s    




z$S5TransitiveSubgroups.get_perm_groupN)
r   r   r   r   r)   r*   r+   r,   r-   r   r   r   r   r   r(   _   s   r(   c                   @   sX   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdd ZdS )S6TransitiveSubgroupsz3
    Names for the transitive subgroups of S6.
    C6r   D6r$   G18zA4 x C2zS4-zS4+zG36-zG36+zS4 x C2zPSL2(F5)G72zPGL2(F5)A6S6c                 C   s  | t jkrtdS | t jkr"t S | t jkr4tdS | t jkrDt S | t j	krTt	 S | t j
krdt
 S | t jkrtt S | t jkrt S | t jkrt S | t jkrt S | t jkrt S | t jkrt S | t jkrt S | t jk rt S | t jk rtdS | t jkrtdS d S )N   )r/   r0   r   r   S3_in_S6r1   r   r$   A4_in_S6r2   A4xC2S4mS4pG36mG36pS4xC2PSL2F5r3   PGL2F5r4   r   r5   r   r   r   r   r   r      s@    












z$S6TransitiveSubgroups.get_perm_groupN)r   r   r   r   r0   r   r1   r$   r2   r9   r:   r;   r<   r=   r>   r?   r3   r@   r4   r5   r   r   r   r   r   r/   v   s$   r/   c                   C   s"   t tddddtddddS )z]
    Return a representation of the Klein four-group as a transitive subgroup
    of S4.
    r   r   r   r   r
   r   r   r   r   r   r'      s    r'   c                  C   sN   t tdddddtdddd} d| _d| _d| _d	| _d	| _d	| _d	| _| S )
z
    Return a representation of the metacyclic group M20, a transitive subgroup
    of S5 that is one of the possible Galois groups for polys of degree 5.

    Notes
    =====

    See [1], Page 323.

    r   r   r   r   r&   r.      TF)	r
   r   Z_degree_orderZ_is_transitiveZ_is_symZ_is_altZ
_is_cyclicZ_is_dihedralGr   r   r   r+      s     r+   c                  C   s<   t tddddddtdddddd} t| dd | S )z
    Return a representation of S3 as a transitive subgroup of S6.

    Notes
    =====

    The representation is found by viewing the group as the symmetries of a
    triangular prism.

    r   r   r   r   r&   r.   r6   r
   r   r   rD   r   r   r   r7      s    ,r7   c                  C   s:   t tddddddtdddddd} t| dd | S )z
    Return a representation of A4 as a transitive subgroup of S6.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r&   r.   r   r   r   r6   r
   r   r	   rD   r   r   r   r8      s    
*r8   c                  C   s6   t tddddtdddddd} t| dd | S )z
    Return a representation of the S4- transitive subgroup of S6.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r&   r.   r   r   r   r6   rF   rD   r   r   r   r:      s    
&r:   c                  C   s6   t tddddddtdddd} t| dd | S )z
    Return a representation of the S4+ transitive subgroup of S6.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r   r&   r   r   r.   r6   rF   rD   r   r   r   r;      s    
&r;   c                   C   s6   t tddddddtddddddtdddS )z
    Return a representation of the (A4 x C2) transitive subgroup of S6.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r&   r.   r   r   r   rA   r   r   r   r   r9     s
    
 r9   c                   C   s4   t tddddtddddddtddddS )z
    Return a representation of the (S4 x C2) transitive subgroup of S6.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r&   r.   r   r   r   rA   r   r   r   r   r>     s
    
 r>   c                   C   s2   t tddddtdddtddddddS )z
    Return a representation of the group G18, a transitive subgroup of S6
    isomorphic to the semidirect product of C3^2 with C2.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r.   r   r   r   r   r&   rA   r   r   r   r   r2   *  s
     
r2   c                   C   s@   t tddddtdddtddddtddddddS )z
    Return a representation of the group G36-, a transitive subgroup of S6
    isomorphic to the semidirect product of C3^2 with C2^2.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r.   r   r   r   r   r&   rA   r   r   r   r   r<   :  s     
 r<   c                   C   s0   t tddddtdddtddddddS )z
    Return a representation of the group G36+, a transitive subgroup of S6
    isomorphic to the semidirect product of C3^2 with C4.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r.   r   r   r   r   r&   rA   r   r   r   r   r=   J  s
     
r=   c                   C   s:   t tddddtddddddtddddddS )z
    Return a representation of the group G72, a transitive subgroup of S6
    isomorphic to the semidirect product of C3^2 with D4.

    Notes
    =====

    See [1], Page 325.

    r.   r   r   r   r&   r   rA   r   r   r   r   r3   Z  s
     r3   c                  C   s6   t tddddddtddddd} t| dd | S )z
    Return a representation of the group $PSL_2(\mathbb{F}_5)$, as a transitive
    subgroup of S6, isomorphic to $A_5$.

    Notes
    =====

    This was computed using :py:func:`~.find_transitive_subgroups_of_S6`.

    r   r&   r.   r   r   r   r6   rG   rD   r   r   r   r?   j  s     r?   c                  C   s8   t tdddddtdddddd} t| dd | S )z
    Return a representation of the group $PGL_2(\mathbb{F}_5)$, as a transitive
    subgroup of S6, isomorphic to $S_5$.

    Notes
    =====

    See [1], Page 325.

    r   r   r   r   r&   r.   r6   rF   rD   r   r   r   r@   {  s     r@   F)print_reportc                    s  dd dfdd	t d}td |d fdd	dfd	d
	}i fdd}tj|ksvtj|kr|td}|tj| tj|kstj|kr|t ddd}|tj| tj|kr|t ddd}|tj| tj|kr|jdgdt dd}|tj| tj|kr@|jdgd}	|tj|	 t	ddddt	ddddg}
tj
|kr|
dgd}|tj
| tj|kr|
ddgddd}|tj| tj|kr܈|
dgddd}|tj| tj|kr|
ddgd}|tj| tj|kr(|td}|tj| tj|krL|t d}|tj| tj|krp|td}|tj| tj|kr|t d}|tj| tj|kr|td}|tj| tj|kr|  |tj  tj|kr||}|tj| S )a	  
    Search for certain transitive subgroups of $S_6$.

    The symmetric group $S_6$ has 16 different transitive subgroups, up to
    conjugacy. Some are more easily constructed than others. For example, the
    dihedral group $D_6$ is immediately found, but it is not at all obvious how
    to realize $S_4$ or $S_5$ *transitively* within $S_6$.

    In some cases there are well-known constructions that can be used. For
    example, $S_5$ is isomorphic to $PGL_2(\mathbb{F}_5)$, which acts in a
    natural way on the projective line $P^1(\mathbb{F}_5)$, a set of order 6.

    In absence of such special constructions however, we can simply search for
    generators. For example, transitive instances of $A_4$ and $S_4$ can be
    found within $S_6$ in this way.

    Once we are engaged in such searches, it may then be easier (if less
    elegant) to find even those groups like $S_5$ that do have special
    constructions, by mere search.

    This function locates generators for transitive instances in $S_6$ of the
    following subgroups:

    * $A_4$
    * $S_4^-$ ($S_4$ not contained within $A_6$)
    * $S_4^+$ ($S_4$ contained within $A_6$)
    * $A_4 \times C_2$
    * $S_4 \times C_2$
    * $G_{18}   = C_3^2 \rtimes C_2$
    * $G_{36}^- = C_3^2 \rtimes C_2^2$
    * $G_{36}^+ = C_3^2 \rtimes C_4$
    * $G_{72}   = C_3^2 \rtimes D_4$
    * $A_5$
    * $S_5$

    Note: Each of these groups also has a dedicated function in this module
    that returns the group immediately, using generators that were found by
    this search procedure.

    The search procedure serves as a record of how these generators were
    found. Also, due to randomness in the generation of the elements of
    permutation groups, it can be called again, in order to (probably) get
    different generators for the same groups.

    Parameters
    ==========

    targets : list of :py:class:`~.S6TransitiveSubgroups` values
        The groups you want to find.

    print_report : bool (default False)
        If True, print to stdout the generators found for each group.

    Returns
    =======

    dict
        mapping each name in *targets* to the :py:class:`~.PermutationGroup`
        that was found

    References
    ==========

    .. [2] https://en.wikipedia.org/wiki/Projective_linear_group#Exceptional_isomorphisms
    .. [3] https://en.wikipedia.org/wiki/Automorphisms_of_the_symmetric_and_alternating_groups#PGL(2,5)

    c                 S   s*   t t}| jD ]}||  | q|S )z-Sort the elements of a group by their order. )r   listelementsorderappend)rE   eltsgr   r   r   elts_by_order  s    
z6find_transitive_subgroups_of_S6.<locals>.elts_by_orderNc                    sP   | }dd |  D  |rLt| dd fddt  D    S )z8Determine how many elements a group has, of each order. c                 S   s   i | ]\}}|t |qS r   len).0oer   r   r   
<dictcomp>  s      zJfind_transitive_subgroups_of_S6.<locals>.order_profile.<locals>.<dictcomp>z:  c                 3   s$   | ]}t  |  d | V  qdS )@NrP   )rR   rprofiler   r   	<genexpr>  s     zIfind_transitive_subgroups_of_S6.<locals>.order_profile.<locals>.<genexpr>)itemsprintjoinsortedkeys)rE   namerM   )rO   rY   r   order_profile  s
    .z6find_transitive_subgroups_of_S6.<locals>.order_profiler6   c                    s   t jfdd|D  D ]}tt|t|k r2qt| t| }| |kr| r|dk	rn| |krnq|r||krq|r||krq|  S qdS )a  
        Find a transitive subgroup of S6.

        Parameters
        ==========

        existing_gens : list of Permutation
            Optionally empty list of generators that must be in the group.

        needed_gen_orders : list of positive int
            Nonempty list of the orders of the additional generators that are
            to be found.

        order: int
            The order of the group being sought.

        alt: bool, None
            If True, require the group to be contained in A6.
            If False, require the group not to be contained in A6.

        profile : dict
            If given, the group's order profile must equal this.

        anti_profile : dict
            If given, the group's order profile must *not* equal this.

        c                    s   g | ]} | qS r   r   )rR   n)S6_by_orderr   r   
<listcomp>  s     zCfind_transitive_subgroups_of_S6.<locals>.search.<locals>.<listcomp>N)		itertoolsproductrQ   setr
   rI   rK   Zis_transitiveZis_subgroup)Zexisting_gensZneeded_gen_ordersrK   altrZ   anti_profileZgensrE   )r4   rd   rb   r   r   search  s    z/find_transitive_subgroups_of_S6.<locals>.searchc                    s*   dd | j D }g ||  | | dS )Nc                 S   s   g | ]}|  qS r   )rK   )rR   rN   r   r   r   re     s     zNfind_transitive_subgroups_of_S6.<locals>.match_known_group.<locals>.<listcomp>)ri   rZ   )
generatorsrK   )rE   ri   needed)rb   rk   r   r   match_known_group  s    z:find_transitive_subgroups_of_S6.<locals>.match_known_groupc                    s0   | | < r,t d t |  d t |j d S )Nz(========================================:)r]   rl   )ra   rE   )foundrH   r   r   	finish_up  s
    z2find_transitive_subgroups_of_S6.<locals>.finish_upr&   F)ri   Tr      )rj   0   r.   r   r   r      $   H   )N)NNN)N)r   r   r/   r$   r9   r:   r>   r;   rl   r   r2   r<   r=   r3   r?   r@   r0   r   r   r1   r   r4   r5   )rH   targetsr5   rn   rq   r8   Z	S4m_in_S6Z	S4p_in_S6ZA4xC2_in_S6ZS4xC2_in_S6ZN_gensZ	G18_in_S6Z
G36m_in_S6Z
G36p_in_S6Z	G72_in_S6ZPSL2F5_in_S6ZPGL2F5_in_S6r0   r   r1   r   )r4   rd   rO   rp   rb   rH   rk   r   find_transitive_subgroups_of_S6  sv    D)
 rx   )&r   collectionsr   enumr   rf   Z sympy.combinatorics.named_groupsr   r   r   r   r   r	   Zsympy.combinatorics.perm_groupsr
   Z sympy.combinatorics.permutationsr   r   r   r   r    r(   r/   r'   r+   r7   r8   r:   r;   r9   r>   r2   r<   r=   r3   r?   r@   rx   r   r   r   r   <module>   s6    

8