Langlib: formal-language theory in Lean 4

Langlib is a Lean 4 + Mathlib library of fully machine-checked results about grammars, automata, and language classes across the Chomsky hierarchy — regular, deterministic context-free, context-free, indexed, context-sensitive, recursive (decidable) and recursively enumerable languages. It formalizes the standard hierarchy theorems (PDA = CFG, CSG = LBA, TM = RE), closure properties (including the hard result that deterministic context-free languages are closed under complement), and decidability/computability results (including every context-sensitive language is recursive and Post’s theorem). Source and build instructions are on GitHub.

This page is a catalog of the library’s results.

Main results

Grammar ⇔ automaton equivalences

Hierarchy: strict inclusions

Regular languages

Deterministic context-free languages (DCFL)

Context-free languages (CFL)

Linear languages

Indexed languages

Context-sensitive languages (CSL)

Recursive (decidable) languages

Recursively enumerable languages (RE)

Closure properties

A machine-checked closure table across all seven classes is in the project README. Abstract closure predicates (ClosedUnderUnion, ClosedUnderHomomorphism, …) are defined as standalone predicates. Highlights:

Decidability and computability

Membership, emptiness, universality and equivalence are stated as uniform class-level predicates (ComputableMembership, ComputableEmptiness, …): each bundles that the encoding is adequate (Characterizes C — its range is exactly the class), effective (MembershipSemiDecidable), and that the relevant decision is computable. This makes both the positive and negative results genuine statements about the class, not artefacts of the encoding.


Formalized in Lean 4 with Mathlib, in Langlib.