Context-free languages are closed under string homomorphisms #
A map f : T → List T' on letters extends to a monoid homomorphism on words, List.flatMap f,
and to a semiring homomorphism Language.stringMap f on languages. The image of a context-free
language under it is context-free: replace every terminal a in every rule by the string f a.
Main definitions #
Language.stringMap: the image of a language under a string homomorphism.Symbol.applyHom,ContextFreeRule.applyHom,ContextFreeGrammar.applyHom: a string homomorphism applied to a symbol, a rule and a grammar.
Main results #
ContextFreeGrammar.applyHom_language: the image grammar generates the image language.Language.IsContextFree.stringMap: closure under string homomorphisms, andLanguage.IsContextFree.mapunder maps of letters.
References #
The image of a language under the string homomorphism induced by f : T → List T', the
monoid homomorphism List.flatMap f on words; Language.map is the case of one-letter images.
Equations
- Language.stringMap f = { toFun := Set.image (List.flatMap f), map_one' := ⋯, map_mul' := ⋯, map_zero' := ⋯, map_add' := ⋯ }
Instances For
The string homomorphism h sends a terminal to the string of terminals it maps to and keeps
a nonterminal.
Equations
- Symbol.applyHom h (Symbol.terminal a) = List.map Symbol.terminal (h a)
- Symbol.applyHom h (Symbol.nonterminal A) = [Symbol.nonterminal A]
Instances For
A string homomorphism applied to a rule.
Equations
- ContextFreeRule.applyHom h r = { input := r.input, output := List.flatMap (Symbol.applyHom h) r.output }
Instances For
The grammar G.applyHom h replaces every terminal in every rule of G by its image under
h.
Equations
- ContextFreeGrammar.applyHom h G = { NT := G.NT, initial := G.initial, rules := Finset.image (ContextFreeRule.applyHom h) G.rules }
Instances For
The image grammar generates the image language.
Context-free languages are closed under string homomorphisms.
Context-free languages are closed under maps of letters.