mathlib documentation

computability.regular_expressions

Regular Expressions #

This file contains the formal definition for regular expressions and basic lemmas. Note these are regular expressions in terms of formal language theory. Note this is different to regex's used in computer science such as the POSIX standard.

TODO

inductive regular_expression (α : Type u) :
Type u

This is the definition of regular expressions. The names used here is to mirror the definition of a Kleene algebra (https://en.wikipedia.org/wiki/Kleene_algebra).

  • 0 (zero) matches nothing
  • 1 (epsilon) matches only the empty string
  • char a matches only the string 'a'
  • star P matches any finite concatenation of strings which match P
  • P + Q (plus P Q) matches anything which match P or Q
  • P * Q (comp P Q) matches x ++ y if x matches P and y matches Q
@[simp]
@[simp]
@[simp]
theorem regular_expression.plus_def {α : Type u} (P Q : regular_expression α) :
P.plus Q = P + Q
@[simp]
theorem regular_expression.comp_def {α : Type u} (P Q : regular_expression α) :
P.comp Q = P * Q
def regular_expression.matches {α : Type u} :

matches P provides a language which contains all strings that P matches

Equations
@[simp]
theorem regular_expression.matches_zero_def {α : Type u} :
@[simp]
theorem regular_expression.matches_epsilon_def {α : Type u} :
@[simp]
theorem regular_expression.matches_add_def {α : Type u} (P Q : regular_expression α) :
@[simp]
theorem regular_expression.matches_mul_def {α : Type u} (P Q : regular_expression α) :
(P * Q).matches = (P.matches) * Q.matches
@[simp]

match_epsilon P is true if and only if P matches the empty string

Equations
def regular_expression.deriv {α : Type u} [dec : decidable_eq α] :

P.deriv a matches x if P matches a :: x, the Brzozowski derivative of P with respect to a

Equations
def regular_expression.rmatch {α : Type u} [dec : decidable_eq α] :

P.rmatch x is true if and only if P matches x. This is a computable definition equivalent to matches.

Equations
@[simp]
theorem regular_expression.zero_rmatch {α : Type u} [dec : decidable_eq α] (x : list α) :
0.rmatch x = ff
theorem regular_expression.one_rmatch_iff {α : Type u} [dec : decidable_eq α] (x : list α) :
theorem regular_expression.char_rmatch_iff {α : Type u} [dec : decidable_eq α] (a : α) (x : list α) :
theorem regular_expression.add_rmatch_iff {α : Type u} [dec : decidable_eq α] (P Q : regular_expression α) (x : list α) :
((P + Q).rmatch x) (P.rmatch x) (Q.rmatch x)
theorem regular_expression.mul_rmatch_iff {α : Type u} [dec : decidable_eq α] (P Q : regular_expression α) (x : list α) :
((P * Q).rmatch x) ∃ (t u : list α), x = t ++ u (P.rmatch t) (Q.rmatch u)
theorem regular_expression.star_rmatch_iff {α : Type u} [dec : decidable_eq α] (P : regular_expression α) (x : list α) :
(P.star.rmatch x) ∃ (S : list (list α)), x = S.join ∀ (t : list α), t St list.nil (P.rmatch t)
@[simp]
theorem regular_expression.rmatch_iff_matches {α : Type u} [dec : decidable_eq α] (P : regular_expression α) (x : list α) :