Theory Greibach_Hardest
section ‹Greibach's Hardest Context-Free Language›
theory Greibach_Hardest
imports
"Context_Free_Grammar.Context_Free_Language"
"Greibach_Normal_Form.Greibach_Normal_Form"
"Dyck_Language.Dyck_Language"
begin
text ‹
Formalization of Theorem 2.1 by Sheila Greibach \cite{Greibach73}:
\textbf{Theorem} For every context-free language ‹L› there is a homomorphism ‹h› with
‹L - {ε} = h⇧-⇧1(L⇩0 - {ε})›, where ‹L⇩0› is one fixed ``hardest'' context-free language.
The construction encodes the leftmost derivations of a
Greibach Normal Form (GNF) grammar as a nondeterministic Dyck word (the encoding homomorphism ‹enc_h›);
the general case is reduced to GNF using the AFP entry \verb!Greibach_Normal_Form! (the function ‹gnf_of›).
›
abbreviation Cons_power :: "'a ⇒ nat ⇒ 'a list" (infixl "#^" 70) where
"a #^ n ≡ replicate n a"
subsection ‹The hardest language ‹L⇩0››
subsubsection ‹The terminal alphabet of ‹L⇩0››
text ‹Greibach's alphabet is ‹T = {a⇩1, a⇩2, ¦a⇩1, ¦a⇩2, c, ¢}› together with a fresh separator ‹d›.
There are two bracket ∗‹kinds› ‹a⇩1, a⇩2›, modelled by the type ‹t0_A›. A bracket letter is ‹Aa›
applied to an opening or closing bracket (of type @{typ ‹'a bracket›}) over a kind: thus
‹Aa (Open A1) = a⇩1›, ‹Aa (Close A1) = ¦a⇩1›, and analogously for ‹a⇩2›. The remaining letters are
‹Cc› for ‹c›, ‹Ce› for ‹¢›, and ‹Dd› for ‹d›.›
datatype t0_A = A1 | A2