Zulip Chat Archive
Stream: mathlib4
Topic: analyzing the definition of `Substring.next`
Bulhwi Cha (Apr 25 2023 at 09:40):
import Mathlib.Data.String.Basic
namespace Substring
def next' : Substring → String.Pos → String.Pos
| ⟨s, b, e⟩, p =>
let absP := b+p
if absP = e then p else p + s.get absP
theorem next_eq_next' : next = next' := by
funext ⟨s, b, e⟩ p
simp [next, next']
split
· rfl
· simp [String.next, String.Pos.ext_iff]
show b.byteIdx + p.byteIdx + String.csize (String.get s (b + p)) - b.byteIdx =
p.byteIdx + String.csize (String.get s (b + p))
rw [Nat.add_comm, Nat.add_sub_assoc, Nat.add_sub_self_left, Nat.add_comm]
apply Nat.le_add_right
end Substring
Is there a better way to prove the above theorem?
Kevin Buzzard (Apr 25 2023 at 10:34):
To unobfuscate: I think you're really asking how to prove foo
, right?
@[simp] lemma String.byteIdx_add {b p : String.Pos} :
(b + p).byteIdx = b.byteIdx + p.byteIdx := rfl
lemma foo (a b c : ℕ) : a + b + c - a = b + c := sorry
theorem next_eq_next' : next = next' := by
funext ⟨s, b, e⟩ p
simp [next, next']
split
· rfl
· simp [String.next, foo]
Floris van Doorn (Apr 25 2023 at 10:55):
foo
is docs4#Nat.add_sub_cancel_left / docs4#add_tsub_cancel_left or maybe one add_assoc
away from it.
Bulhwi Cha (Apr 25 2023 at 11:31):
Kevin Buzzard said:
To unobfuscate: I think you're really asking how to prove
foo
, right?
Right, but I also wonder whether we need to include several lemmas like String.byteIdx_add
in Lean's core library.
Bulhwi Cha (Apr 25 2023 at 11:57):
Floris van Doorn said:
foo
is docs4#Nat.add_sub_cancel_left / docs4#add_tsub_cancel_left or maybe oneadd_assoc
away from it.
Thanks!
example (a b c : Nat) : a + b + c - a = b + c := by
rw [Nat.add_assoc, Nat.add_sub_cancel_left]
Edited proof
Bulhwi Cha (May 02 2023 at 01:00):
Now Kevin Buzzard's proof should be modified as follows:
Edited proof
Last updated: Dec 20 2023 at 11:08 UTC