Zulip Chat Archive
Stream: lean4
Topic: Swiching both sides of the equation
Denson Cash (Dec 18 2023 at 16:59):
I am currently working through "Mathematics in Lean" and reached chapter 2, section 2. There, I already proved eq_neg_of_add_eq_zero
the following way:
theorem eq_neg_of_add_eq_zero {a b : R} (h : a + b = 0) : a = -b := by
rw [← add_left_neg b] at h
exact add_right_cancel h
Now I want to prove neg_eq_of_add_eq_zero
similiarly, but this doesn't work:
theorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b := by
rw [← add_right_neg a] at h
exact add_left_cancel h
application type mismatch
add_left_cancel h
argument
h
has type
a + b = a + -a : Prop
but is expected to have type
a + -a = a + b : Prop
I guess Lean needs me to switch both sides of the equation in h
before finishing with exact add_left_cancel h
and I was wondering how to that. Also, feel free to suggest improvements of my code.
Pedro Sánchez Terraf (Dec 18 2023 at 17:06):
h.symm
is h
with sides switched.
Patrick Massot (Dec 18 2023 at 17:08):
The intended solution uses neg_add_cancel_left
.
Patrick Massot (Dec 18 2023 at 17:08):
But of course there are many ways to prove this.
Denson Cash (Dec 18 2023 at 17:24):
My current working solution looks like this (thanks to Pedro Sánchez Terraf):
theorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b := by
rw [← add_right_neg a] at h
exact add_left_cancel h.symm
Last updated: Dec 20 2023 at 11:08 UTC