§
    OŠtjË#  ã                   óz   — d dl mZmZ d dlmZ d dlmZ d dlmZ de	de
fd„Zde
fd„Zde
fd	„Zde
fd
„Zd„ Zd„ ZdS )é    )ÚchainÚcombinations)Úgcd)Ú	factorint)Úas_intÚfactorsÚreturnc                 ó¶   — |                       ¦   «         D ]C}|                      ¦   «         D ],\  }}d}t          |¦  «        D ]}||z  |z  }|dk    r   dS ŒŒ-ŒDdS )z¸ Check whether `n` is a nilpotent number.
    Note that ``factors`` is a prime factorization of `n`.

    This is a low-level helper for ``is_nilpotent_number``, for internal use.
    é   FT)ÚkeysÚitemsÚrange)r   ÚpÚqÚeÚmÚ_s         ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/combinatorics/group_numbers.pyÚ_is_nilpotent_numberr      s‰   € ð �\Š\‰^Œ^ð !ð !ˆØ—M’M‘O”Oð 	!ð 	!‰DˆAˆqð ˆAÝ˜1‘X”Xð !ð !�Ø�a‘C˜!‘G�Ø˜’6�6Ø ˜5˜5˜5˜5ð ð!ð		!ð ˆ4ó    c                 óˆ   — t          | ¦  «        } | dk    rt          d| z  ¦  «        ‚t          t          | ¦  «        ¦  «        S )aj  
    Check whether `n` is a nilpotent number. A number `n` is said to be
    nilpotent if and only if every finite group of order `n` is nilpotent.
    For more information see [1]_.

    Examples
    ========

    >>> from sympy.combinatorics.group_numbers import is_nilpotent_number
    >>> from sympy import randprime
    >>> is_nilpotent_number(21)
    False
    >>> is_nilpotent_number(randprime(1, 30)**12)
    True

    References
    ==========

    .. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers,
           The American Mathematical Monthly, 107(7), 631-634.
    .. [2] https://oeis.org/A056867

    r   ú$n must be a positive integer, not %i)r   Ú
ValueErrorr   r   )Úns    r   Úis_nilpotent_numberr      s@   € õ0 	ˆq‰	Œ	€AØˆA‚v€vÝÐ?À!ÑCÑDÔDÐDÝ¥	¨!¡¤Ñ-Ô-Ð-r   c                 óâ   — t          | ¦  «        } | dk    rt          d| z  ¦  «        ‚t          | ¦  «        }t          d„ |                     ¦   «         D ¦   «         ¦  «        ot          |¦  «        S )a†  
    Check whether `n` is an abelian number. A number `n` is said to be abelian
    if and only if every finite group of order `n` is abelian. For more
    information see [1]_.

    Examples
    ========

    >>> from sympy.combinatorics.group_numbers import is_abelian_number
    >>> from sympy import randprime
    >>> is_abelian_number(4)
    True
    >>> is_abelian_number(randprime(1, 2000)**2)
    True
    >>> is_abelian_number(60)
    False

    References
    ==========

    .. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers,
           The American Mathematical Monthly, 107(7), 631-634.
    .. [2] https://oeis.org/A051532

    r   r   c              3   ó"   K  — | ]
}|d k     V — ŒdS )é   N© ©Ú.0r   s     r   ú	<genexpr>z$is_abelian_number.<locals>.<genexpr>V   s&   è è € Ð/Ð/˜ˆq�1ŠuÐ/Ð/Ð/Ð/Ð/Ð/r   ©r   r   r   ÚallÚvaluesr   ©r   r   s     r   Úis_abelian_numberr'   8   sl   € õ4 	ˆq‰	Œ	€AØˆA‚v€vÝÐ?À!ÑCÑDÔDÐDÝ˜‰lŒl€GÝÐ/Ð/˜gŸnšnÑ.Ô.Ð/Ñ/Ô/Ñ/Ô/ÐQÕ4HÈÑ4QÔ4QÐQr   c                 óâ   — t          | ¦  «        } | dk    rt          d| z  ¦  «        ‚t          | ¦  «        }t          d„ |                     ¦   «         D ¦   «         ¦  «        ot          |¦  «        S )a  
    Check whether `n` is a cyclic number. A number `n` is said to be cyclic
    if and only if every finite group of order `n` is cyclic. For more
    information see [1]_.

    Examples
    ========

    >>> from sympy.combinatorics.group_numbers import is_cyclic_number
    >>> from sympy import randprime
    >>> is_cyclic_number(15)
    True
    >>> is_cyclic_number(randprime(1, 2000)**2)
    False
    >>> is_cyclic_number(4)
    False

    References
    ==========

    .. [1] Pakianathan, J., Shankar, K., Nilpotent Numbers,
           The American Mathematical Monthly, 107(7), 631-634.
    .. [2] https://oeis.org/A003277

    r   r   c              3   ó"   K  — | ]
}|d k    V — ŒdS ©r   Nr   r    s     r   r"   z#is_cyclic_number.<locals>.<genexpr>w   s&   è è € Ð0Ð0˜!ˆq�AŠvÐ0Ð0Ð0Ð0Ð0Ð0r   r#   r&   s     r   Úis_cyclic_numberr+   Y   sl   € õ4 	ˆq‰	Œ	€AØˆA‚v€vÝÐ?À!ÑCÑDÔDÐDÝ˜‰lŒl€GÝÐ0Ð0˜wŸ~š~Ñ/Ô/Ð0Ñ0Ô0Ñ0Ô0ÐRÕ5IÈ'Ñ5RÔ5RÐRr   c                 ó\  ‡ ‡‡— ˆ fd„‰ D ¦   «         }‰ |z
  Šd}t          j        ˆfd„t          t          ‰¦  «        dz   ¦  «        D ¦   «         ¦  «        }|D ]S}t	          |¦  «        }d}‰|z
  D ]5Št          ˆfd„||z  D ¦   «         ¦  «        }|‰|z  dz
  ‰dz
  z  z  }|s nŒ6||z  }ŒT|S )a|   Number of groups of order `n`.
    where `n` is squarefree and its prime factors are ``prime_factors``.
    i.e., ``n == math.prod(prime_factors)``

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

    When `n` is squarefree, the number of groups of order `n` is expressed by

    .. math ::
        \sum_{d \mid n} \prod_p \frac{p^{c(p, d)} - 1}{p - 1}

    where `n=de`, `p` is the prime factor of `e`,
    and `c(p, d)` is the number of prime factors `q` of `d` such that `q \equiv 1 \pmod{p}` [2]_.

    The formula is elegant, but can be improved when implemented as an algorithm.
    Since `n` is assumed to be squarefree, the divisor `d` of `n` can be identified with the power set of prime factors.
    We let `N` be the set of prime factors of `n`.
    `F = \{p \in N : \forall q \in N, q \not\equiv 1 \pmod{p} \}, M = N \setminus F`, we have the following.

    .. math ::
        \sum_{d \in 2^{M}} \prod_{p \in M \setminus d} \frac{p^{c(p, F \cup d)} - 1}{p - 1}

    Practically, many prime factors are expected to be members of `F`, thus reducing computation time.

    Parameters
    ==========

    prime_factors : set
        The set of prime factors of ``n``. where `n` is squarefree.

    Returns
    =======

    int : Number of groups of order ``n``

    Examples
    ========

    >>> from sympy.combinatorics.group_numbers import _holder_formula
    >>> _holder_formula({2}) # n = 2
    1
    >>> _holder_formula({2, 3}) # n = 2*3 = 6
    2

    See Also
    ========

    groups_count

    References
    ==========

    .. [1] Otto Holder, Die Gruppen der Ordnungen p^3, pq^2, pqr, p^4,
           Math. Ann. 43 pp. 301-412 (1893).
           http://dx.doi.org/10.1007/BF01443651
    .. [2] John H. Conway, Heiko Dietrich and E.A. O'Brien,
           Counting groups: gnus, moas and other exotica
           The Mathematical Intelligencer 30, 6-15 (2008)
           https://doi.org/10.1007/BF02985731

    c                 óL   •‡— h | ]Št          ˆfd „‰D ¦   «         ¦  «        ¯‰’Œ S )c              3   ó*   •K  — | ]}|‰z  d k    V — ŒdS r*   r   ©r!   r   r   s     €r   r"   z,_holder_formula.<locals>.<setcomp>.<genexpr>¹   s+   øè è € Ð(KÐ(K¸¨¨Q©°!ªÐ(KÐ(KÐ(KÐ(KÐ(KÐ(Kr   )r$   )r!   r   Úprime_factorss    @€r   ú	<setcomp>z"_holder_formula.<locals>.<setcomp>¹   s<   øø€ ÐLÐLÐLˆq¥SÐ(KÐ(KÐ(KÐ(K¸]Ð(KÑ(KÔ(KÑ%KÔ%KÐLˆÐLÐLÐLr   r   c              3   ó8   •K  — | ]}t          ‰|¦  «        V — Œd S )N)r   )r!   ÚrÚMs     €r   r"   z"_holder_formula.<locals>.<genexpr>½   s-   øè è € Ð"OÐ"O¸!¥<°°1Ñ#5Ô#5Ð"OÐ"OÐ"OÐ"OÐ"OÐ"Or   r   c                 ó&   •— g | ]}|‰z  d k    ¯|‘ŒS )r   r   r/   s     €r   ú
<listcomp>z#_holder_formula.<locals>.<listcomp>Â   s"   ø€ Ð5Ð5Ð5˜1¨!¨a©%°1ª*¨*�Q¨*¨*¨*r   )r   Úfrom_iterabler   ÚlenÚset)	r0   ÚFÚsÚpowersetÚpsÚprodÚcr4   r   s	   `      @@r   Ú_holder_formular@   z   sû   øøø€ ð~ 	MÐLÐLÐL�MÐLÑLÔL€AØ˜Ñ€Aà	€AÝÔ"Ð"OÐ"OÐ"OÐ"O½uÅSÈÁVÄVÈAÁX¹¼Ð"OÑ"OÔ"OÑOÔO€HØð ð ˆÝ�‰WŒWˆØˆØ�R‘ð 	ð 	ˆAÝÐ5Ð5Ð5Ð5  B¡Ð5Ñ5Ô5Ñ6Ô6ˆAØ�Q˜‘T˜A‘X 1 q¡5Ñ)Ñ)ˆDØð Ø�ðà	ˆT‰	ˆˆØ€Hr   c           
      óŒ  — t          | ¦  «        } | dk    rt          d| z  ¦  «        ‚t          | ¦  «        }t          |¦  «        dk    �rt	          |                     ¦   «         ¦  «        d         \  }}|dk    rg d¢}|t          |¦  «        k     r||         S |dk    rg d¢}|t          |¦  «        k     r||         S |dk    r|S |dk    rdS |d	k    rd
S |dk    r3dd|z  z   dt          |dz
  d¦  «        z  z   t          |dz
  d	¦  «        z   S |dk    rVd|dz  z  d|z  z   dz   dt          |dz
  d¦  «        z  z   dt          |dz
  d	¦  «        z  z   dt          |dz
  d¦  «        z  z   S |dk    rÜ|dk    rdS d|dz  z  d|d	z  z  z   d|dz  z  z   d|dz  z  z   d|z  z   dz   d	|dz  z  d|z  z   dz   t          |dz
  d¦  «        z  z   |dz  d|z  z   dz   t          |dz
  d	¦  «        z  z   d|z  dz   t          |dz
  d¦  «        z  z   d	t          |dz
  d¦  «        z  z   dt          |dz
  d¦  «        z  z   t          |dz
  d¦  «        z   S t          d„ |                     ¦   «         D ¦   «         ¦  «        r[i dd“dd“d d“dd
“d!d	“d"d#“d$d#“dd	“d%d“d&d'“d(d“d'd“d)d
“d*d+“d,d+“d-d	“d.d“d(dd	d'd
dd/d	d0œ¥}| |v r||          S t          d1¦  «        ‚t          |¦  «        dk    r1t          | 
                    ¦   «         ¦  «        \  }}||z  dk    rdndS t          t          | 
                    ¦   «         ¦  «        ¦  «        S )2až   Number of groups of order `n`.
    In [1]_, ``gnu(n)`` is given, so we follow this notation here as well.

    Parameters
    ==========

    n : Integer
        ``n`` is a positive integer

    Returns
    =======

    int : ``gnu(n)``

    Raises
    ======

    ValueError
        Number of groups of order ``n`` is unknown or not implemented.
        For example, gnu(`2^{11}`) is not yet known.
        On the other hand, gnu(99) is known to be 2,
        but this has not yet been implemented in this function.

    Examples
    ========

    >>> from sympy.combinatorics.group_numbers import groups_count
    >>> groups_count(3) # There is only one cyclic group of order 3
    1
    >>> # There are two groups of order 10: the cyclic group and the dihedral group
    >>> groups_count(10)
    2

    See Also
    ========

    is_cyclic_number
        `n` is cyclic iff gnu(n) = 1

    References
    ==========

    .. [1] John H. Conway, Heiko Dietrich and E.A. O'Brien,
           Counting groups: gnus, moas and other exotica
           The Mathematical Intelligencer 30, 6-15 (2008)
           https://doi.org/10.1007/BF02985731
    .. [2] https://oeis.org/A000001

    r   r   r   é   )r   r   rB   é   é   é3   i  i	  iÛ  i!  l   yLZ. r   )
r   r   rB   rC   é   éC   iø  i^$  imM l   ¥NÙC rC   é   rF   é=   é   é'   iX  é   é   é   iù…  é   é,   éª   iÃ  i—	  i#  é   é‡   é   é   é	   c              3   ó"   K  — | ]
}|d k    V — ŒdS r*   r   r    s     r   r"   zgroups_count.<locals>.<genexpr>  s&   è è € Ð
+Ð
+�Qˆ1ˆqŠ5Ð
+Ð
+Ð
+Ð
+Ð
+Ð
+r   é   é   é   é$   rD   é(   é-   é0   é4   é2   é6   é8   é   é<   é?   éD   é
   )éH   éK   éL   éP   éT   éX   éZ   é\   z9Number of groups of order n is unknown or not implemented)r   r   r   r8   Úlistr   r   Úanyr%   Úsortedr   r@   r9   )r   r   r   r   ÚA000679ÚA090091Úsmallr   s           r   Úgroups_countrv   Ê   s7  € õd 	ˆq‰	Œ	€AØˆA‚v€vÝÐ?À!ÑCÑDÔDÐDÝ˜‰lŒl€GÝ
ˆ7�|„|�qÒÑÝ�g—m’m‘o”oÑ&Ô& qÔ)‰ˆˆAØ�Š6ˆ6ØSÐSÐSˆGØ•3�w‘<”<ÒÐØ˜q”zÐ!Ø�Š6ˆ6ØJÐJÐJˆGØ•3�w‘<”<ÒÐØ˜q”zÐ!Ø�Š6ˆ6ØˆHØ�Š6ˆ6Ø�1Ø�Š6ˆ6Ø�2Ø�Š6ˆ6Ø˜˜!™‘8˜a¥ A a¡C¨¡¤™mÑ+­c°!°A±#°q©k¬kÑ9Ð9Ø�Š6ˆ6Ø�Q˜‘T‘6˜B˜q™D‘= 3Ñ&Ø•S˜˜1™˜a‘[”[‘.ñ!Ø#%¥c¨!¨A©#¨q¡k¤k¡>ñ2Ø45µc¸!¸A¹#¸q±k´k±MñBð Bà�Š6ˆ6Ø�AŠvˆvØ�uØ�Q˜‘T‘6˜B˜q !™t™GÑ# b¨¨A©¡gÑ-°°A°q±D±Ñ8¸3¸q¹5Ñ@À4ÑGØ�Q˜‘T‘6˜B˜q™D‘= 3Ñ&­¨A¨a©C°©¬Ñ3ñ4Ø78¸!±t¸bÀ¹d±{ÀSÑ7HÍ#ÈaÐPQÉcÐSTÉ+Ì+Ñ6UñVà�Q‘3˜‘8�S  1¡ a™[œ[Ñ(ñ)à+,­S°°1±°a©[¬[©=ñ9à;<½SÀÀ1ÁÀa¹[¼[¹=ñIåKNÈqÐQRÉsÐTUÉ;Ì;ñWð Wõ Ð
+Ð
+˜'Ÿ.š.Ñ*Ô*Ð
+Ñ
+Ô
+Ñ+Ô+ð Vð7��Qð 7˜˜Að 7˜r 1ð 7 b¨"ð 7¨b°!ð 7°R¸ð 7¸RÀð 7ÀRÈð 7ÈBÐPQð 7ÐSUÐWYð 7Ø�Að7Ø˜1ð7Ø  "ð7Ø&(¨"ð7Ø.0°"ð7Ø68¸!ð7Ø=?Àð7ØHJÐPQÐWXØ˜B B¨B°Að7ð 7ð 7ˆð �ˆ:ˆ:Ø˜”8ˆOÝÐTÑUÔUÐUÝ
ˆ7�|„|�qÒÐÝ�g—l’l‘n”nÑ%Ô%‰ˆˆ1Ø˜‘E˜Q’J�Jˆqˆq AÐ%Ý�3˜wŸ|š|™~œ~Ñ.Ô.Ñ/Ô/Ð/r   N)Ú	itertoolsr   r   Úsympy.external.gmpyr   Úsympy.ntheory.factor_r   Úsympy.utilities.miscr   ÚdictÚboolr   r   r'   r+   r@   rv   r   r   r   ú<module>r}      s  ðØ )Ð )Ð )Ð )Ð )Ð )Ð )Ð )à #Ð #Ð #Ð #Ð #Ð #Ø +Ð +Ð +Ð +Ð +Ð +Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'ð $ð ¨4ð ð ð ð ð$.˜dð .ð .ð .ð .ð<R˜Dð Rð Rð Rð RðBS˜4ð Sð Sð Sð SðBMð Mð Mð`\0ð \0ð \0ð \0ð \0r   