Derivations from concatenations and from single nonterminals #
Mathlib's ContextFreeGrammar.Derives is closed under adding context on either side
(Derives.append_left, Derives.append_right). This file proves the converse decomposition:
a derivation from a concatenation u ++ v splits into independent derivations from u and
from v, the basic fact behind parse trees and the CYK algorithm. It also describes the
derivations from a terminal word (there are none but the trivial one) and from a single
nonterminal (the trivial one, or a first step by a rule).
Splitting lemmas of this kind appear in unmerged Mathlib work: DerivesIn.append_split, for
derivations of bounded length, in Loitzl and Dvořák's leanprover-community/mathlib4#19943
(closed), and the private special case head_tail_split (for s :: ss) in Mündler-Sasahara's
open leanprover-community/mathlib4#33601.
Main results #
ContextFreeGrammar.derives_append_iff:u ++ vderiveswiffw = x ++ ywithuderivingxandvderivingy;Derives.append_splitis the forward direction andDerives.appendthe converse.ContextFreeGrammar.derives_map_terminal_iff: a word of terminals derives only itself.ContextFreeGrammar.produces_nonterminal_iff,ContextFreeGrammar.derives_nonterminal_iff: one-step rewrites and derivations from a single nonterminal.
A derivation from a concatenation splits into derivations from the two parts.
u ++ v derives w exactly when w splits into a word derived from u followed by a word
derived from v.
A word of terminals derives only itself.
A single nonterminal A rewrites in one step to v exactly when v is the output of a rule
with input A.
A single nonterminal A derives w exactly when w = [A] or some rule with input A has an
output deriving w.