Skip to content

Commit 4a4b9c9

Browse files
committed
add simple function to count irreducible polynomials over đť”˝q
1 parent ccc11b6 commit 4a4b9c9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎src/sage/arith/all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
prime_factors,
8282
prime_range,
8383
valuation,
84+
number_of_irreducible_polynomials,
8485
)
8586

8687
lazy_import("sage.arith.misc", ("Sigma", "Moebius", "Euler_Phi"), deprecation=30322)

‎src/sage/arith/misc.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6383,3 +6383,40 @@ def dedekind_psi(N):
63836383
"""
63846384
N = Integer(N)
63856385
return Integer(N * prod(1 + 1 / p for p in N.prime_divisors()))
6386+
6387+
6388+
def number_of_irreducible_polynomials(q, n):
6389+
r"""
6390+
Return the number of irreducible polynomials of degree ``n``
6391+
over the finite field with ``q`` elements.
6392+
6393+
INPUT:
6394+
6395+
- ``q`` -- prime power
6396+
- ``n`` -- positive integer
6397+
6398+
OUTPUT: integer
6399+
6400+
EXAMPLES::
6401+
6402+
sage: number_of_irreducible_polynomials(2, 8)
6403+
30
6404+
sage: number_of_irreducible_polynomials(9, 9)
6405+
43046640
6406+
6407+
This function is *much* faster than enumerating the polynomials::
6408+
6409+
sage: num = number_of_irreducible_polynomials(101, 99)
6410+
sage: num.bit_length()
6411+
653
6412+
6413+
ALGORITHM:
6414+
6415+
Classical formula `\frac1n \sum_{d\mid n} \mu(n/d) q^d` using the
6416+
Möbius function `\mu`; see :func:`moebius`.
6417+
"""
6418+
q, n = ZZ(q), ZZ(n)
6419+
r = ZZ.zero()
6420+
for d in n.divisors():
6421+
r += moebius(n//d) * q**d
6422+
return r // n

0 commit comments

Comments
 (0)