Search Procedures — The Core DSL #
This file defines SearchProc, the central abstraction of the DSL.
A SearchProc captures the pattern:
"Enumerate candidates from a countable domain; test each one; halt when a witness is found."
This is the universal pattern for semi-decision procedures: to check
w ∈ L, we enumerate a domain of "proofs/witnesses" and test each one.
For grammars, the witnesses are derivation sequences; for other problems
they might be computation traces, certificates, etc.
Architecture #
┌─────────────┐ ┌──────────────┐ ┌──────────┐
│ Enum α │────▶│ test : α → │────▶│ halt if │
│ (generator)│ │ List T → │ │ true │
│ │ │ Bool │ │ │
└─────────────┘ └──────────────┘ └──────────┘
The SearchProc bundles:
It recognizes the language { w | ∃ a ∈ enum.range, test a w = true }.
Composability #
Search procedures compose via the Enum combinators:
- To search over pairs, use
Enum.product - To search over lists, use
Enum.finLists - To search with additional structure, use
Enum.bind
The test function can be built from decidable predicates using standard Boolean combinators.
Compilation to TM0 #
The search-to-machine compilation lives in SearchProcToTM0.lean.
if the enumeration and test are "TM-computable" (formalized via
a computability predicate), then the search procedure compiles to
a TM0 machine satisfying is_TM.
Main definitions #
SearchProc— a search procedureSearchProc.accepts— whether the procedure accepts a given wordSearchProc.language— the language recognizedSearchProc.mk'— convenient constructor fromEnum+ test- Composition lemmas
A search procedure over alphabet T with witness type α.
A search procedure recognizes a language by systematically enumerating
witnesses from a countable domain and testing each one against the input word.
It accepts w if and only if some witness passes the test.
This is the core abstraction of the DSL. Every semi-decision procedure
for a language can be expressed as a SearchProc (by Rice's theorem,
the converse also holds for r.e. languages).
- WitTy : Type u_2
The type of witnesses / certificates
Enumeration of all candidate witnesses
The test: given a witness and an input word, does the witness certify membership?
Instances For
Constructors #
Build a search procedure from an Encodable witness type and a test.
Automatically uses the Encodable instance to enumerate all witnesses.
Equations
- SearchProc.ofEncodable test = { WitTy := α, enum := Enum.ofEncodable, test := test }
Instances For
Build a search procedure that searches over all natural numbers.
Equations
- SearchProc.searchNat test = { WitTy := ℕ, enum := Enum.naturals, test := test }
Instances For
Composition #
Transform the witness type of a search procedure.