NTL.jl / complete manual
Version 0.14.0 · Julia 1.9+ · Pure Julia · Offline reference

Exact arithmetic, documented from first construction to verification

The complete NTL.jl manual.

The full project README, expanded field / polynomial / lattice / storage / runtime interfaces, exact verification, optional FLINT integration, random-prime comparisons, and an executable call for every exported interface.

  • Verified4,648,706 passing assertions plus 538 optional checks on Julia 1.11.7
  • Coverage176 exported names demonstrated in one API tour
  • IncludedREADME + expanded API index + full tour source
Prime fields and big modular rings
using NTL

F = PrimeField(101)
a = F(120)       # Machine-word prime field

p = big(2)^127 - 1
R = BigModRing(p)
b = R(big(2)^130 + 123)  # BigInt arithmetic

@assert a isa PrimeField
@assert b isa ModInt
@assert rep(a) == 19
@assert a * inv(a) == one(F)
@assert b * inv(b) == one(R)

NTL.jl

A pure-Julia toolkit for exact finite-field arithmetic, number theory, polynomial computation, extension fields, exact linear algebra, generalized FFT, and lattice reduction.

NTL.jl is inspired by C++ NTL, but it is not a wrapper or an API clone. It is designed to be approachable for new Julia users while providing efficient, tested implementations for research and teaching.

Version: 0.14.0
Tested with: Julia 1.11.7
Compatibility target: Julia 1.9+

Contents

Why NTL.jl?

NTL.jl offers a coherent set of exact-mathematics tools rather than a loose collection of types.

  • Pure Julia: no C++ compiler, NTL installation, binary artifact, or external Julia package is required for core functionality.
  • Exact arithmetic: canonical residues, BigInt coefficients, exact polynomial operations, and verifiable lattice transformations.
  • Beginner-friendly parents: PrimeField{p} stores a prime modulus in the type, while BigModRing and extension fields use explicit runtime parents.
  • Fast when appropriate: machine-word multiplication, Karatsuba, generalized FFT, Zech discrete-log tables, and fast LLL with exact verification.
  • Safe fallbacks: original schoolbook multiplication and exact LLL remain available. Fast paths never change mathematical results.
  • Tested invariants: arithmetic is checked against independent BigInt calculations, polynomial identities, factor reconstruction, matrix identities, LLL conditions, and direct convolution.

The package includes more than finite fields. It also supports integer factorization, modular square roots, discrete logarithms, primitive roots, polynomial factorization, matrices, NTT, and LLL.

Installation

From a local checkout

using Pkg
Pkg.develop(path = "/path/to/NTLJulia")
using NTL

Replace /path/to/NTLJulia with the directory that contains Project.toml.

Run the complete test suite

julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.test()'

The current suite contains 4,648,706 passing assertions, plus 538 optional third-party checks where available. Runtime code depends only on Julia’s Random standard library; Test is used only by the test target.

HTML documentation

Open docs/index.html in a browser. The documentation is self-contained and can be read offline.

A five-minute start

1. Create and use a prime field

using NTL

F = PrimeField(101)        # F is PrimeField{101}
a = F(120)          # 120 mod 101 = 19
b = F(-1)           # -1 mod 101 = 100

println(a + b)      # PrimeField{101}(18)
println(a * b)      # PrimeField{101}(82)
println(a / b)      # division in F_101
println(a^-1)       # inverse using gcdx and sign correction
println(a^1000)     # fast binary power

@assert rep(a) == 19
@assert Int(a) == 19
@assert modulus(a) == 101
@assert characteristic(F) == 101
@assert a * inv(a) == one(F)
@assert zero(F) == F(0)
@assert one(F) == F(1)

Every field element stores a canonical representative in 0:p-1.

2. Iterate over a small field

for x in PrimeField{5}
    println(x)
end

@assert length(PrimeField{5}) == 5
@assert collect(PrimeField{5}) == PrimeField{5}.([0, 1, 2, 3, 4])

Elements are produced in canonical order, from 0 through p-1. Iteration is lazy; collect(F) allocates all p elements and should not be used for a very large field.

3. Multiply two polynomials

F = PrimeField(101)
x = xpoly(F)

f = x^3 + 2x + 1
g = x^2 + 3x + 2

@assert poly_mul(f, g) == f * g
@assert poly_mul(f, g; method = :schoolbook) == f * g
@assert poly_mul(f, g; method = :karatsuba) == f * g
@assert poly_mul(f, g; method = :fft) == f * g

Coefficients are stored from low degree to high degree. The zero polynomial has degree -1.

4. Solve a finite-field linear system

F = PrimeField(101)
A = F.([2 3 1; 4 1 5; 3 7 2])
b = F.([1, 2, 3])

x = solve(A, b)
@assert A * x == b

@assert det(A) != 0
@assert A * matrix_inverse(A) == F.([1 0 0; 0 1 0; 0 0 1])

5. Reduce an integer lattice basis

A = BigInt[1 1 1; -1 0 2; 3 5 6]
result = lll(A)  # fast by default, with exact verification

@assert result.transform * A == result.basis
@assert abs(det_exact(result.transform)) == 1
@assert result.verified

Choosing the right field

Need Recommended parent Why
Fast prime-field arithmetic with an Int modulus PrimeField(p) Type-level modulus, canonical Int representation, field iteration
Arbitrary-precision modulus, including a composite one BigModRing(n) BigInt representation and explicit runtime parent
Binary field arithmetic GF2 XOR/AND arithmetic and bit-packed polynomials
General polynomial extension extension_field(F, m) Polynomial quotient F[x]/(m)
Frequent arithmetic in a small extension zech_field(E) Discrete-log multiplication, inversion, and powers

PrimeField versus BigModRing

using Test

F = PrimeField(101)             # Machine-word prime field
R = BigModRing(12)          # Arbitrary-precision modular ring

@assert R(5) * R(5) == R(1)
@test_throws DomainError inv(R(6))

PrimeField deliberately requires a prime modulus. BigModRing also permits composite moduli, but only units are invertible.

The modular-ring interface has two primary names with distinct roles:

  • BigModRing(n) constructs a reusable parent of type BigModRing;
  • ModInt is the element type. Prefer R(a) for ordinary construction and use ModInt(R, a) when an explicit type spelling is helpful.
R = BigModRing(12)
a = R(17)

@assert R isa BigModRing
@assert a isa ModInt
@assert a == R(5)
@assert rep(a) == 5
@assert ModInt(R, 17) == a

The public interface uses only the canonical names shown above. Legacy capitalization aliases have been removed in version 0.12.0, so new readers do not need to distinguish names that differ only by capitalization.

Everyday operations

Construction and metadata

F = PrimeField(97)
a = F(-3)

rep(a)              # 94
Int(a)              # 94
modulus(a)          # 97
characteristic(a)   # 97
parent(a)           # PrimeField{97}
zero(a)             # PrimeField{97}(0)
one(a)              # PrimeField{97}(1)
iszero(a)           # false
isone(a)            # false

Arithmetic

x + y
x - y
-x
x * y
x / y
inv(x)
x^e

Mixed integer arithmetic is reduced automatically:

@assert F(3) + 100 == F(0)
@assert 2F(3) == F(6)
@assert F(3) * big(8) == F(3)

Random elements and vectors

using Random

rng = MersenneTwister(2026)
a = rand(rng, F)
v = rand(rng, F, 10)
w = VectorRandom(F, 4; rng = rng)
c = VectorConv(F, [-1, 0, 98, big(10)^40])

Useful scalar helpers

Function Meaning
rep(x) Canonical representative
Int(x) Convert to machine integer
BigInt(x) Convert to arbitrary-precision integer
modulus(F) Modulus of the parent
characteristic(F) Field characteristic
parent(x) Parent field object
zero(F), one(F) Additive and multiplicative identities
iszero(x), isone(x) Identity tests
add, sub, negate, mul, sqr, divide, power Procedural arithmetic aliases
muladd(x,y,z) Fused x*y+z with fewer temporary objects

Polynomials

Construction

F = PrimeField(101)
f = poly(F, [1, 2, 3])   # 1 + 2x + 3x^2
x = xpoly(F)              # x

@assert degree(f) == 2
@assert coeff(f, 0) == 1
@assert coeff(f, 2) == 3
@assert coeff(f, 20) == 0
@assert LeadCoeff(f) == 3
@assert ConstTerm(f) == 1

poly(F, f) is also valid for constructing from a compatible polynomial. coefficients(f) returns a copy of the coefficient vector.

Core operations

Function Purpose
DivRem(f,g) Polynomial quotient and remainder
GCD(f,g) / gcd(f,g) Monic Euclidean GCD
XGCD(f,g) Return (d,s,t) with d = s*f + t*g
derivative(f) / diff(f) Formal derivative
evaluate(f,x) Horner evaluation
compose(f,g) Polynomial composition
interpolate(F,xs,ys) Lagrange interpolation
truncate(f,n) Keep terms of degree < n
MulTrunc(f,g,n) Multiply then truncate
InvTrunc(f,n) Newton truncated inverse
MulMod(f,g,m) Product modulo polynomial m
InvMod(f,m) Inverse in a quotient ring
PowerMod(f,e,m) Binary powering modulo m

Factorization and irreducibility

F = PrimeField(97)
x = xpoly(F)
f = (x + 1)^3 * (x^2 + x + 1)

fac = factor(f)
@assert reconstruct(fac) == f
@assert all(is_irreducible(g) for (g, multiplicity) in fac.factors)

The factorization layer includes:

  • square-free decomposition;
  • distinct-degree factorization;
  • Cantor–Zassenhaus equal-degree splitting;
  • Rabin irreducibility testing;
  • random irreducible polynomial generation with BuildIrred;
  • root extraction with FindRoots and FindRoot.

Multiplication and acceleration

Acceleration is enabled by default.

set_polynomial_acceleration!(true)
result = poly_mul(f, g)

The automatic strategy is:

  1. Schoolbook for small degrees;
  2. Karatsuba for medium degrees;
  3. Generalized FFT for large degrees, using same-prime NTT when possible and compatible NTT primes with CRT otherwise.

Explicit method selection

reference = poly_mul(f, g; method = :schoolbook)

@assert poly_mul(f, g; method = :karatsuba) == reference
@assert poly_mul(f, g; method = :ntt) == reference
@assert poly_mul(f, g; method = :fft) == reference
@assert poly_mul(f, g; method = :auto) == reference

To restore the original behavior everywhere:

set_polynomial_acceleration!(false)

Why are there both :ntt and :fft?

  • :ntt requests the same-prime transform and therefore requires the transform length to divide p-1.
  • :fft is the generalized route. It can use compatible NTT primes and reconstruct exact integer coefficients with a coefficient bound or CRT.

If generalized FFT is unavailable for an input, automatic mode falls back to Karatsuba.

GF2 and GF2X

GF2 is the two-element field. GF2X stores a binary polynomial as bits of a BigInt, so bit i is the coefficient of x^i.

x = GF2X(2)             # x
f = x^2 + x + 1         # x^2 + x + 1

@assert is_irreducible(f)
@assert (x + 1)^2 == x^2 + 1  # characteristic two
@assert weight(f) == 3

fac = factor((x + 1)^3 * (x^2 + x + 1)^2)
@assert reconstruct(fac) == (x + 1)^3 * (x^2 + x + 1)^2

Useful functions include bits, weight, NumBits, NumBytes, DivRem, XGCD, MulMod, PowerMod, factor, is_irreducible, and BuildIrredGF2X.

Extension fields

The mathematical model

extension_field(F, m) constructs the quotient E=F[X]/(m(X))E=F[X]/(m(X)). By default it verifies that m is irreducible, so the quotient is a field. If F=𝔽qF=\mathbb F_q and degm=d\deg m=d, then:

  • E≅𝔽qdE\cong\mathbb F_{q^d} and cardinality(E) == q^d;
  • t = gen(E) is the image of XX, so m(t)=0m(t)=0 in E;
  • every element has a unique representative a0+a1t+⋯+ad−1td−1a_0+a_1t+\cdots+a_{d-1}t^{d-1};
  • ExtensionElem is the element type, while ExtensionField is the parent type.

Everyday code normally does not need to name the element type: use E(...). ExtensionElem is the actual concrete element type when an explicit descriptive name is useful.

Construct a field and its elements

The following example builds 𝔽25=𝔽5[t]\mathbb F_{25}=\mathbb F_5[t], where t2=−2=3t^2=-2=3. The polynomial X2+2X^2+2 is irreducible over 𝔽5\mathbb F_5.

using NTL
using Random
using Test

F = PrimeField(5)
X = xpoly(F)
m = X^2 + 2
@assert is_irreducible(m)

E = extension_field(F, m)  # Check irreducibility and build the parent.
t = gen(E)                 # t is the image of X.

a = E([1, 2])               # 1 + 2t: coefficients are low degree first.
b = E(1 + 3X)              # Polynomial input is reduced modulo m.
c = E(4)                   # A scalar becomes a constant extension element.

@assert E isa ExtensionField
@assert a isa ExtensionElem
@assert a == 1 + 2t
@assert b == 1 + 3t
@assert c == E([4])
@assert E(a) == a
@assert ExtensionElem(E, [1, 2]) == a  # Optional descriptive type spelling.
p = E(X^3 + 1)             # Polynomial input is reduced before storage.
@assert degree(rep(p)) < extension_degree(E)
@assert t^2 == E(3)

There are three equivalent everyday construction styles:

Construction Meaning
E(c) General parent call: accepts a scalar, coefficient vector, polynomial, or compatible extension element
ExtensionElem(E, c) Explicit element-type spelling for scalars, coefficient vectors, polynomials, and extension elements
gen(E) The distinguished generator t=X(modm)t=X\pmod m

For polynomial input, E(p) and ExtensionElem(E, p) are equivalent and always reduce p modulo the defining polynomial. Coefficient vectors are converted to the base field and normalized; they do not need to have exactly d entries.

Inspect the representation

rep(a) is a reduced ModPoly, not an integer and not a Zech logarithm. Its coefficient vector is stored from low degree to high degree and may be shorter than d when high coefficients are zero. Use coeff(rep(a), i) when you need a fixed coefficient position, because out-of-range coefficients read as zero.

@assert parent(a) == E
@assert base_field(a) == F
@assert base_field(E) == F
@assert modulus(a) == m
@assert modulus(E) == m
@assert defining_polynomial(E) == m
@assert characteristic(a) == 5
@assert extension_degree(E) == 2
@assert degree(E) == 2
@assert cardinality(E) == 25

@assert degree(rep(a)) <= 1
@assert coeff(rep(a), 0) == F(1)
@assert coeff(rep(a), 1) == F(2)
@assert coeff(rep(a), 2) == F(0)
@assert coefficients(rep(a)) == F.([1, 2])
Interface Result for an element or parent
parent(a) The ExtensionField parent
rep(a) The canonical reduced polynomial representative
base_field(E) or base_field(a) The underlying coefficient field
defining_polynomial(E) or modulus(a) The monic defining polynomial
extension_degree(E) or degree(E) The degree dd
cardinality(E) The field order qdq^d, as an arbitrary-precision integer
characteristic(E) or characteristic(a) The characteristic pp
zero(E), one(E) Additive and multiplicative identities
iszero(a), isone(a) Identity tests

Addition, multiplication, division, and powers

Addition and subtraction operate coefficient by coefficient. Multiplication first multiplies the polynomial representatives and then reduces modulo m. Inversion uses the polynomial extended Euclidean algorithm. Powers use modular square-and-multiply; negative exponents invert first.

d = E([2, 1])              # 2 + t

@assert a + d == E([3, 3])
@assert a - d == E([-1, 1])
@assert -a == E([-1, -2])
@assert a * d == E(rem(rep(a) * rep(d), m))
@assert sqr(a) == a * a

# Directly, (1 + 2t)^2 = 3 + 4t because t^2 = 3 in F_5.
@assert a^2 == E([3, 4])

@assert a * inv(a) == one(E)
@assert a / d == a * inv(d)
@assert a^(-3) == inv(a)^3
@assert power(a, 17) == a^17

# Integer and base-field scalars are embedded as constant polynomials.
@assert a + 2 == E([3, 2])
@assert 3a == E([3, 1])
@assert a * F(2) == E([2, 4])

Division by zero and inversion of zero throw DomainError. Operands belonging to different extension parents are not mixed implicitly.

@test_throws DomainError inv(zero(E))

E2 = extension_field(F, X^2 + 3)
@test_throws ArgumentError a + E2([1, 2])
@test_throws ArgumentError extension_field(F, X^2 + 1) # Reducible over F_5.

The advanced keyword check = false skips the irreducibility test. It is intended only for users who deliberately want a polynomial quotient ring; field-only claims and inverses are not guaranteed when m is reducible.

Frobenius, trace, and norm

For q=|F|q=|F| and d=[E:F]d=[E:F], the Frobenius map is a↦aqa\mapsto a^q. NTL.jl computes the absolute trace and norm by

TrE/F(a)=∑i=0d−1aqi,NE/F(a)=a(qd−1)/(q−1). \operatorname{Tr}_{E/F}(a)=\sum_{i=0}^{d-1}a^{q^i}, \qquad \operatorname{N}_{E/F}(a)=a^{(q^d-1)/(q-1)}.

Both return a base-field element, not a ExtensionElem.

@assert a^5 == E([1, 3])       # Frobenius conjugate of 1 + 2t
@assert trace(a) == F(2)
@assert norm(a) == F(4)
@assert E(trace(a)) == a + a^5
@assert E(norm(a)) == a * a^5

@assert trace(t) == F(0)
@assert norm(t) == F(2)

For an element of degree dd over a machine-word prime field, addition costs O(d)O(d) coefficient operations. Multiplication and inversion inherit the dense-polynomial multiplication and XGCD costs. Trace uses Frobenius powers; norm uses modular exponentiation.

Random elements and arrays

rng = MersenneTwister(2026)
u = rand(rng, E)
v = rand(rng, E, 4)

@assert u isa ExtensionElem
@assert parent(u) == E
@assert length(v) == 4
@assert all(parent(w) == E for w in v)

A random extension element is produced by sampling a polynomial of degree below d and reducing it in E. Supplying an explicit RNG makes experiments reproducible.

Polynomials whose coefficients are ExtensionElem

ExtensionElem is a first-class coefficient type for ModPoly. This enables extension-field polynomials without a separate C++-style global context.

Y = xpoly(E)
h = Y^2 + a*Y + d

@assert field(h) == E
@assert evaluate(h, zero(E)) == d

q, r = DivRem(h, Y + 1)
@assert q * (Y + 1) + r == h
@assert GCD((Y + 1)^2, Y + 1) == Y + 1

Use factor, FindRoots, interpolate, and the other generic polynomial algorithms over an extension exactly as over a prime field.

Binary extensions use the same element model

GF2E(m) is a convenience constructor for an extension of GF2; its elements also use ExtensionElem with a GF2 base field.

g = GF2X(2)
aes_modulus = g^8 + g^4 + g^3 + g + 1
@assert is_irreducible(aes_modulus)

B = GF2E(aes_modulus)
z = gen(B) + 1

@assert gen(B) isa ExtensionElem
@assert cardinality(B) == 256
@assert z^255 == one(B)
@assert z * inv(z) == one(B)

For a minimal binary example, t2+t+1=0t^2+t+1=0 gives 𝔽4\mathbb F_4:

B4 = GF2E(g^2 + g + 1)
@assert cardinality(B4) == 4
@assert gen(B4)^3 == one(B4)

ExtensionElem or ZechElem?

Both represent elements of the same mathematical extension, but their storage and fast operations differ.

Need Recommended representation
Inspect coefficients, defining polynomials, trace, or norm ExtensionElem through extension_field
Build polynomials over the extension ExtensionElem
Work in a large extension ExtensionElem
Repeated multiplication, inversion, and powers in a small extension ZechElem through zech_field
Convert a Zech result back to polynomial form extension_element(z)

The Zech representation stores discrete logarithms and is limited to fields of order at most 65,535. ExtensionElem stores polynomial representatives and has no such field-order table limit.

Zech fields for fast small-field arithmetic

A Zech field is a discrete-log representation of the same extension field. It is not a different mathematical field.

For a field of order q, a primitive element g is chosen so that every nonzero element is g^k. Multiplication becomes addition of exponents modulo q-1; inversion and powering become sign change and scalar multiplication of exponents.

F = PrimeField(3)
E = extension_field(F, poly(F, [2, 1, 1]))
Z = zech_field(E)
x = ZechElem(Z, Z._generator)

@assert cardinality(Z) == 9
@assert x * inv(x) == one(Z)
@assert x^8 == one(Z)
@assert muladd(x, x, one(x)) == x * x + one(x)
@assert isbitstype(typeof(x))

Why is it faster?

Ordinary extension multiplication performs polynomial multiplication and reduction. Zech multiplication performs table lookups:

  • log[a] + log[b] for multiplication;
  • log[a] - log[b] for division;
  • -log[a] for inversion;
  • e * log[a] for powers.

Use extension_element(a) to return to the ordinary polynomial extension representation.

Limits and requirements

  • The base must currently be a machine-word prime field PrimeField.
  • The extension order must satisfy q <= 65535.
  • A primitive multiplicative generator is required. zech_field searches for one automatically; an explicitly supplied non-generator is rejected.

Elliptic-curve point counting

For the cubic

E:y2=x3+2x+3 E: y^2 = x^3 + 2x + 3

NTL.jl can count projective points over 𝔽5k\mathbb F_{5^k}. The implementation counts the point at infinity as well as all affine solutions. It uses the Euler criterion to decide whether the right-hand side is a square, avoiding a full q2q^2 search for larger fields.

using NTL

elliptic(x, y) = y^2 - x^3 - 2x - 3

function count_points_fast(F)
    q = cardinality(F)
    affine = 0
    for x in all_elements(F)
        rhs = x^3 + 2x + 3
        if iszero(rhs)
            affine += 1
        elseif rhs^div(q - 1, 2) == one(rhs)
            affine += 2
        end
    end
    (affine = affine, projective = affine + 1)
end

For small fields, the fast method is checked against exhaustive enumeration of all (x,y)(x,y) pairs. Current results are:

kk q=5kq=5^k Affine points Projective points
1 5 6 7
2 25 24 25
3 125 126 127
4 625 624 625
5 3125 3126 3127
6 15625 15624 15625

The helper all_elements(F) is defined in the example and enumerates every field element. The complete example is examples/13_elliptic_curve.jl. It constructs 𝔽5k\mathbb F_{5^k} with irreducible polynomials and prints both affine and projective counts. The cubic is singular in characteristic five because 4⋅23+27⋅32=275≡0(mod5)4\cdot2^3+27\cdot3^2=275\equiv0\pmod5, but the point count is still well-defined.

Matrices and exact linear algebra

The generic matrix routines work over supported fields.

F = PrimeField(101)
A = F.([2 3 1; 4 1 5; 3 7 2])
b = F.([1, 2, 3])

x = solve(A, b)
d = det(A)
invA = matrix_inverse(A)

@assert A * x == b
@assert A * invA == F.([1 0 0; 0 1 0; 0 0 1])

S = F.([1 2 3; 2 4 6; 0 1 1])
@assert iszero(det(S))
@assert rank(S) == 2
@assert all(iszero, S * nullspace(S)[1])
Function Purpose
det(A) Determinant by Gaussian elimination
det_exact(A) Exact integer determinant by Bareiss elimination
rref(A) Reduced row-echelon form and pivot columns
rank(A) Rank over an exact field
solve(A,b) Solve a nonsingular square system
matrix_inverse(A) Inverse over a field
nullspace(A) Basis of the right nullspace

LLL lattice reduction

A = BigInt[1 1 1; -1 0 2; 3 5 6]
result = lll(A; mode = :fast, verify = true)

@assert result.transform * A == result.basis
@assert abs(det_exact(result.transform)) == 1
@assert result.verified

Modes

Mode Behavior
:fast Exact integer row operations, floating GSO for decisions, exact verification
:exact Original exact-rational implementation

The default fast mode verifies:

  • transform * A == basis;
  • abs(det_exact(transform)) == 1;
  • exact size-reduction bounds;
  • the exact Lovász condition.

If verification fails, the implementation automatically falls back to exact mode. verify = false skips the additional verification pass when that trade-off is intentional.

Extended mathematical interfaces

Characteristic and minimal polynomials

charpoly(A) uses a division-free Berkowitz recurrence and supports integer, prime-field, composite-modulus, GF2, and ordinary extension matrices. MinPolyMod(h,f) computes the first monic dependence in a quotient algebra; minpoly(a) handles extension elements. Square matrices, reducible moduli, zero divisors, and characteristic two are explicit edge cases rather than hidden assumptions.

A = BigInt[1 2; 3 4]
@assert charpoly(A) == poly(BigInt, [-2, -5, 1])

Integer matrices and exact linear systems

hnf(A; transform=true) returns H,U with U*A == H and abs(det(U)) == 1. The row-Hermite convention uses positive pivots, nonnegative remainders above pivots, and trailing zero rows. kernel_integer(A) returns a column lattice basis of A*x == 0, image_integer(A) returns a basis of the integer column image, and solve_integer(A,b) returns nothing for an inconsistent integer system or x plus a kernel basis otherwise.

Integer polynomial factorization

content_primitive(f) separates unit, content, and primitive part. factor_integer_poly(f) returns a PolyFactorization with irreducible factors and multiplicities; is_irreducible_integer_poly(f) checks the corresponding predicate, and reconstruct(z) verifies the result. The default path is exact Kronecker interpolation for small inputs. With Nemo loaded, NTLNemoExt uses FLINT as an optional acceleration backend without changing the return contract.

GF2EX and ZZ_pEX factorization

GF2EXFactoring and ZZ_pEXFactoring first remove linear factors when cardinality(E) <= 32 and 1 <= degree(f) <= 12 with a prime base field. Remaining factors use generic Cantor–Zassenhaus. The specialized root-removal step is only a fast path; it does not change the mathematical factorization result.

Conway fields and isomorphisms

conway_field(p,n;symbol=:α) and conway_polynomial(p,n) provide the package’s 96 Conway records for p ∈ {2,3,5,7,11,13,17,19} and 1 <= n <= 12. identify(S,T;generator_map) returns a transport function. convert(T,a;generator_map) applies the same rule to an element. Source polynomial roots, generator images, round trips, trace, norm, and logarithm are checked explicitly.

Primitive elements and logarithms

primitive_element, order, is_primitive_root, any_primitive_root, minimal_primitive_root, log, and exp cover multiplicative-order and discrete-logarithm operations. enable_zech_multiplication(E) produces a table representation, while disable_zech_multiplication(Z) returns the ordinary extension. log(a) and exp(k,F) are inverses for nonzero elements.

Storage and runtime interfaces

Packed vectors and modular storage

ZZVec and GF2XVec provide continuous-limb storage, copying, slicing, addition, subtraction, and packed_dot. packedfieldvec(F, values; storage) chooses Int8 through Int128 or BigInt based on the modulus and can enforce a requested storage type. These are storage choices, not free speedups: compact arrays reduce payload size but add reconstruction overhead.

Polynomials.jl interoperability

Loading Polynomials enables Polynomial(f) and ModPoly(p) conversions plus DivRem, GCD, factor, evaluate, derivative, integrate, resultant, discriminant, subresultants, and roots. A zero polynomial with a runtime parent requires an explicit ring argument.

BKZ

bkz(A;block_size=20,delta=99//100,verify=true,maxiter=100000) performs exact projected-block shortest-vector enumeration and unimodular insertion. It returns basis, transform, and verified. Enumeration is exponential in the block dimension, so block size is an explicit performance parameter rather than a promise of polynomial-time behavior.

Real arithmetic and real roots

RR is an alias for BigFloat; xdouble and quad_float provide software-rounded 53-bit and 106-bit real values, and mat_RR provides matrices over them. isolate_real_roots(f) uses a Sturm sequence to return disjoint open rational intervals, one for each distinct real root.

Caching and concurrency

ArithmeticCache, cached_field, cached_ntt_convolve, and cached_zech let callers own the cache lifetime. BasicThreadPool and parallel_map preserve input order and propagate task errors. Lazy and LazyTable support thread-safe lazy initialization; individual BKZ and factorization routines remain serial unless the caller explicitly parallelizes a batch.

NTT and generalized FFT

Same-prime NTT

ntt_convolve(a,b) computes convolution over a supported prime field. A radix-two transform of length n requires n to be a power of two and to divide p-1.

F = PrimeField(97)  # 97-1 = 96, which is divisible by 32
a = rand(MersenneTwister(1), F, 32)
@assert intt(ntt(a)) == a

b = rand(MersenneTwister(2), F, 32)
@assert ntt_convolve(a, b) == convolve(a, b)

Generalized FFT

fft_convolve(a,b) uses a same-prime fast path when possible. Otherwise it selects compatible NTT primes and reconstructs exact coefficients with a coefficient bound and, when needed, multi-prime CRT.

F = PrimeField(101)
f = random_poly(F, 1000)
g = random_poly(F, 1000)

reference = poly_mul(f, g; method = :schoolbook)
@assert poly_mul(f, g; method = :fft) == reference

The reconstruction is exact; it is not a floating-point approximation.

Number theory

Function Purpose
ProbPrime(n; rounds=16) Miller–Rabin primality test; deterministic in the signed Int range
MillerWitness(n,w) Test whether w witnesses compositeness
NextPrime(m) Least probable prime >= m
PrevPrime(m) Greatest probable prime <= m
GenPrime(bits) Generate a probable prime with an exact bit length
RandomBits(bits) Random integer with at most bits bits
RandomLen(bits) Random integer with exactly bits bits
RandomBnd(n) Uniform random integer below n
FactorInt(n) Factorization using Miller–Rabin and Pollard–Brent rho
EulerPhi(n) Euler’s totient from the factorization
CRT(r,m) Chinese remaindering for pairwise-coprime moduli
SqrRootMod(a,p) Tonelli–Shanks square root; returns nothing for a nonresidue
DiscreteLog(a,b,p) Baby-step/giant-step logarithm
PrimitiveRoot(p) Generator of the multiplicative group modulo a prime

A small example

@assert ProbPrime(97)
@assert !ProbPrime(341)
@assert NextPrime(100) == 101
@assert PrevPrime(100) == 97

fac = FactorInt(99991 * 10007)
@assert prod(p^e for (p, e) in fac; init = BigInt(1)) == 99991 * 10007

x, M = CRT([2, 3, 2], [3, 5, 7])
@assert (x, M) == (23, 105)

g = PrimitiveRoot(97)
y = powermod(g, 42, 97)
@assert powermod(g, DiscreteLog(g, y, 97), 97) == y

Important API reference

Prime-field and modular arithmetic

Function Purpose
PrimeField(p) Validate a prime and return PrimeField{p}
PRIME_FIELD_MIN, PRIME_FIELD_MAX Bounds of supported machine-word prime moduli
AddMod, SubMod, NegateMod Overflow-safe modular add/subtract/negate on reduced Int values
MulMod, SqrMod Modular multiplication and squaring
InvMod, InvModStatus Inverse or a nonthrowing status result
PowerMod Binary modular powering with negative-exponent support
muladd(x,y,z) Fused x*y+z
BigModRing(n) Construct an arbitrary-precision modular parent
BigModRing, ModInt Parent and element types; ModInt(R,a) is direct element construction
rep, parent, modulus, characteristic Canonical representative and parent metadata
rand, VectorRandom, VectorConv Random elements and vector conversion

Polynomial acceleration

Function Purpose
poly_mul(f,g; method) Select schoolbook, Karatsuba, NTT, generalized FFT, or automatic mode
set_polynomial_acceleration!(Bool) Enable/disable automatic acceleration
polynomial_acceleration() Inspect the current mode
fft_convolve(a,b) Generalized FFT with exact reconstruction
ntt_convolve(a,b) Same-prime NTT convolution
convolve(a,b) Direct schoolbook convolution

Extension fields and Zech fields

Function Purpose
ExtensionField, ExtensionElem Extension parent and descriptive polynomial-represented element type
extension_field(F,m; check=true) Checked polynomial quotient extension
E(c), ExtensionElem(E,c) Construct scalars, coefficient vectors, polynomials through E, or copy elements
GF2E(m) Binary extension using the same ExtensionElem element model
gen(E) Image of the polynomial indeterminate in the extension
base_field, defining_polynomial, parent, rep Parent and representation metadata
extension_degree(E), degree(E) Extension degree
cardinality(E) Number of elements, qdq^d
+, -, *, /, inv, power, ^ Extension arithmetic with reduction modulo the defining polynomial
rand(rng,E), rand(rng,E,n) Random extension elements and arrays
trace(a), norm(a) Absolute trace and norm to the base field
xpoly(E), poly(E,c) Polynomials with ExtensionElem coefficients
zech_field(E) Build a small-field discrete-log representation
extension_element(a) Convert a Zech element back to ExtensionElem

Matrix and lattice functions

Function Purpose
det, det_exact, rank, rref, solve, matrix_inverse, nullspace Exact matrix algorithms
gram_schmidt_exact(B) Exact rational Gram–Schmidt data
lll(A; mode, verify) LLL with fast and exact modes

Extended mathematical interfaces

Interface Purpose
charpoly, MinPolyMod, minpoly Characteristic and minimal polynomials
hnf, kernel_integer, image_integer, solve_integer Exact integer matrix structure and integer linear systems
factor_integer_poly, content_primitive, is_irreducible_integer_poly Integer polynomial factorization with optional FLINT acceleration
GF2EXFactoring, ZZ_pEXFactoring Extension-field polynomial factorization
conway_field, conway_polynomial Conway polynomial construction and generator selection
identify, convert Isomorphism transport between extension fields
primitive_element, order, is_primitive_root, any_primitive_root, minimal_primitive_root, log, exp Multiplicative order and discrete logarithms
ZZVec, GF2XVec, packed_dot, packedfieldvec Packed storage and limb operations
bkz Block Korkin–Zolotarev reduction with exact verification
RR, xdouble, quad_float, mat_RR, isolate_real_roots Real arithmetic and Sturm real-root isolation
ArithmeticCache, cached_field, cached_ntt_convolve, cached_zech, BasicThreadPool, parallel_map, Lazy, LazyTable Cache lifetime, lazy initialization, and ordered parallel work

Project architecture

NTLJulia/
├── Project.toml
├── README.md
├── docs/
│   └── index.html
├── src/
│   ├── NTL.jl              # Module entry, prime fields, low-level arithmetic
│   ├── big_mod_ring.jl          # BigModRing parents and ModInt elements
│   ├── numbertheory.jl     # Primality, factorization, CRT, roots, discrete logs
│   ├── polynomial.jl       # Dense polynomials and factorization
│   ├── polynomial_mul.jl   # Schoolbook, Karatsuba, and acceleration strategies
│   ├── binary.jl           # GF2 and bit-packed GF2X
│   ├── extension.jl        # ExtensionField and ExtensionElem polynomial representatives
│   ├── zech.jl             # Isbits Zech representation and tables
│   ├── matrix.jl           # Determinants, RREF, solving, rank, nullspace
│   ├── lattice.jl          # Original exact LLL implementation
│   ├── lll_fast.jl         # Fast LLL with exact verification and fallback
│   ├── bkz.jl              # Exact projected-block SVP enumeration and insertion
│   ├── exact_interfaces.jl # charpoly, MinPolyMod, hnf, integer linear algebra
│   ├── integer_polys.jl    # Integer polynomial factorization
│   ├── finite_interfaces.jl # Conway, identify, primitive roots and logs
│   ├── packed.jl           # Packed vectors and modular storage
│   ├── poly_extras.jl      # Resultants, discriminants and real-root isolation
│   ├── extras_runtime.jl   # Real arithmetic, caches and concurrency
│   ├── transform.jl        # Same-prime NTT and optimized butterflies
│   └── fft.jl              # Generalized FFT and CRT reconstruction
├── ext/
│   ├── NTLNemoExt.jl       # Optional Nemo / FLINT integration
│   └── NTLPolynomialsExt.jl # Polynomials.jl integration
├── data/
│   └── conway.txt          # 96 Conway polynomial records
├── example.jl            # HNF, solve_integer and BKZ examples
├── extension_checks.jl   # Extension-field factorization checks
├── storage_bench.jl      # Packed versus ordinary storage benchmark
├── optional.jl           # Optional third-party checks
├── setup_optional.jl     # Optional environment setup
├── examples/
│   ├── 01_basic_arithmetic.jl
│   ├── 02_vectors_and_random.jl
│   ├── 03_linear_system.jl
│   ├── 04_number_theory.jl
│   ├── 05_polynomial_factorization.jl
│   ├── 06_extension_gf2.jl
│   ├── 07_matrix_lattice.jl
│   ├── 08_ntt_convolution.jl
│   ├── 09_polynomial_acceleration.jl
│   ├── 10_generalized_fft.jl
│   ├── 11_fast_lll.jl
│   ├── 12_zech_extension.jl
│   ├── 13_elliptic_curve.jl
│   └── api_tour.jl          # At least one executable call for every exported API
└── test/
    ├── runtests.jl
    ├── primefield_numtheory.jl
    ├── polynomial.jl
    ├── binary_extension.jl
    ├── matrix_lattice_transform.jl
    ├── exact_interfaces.jl
    ├── factor_smallfield.jl
    ├── performance_regressions.jl
    ├── acceleration.jl
    ├── lll_fast.jl
    ├── lll_exact_certificates.jl
    ├── zech.jl
    ├── elliptic.jl
    └── naming.jl            # Canonical names and compatibility aliases

The public API is grouped by mathematical role rather than by C++ header names, so the implementation is easier to navigate for new users.

Examples and tests

Run any example with:

julia --project=. examples/01_basic_arithmetic.jl

Complete API coverage: examples/api_tour.jl contains at least one executable call for every exported NTL.jl interface. It also includes a dedicated extension-field block covering construction, representation, arithmetic, inversion, powers, random elements, and polynomials over an extension. Run it with:

julia --project=. examples/api_tour.jl
Script Demonstrates
01_basic_arithmetic.jl Prime-field construction, arithmetic, low-level helpers, iteration
02_vectors_and_random.jl Random elements, conversion, vector operations
03_linear_system.jl Solving a finite-field linear system
04_number_theory.jl Primality, factorization, CRT, modular roots, discrete logs, prime generation
05_polynomial_factorization.jl Factor reconstruction, irreducibility, interpolation, modular powers
06_extension_gf2.jl GF(2^8), prime-field extensions, extension-field polynomials
07_matrix_lattice.jl Matrix solving, inverse, nullspace, exact LLL
08_ntt_convolution.jl NTT round trips and convolution
09_polynomial_acceleration.jl Schoolbook, Karatsuba, NTT, and automatic selection
10_generalized_fft.jl Generalized FFT and exact coefficient reconstruction
11_fast_lll.jl Fast and exact LLL modes with verification
12_zech_extension.jl Zech elements, inverse, powers, and muladd
13_elliptic_curve.jl Elliptic-curve point counting over 𝔽5k\mathbb F_{5^k}, including the point at infinity
api_tour.jl Every exported interface, including the complete extension-field workflow

Comparison with C++ NTL

The following table was rerun on 2026-11-22 using the 0.13.0 baseline, the selectively optimized 0.13.2 kernels, official C++ NTL 11.4.2, and Julia 1.11.7 on the 2-core project server. Each value is the median of 31 runs after warm-up, with input construction excluded. These are workload-specific examples, not universal performance guarantees.

Operation C++ NTL (ms) Baseline (ms) Selective 0.13.2 (ms) Optimized / C++
Small modular mul/add (typed hot loop) 8.4581 67.8763 5.0605 0.60x
BigInt modular exponentiation 0.0130 0.0049 0.0047 0.36x
Polynomial multiplication 0.0660 0.0693 0.0677 1.03x
NTT convolution 0.6572 0.5898 0.5793 0.88x
Polynomial factorization (degree 8) 0.0250 0.0753 0.0261 1.05x
Finite-field determinant 0.0302 0.0148 0.0150 0.50x
LLL (Julia default + exact verification) 0.0699 0.1843 0.0989 1.41x
LLL (Julia reduction only) 0.0694 0.0320 0.0415 0.60x
Primality test (per call) 0.0678 0.0262 0.0264 0.39x

What these results mean

The LLL rows are not at the same verification layer. Native C++ LLL(det2,B,U) does not perform Julia’s independent exact post-verification. The default Julia row therefore measures end-to-end API cost, not a like-for-like algorithm-only benchmark. For the reduction layer, compare verify = false with native C++ LLL. The optional cpp_checked.cpp verifier is a separate custom checker, not part of upstream C++ NTL’s timing.

  • The small-field factorization path is competitive with C++ NTL for the repository’s degree-8 input: 26.12 μs versus 24.99 μs. An early-splitting probe now avoids exhaustive root scans when multiple roots are found among the first eight candidates.
  • small_modmul uses a typed hot loop to make Julia dispatch boundaries explicit. It does not demonstrate a library-only speedup: the original loop remains about 68–71 ms in these runs. The small-residue multiplication patch itself was not merged, because it did not show a stable benefit on this server.
  • The 0.13.0 optimized polynomial, NTT, determinant, and LLL paths remain in place. Default LLL still includes exact post-verification, whereas the reduction-only row measures the faster path without that cost.
  • Primality uses different witness strategies and is shown only as a reference.

Performance optimizations

Version 0.14.0 adds the extended interfaces described above. Independent benchmarks on the same server measured:

Workload Time
charpoly on a 2×2 matrix 0.015 ms
HNF on a 12×12 integer matrix 1.620 ms
Integer factorization of the degree-8 test polynomial 9.014 ms
The same factorization with Nemo/FLINT enabled 0.076 ms
GF2EX factorization 0.453 ms
ZZ_pEX factorization 0.395 ms
One generator-map conversion 0.031 ms
BKZ with block size 3 0.680 ms
Real-root isolation for (x-1)^2*(x^2-2) 1.901 ms
Packed-vector read sum 25.170 ms
Ordinary-vector read sum 8.641 ms

The optional FLINT path was approximately 119× faster than basic Kronecker interpolation for this input, but this is not a universal factorization guarantee. Packed storage used 100,000 bytes rather than 800,000 bytes for 100,000 residues, while sequential reconstruction was about 2.9× slower.

Version 0.13.3

Version 0.13.3 accelerates exact LLL verification with bounded fixed-width checks and a generic BigInt fallback. The reduction now retains native Int candidates through verification before converting the public result to BigInt once. Before converting the original matrix A, it verifies that all entries fit the fixed-width bound; an oversized original matrix therefore goes directly to the generic verifier rather than throwing InexactError.

The new test/lll_exact_certificates.jl suite adds 536 assertions for exact transformation, unimodularity, size reduction, Lovász conditions, row exchanges, forged inputs, overflow fallbacks, and oversized original matrices. The benchmark separates reduction, exact verification, and their combination rather than attributing all LLL cost to the reducer.

Version 0.13.2

Version 0.13.2 adds an early-splitting fallback. Before trying the small-field exhaustive path, it evaluates at most eight candidate roots and immediately returns to generic Cantor–Zassenhaus when at least two are found. This prevents highly splitting polynomials from paying for a full root scan while preserving the fast path for root-free and sparse-root inputs.

Threshold scans show the improvement most clearly. For distinct linear factors, the specialized-versus-generic ratios changed from 2.667 to 0.994 for p=31, d=4, from 4.771 to 0.989 for p=61, d=8, from 4.687 to 0.951 for p=101, d=12, and from 7.115 to 0.995 for p=127, d=16. The repository’s degree-8 workload remains close to C++ NTL at 26.12 μs versus 24.99 μs.

Version 0.13.1

Version 0.13.1 adds a selective small-field factorization path. It removes roots by exhaustive evaluation only when P <= 127 and 1 <= degree(f) <= 16, uses synthetic division for multiplicities, handles root-free quartics by monic quadratic pairing, and delegates all other inputs to the general factorization implementation. The small-residue multiplication patch from the same proposal was evaluated but deliberately not merged because it did not improve performance on this server.

The new test/factor_smallfield.jl suite adds 306,588 assertions, including exhaustive monic quartics over 𝔽2\mathbb F_2 and 𝔽3\mathbb F_3, factor reconstruction, irreducibility, distinct-factor checks, and small-residue boundary cases. The benchmark repository also records the typed hot loop separately from the original loop so that dispatch-boundary improvements are not misattributed to the arithmetic implementation.

Version 0.13.0

Version 0.13.0 adds a larger set of specialized kernels while preserving generic fallbacks and exact verification:

  1. PrimeField: specialized unsigned multiplication, Barrett reduction for large machine-word moduli, and Montgomery powering on 64-bit builds.
  2. BigModRing: conditional add/subtract corrections, GMP-backed inversion and powermod, with no shared mutable global workspace.
  3. Polynomials: exact packed-integer multiplication when the coefficient bound fits one digit, typed auxiliary NTT, DIF/DIT convolution, and UInt128 CRT for at most four auxiliary primes.
  4. Determinants: column-major elimination with a computed refresh interval for delayed modular reduction and a generic fallback.
  5. Factorization: typed polynomial parents, buffered modular powers, and no repeated leading-inverse work in small-degree cases.
  6. LLL: incremental floating GSO updates, checked machine-integer row operations with BigInt fallback, and exact fraction-free verification of transformation, unimodularity, size reduction, and the Lovász condition.

The accompanying test/performance_regressions.jl adds 1,987 assertions for these paths, including large prime moduli, packed-digit boundaries, CRT reconstruction, negative exponents, root-of-unity selection, singular matrices, and exact LLL invariants.

Version 0.11.0

Version 0.11.0 implements three measured optimizations while preserving the original algorithms as fallbacks:

  1. Generalized FFT: single-prime reconstruction stays in machine integers, auxiliary primes enter a typed NTT kernel through a function barrier, and one primitive root is shared by the three transforms of a convolution. Multi-prime CRT remains unchanged for inputs that need it.
  2. Prime-field determinants: elimination follows Julia’s column-major layout, reuses each pivot inverse, and uses delayed modular reduction on Int representatives. The delayed path is selected only when n(p−1)2+(p−1)≤typemax(Int)n(p-1)^2+(p-1)\le\mathrm{typemax}(\mathrm{Int}); larger or unsafe cases use the general field implementation.
  3. Polynomial long division: the remainder coefficient buffer is reused, the divisor’s leading inverse is computed once, and standalone rem does not allocate a quotient. This also accelerates polynomial GCD and factorization.

The following before/after measurements were rerun on the same project server with Julia 1.11.7. Each entry is the median of 31 runs after warm-up, with input construction excluded. They are not copied from prototype results obtained on different hardware.

Workload 0.10.0 baseline 0.11.0 optimized Speedup Allocation before → after
Polynomial multiplication, 1024 + 1024 coefficients, p=101 1194.30 μs 319.76 μs 3.73× 535,240 → 126,544 bytes
Determinant, 256×256, p=101 24.177 ms 2.502 ms 9.66× 528,736 → 526,872 bytes
Factorization, 60 distinct linear factors, p=101 55.514 ms 18.324 ms 3.03× 20,769,488 → 8,936,736 bytes
DivRem, coefficient counts 800 / 400, p=101 61.030 ms 13.417 ms 4.55× 30,286,984 → 10,858,288 bytes
rem, coefficient counts 800 / 400, p=101 60.261 ms 13.450 ms 4.48× 30,287,016 → 10,851,696 bytes

The determinant allocation count is nearly unchanged because the specialized path deliberately allocates one Int work matrix; its gain comes from contiguous updates and fewer modular inverses. Performance varies with modulus, transform length, sparsity, and factor structure, so these figures are workload-specific rather than universal guarantees.

Comparison with GaloisFields.jl

GaloisFields.jl is particularly strong for small finite fields and extension arithmetic. This table was rerun on 2026-11-22 with NTL.jl 0.13.3, GaloisFields.jl 1.4, and Julia 1.11.7. Every workload uses the same eight random 7-bit primes for both packages: [67, 73, 83, 89, 97, 101, 107, 113]. Each per-prime value is the median of 31 runs after warm-up; the table reports the median across primes. Input construction is excluded.

Operation NTL.jl (ms) GaloisFields (ms)
Prime-field mul/add x1e6 69.9130 72.0840
Prime-field fused muladd x1e6 9.9001 14.9645
Prime-field power x10000 0.3935 0.4288
Prime-field inverse x10000 0.2408 0.2339
Zech extension ops x10000 0.5010 0.8568
Zech muladd x10000 0.5971 0.8385
Zech inverse x10000 0.3940 0.4656
Zech power x10000 0.4858 0.3820
Polynomial multiplication, deg 999 0.0649 6.5789

Interpretation

  • Across the random primes, NTL.jl was faster for separate and fused prime-field mul/add and for the median power workload; GaloisFields was slightly faster for the median inverse workload.
  • In the Zech comparison, NTL.jl was faster for extension ops, fused muladd, and inversion, while GaloisFields was faster for the tested power loop.
  • The 0.13.0 packed polynomial path substantially improved degree-999 multiplication. The full report includes per-prime ranges, so these are not single-prime conclusions.
  • The random-prime report separately covers larger moduli and the GaloisFields signed-Int128 boundary. GaloisFields remains a strong choice for compact small-field code; NTL.jl additionally covers matrices, LLL, generalized FFT, and number theory.

Design principles

Mathematical correctness before speed

Fast paths are checked against the original algorithms. A user can always request :schoolbook or mode = :exact to obtain the original behavior.

Explicit mathematical parents

PrimeField{p} keeps the modulus in the type, so different moduli cannot be mixed accidentally. BigModRing, ExtensionField, and ZechField make runtime parent relationships explicit.

Canonical and exact representations

Prime-field elements are always stored in 0:p-1. Polynomial coefficients are stored low degree first. Zech elements use isbits integer representatives with a parent-table identifier.

Acceleration with safe fallbacks

The package prefers degree-based and representation-based acceleration rather than one universal algorithm. Unsupported NTT lengths, large coefficient bounds, or failed LLL verification trigger a safe fallback.

Verification as part of the implementation

The LLL fast path checks the returned basis and transformation with exact rational GSO. Polynomial acceleration is tested by comparing every result with schoolbook and direct convolution.

Limitations

  • The extended interfaces are functional and independently checked, but they are not performance-complete replacements for every NTL module. C++ ABI compatibility is not included.
  • Integer factorization uses exact Kronecker interpolation for small inputs; optional Nemo/FLINT is recommended for large coefficients or higher degrees.
  • BKZ enumeration is exponential in block size. The default block_size = 20 is not a guarantee of practical runtime on large lattices.
  • Conway data currently contains 96 records for p ∈ {2,3,5,7,11,13,17,19} and n ∈ 1:12; other (p,n) pairs raise KeyError.
  • GF2EX/ZZ_pEX specialization applies only when the extension has at most 32 elements and degree at most 12. Other inputs retain generic factorization.
  • Packed storage reduces payload size but not necessarily read time. Measured sequential reads are slower than ordinary vectors in this implementation.
  • RR is an alias for BigFloat, not a complete NTL RR compatibility layer. Real-root isolation currently targets integer polynomials with distinct real roots and returns open rational intervals.
  • Radix-two NTT requires a power-of-two transform length and an appropriate root of unity.
  • Generalized FFT currently supports scalar modular coefficients; extension-field coefficients require other multiplication paths.
  • Zech tables require a primitive generator and are limited to fields with at most 65,535 elements.
  • Fast LLL and exact verification are intended for reproducible exact arithmetic on modest bases, not as a replacement for NTL’s highly tuned large-basis reduction routines.
  • Polynomial factorization and matrix algorithms are not claimed to match C++ NTL’s performance for very large inputs.

FAQ for beginners

Why does PrimeField(15) fail?

PrimeField represents a prime field. Fifteen is composite. Use BigModRing(15) if you intentionally need a modular ring, and remember that only units have inverses.

Why is F(2) zero when F = PrimeField(2)?

Construction always reduces modulo the field modulus: 2 mod 2 = 0.

Why can I not add PrimeField{7}(1) to PrimeField{11}(1)?

They belong to different fields. Choose one parent explicitly instead of relying on an implicit and potentially incorrect conversion.

Why does collect(F) use memory even though iteration is lazy?

Iteration produces elements one at a time, but collect allocates a vector of all p elements. Use length(F) for size and for x in F for lazy traversal.

Why does NTT report that n must divide p-1?

A primitive n-th root of unity exists in F_p only when n divides p-1. If that condition fails, automatic multiplication uses generalized FFT or Karatsuba instead.

Why does generalized FFT sometimes use other primes?

It allows convolution when the original field lacks a suitable root. Exact integer bounds and CRT ensure that the reconstructed result is correct before reduction to the original modulus.

When should I use zech_field instead of extension_field?

Use it for frequent multiplication, inversion, and powers in a small extension. It builds a discrete-log table once and then performs fast table-based operations. For large extensions or polynomial-heavy theory, use the ordinary extension representation.

Is verify = false in LLL unsafe?

It does not change the integer arithmetic of the basis or transformation, but it skips the additional exact verification step. Use it only when you intentionally want to avoid that cost.

Contributing

Contributions should preserve the package’s verification-first style.

  1. Add mathematical identities and regression tests before optimizing.
  2. Compare with schoolbook, direct convolution, or C++ NTL where practical.
  3. Keep the original algorithm available as an explicit fallback.
  4. Document supported moduli, parent requirements, complexity, and failure modes.
  5. Run the full test suite and all examples before pushing.
  6. Update README.md, docs/index.html, and relevant examples for every public interface change.

Useful invariants include U*A == B, abs(det_exact(U)) == 1, factor reconstruction, A*x == b, and exact coefficient reconstruction.

Documentation appendices

A. Run the complete API tour

The HTML manual contains the entire README above and the complete executable tour below. The source file is examples/api_tour.jl. From the package root, run:

julia --project=. examples/api_tour.jl

A successful run ends with API tour completed successfully. The tour covers all 176 exported names and checks results with assertions rather than merely printing them.

B. Complete executable API tour

using NTL
using Random
using Test
using Statistics

# This tour exercises every exported interface in the current module.

# Prime-field metadata and arithmetic -----------------------------------------
@assert PRIME_FIELD_MIN == 2
@assert PRIME_FIELD_MAX > PRIME_FIELD_MIN
F = PrimeField(101)
@assert modulus(F) == 101
@assert characteristic(F) == 101
@assert parent(F(1)) == F
@assert info(PrimeField).minimum_modulus == 2
@assert info(F).modulus == 101
@assert info(F(3)).representative == 3

x, y = F(3), F(4)
@assert rep(x) == 3
@assert Int(x) == 3
@assert BigInt(x) == 3
@assert zero(F) == F(0)
@assert one(F) == F(1)
@assert oneunit(F) == F(1)
@assert zero(x) == zero(F)
@assert one(x) == one(F)
@assert oneunit(x) == one(F)
@assert iszero(zero(F))
@assert isone(one(F))
@assert !iszero(x)
@assert !isone(y)
@assert x + y == F(7)
@assert x - y == F(100)
@assert -x == F(98)
@assert x * y == F(12)
@assert x / y == F(3 * inv(y))
@assert add(x, y) == x + y
@assert sub(x, y) == x - y
@assert negate(x) == -x
@assert mul(x, y) == x * y
@assert sqr(x) == x * x
@assert divide(x, y) == x / y
@assert power(x, 3) == x^3
@assert inv(x) * x == one(F)
@assert muladd(x, y, x) == x * y + x
@assert swap(x, y) == (y, x)

# Low-level modular helpers ----------------------------------------------------
@assert AddMod(100, 2, 101) == 1
@assert SubMod(1, 2, 101) == 100
@assert NegateMod(1, 101) == 100
@assert MulMod(3, 4, 101) == 12
@assert SqrMod(3, 101) == 9
@assert InvMod(3, 101) == 34
@assert InvModStatus(3, 101) == (true, 34)
@assert InvModStatus(0, 101) == (false, 0)
@assert PowerMod(3, -1, 101) == 34
@assert PowerMod(3, big(1000), 101) == 1

@assert VectorConv(F, [-1, 0, 2, 103]) == F.([100, 0, 2, 2])
@assert length(VectorRandom(F, 4; rng = MersenneTwister(1))) == 4
@assert rand(MersenneTwister(2), F) isa F
@assert VectorMulMod([1, 2, 3], 3, 101) == [3, 6, 9]
out = zeros(Int, 3)
@assert VectorMulMod!(out, [1, 2, 3], 3, 101) === out
@assert out == [3, 6, 9]

# Arbitrary-precision modular rings -------------------------------------------
R = BigModRing(12)
@assert R isa BigModRing
@assert R(5) isa ModInt
@assert ModInt(R, 5) == R(5)

@assert modulus(R) == 12
@assert characteristic(R) == 12
@assert R(5) * R(5) == R(1)
@assert rep(R(-1)) == 11
@assert BigInt(R(5)) == 5
@assert parent(R(5)) == R
@assert zero(R) == R(0)
@assert one(R) == R(1)
@assert oneunit(R) == R(1)
@assert R(5) * inv(R(5)) == one(R)
@assert R(5)^(-1) == inv(R(5))
@test_throws DomainError inv(R(6))
@test_throws ErrorException R(1) + PrimeField(7)(1)
@assert length(VectorRandom(R, 2; rng = MersenneTwister(3))) == 2
@assert VectorConv(R, [-1, 2, 13]) == R.([-1, 2, 13])
@assert rand(MersenneTwister(4), R) isa ModInt

# Number theory ----------------------------------------------------------------
@assert ProbPrime(101)
@assert !ProbPrime(341)
@assert MillerWitness(341, 2)
@assert !MillerWitness(101, 2)
@assert NextPrime(100) == 101
@assert PrevPrime(100) == 97
@assert ndigits(GenPrime(16; rng = MersenneTwister(5)), base = 2) == 16
@assert 0 <= RandomBits(12; rng = MersenneTwister(6)) < (big(1) << 12)
@assert ndigits(RandomLen(12; rng = MersenneTwister(7)), base = 2) == 12
@assert 0 <= RandomBnd(100; rng = MersenneTwister(8)) < 100
@assert FactorInt(99991 * 10007) == [(10007, 1), (99991, 1)]
@assert EulerPhi(36) == 12
@assert CRT([2, 3, 2], [3, 5, 7]) == (23, 105)
r = SqrRootMod(10, 13)
@assert r !== nothing && r^2 % 13 == 10
@assert SqrRootMod(2, 13) === nothing
@assert DiscreteLog(2, 8, 13) == 3
@assert PrimitiveRoot(97) == 5
@assert primitive_root(F) != 0

# Dense polynomials -------------------------------------------------------------
P = F
x = xpoly(P)
f = poly(P, [1, 2, 3])
@assert poly_mul(f, x + 1) == f * (x + 1)
@assert field(f) == P
@assert coefficients(f) == P.([1, 2, 3])
@assert coeff(f, 0) == 1
@assert coeff(f, 2) == 3
@assert coeff(f, 20) == 0
@assert degree(f) == 2 == deg(f)
@assert LeadCoeff(f) == 3
@assert ConstTerm(f) == 1
@assert leading(f) == 3
setcoeff!(f, 3, 4)
@assert coeff(f, 3) == 4
f = poly(P, [1, 2, 3])
@assert monic(2x^2 + 1) == x^2 + P(51)
@assert ismonic(monic(f))
@assert LeftShift(f, 2) == x^2 * f
@assert RightShift(LeftShift(f, 2), 2) == f
q, r = DivRem(f^2, x + 1)
@assert q * (x + 1) + r == f^2
@assert GCD((x + 1)^2, x + 1) == x + 1
d, s, t = XGCD(x^2 + 1, x + 1)
@assert d == s * (x^2 + 1) + t * (x + 1)
@assert derivative(f) == 2 + 6x
@assert diff(f) == derivative(f)
@assert evaluate(f, 2) == 17
@assert evaluate(f, [0, 1, 2]) == P.([1, 6, 17])
@assert compose(f, x + 1) == 3x^2 + 8x + 6
@assert CompMod(f, x + 1, x^2 + 1) == rem(compose(f, x + 1), x^2 + 1)
@assert truncate(f^3, 2) == poly(P, [1, 6])
@assert MulTrunc(f, x + 1, 2) == truncate(f * (x + 1), 2)
@assert truncate((1 + x + x^2) * InvTrunc(1 + x + x^2, 3), 3) == one(f)
@assert MulMod(f, x + 1, x^2 + 1) == rem(f * (x + 1), x^2 + 1)
@assert rem(InvMod(x + 1, x^2 + 1) * (x + 1), x^2 + 1) == one(f)
@assert InvModStatus(x + 1, x^2 + 1)[1]
@assert PowerMod(x + 1, 3, x^2 + 1) == rem((x + 1)^3, x^2 + 1)
@assert random_poly(P, 4) isa ModPoly
@assert BuildFromRoots(P, [1, 2]) == x^2 - 3x + 2
@assert evaluate(interpolate(P, [0, 1, 2], [1, 2, 5]), [0, 1, 2]) == P.([1, 2, 5])
@assert !isempty(SquareFreeDecomp((x + 1)^2 * (x + 2)))
@assert !isempty(DistinctDegreeDecomp((x + 1) * (x + 2)))
@assert !isempty(EqualDegreeSplit((x + 1) * (x + 2), 1))
fac = factor((x + 1)^2 * (x + 2))
@assert fac isa PolyFactorization
@assert reconstruct(fac) == (x + 1)^2 * (x + 2)
@assert all(is_irreducible(g) for (g, _) in fac.factors)
@assert is_irreducible(BuildIrred(P, 3))
@assert !isempty(FindRoots((x - 1) * (x - 2)))
@assert FindRoot(x - 2) == P(2)

# GF2 and bit-packed GF2X -------------------------------------------------------
@assert GF2(0) == GF2(0)
@assert GF2(1) + GF2(1) == GF2(0)
@assert GF2(1) * GF2(1) == GF2(1)
@assert Int(GF2(1)) == 1
@assert zero(GF2) == GF2(0)
@assert one(GF2) == GF2(1)
@assert oneunit(GF2) == GF2(1)
@assert iszero(GF2(0))
@assert isone(GF2(1))
g = GF2X(2)
@assert bits(g) == 2
@assert weight(g^2 + g + 1) == 3
@assert NumBits(g^2 + 1) == 3
@assert NumBytes(g^2 + 1) == 1
@assert random_GF2X(5) isa GF2X
@assert to_modpoly(g^2 + 1) isa ModPoly
@assert from_modpoly(to_modpoly(g^2 + 1)) == g^2 + 1
@assert BuildIrredGF2X(3) isa GF2X
@assert is_irreducible(BuildIrredGF2X(3))
@assert (g + 1)^2 == g^2 + 1
facg = factor((g + 1)^3 * (g^2 + g + 1)^2)
@assert facg isa GF2XFactorization
@assert reconstruct(facg) == (g + 1)^3 * (g^2 + g + 1)^2

# Extension fields --------------------------------------------------------------
E = extension_field(P, x^2 + 2)
@assert E isa ExtensionField
@assert ExtensionElem(E, gen(E)) == gen(E) # Retain the NTL-facing constructor spelling.
@assert base_field(E) == P
@assert defining_polynomial(E) == x^2 + 2
@assert extension_degree(E) == 2
@assert cardinality(E) == modulus(P)^2
@assert gen(E)^2 == E(-2)
@assert trace(gen(E)) == P(0)
@assert norm(gen(E)) == P(2)
@assert parent(gen(E)) == E
@assert rep(gen(E)) isa ModPoly
@assert modulus(gen(E)) == defining_polynomial(E)
@assert characteristic(gen(E)) == 101
@assert iszero(zero(E))
@assert isone(one(E))
@assert zero(gen(E)) == zero(E)
@assert one(gen(E)) == one(E)
@assert oneunit(gen(E)) == one(E)
@test_throws DomainError inv(zero(E))
@assert ExtensionElem(E, [1, 1]) == E([1, 1])
@assert ExtensionElem(E, 2) == E(2)
@assert ExtensionElem(E, x^3 + 1) == E(x^3 + 1)
@assert degree(rep(ExtensionElem(E, x^3 + 1))) < extension_degree(E)
@assert ExtensionElem(E, gen(E)) == gen(E)
@assert ExtensionElem(E, gen(E)) isa ExtensionElem

a = E([1, 2]) # 1 + 2t, where t = gen(E) and t^2 = -2
b = E([2, 1])
@assert coefficients(rep(a)) == P.([1, 2])
@assert a + b == E([3, 3])
@assert a - b == E([-1, 1])
@assert -a == E([-1, -2])
@assert a * b == E(rem(rep(a) * rep(b), defining_polynomial(E)))
@assert sqr(a) == a^2
@assert a * inv(a) == one(E)
@assert a / b == a * inv(b)
@assert power(a, 3) == a^3
@assert a^(-2) == inv(a)^2
@assert rand(MersenneTwister(13), E) isa ExtensionElem
@assert length(rand(MersenneTwister(14), E, 2)) == 2
u = xpoly(E)
@assert evaluate(u^2 + a, zero(E)) == a

g2 = GF2X(2)
E2 = GF2E(g2^2 + g2 + 1)
@assert cardinality(E2) == 4
@assert gen(E2)^3 == one(E2)

# Zech extension representation --------------------------------------------------
Z = zech_field(E)
@assert Z isa ZechField
z = ZechElem(Z, Z._generator)
@assert parent(z) == Z
@assert rep(z) isa Int
@assert Int(z) == rep(z)
@assert modulus(z) == defining_polynomial(E)
@assert characteristic(z) == 101
@assert extension_degree(Z) == 2
@assert cardinality(Z) == cardinality(E)
@assert extension_field(Z) == E
@assert extension_element(z) isa ExtensionElem
@assert length(Z) == cardinality(Z)
@assert length(collect(Z)) == cardinality(Z)
@assert iszero(zero(Z))
@assert isone(one(Z))
@assert zero(z) == zero(Z)
@assert one(z) == one(Z)
@assert oneunit(z) == one(Z)
@assert z * inv(z) == one(Z)
@assert z^(cardinality(Z) - 1) == one(Z)
@assert muladd(z, z, one(z)) == z * z + one(z)
@assert iszero(ZechElem(Z, 0))
@assert isone(ZechElem(Z, 1))
@assert hash(z) == hash(z)
@assert rand(MersenneTwister(9), Z) isa ZechElem
@assert rand(MersenneTwister(10), Z, 2) isa Vector

# Matrices ----------------------------------------------------------------------
A = P.([2 3 1; 4 1 5; 3 7 2])
b = P.([1, 2, 3])
@assert det(A) != 0
@assert det_exact(BigInt.(A)) != 0
@assert rank(A) == 3
@assert A * solve(A, b) == b
@assert A * matrix_inverse(A) == P.([1 0 0; 0 1 0; 0 0 1])
S = P.([1 2 3; 2 4 6; 0 1 1])
@assert iszero(det(S))
@assert rank(S) == 2
R, pivots = rref(S)
@assert pivots == [1, 2]
K = nullspace(S)
@assert length(K) == 1
@assert all(iszero, S * K[1])

B = BigInt[1 1 1; -1 0 2; 3 5 6]
result = lll(B)
@assert result.transform * B == result.basis
@assert abs(det_exact(result.transform)) == 1
@assert result.verified
@assert result.mode == :fast
@assert lll(B).basis == result.basis
@assert gram_schmidt_exact(result.basis) isa Tuple

# NTT, generalized FFT, and acceleration -----------------------------------------
NTT_F = PrimeField(193) # 64 divides 193 - 1, so both 32- and 64-point transforms are valid.
omega = root_of_unity(32, NTT_F)
@assert omega^32 == one(omega)
va = rand(MersenneTwister(11), NTT_F, 32)
@assert intt(ntt(va)) == va
vb = rand(MersenneTwister(12), NTT_F, 32)
@assert ntt_convolve(va, vb) == convolve(va, vb)
@assert fft_convolve(va, vb) == convolve(va, vb)
@assert !isempty(FFT_PRIMES)

set_polynomial_acceleration!(true)
@assert polynomial_acceleration()
set_polynomial_acceleration!(false)
@assert !polynomial_acceleration()
set_polynomial_acceleration!(true)
# Extended mathematical interfaces -------------------------------------------------
A0 = BigInt[1 2; 3 4]
cp = charpoly(A0)
@assert cp == poly(BigInt, [-2, -5, 1])
@assert A0^2 - 5A0 - 2one(A0) == zeros(BigInt, 2, 2)
H0, U0 = hnf(A0)
@assert U0 * A0 == H0
@assert abs(det_exact(U0)) == 1

K0 = kernel_integer(BigInt[2 4; 4 8])
@assert BigInt[2 4; 4 8] * K0 == zeros(BigInt, 2, size(K0, 2))
@assert image_integer(BigInt[6 10]) == reshape(BigInt[2], 1, 1)
s0 = solve_integer(BigInt[2 4], BigInt[2])
@assert s0 !== nothing && BigInt[2 4] * s0.x == BigInt[2]

cp6 = content_primitive(-6 * xpoly(BigInt))
@assert cp6.unit == -1 && cp6.content == 6 && cp6.primitive == xpoly(BigInt)
fx = (xpoly(BigInt) + 1)^2 * (xpoly(BigInt) + 2)
f6 = factor_integer_poly(fx)
@assert reconstruct(f6) == fx
@assert all(is_irreducible_integer_poly(g) for (g, _) in f6.factors)
@assert is_irreducible_integer_poly(xpoly(BigInt)^4 + 1)
@assert !is_irreducible_integer_poly(xpoly(BigInt)^4 - 1)

E3, alpha = conway_field(2, 3; symbol = :beta)
@assert conway_polynomial(2, 3) == defining_polynomial(E3)
T3 = GF2E(GF2X(13))
phi = identify(E3, T3)
psi = identify(T3, E3; generator_map = first(b for b in NTL._field_values(E3) if phi(b) == gen(T3)))
for v in NTL._field_values(E3)
    @assert psi(phi(v)) == v
    @assert phi(v + alpha) == phi(v) + phi(alpha)
    @assert phi(v * alpha) == phi(v) * phi(alpha)
    @test trace(v) == trace(phi(v)) && norm(v) == norm(phi(v))
end
@assert parent(convert(T3, alpha)) == T3

@assert minpoly(alpha) == defining_polynomial(E3)
@assert MinPolyMod(rep(alpha), modulus(alpha)) == defining_polynomial(E3)
@assert order(alpha) == cardinality(E3) - 1
@assert is_primitive_root(alpha)
@assert any_primitive_root(E3) == primitive_element(E3)
@assert minimal_primitive_root(E3) == primitive_element(E3)
@assert exp(log(alpha), E3) == alpha
Z3 = enable_zech_multiplication(E3)
@assert Z3 isa ZechField
@assert disable_zech_multiplication(Z3) == E3

f2e = (xpoly(E3) + alpha)^2 * (xpoly(E3) + alpha + 1)
@assert reconstruct(GF2EXFactoring(f2e)) == f2e
@assert reconstruct(ZZ_pEXFactoring(f2e)) == f2e

zint = ZZVec([-big(2)^75, 2, 0])
@assert collect(zint + zint) == 2 .* collect(zint)
@assert copy(zint) !== zint
@assert packed_dot(zint, zint) == big(2)^150 + 4
zgf = GF2XVec(GF2X.([3, 6]))
@assert packed_dot(zgf, zgf) == GF2X(3)^2 + GF2X(6)^2

R97 = BigModRing(97)
v97 = packedfieldvec(R97, [0, 96, -1])
@assert eltype(v97.data) == Int8
@assert v97[2] == R97(-1) && v97[3] == R97(96)

x = xpoly(BigInt)
@assert resultant(x^2 + 1, x + 1) == 2
@assert discriminant(3x^2 + 4x - 1) == 28
@assert first(subresultants(x^2 + 1, x + 1)) == poly(BigInt, 2)
@assert derivative(integrate(6x^2 - 2x + 1)) == 6x^2 - 2x + 1
@assert roots(2x^2 - x - 1) == [1]
@assert length(isolate_real_roots((x - 1)^2 * (x^2 - 2))) == 3
@assert length(isolate_real_roots(x)) == 1

@assert sqrt(RR(4)) == RR(2)
@assert sqrt(xdouble(4)) == xdouble(2)
@assert abs(Float64(sin(quad_float(1))) - sin(1)) < 1e-15
@assert mat_RR([1 0; 0 1]) == BigFloat[1 0; 0 1]

Ab = BigInt[28 18 -1 -6; 29 21 -7 27; -21 6 11 5; -28 -9 24 -7]
zb = bkz(Ab; block_size = 3)
@assert zb.verified && zb.transform * Ab == zb.basis && abs(det_exact(zb.transform)) == 1

cache = ArithmeticCache()
F97c = cached_field(cache, 97)
ac, bc = F97c.([1, 2, 3]), F97c.([5, 6])
@assert cached_ntt_convolve(cache, ac, bc) == convolve(ac, bc)
@assert cached_zech(cache, E3) === cached_zech(cache, E3)
@assert length(cache.roots.values) >= 1
@assert length(cache.twiddles.values) >= 1
@assert parallel_map(identity, BasicThreadPool(2), 1:6) == 1:6
lt = LazyTable{Int, Int}()
get!(lt, 1) do
    19
end
@assert get!(()->19, lt, 1) == 19
@assert Lazy(() -> 42)[] == 42

println("API tour completed successfully.")

C. Exported-interface index

This index contains the canonical public interface, including the 0.14.0 extended mathematical, storage, real-arithmetic and runtime interfaces.

Source layer Exported names demonstrated in the tour
NTL.jl PrimeField, PRIME_FIELD_MIN, PRIME_FIELD_MAX, rep, modulus, characteristic, info, AddMod, SubMod, NegateMod, MulMod, SqrMod, InvMod, InvModStatus, PowerMod, add, sub, negate, mul, sqr, divide, power, muladd, VectorRandom, VectorConv, VectorMulMod, VectorMulMod!, swap
big_mod_ring.jl BigModRing, ModInt, parent
binary.jl GF2, GF2X, bits, weight, NumBits, NumBytes, random_GF2X, GF2XFactorization, BuildIrredGF2X, to_modpoly, from_modpoly
bkz.jl bkz
exact_interfaces.jl charpoly, MinPolyMod, minpoly, hnf, kernel_integer, image_integer, solve_integer
extension.jl ExtensionField, ExtensionElem, extension_field, GF2E, base_field, defining_polynomial, extension_degree, cardinality, gen, trace, norm
extras_runtime.jl RR, xdouble, quad_float, mat_RR, isolate_real_roots, BasicThreadPool, parallel_map, Lazy, LazyTable, ArithmeticCache, cached_field, cached_ntt_convolve, cached_zech
fft.jl fft_convolve, FFT_PRIMES
finite_interfaces.jl conway_field, conway_polynomial, identify, primitive_element, order, is_primitive_root, any_primitive_root, minimal_primitive_root, enable_zech_multiplication, disable_zech_multiplication, GF2EXFactoring, ZZ_pEXFactoring
integer_polys.jl factor_integer_poly, content_primitive, is_irreducible_integer_poly
lattice.jl gram_schmidt_exact, lll
matrix.jl det, matrix_inverse, solve, rank, nullspace, rref, det_exact
numbertheory.jl ProbPrime, MillerWitness, NextPrime, PrevPrime, GenPrime, RandomBits, RandomLen, RandomBnd, FactorInt, EulerPhi, CRT, SqrRootMod, DiscreteLog, PrimitiveRoot
packed.jl ZZVec, GF2XVec, packedfieldvec, packed_dot
poly_extras.jl resultant, discriminant, subresultants, integrate, roots
polynomial.jl ModPoly, poly, xpoly, field, coefficients, coeff, degree, deg, LeadCoeff, ConstTerm, leading, setcoeff!, monic, ismonic, DivRem, GCD, XGCD, derivative, diff, evaluate, compose, LeftShift, RightShift, truncate, MulTrunc, InvTrunc, MulMod, InvMod, InvModStatus, PowerMod, CompMod, random_poly, BuildFromRoots, interpolate, SquareFreeDecomp, DistinctDegreeDecomp, EqualDegreeSplit, PolyFactorization, factor, reconstruct, is_irreducible, BuildIrred, FindRoots, FindRoot
polynomial_mul.jl set_polynomial_acceleration!, polynomial_acceleration, poly_mul
transform.jl primitive_root, root_of_unity, ntt, intt, convolve, ntt_convolve
zech.jl ZechField, ZechElem, zech_field, extension_element

D. Documentation and verification checklist

  • Release documented here: NTL.jl 0.14.0, targeting Julia 1.9 or later and tested with Julia 1.11.7.
  • Full regression suite: 4,648,706 passing assertions, including matrix/quotient polynomials, integer lattices, factorization and domain checks, storage, BKZ, real arithmetic and task/cache tests. An additional 538 optional third-party checks also passed.
  • Every exported name occurs in at least one executable example in api_tour.jl; all 14 original package examples and the new extended tour also passed on the optimized server build.
  • PrimeField(p) is the machine-word prime-field constructor, with the modulus carried by PrimeField{p} at the type level.
  • BigModRing(n) is the arbitrary-precision modular-ring parent and ModInt is its element type.
  • ExtensionElem is the actual concrete extension-element type; ordinary extension construction continues to use E(...).
  • Conway data currently contains 96 records for p ∈ {2,3,5,7,11,13,17,19} and n ∈ 1:12; other pairs raise KeyError.
  • GF2EX/ZZ_pEX specialization applies only when cardinality(E) <= 32 and 1 <= degree(f) <= 12 with a prime base field. Other inputs retain generic factorization.
  • Packed storage reduces payload size but not necessarily read time; current sequential read benchmarks are slower than ordinary vectors.
  • The optional Nemo/FLINT factorization path was about 119× faster than basic Kronecker interpolation for the tested degree-8 integer polynomial, but it is an optional backend rather than a universal guarantee.
  • This page is self-contained: equations use MathML, styling is embedded, and no web framework or network connection is required.