6. ”Derivatives of Regular Expressions”, Janusz Brzozowski, Journal
of the ACM 1964.
R(s) : s R
{
ν(R) (s = ””)
R(s) =
(∂a R)(s ) (s = a :: s )
ν(R) = R
∂a R = R a
NFA R a
∂a R
”Yacc is Dead” (http://arxiv.org/abs/1010.5023)
2011 Brzozowski
@tmiya : Coq , 6
9. (2/4)
Fixpoint nu(re:RegExp):bool :=
match re with
| Empty => false
| Eps => true
| Char c => false
| Cat r s => (nu r && nu s)%bool
| Or r s => (nu r || nu s)%bool
| Star r => true
end.
@tmiya : Coq , 9
10. (3/4)
Fixpoint derive(a:ascii)(re:RegExp):RegExp :=
match re with
| Empty => Empty
| Eps => Empty
| Char c => match (ascii_dec c a) with
| left _ => Eps
| right _ => Empty
end
| Cat r s => match (nu r) with
| true => ((derive a r) ++ s) || (derive a s)
| false => (derive a r) ++ s
end
| Or r s => (derive a r) || (derive a s)
| Star r => (derive a r) ++ (Star r)
end.
Notation "re / a" := (derive a re).
@tmiya : Coq , 10
11. (4/4)
Fixpoint matches (re:RegExp)(s:string) : bool :=
match s with
| EmptyString => nu re
| String a w => matches (re / a) w
end.
Notation "re ~= s" := (matches re s) (at level 60).
@tmiya : Coq , 11
12. Kleene
Kleene
”A Completeness Theorem for Kleene Algebras and the Algebra of
Regular Events,” D. Kozen (1994)
∅ 0 1
• x + (y + z) = (x + y ) + z, x(yz) = (xy )z :
• x +y =y +z :
• x(y + z) = xy + xz, (x + y )z = xz + yz :
• x + 0 = 0 + x = x, 1x = x1 = x :
• x0 = 0x = 0 :
x +x =x :
Kleene-star (x ≤ y ⇔ x + y = y )
• 1 + xx ∗ ≤ x ∗ , 1 + x ∗ x ≤ x ∗
• x + yz ≤ z ⇒ y ∗ x ≤ z
• x + yz ≤ y ⇒ xy ∗ ≤ z
Kleene
:
:
@tmiya : Coq , 12