Bounded-degree incidence queries and randomized testers
DefinitionYoshidaTwoSAT_QueryModelThe oracle reports one incident clause or an empty slot for a selected variable and index. A randomized tester samples an adaptive decision tree of bounded depth. The exact-width subclass consists of clauses on two distinct variables.
import Mathlib.Probability.ProbabilityMassFunction.Constructions
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Definitions.Def_YoshidaTwoSAT_Formula
namespace TwoSAT
/-- Each binary clause is written in increasing variable order. -/
def Clause.canonical {n} : Clause (Fin n) → Prop
| .pair a b => a.var < b.var
| _ => True
abbrev Answer (n : ℕ) := Option (Clause (Fin n))
abbrev Oracle (n d : ℕ) := Fin n → Fin d → Answer n
/-- Soundness and unique coverage tie every non-null slot to the formula. -/
structure Input (n d : ℕ) where
formula : List (Clause (Fin n))
distinct : formula.Nodup
canonical : ∀ c ∈ formula, c.canonical
oracle : Oracle n d
sound : ∀ x i c, oracle x i = some c → c ∈ formula ∧ c.incident x
coverage : ∀ x c, c ∈ formula → c.incident x → ∃! i, oracle x i = some c
/-- An adaptive incidence-query algorithm with a worst-case query budget.
A leaf returns true on rejection. -/
inductive Tree (n d : ℕ) : ℕ → Type where
| leaf {q} (reject : Bool) : Tree n d q
| ask {q} (x : Fin n) (i : Fin d) (next : Answer n → Tree n d q) : Tree n d (q + 1)
def Tree.run {n d : ℕ} (o : Oracle n d) : {q : ℕ} → Tree n d q → Bool
| _, .leaf reject => reject
| _, .ask x i next => Tree.run o (next (o x i))
/-- The random tree is sampled independently of the unknown input. -/
noncomputable def rejection {n d q} (alg : PMF (Tree n d q)) (F : Input n d) : ENNReal :=
(alg.map (fun tr => tr.run F.oracle)) true
end TwoSAT
namespace TwoSAT.Reduction
def Exact {n d} (F : Input n d) : Prop :=
∀ c ∈ F.formula, ∃ a b, c = .pair a b ∧ a.var < b.var
end TwoSAT.Reduction
Read-back
What the Lean code literally says, in plain math · OpenAI GPT-6 (Codex)
For natural numbers , variables range from to and slots from to , with an empty range when the corresponding parameter is zero. A clause is canonical if it is a unit, a tautology, or a pair of literals whose first variable is strictly smaller than its second. An input consists of a finite list of pairwise distinct canonical clauses and a function giving either no clause or one clause for each variable and slot. Every returned clause belongs to the list and is incident to the queried variable. Conversely, for each variable and each listed clause incident to it, exactly one slot at that variable returns the clause. Incidence means being the variable of the unit, the variable carried by the tautology, or either variable of the pair. The distinguished predicate of exactness holds precisely when every listed clause is a pair in strictly increasing variable order. An empty list satisfies this predicate. If either or , the input list must be empty. For any natural budget , a decision tree may be a leaf returning a Boolean. At budget it may instead query a particular variable and slot and specify a subtree of budget for each possible answer. Execution follows the subtree indexed by the actual oracle answer until it reaches a leaf. For any probability mass function on trees of a fixed budget and any input, the rejection value is the probability mass of the trees whose execution against that input's oracle returns true. A run makes at most the budgeted number of queries and may end immediately.