@@ -1031,20 +1031,38 @@ def number_of_irreducible_polynomials(n, q=None, m=1):
1031
1031
n = ZZ (n )
1032
1032
if n <= 0 :
1033
1033
raise ValueError ('n must be positive' )
1034
+ if m <= 0 :
1035
+ raise ValueError ('m must be positive' )
1036
+
1034
1037
if q is None :
1035
1038
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
+
1038
1041
if m == 1 :
1039
1042
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 ())
1041
1044
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