K i#xddlmZmZddlmZddlmZddlmZde de fdZ de fdZ de fd Z de fd Zd Zd Zy ))chain combinations)gcd) factorint)as_intfactorsreturnc|jD]=}|jD](\}}d}t|D]}||z|z}|dk(sy*?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)keysitemsrange)rpqem_s g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/combinatorics/group_numbers.py_is_nilpotent_numberrsh \\^!MMO !DAqA1X !aC!G6  !  !! cft|}|dkrtd|ztt|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 ValueErrorrr)ns ris_nilpotent_numberrs40 q AAv?!CDD  ! --rct|}|dkrtd|zt|}td|j Dxr 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 rrc3&K|] }|dk yw)N.0rs r z$is_abelian_number..Vs/q1u/rrrallvaluesrrrs ris_abelian_numberr(8sQ4 q AAv?!CDDlG /gnn./ / Q4H4QQrct|}|dkrtd|zt|}td|j Dxr 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 rrc3&K|] }|dk( ywr Nrr s rr"z#is_cyclic_number..ws0!qAv0r#r$r's ris_cyclic_numberr,YsQ4 q AAv?!CDDlG 0w~~/0 0 R5I'5RRrc  |Dchc]tfd|Ds}}||z d}tj fdtt dzD}|D]X}t |}d} |z D]<t ||zDcgc] }|zdk(s |c}}||zdz dz zz}|r<n||z }Z|Scc}wcc}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 c3.K|] }|zdk7ywr+r)r!rrs rr"z"_holder_formula..s(KQ!(Ksrc36K|]}t|yw)N)r)r!rMs rr"z"_holder_formula..s"O!<1#5"Osr )r%r from_iterablerlenset) prime_factorsrFspowersetpsprodrcr1s ` @r_holder_formular<zs~"LqS(K](K%KLALA A"""OuSVAX"OOH WR AB51!a%1*Q56A QTAX1q5) )D   T  H M6sCC C C c jt|}|dkrtd|zt|}t|dk(rt |j d\}}|dk(rgd}|t|kr||S|dk(rgd}|t|kr||S|dkr|S|dk(ry|d k(ry |dk(r+d d|zzdt |dz dzzt |dz d zS|d k(rJd|dzzd |zzdzdt |dz dzzdt |dz d zzdt |dz dzzS|dk(r|dk(ryd|dzzd|d zzzd|dzzzd|dzzzd|zzdzd |dzzd|zzdzt |dz dzz|dzd|zzdzt |dz d zzd|zdzt |dz dzzd t |dz dzzdt |dz dzzt |dz dzStd|jDrTiddddd ddd d!d d"d#d$d#dd d%dd&d'd(dd'dd)d d*d+d,d+d-d d.dd(dd d'd dd/d d0}||vr||Std1t|dk(r(t|j\}}||zdk(rdSdStt|jS)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 rrr ) r r r>3i i ii!lyLZ .r) r r r>r?Cii^$imMlNCr?rB='iX i ,ii i# c3&K|] }|dkD ywr+rr s rr"zgroups_count..s +Q1q5 +r#$r@(-04268 <?D )HKLPTXZ\z9Number of groups of order n is unknown or not implemented) rrrr3listr ranyr&sortedr r<r4)rrrrA000679A090091smallrs r groups_countrrsd q AAv?!CDDlG 7|qgmmo&q)A 6SG3w<qz! 6JG3w<qz! 6H 6 6 6!8aAaC m+c!A#qk9 9 6QT6BqD=3&S1a[.!#%c!A#qk>245c!A#qkMB B 6AvQT6Bq!tG#bAg-AqD83q5@4GQT6BqD=3&AaC 3478!tbd{S7H#aPQcST+6UVQ38S1a[()+,S1a[=9;rys[)#+'$4$.d.<RDRBS4SBM `\0r