Index of theproofnetwork/open-problems@860a535/Prove2Me/Definitions/Def_ExactDFT_CircuitModel.lean

qedmarket’s copy of theproofnetwork/open-problems@860a535, 3 Dec 2026original source ↗

72 lines · 2.6 kBraw
/-From Prove2Me, definition `ExactDFT_CircuitModel` (https://prove2.me/definitions/302a1203-de24-5039-8bb9-62180705b66e). Apache-2.0 per Prove2Me's terms.-/import Mathlib namespace ExactDFT /-- A binary linear gate forms a weighted sum of two available wires. -/structure BinaryGate (K W : Type*) where  left : W  right : W  leftCoeff : K  rightCoeff : K def BinaryGate.eval {K W : Type*} [Semiring K] (g : BinaryGate K W) (v : W → K) : K :=  g.leftCoeff * v g.left + g.rightCoeff * v g.right /-- An acyclic straight-line program with exactly `s` charged binary linear gates. -/inductive Program (K I : Type*) : ℕ → Type _ where  | nil : Program K I 0  | step {r : ℕ} (p : Program K I r) (g : BinaryGate K (I ⊕ Fin r)) :      Program K I (r + 1) namespace Programvariable {K I : Type*} [Semiring K] /-- Values in the gate registers; the newest gate output is register zero. -/def value : {r : ℕ} → Program K I r → (I → K) → Fin r → K  | _, .nil, _ => Fin.elim0  | _, .step p g, x => Fin.cases (g.eval (Sum.elim x (p.value x))) (p.value x)end Program /-- An output can be zero or a scaled selection of an input or gate register. -/inductive Readout (K W : Type*) where  | zero  | scaled (coeff : K) (wire : W) def Readout.eval {K W : Type*} [Semiring K] (z : Readout K W) (v : W → K) : K :=  match z with  | .zero => 0  | .scaled c w => c * v w /-- A circuit is a straight-line program together with its output readouts. -/structure Circuit (K I O : Type*) (s : ℕ) where  program : Program K I s  output : O → Readout K (I ⊕ Fin s) namespace Circuitvariable {K I O : Type*} [Semiring K] {s : ℕ} def eval (p : Circuit K I O s) (x : I → K) (o : O) : K :=  (p.output o).eval (Sum.elim x (p.program.value x)) /-- The linear map computed by a circuit, represented by its matrix on basis inputs. -/noncomputable def matrix [Fintype I] [Fintype O] (p : Circuit K I O s) : Matrix O I K := by  classical  exact fun o i => p.eval (Pi.single i 1) oend Circuit /-- A matrix is realizable using at most `s` binary linear gates. -/def RealizableAtMost {K I O : Type*} [Semiring K] [Fintype I] [Fintype O]    (M : Matrix O I K) (s : ℕ) : Prop :=  ∃ r ≤ s, ∃ p : Circuit K I O r, p.matrix = M /-- The standard positive-sign, unnormalized complex DFT matrix of length `n`. -/noncomputable def root (n : ℕ) : ℂ :=  Complex.exp (2 * Real.pi * Complex.I / (n : ℂ)) noncomputable def dftMatrix (n : ℕ) : Matrix (Fin n) (Fin n) ℂ :=  fun j k => root n ^ (j.val * k.val) end ExactDFT

download (.tar)