Skip to content

Commit 97e8880

Browse files
committed
Remove redundant hypotheses
1 parent 825f86b commit 97e8880

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ theorem singleton_append_inj : singleton c ++ s = singleton d ++ t ↔ c = d ∧
2727
theorem push_inj : push s c = push t d ↔ s = t ∧ c = d := by
2828
simp [← toList_inj]
2929

30+
@[simp]
31+
theorem append_eq_empty_iff {s t : String} : s ++ t = "" ↔ s = "" ∧ t = "" := by
32+
rw [← toList_inj]; simp
33+
34+
@[simp]
35+
theorem push_ne_empty : push s c ≠ "" := by
36+
rw [ne_eq, ← toList_inj]; simp
37+
38+
@[simp]
39+
theorem singleton_ne_empty {c : Char} : singleton c ≠ "" := by
40+
simp [singleton]
41+
3042
end String

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module
88
prelude
99
public import Init.Data.String.Modify
1010
import all Init.Data.String.Modify
11+
import Init.Data.String.Lemmas.Basic
1112

1213
/-!
1314
# Lemmas for `Init.Data.String.Modify`
@@ -21,28 +22,28 @@ public section
2122

2223
namespace String
2324

24-
-- TODO: `hp` actually follows from `h`.
2525
/-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
26-
theorem ValidPos.Splits.pastSet {s : String} {p : s.ValidPos} {t₁ t₂ : String} (hp : p ≠ s.endValidPos)
26+
theorem ValidPos.Splits.pastSet {s : String} {p : s.ValidPos} {t₁ t₂ : String}
2727
{c d : Char} (h : p.Splits t₁ (singleton c ++ t₂)) :
28-
(p.pastSet d hp).Splits (t₁ ++ singleton d) t₂ := by
28+
(p.pastSet d h.ne_endValidPos_of_singleton).Splits (t₁ ++ singleton d) t₂ := by
29+
generalize h.ne_endValidPos_of_singleton = hp
2930
obtain ⟨rfl, rfl, rfl⟩ := by simpa using h.eq (p.splits_next_right hp)
3031
apply splits_pastSet
3132

32-
-- TODO: `hp` actually follows from `h`.
3333
/-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
34-
theorem ValidPos.Splits.pastModify {s : String} {p : s.ValidPos} {t₁ t₂ : String} (hp : p ≠ s.endValidPos)
34+
theorem ValidPos.Splits.pastModify {s : String} {p : s.ValidPos} {t₁ t₂ : String}
3535
{c : Char} (h : p.Splits t₁ (singleton c ++ t₂)) :
36-
(p.pastModify f hp).Splits (t₁ ++ singleton (f (p.get hp))) t₂ :=
37-
h.pastSet hp
36+
(p.pastModify f h.ne_endValidPos_of_singleton).Splits
37+
(t₁ ++ singleton (f (p.get h.ne_endValidPos_of_singleton))) t₂ :=
38+
h.pastSet
3839

3940
theorem toList_mapAux {f : Char → Char} {s : String} {p : s.ValidPos}
4041
(h : p.Splits t₁ t₂) : (mapAux f s p).toList = t₁.toList ++ t₂.toList.map f := by
4142
fun_induction mapAux generalizing t₁ t₂ with
4243
| case1 s => simp_all
4344
| case2 s p hp ih =>
4445
obtain ⟨c, rfl⟩ := h.exists_eq_singleton_append hp
45-
simp [ih (h.pastModify hp)]
46+
simp [ih h.pastModify]
4647

4748
@[simp]
4849
theorem toList_map {f : Char → Char} {s : String} : (s.map f).toList = s.toList.map f := by

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,19 @@ theorem ValidPos.Splits.exists_eq_append_singleton {s : String} {p : s.ValidPos}
143143
(hp : p ≠ s.endValidPos) (h : (p.next hp).Splits t₁ t₂) : ∃ t₁', t₁ = t₁' ++ singleton (p.get hp) :=
144144
⟨(s.replaceEnd p).copy, h.eq_left (p.splits_next hp)⟩
145145

146-
-- TODO: `hp` actually follows from `h`.
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] ⟩
150+
151+
theorem ValidPos.Splits.ne_endValidPos_of_singleton {s : String} {p : s.ValidPos}
152+
(h : p.Splits t₁ (singleton c ++ t₂)) : p ≠ s.endValidPos := by
153+
simp [h.eq_endValidPos_iff]
154+
147155
/-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
148-
theorem ValidPos.Splits.next {s : String} {p : s.ValidPos} (h : p.Splits t₁ (singleton c ++ t₂))
149-
(hp : p ≠ s.endValidPos) : (p.next hp).Splits (t₁ ++ singleton c) t₂ := by
156+
theorem ValidPos.Splits.next {s : String} {p : s.ValidPos}
157+
(h : p.Splits t₁ (singleton c ++ t₂)) : (p.next h.ne_endValidPos_of_singleton).Splits (t₁ ++ singleton c) t₂ := by
158+
generalize h.ne_endValidPos_of_singleton = hp
150159
obtain ⟨rfl, rfl, rfl⟩ := by simpa using h.eq (splits_next_right p hp)
151160
exact splits_next p hp
152161

0 commit comments

Comments
 (0)