@@ -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]
114126theorem 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+
124141theorem 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+
128184theorem 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+
138204theorem 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
151220theorem 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. -/
156237theorem 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+
162250end String
0 commit comments