Encoded Right-Regular Grammars #
This file introduces a concrete encoded representation of right-regular grammars
(EncodedRG) that is Primcodable, together with the language it denotes
(regularLanguageOf). It is the shared scaffolding for the uniform computability
results proved in Decidability/Membership.lean and Decidability/Emptiness.lean.
Every right-regular grammar is in particular a context-free grammar, so an
EncodedRG maps (via toCFG, a primitive-recursive translation) into the encoded
context-free grammars EncodedCFG, and regularLanguageOf is defined as the
context-free language of that image. The two uniform results are then obtained by
composing the already-established uniform CF results
(contextFree_computableMembership, contextFree_computableEmptiness) with the
primitive-recursive map toCFG.
Restricting the rule shape to the right-regular productions A → a B, A → a,
A → ε guarantees that every code denotes a regular language, so this is a
faithful encoding of the regular class (and conversely every regular language is
generated by some right-regular grammar, hence representable).
Main definitions #
EncodedRG— the encoded right-regular grammar typeEncodedRG.toCFG— translation toEncodedCFGEncodedRG.regularLanguageOf— the denoted language
An encoded right-regular grammar over terminal alphabet T.
The underlying type is ℕ × ℕ × List (ℕ × Option (T × Option ℕ)):
- the first
ℕis the number of nonterminals minus one (so the nonterminal type isFin (numNT + 1), always nonempty), matchingEncodedCFG; - the second
ℕis the index of the initial nonterminal; - each rule
(lhs, body)hasbody : Option (T × Option ℕ)encoding exactly one of the three right-regular shapes:none— the rulelhs → ε;some (a, none)— the rulelhs → a;some (a, some B)— the rulelhs → a B.
Because each component is built from ℕ, Option, × and List, the type inherits
Primcodable from the standard Mathlib instances (given Primcodable T).
Instances For
Equations
- Regular.EncodedRG.instPrimcodable = inferInstanceAs (Primcodable (ℕ × ℕ × List (ℕ × Option (T × Option ℕ))))
Translate an encoded right-regular grammar to an encoded context-free grammar.
The nonterminal count and initial index are kept; each right-regular rule body is
expanded to its context-free right-hand side via bodyToRHS.
Equations
Instances For
The language denoted by an encoded right-regular grammar: the context-free language of its context-free image.
Equations
Instances For
Primitive recursiveness of the translation #
bodyToRHS is primitive recursive.
toCFG is primitive recursive.