Expand description
Finite Field Arithmetic for Modular GCD Algorithms
This module provides efficient arithmetic in finite fields Z_p (integers mod prime p)
and polynomials over finite fields Z_p[x]. These are foundational for:
- Modular GCD algorithms (Zippel, Brown)
- Chinese Remainder Theorem reconstruction
- Sparse interpolation
- Industrial-strength polynomial computation
- Fast polynomial multiplication via NTT
- Polynomial factorization (Berlekamp, Hensel lifting)
§Mathematical Background
A finite field Z_p contains integers {0, 1, 2, …, p-1} with arithmetic modulo prime p. Every non-zero element has a multiplicative inverse (Fermat’s little theorem: a^(p-1) = 1 mod p).
Key properties exploited:
- Division is always exact (multiplicative inverses exist)
- GCD algorithms terminate in polynomial time
- Evaluation at random points allows sparse reconstruction
- Number Theoretic Transform enables O(n log n) polynomial multiplication
- Factorization over Z_p enables factorization over Z via Hensel lifting
§Module Organization
element:Zptype (field elements)poly:PolyZptype (polynomials over Z_p)gcd: GCD algorithms for PolyZpntt: Fast polynomial multiplication via Number Theoretic Transformberlekamp: Polynomial factorization (Berlekamp’s algorithm, Hensel lifting)bridge: Conversion to/from Expression
§Performance Considerations
Following the Rust Performance Book guidelines:
- Use
u64for field elements to leverage native CPU operations - Avoid branches in hot paths using conditional moves
- Preallocate vectors with known capacity
- Use
#[inline]for small, frequently-called functions - Use NTT for large polynomial multiplication (O(n log n) vs O(n²))
§References
[Zippel79]Zippel, R. “Probabilistic algorithms for sparse polynomials”[GCL92]Geddes, Czapor, Labahn. “Algorithms for Computer Algebra”[CT65]Cooley, Tukey. “An algorithm for the machine calculation of complex Fourier series”
Modules§
- berlekamp
- Polynomial Factorization over Finite Fields
- educational
- Educational explanations for finite field operations
Structs§
Enums§
- Finite
Field Error - Error types for finite field operations
Constants§
- NTT_
PRIME_ 1 - Common NTT-friendly prime: 2013265921 = 15 * 2^27 + 1 Supports NTT up to degree 2^27 - 1
- NTT_
PRIME_ 2 - Common NTT-friendly prime: 469762049 = 7 * 2^26 + 1 Supports NTT up to degree 2^26 - 1
- NTT_
PRIME_ 3 - Common NTT-friendly prime: 1004535809 = 479 * 2^21 + 1 Supports NTT up to degree 2^21 - 1
- NTT_
THRESHOLD - Threshold for switching from naive to NTT multiplication Empirically determined crossover point where NTT becomes faster Lowered to 32 for better performance on medium-sized polynomials
Functions§
- content
- Compute content (GCD of all coefficients)
- extended_
gcd - Extended Euclidean algorithm
- is_
prime - Check if a number is prime using trial division
- multiply_
auto - Multiply two polynomials using automatic threshold-based selection
- ntt_
multiply - Fast polynomial multiplication using optimized NTT
Type Aliases§
- Finite
Field Result - Result type for finite field operations