Skip to content

Commit ea2b650

Browse files
create regex folder and add a Language definition
1 parent 4e4849c commit ea2b650

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Katydid.lean

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import Katydid.Std.Balistic
66

77
import Katydid.Example.SimpLibrary
88

9+
import Katydid.Regex.Regex
10+
import Katydid.Regex.Language
11+
912
import Katydid.Expr.Desc
10-
import Katydid.Expr.Regex

Katydid/Regex/Language.lean

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace Language
2+
3+
def Lang (α: Type): Type := List α -> Prop
4+
5+
def emptyset : Lang α :=
6+
fun _ => False
7+
8+
def universal {α: Type} : Lang α :=
9+
fun _ => True
10+
11+
def emptystr {α: Type} : Lang α :=
12+
fun w => w = []
13+
14+
def char {α: Type} (a : α): Lang α :=
15+
fun w => w = [a]
16+
17+
def or {α: Type} (P : Lang α) (Q : Lang α) : Lang α :=
18+
fun w => P w \/ Q w
19+
20+
def and {α: Type} (P : Lang α) (Q : Lang α) : Lang α :=
21+
fun w => P w /\ Q w
22+
23+
def concat {α: Type} (P : Lang α) (Q : Lang α) : Lang α :=
24+
fun (w : List α) =>
25+
∃ (x : List α) (y : List α), P x /\ Q y /\ w = (x ++ y)
26+
27+
inductive All {α: Type} (P : α -> Prop) : (List α -> Prop) where
28+
| nil : All P []
29+
| cons : ∀ {x xs} (_px : P x) (_pxs : All P xs), All P (x :: xs)
30+
31+
def star {α: Type} (P : Lang α) : Lang α :=
32+
fun (w : List α) =>
33+
∃ (ws : List (List α)), All P ws /\ w = (List.join ws)
34+
35+
-- attribute [simp] allows these definitions to be unfolded when using the simp tactic.
36+
attribute [simp] universal emptyset emptystr char or and concat star
37+
38+
example: Lang α := universal
39+
example: Lang α := emptystr
40+
example: Lang α := (or emptystr universal)
41+
example: Lang α := (and emptystr universal)
42+
example: Lang α := emptyset
43+
example: Lang α := (star emptyset)
44+
example: Lang Char := char 'a'
45+
example: Lang Char := char 'b'
46+
example: Lang Char := (or (char 'a') emptyset)
47+
example: Lang Char := (and (char 'a') (char 'b'))
48+
example: Lang Nat := (and (char 1) (char 2))
49+
example: Lang Nat := (concat (char 1) (char 2))
50+
51+
end Language
File renamed without changes.

0 commit comments

Comments
 (0)