Skip to content

Commit 2bcc611

Browse files
committed
Missing material
1 parent 97e8880 commit 2bcc611

File tree

3 files changed

+104
-4
lines changed

3 files changed

+104
-4
lines changed

src/Init/Data/String/Lemmas/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ theorem push_ne_empty : push s c ≠ "" := by
3939
theorem singleton_ne_empty {c : Char} : singleton c ≠ "" := by
4040
simp [singleton]
4141

42+
@[simp]
43+
theorem Slice.Pos.toCopy_inj {s : Slice} {p₁ p₂ : s.Pos} : p₁.toCopy = p₂.toCopy ↔ p₁ = p₂ := by
44+
simp [Pos.ext_iff, ValidPos.ext_iff]
45+
4246
end String

src/Init/Data/String/Lemmas/Modify.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ theorem toList_mapAux {f : Char → Char} {s : String} {p : s.ValidPos}
4949
theorem toList_map {f : Char → Char} {s : String} : (s.map f).toList = s.toList.map f := by
5050
simp [map, toList_mapAux s.splits_startValidPos]
5151

52+
@[simp]
53+
theorem length_map {f : Char → Char} {s : String} : (s.map f).length = s.length := by
54+
simp [← length_toList]
55+
56+
@[simp]
57+
theorem map_eq_empty {f : Char → Char} {s : String} : s.map f = "" ↔ s = "" := by
58+
simp [← toList_eq_nil_iff]
59+
5260
end String

src/Init/Data/String/Lemmas/Splits.lean

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ theorem ValidPos.Splits.eq {s : String} {p : s.ValidPos} {t₁ t₂ t₃ t₄}
110110
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ ∧ t₂ = t₄ :=
111111
⟨h₁.eq_left h₂, h₁.eq_right h₂⟩
112112

113+
theorem Slice.Pos.Splits.eq_left {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
114+
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ :=
115+
(splits_toCopy_iff.2 h₁).eq_left (splits_toCopy_iff.2 h₂)
116+
117+
theorem Slice.Pos.Splits.eq_right {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
118+
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₂ = t₄ :=
119+
(splits_toCopy_iff.2 h₁).eq_right (splits_toCopy_iff.2 h₂)
120+
121+
theorem Slice.Pos.Splits.eq {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
122+
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ ∧ t₂ = t₄ :=
123+
(splits_toCopy_iff.2 h₁).eq (splits_toCopy_iff.2 h₂)
124+
113125
@[simp]
114126
theorem splits_endValidPos (s : String) : s.endValidPos.Splits s "" where
115127
eq_append := by simp
@@ -121,10 +133,54 @@ theorem splits_endValidPos_iff {s : String} :
121133
fun h => ⟨h.eq_left s.splits_endValidPos, h.eq_right s.splits_endValidPos⟩,
122134
by rintro ⟨rfl, rfl⟩; exact t₁.splits_endValidPos⟩
123135

136+
theorem ValidPos.Splits.eq_endValidPos_iff {s : String} {p : s.ValidPos} (h : p.Splits t₁ t₂) :
137+
p = s.endValidPos ↔ t₂ = "" :=
138+
fun h' => h.eq_right (h' ▸ s.splits_endValidPos),
139+
by rintro rfl; simp [ValidPos.ext_iff, h.offset_eq_rawEndPos, h.eq_append]⟩
140+
124141
theorem splits_startValidPos (s : String) : s.startValidPos.Splits "" s where
125142
eq_append := by simp
126143
offset_eq_rawEndPos := by simp
127144

145+
@[simp]
146+
theorem splits_startValidPos_iff {s : String} :
147+
s.startValidPos.Splits t₁ t₂ ↔ t₁ = "" ∧ t₂ = s :=
148+
fun h => ⟨h.eq_left s.splits_startValidPos, h.eq_right s.splits_startValidPos⟩,
149+
by rintro ⟨rfl, rfl⟩; exact t₂.splits_startValidPos⟩
150+
151+
theorem ValidPos.Splits.eq_startValidPos_iff {s : String} {p : s.ValidPos} (h : p.Splits t₁ t₂) :
152+
p = s.startValidPos ↔ t₁ = "" :=
153+
fun h' => h.eq_left (h' ▸ s.splits_startValidPos),
154+
by rintro rfl; simp [ValidPos.ext_iff, h.offset_eq_rawEndPos]⟩
155+
156+
@[simp]
157+
theorem Slice.splits_endPos (s : Slice) : s.endPos.Splits s.copy "" where
158+
eq_append := by simp
159+
offset_eq_rawEndPos := by simp
160+
161+
@[simp]
162+
theorem Slice.splits_endPos_iff {s : Slice} :
163+
s.endPos.Splits t₁ t₂ ↔ t₁ = s.copy ∧ t₂ = "" := by
164+
rw [← Pos.splits_toCopy_iff, ← endValidPos_copy, splits_endValidPos_iff]
165+
166+
theorem Slice.Pos.Splits.eq_endPos_iff {s : Slice} {p : s.Pos} (h : p.Splits t₁ t₂) :
167+
p = s.endPos ↔ t₂ = "" := by
168+
rw [← toCopy_inj, ← endValidPos_copy, h.toCopy.eq_endValidPos_iff]
169+
170+
@[simp]
171+
theorem Slice.splits_startPos (s : Slice) : s.startPos.Splits "" s.copy where
172+
eq_append := by simp
173+
offset_eq_rawEndPos := by simp
174+
175+
@[simp]
176+
theorem Slice.splits_startPos_iff {s : Slice} :
177+
s.startPos.Splits t₁ t₂ ↔ t₁ = "" ∧ t₂ = s.copy := by
178+
rw [← Pos.splits_toCopy_iff, ← startValidPos_copy, splits_startValidPos_iff]
179+
180+
theorem Slice.Pos.Splits.eq_startPos_iff {s : Slice} {p : s.Pos} (h : p.Splits t₁ t₂) :
181+
p = s.startPos ↔ t₁ = "" := by
182+
rw [← toCopy_inj, ← startValidPos_copy, h.toCopy.eq_startValidPos_iff]
183+
128184
theorem ValidPos.splits_next_right {s : String} (p : s.ValidPos) (hp : p ≠ s.endValidPos) :
129185
p.Splits (s.replaceEnd p).copy (singleton (p.get hp) ++ (s.replaceStart (p.next hp)).copy) where
130186
eq_append := by simpa [← append_assoc] using p.eq_copy_replaceEnd_append_get hp
@@ -135,6 +191,16 @@ theorem ValidPos.splits_next {s : String} (p : s.ValidPos) (hp : p ≠ s.endVali
135191
eq_append := p.eq_copy_replaceEnd_append_get hp
136192
offset_eq_rawEndPos := by simp
137193

194+
theorem Slice.Pos.splits_next_right {s : Slice} (p : s.Pos) (hp : p ≠ s.endPos) :
195+
p.Splits (s.replaceEnd p).copy (singleton (p.get hp) ++ (s.replaceStart (p.next hp)).copy) where
196+
eq_append := by simpa [← append_assoc] using p.copy_eq_copy_replaceEnd_append_get hp
197+
offset_eq_rawEndPos := by simp
198+
199+
theorem Slice.Pos.splits_next {s : Slice} (p : s.Pos) (hp : p ≠ s.endPos) :
200+
(p.next hp).Splits ((s.replaceEnd p).copy ++ singleton (p.get hp)) (s.replaceStart (p.next hp)).copy where
201+
eq_append := p.copy_eq_copy_replaceEnd_append_get hp
202+
offset_eq_rawEndPos := by simp
203+
138204
theorem ValidPos.Splits.exists_eq_singleton_append {s : String} {p : s.ValidPos}
139205
(hp : p ≠ s.endValidPos) (h : p.Splits t₁ t₂) : ∃ t₂', t₂ = singleton (p.get hp) ++ t₂' :=
140206
⟨(s.replaceStart (p.next hp)).copy, h.eq_right (p.splits_next_right hp)⟩
@@ -143,20 +209,42 @@ theorem ValidPos.Splits.exists_eq_append_singleton {s : String} {p : s.ValidPos}
143209
(hp : p ≠ s.endValidPos) (h : (p.next hp).Splits t₁ t₂) : ∃ t₁', t₁ = t₁' ++ singleton (p.get hp) :=
144210
⟨(s.replaceEnd p).copy, h.eq_left (p.splits_next hp)⟩
145211

146-
theorem ValidPos.Splits.eq_endValidPos_iff {s : String} {p : s.ValidPos} (h : p.Splits t₁ t₂) :
147-
p = s.endValidPos ↔ t₂ = "" :=
148-
fun h' => h.eq_right (h' ▸ s.splits_endValidPos),
149-
by rintro rfl; simp [ValidPos.ext_iff, h.offset_eq_rawEndPos, h.eq_append] ⟩
212+
theorem Slice.Pos.Splits.exists_eq_singleton_append {s : Slice} {p : s.Pos}
213+
(hp : p ≠ s.endPos) (h : p.Splits t₁ t₂) : ∃ t₂', t₂ = singleton (p.get hp) ++ t₂' :=
214+
⟨(s.replaceStart (p.next hp)).copy, h.eq_right (p.splits_next_right hp)⟩
215+
216+
theorem Slice.Pos.Splits.exists_eq_append_singleton {s : Slice} {p : s.Pos}
217+
(hp : p ≠ s.endPos) (h : (p.next hp).Splits t₁ t₂) : ∃ t₁', t₁ = t₁' ++ singleton (p.get hp) :=
218+
⟨(s.replaceEnd p).copy, h.eq_left (p.splits_next hp)⟩
150219

151220
theorem ValidPos.Splits.ne_endValidPos_of_singleton {s : String} {p : s.ValidPos}
152221
(h : p.Splits t₁ (singleton c ++ t₂)) : p ≠ s.endValidPos := by
153222
simp [h.eq_endValidPos_iff]
154223

224+
theorem ValidPos.Splits.ne_startValidPos_of_singleton {s : String} {p : s.ValidPos}
225+
(h : p.Splits (t₁ ++ singleton c) t₂) : p ≠ s.startValidPos := by
226+
simp [h.eq_startValidPos_iff]
227+
228+
theorem Slice.Pos.Splits.ne_endPos_of_singleton {s : Slice} {p : s.Pos}
229+
(h : p.Splits t₁ (singleton c ++ t₂)) : p ≠ s.endPos := by
230+
simp [h.eq_endPos_iff]
231+
232+
theorem Slice.Pos.Splits.ne_startPos_of_singleton {s : Slice} {p : s.Pos}
233+
(h : p.Splits (t₁ ++ singleton c) t₂) : p ≠ s.startPos := by
234+
simp [h.eq_startPos_iff]
235+
155236
/-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
156237
theorem ValidPos.Splits.next {s : String} {p : s.ValidPos}
157238
(h : p.Splits t₁ (singleton c ++ t₂)) : (p.next h.ne_endValidPos_of_singleton).Splits (t₁ ++ singleton c) t₂ := by
158239
generalize h.ne_endValidPos_of_singleton = hp
159240
obtain ⟨rfl, rfl, rfl⟩ := by simpa using h.eq (splits_next_right p hp)
160241
exact splits_next p hp
161242

243+
/-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
244+
theorem Slice.Pos.Splits.next {s : Slice} {p : s.Pos}
245+
(h : p.Splits t₁ (singleton c ++ t₂)) : (p.next h.ne_endPos_of_singleton).Splits (t₁ ++ singleton c) t₂ := by
246+
generalize h.ne_endPos_of_singleton = hp
247+
obtain ⟨rfl, rfl, rfl⟩ := by simpa using h.eq (splits_next_right p hp)
248+
exact splits_next p hp
249+
162250
end String

0 commit comments

Comments
 (0)