Zulip Chat Archive
Stream: Is there code for X?
Topic: add_min_max
Xavier Xarles (Apr 22 2022 at 08:12):
I am quite sure this is already in mathlib, but I cannot find it
import data.int.basic
lemma add_min_max {a b : ℕ}: a+b= (min a b)+(max a b):=
begin
cases le_total a b with h h,
rw [min_eq_left h,max_eq_right h],
rw [min_eq_right h,max_eq_left h,add_comm a b],
end
Of course it can be done with other type of numbers or much more generally...
Thanks!
Yaël Dillies (Apr 22 2022 at 08:12):
Kevin Buzzard (Apr 22 2022 at 08:42):
import tactic
lemma add_min_max {a b : ℕ}: a+b= (min a b)+(max a b):=
begin
library_search
end
is the way to answer questions like this. Note that "equality is not symmetric" in Lean! In the maths library the convention is to put the more complicated expression on the left hand side of the equality (so that you can rw
more easily) , so you would expect the result to be min a b + max a b = a + b
, as indeed it is, but library_search
is smart enough to spot the result anyway.
Xavier Xarles (Apr 22 2022 at 11:08):
I tried library_search but didn't work. May be because I did not import tactic first?
Kevin Buzzard (Apr 22 2022 at 11:34):
import data.int.basic
lemma add_min_max {a b : ℕ}: a+b= (min a b)+(max a b):=
begin
library_search
end
works for me. I often import tactic
though because it just guarantees that you have a bunch of basic stuff imported.
Last updated: Dec 20 2023 at 11:08 UTC