
    g#                     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/ai-engine/env/lib/python3.11/site-packages/sympy/combinatorics/group_numbers.py_is_nilpotent_numberr      s     \\^^ ! !MMOO 	! 	!DAq A1XX ! !aC!G66 5555 !		! 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Avv?!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&      //q1u//////r   r   r   r   allvaluesr   r   r   s     r   is_abelian_numberr'   8   sl    4 	q		AAvv?!CDDDllG//gnn../////Q4H4Q4Q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!qAv000000r   r#   r&   s     r   is_cyclic_numberr+   Y   sl    4 	q		AAvv?!CDDDllG00w~~//00000R5I'5R5R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LqS(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51!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LMLLLAA	A""O"O"O"OuSVVAX"O"O"OOOH  WWR 	 	A5555B55566AQTAX1q5))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    r;t	          |	                                          \  }}||k    r||}}||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(12) is known to be 5,
        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   NC 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&      
+
+Q1q5
+
+
+
+
+
+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%   r   r@   r9   )r   r   r   r   A000679A090091smallr   s           r   groups_countru      sI   d 	q		AAvv?!CDDDllG
7||qgmmoo&&q)A66SSSG3w<<qz!66JJJG3w<<qz!66H66166266!8aAaCm+c!A#qkk9966QT6BqD=3&S1a[[.!#%c!A#qkk>245c!A#qkkMB B66AvvuQT6Bq!tG#bAg-AqD83q5@4GQT6BqD=3&AaC3478!tbd{S7H#aPQcST++6UVQ38S1a[[()+,S1a[[=9;<S1a[[=IKNqQRsTU;;W W 
+
+'..**
+
+
+++ V7Q 7A 7r1 7b" 7b! 7R 7R 7R 7BPQ 7SUWY 7A717 "7&("7.0"768!7=?7HJPQWXBBBA7 7 7 ::8OTUUU
7||qGLLNN##1q55aqAEQJJqqA%3w||~~..///r   N)	itertoolsr   r   sympy.external.gmpyr   sympy.ntheory.factor_r   sympy.utilities.miscr   dictboolr   r   r'   r+   r@   ru   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   