The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V32. Logic, model theory and computability

Mathlib.Computability.ContextFreeGrammar

101 declarations. Mathlib docs · Source

def ContextFreeRule.ctorIdx E1 #

{T : Type u_1} → {N : Type u_2} → ContextFreeRule T N → ℕ

abbrev Symbol.ctorElimType E1 #

{T : Type u_1} →
  {N : Type u_2} → {motive : Symbol T N → Sort u} → ℕ → Sort (max 1 (imax (u_1 + 1) u) (imax (u_2 + 1) u))

abbrev Symbol.proxyTypeEquiv E1 #

(T : Type u_1) → (N : Type u_2) → T ⊕ N ≃ Symbol T N

An equivalence between the "proxy type" Symbol.proxyType and Symbol. The proxy type is a reducible definition that represents the inductive type using Unit, PLift, Sigma, Empty, and Sum (and whatever other inductive types appear within the inductive type), and the intended use is to define typeclass instances uses pre-existing instances on these. (Generated by the proxy_equiv% elaborator.)

def Symbol.ctorIdx E1 #

{T : Type u_1} → {N : Type u_2} → Symbol T N → ℕ

ctor ContextFreeRule.Rewrites.below.cons E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N}
  {motive : (a a_1 : List (Symbol T N)) → r.Rewrites a a_1 → Prop} (x : Symbol T N) {s₁ s₂ : List (Symbol T N)}
  (hrs : r.Rewrites s₁ s₂), ContextFreeRule.Rewrites.below hrs → motive s₁ s₂ hrs → ContextFreeRule.Rewrites.below ⋯

theorem ContextFreeGrammar.mk.injEq E0 #

∀ {T : Type u_1} (NT : Type) (initial : NT) (rules : Finset (ContextFreeRule T NT)) (NT_1 : Type) (initial_1 : NT_1)
  (rules_1 : Finset (ContextFreeRule T NT_1)),
  ({ NT := NT, initial := initial, rules := rules } = { NT := NT_1, initial := initial_1, rules := rules_1 }) =
    (NT = NT_1 ∧ initial ≍ initial_1 ∧ rules ≍ rules_1)

def ContextFreeGrammar.ctorIdx E1 #

{T : Type u_1} → ContextFreeGrammar T → ℕ

theorem Symbol.nonterminal.injEq E0 #

∀ {T : Type u_1} {N : Type u_2} (n n_1 : N), (Symbol.nonterminal n = Symbol.nonterminal n_1) = (n = n_1)

ctor ContextFreeRule.Rewrites.below.head E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N}
  {motive : (a a_1 : List (Symbol T N)) → r.Rewrites a a_1 → Prop} (s : List (Symbol T N)),
  ContextFreeRule.Rewrites.below ⋯

abbrev Symbol.proxyType E1 #

Type u_1 → Type u_2 → Type (max u_1 u_2)

A "proxy type" equivalent to Symbol that is constructed from Unit, PLift, Sigma, Empty, and Sum. See Symbol.proxyTypeEquiv for the equivalence. (Generated by the proxy_equiv% elaborator.)

theorem Symbol.nonterminal.inj E1 #

∀ {T : Type u_1} {N : Type u_2} {n n_1 : N}, Symbol.nonterminal n = Symbol.nonterminal n_1 → n = n_1

theorem ContextFreeRule.mk.inj E1 #

∀ {T : Type u_1} {N : Type u_2} {input : N} {output : List (Symbol T N)} {input_1 : N} {output_1 : List (Symbol T N)},
  { input := input, output := output } = { input := input_1, output := output_1 } → input = input_1 ∧ output = output_1

theorem ContextFreeGrammar.mk.inj E1 #

∀ {T : Type u_1} {NT : Type} {initial : NT} {rules : Finset (ContextFreeRule T NT)} {NT_1 : Type} {initial_1 : NT_1}
  {rules_1 : Finset (ContextFreeRule T NT_1)},
  { NT := NT, initial := initial, rules := rules } = { NT := NT_1, initial := initial_1, rules := rules_1 } →
    NT = NT_1 ∧ initial ≍ initial_1 ∧ rules ≍ rules_1

theorem Symbol.terminal.inj E1 #

∀ {T : Type u_1} {N : Type u_2} {t t_1 : T}, Symbol.terminal t = Symbol.terminal t_1 → t = t_1

theorem ContextFreeRule.mk.injEq E0 #

∀ {T : Type u_1} {N : Type u_2} (input : N) (output : List (Symbol T N)) (input_1 : N) (output_1 : List (Symbol T N)),
  ({ input := input, output := output } = { input := input_1, output := output_1 }) =
    (input = input_1 ∧ output = output_1)

theorem Symbol.terminal.injEq E0 #

∀ {T : Type u_1} {N : Type u_2} (t t_1 : T), (Symbol.terminal t = Symbol.terminal t_1) = (t = t_1)

inductive Symbol E1 #

Type u_1 → Type u_2 → Type (max u_1 u_2)

Symbols for use by all kinds of grammars.

ctor Symbol.terminal E0 #

{T : Type u_1} → {N : Type u_2} → T → Symbol T N

Terminal symbols (of the same type as the language)

ctor Symbol.nonterminal E0 #

{T : Type u_1} → {N : Type u_2} → N → Symbol T N

Nonterminal symbols (must not be present when the word being generated is finalized)

def instDecidableEqSymbol.decEq E1 #

{T : Type u_1} → {N : Type u_2} → [DecidableEq T] → [DecidableEq N] → (x x_1 : Symbol T N) → Decidable (x = x_1)

instance instDecidableEqSymbol E0 #

{T : Type u_1} → {N : Type u_2} → [DecidableEq T] → [DecidableEq N] → DecidableEq (Symbol T N)

def instReprSymbol.repr E1 #

{T : Type u_1} → {N : Type u_2} → [Repr T] → [Repr N] → Symbol T N → ℕ → Std.Format

instance instFintypeSymbol E0 #

{T : Type u_1} → {N : Type u_2} → [Fintype T] → [Fintype N] → Fintype (Symbol T N)

instance instReprSymbol E0 #

{T : Type u_1} → {N : Type u_2} → [Repr T] → [Repr N] → Repr (Symbol T N)

structure ContextFreeRule E1 #

Type u_1 → Type u_2 → Type (max u_1 u_2)

Rule that rewrites a single nonterminal to any string (a list of symbols).

theorem ContextFreeRule.ext_iff E0 #

∀ {T : Type u_1} {N : Type u_2} {x y : ContextFreeRule T N}, x = y ↔ x.input = y.input ∧ x.output = y.output

theorem ContextFreeRule.ext E1 #

∀ {T : Type u_1} {N : Type u_2} {x y : ContextFreeRule T N}, x.input = y.input → x.output = y.output → x = y

ctor ContextFreeRule.mk E0 #

{T : Type u_1} → {N : Type u_2} → N → List (Symbol T N) → ContextFreeRule T N

abbrev ContextFreeRule.input E1 #

{T : Type u_1} → {N : Type u_2} → ContextFreeRule T N → N

Input nonterminal a.k.a. left-hand side.

abbrev ContextFreeRule.output E1 #

{T : Type u_1} → {N : Type u_2} → ContextFreeRule T N → List (Symbol T N)

Output string a.k.a. right-hand side.

def instDecidableEqContextFreeRule.decEq E1 #

{T : Type u_1} →
  {N : Type u_2} → [DecidableEq T] → [DecidableEq N] → (x x_1 : ContextFreeRule T N) → Decidable (x = x_1)

instance instDecidableEqContextFreeRule E0 #

{T : Type u_1} → {N : Type u_2} → [DecidableEq T] → [DecidableEq N] → DecidableEq (ContextFreeRule T N)

instance instReprContextFreeRule E0 #

{T : Type u_1} → {N : Type u_2} → [Repr T] → [Repr N] → Repr (ContextFreeRule T N)

def instReprContextFreeRule.repr E1 #

{T : Type u_1} → {N : Type u_2} → [Repr T] → [Repr N] → ContextFreeRule T N → ℕ → Std.Format

structure ContextFreeGrammar E3 #

Type u_1 → Type (max 1 u_1)

Context-free grammar that generates words over the alphabet T (a type of terminals).

ctor ContextFreeGrammar.mk E0 #

{T : Type u_1} → (NT : Type) → NT → Finset (ContextFreeRule T NT) → ContextFreeGrammar T

abbrev ContextFreeGrammar.NT E1 #

{T : Type u_1} → ContextFreeGrammar T → Type

Type of nonterminals.

abbrev ContextFreeGrammar.initial E1 #

{T : Type u_1} → (self : ContextFreeGrammar T) → self.NT

Initial nonterminal.

abbrev ContextFreeGrammar.rules E1 #

{T : Type u_1} → (self : ContextFreeGrammar T) → Finset (ContextFreeRule T self.NT)

Rewrite rules.

inductive ContextFreeRule.Rewrites E1 #

{T : Type u_1} → {N : Type u_2} → ContextFreeRule T N → List (Symbol T N) → List (Symbol T N) → Prop

Inductive definition of a single application of a given context-free rule r to a string u; r.Rewrites u v means that the r sends u to v (there may be multiple such strings v).

ctor ContextFreeRule.Rewrites.head E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} (s : List (Symbol T N)),
  r.Rewrites (Symbol.nonterminal r.input :: s) (r.output ++ s)

The replacement is at the start of the remaining string.

ctor ContextFreeRule.Rewrites.cons E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} (x : Symbol T N) {s₁ s₂ : List (Symbol T N)},
  r.Rewrites s₁ s₂ → r.Rewrites (x :: s₁) (x :: s₂)

There is a replacement later in the string.

theorem ContextFreeRule.Rewrites.exists_parts E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v → ∃ p q, u = p ++ [Symbol.nonterminal r.input] ++ q ∧ v = p ++ r.output ++ q

theorem ContextFreeRule.Rewrites.input_output E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N}, r.Rewrites [Symbol.nonterminal r.input] r.output

theorem ContextFreeRule.rewrites_of_exists_parts E1 #

∀ {T : Type u_1} {N : Type u_2} (r : ContextFreeRule T N) (p q : List (Symbol T N)),
  r.Rewrites (p ++ [Symbol.nonterminal r.input] ++ q) (p ++ r.output ++ q)

theorem ContextFreeRule.rewrites_iff E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v ↔ ∃ p q, u = p ++ [Symbol.nonterminal r.input] ++ q ∧ v = p ++ r.output ++ q

Rule r rewrites string u is to string v iff they share both a prefix p and postfix q such that the remaining middle part of u is the input of r and the remaining middle part of u is the output of r.

theorem ContextFreeRule.Rewrites.nonterminal_input_mem E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v → Symbol.nonterminal r.input ∈ u

theorem ContextFreeRule.Rewrites.append_left E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v → ∀ (p : List (Symbol T N)), r.Rewrites (p ++ u) (p ++ v)

Add extra prefix to context-free rewriting.

theorem ContextFreeRule.Rewrites.append_right E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v → ∀ (p : List (Symbol T N)), r.Rewrites (u ++ p) (v ++ p)

Add extra postfix to context-free rewriting.

def ContextFreeGrammar.Produces E1 #

{T : Type u_1} → (g : ContextFreeGrammar T) → List (Symbol T g.NT) → List (Symbol T g.NT) → Prop

Given a context-free grammar g and strings u and v g.Produces u v means that one step of a context-free transformation by a rule from g sends u to v.

abbrev ContextFreeGrammar.Derives E1 #

{T : Type u_1} → (g : ContextFreeGrammar T) → List (Symbol T g.NT) → List (Symbol T g.NT) → Prop

Given a context-free grammar g and strings u and v g.Derives u v means that g can transform u to v in some number of rewriting steps.

def ContextFreeGrammar.Generates E1 #

{T : Type u_1} → (g : ContextFreeGrammar T) → List (Symbol T g.NT) → Prop

Given a context-free grammar g and a string s g.Generates s means that g can transform its initial nonterminal to s in some number of rewriting steps.

def ContextFreeGrammar.language E1 #

{T : Type u_1} → ContextFreeGrammar T → Language T

The language (set of words) that can be generated by a given context-free grammar g.

theorem ContextFreeGrammar.mem_language_iff E0 #

∀ {T : Type u_1} (g : ContextFreeGrammar T) (w : List T),
  w ∈ g.language ↔ g.Derives [Symbol.nonterminal g.initial] (List.map Symbol.terminal w)

A given word w belongs to the language generated by a given context-free grammar g iff g can derive the word w (wrapped as a string) from the initial nonterminal of g in some number of steps.

theorem ContextFreeGrammar.Derives.refl E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} (w : List (Symbol T g.NT)), g.Derives w w

theorem ContextFreeGrammar.Produces.single E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {v w : List (Symbol T g.NT)}, g.Produces v w → g.Derives v w

theorem ContextFreeGrammar.Derives.trans E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v w : List (Symbol T g.NT)},
  g.Derives u v → g.Derives v w → g.Derives u w

theorem ContextFreeGrammar.Derives.trans_produces E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v w : List (Symbol T g.NT)},
  g.Derives u v → g.Produces v w → g.Derives u w

theorem ContextFreeGrammar.Produces.trans_derives E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v w : List (Symbol T g.NT)},
  g.Produces u v → g.Derives v w → g.Derives u w

theorem ContextFreeGrammar.derives_iff_eq_or_head E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u w : List (Symbol T g.NT)},
  g.Derives u w ↔ u = w ∨ ∃ v, g.Produces u v ∧ g.Derives v w

theorem ContextFreeGrammar.derives_iff_eq_or_tail E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u w : List (Symbol T g.NT)},
  g.Derives u w ↔ w = u ∨ ∃ v, g.Derives u v ∧ g.Produces v w

theorem ContextFreeGrammar.Produces.append_left E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {v w : List (Symbol T g.NT)},
  g.Produces v w → ∀ (p : List (Symbol T g.NT)), g.Produces (p ++ v) (p ++ w)

Add extra prefix to context-free producing.

theorem ContextFreeGrammar.Produces.append_right E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {v w : List (Symbol T g.NT)},
  g.Produces v w → ∀ (p : List (Symbol T g.NT)), g.Produces (v ++ p) (w ++ p)

Add extra postfix to context-free producing.

theorem ContextFreeGrammar.Derives.append_left E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {v w : List (Symbol T g.NT)},
  g.Derives v w → ∀ (p : List (Symbol T g.NT)), g.Derives (p ++ v) (p ++ w)

Add extra prefix to context-free deriving.

theorem ContextFreeGrammar.Derives.append_right E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {v w : List (Symbol T g.NT)},
  g.Derives v w → ∀ (p : List (Symbol T g.NT)), g.Derives (v ++ p) (w ++ p)

Add extra postfix to context-free deriving.

theorem ContextFreeGrammar.Produces.exists_nonterminal_input_mem E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.Produces u v → ∃ r ∈ g.rules, Symbol.nonterminal r.input ∈ u

theorem ContextFreeGrammar.derives_nonterminal E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {t : g.NT},
  (∀ r ∈ g.rules, r.input ≠ t) →
    ∀ (s : List (Symbol T g.NT)), s ≠ [Symbol.nonterminal t] → ¬g.Derives [Symbol.nonterminal t] s

theorem ContextFreeGrammar.language_eq_zero_of_forall_input_ne_initial E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T}, (∀ r ∈ g.rules, r.input ≠ g.initial) → g.language = 0

def Language.IsContextFree E3 #

{T : Type u_1} → Language T → Prop

Context-free languages are defined by context-free grammars.

def ContextFreeRule.reverse E1 #

{T : Type u_1} → {N : Type u_2} → ContextFreeRule T N → ContextFreeRule T N

Rules for a grammar for a reversed language.

theorem ContextFreeRule.reverse_reverse E0 #

∀ {T : Type u_1} {N : Type u_2} (r : ContextFreeRule T N), r.reverse.reverse = r

theorem ContextFreeRule.reverse_comp_reverse E0 #

∀ {T : Type u_1} {N : Type u_2}, ContextFreeRule.reverse ∘ ContextFreeRule.reverse = id

theorem ContextFreeRule.reverse_involutive E1 #

∀ {T : Type u_1} {N : Type u_2}, Function.Involutive ContextFreeRule.reverse

theorem ContextFreeRule.reverse_bijective E1 #

∀ {T : Type u_1} {N : Type u_2}, Function.Bijective ContextFreeRule.reverse

theorem ContextFreeRule.reverse_injective E1 #

∀ {T : Type u_1} {N : Type u_2}, Function.Injective ContextFreeRule.reverse

theorem ContextFreeRule.reverse_surjective E1 #

∀ {T : Type u_1} {N : Type u_2}, Function.Surjective ContextFreeRule.reverse

theorem ContextFreeRule.Rewrites.reverse E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.Rewrites u v → r.reverse.Rewrites u.reverse v.reverse

theorem ContextFreeRule.rewrites_reverse E1 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.reverse.Rewrites u.reverse v.reverse ↔ r.Rewrites u v

theorem ContextFreeRule.rewrites_reverse_comm E0 #

∀ {T : Type u_1} {N : Type u_2} {r : ContextFreeRule T N} {u v : List (Symbol T N)},
  r.reverse.Rewrites u v ↔ r.Rewrites u.reverse v.reverse

def ContextFreeGrammar.reverse E1 #

{T : Type u_1} → ContextFreeGrammar T → ContextFreeGrammar T

Grammar for a reversed language.

theorem ContextFreeGrammar.reverse_NT E0 #

∀ {T : Type u_1} (g : ContextFreeGrammar T), g.reverse.NT = g.NT

theorem ContextFreeGrammar.reverse_initial E0 #

∀ {T : Type u_1} (g : ContextFreeGrammar T), g.reverse.initial = g.initial

theorem ContextFreeGrammar.reverse_rules E0 #

∀ {T : Type u_1} (g : ContextFreeGrammar T),
  g.reverse.rules = Finset.map { toFun := ContextFreeRule.reverse, inj' := ⋯ } g.rules

theorem ContextFreeGrammar.reverse_reverse E0 #

∀ {T : Type u_1} (g : ContextFreeGrammar T), g.reverse.reverse = g

theorem ContextFreeGrammar.reverse_involutive E1 #

∀ {T : Type u_1}, Function.Involutive ContextFreeGrammar.reverse

theorem ContextFreeGrammar.reverse_bijective E1 #

∀ {T : Type u_1}, Function.Bijective ContextFreeGrammar.reverse

theorem ContextFreeGrammar.reverse_injective E1 #

∀ {T : Type u_1}, Function.Injective ContextFreeGrammar.reverse

theorem ContextFreeGrammar.reverse_surjective E1 #

∀ {T : Type u_1}, Function.Surjective ContextFreeGrammar.reverse

theorem ContextFreeGrammar.produces_reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.reverse.Produces u.reverse v.reverse ↔ g.Produces u v

theorem ContextFreeGrammar.Produces.reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.Produces u v → g.reverse.Produces u.reverse v.reverse

Alias of the reverse direction of ContextFreeGrammar.produces_reverse.

theorem ContextFreeGrammar.produces_reverse_comm E0 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.reverse.Produces u v ↔ g.Produces u.reverse v.reverse

theorem ContextFreeGrammar.Derives.reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.Derives u v → g.reverse.Derives u.reverse v.reverse

theorem ContextFreeGrammar.derives_reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.reverse.Derives u.reverse v.reverse ↔ g.Derives u v

theorem ContextFreeGrammar.derives_reverse_comm E0 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u v : List (Symbol T g.NT)},
  g.reverse.Derives u v ↔ g.Derives u.reverse v.reverse

theorem ContextFreeGrammar.generates_reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u : List (Symbol T g.NT)}, g.reverse.Generates u.reverse ↔ g.Generates u

theorem ContextFreeGrammar.Generates.reverse E1 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u : List (Symbol T g.NT)}, g.Generates u → g.reverse.Generates u.reverse

Alias of the reverse direction of ContextFreeGrammar.generates_reverse.

theorem ContextFreeGrammar.generates_reverse_comm E0 #

∀ {T : Type u_1} {g : ContextFreeGrammar T} {u : List (Symbol T g.NT)}, g.reverse.Generates u ↔ g.Generates u.reverse

theorem ContextFreeGrammar.language_reverse E0 #

∀ {T : Type u_1} {g : ContextFreeGrammar T}, g.reverse.language = g.language.reverse

theorem Language.IsContextFree.reverse E1 #

∀ {T : Type u_1} {L : Language T}, L.IsContextFree → L.reverse.IsContextFree

The class of context-free languages is closed under reversal.

theorem Language.IsContextFree.of_reverse E1 #

∀ {T : Type u_1} {L : Language T}, L.reverse.IsContextFree → L.IsContextFree

theorem Language.isContextFree_reverse E0 #

∀ {T : Type u_1} {L : Language T}, L.reverse.IsContextFree ↔ L.IsContextFree