@@ -153,7 +153,6 @@ def ListCharPos_aux (s: Str) (i: Nat):= match s with
153
153
| _::_ => i:: ListCharPos_aux t (i+ Char.utf8Size h)
154
154
155
155
/- List of the byte positions of all Chars in the String s-/
156
- @[simp]
157
156
def ListCharPos (s: Str) := ListCharPos_aux s 0
158
157
159
158
lemma ListCharPos_aux_sound : x ∈ ListCharPos_aux s k ↔ ∃ p, List.IsPrefix p s ∧ p ≠ s ∧ byteSize p + k = x :=by
@@ -188,11 +187,10 @@ lemma ListCharPos_aux_sound : x ∈ ListCharPos_aux s k ↔ ∃ p, List.IsPrefix
188
187
simp only [ne_eq, not_false_eq_true, not_sym, true_implies] at ind;
189
188
simp only [ind.mpr this, or_true]
190
189
191
- theorem ListCharPos_sound : x ∈ ListCharPos s ↔ ∃ pf , List.IsPrefix pf s ∧ pf ≠ s ∧ byteSize pf = x :=by
190
+ theorem ListCharPos_sound : x ∈ ListCharPos s ↔ ∃ p , List.IsPrefix p s ∧ p ≠ s ∧ byteSize p = x :=by
192
191
simp only [ListCharPos, ListCharPos_aux_sound, ne_eq, add_zero]
193
192
194
193
195
- @[simp]
196
194
def CharBoundPos_aux (l: Str) (s: Nat): List Nat := match l with
197
195
| [] => [s]
198
196
| h::t => s :: CharBoundPos_aux t (s + Char.utf8Size h)
@@ -258,7 +256,6 @@ lemma ListCharPos_prefix_CharBoundPos_aux : List.IsPrefix (ListCharPos_aux s k)
258
256
rw[this] at hl; simp only [succ.injEq] at hl;
259
257
exact ind hl
260
258
261
-
262
259
lemma ListCharPos_prefix_CharBoundPos : List.IsPrefix (ListCharPos s) (CharBoundPos s) := by
263
260
unfold CharBoundPos ListCharPos; apply ListCharPos_prefix_CharBoundPos_aux
264
261
@@ -312,7 +309,8 @@ lemma byteSize_in_CharBoundPos : (byteSize s) ∈ (CharBoundPos s) := by
312
309
unfold CharBoundPos; rw[byteSize_aux_para1_elim]
313
310
apply byteSize_aux_mem_CharBoundPos_aux
314
311
315
- lemma CharBoundPos_eq_ListCharPos_cc_byteSize : CharBoundPos s = (ListCharPos s)++[byteSize s] := by
312
+ theorem CharBoundPos_EQ : CharBoundPos s = CharBoundPos_def s := by
313
+ unfold CharBoundPos_def
316
314
have p: List.IsPrefix (ListCharPos s) (CharBoundPos s) := by exact ListCharPos_prefix_CharBoundPos
317
315
unfold List.IsPrefix at p; obtain ⟨t, ht⟩ := p
318
316
have m: byteSize s ∈ CharBoundPos s := by exact byteSize_in_CharBoundPos
@@ -336,8 +334,13 @@ lemma CharBoundPos_eq_ListCharPos_cc_byteSize: CharBoundPos s = (ListCharPos s)+
336
334
simp only [length_cons, succ.injEq, add_eq_zero, one_ne_zero, and_false, not_false_eq_true,
337
335
not_sym] at tl
338
336
339
- theorem CharBoundPos_EQ : CharBoundPos s = CharBoundPos_def s := by
340
- rw[CharBoundPos_eq_ListCharPos_cc_byteSize, CharBoundPos_def]
337
+ lemma prefix_byteSize_in_CharBoundPos : List.IsPrefix p s → byteSize p ∈ CharBoundPos s :=by
338
+ rw[CharBoundPos_EQ, CharBoundPos_def]; intro g;
339
+ by_cases (p ≠ s)
340
+ have : byteSize p ∈ ListCharPos s :=by apply ListCharPos_sound.mpr; use p;
341
+ simp only [mem_append, this, mem_singleton, true_or]
342
+ rename_i gc; simp only [ne_eq, Decidable.not_not] at gc
343
+ simp only [gc, mem_append, mem_singleton, or_true]
341
344
342
345
lemma prefix_byteSize_le_aux (g: List.IsPrefix p s) : byteSize_aux p k ≤ byteSize_aux s k:=by
343
346
generalize gl: s.length = n
@@ -374,7 +377,6 @@ lemma prefix_byteSize_lt_aux (g: List.IsPrefix p s) (gl: p.length < s.length):
374
377
simp_all only [length_cons, succ.injEq, byteSize_aux, gt_iff_lt]
375
378
apply ind g.right (by omega) gn
376
379
377
-
378
380
lemma prefix_byteSize_lt (g: List.IsPrefix p s) (gp: p.length < s.length): byteSize p < byteSize s :=by
379
381
rw[byteSize_aux_para1_elim]; rw[byteSize_aux_para1_elim]; apply prefix_byteSize_lt_aux g gp
380
382
@@ -392,7 +394,6 @@ lemma byteSize_le_of_length_le (g1: List.IsPrefix p1 s) (g2: List.IsPrefix p2 s)
392
394
have g:= List.prefix_of_prefix_length_le g1 g2 gi
393
395
apply prefix_byteSize_le g
394
396
395
-
396
397
lemma prefix_of_byteSize_le (g1: List.IsPrefix p1 s) (g2: List.IsPrefix p2 s)
397
398
(gi: byteSize p1 ≤ byteSize p2) : List.IsPrefix p1 p2 :=by
398
399
have g:= length_le_of_byteSize_le g1 g2 gi
@@ -426,17 +427,17 @@ theorem is_char_boundary_EQ : is_char_boundary s i = is_char_boundary_def s i :
426
427
unfold is_char_boundary is_char_boundary_def
427
428
have : ∀ m l, m ∈ ListCharPos l ∨ m = byteSize l ↔ m ∈ (ListCharPos l ++ [byteSize l]) :=by
428
429
intro m l; simp only [ListCharPos,byteSize, mem_append, mem_singleton]
429
- rw[this, ← CharBoundPos_eq_ListCharPos_cc_byteSize ]
430
+ rw[this, ← CharBoundPos_def, ← CharBoundPos_EQ ]
430
431
unfold CharBoundPos CharBoundPos_aux
431
432
split; rename_i g; simp only [g, zero_add, mem_cons, true_or]
432
433
split; rename_i g _; simp only [zero_add, mem_cons, g, not_false_eq_true, not_sym, false_or, eq_iff_iff, false_iff]
433
434
rw[CharBoundPos_aux_para1_elim]; by_contra; rename_i gi
434
435
simp only [CharBoundPos, mem_map] at gi; obtain⟨a, ga⟩ := gi; omega
435
436
rename_i gi1 gi2; simp only [zero_add, mem_cons, gi1, not_false_eq_true, not_sym, false_or, eq_iff_iff]
436
437
rw[CharBoundPos_aux_para1_elim]; simp only [CharBoundPos, mem_map]
437
- constructor; intro g; rw[ind, is_char_boundary_def, this, ← CharBoundPos_eq_ListCharPos_cc_byteSize , CharBoundPos] at g;
438
+ constructor; intro g; rw[ind, is_char_boundary_def, this, ← CharBoundPos_def, ← CharBoundPos_EQ , CharBoundPos] at g;
438
439
use i - Char.utf8Size h; simp only [g, true_and]; omega
439
- intro g; obtain⟨a, ga⟩ := g ; rw[ind, is_char_boundary_def, this, ← CharBoundPos_eq_ListCharPos_cc_byteSize , CharBoundPos]
440
+ intro g; obtain⟨a, ga⟩ := g ; rw[ind, is_char_boundary_def, this, ← CharBoundPos_def, ← CharBoundPos_EQ , CharBoundPos]
440
441
have : i - Char.utf8Size h = a := by omega
441
442
rw[this]; simp only [ga]
442
443
@@ -673,8 +674,12 @@ def PrefixFromPos_safe_r (s: Str) (i: Nat): Str := match s with
673
674
def PrefixFromPos (s: Str) (i: Nat): Option Str :=
674
675
if is_char_boundary s i then some (PrefixFromPos_safe_r s i) else none
675
676
677
+ lemma PrefixFromPos_none_sound : PrefixFromPos s i = none ↔ ¬ is_char_boundary s i :=by
678
+ unfold PrefixFromPos
679
+ split; rename_i g; simp only [g, not_true_eq_false]
680
+ rename_i g; simp only [g, Bool.false_eq_true, not_false_eq_true, not_sym]
676
681
677
- lemma PrefixFromPos_verified : PrefixFromPos s i = some p ↔ (List.IsPrefix p s) ∧ (byteSize p = i) := by
682
+ lemma PrefixFromPos_some_sound : PrefixFromPos s i = some p ↔ (List.IsPrefix p s) ∧ (byteSize p = i) := by
678
683
unfold PrefixFromPos ;
679
684
split; simp only [Option.some.injEq, byteSize]
680
685
induction s generalizing i p
@@ -727,7 +732,7 @@ lemma PrefixFromPos_verified: PrefixFromPos s i = some p ↔ (List.IsPrefix p s)
727
732
728
733
lemma PrefixFromPos_byteSize : PrefixFromPos s i = some p → byteSize p = i := by
729
734
intro h ;
730
- have h1 := PrefixFromPos_verified .mp h
735
+ have h1 := PrefixFromPos_some_sound .mp h
731
736
exact h1.right
732
737
733
738
lemma is_char_boundary_from_prefix (h: PrefixFromPos s i = some pre)
@@ -736,10 +741,10 @@ lemma is_char_boundary_from_prefix (h: PrefixFromPos s i = some pre)
736
741
split at h; assumption; contradiction
737
742
738
743
lemma PrefixFromPos_self : PrefixFromPos s0 (byteSize s0) = some s0 :=by
739
- apply PrefixFromPos_verified .mpr; simp
744
+ apply PrefixFromPos_some_sound .mpr; simp
740
745
741
746
lemma PrefixFromPos_prefix (hp: List.IsPrefix i s) : PrefixFromPos s (byteSize i) = some i := by
742
- apply PrefixFromPos_verified .mpr; simp [hp]
747
+ apply PrefixFromPos_some_sound .mpr; simp [hp]
743
748
744
749
lemma PrefixFromPos_eq_split_at_none : PrefixFromPos s i = none ↔ split_at s i = none :=by
745
750
simp only [PrefixFromPos, ite_eq_right_iff, not_false_eq_true, not_sym, imp_false,
0 commit comments