Coq初学者 - 证明一个基本的引理

时间:2017-03-20 01:43:41

标签: coq

我是Coq的初学者所以也许我的问题似乎是一个愚蠢的问题,但这是我的问题:

我定义了一个简单的模块,我在其中定义了一个类型T和一个函数“my_custom_equal”:

  Definition T := nat.

  Fixpoint my_custom_equal (x y : T) :=
    match x, y with
      | O, O => true
      | O, S _ => false
      | S _, O => false
      | S sub_x, S sub_y => my_custom_equal sub_x sub_y
    end.

  Lemma my_custom_reflex : forall x : T, my_custom_equal x x = true.
  Proof.
    intros.
    induction x.
    simpl.
    reflexivity.
    simpl.
    rewrite IHx.
    reflexivity.
  Qed.

  Lemma my_custom_unicite : forall x y : T, my_custom_equal x y = true -> x = y.
  Proof.
    intros.
    induction x.
    induction y.
    reflexivity.
    discriminate.

  Qed.

正如你所看到的,它并不是很复杂,但我仍然坚持my_custom_unicite证明,我总是达到我需要证明“S x = y”并且我的假设只是:

y : nat
H : my_custom_equal 0 (S y) = true
IHy : my_custom_equal 0 y = true -> 0 = y
______________________________________(1/1)
S x = y

我不明白如何实现这个证据,你能帮助我吗?

谢谢!

1 个答案:

答案 0 :(得分:4)

这是初学者的典型陷阱。问题是,当您在上下文中引入x时,您已在y上执行归纳。因此,您获得的归纳假设不够通用:您真正想要的是具有类似的东西

forall y, my_custom_equal x y = true -> x = y

注意额外的forall。解决方案是将y放回到您的目标中:

Lemma my_custom_unicite : forall x y, my_custom_equal x y = true -> x = y.
Proof.
intros x y. revert y.
induction x as [|x IH].
- intros []; easy.
- intros [|y]; try easy.
  simpl.
  intros H.
  rewrite (IH y H).
  reflexivity.
Qed.

尝试以交互方式运行此证明,并检查当您到达第二个案例时,归纳假设如何变化。

相关问题