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
([HMU00]).
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, with its contrapositiveLanguage.not_isContextFree_of_stringMap_not.
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
A string homomorphism on terminals applied to a symbol: a terminal becomes the string of terminals it maps to, a nonterminal stays.
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 word of the image grammar comes from a word of the source.
A nonterminal in the image of a sentential form comes from the same nonterminal in the source.
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
A string homomorphism applied to a grammar: every terminal in every rule is replaced by its image.
Equations
- ContextFreeGrammar.applyHom h G = { NT := G.NT, initial := G.initial, rules := Finset.image (ContextFreeRule.applyHom h) G.rules }
Instances For
A step of the image grammar from the image of a sentential form is the image of a step of the source grammar.
The image grammar generates the image language.
Context-free languages are closed under string homomorphisms.
If the homomorphic image of L is not context-free, then L is not context-free.