Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Definitions of ParametersBase: Basic parameters and scalar infrastructure for the low individual degree test Core parameter data, finite-field models,…

Definition
MIPRE_Background_LIDT_MIPStarRE_LDT_Basic_ParametersBase

by thomasvidick · Oct 16, 2026 · Mathlib 0df444a (Lean v4.33.1)

low-degree-testmip-remipre-formalizationpolynomial-time

The definitions of the module MIPRE.Background.LIDT.MIPStarRE.LDT.Basic.ParametersBase of the MIP* = RE formalization (commit 70cbf1c of vidick/MIPRE-formalization). Basic parameters and scalar infrastructure for the low individual degree test. Core parameter data, finite-field models, and coordinate arithmetic. Note: this module contributes declarations to the comparator statement closure of mainFormal, which must elaborate in the same environment as the Mathlib-only Challenge.lean. Keep the full import Mathlib; do not narrow it. See docs/comparator.md, "Environment alignment".

The module is vendored read-only, with the authors' permission, from LionSR/MIPStarRE (Sirui Lu and the MIPStarRE contributors, Apache 2.0; commit and upstream path in the file header) by scripts/vendor-lidt.py.

Definitions (45): MIPStarRE.LDT.Error; MIPStarRE.LDT.FieldModel (A bundled field model for the paper's F_q, together with a coding equivalence to the repository's finite carrier Fin q.); MIPStarRE.LDT.Fq; MIPStarRE.LDT.HonestFq (An honest finite field of order q, obtained from the prime-power witness bundled in Parameters.); MIPStarRE.LDT.LinePolynomialModel; MIPStarRE.LDT.Parameters (Parameters for the (m,q,d) low individual degree test.); MIPStarRE.LDT.Parameters.SuccessorDecomposition (A bundled predecessor for a parameter set known to be a successor dimension.); MIPStarRE.LDT.Parameters.next (The successor test obtained by appending one coordinate.); MIPStarRE.LDT.Parameters.ofPrime (Build parameters when q itself is prime.); MIPStarRE.LDT.Parameters.ofTwo (Convenience constructor for the ubiquitous binary field.); MIPStarRE.LDT.Parameters.previous (The predecessor parameters obtained by removing the last coordinate from a non-base ambient dimension.); MIPStarRE.LDT.Parameters.primePowerFieldSpec (Recover the prime-power specification bundled inside Parameters.); MIPStarRE.LDT.Parameters.successorDecompositionOfNeOne (Non-base parameters have a bundled predecessor decomposition.); MIPStarRE.LDT.Parameters.successorDecompositionOfOneLtM (Every parameter bundle of dimension strictly larger than one has a bundled predecessor whose successor is propositionally equal to the…); MIPStarRE.LDT.Point; MIPStarRE.LDT.PointTuple; and 22 more.

Embedded lemmas (14): the small results the bodies of these definitions need (proof fields, simp rules, decidability and finiteness instances), proved inside the bundle so that it imports no unproved statement: card, one_lt_m_of_ne_one, previous_next_eq, prime_primePower, other_other, addCoord_subCoord_left, addCoord_subCoord_right, decode_encodeScalar, encode_decodeScalar, instNeZeroNatQ, ….

Formalization Note The bundle is the module MIPRE.Background.LIDT.MIPStarRE.LDT.Basic.ParametersBase (MIPRE/Background/LIDT/MIPStarRE/LDT/Basic/ParametersBase.lean) with every declaration not listed removed, imports rewritten to the bundles of the module's import closure; the declarations keep their names, statements and bodies.

Definition code
/-
Copyright (c) 2026 Sirui Lu and the MIPStarRE contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE, with the
authors' permission. Vendored from https://github.com/LionSR/MIPStarRE
(commit 507e8122, 2026-08-25) by scripts/vendor-lidt.py; do not edit by hand.
Upstream path: MIPStarRE/LDT/Basic/ParametersBase.lean
-/
/- Generated for Prove2Me from vidick/MIPRE-formalization@70cbf1c, MIPRE/Background/LIDT/MIPStarRE/LDT/Basic/ParametersBase.lean (definition bundle: declarations the uploaded statements rest on);
   produced mechanically by prove2me/tools/gen.py, never edited by hand. -/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Group.Finsupp
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Algebra.GroupWithZero.Nat
import Mathlib.Algebra.GroupWithZero.Units.Basic
import Mathlib.Algebra.MonoidAlgebra.Defs
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.Algebra.MvPolynomial.Eval
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Ring.Hom.Defs
import Mathlib.Analysis.Matrix.Order
import Mathlib.Data.Finite.Defs
import Mathlib.Data.Finset.Defs
import Mathlib.Data.Finset.Insert
import Mathlib.Data.Finsupp.Defs
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Fintype.Defs
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.FunLike.Basic
import Mathlib.Data.FunLike.Equiv
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Data.List.Nodup
import Mathlib.Data.Multiset.Defs
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Nat.Cast.Defs
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.Real.Basic
import Mathlib.Data.SetLike.Basic
import Mathlib.FieldTheory.Finite.GaloisField
import Mathlib.Logic.Basic
import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Nonempty
import Mathlib.Order.Basic
import Mathlib.Order.Defs.PartialOrder
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Tactic

set_option backward.isDefEq.respectTransparency false

/-!
# Basic parameters and scalar infrastructure for the low individual degree test

Core parameter data, finite-field models, and coordinate arithmetic.

Note: this module contributes declarations to the comparator statement closure
of `mainFormal`, which must elaborate in the same environment as the
Mathlib-only `Challenge.lean`.  Keep the full `import Mathlib`; do not narrow
it.  See `docs/comparator.md`, "Environment alignment".
-/

open scoped BigOperators MatrixOrder Matrix ComplexOrder

namespace MIPStarRE.LDT

abbrev Error := ℝ

inductive Role where
  | A
  | B
  deriving DecidableEq, Repr, Inhabited, Fintype

def Role.other : Role → Role
  | .A => .B
  | .B => .A

@[simp] theorem Role.other_other (r : Role) : r.other.other = r := by
  cases r <;> rfl

/-- Parameters for the `(m,q,d)` low individual degree test.

Besides the usual positivity assumptions, we bundle the paper-faithful witness
that `q = p^n` is a prime power. -/
structure Parameters where
  m : ℕ
  q : ℕ
  d : ℕ
  hm : 0 < m
  /-- Kept as a compatibility field so existing positivity proofs can continue
  to use `params.hq`; it is derivable from `hqPrimePower`. -/
  hq : 0 < q
  /-- Paper-faithful witness that `q` is a prime power. -/
  hqPrimePower : ∃ p n, Nat.Prime p ∧ 0 < n ∧ q = p ^ n

deriving instance DecidableEq for Parameters

namespace Parameters

/-- Prime numbers are prime powers of exponent `1`. -/
theorem prime_primePower {q : ℕ} (hqPrime : Nat.Prime q) :
    ∃ p n, Nat.Prime p ∧ 0 < n ∧ q = p ^ n := by
  exact ⟨q, 1, hqPrime, by decide, by simp⟩

/-- Build parameters when `q` itself is prime. -/
def ofPrime (m q d : ℕ) (hm : 0 < m) (hqPrime : Nat.Prime q) : Parameters :=
  { m := m
    q := q
    d := d
    hm := hm
    hq := hqPrime.pos
    hqPrimePower := prime_primePower hqPrime }

/-- Convenience constructor for the ubiquitous binary field. -/
def ofTwo (m d : ℕ) (hm : 0 < m) : Parameters :=
  ofPrime m 2 d hm Nat.prime_two

end Parameters

instance : Inhabited Parameters where
  default := Parameters.ofTwo 1 0 (by decide)

/-- The successor test obtained by appending one coordinate. -/
def Parameters.next (params : Parameters) : Parameters :=
  { m := params.m + 1
    q := params.q
    d := params.d
    hm := Nat.succ_pos _
    hq := params.hq
    hqPrimePower := params.hqPrimePower }

namespace Parameters

/-- The predecessor parameters obtained by removing the last coordinate from a
non-base ambient dimension.

This is the inverse construction to `Parameters.next` on the data fields.  The
proof fields are inherited from the original parameter bundle, so the inverse is
propositional rather than definitional. -/
def previous (params : Parameters) (hm : 1 < params.m) : Parameters :=
  { m := params.m - 1
    q := params.q
    d := params.d
    hm := Nat.sub_pos_of_lt hm
    hq := params.hq
    hqPrimePower := params.hqPrimePower }

/-- Removing the last coordinate and then applying `Parameters.next` recovers the
original non-base parameters. -/
theorem previous_next_eq (params : Parameters) (hm : 1 < params.m) :
    (previous params hm).next = params := by
  cases params with
  | mk m q d hm0 hq hqPrimePower =>
      have hsub : m - 1 + 1 = m := Nat.sub_add_cancel (le_of_lt hm)
      simp [previous, Parameters.next, hsub]

/-- A bundled predecessor for a parameter set known to be a successor dimension. -/
structure SuccessorDecomposition (params : Parameters) where
  /-- The predecessor parameter bundle. -/
  pred : Parameters
  /-- The predecessor's successor is the original parameter bundle. -/
  next_eq : pred.next = params

/-- Every parameter bundle of dimension strictly larger than one has a bundled
predecessor whose successor is propositionally equal to the original bundle. -/
def successorDecompositionOfOneLtM (params : Parameters) (hm : 1 < params.m) :
    SuccessorDecomposition params where
  pred := previous params hm
  next_eq := previous_next_eq params hm

/-- A positive dimension that is not the base dimension is strictly larger than
one. -/
theorem one_lt_m_of_ne_one (params : Parameters) (hm_ne_one : params.m ≠ 1) :
    1 < params.m :=
  lt_of_le_of_ne params.hm (Ne.symm hm_ne_one)

/-- Non-base parameters have a bundled predecessor decomposition. -/
def successorDecompositionOfNeOne (params : Parameters) (hm_ne_one : params.m ≠ 1) :
    SuccessorDecomposition params :=
  successorDecompositionOfOneLtM params (one_lt_m_of_ne_one params hm_ne_one)

end Parameters

instance {params : Parameters} : NeZero params.q :=
  ⟨Nat.ne_of_gt params.hq⟩

abbrev Fq (params : Parameters) := Fin params.q
abbrev Point (params : Parameters) := Fin params.m → Fq params
abbrev PointTuple (params : Parameters) (k : ℕ) := Fin k → Fq params

instance {params : Parameters} : Inhabited (Fin params.m) :=
  ⟨⟨0, params.hm⟩⟩

instance {params : Parameters} : Inhabited (Fq params) :=
  ⟨⟨0, params.hq⟩⟩

/-- Prime-power metadata extracted from `params.hqPrimePower`, exposing the
honest finite-field carrier `GaloisField p n` underlying the paper's notation
`F_q`. -/
structure PrimePowerFieldSpec (params : Parameters) where
  p : ℕ
  n : ℕ
  pPrime : Nat.Prime p
  nPos : 0 < n
  cardEq : params.q = p ^ n

/-- Recover the prime-power specification bundled inside `Parameters`. -/
noncomputable def Parameters.primePowerFieldSpec
    (params : Parameters) : PrimePowerFieldSpec params :=
  have : Nonempty (PrimePowerFieldSpec params) := by
    obtain ⟨p, n, hp, hn, hq⟩ := params.hqPrimePower
    exact ⟨{
      p := p
      n := n
      pPrime := hp
      nPos := hn
      cardEq := hq
    }⟩
  this.some

/-- An honest finite field of order `q`, obtained from the prime-power
witness bundled in `Parameters`. -/
noncomputable abbrev HonestFq (params : Parameters) (spec : PrimePowerFieldSpec params) :=
  letI : Fact spec.p.Prime := ⟨spec.pPrime⟩
  GaloisField spec.p spec.n

/-- A bundled field model for the paper's `F_q`, together with a coding equivalence
to the repository's finite carrier `Fin q`. -/
class FieldModel (q : ℕ) where
  K : Type*
  instField : Field K
  instFintype : Fintype K
  instDecidableEq : DecidableEq K
  equiv : K ≃ Fin q

attribute [instance_reducible, instance] MIPStarRE.LDT.FieldModel.instField MIPStarRE.LDT.FieldModel.instFintype MIPStarRE.LDT.FieldModel.instDecidableEq

namespace FieldModel

/-- The carrier bundled in a `FieldModel q` has exactly `q` elements, matching the
paper's finite-field convention `|F_q| = q` (`preliminaries.tex`, lines 17--19). -/
@[simp] theorem card (q : ℕ) [FieldModel q] :
    Fintype.card (FieldModel.K q) = q := by
  simpa using Fintype.card_congr (FieldModel.equiv (q := q))

end FieldModel

/-- Build the honest field model from prime-power data. -/
@[reducible] noncomputable def PrimePowerFieldSpec.toFieldModel (params : Parameters)
    (spec : PrimePowerFieldSpec params) : FieldModel params.q := by
  classical
  letI : Fact spec.p.Prime := ⟨spec.pPrime⟩
  let K := HonestFq params spec
  letI : Fintype K := Fintype.ofFinite K
  have hcard : Fintype.card K = params.q := by
    rw [← Nat.card_eq_fintype_card, spec.cardEq]
    simpa [K, HonestFq] using (GaloisField.card (p := spec.p) (n := spec.n) spec.nPos.ne')
  exact
    { K := K
      instField := inferInstance
      instFintype := inferInstance
      instDecidableEq := inferInstance
      equiv := Fintype.equivFinOfCardEq hcard }

/-- The canonical field model associated to the paper-faithful prime-power data
stored in `params`. Lean prefers larger numeric priorities, so this fallback
uses `100` while the `params.next` transport below uses `200`; that lets
instance search reuse an already chosen model when one is available. This
instance is noncomputable because the coding equivalence to `Fin q` is obtained
from finite cardinality data, so declarations that discover it through
typeclass search may also need to be marked `noncomputable` when they reduce
the model. -/
noncomputable instance (priority := 100) (params : Parameters) : FieldModel params.q :=
  PrimePowerFieldSpec.toFieldModel params (Parameters.primePowerFieldSpec params)

/-- Reuse an already chosen field model for successor parameters. Since Lean
prefers larger numeric priorities, this transport uses `200` so it is tried
before the canonical fallback above. -/
instance (priority := 200) {params : Parameters} [inst : FieldModel params.q] :
    FieldModel params.next.q := by
  simpa [Parameters.next] using inst

abbrev Scalar (params : Parameters) [FieldModel params.q] := FieldModel.K params.q
abbrev PolynomialModel (params : Parameters) [FieldModel params.q] :=
  MvPolynomial (Fin params.m) (Scalar params)
abbrev LinePolynomialModel (params : Parameters) [FieldModel params.q] :=
  _root_.Polynomial (Scalar params)

/-- The chosen scalar model for the paper's `F_q` has exactly `q` elements
(`preliminaries.tex`, lines 17--19 and 89--93). -/
@[simp] theorem scalar_card (params : Parameters) [FieldModel params.q] :
    Fintype.card (Scalar params) = params.q := by
  simp [Scalar]

/-- Interpret a coded coordinate in `Fin q` as a scalar in the chosen field model. -/
def decodeScalar {params : Parameters} [FieldModel params.q] (x : Fq params) : Scalar params :=
  (FieldModel.equiv (q := params.q)).symm x

/-- Re-encode a field-model scalar as its canonical representative in `Fin q`. -/
def encodeScalar {params : Parameters} [FieldModel params.q] (x : Scalar params) : Fq params :=
  FieldModel.equiv (q := params.q) x

@[simp] theorem encode_decodeScalar {params : Parameters} [FieldModel params.q] (x : Fq params) :
    encodeScalar (decodeScalar x) = x := by
  simp [encodeScalar, decodeScalar]

@[simp] theorem decode_encodeScalar {params : Parameters} [FieldModel params.q]
    (x : Scalar params) :
    decodeScalar (encodeScalar x) = x := by
  simp [encodeScalar, decodeScalar]

/-- The zero coordinate. -/
def zeroCoord {params : Parameters} [FieldModel params.q] : Fq params :=
  encodeScalar 0

/-- Coordinate addition transported through the `Fin q` coding. -/
def addCoord {params : Parameters} [FieldModel params.q] (x y : Fq params) : Fq params :=
  encodeScalar (decodeScalar x + decodeScalar y)

/-- Coordinate subtraction transported through the `Fin q` coding. -/
def subCoord {params : Parameters} [FieldModel params.q] (x y : Fq params) : Fq params :=
  encodeScalar (decodeScalar x - decodeScalar y)

@[simp] theorem addCoord_subCoord_right {params : Parameters} [FieldModel params.q]
    (x y : Fq params) :
    addCoord y (subCoord x y) = x := by
  unfold addCoord subCoord
  rw [decode_encodeScalar]
  simp [sub_eq_add_neg]

@[simp] theorem addCoord_subCoord_left {params : Parameters} [FieldModel params.q]
    (x y : Fq params) :
    addCoord (subCoord x y) y = x := by
  unfold addCoord subCoord
  rw [decode_encodeScalar]
  simp [sub_eq_add_neg]

@[simp] theorem subCoord_addCoord_right {params : Parameters} [FieldModel params.q]
    (x y : Fq params) :
    subCoord (addCoord x y) y = x := by
  unfold subCoord addCoord
  rw [decode_encodeScalar]
  simp [sub_eq_add_neg]

/-- Coordinate multiplication transported through the `Fin q` coding. -/
def mulCoord {params : Parameters} [FieldModel params.q] (x y : Fq params) : Fq params :=
  encodeScalar (decodeScalar x * decodeScalar y)

/-- Coordinate inversion transported through the `Fin q` coding. -/
def invCoord {params : Parameters} [FieldModel params.q] (x : Fq params) : Fq params :=
  encodeScalar ((decodeScalar x)⁻¹)

/-- Pointwise addition in the coded ambient space. -/
def addPoint {params : Parameters} [FieldModel params.q] (u v : Point params) : Point params :=
  fun i => addCoord (u i) (v i)

/-- Scalar multiplication in the coded ambient space. -/
def smulPoint {params : Parameters} [FieldModel params.q] (t : Fq params) (u : Point params) :
    Point params :=
  fun i => mulCoord t (u i)

/-- The zero point in `F_q^m`. -/
def zeroPoint {params : Parameters} [FieldModel params.q] : Point params :=
  fun _ => zeroCoord

/-- The inclusion of the first `m` coordinates into `m + 1` coordinates. -/
def embedCoord (params : Parameters) : Fin params.m → Fin params.next.m :=
  fun i => ⟨i.1, Nat.lt_trans i.2 (Nat.lt_succ_self params.m)⟩

/-- The last coordinate of `F_q^(m+1)`. -/
def lastCoord (params : Parameters) : Fin params.next.m :=
  ⟨params.m, Nat.lt_succ_self params.m⟩

/-- Append a final coordinate to a point in `F_q^m`. -/
def appendPoint (params : Parameters) (u : Point params) (x : Fq params) : Point params.next :=
  fun i => if h : i.1 < params.m then u ⟨i.1, h⟩ else x

/-- Truncate the last coordinate of a point in `F_q^{m+1}`. -/
def truncatePoint (params : Parameters) (u : Point params.next) : Point params :=
  fun i => u ⟨i.1, Nat.lt_trans i.2 (Nat.lt_succ_self params.m)⟩

/-- Extract the final coordinate of a point in `F_q^{m+1}`. -/
def pointHeight (params : Parameters) (u : Point params.next) : Fq params :=
  u (lastCoord params)

@[simp] theorem truncatePoint_appendPoint (params : Parameters)
    (u : Point params) (x : Fq params) :
    truncatePoint params (appendPoint params u x) = u := by
  funext i
  simp [truncatePoint, appendPoint, i.2]

@[simp] theorem pointHeight_appendPoint (params : Parameters)
    (u : Point params) (x : Fq params) :
    pointHeight params (appendPoint params u x) = x := by
  simp [pointHeight, lastCoord, appendPoint]

/-- Decode a coded point as a tuple of scalars in the chosen field model. -/
def decodePoint {params : Parameters} [FieldModel params.q] (u : Point params) :
    Fin params.m → Scalar params :=
  fun i => decodeScalar (u i)

/-- Evaluate a multivariate polynomial over the chosen field model on a coded point. -/
noncomputable def evalPolynomialModel (params : Parameters) [FieldModel params.q]
    (p : PolynomialModel params) (u : Point params) : Fq params :=
  encodeScalar (MvPolynomial.eval (decodePoint u) p)

/-- Evaluate a univariate polynomial over the chosen field model on a coded point. -/
noncomputable def evalLinePolynomialModel (params : Parameters) [FieldModel params.q]
    (p : LinePolynomialModel params) (t : Fq params) : Fq params :=
  encodeScalar (_root_.Polynomial.eval (decodeScalar t) p)

end MIPStarRE.LDT
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Background/LIDT/MIPStarRE/LDT/Basic/ParametersBase.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me