/- Copyright (c) 2026 Anthropic, PBC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. SPDX-License-Identifier: Apache-2.0 -/ module public import PaperDefs.P01.Notions public import Mathlib.Analysis.Matrix.MeasurableSpace public import Mathlib.LinearAlgebra.Matrix.NonsingularInverse public import Mathlib.MeasureTheory.Group.Measure public import Mathlib.MeasureTheory.Integral.Bochner.Basic public import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace public import Mathlib.Probability.HasLaw public import Mathlib.Probability.Independence.Basic public import Mathlib.Probability.Kernel.Composition.MeasureComp public import Mathlib.Probability.UniformOn public import Mathlib.RingTheory.Ideal.Operations /-! # Paper 1, Part 2 (Sections 9 to 13, with Corollaries 24.8 and 24.9): module lattices over `R = ℤ[x]/(xⁿ + 1)` **What the paper proves.** For module lattices of rank `k` over `R`, in a time that is quasi-polynomial in `n` for `k ≤ log^O(1) n`: * Theorem A, Corollary 9.9: the canonical filtration with a certificate, by a classical program with a sampling oracle and hence by a quantum program. Corollaries 24.8, 24.9: short certificates exist, and semistability is in NP ∩ coNP for bounded rank. * Theorem B: list decoding up to `nd_min/γ`, SIVP and CVP within `O(k n)`, Gaussian samples of width `ς_ε(r) η_det`. * Theorems 9.1 and C: search Module-LWE on random instances. * Theorem D: Module-SIS, and the densest rank-one submodule in rank two, which in an NTRU lattice contains a short key. * `Abstract_allNoiseRates`, from Proposition 13.5: for large `n`, the worst-case problem that [LS15] reduces to Module-LWE, at every noise rate at which polynomially many samples determine the secret. **What is assumed.** Nothing. The printed hypothesis (Sampler) holds by Corollary 1.5. **How to read.** A module lattice `Λ` of ring degree `n`, rank `k` and rank `r = k n` over `ℤ` is written as the Gram matrix of a basis `Λ.b` and the matrix of `ζ` (`Λ.data`); points are written as their coordinates (`rationalPoint`, `latticePoint`). The input of a quantum program has `κ` words, `β = 64 κ` bits, and `steps C n k κ` is `2^(C ln² m_*) β^C` with `m_* = (2n)^(C k²) 2^(C k⁴)`; for programs with an oracle and for certificates, `β` counts the bits (`bitSize`). In `SolvesWithZeroError` the output is right or, with probability at most `1/2`, «failure». `decodingRatio J` is `v_J`, `successiveNormalizedDet X j` is `nd_j(X)`, and `determinantSmoothing` is `η_det`, the maximum of `nd` over the quotients (`Equation_11_1` in `PaperDetails`). Time is counted in steps of the machine; the bounds for the steps also bound the qubits, and a call of an oracle costs steps for all its bits. A filtration with a certificate is written by HNF bases; other returned sublattices are given by generators. **Where things are.** The definitions stand below, in `Notions` and in `Common`. `PaperDetails/P01/PartTwo` has Theorems 10.7 and 11.14, Corollary 13.8 and other steps of the proofs, Remark 9.2, the parameter families of Section 12.5, and the forms `X_detailed`, which name the algorithms. Differences from the print: `docs/departures.md`. -/ @[expose] public section /-! ## Factors in the bounds; lists of points, canonical filtrations and submodules in coordinates -/ namespace QL.P01 open Crypto Matrix Real ModuleLattices /-! ### Factors and bounds -/ /-- The number `ς_ε(r)` of Definition 11.7. -/ noncomputable def widthFactor (ε : ℝ) (r : ℕ) : ℝ := (√r + √(14 * log (2 / ε))) / √(2 * π) /-- The number `Φ_r` of Definition 11.7. -/ noncomputable def approximationFactor (r : ℕ) : ℝ := (√r + 7) ^ 2 / (2 * π) /-- The number `Φ^∞_r` of Theorem D. -/ noncomputable def supremumFactor (r : ℕ) : ℝ := (√r + 7) * √(log (16 * r)) / π /-- `2^(c log^c n) β^c` for `n = 2^a` and an input of `κ` words: quasi-polynomial in `n`, polynomial in `β`. -/ noncomputable def quasiPolynomial (c a κ : ℕ) : ℝ := 2 ^ (c * a ^ c) * (64 * κ) ^ c /-! ### Lists of points -/ /-- The list holds `r` linearly independent vectors of `Λ`. -/ def SpansFully (Λ : ModuleLattice) (list : List (Fin Λ.r → ℤ)) : Prop := list.length = Λ.r ∧ LinearIndependent ℝ fun j : Fin list.length => latticePoint Λ.b list[j] /-- `list` is the list of all `x ∈ Λ` with `‖t - x‖ ≤ ϱ`. -/ def ListsNear (Λ : ModuleLattice) (t : Fin Λ.r → ℚ) (ϱ : ℝ) (list : List (Fin Λ.r → ℤ)) : Prop := list.Nodup ∧ ∀ x, x ∈ list ↔ ‖rationalPoint Λ.b t - latticePoint Λ.b x‖ ≤ ϱ /-! ### Canonical filtrations and their certificates -/ /-- The chain `Y` of sublattices, each given by generators in coordinates, is the canonical filtration of `Λ`. -/ def IsFiltrationOf (Λ : ModuleLattice) (Y : List (List (Fin Λ.r → ℤ))) : Prop := IsCanonicalList (spannedLattice Λ.b) (Y.map (sublattice Λ.b)) /-- The same, and each term is written as its basis in Hermite normal form. -/ def IsWrittenFiltration (Λ : ModuleLattice) (Y : List (List (Fin Λ.r → ℤ))) : Prop := (∀ W ∈ Y, IsHNF (.of W.get)) ∧ IsFiltrationOf Λ Y /-- `verify` is a deterministic polynomial-time program that rejects, with every string, every chain `Y` other than the canonical filtration (Theorem A (b)). -/ def IsSoundVerifier (verify : Prog Empty Empty) (C : ℕ) : Prop := PolyTime verify C ∧ ∀ (Λ : ModuleLattice) Y (string : List Bool), ¬IsFiltrationOf Λ Y → Maps verify C (Λ.data, Y, string) false /-- The string is a short certificate for `Λ` and `Y`. -/ abbrev IsCertificateFor (verify : Prog Empty Empty) (C : ℕ) (Λ : ModuleLattice) (Y : List (List (Fin Λ.r → ℤ))) : List Bool → Prop := IsShortCertificate verify C Λ.k Λ.n Λ.data Y /-! ### Submodules of rank one -/ /-- `L` is a submodule of `Λ` of rank one over `R`, that is of rank `n` over `ℤ`. -/ def IsRankOneSubmodule (Λ : ModuleLattice) (L : Submodule ℤ (EuclideanSpace ℝ (Fin Λ.r))) : Prop := L ≤ spannedLattice Λ.b ∧ (∀ x, rationalPoint Λ.b x ∈ L ↔ rationalPoint Λ.b (Λ.Z *ᵥ x) ∈ L) ∧ latticeRank L = Λ.n /-- The same, and `L` is saturated. -/ def IsSaturatedRankOne (Λ : ModuleLattice) (L : Submodule ℤ (EuclideanSpace ℝ (Fin Λ.r))) : Prop := IsRankOneSubmodule Λ L ∧ IsSaturated L (spannedLattice Λ.b) end QL.P01 /-! ## Classical programs with a filtration oracle A call of the oracle exchanges one word. The program sends the string of a query bit by bit, then fetches the string of the answer bit by bit; `bit` is the bit that a word holds, if any, and `pending log` are the bits sent and fetched since the last answer ended. -/ namespace QL.P01 open Crypto Matrix Real Common Letter ModuleLattices /-- The filtration oracle on strings: the answer to a module lattice is its canonical filtration. There is such an oracle (`FiltrationOraclesExist`). -/ def IsFiltrationOracle (answer : List Bool → List Bool) : Prop := ∀ X : ModuleLattice, ∃ Y, answer (bitsOf X.data) = bitsOf Y ∧ IsWrittenFiltration X Y /-- After the calls `log`, a call that fetches gets the next bit of the answer to the string that has been sent, and no bit after the last one; a call that sends gets no bit. -/ noncomputable def nextLetter (answer : List Bool → List Bool) (log : List (BitVec 64 × BitVec 64)) (q : BitVec 64) : BitVec 64 := word 64 (bitsOf ((bit q).elim (answer (pending log).1)[(pending log).2.length]? fun _ => none)) /-- Definition 9.10. Given `x` and a filtration oracle, the classical program `P` halts within `steps` steps: the list `run.side.log` of its calls of the coin is empty, the first `m` bits `run.out` of its output say a `good` value, and the list `run.side.base.log` of its calls of the oracle holds queries that are module lattices whose list is `allowed`. -/ def WithFiltrationOracle {α β : Type} [Enc α] [Enc β] (P : OracleProgram) (x : α) (steps : ℝ) (allowed : List ModuleLattice → Prop) (good : β → Prop) : Prop := P.classical ∧ ∀ answer, IsFiltrationOracle answer → ∃ m, ∀ N : ℕ, steps ≤ N → ∀ 𝒪 : Oracle (oracleAndCoin 64), (∀ t q, 𝒪 (some none) t q = nextLetter answer t.base.log q) → ∀ run ∈ runsWith P [(wordsOf x).length] N (wordsOf x) 𝒪 m, run.halted ∧ run.side.log = [] ∧ (∃ y, good y ∧ Says run.out y) ∧ ∃ queries, allowed queries ∧ queriesMade run.side.base.log = queries.map (bitsOf ·.data) /-- The queries of Theorem 11.14 (b): at most one of each ring degree; of ring degree `n` and rank `k + 1`, or of ring degree `n / 2^h`, `1 ≤ h ≤ log n`, and rank at most `2 J - 1`; each of at most `bits` bits. -/ def AreDecodingQueries (n k J bits : ℕ) (queries : List ModuleLattice) : Prop := (queries.map (·.n)).Nodup ∧ ∀ X ∈ queries, bitSize X.data ≤ bits ∧ (X.n = n ∧ X.k = k + 1 ∨ ∃ h, 1 ≤ h ∧ h ≤ n.log2 ∧ X.n = n / 2 ^ h ∧ X.k ≤ 2 * J - 1) end QL.P01 /-! ## Module-LWE, NTRU lattices, and the problem M-SLWE of [LS15] (Sections 9, 12 and 13) `R = ℤ[X]/(Xⁿ + 1)`, `n = 2^a`. -/ namespace QL.P01 open Crypto Matrix Real /-! ### Instances, and the hypotheses of Theorems 9.1 and C -/ namespace ModuleLWE open MeasureTheory ProbabilityTheory Negacyclic open ModuleLattices (decodingRatio leastListIndex decodingRank steps) /-- All sets of elements of `R/qR` are measurable. -/ scoped instance {n q : ℕ} : MeasurableSpace (NegacyclicMod n q) := ⊤ /-- Pairs `(s, e) ∈ R^d × R^m`. -/ abbrev Solution (d m n : ℕ) : Type := (Fin d → Negacyclic ℤ n) × (Fin m → Negacyclic ℤ n) variable {Ω : Type} [MeasurableSpace Ω] (μ : Measure Ω) section variable {d m n q : ℕ} [NeZero n] /-- `A s + e` modulo `q`. -/ noncomputable def sample (A : Matrix (Fin m) (Fin d) (NegacyclicMod n q)) (p : Solution d m n) : Fin m → NegacyclicMod n q := A *ᵥ reduceVector q p.1 + reduceVector q p.2 /-- The `(d + m) n` coefficients of `(s, e)`. -/ noncomputable def Solution.coefficient (p : Solution d m n) (i : (Fin d ⊕ Fin m) × Fin n) : ℤ := (Sum.elim p.1 p.2 i.1).coefficients i.2 /-- The point `(ω s, e)`; its norm is `‖(s, e)‖_ω`. -/ noncomputable def Solution.point (ω : ℝ) (p : Solution d m n) : EuclideanSpace ℝ ((Fin d ⊕ Fin m) × Fin n) := .toLp 2 fun i => Sum.elim (fun _ => ω) (fun _ => 1) i.1 * p.coefficient i /-- The output is the list of all solutions `(s, e)` of `u = A s + e` with `‖(s, e)‖_ω ≤ ϱ`, or generators `(x, y)`, `y ≡ A x`, of a sublattice `W ≠ 0` of `Λ_A^ω` with `nd W ≤ c`. -/ def Decodes (ω : ℝ) (A : Matrix (Fin m) (Fin d) (NegacyclicMod n q)) (u : Fin m → NegacyclicMod n q) (ϱ c : ℝ) : List (Solution d m n) ⊕ List (Solution d m n) → Prop := Sum.elim (fun l => l.Nodup ∧ ∀ p, p ∈ l ↔ u = sample A p ∧ ‖p.point ω‖ ≤ ϱ) fun l => (∀ p ∈ l, reduceVector q p.2 = A *ᵥ reduceVector q p.1) ∧ (∃ p ∈ l, p ≠ 0) ∧ Euclid.normalizedDet (Submodule.span ℤ (Solution.point ω '' {p | p ∈ l})) ≤ c /-- The coefficients of `p = (s, e)` are independent random variables. -/ def HasIndependentCoefficients (p : Ω → Solution d m n) : Prop := (∀ i, AEMeasurable (fun ω => (p ω).coefficient i) μ) ∧ iIndepFun (fun i ω => (p ω).coefficient i) μ end /-- `θ_q`, whose `n`-th power is the number of ideals of `R` that divide `q`. -/ noncomputable def idealCountRoot (n q : ℕ) : ℝ := (Nat.card {𝔞 : Ideal (Negacyclic ℤ n) // 𝔞 ∣ Ideal.span {(q : Negacyclic ℤ n)}} : ℝ) ^ (n : ℝ)⁻¹ /-- `𝔼 x² ≤ σ²` -/ def SecondMoment (x : Ω → ℤ) (σ : ℝ) : Prop := Integrable (fun ω => (x ω : ℝ) ^ 2) μ ∧ ∫ ω, (x ω : ℝ) ^ 2 ∂μ ≤ σ ^ 2 /-- The numbers in Theorem C: `n = 2^a`, the ranks, `q`, `γ₀`, `η` and `ω²`. -/ structure Numbers : Type where (a d m q : ℕ) (γ₀ η ωsq : ℚ) namespace Numbers variable (x : Numbers) /-- The degree. -/ abbrev n : ℕ := 2 ^ x.a /-- `k = d + m` -/ abbrev k : ℕ := x.d + x.m /-- The scaling factor. -/ noncomputable abbrev ω : ℝ := √x.ωsq /-- The ranges of the numbers. -/ def Valid : Prop := 1 ≤ x.d ∧ 1 ≤ x.m ∧ 2 ≤ x.q ∧ 1 < x.γ₀ ∧ 0 < x.η ∧ x.η ≤ 1 ∧ 1 ≤ x.ωsq /-- `P`, given `q`, `γ₀`, `η`, `ω²`, `A` and `u` in any number `κ` of words that hold them, `β = 64 κ`, returns a `good` output with zero error within `2^(C ln² m_*) β^C` steps; `m_*` is formed for the rank `k_* = max {k + 1, 2J - 1}`, where `J` is the least integer with `v_J < γ₀`. -/ def Computes (P : Prog Empty Empty) (C : ℕ) (A : Matrix (Fin x.m) (Fin x.d) (NegacyclicMod x.n x.q)) (u : Fin x.m → NegacyclicMod x.n x.q) (good : List (Solution x.d x.m x.n) ⊕ List (Solution x.d x.m x.n) → Prop) : Prop := ∀ κ, SolvesWithZeroError P κ (x.q, x.γ₀, x.η, x.ωsq, A, u) (steps C x.n (decodingRank x.k x.γ₀) κ) good /-- `σ = σ_s^(d/k) σ_e^(m/k)` -/ noncomputable def meanWidth (σs σe : ℝ) : ℝ := σs ^ ((x.d : ℝ) / x.k) * σe ^ ((x.m : ℝ) / x.k) /-- The hypotheses on the widths `σ_s`, `σ_e = ω σ_s` and the number `B₀`. -/ structure HasSmallRatio (σs σe B₀ : ℝ) : Prop where pos : 0 < σs ratio : σe / σs = x.ω one_le : 1 ≤ B₀ /-- (Small ratio) -/ small : x.meanWidth σs σe / x.q ≤ (x.q : ℝ) ^ (-(x.d : ℝ) / x.k) / (2 ^ (x.η : ℝ) * x.γ₀ * √(x.k * x.n)) /-- (Large modulus): `θ_q t₀^k ≤ (q/ω)^(dm/k)` for `t₀ = 10 (ln n + 2)` -/ def HasLargeModulus : Prop := idealCountRoot x.n x.q * (10 * (log x.n + 2)) ^ x.k ≤ (x.q / x.ω) ^ ((x.d * x.m : ℝ) / x.k) /-- A list of at most `(1 + 2/v_J)^(J-1)` members that contains `p`; for `γ₀ > 2` it consists of `p` alone. -/ def IsShortList (p : Solution x.d x.m x.n) (y : List (Solution x.d x.m x.n) ⊕ List (Solution x.d x.m x.n)) : Prop := ∃ l, y = .inl l ∧ p ∈ l ∧ (2 < x.γ₀ → l = [p]) ∧ l.length ≤ (1 + 2 / decodingRatio (leastListIndex x.γ₀)) ^ (leastListIndex x.γ₀ - 1) /-- The first term of the bounds for the probability. -/ noncomputable def badMatrices : ℝ := 12 * (3 / 2) ^ x.k * log (2 * x.q) * exp (-(x.η * x.n) / 5) variable (σs σe B₀ : ℝ) (A : Ω → Matrix (Fin x.m) (Fin x.d) (NegacyclicMod x.n x.q)) (p : Ω → Solution x.d x.m x.n) /-- The hypotheses of Theorem C on `A` and `p = (s, e)`. -/ structure Sampled : Prop where uniform : HasLaw A (uniformOn Set.univ) μ independent : HasIndependentCoefficients μ p secret : ∀ i t, SecondMoment μ (fun ω => (p ω).coefficient (.inl i, t)) σs error : ∀ i t, SecondMoment μ (fun ω => (p ω).coefficient (.inr i, t)) σe /-- The hypotheses of Theorem C (c) on `n`, `q`, `A`, `p = (s, e')` and the rounding `χ`; `z.2` is a uniform residue. -/ structure SampledForRounding (χ : ZMod x.q → ℤ) : Prop where degree : 2 ≤ x.n prime : x.q.Prime uniform : HasLaw A (uniformOn Set.univ) μ independent : HasIndependentCoefficients μ p apart : IndepFun A (fun ω => (p ω).coefficient) μ secret : ∀ i t, SecondMoment μ (fun ω => (p ω).coefficient (.inl i, t)) σs secret_le : ∀ i t, ∀ᵐ ω ∂μ, |((p ω).coefficient (.inl i, t) : ℝ)| ≤ B₀ * σs small : B₀ * σs ≤ √(x.q / x.n) error : ∀ i t, SecondMoment (μ.prod (uniformOn Set.univ)) (fun z : Ω × Fin x.q => (p z.1).coefficient (.inr i, t) + χ (z.2 : ℕ)) σe error_le : ∀ i t, ∀ᵐ z : Ω × Fin x.q ∂μ.prod (uniformOn Set.univ), |(((p z.1).coefficient (.inr i, t) + χ (z.2 : ℕ) : ℤ) : ℝ)| ≤ B₀ * σe /-- The bound for the probability in (a) and (b); the last term is `p₀`. -/ noncomputable def failure : ℝ := x.badMatrices + exp (-x.η ^ 2 * (x.k * x.n) / B₀ ^ 4) + μ.real {ω | (∃ i t, B₀ * σs < |((p ω).coefficient (.inl i, t) : ℝ)|) ∨ ∃ i t, B₀ * σe < |((p ω).coefficient (.inr i, t) : ℝ)|} /-- The bound for the probability in (c). -/ noncomputable def failureRounded : ℝ := x.badMatrices + 2 * exp (-x.η ^ 2 * (x.k * x.n) / (2 * B₀ ^ 4)) + μ.real {ω | (p ω).1 = 0} /-- `e^(-η/3) λ_q ≤ γ₀ ϱ ≤ e^(-η/4) λ_q` for `λ_q = ω^(d/k) q^(m/k)`, the normalized determinant of `Λ_A^ω`. -/ def IsRadius (ϱ : ℝ) : Prop := let scale := x.ω ^ ((x.d : ℝ) / x.k) * (x.q : ℝ) ^ ((x.m : ℝ) / x.k) exp (-x.η / 3) * scale ≤ x.γ₀ * ϱ ∧ x.γ₀ * ϱ ≤ exp (-x.η / 4) * scale end Numbers end ModuleLWE /-! ### NTRU lattices -/ /-- The pair `(u, v)` as the point of its `2 n` coefficients, as above for `d = m = 1` and `ω = 1`: `M_h` is `Λ_A^1` for `A = (h)`. -/ noncomputable def pairPoint {n : ℕ} [NeZero n] (u v : Negacyclic ℤ n) : EuclideanSpace ℝ ((Fin 1 ⊕ Fin 1) × Fin n) := ModuleLWE.Solution.point 1 (fun _ => u, fun _ => v) /-- Definition 13.7: the NTRU lattice `M_h = {(u, v) ∈ R² : v ≡ u h mod q}`. -/ noncomputable def ntruLattice {n q : ℕ} [NeZero n] (h : NegacyclicMod n q) : Submodule ℤ (EuclideanSpace ℝ ((Fin 1 ⊕ Fin 1) × Fin n)) := .span ℤ {x | ∃ u v, x = pairPoint u v ∧ Negacyclic.reduceCoefficients q v = Negacyclic.reduceCoefficients q u * h} /-- The saturated rank-one submodule of `M_h` that contains `(f, g) ≠ 0`: the `(u, v) ∈ M_h` with `u g = v f`. -/ noncomputable def ntruSubmodule {n q : ℕ} [NeZero n] (h : NegacyclicMod n q) (f g : Negacyclic ℤ n) : Submodule ℤ (EuclideanSpace ℝ ((Fin 1 ⊕ Fin 1) × Fin n)) := .span ℤ {x ∈ ntruLattice h | ∃ u v, x = pairPoint u v ∧ u * g = v * f} /-! ### M-SLWE (Definition 13.4) -/ open Filter MeasureTheory ProbabilityTheory /-- `f(n) = ω(√(ln n))`, where `n` ranges over the powers of two. -/ def GrowsFasterThanRootLog (f : ℕ → ℝ) : Prop := Tendsto (fun a : ℕ => f (2 ^ a) / √(log (2 ^ a : ℕ))) atTop atTop /-- `K_ℝ / R^∨`, in coefficients: `R^∨ = (1/n) R`. -/ abbrev Torus (n : ℕ) : Type := EuclideanSpace ℝ (Fin n) ⧸ ((Euclid.integerLattice (Fin n)).comap (LinearMap.lsmul ℤ _ n)).toAddSubgroup /-- The image of `x ∈ K_ℝ` under the embedding that maps `ζ` to `exp (π i (2 j + 1) / n)`. -/ noncomputable def embedding {n : ℕ} (x : EuclideanSpace ℝ (Fin n)) (j : Fin n) : ℂ := ∑ i : Fin n, x i * Complex.exp (π * Complex.I * (2 * j + 1) / n) ^ (i : ℕ) /-- The elliptical Gaussian distribution with the widths `r j` in the canonical embedding, modulo `R^∨`. -/ noncomputable def elliptical {n : ℕ} (r : Fin n → ℝ) : Measure (Torus n) := ((volume.withDensity fun x => .ofReal (∏ j, exp (-π * ‖embedding x j‖ ^ 2 / r j ^ 2)))[|Set.univ]).map QuotientAddGroup.mk /-- The law of a sample `(a, (1/q) ∑ aᵢ sᵢ + e)` of M-SLWE: `a` is uniform in `(R/q)^d` and `e` has the law `ψ`. The secret `s ∈ (R^∨ / q R^∨)^d` is written as `n s ∈ (R/q)^d`. -/ noncomputable def sampleLaw {n q d : ℕ} [NeZero n] (s : Fin d → Fin n → ZMod q) (ψ : Measure (Torus n)) : Measure ((Fin d → Fin n → ZMod q) × Torus n) := ((uniformOn Set.univ).prod ψ).map fun (a, e) => (a, QuotientAddGroup.mk (.toLp 2 fun j => ((∑ i, Negacyclic.ofCoefficients (a i) * Negacyclic.ofCoefficients (s i)).coefficients j).val / (q * n : ℝ)) + e) /-- Some randomized map `𝒜`, of any running time, finds every secret from at most `M` samples with probability at least `p`, for all elliptical Gaussians of widths at most `α` (conjugate embeddings `j`, `n - 1 - j` have one width). -/ def SamplesDetermineSecret (n q d : ℕ) [NeZero n] (α : ℝ) (M : ℕ) (p : ℝ) : Prop := ∃ m ≤ M, ∃ 𝒜 : ProbabilityTheory.Kernel (Fin m → (Fin d → Fin n → ZMod q) × Torus n) (Fin d → Fin n → ZMod q), IsMarkovKernel 𝒜 ∧ ∀ (s : Fin d → Fin n → ZMod q) (r : Fin n → ℝ), (∀ j, 0 < r j ∧ r j ≤ α ∧ r j.rev = r j) → p ≤ (𝒜 ∘ₘ Measure.pi fun _ : Fin m => sampleLaw s (elliptical r)).real {s} end QL.P01 namespace QL.P01 open Crypto Matrix Real ModuleLattices /-! ## Main theorems ### The canonical filtration -/ /-- What Theorem A says of its programs. (b) The polynomial-time program `verify` accepts no other chain. (a), (c) The classical program `find` returns the canonical filtration and a certificate for every sampling oracle, calls it on instances of rank at most `m_*` and of at most `(m_* β)^C` bits, and takes at most `2^(C ln² 2n) (m_* β)^C` steps on average if the oracle is Gaussian. Only `C` depends on the constant `c_s`; the constant `C₀` of the certificate does not (Remark 24.7). -/ def MeetsTheoremA (find : OracleProgram) (verify : Prog Empty Empty) (C₀ : ℕ) : Prop := IsSoundVerifier verify C₀ ∧ ∀ cs, ∃ C : ℕ, ∀ Λ : ModuleLattice, let β := bitSize Λ.data let m := samplingRank C Λ.n Λ.k WithSamplingOracle find cs Λ.data (fun (Y, string) => IsWrittenFiltration Λ Y ∧ IsCertificateFor verify C₀ Λ Y string) m ((m * β) ^ C) (2 ^ (C * log (2 * Λ.n) ^ 2) * (m * β) ^ C) /-- Theorem A: computation and certification of the canonical filtration, given a sampling oracle. -/ def Theorem_A : Prop := ∃ find verify C₀, MeetsTheoremA find verify C₀ /-- For `c ≥ 5` there are Gaussian sampling oracles (proof of Corollary 24.8). -/ def GaussianOraclesExist : Prop := ∀ c ≥ 5, ∃ K, IsGaussianOracle c K /-- Corollary 9.9: a quantum program computes the canonical filtration and a certificate with zero error, within `2^(C ln² m_*) β^C` steps and qubits; the polynomial-time program `verify` accepts no other chain. -/ def Corollary_9_9 : Prop := ∃ P verify C, IsSoundVerifier verify C ∧ ∀ (Λ : ModuleLattice) κ, SolvesWithZeroError P κ Λ.data (steps C Λ.n Λ.k κ) fun (Y, string) => IsWrittenFiltration Λ Y ∧ IsCertificateFor verify C Λ Y string /-- Corollary 24.8. The canonical filtration of every module lattice, its terms given by any generators, has a string of at most `(2kn)^(C k²) β^C` bits that the program `verify` of Theorem A accepts. -/ def Corollary_24_8 : Prop := ∃ find verify C, MeetsTheoremA find verify C ∧ ∀ (Λ : ModuleLattice) Y, IsFiltrationOf Λ Y → ∃ string, IsCertificateFor verify C Λ Y string /-- Corollary 24.9. For module lattices of rank at most `k₀`, the set of the semistable ones is in NP ∩ coNP, and so is the set of triples `(Λ, j, λ²)` with `1 ≤ j ≤ r`, `λ² > 0` and `nd_j(Λ) ≤ λ`. -/ def Corollary_24_9 : Prop := ∀ k₀, let semistable := Promise.language (fun Λ : ModuleLattice => bitsOf Λ.data) fun Λ => Λ.k ≤ k₀ ∧ Semistable (spannedLattice Λ.b) let below := Promise.language (fun ((Λ, j, L) : ModuleLattice × ℕ × ℚ) => bitsOf (Λ.data, j, L)) fun (Λ, j, L) => Λ.k ≤ k₀ ∧ 1 ≤ j ∧ j ≤ Λ.r ∧ 0 < L ∧ successiveNormalizedDet (spannedLattice Λ.b) j ≤ √L (semistable.InNP ∧ semistable.InCoNP) ∧ below.InNP ∧ below.InCoNP /-! ### Decoding, SIVP, CVP, Gaussian samples -/ /-- Theorem B (a): list decoding up to the distance `nd_min(Λ)/γ`. The output is `ϱ²` and the list of all `x ∈ Λ` with `‖t - x‖ ≤ ϱ`. -/ def Theorem_Ba : Prop := ∃ P C, ∀ γ : ℚ, 1 < γ → let J := leastListIndex γ IsLeast {J | 1 ≤ J ∧ decodingRatio J < γ} J ∧ (γ ≤ 2 → J < 1 + 3 / (2 * (γ - 1 : ℝ)) * log (exp 1 / (γ - 1))) ∧ ∀ (Λ : ModuleLattice) (t : Fin Λ.r → ℚ) κ, SolvesWithZeroError P κ (Λ.data, t, γ) (steps C Λ.n (decodingRank Λ.k γ) κ) fun ((radiusSq, list) : ℚ × List (Fin Λ.r → ℤ)) => minNormalizedDet (spannedLattice Λ.b) / γ ≤ √radiusSq ∧ ListsNear Λ t √radiusSq list ∧ list.length ≤ (1 + 2 / decodingRatio J) ^ (J - 1) ∧ (2 < γ → list.length ≤ 1) /-- What Theorem B (b) says of `P`: it computes independent vectors with `‖y_j‖ ≤ Φ_r nd_j(Λ) ≤ Φ_r λ_j(Λ)`. -/ def MeetsTheoremBb (P : Prog Empty Empty) (C : ℕ) : Prop := ∀ (Λ : ModuleLattice) κ, SolvesWithZeroError P κ Λ.data (steps C Λ.n (Λ.k + 1) κ) fun list => SpansFully Λ list ∧ ∀ j : Fin list.length, ‖latticePoint Λ.b list[j]‖ ≤ approximationFactor Λ.r * successiveNormalizedDet (spannedLattice Λ.b) (j + 1) ∧ approximationFactor Λ.r * successiveNormalizedDet (spannedLattice Λ.b) (j + 1) ≤ approximationFactor Λ.r * successiveMinimum (spannedLattice Λ.b) (j + 1) /-- Theorem B (b): approximate SIVP. -/ def Theorem_Bb : Prop := ∃ P C, MeetsTheoremBb P C /-- Theorem B (c): approximate CVP. The output is the point `y` and the number `L²`. -/ def Theorem_Bc : Prop := ∃ P C, ∀ (Λ : ModuleLattice) (target : Fin Λ.r → ℚ) κ, SolvesWithZeroError P κ (Λ.data, target) (steps C Λ.n (Λ.k + 1) κ) fun ((answer, boundSq) : (Fin Λ.r → ℤ) × ℚ) => let t := rationalPoint Λ.b target let y := latticePoint Λ.b answer let distance := Metric.infDist t (spannedLattice Λ.b) ∃ L ≥ (0 : ℝ), L ^ 2 = boundSq ∧ L ≤ distance ∧ distance ≤ ‖t - y‖ ∧ ‖t - y‖ ≤ √(1 + 4 * approximationFactor Λ.r ^ 2) * L ∧ ‖t - y‖ ≤ √(1 / 4 + approximationFactor Λ.r ^ 2) * successiveNormalizedDet (spannedLattice Λ.b) Λ.r ∧ (distance ≤ 0.49 * successiveNormalizedDet (spannedLattice Λ.b) 1 → ∀ x ∈ spannedLattice Λ.b, x ≠ y → ‖t - y‖ < ‖t - x‖) /-- What Theorem B (d) says of `P`: it returns a sample within statistical distance `ε` of the discrete Gaussian `D_{Λ,ς,c}`, for `ς ≥ ς_ε(r) η_det(Λ)`; the width `ς` is given by its square. -/ def MeetsTheoremBd (P : Prog Empty Empty) (C : ℕ) : Prop := ∀ (Λ : ModuleLattice) (c : Fin Λ.r → ℚ) (ε widthSq : ℚ) κ, 0 < ε → ε ≤ 1 / 2 → 0 < widthSq → widthFactor ε Λ.r * determinantSmoothing (spannedLattice Λ.b) ≤ √widthSq → Returns P κ (Λ.data, c, ε, widthSq) (steps C Λ.n (Λ.k + 1) κ) (steps C Λ.n (Λ.k + 1) κ) (Samples (gaussianShare fun x => ‖latticePoint Λ.b x - rationalPoint Λ.b c‖ ^ 2 / widthSq) ε) /-- Theorem B (d): Gaussian samples. -/ def Theorem_Bd : Prop := ∃ P C, MeetsTheoremBd P C /-! ### Module-LWE -/ open Filter MeasureTheory ProbabilityTheory ModuleLWE /-- Theorem 9.1: one quantum program solves search Module-LWE with short secret. It is given `q`, `A` and `A s + e` in `κ` words, so `β = 64 κ`. The bounds for the steps and for «failure» hold on every input. Under the two inequalities, every output other than «failure» is `p = (s, e)`, except with the printed probability over `A`, `s`, `e`. -/ def Theorem_9_1 : Prop := ∃ (P : Prog Empty Empty) (C : ℕ), ∀ a d m q : ℕ, 1 ≤ d → 1 ≤ m → q.Prime → let n := 2 ^ a let k := d + m let Outputs (A : Matrix (Fin m) (Fin d) (NegacyclicMod n q)) (u : Fin m → NegacyclicMod n q) (good : Solution d m n → Prop) : Prop := ∀ κ, SolvesWithZeroError P κ (q, A, u) (2 ^ (C * (k ^ 2 * log n + k ^ 4) ^ 2) * (64 * κ) ^ C) good (∀ A u, Outputs A u fun _ => True) ∧ ∀ σ ≥ (0 : ℝ), ∀ B ≥ (1 : ℝ), 2 * (10 * (log n + 2)) ^ k ≤ (q : ℝ) ^ ((d * m : ℝ) / k) → 3 * σ * √(k * n) ≤ (q : ℝ) ^ ((m : ℝ) / k) → ∀ (Ω : Type) [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (A : Ω → Matrix (Fin m) (Fin d) (NegacyclicMod n q)) (p : Ω → Solution d m n), HasLaw A (uniformOn Set.univ) μ → HasIndependentCoefficients μ p → (∀ i, SecondMoment μ (fun ω => (p ω).coefficient i) σ) → (∀ i, ∀ᵐ ω ∂μ, |((p ω).coefficient i : ℝ)| ≤ B * σ) → μ.real {ω | ¬Outputs (A ω) (sample (A ω) (p ω)) (· = p ω)} ≤ 13 * (3 / 2) ^ k * log (2 * q) * exp (-n / (10 * B ^ 4)) /-- Theorem C, the assertions on the program: one quantum program `P` decodes Module-LWE with zero error within `2^(C ln² m_*) β^C` steps (`Numbers.Computes`). The radius `ϱ` depends on `d`, `m`, `q`, `ω`, `γ₀`, `η` only. On every instance, whatever the modulus (the text after the theorem), `P` returns the list of all solutions of norm at most `ϱ`, or generators `(x, y)`, `y ≡ A x`, of a sublattice `W ≠ 0` of `Λ_A^ω` with `nd W ≤ γ₀ ϱ`. Under (Large modulus) and (Small ratio), `P` returns a list of at most `(1 + 2/v_J)^(J-1)` members with the solution, for `γ₀ > 2` the solution alone, except with the printed probability: (a) on random instances; (b) on the matrix `A' = -A A₁⁻¹` and the vector `u' = u + A' u₁` that come from samples `u₁ = A₁ s₀ + s`, `u = A s₀ + e`, conditionally on an invertible `A₁`, where the secret `s₀` may depend on the other choices; (c) on rounded samples, where for `v = A s + e'` the error is `e' + χ(v)` and the sample is `v + χ(v)`. -/ def Theorem_C : Prop := ∃ (P : Prog Empty Empty) (C : ℕ) (radius : ℕ → ℕ → ℕ → ℚ → ℚ → ℚ → ℝ), ∀ x : Numbers, x.Valid → let ϱ := radius x.d x.m x.q x.ωsq x.γ₀ x.η x.IsRadius ϱ ∧ (∀ A u, x.Computes P C A u (Decodes x.ω A u ϱ (x.γ₀ * ϱ))) ∧ ∀ σs σe B₀, x.HasSmallRatio σs σe B₀ → x.HasLargeModulus → ∀ (Ω : Type) [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] A p, -- (a) (x.Sampled μ σs σe A p → μ.real {ω | ¬x.Computes P C (A ω) (sample (A ω) (p ω)) (x.IsShortList (p ω))} ≤ x.failure μ σs σe B₀ p) ∧ -- (b) (∀ (A₁ : Ω → Matrix (Fin x.d) (Fin x.d) (NegacyclicMod x.n x.q)) (s₀ : Ω → Fin x.d → NegacyclicMod x.n x.q), let u₁ ω := A₁ ω *ᵥ s₀ ω + Negacyclic.reduceVector x.q (p ω).1 let u ω := A ω *ᵥ s₀ ω + Negacyclic.reduceVector x.q (p ω).2 let A' ω := -(A ω * (A₁ ω)⁻¹) x.Sampled μ σs σe A p → HasLaw A₁ (uniformOn Set.univ) μ → IndepFun A₁ (fun ω => (A ω, (p ω).coefficient)) μ → ∀ B, IsUnit B → (μ[|A₁ ⁻¹' {B}]).real {ω | ¬x.Computes P C (A' ω) (u ω + A' ω *ᵥ u₁ ω) (x.IsShortList (p ω))} ≤ x.failure μ σs σe B₀ p) ∧ -- (c) ∀ χ : ZMod x.q → ℤ, let rounded ω : Solution x.d x.m x.n := ((p ω).1, (p ω).2 + fun i => ofCoefficients fun t => χ ((sample (A ω) (p ω) i).coefficients t)) x.SampledForRounding μ σs σe B₀ A p χ → μ.real {ω | ¬x.Computes P C (A ω) (sample (A ω) (rounded ω)) (x.IsShortList (rounded ω))} ≤ x.failureRounded μ B₀ p /-- Theorem C (b), the assertions on `A₁`: if it is invertible, then `s₀ = A₁⁻¹ (u₁ - s)`; a uniform `A₁` is invertible with probability at least `1/2` for an odd prime `q`, and at least `1/(8 ln^(1/2) 2q)` for every `q ≥ 2`. -/ def Theorem_C_invertible : Prop := ∀ a d q : ℕ, 2 ≤ q → (∀ (A₁ : Matrix (Fin d) (Fin d) (NegacyclicMod (2 ^ a) q)) s₀ s u₁, IsUnit A₁ → u₁ = A₁ *ᵥ s₀ + s → s₀ = A₁⁻¹ *ᵥ (u₁ - s)) ∧ let p := (uniformOn Set.univ).real {A₁ : Matrix (Fin d) (Fin d) (NegacyclicMod (2 ^ a) q) | IsUnit A₁} (q.Prime → q ≠ 2 → 1 / 2 ≤ p) ∧ 1 / (8 * √(log (2 * q))) ≤ p /-! ### Module-SIS and rank two -/ /-- Theorem D (a). For `1 ≤ d < k`, `q ≥ 2` and every matrix `A` over `R/q`, a quantum algorithm computes with zero error a vector `y ≠ 0` of `R^k` with `A y = 0` modulo `q`, `‖y‖ ≤ Φ_(kn) q^(d/k)` and `‖y‖_∞ ≤ Φ^∞_(kn) q^(d/k)`. (On coefficient vectors this is the problem `ModuleSIS` of paper 2.) -/ def Theorem_Da : Prop := ∃ (P : Prog Empty Empty) (C : ℕ), ∀ (a d k q : ℕ) (A : Matrix (Fin d) (Fin k) (NegacyclicMod (2 ^ a) q)) (κ : ℕ), 1 ≤ d → d < k → 2 ≤ q → SolvesWithZeroError P κ (q, A) (steps C (2 ^ a) k κ) fun y : Fin k → Negacyclic ℤ (2 ^ a) => y ≠ 0 ∧ A *ᵥ Negacyclic.reduceVector q y = 0 ∧ Negacyclic.vectorNorm y ≤ approximationFactor (k * 2 ^ a) * (q : ℝ) ^ ((d : ℝ) / k) ∧ ∀ i j, |((y i).coefficients j : ℝ)| ≤ supremumFactor (k * 2 ^ a) * (q : ℝ) ^ ((d : ℝ) / k) /-- What Theorem D (b) says of its programs. For a module lattice `M` of rank two, the quantum program `P` returns with zero error a chain of HNF bases and a certificate; the polynomial-time program `verify` accepts no chain but the canonical filtration. The chain is `0 ⊊ L ⊊ M` with the unique saturated rank-one submodule `L` with `nd L < nd M`, if there is one. Otherwise it is `0 ⊊ M`, so the string certifies that `M` is semistable. -/ def MeetsTheoremDb (P verify : Prog Empty Empty) (C : ℕ) : Prop := IsSoundVerifier verify C ∧ ∀ (Λ : ModuleLattice) κ, Λ.k = 2 → let M := spannedLattice Λ.b SolvesWithZeroError P κ Λ.data (steps C Λ.n 2 κ) fun ((chain : List (List (Fin Λ.r → ℤ))), string) => (∀ W ∈ chain, IsHNF (.of W.get)) ∧ IsCertificateFor verify C Λ chain string ∧ ((∃ L, chain.map (sublattice Λ.b) = [⊥, L, M] ∧ ∀ L', IsSaturatedRankOne Λ L' ∧ normalizedDet L' < normalizedDet M ↔ L' = L) ∨ chain.map (sublattice Λ.b) = [⊥, M] ∧ ∀ L', IsSaturatedRankOne Λ L' → normalizedDet M ≤ normalizedDet L') /-- Theorem D (b): the densest rank-one submodule in rank two. -/ def Theorem_Db : Prop := ∃ P verify C, MeetsTheoremDb P verify C /-- The text after Theorem D, on NTRU lattices. Let `L` be the saturated rank-one submodule of `M_h` that contains `(f, g) ≠ 0` (a secret key, for instance), and `nd L < √q`. The program of Theorem D (b) returns `L` on every module lattice `Λ` that writes `M_h`, up to an isometry `φ`; and a quantum program that is given `q` and `h` computes generators of `L` with zero error. -/ def Theorem_D_NTRU : Prop := (∀ P verify C, MeetsTheoremDb P verify C → ∀ (a q : ℕ) (h : NegacyclicMod (2 ^ a) q) (f g : Negacyclic ℤ (2 ^ a)), let L := ntruSubmodule h f g 2 ≤ q → (f, g) ≠ 0 → Negacyclic.reduceCoefficients q g = Negacyclic.reduceCoefficients q f * h → normalizedDet L < √q → ∀ (Λ : ModuleLattice) (φ : _ →ₗ[ℝ] EuclideanSpace ℝ (Fin Λ.r)) κ, Λ.k = 2 → linearImage φ (ntruLattice h) = spannedLattice Λ.b → (∀ x ∈ linearSpan (ntruLattice h), ‖φ x‖ = ‖x‖) → SolvesWithZeroError P κ Λ.data (steps C Λ.n 2 κ) fun ((chain, _) : List (List (Fin Λ.r → ℤ)) × List Bool) => chain.map (sublattice Λ.b) = [⊥, linearImage φ L, spannedLattice Λ.b]) ∧ ∃ (P : Prog Empty Empty) (C : ℕ), ∀ (a q : ℕ) (h : NegacyclicMod (2 ^ a) q) (f g : Negacyclic ℤ (2 ^ a)) (κ : ℕ), let L := ntruSubmodule h f g 2 ≤ q → (f, g) ≠ 0 → Negacyclic.reduceCoefficients q g = Negacyclic.reduceCoefficients q f * h → normalizedDet L < √q → SolvesWithZeroError P κ (q, h) (steps C (2 ^ a) 2 κ) fun l : List (Negacyclic ℤ (2 ^ a) × Negacyclic ℤ (2 ^ a)) => L = .span ℤ ((fun p => pairPoint p.1 p.2) '' {p | p ∈ l}) /-! ### The sentences of the abstract on ranks `k ≤ log^O(1) n` The ring degree is `n = 2^a ≥ 2`, so `a = log n`; for every `b` one constant `c` serves all ranks `k ≤ a^b`. -/ /-- Abstract: the canonical filtration, and SIVP and CVP within factors `O(k n)`. -/ def Abstract_smallRanks : Prop := ∃ (P₀ P₁ P₂ : Prog Empty Empty) (K : ℝ), ∀ b, ∃ c, ∀ a ≥ 1, ∀ Λ : ModuleLattice, Λ.n = 2 ^ a → Λ.k ≤ a ^ b → ∀ κ, SolvesWithZeroError P₀ κ Λ.data (quasiPolynomial c a κ) (IsFiltrationOf Λ) ∧ (SolvesWithZeroError P₁ κ Λ.data (quasiPolynomial c a κ) fun list => SpansFully Λ list ∧ ∀ j : Fin list.length, ‖latticePoint Λ.b list[j]‖ ≤ K * (Λ.k * Λ.n) * successiveMinimum (spannedLattice Λ.b) (j + 1)) ∧ ∀ t, SolvesWithZeroError P₂ κ (Λ.data, t) (quasiPolynomial c a κ) fun y : Fin Λ.r → ℤ => ‖rationalPoint Λ.b t - latticePoint Λ.b y‖ ≤ K * (Λ.k * Λ.n) * Metric.infDist (rationalPoint Λ.b t) (spannedLattice Λ.b) /-- Abstract: for all large `n`, Mod-GIVP with the factor `γ = √(8 N d) f(n) / α` of Proposition 13.5, for every noise rate `α` at which `n^e` samples determine the secret with probability `n^(-e')`. -/ def Abstract_allNoiseRates : Prop := ∃ P : Prog Empty Empty, ∀ b, ∃ c, ∀ f, GrowsFasterThanRootLog f → ∀ e e' : ℕ, ∀ᶠ a : ℕ in atTop, ∀ (Λ : ModuleLattice) (q κ : ℕ) (α ε : ℝ), Λ.n = 2 ^ a → Λ.k ≤ a ^ b → 0 < α → α < 1 → 2 * √Λ.k * f Λ.n < α * q → SamplesDetermineSecret (2 ^ a) q Λ.k α ((2 ^ a) ^ e) (1 / (2 ^ a : ℕ) ^ e') → 0 < ε → ε ≤ 1 / 2 → SolvesWithZeroError P κ Λ.data (quasiPolynomial c a κ) fun list => SpansFully Λ list ∧ ∀ v ∈ list, ‖latticePoint Λ.b v‖ ≤ √(8 * Λ.r * Λ.k) * f Λ.n / α * smoothingParameter ε (spannedLattice Λ.b) /-- Abstract: in rank two, the densest rank-one submodule `L`, if it is denser than the lattice, as the middle term of a chain. In an NTRU lattice `M_h` with a key of norm below `√q`, the submodule `L` of the key is the middle term of the canonical filtration, and `nd L < √q = nd M_h`; so the program of `Theorem_D_NTRU` computes it. -/ def Abstract_densestSubmodule : Prop := (∃ (P : Prog Empty Empty) (c : ℕ), ∀ a ≥ 1, ∀ Λ : ModuleLattice, Λ.n = 2 ^ a → Λ.k = 2 → ∀ L, IsRankOneSubmodule Λ L → (∀ L', IsRankOneSubmodule Λ L' → normalizedDet L ≤ normalizedDet L') → normalizedDet L < normalizedDet (spannedLattice Λ.b) → ∀ κ, SolvesWithZeroError P κ Λ.data (quasiPolynomial c a κ) fun chain : List (List (Fin Λ.r → ℤ)) => chain.map (sublattice Λ.b) = [⊥, L, spannedLattice Λ.b]) ∧ ∀ (a q : ℕ) (h : NegacyclicMod (2 ^ a) q) (f g : Negacyclic ℤ (2 ^ a)), let L := ntruSubmodule h f g 2 ≤ q → (f, g) ≠ 0 → Negacyclic.reduceCoefficients q g = Negacyclic.reduceCoefficients q f * h → ‖pairPoint f g‖ < √q → pairPoint f g ∈ L ∧ normalizedDet L < √q ∧ normalizedDet (ntruLattice h) = √q ∧ IsCanonicalList (ntruLattice h) [⊥, L, ntruLattice h] /-- Abstract, Module-LWE: for all large `n`, rank `d` and `d` samples, independent coefficients in `[-σ, σ]`, `σ ≥ 1`, and primes `q` with `K d σ² n ≤ q ≤ 2^n`, the output is `p = (s, e)` or «failure», except with probability `exp(-n/20)` over the instance. -/ def Abstract_moduleLWE : Prop := ∃ (P : Prog Empty Empty) (K : ℝ), ∀ b, ∃ c, ∀ᶠ a : ℕ in atTop, ∀ (d q : ℕ) (σ : ℝ), 1 ≤ d → d ≤ a ^ b → q.Prime → 1 ≤ σ → K * d * σ ^ 2 * (2 ^ a : ℕ) ≤ q → q ≤ 2 ^ 2 ^ a → ∀ (Ω : Type) [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] (A : Ω → Matrix (Fin d) (Fin d) (NegacyclicMod (2 ^ a) q)) (p : Ω → Solution d d (2 ^ a)), HasLaw A (uniformOn Set.univ) μ → HasIndependentCoefficients μ p → (∀ i, ∀ᵐ ω ∂μ, |((p ω).coefficient i : ℝ)| ≤ σ) → μ.real {ω | ¬∀ κ, SolvesWithZeroError P κ (q, A ω, sample (A ω) (p ω)) (quasiPolynomial c a κ) (· = p ω)} ≤ exp (-(2 ^ a : ℕ) / 20) /-- Abstract, Module-SIS: a solution within a factor `O(√(k n))` of the bound `√(k n) q^(d/k)` in Minkowski's first theorem, for all moduli `q ≥ 2`. -/ def Abstract_moduleSIS : Prop := ∃ (P : Prog Empty Empty) (K : ℝ), ∀ b, ∃ c, ∀ a ≥ 1, ∀ (d k q : ℕ) (A : Matrix (Fin d) (Fin k) (NegacyclicMod (2 ^ a) q)), 1 ≤ d → d < k → k ≤ a ^ b → 2 ≤ q → ∀ κ, SolvesWithZeroError P κ (q, A) (quasiPolynomial c a κ) fun y : Fin k → Negacyclic ℤ (2 ^ a) => y ≠ 0 ∧ A *ᵥ Negacyclic.reduceVector q y = 0 ∧ Negacyclic.vectorNorm y ≤ K * √(k * (2 ^ a : ℕ)) * (√(k * (2 ^ a : ℕ)) * (q : ℝ) ^ ((d : ℝ) / k)) /-! ## Further theorems -/ open Euclid in /-- Theorem 10.1. Every Euclidean lattice `X` has exactly one chain of primitive sublattices with semistable quotients of increasing normalized determinants. Isometries of `X` preserve its terms. The chain is the canonical filtration. For a module lattice of rank `k`, the terms are submodules and `s ≤ k`. -/ def Theorem_10_1 : Prop := (∀ (F : Type) [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] (X : Submodule ℤ F), IsDiscreteLattice X → ∃ Y s, IsStableChain X Y s ∧ (∀ Y' s', IsStableChain X Y' s' → s' = s ∧ ∀ i ≤ s, Y' i = Y i) ∧ (∀ f : F →ₗ[ℝ] F, linearImage f X = X → (∀ x ∈ linearSpan X, ‖f x‖ = ‖x‖) → ∀ i ≤ s, linearImage f (Y i) = Y i) ∧ IsCanonical X Y s) ∧ ∀ (Λ : ModuleLattice) Y s, IsCanonical (spannedLattice Λ.b) Y s → s ≤ Λ.k ∧ ∀ i ≤ s, ∀ x, rationalPoint Λ.b x ∈ Y i ↔ rationalPoint Λ.b (Λ.Z *ᵥ x) ∈ Y i open Euclid in /-- Corollary 11.4 (c), for a Euclidean lattice `X` of rank `r ≥ 1`: `nd_j ≤ λ_j`, `λ_1 ≤ √r nd_1` and `(2/3) nd_r ≤ η_(1/2)`. -/ def Corollary_11_4c : Prop := ∀ (F : Type) [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] (X : Submodule ℤ F), IsDiscreteLattice X → X ≠ ⊥ → let r := latticeRank X (∀ j ∈ Set.Icc 1 r, successiveNormalizedDet X j ≤ successiveMinimum X j) ∧ successiveMinimum X 1 ≤ √r * successiveNormalizedDet X 1 ∧ 2 / 3 * successiveNormalizedDet X r ≤ smoothingParameter (1 / 2) X /-- There is a filtration oracle; the two statements below hold for every such oracle. -/ def FiltrationOraclesExist : Prop := ∃ answer, IsFiltrationOracle answer /-- The existence form of Theorem 11.14, which `PaperDetails` states of Construction 11.13: list decoding reduces to the canonical filtration. Given `(Λ, t, ϱ², J)` in `β` bits, a deterministic program with a filtration oracle returns the list of all `x ∈ Λ` with `‖t - x‖ ≤ ϱ`, or a sublattice `W ≠ 0` with `nd(W) ≤ v_J ϱ`; if `v_J ϱ < nd_min(Λ)`, it returns the list, which has at most `(1 + 2/v_J)^(J-1)` members. It takes at most `2^((J+1)²) β^C` steps and asks at most one query of each ring degree, of rank `k + 1` or at most `2J - 1`. -/ def Statement_listDecoding : Prop := ∃ P C, ∀ (Λ : ModuleLattice) (t : Fin Λ.r → ℚ) (radiusSq : ℚ) (J : ℕ), 0 < radiusSq → 1 ≤ J → let β := bitSize (Λ.data, t, radiusSq, J) WithFiltrationOracle P (Λ.data, t, radiusSq, J) (2 ^ (J + 1) ^ 2 * β ^ C) (AreDecodingQueries Λ.n Λ.k J (β ^ C)) fun output : List (Fin Λ.r → ℤ) ⊕ List (Fin Λ.r → ℤ) => (output.elim (ListsNear Λ t √radiusSq) fun W => sublattice Λ.b W ≠ ⊥ ∧ normalizedDet (sublattice Λ.b W) ≤ decodingRatio J * √radiusSq) ∧ (decodingRatio J * √radiusSq < minNormalizedDet (spannedLattice Λ.b) → ∃ list, output = .inl list ∧ (list.length : ℝ) ≤ (1 + 2 / decodingRatio J) ^ (J - 1)) /-- Corollary 12.2: Module-LWE reduces to the canonical filtration. Given `(q, A, u, ω², J, ϱ²)`, a deterministic program with a filtration oracle returns the list of all solutions `(s, e)` with `‖(ω s, e)‖ ≤ ϱ`, or generators of a sublattice `W ≠ 0` of `Λ_A^ω = {(ω x, y) : y ≡ A x}` with `nd(W) ≤ v_J ϱ`. The steps and the queries are bounded as in Theorem 11.14, for `k = d + m`. -/ def Corollary_12_2 : Prop := ∃ P C, ∀ (a d m q : ℕ) (A : Matrix (Fin m) (Fin d) (NegacyclicMod (2 ^ a) q)) (u : Fin m → NegacyclicMod (2 ^ a) q) (ωsq : ℚ) (J : ℕ) (radiusSq : ℚ), 1 ≤ d → 1 ≤ m → 2 ≤ q → 1 ≤ ωsq → 1 ≤ J → 0 < radiusSq → let β := bitSize (q, A, u, ωsq, J, radiusSq) WithFiltrationOracle P (q, A, u, ωsq, J, radiusSq) (2 ^ (J + 1) ^ 2 * β ^ C) (AreDecodingQueries (2 ^ a) (d + m) J (β ^ C)) (Decodes √ωsq A u √radiusSq (decodingRatio J * √radiusSq)) /-- Proposition 13.5 (a), for `Λ` of rank `d = Λ.k` and `N = n d = Λ.r ≥ 9`; `F` is the value `f(n)`, and `γ = √(8 N d) f(n) / α`. If `α ≤ f(n)/√n`, then `γ ≥ √8 N ≥ (3/2) Φ_N`, and a quantum program solves Mod-GIVP within the steps of Theorem B (b): it computes `N` linearly independent vectors of norm at most `γ η_ε(Λ)`. Here `ε` is any number in `(0, 1/2]`; the other printed hypotheses on `f`, `α` and `q` are not needed. -/ def Proposition_13_5a : Prop := ∃ P C, ∀ (Λ : ModuleLattice) κ (F α ε : ℝ), let γ := √(8 * Λ.r * Λ.k) * F / α 0 < α → α ≤ F / √Λ.n → 9 ≤ Λ.r → 0 < ε → ε ≤ 1 / 2 → √8 * Λ.r ≤ γ ∧ 3 / 2 * approximationFactor Λ.r ≤ √8 * Λ.r ∧ SolvesWithZeroError P κ Λ.data (steps C Λ.n (Λ.k + 1) κ) fun y : List (Fin Λ.r → ℤ) => SpansFully Λ y ∧ ∀ v ∈ y, ‖latticePoint Λ.b v‖ ≤ γ * smoothingParameter ε (spannedLattice Λ.b) /-- Proposition 13.5 (b). If `α > f(n)/√n`, the spherical Gaussian of width `α` is within negligible statistical distance of the uniform distribution on `K_ℝ / R^∨`, and no algorithm solves M-SLWE from `n^e` samples with probability `n^(-c)`. -/ def Proposition_13_5b : Prop := ∀ f, GrowsFasterThanRootLog f → ∀ c e : ℕ, ∀ᶠ a : ℕ in atTop, ∀ (d q : ℕ) (α : ℝ), let n := 2 ^ a 1 ≤ d → 0 < α → α < 1 → 2 * √d * f n < α * q → f n / √n < α → (∀ uniform : Measure (Torus n), IsProbabilityMeasure uniform → uniform.IsAddLeftInvariant → ∀ A, MeasurableSet A → |(elliptical fun _ => α).real A - uniform.real A| ≤ 1 / n ^ c) ∧ ¬SamplesDetermineSecret n q d α (n ^ e) (1 / n ^ c) end QL.P01