Skip to content

Commit d7693c2

Browse files
half a proof for smartOr_is_or
1 parent ab94823 commit d7693c2

File tree

2 files changed

+123
-28
lines changed

2 files changed

+123
-28
lines changed

Katydid/Regex/SmartRegex.lean

+100-5
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,113 @@ def smartOr (x y: Regex α): Regex α :=
393393
| Regex.emptyset => x
394394
| Regex.star (Regex.pred (Predicate.mk "any" _)) => y
395395
| _ =>
396-
-- it is implied that xs is sorted, given it was created using smartOr
397396
let xs := orToList x
398397
let ys := orToList y
399-
-- merge the sorted lists and remove duplicates,
400-
-- resulting in a sorted list of unique items.
398+
-- It is implied that xs is sorted, given it was created using smartOr.
399+
-- Merge the sorted lists and remove duplicates, resulting in a sorted list of unique items.
401400
let ors := NonEmptyList.mergeReps xs ys
402401
orFromList ors
403402

403+
private theorem smartOr_emptyset_l_is_r (x: Regex α):
404+
denote (Regex.or Regex.emptyset x) = denote (smartOr Regex.emptyset x) := by
405+
simp only [smartOr]
406+
nth_rewrite 1 [denote]
407+
nth_rewrite 1 [denote]
408+
rw [Language.simp_or_emptyset_l_is_r]
409+
410+
private theorem smartOr_emptyset_r_is_l':
411+
smartOr x Regex.emptyset = x := by
412+
simp only [smartOr]
413+
split
414+
· rfl
415+
· rfl
416+
· rfl
417+
418+
private theorem smartOr_emptyset_r_is_l (x: Regex α):
419+
denote (Regex.or x Regex.emptyset) = denote (smartOr x Regex.emptyset) := by
420+
nth_rewrite 1 [denote]
421+
nth_rewrite 1 [denote]
422+
rw [Language.simp_or_emptyset_r_is_l]
423+
rw [smartOr_emptyset_r_is_l']
424+
425+
private theorem smartOr_orFromList_mergeReps_orToList_is_or (x y: Regex α):
426+
denote (orFromList (NonEmptyList.mergeReps (orToList x) (orToList y))) = denote (Regex.or x y):= by
427+
induction x with
428+
| emptyset =>
429+
simp [denote, orFromList, orToList, NonEmptyList.mergeReps]
430+
sorry
431+
| emptystr =>
432+
sorry
433+
| pred _ =>
434+
sorry
435+
| or x1 x2 =>
436+
sorry
437+
| concat x1 x2 =>
438+
sorry
439+
| star x1 =>
440+
sorry
441+
404442
theorem smartOr_is_or (x y: Regex α):
405443
denote (Regex.or x y) = denote (smartOr x y) := by
406-
-- TODO
407-
sorry
444+
induction x with
445+
| emptyset =>
446+
rw [smartOr_emptyset_l_is_r]
447+
| emptystr =>
448+
cases y with
449+
| emptyset =>
450+
rw [smartOr_emptyset_r_is_l]
451+
| emptystr =>
452+
simp only [smartOr]
453+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
454+
| pred _ =>
455+
simp only [smartOr]
456+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
457+
| or y1 y2 =>
458+
simp only [smartOr]
459+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
460+
| concat y1 y2 =>
461+
simp only [smartOr]
462+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
463+
| star y1 =>
464+
cases y1 with
465+
| emptyset =>
466+
simp only [smartOr]
467+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
468+
| emptystr =>
469+
simp only [smartOr]
470+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
471+
| pred p1 =>
472+
simp only [smartOr]
473+
split
474+
· case _ _ h =>
475+
contradiction
476+
· case _ _ h _ _ h' =>
477+
simp at h'
478+
rw [h']
479+
unfold denote
480+
sorry
481+
· case _ _ h _ =>
482+
sorry
483+
| or y11 y12 =>
484+
simp only [smartOr]
485+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
486+
| concat y11 y12 =>
487+
simp only [smartOr]
488+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
489+
| star y11 =>
490+
simp only [smartOr]
491+
rw [smartOr_orFromList_mergeReps_orToList_is_or]
492+
| pred p =>
493+
cases p
494+
case mk pred dpred desc func =>
495+
simp only [smartOr]
496+
sorry
497+
| or x1 x2 =>
498+
sorry
499+
| concat x1 x2 =>
500+
sorry
501+
| star x1 =>
502+
sorry
408503

409504
def derive (r: Regex α) (a: α): Regex α :=
410505
match r with

Katydid/Std/NonEmptyList.lean

+23-23
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,36 @@ def merge' [Ord α] (xs: NonEmptyList α) (ys: NonEmptyList α): List α :=
3434

3535
def merge [Ord α] (xs: NonEmptyList α) (ys: NonEmptyList α): NonEmptyList α :=
3636
match xs with
37-
| NonEmptyList.mk x' xs' =>
37+
| NonEmptyList.mk x1 xs1 =>
3838
match ys with
39-
| NonEmptyList.mk y' ys' =>
40-
match Ord.compare x' y' with
39+
| NonEmptyList.mk y1 ys1 =>
40+
match Ord.compare x1 y1 with
4141
| Ordering.eq =>
42-
NonEmptyList.mk x' (Lists.merge xs' ys')
42+
NonEmptyList.mk x1 (Lists.merge xs1 ys1)
4343
| Ordering.lt =>
44-
NonEmptyList.mk x' (Lists.merge xs' (y'::ys'))
44+
NonEmptyList.mk x1 (Lists.merge xs1 (y1::ys1))
4545
| Ordering.gt =>
46-
NonEmptyList.mk y' (Lists.merge (x'::xs') ys')
46+
NonEmptyList.mk y1 (Lists.merge (x1::xs1) ys1)
4747

4848
def eraseReps [BEq α] (xs: NonEmptyList α): NonEmptyList α :=
4949
match xs with
50-
| NonEmptyList.mk x' xs' =>
51-
match xs' with
52-
| [] => xs
53-
| (x''::xs'') =>
54-
if x' == x''
55-
then NonEmptyList.eraseReps (NonEmptyList.mk x'' xs'')
56-
else NonEmptyList.mk x' (Lists.eraseReps xs')
50+
| NonEmptyList.mk x1 xs1 =>
51+
match xs1 with
52+
| [] => xs
53+
| (x2::xs2) =>
54+
if x1 == x2
55+
then NonEmptyList.eraseReps (NonEmptyList.mk x2 xs2)
56+
else NonEmptyList.mk x1 (Lists.eraseReps xs1)
5757

5858
def mergeReps [BEq α] [Ord α] (xs ys : NonEmptyList α): NonEmptyList α :=
5959
match xs, ys with
60-
| NonEmptyList.mk x xs, NonEmptyList.mk y ys =>
61-
match Ord.compare x y with
62-
| Ordering.eq =>
63-
match xs with
64-
| [] =>
65-
NonEmptyList.mk y ys
66-
| (x'::xs') =>
67-
NonEmptyList.mergeReps (NonEmptyList.mk x' xs') (NonEmptyList.mk y ys)
68-
| Ordering.lt => NonEmptyList.mk x (Lists.mergeReps xs (y::ys))
69-
| Ordering.gt => NonEmptyList.mk y (Lists.mergeReps (x::xs) ys)
60+
| NonEmptyList.mk x1 xs1, NonEmptyList.mk y1 ys1 =>
61+
match Ord.compare x1 y1 with
62+
| Ordering.eq =>
63+
match xs1 with
64+
| [] =>
65+
NonEmptyList.mk y1 ys1
66+
| (x2::xs2) =>
67+
NonEmptyList.mergeReps (NonEmptyList.mk x2 xs2) (NonEmptyList.mk y1 ys1)
68+
| Ordering.lt => NonEmptyList.mk x1 (Lists.mergeReps xs1 (y1::ys1))
69+
| Ordering.gt => NonEmptyList.mk y1 (Lists.mergeReps (x1::xs1) ys1)

0 commit comments

Comments
 (0)