Skip to content

Commit 4935e12

Browse files
committed
reviewer feedback
1 parent 2c9908c commit 4935e12

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/sage/combinat/q_analogues.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,20 +1031,38 @@ def number_of_irreducible_polynomials(n, q=None, m=1):
10311031
n = ZZ(n)
10321032
if n <= 0:
10331033
raise ValueError('n must be positive')
1034+
if m <= 0:
1035+
raise ValueError('m must be positive')
1036+
10341037
if q is None:
10351038
from sage.rings.rational_field import QQ
1036-
q = QQ['q'].gen() # for m > 1, we produce an integer-valued polynomial in q, but it does not necessarily have integer coefficients
1037-
R = parent(q)
1039+
q = QQ['q'].gen() # we produce an integer-valued polynomial in q, but it does not necessarily have integer coefficients
1040+
10381041
if m == 1:
10391042
from sage.arith.misc import moebius
1040-
r = sum((moebius(n//d) * q**d for d in n.divisors()), R.zero())
1043+
r = sum((moebius(n//d) * q**d for d in n.divisors()), parent(q).zero())
10411044
return r // n
1042-
elif m > 1:
1043-
from sage.functions.other import binomial
1044-
from sage.combinat.partition import Partitions
1045-
r = []
1046-
for d in range(n):
1047-
r.append( (q**binomial(d+m,m-1) - 1) // (q-1) * q**binomial(d+m,m) - sum(prod(binomial(r_+t-1,t) for r_,t in zip(r,p.to_exp(d))) for p in Partitions(d+1,max_part=d)) )
1048-
return r[-1]
1049-
else:
1050-
raise ValueError('m must be positive')
1045+
1046+
from sage.functions.other import binomial
1047+
from sage.combinat.partition import Partitions
1048+
1049+
def monic_reducible(irreducible, d):
1050+
"""
1051+
Compute the number of monic reducible polynomials of degree `d`
1052+
given the numbers of irreducible polynomials up to degree `d-1`.
1053+
"""
1054+
res = 0
1055+
for p in Partitions(d+1, max_part=d):
1056+
tmp = 1
1057+
for r, t in zip(irreducible, p.to_exp(d)):
1058+
tmp *= binomial(r+t-1, t)
1059+
res += tmp
1060+
return res
1061+
1062+
r = []
1063+
for d in range(n):
1064+
monic = (q**binomial(d + m, m - 1) - 1) * q**binomial(d + m, m) // (q - 1)
1065+
reducible = monic_reducible(r, d)
1066+
r.append(monic - reducible)
1067+
1068+
return r[-1]

0 commit comments

Comments
 (0)