@@ -146,17 +146,17 @@ def extracts (xs: Vec (Regex σ) nregex) (acc: Vec σ nacc):
146146 | Vec.nil =>
147147 ( Vec.nil, acc )
148148 | @Vec.cons _ nregex x xs =>
149- let (regex1 , acc1) := Symbol.extract x acc
150- let (regexes2 , accs) := extracts xs acc1
151- let regex1 ': RegexID (nacc + nums (Vec.cons x xs)) :=
152- RegexID.cast (RegexID.add (nums xs) regex1 ) (by simp only [nums]; ac_rfl)
153- let regexes2 ' : Vec (RegexID (nacc + nums (Vec.cons x xs))) nregex :=
154- RegexID.casts regexes2 (by simp only [nums]; ac_rfl)
155- let regexes : Vec (RegexID (nacc + nums (Vec.cons x xs))) (nregex + 1 ) :=
156- Vec.cast (Vec.cons regex1' regexes2 ') (by simp only)
149+ let (regexid , acc1) := Symbol.extract x acc
150+ let (regexids , accs) := extracts xs acc1
151+ let regexid ': RegexID (nacc + nums (Vec.cons x xs)) :=
152+ RegexID.cast (RegexID.add (nums xs) regexid ) (by simp only [nums]; ac_rfl)
153+ let regexesids ' : Vec (RegexID (nacc + nums (Vec.cons x xs))) nregex :=
154+ RegexID.casts regexids (by simp only [nums]; ac_rfl)
155+ let regexidcons : Vec (RegexID (nacc + nums (Vec.cons x xs))) (nregex + 1 ) :=
156+ Vec.cast (Vec.cons regexid' regexesids ') (by simp only)
157157 let accs' : (Vec σ (nacc + nums (Vec.cons x xs))) :=
158158 Vec.cast accs (by simp only [nums]; ac_rfl)
159- (regexes , accs')
159+ (regexidcons , accs')
160160
161161def extractsFrom (xs: Vec (Regex σ) nregex):
162162 (Vec (RegexID (nums xs)) nregex) × (Vec σ (nums xs)) :=
@@ -679,23 +679,13 @@ theorem extractFrom_replaceFrom_is_fmap (r: Regex α) (f: α -> β):
679679 rw [<- replace_cast_both]
680680 rw [<- extract_replace_is_fmap r Vec.nil]
681681
682- theorem zip_map {α: Type } {β: Type } (f: α -> β) (xs: Vec α l):
683- (Vec.map xs (fun x => (x, f x))) =
684- (Vec.zip xs (Vec.map xs f)) := by
685- induction xs with
686- | nil =>
687- simp only [Vec.zip, Vec.map]
688- | @cons l x xs ih =>
689- simp only [Vec.zip, Vec.map]
690- rw [ih]
691-
692682theorem Symbol_derive_is_derive'
693683 {σ: Type } {α: Type } (p: σ -> α -> Bool) (r: Regex σ) (a: α):
694684 Symbol.derive p r a = Symbol.derive' p r a := by
695685 unfold Symbol.derive
696686 unfold Symbol.derive'
697687 simp only
698- rw [zip_map]
688+ rw [Vec. zip_map]
699689
700690theorem Symbol_derive_is_Regex_derive
701691 {σ: Type } {α: Type } (p: σ -> α -> Bool) (r: Regex σ) (a: α):
@@ -1014,26 +1004,6 @@ theorem extracts_fmap2 (rs: Vec (Regex α) l) (acc: Vec α n) (f: α -> β):
10141004 congr 1
10151005 simp only [num_map]
10161006
1017- theorem Vec.map_cons (f : α → β) (x : α) (xs: Vec α n):
1018- Vec.map (Vec.cons x xs) f = (Vec.cons (f x) (Vec.map xs f)) := by
1019- simp only [Vec.map]
1020-
1021- -- theorem map_cons (f : α → β) (x : α) (xs: List α) (h: (x :: xs).length = n):
1022- -- Vec.map ⟨List.cons x xs, h⟩ f = Vec.cast (by
1023- -- simp only [ List.length ] at h
1024- -- subst h
1025- -- simp_all only [add_tsub_cancel_right, Nat.succ_eq_add_one]
1026- -- ) (Vec.cons (f x) ((Vec.map ⟨xs, by
1027- -- simp only [ List.length ] at h
1028- -- rw [<- h]
1029- -- simp only [ add_tsub_cancel_right ]
1030- -- ⟩ f) : Vec β (n - 1)): Vec β ((n - 1).succ)) := by
1031- -- simp only [Vec.map, List.map]
1032- -- -- aesop?
1033- -- subst h
1034- -- simp_all only [ Nat.succ_eq_add_one ]
1035- -- rfl
1036-
10371007theorem RegexID.casts_symm :
10381008 RegexID.casts rs1 h = rs2
10391009 <->
@@ -1047,10 +1017,11 @@ theorem RegexID.casts_symm:
10471017 simp only [RegexID.cast_is_cast_map]
10481018 unfold RegexID.cast_map
10491019 simp only [Regex.map_map]
1050- sorry
1051- -- simp only [Fin.cast_trans, Fin.cast_eq_self]
1052- -- simp only [ Regex.map_id ]
1053- -- simp only [ Vec.map_id ]
1020+ rename_i h_1
1021+ subst h h_1
1022+ simp_all only [Fin.cast_refl, id_eq]
1023+ simp only [Regex.map_id]
1024+ simp only [Vec.map_id]
10541025 case mpr =>
10551026 intro h
10561027 rw [<- h]
@@ -1059,10 +1030,11 @@ theorem RegexID.casts_symm:
10591030 simp only [RegexID.cast_is_cast_map]
10601031 unfold RegexID.cast_map
10611032 simp only [Regex.map_map]
1062- sorry
1063- -- simp only [Fin.cast_trans, Fin.cast_eq_self]
1064- -- simp only [ Regex.map_id ]
1065- -- simp only [ Vec.map_id ]
1033+ rename_i h_1
1034+ subst h h_1
1035+ simp_all only [Fin.cast_refl, id_eq]
1036+ simp only [Regex.map_id]
1037+ simp only [Vec.map_id]
10661038
10671039theorem extracts_append (acc: Vec α n) (xs: Vec (Regex α) l):
10681040 (extracts xs acc).2 = Vec.cast (Vec.append acc (extracts xs Vec.nil).2 ) (by omega) := by
@@ -1093,33 +1065,64 @@ theorem extracts_take (r: Regex α) (acc: Vec α n) (rs: Vec (Regex α) l):
10931065 rw [Vec.take_append]
10941066 rw [Vec.cast_cast]
10951067
1068+ theorem RegexID.cast_lift_cons {x: RegexID n} {h: n = m} {xs: Vec (RegexID n) l}:
1069+ Vec.cons (RegexID.cast x h) (RegexID.casts xs h)
1070+ = RegexID.casts (Vec.cons x xs) h := by
1071+ simp only [RegexID.casts]
1072+ simp only [Vec.map]
1073+
1074+ theorem replacesFrom_cons (rs: Vec (RegexID n) l) (xs: Vec σ n):
1075+ replacesFrom (Vec.cons r rs) xs
1076+ = Vec.cons (replaceFrom r xs) (replacesFrom rs xs)
1077+ := by
1078+ simp only [replacesFrom]
1079+ simp only [Vec.map]
1080+
1081+ theorem RegexID.add_zero :
1082+ (RegexID.add 0 r) = r := by
1083+ simp only [Nat.add_zero, RegexID.add, Fin.eta, Regex.map_id]
1084+
1085+ theorem replaceFrom_append {r: Regex α} {xs: Vec α (n + num r)} {acc: Vec α n} {ys: Vec α m}:
1086+ replaceFrom (RegexID.add m (extract r acc).1 ) (Vec.append xs ys)
1087+ = replaceFrom (extract r acc).1 xs := by
1088+ unfold replaceFrom
1089+ rw [← replace_regexid_add (extract r acc).1 (xs.append ys)]
1090+ rw [← replace_take (extract r acc).1 (xs.append ys)]
1091+ rw [Vec.take_append xs ys]
1092+ rw [replace_cast_symbols]
1093+
1094+ theorem replaceFrom_extracts_cons :
1095+ replaceFrom (RegexID.add (nums rs) (extract r acc).1 ) (((extract r acc).2 .append ((extracts rs Vec.nil).2 .cast h)))
1096+ = replaceFrom (extract r acc).1 (extract r acc).2
1097+ := by
1098+ rw [replaceFrom_append]
1099+
10961100theorem extracts_replacesFrom_is_id (rs: Vec (Regex α) l) (acc: Vec α n):
10971101 rs = replacesFrom (extracts rs acc).1 (extracts rs acc).2 := by
10981102 induction rs generalizing n acc with
10991103 | nil =>
11001104 apply Vec.eq
11011105 simp [extracts, replacesFrom]
11021106 simp only [Vec.map_nil]
1103- | cons r rs ih =>
1104- nth_rewrite 1 [ih acc]
1105-
1106-
1107-
1108-
1109-
1110-
1107+ | @cons l r rs ih =>
11111108 simp only [extracts]
1112- simp only [replacesFrom] at *
1113-
1114-
1115- sorry
1109+ rw [Vec.cast_rfl]
1110+ simp only [RegexID.cast_lift_cons]
1111+ rw [<- replacesFrom_cast_both]
1112+ rw [replacesFrom_cons]
1113+ nth_rewrite 1 [extracts_append]
1114+ congr 1
1115+ · rw [<- Vec.append_cast_r (xs := (extract r acc).2 ) (ys := (extracts rs Vec.nil).2 ) (h := (by simp only [zero_add]))]
1116+ rw [replaceFrom_extracts_cons]
1117+ rw [<- extract_replaceFrom_is_id]
1118+ · generalize (extract r acc).2 = acc'
1119+ rw [<- ih]
11161120
11171121theorem extracts_fmap1 (rs: Vec (Regex α) l) (acc: Vec α n) (f: α -> β):
11181122 (extracts rs acc).1
11191123 = (RegexID.casts (extracts (Regexes.map rs f) (Vec.map acc f)).1
11201124 (by simp only [nums_map])
11211125 ) := by
1122- repeat rw [toList_cast]
11231126 simp only [Regexes.map]
11241127
11251128 induction rs generalizing n acc with
@@ -1192,7 +1195,7 @@ theorem extracts_fmap1 (rs: Vec (Regex α) l) (acc: Vec α n) (f: α -> β):
11921195 -- rw [ hfmap1 ]
11931196
11941197
1195- simp only [Vec.map, List.map, extracts]
1198+ simp only [Vec.map, extracts]
11961199
11971200 sorry
11981201
@@ -1223,7 +1226,7 @@ theorem Symbol_derives_is_fmap
12231226 nth_rewrite 2 [<- Vec.map_map]
12241227 nth_rewrite 1 [<- Vec.map_map]
12251228 apply (congrArg (fun xs => Vec.map xs Regex.derive2))
1226- rw [<- zip_map]
1229+ rw [<- Vec. zip_map]
12271230 -- rewrites under the closure
12281231 simp only [<- extractFrom_replaceFrom_is_fmap]
12291232 rw [<- extractsFrom_replacesFrom_is_fmap]
0 commit comments