I'm working my way through the chapter 4 of the lean tutorial.
I'd like to be able to prove simple equalities, such as a = b → a + 1 = b + 1
without having to use the calc environment. In other words I'd like to explicitly construct the proof term of:
example (a b : nat) (H1 : a = b) : a + 1 = b + 1 := sorry
My best guess is that I need to use eq.subst
and some relevant lemma about equality on natural numbers from the standard library, but I'm at loss. The closest lean example I can find is this:
example (A : Type) (a b : A) (P : A → Prop) (H1 : a = b) (H2 : P a) : P b :=
eq.subst H1 H2
More general : a = b -> a + c = b + c in a Ring
While
congr_arg
is a good solution in general, this specific example can indeed be solved witheq.subst
+ higher-order unification (whichcongr_arg
uses internally).You can use the
congr_arg
lemmawhich means if you supply equal inputs to a function, the output values will be equal too.
The proof goes like this:
Note, that Lean is able to infer that our function is
λ n, n + 1
, so the proof can be simplified intocongr_arg _ H
.