Regular Expressions #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 #
- Show that this regular expressions and DFA/NFA's are equivalent.
attribute [pattern] has_mul.mul
has been added into this file, it could be moved.
- zero : Π {α : Type u}, regular_expression α
- epsilon : Π {α : Type u}, regular_expression α
- char : Π {α : Type u}, α → regular_expression α
- plus : Π {α : Type u}, regular_expression α → regular_expression α → regular_expression α
- comp : Π {α : Type u}, regular_expression α → regular_expression α → regular_expression α
- star : Π {α : Type u}, regular_expression α → regular_expression α
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 nothing1
(epsilon
) matches only the empty stringchar a
matches only the string 'a'star P
matches any finite concatenation of strings which matchP
P + Q
(plus P Q
) matches anything which matchP
orQ
P * Q
(comp P Q
) matchesx ++ y
ifx
matchesP
andy
matchesQ
Instances for regular_expression
Equations
Equations
Equations
Equations
Equations
Equations
- regular_expression.nat.has_pow = {pow := λ (n : regular_expression α) (r : ℕ), npow_rec r n}
matches P
provides a language which contains all strings that P
matches
Equations
Instances for regular_expression.matches
match_epsilon P
is true if and only if P
matches the empty string
Equations
- P.star.match_epsilon = bool.tt
- (P * Q).match_epsilon = P.match_epsilon && Q.match_epsilon
- (P + Q).match_epsilon = P.match_epsilon || Q.match_epsilon
- (regular_expression.char _x).match_epsilon = bool.ff
- 1.match_epsilon = bool.tt
- 0.match_epsilon = bool.ff
P.deriv a
matches x
if P
matches a :: x
, the Brzozowski derivative of P
with respect
to a
P.rmatch x
is true if and only if P
matches x
. This is a computable definition equivalent
to matches
.
Equations
- regular_expression.matches.decidable_pred P = id (λ (x : list α), id (_.mpr (eq.decidable (P.rmatch x) bool.tt)))
Map the alphabet of a regular expression.
Equations
- regular_expression.map f R.star = (regular_expression.map f R).star
- regular_expression.map f (R * S) = regular_expression.map f R * regular_expression.map f S
- regular_expression.map f (R + S) = regular_expression.map f R + regular_expression.map f S
- regular_expression.map f (regular_expression.char a) = regular_expression.char (f a)
- regular_expression.map f 1 = 1
- regular_expression.map f 0 = 0
The language of the map is the map of the language.