Skip to content

Commit b704510

Browse files
prove derives foldl
1 parent 4468363 commit b704510

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Katydid/Regex/Calculus.lean

+14-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def derive' (P: Lang α) (a: α): Lang α :=
1818
def null {α: Type} (f: List α -> Prop): Prop :=
1919
f []
2020

21-
def derives {α: Type} (f: List α -> Prop) (u: List α): (List α -> Prop) :=
22-
λ v => f (u ++ v)
21+
def derives {α: Type} (f: List α -> Prop) (xs: List α): (List α -> Prop) :=
22+
λ ys => f (xs ++ ys)
2323

2424
def derive {α: Type} (f: List α -> Prop) (a: α): (List α -> Prop) :=
2525
derives f [a]
@@ -29,22 +29,28 @@ attribute [simp] null derive derives
2929
def derives_emptylist : derives f [] = f :=
3030
rfl
3131

32-
def derives_strings (f: List α -> Prop) (u v: List α): derives f (u ++ v) = derives (derives f u) v :=
33-
match u with
32+
def derives_strings (f: List α -> Prop) (xs ys: List α): derives f (xs ++ ys) = derives (derives f xs) ys :=
33+
match xs with
3434
| [] => rfl
35-
| (a :: u') => derives_strings (derive f a) u' v
35+
| (x :: xs) => derives_strings (derive f x) xs ys
3636

3737
def null_derives (f: List α -> Prop) (u: List α): (null ∘ derives f) u = f u := by
3838
simp
3939

40-
def derives_foldl (f: List α -> Prop) (u: List α): (derives f) u = (List.foldl derive f) u := by
41-
induction u with
40+
def derives_foldl (f: List α -> Prop) (xs: List α): (derives f) xs = (List.foldl derive f) xs := by
41+
revert f
42+
induction xs with
4243
| nil =>
4344
simp
4445
unfold derives
4546
simp
4647
| cons x xs ih =>
47-
sorry
48+
intro f
49+
unfold List.foldl
50+
have h: x :: xs = [x] ++ xs := by simp
51+
rw [h]
52+
rw [derives_strings]
53+
apply ih
4854

4955
def null_emptyset {α: Type}:
5056
@null α emptyset = False :=

0 commit comments

Comments
 (0)