|
| 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 |
0 commit comments