Coq中加法的归纳谓词

时间:2014-03-14 15:29:52

标签: coq

我对Coq的归纳谓词不熟悉。我已经学会了如何定义简单的归纳谓词,例如" even" (如adam.chlipala.net/cpdt/html/Predicates.html)或" last" (如http://www.cse.chalmers.se/research/group/logic/TypesSS05/resources/coq/CoqArt/inductive-prop-chap/SRC/last.v)。

现在我想尝试一些稍微复杂的东西:将加法定义为归纳谓词,但我陷入困境。我做了以下事情:

Inductive N : Type :=
| z : N  (* zero *)
| s : N -> N.  (* successor *)

Inductive Add: N -> N -> N -> Prop :=
| add_z: forall n, (Add n z n)
| add_s: forall m n r, (Add m n r) -> (Add m (s n) (s r)).

Fixpoint plus (x y : N) := 
  match y with
  | z => x
  | (s n) => (s (plus x n))
  end.

我想证明一个简单的定理(类似于www.cse.chalmers.se/research/group/logic/TypesSS05/resources/coq/CoqArt/inductive-prop-中为last和last所做的事情。 CHAP / SRC / last.v):

Theorem T1: forall x y r, (plus x y) = r -> (Add x y r).
Proof.
intros x y r. induction y.
  simpl. intro H. rewrite H. apply add_z.

  case r.
    simpl. intro H. discriminate H.

    ???

但后来我陷入困境。归纳假设似乎很奇怪。我不知道我是否错误地定义了Add,或者我是否只是使用了错误的策略。你能帮助我,纠正我的归纳Add或告诉我如何完成这个证明吗?

1 个答案:

答案 0 :(得分:2)

您在使用r上的归纳之前介绍了y。一般来说,你会在引入任何东西之前使用归纳法,因此归纳假设尽可能通用。

Conjecture injectivity : forall n m, s n = s m -> n = m.

Theorem T1: forall x y r, (plus x y) = r -> (Add x y r).
Proof.
intros x y. induction y.
  simpl. intros r H. rewrite H. apply add_z.

  intro r. case r.
    simpl. intro H. discriminate H.

    simpl. intros n H. apply add_s. apply IHy. apply injectivity. apply H.
Qed.
相关问题