How to prove a = b → a + 1 = b + 1 in lean?

馋奶兔 提交于 2019-12-05 15:54:45

While congr_arg is a good solution in general, this specific example can indeed be solved with eq.subst + higher-order unification (which congr_arg uses internally).

example (a b : nat) (H1 : a = b) : a + 1 = b + 1 :=
eq.subst H1 rfl

You can use the congr_arg lemma

lemma congr_arg {α : Sort u} {β : Sort v} {a₁ a₂ : α} (f : α → β) :
  a₁ = a₂ → f a₁ = f a₂

which means if you supply equal inputs to a function, the output values will be equal too.

The proof goes like this:

example (a b : nat) (H : a = b) : a + 1 = b + 1 :=
  congr_arg (λ n, n + 1) H

Note, that Lean is able to infer that our function is λ n, n + 1, so the proof can be simplified into congr_arg _ H.

More general : a = b -> a + c = b + c in a Ring

import algebra.ring
open algebra

variable {A : Type}

variables [s : ring A] (a b c : A)
include s

example (a b c : A) (H1 : a = b) : a + c = b + c :=
eq.subst H1 rfl
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!