Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Fair-bit Boolean circuits and finite output laws

Definition
FSS23105365_Circuits

by YY · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

finite-staterandomized-ac0sampling

A finite topologically ordered AND/OR/NOT circuit with constants, checked backward wire references, and designated outputs. AND/OR fan-in is unbounded. Input bits are independent fair bits. Depth is the maximum output gate depth; size counts inputs, gates, source wires and output wires. The output probability is its number of seed preimages divided by 2r2^r2r. Exactness requires all outputs to encode outcomes and all outcome masses to match. Support preservation quantifies over every seed. Total variation is half the finite sum of absolute mass differences. Encoders are arbitrary at this foundational interface; each target uses its specified injective encoding.

Definition code
import Mathlib.Data.Real.Basic
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Option
import Mathlib.Algebra.BigOperators.Group.Finset.Basic

set_option autoImplicit false
noncomputable section
namespace FSS23105365
open scoped BigOperators

abbrev Bits (r : ℕ) := Fin r → Bool

inductive Gate where
  | constant (b : Bool)
  | neg (wire : ℕ)
  | conj (wires : List ℕ)
  | disj (wires : List ℕ)

def Gate.sources : Gate → List ℕ
  | .constant _ => []
  | .neg j => [j]
  | .conj js => js
  | .disj js => js

def Gate.eval (values : List Bool) : Gate → Bool
  | .constant b => b
  | .neg j => !(values.getD j false)
  | .conj js => js.all (fun j => values.getD j false)
  | .disj js => js.any (fun j => values.getD j false)

def Gate.depth (depths : List ℕ) (g : Gate) : ℕ :=
  1 + (g.sources.map (fun j => depths.getD j 0)).foldl max 0

/-- Gates are in topological order. Inputs have depth zero; each gate adds one.
The source lists permit unbounded fan-in. All sources must refer to earlier wires. -/
structure Circuit (Out : Type) where
  randomBits : ℕ
  gates : List Gate
  output : Out → ℕ
  gate_valid : ∀ i : Fin gates.length, ∀ j ∈ (gates.get i).sources,
    j < randomBits + i.val
  output_valid : ∀ o, output o < randomBits + gates.length

def Circuit.eval {Out : Type} (C : Circuit Out) (seed : Bits C.randomBits) : Out → Bool :=
  let values := C.gates.foldl (fun vs g => vs ++ [g.eval vs]) (List.ofFn seed)
  fun o => values.getD (C.output o) false

noncomputable def Circuit.depth {Out : Type} [Fintype Out] (C : Circuit Out) : ℕ := by
  classical
  exact
    let ds := C.gates.foldl (fun vs g => vs ++ [g.depth vs])
      (List.replicate C.randomBits 0)
    (List.ofFn (fun i : Fin (Fintype.card Out) =>
      ds.getD (C.output ((Fintype.equivFin Out).symm i)) 0)).foldl max 0

/-- Size counts inputs, gates, gate input wires, and output wires. -/
def Circuit.size {Out : Type} [Fintype Out] (C : Circuit Out) : ℕ :=
  C.randomBits + C.gates.length +
    (C.gates.map (fun g => g.sources.length)).sum + Fintype.card Out

noncomputable def mass {Out Ω : Type} [Fintype Ω]
    (C : Circuit Out) (encode : Ω → (Out → Bool)) (x : Ω) : ℝ := by
  classical
  exact ((Finset.univ.filter (fun seed : Bits C.randomBits =>
    C.eval seed = encode x)).card : ℝ) / (2 : ℝ) ^ C.randomBits

def ValidOutputs {Out Ω : Type} (C : Circuit Out) (encode : Ω → (Out → Bool)) : Prop :=
  ∀ seed : Bits C.randomBits, ∃ x : Ω, C.eval seed = encode x

def ExactLaw {Out Ω : Type} [Fintype Ω] (C : Circuit Out)
    (encode : Ω → (Out → Bool)) (p : Ω → ℝ) : Prop :=
  ValidOutputs C encode ∧ ∀ x, mass C encode x = p x

def SupportPreserving {Out Ω : Type} (C : Circuit Out)
    (encode : Ω → (Out → Bool)) (p : Ω → ℝ) : Prop :=
  ∀ seed : Bits C.randomBits, ∃ x : Ω, C.eval seed = encode x ∧ 0 < p x

noncomputable def tv {Ω : Type} [Fintype Ω] (p q : Ω → ℝ) : ℝ :=
  (∑ x, |p x - q x|) / 2

end FSS23105365
Source
Jiarui Zhang, Chengwei Liang, Haozhe Jiang, Binhang Yuan, Jingzhao Zhang, Revision Provably Reduces Sequential Computation in Diffusion Language Models, Zenodo preprint, 2026-10-02, https://doi.org/10.5281/zenodo.23105365, Section 2, circuit model and Eq. (2); Appendix E.
Human review
  • Endorsed by Shuze Chen · Oct 10, 2026

    Confirmed by the moderator at approval.

  • Endorsed by YY · Oct 10, 2026

    Confirmed by the mission captain (proposal self-audit).

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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me