Apply a function to both sides of an equality in Coq?

浪尽此生 提交于 2020-01-03 09:01:06

问题


I'm in Coq trying to prove that

Theorem evenb_n__oddb_Sn : ∀n : nat,
  evenb n = negb (evenb (S n)).

I'm using induction on n. The base case is trivial, so I'm at the inductive case and my goal looks like:

k : nat
IHk : evenb k = negb (evenb (S k))
============================
 evenb (S k) = negb (evenb (S (S k)))

Now of course there's a fundamental axiom of functions that asserts

a = b -> f a = f b

For all functions f : A -> B. So I could apply negb to both sides, which would give me

k : nat
IHk : evenb k = negb (evenb (S k))
============================
 negb (evenb (S k)) = negb (negb (evenb (S (S k))))

Which would let me use my inductive hypothesis from right to left, the negations on the right would cancel each other out, and the defintion of evenb would complete the proof.

Now, there might be a better way to prove this particular theorem (edit: there is, I did it another way), but as this in general seems like a useful thing to do, what's the way to modify an equality goal in Coq by applying a function to both sides?

Note: I realize that this wouldn't work for any arbitrary function: for example, you could use it to prove that -1 = 1 by applying abs to both sides. However, it holds for any injective function (one for which f a = f b -> a = b), which negb is. Perhaps a better question to ask, then, is given a function which operates on a proposition (for example, negb x = negb y -> x = y), how can I use that function to modify the current goal?


回答1:


It seems that you just want the apply tactic. If you have a lemma negb_inj : forall b c, negb b = negb c -> b = c, doing apply negb_inj on your goal would give you exactly that.



来源:https://stackoverflow.com/questions/27069454/apply-a-function-to-both-sides-of-an-equality-in-coq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!