Skip to content

Commit 5799b12

Browse files
committed
feat: add missing instances
1 parent 1ee871d commit 5799b12

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

Batteries/Data/Stream/Finite.lean

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: François G. Dorais
55
-/
66
import Batteries.WF
7+
import Batteries.Data.ByteSubarray
78

89
/-! # Finite and Well-Founded Streams
910
@@ -91,14 +92,60 @@ def WellFounded.ofMeasure.{u,v} [Stream.{u,v} σ α] (f : σ → Nat)
9192
macro_rules
9293
| `(tactic| decreasing_trivial) => `(tactic| apply Stream.next_of_next?_eq_some; assumption)
9394

94-
instance instWellFoundedList (α) : WellFounded (List α) α :=
95+
instance (α) : WellFounded (List α) α :=
9596
.ofMeasure List.length <| by
96-
intro s t x h
97+
intro _ _ _ h
9798
simp only [next?] at h
9899
split at h
99100
· contradiction
100101
· cases h; simp
101102

103+
instance : WellFounded Substring Char :=
104+
.ofMeasure Substring.bsize <| by
105+
intro _ _ _ h
106+
simp only [next?] at h
107+
split at h
108+
· next hlt =>
109+
cases h
110+
simp only [Substring.bsize, String.next, String.pos_add_char, Nat.sub_eq]
111+
apply Nat.sub_lt_sub_left hlt
112+
apply Nat.lt_add_of_pos_right
113+
exact Char.utf8Size_pos _
114+
· contradiction
115+
116+
instance (α) : WellFounded (Subarray α) α :=
117+
.ofMeasure Subarray.size <| by
118+
intro _ _ _ h
119+
simp only [next?] at h
120+
split at h
121+
· cases h
122+
simp only [Subarray.size, Subarray.stop, Subarray.start]
123+
apply Nat.sub_one_lt
124+
apply Nat.sub_ne_zero_of_lt
125+
assumption
126+
· contradiction
127+
128+
instance : WellFounded Batteries.ByteSubarray UInt8 :=
129+
.ofMeasure Batteries.ByteSubarray.size <| by
130+
intro _ _ _ h
131+
simp only [next?, bind, Option.bind] at h
132+
split at h
133+
· contradiction
134+
· next heq =>
135+
rw [getElem?_def] at heq
136+
split at heq
137+
· next hpos =>
138+
cases h
139+
simp only [Batteries.ByteSubarray.size, Batteries.ByteSubarray.popFront] at hpos ⊢
140+
split
141+
· next heq =>
142+
simp [heq] at hpos
143+
· simp
144+
apply Nat.sub_one_lt
145+
exact Nat.ne_zero_of_lt hpos
146+
· contradiction
147+
done
148+
102149
/-- Class for a finite stream of type `σ`. -/
103150
class Finite [WithNextRelation σ α] (s : σ) : Prop where
104151
/-- A finite stream is accessible with respect to the `Next` relation. -/

0 commit comments

Comments
 (0)