Ë
    7^(hË#  ã                   óx   — 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y)é    )ÚchainÚcombinations)Úgcd)Ú	factorint)Úas_intÚfactorsÚreturnc                 ó¤   — | j                  «       D ]=  }| j                  «       D ](  \  }}d}t        |«      D ]  }||z  |z  }|dk(  sŒ   y Œ* Œ? y)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/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/combinatorics/group_numbers.pyÚ_is_nilpotent_numberr      sh   € ð �\‰\‹^ò !ˆØ—M‘M“Oò 	!‰DˆAˆqð ˆAÜ˜1“Xò !�Ø�a‘C˜!‘G�Ø˜“6Û ñ!ñ		!ð!ð ó    c                 óf   — 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      s4   € ô0 	ˆq‹	€AØˆA‚vÜÐ?À!ÑCÓDÐDÜ¤	¨!£Ó-Ð-r   c                 ó®   — t        | «      } | dk  rt        d| z  «      ‚t        | «      }t        d„ |j	                  «       D «       «      xr 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  –— Œ y­w)é   N© ©Ú.0r   s     r   ú	<genexpr>z$is_abelian_number.<locals>.<genexpr>V   s   è ø€ Ò/˜ˆq�1�uÑ/ùó   ‚©r   r   r   ÚallÚvaluesr   ©r   r   s     r   Úis_abelian_numberr(   8   sQ   € ô4 	ˆq‹	€AØˆA‚vÜÐ?À!ÑCÓDÐDÜ˜‹l€GÜÑ/˜gŸn™nÓ.Ô/Ó/ÒQÔ4HÈÓ4QÐQr   c                 ó®   — t        | «      } | dk  rt        d| z  «      ‚t        | «      }t        d„ |j	                  «       D «       «      xr 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(  –— Œ y­w©r   Nr   r    s     r   r"   z#is_cyclic_number.<locals>.<genexpr>w   s   è ø€ Ò0˜!ˆq�A�vÑ0ùr#   r$   r'   s     r   Úis_cyclic_numberr,   Y   sQ   € ô4 	ˆq‹	€AØˆA‚vÜÐ?À!ÑCÓDÐDÜ˜‹l€GÜÑ0˜wŸ~™~Ó/Ô0Ó0ÒRÔ5IÈ'Ó5RÐRr   c           	      ó–  ‡‡	— | D �‡ch c]  Št        ˆfd„| D «       «      sŒ‰’Œ }}| |z
  Š	d}t        j                  ˆ	fd„t        t	        ‰	«      dz   «      D «       «      }|D ]X  }t        |«      }d}‰	|z
  D ]<  Št	        ||z  D �cg c]  }|‰z  dk(  sŒ|‘Œ c}«      }|‰|z  dz
  ‰dz
  z  z  }|rŒ< n ||z  }ŒZ |S c c}w c c}w )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              3   ó.   •K  — | ]  }|‰z  d k7  –— Œ y­wr+   r   )r!   r   r   s     €r   r"   z"_holder_formula.<locals>.<genexpr>¹   s   øè ø€ Ò(K¸¨¨Q©°!­Ñ(Kùs   ƒr   c              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­w)N)r   )r!   ÚrÚMs     €r   r"   z"_holder_formula.<locals>.<genexpr>½   s   øè ø€ Ò"O¸!¤<°°1×#5Ñ"Oùs   ƒr   )r%   r   Úfrom_iterabler   ÚlenÚset)
Úprime_factorsr   ÚFÚsÚpowersetÚpsÚprodr   Úcr1   s
    `       @r   Ú_holder_formular<   z   sè   ù€ ð~ "×Lˆq¤SÓ(K¸]Ô(KÕ%KŠÐL€AÐLØ˜Ñ€Aà	€AÜ×"Ñ"Ó"O¼uÄSÈÃVÈAÁX»Ô"OÓO€HØò ˆÜ�‹WˆØˆØ�R‘ò 	ˆAÜ  B¡Ö5˜1¨!¨a©%°1«*’QÒ5Ó6ˆAØ�Q˜‘T˜A‘X 1 q¡5Ñ)Ñ)ˆDÚÙð		ð
 	
ˆT‰	‰ðð €Hùò 	Mùò 6s   ˆC¢CÂCÂCc           
      ój  — t        | «      } | dk  rt        d| z  «      ‚t        | «      }t        |«      dk(  �r°t	        |j                  «       «      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y|d	k(  ry
|dk(  r+dd|z  z   dt        |dz
  d«      z  z   t        |dz
  d	«      z   S |dk(  rJd|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y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„ |j                  «       D «       «      rTi 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(  r(t        |j                  «       «      \  }}||z  dk(  rdS dS t        t        |j                  «       «      «      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   r>   é   é   é3   i  i	  iÛ  i!  l   yLZ. r   )
r   r   r>   r?   é   éC   iø  i^$  imM l   ¥NÙC r?   é   rB   é=   é   é'   iX  é   é   é   iù…  é   é,   éª   iÃ  i—	  i#  é   é‡   é   é   é	   c              3   ó&   K  — | ]	  }|d kD  –— Œ y­wr+   r   r    s     r   r"   zgroups_count.<locals>.<genexpr>  s   è ø€ Ò
+�Qˆ1ˆq�5Ñ
+ùr#   é   é   é   é$   r@   é(   é-   é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   r3   Úlistr   r   Úanyr&   Úsortedr   r<   r4   )r   r   r   r   ÚA000679ÚA090091Úsmallr   s           r   Úgroups_countrr   Ê   s©  € ôd 	ˆq‹	€AØˆA‚vÜÐ?À!ÑCÓDÐDÜ˜‹l€GÜ
ˆ7ƒ|�qÓÜ�g—m‘m“oÓ& qÑ)‰ˆˆAØ�Š6ÚSˆGØ”3�w“<ÒØ˜q‘zÐ!Ø�Š6ÚJˆGØ”3�w“<ÒØ˜q‘zÐ!Ø�Š6ØˆHØ�Š6ØØ�Š6ØØ�Š6Ø˜˜!™‘8˜a¤ A a¡C¨£™mÑ+¬c°!°A±#°q«kÑ9Ð9Ø�Š6Ø�Q˜‘T‘6˜B˜q™D‘= 3Ñ&Ø”S˜˜1™˜a“[‘.ñ!Ø#%¤c¨!¨A©#¨q£k¡>ñ2Ø45´c¸!¸A¹#¸q³k±MñBð Bà�Š6Ø�AŠvØØ�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ô Ñ
+˜'Ÿ.™.Ó*Ô
+Ô+ð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ˆð �‰:Ø˜‘8ˆOÜÐTÓUÐUÜ
ˆ7ƒ|�qÒÜ�g—l‘l“nÓ%‰ˆˆ1Ø˜‘E˜Q’JˆqÐ% AÐ%Üœ3˜wŸ|™|›~Ó.Ó/Ð/r   N)Ú	itertoolsr   r   Úsympy.external.gmpyr   Úsympy.ntheory.factor_r   Úsympy.utilities.miscr   ÚdictÚboolr   r   r(   r,   r<   rr   r   r   r   ú<module>ry      s[   ðß )å #Ý +Ý 'ð $ð ¨4ó ð$.˜dó .ð<R˜Dó RðBS˜4ó SòBMó`\0r   