Closure of IsContextFree under string homomorphism #
The image of a context-free language under a string homomorphism — induced by a
per-symbol map f : T → List T' — is context-free. Construction: replace each
terminal a in each grammar rule's output with the symbol-list (f a).map .terminal.
Nonterminals are unchanged.
Main definitions #
Language.stringMap f : Language T →+* Language T'— image under the string homomorphism. SinceList α = FreeMonoid α, the actionList.flatMap fis the free-monoid liftFreeMonoid.lift f; bundled as a semiring hom mirroring mathlib'sLanguage.map, of which the letter-to-letter case is the special caseLanguage.stringMap_letterMap.
Main theorems #
Language.IsContextFree.stringMap— context-free languages are closed under string homomorphism.ContextFreeGrammar.applyHom_language— the grammar construction realizesstringMap.
[HMU00] (homomorphism-closure construction).
The image of a language under the string homomorphism induced by a per-symbol
map f : T → List T'. On a word the action is List.flatMap f — i.e. the
free-monoid lift FreeMonoid.lift f, since List α = FreeMonoid α. Bundled as a
semiring hom mirroring mathlib's Language.map; the letter-to-letter map is the
special case Language.stringMap_letterMap.
Equations
- Language.stringMap f = { toFun := Set.image (List.flatMap f), map_one' := ⋯, map_mul' := ⋯, map_zero' := ⋯, map_add' := ⋯ }
Instances For
Bridge to mathlib's Language.map. The letter-to-letter map f : T → T'
(singleton outputs) is the special case of stringMap that collapses to mathlib's
Language.map f, so stringMap genuinely generalizes the existing letter image.
Apply a string homomorphism h : T → List T' to a single Symbol,
producing a symbol-list. Terminals are substituted; nonterminals are
preserved as singletons.
Equations
- ContextFreeRule.Symbol.applyHom h (Symbol.terminal a) = List.map Symbol.terminal (h a)
- ContextFreeRule.Symbol.applyHom h (Symbol.nonterminal X) = [Symbol.nonterminal X]
Instances For
Apply a string homomorphism h : T → List T' to a symbol list (free
monoid functoriality).
Equations
- ContextFreeRule.applyHomList h = List.flatMap (ContextFreeRule.Symbol.applyHom h)
Instances For
For a list of terminals, applyHomList becomes flatMap h followed by
re-wrapping as terminals.
Apply a string homomorphism to a CFG rule.
Equations
- ContextFreeRule.applyHom h r = { input := r.input, output := ContextFreeRule.applyHomList h r.output }
Instances For
A single rule's Rewrites relation lifts under applyHom.
Apply a string homomorphism to a CFG: substitute terminals in every rule.
Noncomputable due to Finset.image requiring decidable equality on rules
(provided classically).
Equations
- ContextFreeGrammar.applyHom h G = { NT := G.NT, initial := G.initial, rules := Finset.image (ContextFreeRule.applyHom h) G.rules }
Instances For
Produces lifts under applyHom.
Derives lifts under applyHom.
Forward inclusion: every (G.applyHom h)-generated string is in
Language.stringMap h G.language.
Backward inclusion: every (G.applyHom h)-generated string is the image
of some G-generated preimage under h. The construction lifts
G'-derivations to G-derivations step-by-step using decompose_applyHomList
and liftMapTerminal. Standard textbook construction
([HMU00] Theorem 7.24 part 4 (p. 284-285, homomorphism case)).