File: Mathlib/Computability/RegularExpressions.lean

full_name: RegularExpression.star
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: RegularExpression α → RegularExpression α

full_name: RegularExpression.zero
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: RegularExpression α

full_name: RegularExpression.char
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: α → RegularExpression α

full_name: RegularExpression
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: Type u

full_name: RegularExpression.plus
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: RegularExpression α → RegularExpression α → RegularExpression α

full_name: RegularExpression.comp
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: RegularExpression α → RegularExpression α → RegularExpression α

full_name: RegularExpression.epsilon
code: /-- 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`
-/
inductive RegularExpression (α : Type u) : Type u
  | zero : RegularExpression α
  | epsilon : RegularExpression α
  | char : α → RegularExpression α
  | plus : RegularExpression α → RegularExpression α → RegularExpression α
  | comp : RegularExpression α → RegularExpression α → RegularExpression α
  | star : RegularExpression α → RegularExpression α
goal: RegularExpression α

full_name: RegularExpression.instInhabited
code: instance : Inhabited (RegularExpression α) 
goal: Inhabited (RegularExpression α)

full_name: RegularExpression.instAdd
code: instance : Add (RegularExpression α) 
goal: Add (RegularExpression α)

full_name: RegularExpression.instMul
code: instance : Mul (RegularExpression α) 
goal: Mul (RegularExpression α)

full_name: RegularExpression.instOne
code: instance : One (RegularExpression α) 
goal: One (RegularExpression α)

full_name: RegularExpression.instZero
code: instance : Zero (RegularExpression α) 
goal: Zero (RegularExpression α)

full_name: RegularExpression.instPowNat
code: instance : Pow (RegularExpression α) ℕ 
goal: Pow (RegularExpression α) ℕ

full_name: RegularExpression.zero_def
code: @[simp]
theorem zero_def : (zero : RegularExpression α) = 0 
goal: RegularExpression.zero = 0

full_name: RegularExpression.one_def
code: @[simp]
theorem one_def : (epsilon : RegularExpression α) = 1 
goal: RegularExpression.epsilon = 1

full_name: RegularExpression.plus_def
code: @[simp]
theorem plus_def (P Q : RegularExpression α) : plus P Q = P + Q 
goal: P.plus Q = P + Q

full_name: RegularExpression.comp_def
code: @[simp]
theorem comp_def (P Q : RegularExpression α) : comp P Q = P * Q 
goal: P.comp Q = P * Q

full_name: RegularExpression.matches'
code: /-- `matches' P` provides a language which contains all strings that `P` matches -/
-- Porting note: was '@[simp] but removed based on
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/simpNF.20issues.20in.20Computability.2ERegularExpressions.20!4.232306/near/328355362
def matches' : RegularExpression α → Language α
  
goal: RegularExpression α → Language α

full_name: RegularExpression.matches'_zero
code: @[simp]
theorem matches'_zero : (0 : RegularExpression α).matches' = 0 
goal: RegularExpression.matches' 0 = 0

full_name: RegularExpression.matches'_epsilon
code: @[simp]
theorem matches'_epsilon : (1 : RegularExpression α).matches' = 1 
goal: RegularExpression.matches' 1 = 1

full_name: RegularExpression.matches'_char
code: @[simp]
theorem matches'_char (a : α) : (char a).matches' = {[a]} 
goal: (RegularExpression.char a).matches' = {[a]}

full_name: RegularExpression.matches'_add
code: @[simp]
theorem matches'_add (P Q : RegularExpression α) : (P + Q).matches' = P.matches' + Q.matches' 
goal: (P + Q).matches' = P.matches' + Q.matches'

full_name: RegularExpression.matches'_mul
code: @[simp]
theorem matches'_mul (P Q : RegularExpression α) : (P * Q).matches' = P.matches' * Q.matches' 
goal: (P * Q).matches' = P.matches' * Q.matches'

full_name: RegularExpression.matches'_pow
code: @[simp]
theorem matches'_pow (P : RegularExpression α) : ∀ n : ℕ, (P ^ n).matches' = P.matches' ^ n
  
goal: (P ^ n).matches' = P.matches' ^ n

full_name: RegularExpression.matches'_star
code: @[simp]
theorem matches'_star (P : RegularExpression α) : P.star.matches' = P.matches'∗ 
goal: P.star.matches' = P.matches'∗

full_name: RegularExpression.matchEpsilon
code: /-- `matchEpsilon P` is true if and only if `P` matches the empty string -/
def matchEpsilon : RegularExpression α → Bool
  
goal: RegularExpression α → Bool

full_name: RegularExpression.deriv
code: /-- `P.deriv a` matches `x` if `P` matches `a :: x`, the Brzozowski derivative of `P` with respect
  to `a` -/
def deriv : RegularExpression α → α → RegularExpression α
  
goal: RegularExpression α → α → RegularExpression α

full_name: RegularExpression.deriv_zero
code: @[simp]
theorem deriv_zero (a : α) : deriv 0 a = 0 
goal: RegularExpression.deriv 0 a = 0

full_name: RegularExpression.deriv_one
code: @[simp]
theorem deriv_one (a : α) : deriv 1 a = 0 
goal: RegularExpression.deriv 1 a = 0

full_name: RegularExpression.deriv_char_self
code: @[simp]
theorem deriv_char_self (a : α) : deriv (char a) a = 1 
goal: (RegularExpression.char a).deriv a = 1

full_name: RegularExpression.deriv_char_of_ne
code: @[simp]
theorem deriv_char_of_ne (h : a ≠ b) : deriv (char a) b = 0 
goal: (RegularExpression.char a).deriv b = 0

full_name: RegularExpression.deriv_add
code: @[simp]
theorem deriv_add (P Q : RegularExpression α) (a : α) : deriv (P + Q) a = deriv P a + deriv Q a 
goal: (P + Q).deriv a = P.deriv a + Q.deriv a

full_name: RegularExpression.deriv_star
code: @[simp]
theorem deriv_star (P : RegularExpression α) (a : α) : deriv P.star a = deriv P a * star P 
goal: P.star.deriv a = P.deriv a * P.star

full_name: RegularExpression.rmatch
code: /-- `P.rmatch x` is true if and only if `P` matches `x`. This is a computable definition equivalent
  to `matches'`. -/
def rmatch : RegularExpression α → List α → Bool
  
goal: RegularExpression α → List α → Bool

full_name: RegularExpression.zero_rmatch
code: @[simp]
theorem zero_rmatch (x : List α) : rmatch 0 x = false 
goal: RegularExpression.rmatch 0 x = false

full_name: RegularExpression.one_rmatch_iff
code: theorem one_rmatch_iff (x : List α) : rmatch 1 x ↔ x = [] 
goal: RegularExpression.rmatch 1 x = true ↔ x = []

full_name: RegularExpression.char_rmatch_iff
code: theorem char_rmatch_iff (a : α) (x : List α) : rmatch (char a) x ↔ x = [a] 
goal: (RegularExpression.char a).rmatch x = true ↔ x = [a]

full_name: RegularExpression.add_rmatch_iff
code: theorem add_rmatch_iff (P Q : RegularExpression α) (x : List α) :
    (P + Q).rmatch x ↔ P.rmatch x ∨ Q.rmatch x 
goal: (P + Q).rmatch x = true ↔ P.rmatch x = true ∨ Q.rmatch x = true

full_name: RegularExpression.mul_rmatch_iff
code: theorem mul_rmatch_iff (P Q : RegularExpression α) (x : List α) :
    (P * Q).rmatch x ↔ ∃ t u : List α, x = t ++ u ∧ P.rmatch t ∧ Q.rmatch u 
goal: (P * Q).rmatch x = true ↔ ∃ t u, x = t ++ u ∧ P.rmatch t = true ∧ Q.rmatch u = true

full_name: RegularExpression.star_rmatch_iff
code: theorem star_rmatch_iff (P : RegularExpression α) :
    ∀ x : List α, (star P).rmatch x ↔ ∃ S : List (List α), x
          = S.join ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t 
goal: P.star.rmatch x = true ↔ ∃ S, x = S.join ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t = true

full_name: RegularExpression.rmatch_iff_matches'
code: @[simp]
theorem rmatch_iff_matches' (P : RegularExpression α) (x : List α) :
    P.rmatch x ↔ x ∈ P.matches' 
goal: P.rmatch x = true ↔ x ∈ P.matches'

full_name: RegularExpression.instDecidablePredListMemLanguageMatches'
code: instance (P : RegularExpression α) : DecidablePred (· ∈ P.matches') 
goal: DecidablePred fun x => x ∈ P.matches'

full_name: RegularExpression.map
code: /-- Map the alphabet of a regular expression. -/
@[simp]
def map (f : α → β) : RegularExpression α → RegularExpression β
  
goal: RegularExpression α → RegularExpression β

full_name: RegularExpression.map_pow
code: @[simp]
protected theorem map_pow (f : α → β) (P : RegularExpression α) :
    ∀ n : ℕ, map f (P ^ n) = map f P ^ n
  
goal: RegularExpression.map f (P ^ n) = RegularExpression.map f P ^ n

full_name: RegularExpression.map_id
code: @[simp]
theorem map_id : ∀ P : RegularExpression α, P.map id = P
  
goal: RegularExpression.map id P = P

full_name: RegularExpression.map_map
code: @[simp]
theorem map_map (g : β → γ) (f : α → β) : ∀ P : RegularExpression α, (P.map f).map g = P.map (g ∘ f)
  
goal: RegularExpression.map g (RegularExpression.map f P) = RegularExpression.map (g ∘ f) P

full_name: RegularExpression.matches'_map
code: /-- The language of the map is the map of the language. -/
@[simp]
theorem matches'_map (f : α → β) :
    ∀ P : RegularExpression α, (P.map f).matches' = Language.map f P.matches'
  
goal: (RegularExpression.map f P).matches' = (Language.map f) P.matches'