Skip to main content

log_fft/
lib.rs

1//! # log-fft
2//!
3//! Exact Fourier transforms over the Goldilocks field
4//! `F_p`, `p = 2^64 − 2^32 + 1`. The crate also includes executable building
5//! blocks of the construction in *"The logarithmic exponent of finite
6//! Fourier transforms"* (OpenAI preprint, 2026-11-24,
7//! <https://github.com/openai/math>).
8//!
9//! ## Transforms
10//!
11//! * [`Ntt`]: power-of-two NTT (`n ≤ 2^32`), in place.
12//! * [`Dft`]: DFT of **every** length `F_p` supports (`n | p − 1`), using
13//!   Good–Thomas over the coprime factors `2^j, 3, 5, 17, 257, 65537`.
14//! * [`ChirpZ`]: `y_k = Σ_j x_j q^{jk}` for any nonzero `q` and any sizes,
15//!   without needing `√q`.
16//! * [`InverseChirpZ`]: interpolation at geometric nodes `q^0 … q^{n−1}`.
17//!   It uses the paper's Newton factorisation `V = D_H · T · M · Tᵀ · D_H`,
18//!   so it runs in `O(n log n)`.
19//! * [`GroupDft`]: DFT on `Z_{a_1} × … × Z_{a_r}`.
20//! * [`convolve`], [`series_inverse`]: exact polynomial multiplication and
21//!   power-series inversion.
22//!
23//! Everything is exact modular arithmetic, with no rounding.
24//!
25//! ```
26//! use log_fft::{Dft, Fp};
27//! let dft = Dft::new(255); // 255 = 3·5·17
28//! let x: Vec<Fp> = (0..255).map(Fp::new).collect();
29//! let y = dft.forward(&x);
30//! assert_eq!(dft.inverse(&y), x);
31//! ```
32//!
33//! ## About the paper
34//!
35//! The paper proves `N(log N)^{1/2+o(1)}` circuit bounds. Its constants are
36//! non-explicit, and its recursion is defined to use direct transforms for
37//! bounded sizes. From its own cost formulas, any saving needs arrays
38//! beyond about `2^500` entries. So the transforms above are the path the
39//! paper's algorithm takes at every size a computer can hold. The paper's
40//! lemmas themselves (predictor, Hermite repair, matrix root, Newton/Toeplitz
41//! reduction) are implemented and tested in [`paper`].
42
43// Index-heavy numeric code reads more clearly with explicit index loops.
44#![allow(clippy::needless_range_loop)]
45
46pub mod chirp;
47pub mod dft;
48pub mod field;
49pub mod ntt;
50pub mod paper;
51
52pub use chirp::{ChirpZ, InverseChirpZ};
53pub use dft::{is_supported_len, Dft, GroupDft};
54pub use field::Fp;
55pub use ntt::{convolve, series_inverse, Ntt};
56
57#[cfg(doctest)]
58#[doc = include_str!("../README.md")]
59pub struct ReadmeDoctests;