Shared first-order counter-program control #
Compile Mathlib first-order formulas using one counter per bound variable. Equality compares compiled term expressions; relation atoms execute a single supplied branch/read instruction. Implication and universal quantification use the existing fixed-control model-checking recursion. The atomic-handler correctness hypothesis is discharged by each concrete model checker.
This factors the control proof of the original order-free model checker without changing its code lengths, quantifier order or empty-universe behavior.
Main definitions #
Cslib.Logic.FO.boundDepth: the register depth of a bounded formula.Cslib.Logic.Vocabulary.ModelChecker.AtomicCompiler: term and relation handlers.Cslib.Logic.Vocabulary.ModelChecker.formulaCodeWith: shared formula compilation.
Main results #
Cslib.Logic.Vocabulary.ModelChecker.reaches_formulaCodeWith: semantic correctness and register preservation, from the actual atomic-handler proofs.Cslib.Logic.FO.boundDepth_eq_add_quantifierRank: the register depth is the number of bound variables in scope plus the quantifier rank.
References #
The number of bound variables in scope at the deepest point of a formula: the nesting depth of its quantifiers, plus the number of bound variables in scope at the formula itself.
Instances For
The register depth of a formula is the number of bound variables in scope plus its quantifier rank.
Compile terms to arithmetic expressions and relations to one branch/read instruction.
The handlers do not change registers. Their semantics are proved by AtomicCompiler.Correct.
- term {k : ℕ} : L.Term (α ⊕ Fin k) → Turing.CounterProgram.Expr
The expression computing a term, for every number of bound variables.
The instruction branching on a relation atom.
Instances For
The atomic handlers realize terms and relations in a concrete input structure, without changing the assignment registers. This is an internal compiler specification, not a hypothesis of the concrete query-language membership theorems.
- term {k : ℕ} (regs : List ℕ) (xs : Fin k → Fin n) : regs.getD 0 0 = n → (∀ (x : α), regs.getD (fv x) 0 = ↑(val x)) → (∀ (i : Fin k), regs.getD (base + ↑i) 0 = ↑(xs i)) → ∀ (t : L.Term (α ⊕ Fin k)), Turing.CounterProgram.Expr.eval regs (C.term t) = ↑(FirstOrder.Language.Term.realize (Sum.elim val xs) t)
Term expressions compute the canonical natural index.
- rel {k r : ℕ} (R : L.Relations r) (ts : Fin r → L.Term (α ⊕ Fin k)) (P : Turing.CounterProgram) (b T F B : ℕ) (regs : List ℕ) (xs : Fin k → Fin n) : regs.getD 0 0 = n → (∀ (x : α), regs.getD (fv x) 0 = ↑(val x)) → (∀ (i : Fin k), regs.getD (base + ↑i) 0 = ↑(xs i)) → (∀ x ∈ regs, x ≤ B) → P.instr b = C.rel R ts T F → ∃ (res : Bool), (res = true ↔ FirstOrder.Language.Structure.RelMap R fun (i : Fin r) => FirstOrder.Language.Term.realize (Sum.elim val xs) (ts i)) ∧ P.Reaches w (P.Running B) (b, regs) (if res = true then T else F, regs)
A relation instruction selects exactly its semantic branch.
Instances For
The number of instructions compiled from a formula
(Cslib.Logic.Vocabulary.ModelChecker.formulaCodeWith).
Instances For
The code evaluating a formula with free variables α and k bound variables, placed at the
label b: with the cardinality in register 0, the values expected by the atomic handlers,
and the bound variable i in register base + i, it goes to T if the formula holds and to F
otherwise. A quantifier over the bound variable k loops over the values of
register base + k below the cardinality; equality compares two compiled expressions, and a
relation uses its supplied branch instruction.
Instances For
Compiled first-order control evaluates the formula and preserves the registers below the current bound-variable scope. Only the atomic handlers depend on the input vocabulary/model.