Skip to content

Kleene's theorem

30 fully proved

Kleene Converse

TheoremThe empty language is regex-denoted#✓fully proved

The empty language is denoted by 0.

theorem IsRegexDenoted.zero : IsRegexDenoted (0 : Language α)
Uses 1 · Used by 2

TheoremThe language of the empty word is regex-denoted#✓fully proved

The language {[]} is denoted by 1.

theorem IsRegexDenoted.one : IsRegexDenoted (1 : Language α)
Uses 1 · Used by 1

TheoremSingle-letter languages are regex-denoted#✓fully proved

A singleton {[a]} is denoted by char a.

theorem IsRegexDenoted.char (a : α) : IsRegexDenoted ({[a]} : Language α)
Uses 1 · Used by 1

TheoremRegex-denoted languages are closed under union#✓fully proved

Denoted languages are closed under union.

theorem IsRegexDenoted.add {L K : Language α} (hL : IsRegexDenoted L) (hK : IsRegexDenoted K) :
    IsRegexDenoted (L + K)
Uses 1 · Used by 2

TheoremRegex-denoted languages are closed under concatenation#✓fully proved

Denoted languages are closed under concatenation.

theorem IsRegexDenoted.mul {L K : Language α} (hL : IsRegexDenoted L) (hK : IsRegexDenoted K) :
    IsRegexDenoted (L * K)
Uses 1 · Used by 1

TheoremRegex-denoted languages are closed under Kleene star#✓fully proved

Denoted languages are closed under Kleene star.

theorem IsRegexDenoted.kstar {L : Language α} (hL : IsRegexDenoted L) :
    IsRegexDenoted (L∗)
Uses 1 · Used by 1

TheoremRegex-denoted languages are closed under finite unions#✓fully proved

Denoted languages are closed under finite unions.

theorem IsRegexDenoted.sum {ι : Type*} {s : Finset ι} {f : ι → Language α}
    (h : ∀ i ∈ s, IsRegexDenoted (f i)) : IsRegexDenoted (∑ i ∈ s, f i)
Uses 3 · Used by 2

TheoremMembership in a finite union of languages#✓fully proved

Membership in a finite union of languages.

theorem mem_sum {ι : Type*} {s : Finset ι} {f : ι → Language α} {w : List α} :
    w ∈ ∑ i ∈ s, f i ↔ ∃ i ∈ s, w ∈ f i
Used by 2

TheoremEmpty word outside a concatenation#✓fully proved

The empty word is not in a concatenation whose right factor excludes it.

theorem nil_notMem_mul_of_nil_notMem_right {L K : Language α} (hK : [] ∉ K) :
    [] ∉ L * K
Used by 1

DefinitionCoefficient in the equation system of a DFA#✓fully proved

The system of equations of a DFA at a state: the coefficient of X j in the equation for X q, the finite union of the singletons {[a]} over the letters taking q to j.

def coeff {σ : Type*} [DecidableEq σ] [Fintype α] (M : DFA α σ) (q j : σ) : Language α :=
  ∑ a ∈ Finset.univ.filter (fun a => M.step q a = j), ({[a]} : Language α)
Used by 5

DefinitionConstant term in the equation system of a DFA#✓fully proved

The constant term of the equation for X q: 1 on accepting states, 0 otherwise.

def constTerm {σ : Type*} (M : DFA α σ) (q : σ) : Language α := by
  classical
  exact if q ∈ M.accept then 1 else 0
Used by 3

DefinitionLanguage accepted from a DFA state#✓fully proved

The language accepted from a state: the unknown X q of the system.

def fromState {σ : Type*} (M : DFA α σ) (q : σ) : Language α :=
  M.acceptsFrom q
Used by 2

TheoremMembership in a DFA equation coefficient#✓fully proved

Membership in a coefficient: the word is a single letter taking q to j.

theorem mem_coeff {σ : Type*} [DecidableEq σ] [Fintype α] {M : DFA α σ} {q j : σ} {w : List α} :
    w ∈ coeff M q j ↔ ∃ a, M.step q a = j ∧ w = [a]
Uses 2 · Used by 2

TheoremDFA equation coefficients exclude the empty word#✓fully proved

No coefficient contains the empty word.

theorem nil_notMem_coeff {σ : Type*} [DecidableEq σ] [Fintype α] {M : DFA α σ} {q j : σ} :
    [] ∉ coeff M q j
Uses 2 · Used by 2

TheoremDFA equation coefficients are regex-denoted#✓fully proved

Every coefficient is denoted by a regular expression.

theorem denoted_coeff {σ : Type*} [DecidableEq σ] [Fintype α] {M : DFA α σ} {q j : σ} :
    IsRegexDenoted (coeff M q j)
Uses 4 · Used by 1

TheoremDFA equation constant terms are regex-denoted#✓fully proved

Every constant term is denoted by a regular expression.

theorem denoted_constTerm {σ : Type*} {M : DFA α σ} {q : σ} :
    IsRegexDenoted (constTerm M q)
Uses 4 · Used by 1

TheoremEquation system satisfied by DFA state languages#✓fully proved

The DFA equations: from q, either step on a letter and continue, or stop if q accepts.

theorem fromState_eq {σ : Type*} [DecidableEq σ] [Fintype σ] [Fintype α] {M : DFA α σ} {q : σ} :
    fromState M q = (∑ j, coeff M q j * fromState M j) + constTerm M q
Uses 6 · Used by 1

DefinitionCoefficient after eliminating the last state#✓fully proved

The coefficient of the reduced system obtained by eliminating the last state: the old coefficient, plus the detour through the last state, which may loop there any number of times.

def elimCoeff {n : ℕ} (A : Fin (n + 1) → Fin (n + 1) → Language α) :
    Fin n → Fin n → Language α :=
  fun i j =>
    A (Fin.castSucc i) (Fin.castSucc j) +
      A (Fin.castSucc i) (Fin.last n) * (A (Fin.last n) (Fin.last n))∗ *
        A (Fin.last n) (Fin.castSucc j)
Used by 1

DefinitionConstant term after eliminating the last state#✓fully proved

The constant term of the reduced system obtained by eliminating the last state.

def elimConst {n : ℕ} (A : Fin (n + 1) → Fin (n + 1) → Language α)
    (B : Fin (n + 1) → Language α) : Fin n → Language α :=
  fun i =>
    B (Fin.castSucc i) +
      A (Fin.castSucc i) (Fin.last n) * (A (Fin.last n) (Fin.last n))∗ * B (Fin.last n)
Used by 1

TheoremSolving a system of language equations#✓fully proved

If the languages X i satisfy X i = (∑ j, A i j * X j) + B i with every coefficient A i j excluding the empty word and every coefficient and constant term denoted by a regular expression, then every X i is denoted by a regular expression. The proof eliminates the last state with Arden's lemma and applies the induction hypothesis to the reduced system.

theorem exists_regex_of_system (n : ℕ) :
    ∀ {A : Fin n → Fin n → Language α} {B X : Fin n → Language α},
      (∀ i j, IsRegexDenoted (A i j)) → (∀ i j, [] ∉ A i j) →
      (∀ i, IsRegexDenoted (B i)) → (∀ i, X i = (∑ j, A i j * X j) + B i) →
      ∀ i, IsRegexDenoted (X i)
Uses 8 · Used by 1

TheoremLanguages of DFAs on finitely many numbered states are regex-denoted#✓fully proved

The language of a DFA with Fin n states is denoted by a regular expression.

theorem exists_regex_of_dfa_fin {n : ℕ} [Finite α] (M : DFA α (Fin n)) :
    ∃ r : RegularExpression α, r.matches' = M.accepts
Uses 9 · Used by 1

TheoremKleene's theorem: DFA languages are regex-denoted#✓fully proved

The language of a DFA over a finite state type is denoted by a regular expression.

theorem exists_regex_of_dfa {σ : Type*} [Finite σ] [Finite α] (M : DFA α σ) :
    ∃ r : RegularExpression α, r.matches' = M.accepts
Uses 1 · Used by 1

DefinitionLetters occurring in a regular expression#✓fully proved

The letters occurring in a regular expression.

def regexLetters [DecidableEq α] : RegularExpression α → Finset α
  | .zero => ∅
  | .epsilon => ∅
  | .char a => {a}
  | .plus P Q => regexLetters P ∪ regexLetters Q
  | .comp P Q => regexLetters P ∪ regexLetters Q
  | .star P => regexLetters P
Used by 2

TheoremLetters of matched words occur in the regular expression#✓fully proved

Every letter of a word matched by r occurs in r.

theorem mem_matches'_letters [DecidableEq α] {r : RegularExpression α} {w : List α}
    (hw : w ∈ r.matches') {a : α} (ha : a ∈ w) : a ∈ regexLetters r
Uses 1 · Used by 1

DefinitionDFA accepting the one-letter words#✓fully proved

The three-state DFA accepting exactly the one-letter words.

def singletonDFA : DFA α (Fin 3) where
  step q _ := if q = 0 then 1 else 2
  start := 0
  accept := {1}
Used by 2

TheoremThe one-letter-word DFA accepts exactly words of length one#✓fully proved

The one-letter-word DFA accepts exactly the words of length one.

theorem singletonDFA_accepts :
    (singletonDFA : DFA α (Fin 3)).accepts = {w : List α | w.length = 1}
Uses 1 · Used by 1

Language

TheoremKleene's theorem, converse direction#✓fully proved

Kleene's theorem, converse direction (Sipser, Introduction to the Theory of Computation, 3rd ed., Theorem 1.54): every regular language over a finite alphabet is denoted by a regular expression. Source: M. Sipser, Introduction to the Theory of Computation, 3rd ed., Theorem 1.54.

theorem IsRegular.exists_regex {α : Type*} [Finite α] {L : Language α} (hL : L.IsRegular) :
    ∃ r : RegularExpression α, r.matches' = L
Uses 1 · Used by 1

TheoremKleene's theorem#✓fully proved

Kleene's theorem (Sipser, 3rd ed., Theorem 1.54): over a finite alphabet, a language is regular if and only if it is denoted by a regular expression. Source: M. Sipser, Introduction to the Theory of Computation, 3rd ed., Theorem 1.54.

theorem isRegular_iff_exists_regex {α : Type*} [Finite α] {L : Language α} :
    L.IsRegular ↔ ∃ r : RegularExpression α, r.matches' = L
Uses 1

TheoremSharpness of the finite-alphabet hypothesis#✓fully proved

Over an infinite alphabet, the language of one-letter words is regular but is denoted by no regular expression, since a regular expression mentions only finitely many letters. Source: M. Sipser, Introduction to the Theory of Computation, 3rd ed., Theorem 1.54 (finite alphabet).

theorem exists_regular_not_regex {α : Type*} [Infinite α] :
    ∃ L : Language α, L.IsRegular ∧ ∀ r : RegularExpression α, r.matches' ≠ L
Uses 4

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.