Closure of IsContextFree under string homomorphism #
The image of a context-free language under a string homomorphism h : T → List T'
is context-free. Construction: replace each terminal a in each grammar rule's
output with the symbol-list (h a).map .terminal. Nonterminals are unchanged.
Owns the Language.stringMap definition and proves
Language.IsContextFree.stringMap. Together with the parallel Bar-Hillel
proof in InterRegular.lean, this dissolves the closure axioms previously
in Closure.lean.
@cite{hopcroft-motwani-ullman-2000} Theorem 7.24 part 4 (p. 284-285, homomorphism case).
The homomorphic image of a language under a string homomorphism.
Language.stringMap h L = {h(v) | v ∈ L}.
Equations
- Language.stringMap h L = {w : List T' | ∃ v ∈ L, h.apply v = w}
Instances For
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
(@cite{hopcroft-motwani-ullman-2000} Theorem 7.24 part 4 (p. 284-285, homomorphism case)).