Documentation

Mathlib.Computability.RegularExpressions

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 RegularExpression (α : 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
Instances For
    Equations
    • RegularExpression.instInhabitedRegularExpression = { default := RegularExpression.zero }
    Equations
    • RegularExpression.instAddRegularExpression = { add := RegularExpression.plus }
    Equations
    • RegularExpression.instMulRegularExpression = { mul := RegularExpression.comp }
    Equations
    • RegularExpression.instOneRegularExpression = { one := RegularExpression.epsilon }
    Equations
    • RegularExpression.instZeroRegularExpression = { zero := RegularExpression.zero }
    Equations
    @[simp]
    theorem RegularExpression.zero_def {α : Type u_1} :
    RegularExpression.zero = 0
    @[simp]
    theorem RegularExpression.one_def {α : Type u_1} :
    RegularExpression.epsilon = 1
    def RegularExpression.deriv {α : Type u_1} [dec : DecidableEq α] :

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

    Equations
    Instances For
      @[simp]
      theorem RegularExpression.deriv_zero {α : Type u_1} [dec : DecidableEq α] (a : α) :
      @[simp]
      theorem RegularExpression.deriv_one {α : Type u_1} [dec : DecidableEq α] (a : α) :
      @[simp]
      theorem RegularExpression.deriv_char_of_ne {α : Type u_1} [dec : DecidableEq α] {a : α} {b : α} (h : a b) :
      def RegularExpression.rmatch {α : Type u_1} [dec : DecidableEq α] :

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

      Equations
      Instances For
        @[simp]
        Equations
        • One or more equations did not get rendered due to their size.
        @[simp]
        theorem RegularExpression.map_pow {α : Type u_1} {β : Type u_2} (f : αβ) (P : RegularExpression α) (n : ) :
        @[simp]
        theorem RegularExpression.map_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} (g : βγ) (f : αβ) (P : RegularExpression α) :
        @[simp]

        The language of the map is the map of the language.