1

不幸的是,我再次陷入困境:

Inductive even : nat > Prop :=
| ev_0 : even 0
| ev_SS (n : nat) (H : even n) : even (S (S n)).

Lemma even_Sn_not_even_n : forall n,
    even (S n) <-> not (even n).
Proof.
  intros n. split.
  + intros H. unfold not. intros H1. induction H1 as [|n' E' IHn].
    - inversion H.
    - inversion_clear H. apply IHn in H0. apply H0.
  + intros H. induction n as [|n' IHn].
    - exfalso. apply H. apply ev_0.
    - apply evSS_inv'.

结果如下:

1 subgoal (ID 179)

n' : nat
H : ~ even (S n')
IHn : ~ even n' -> even (S n')
============================
even n'

据我所知,我可以用文字来证明:

(n' + 1) 根据 H 不是偶数。因此根据 IHn,n' 不是偶数是不正确的(双重否定):

IHn : ~ ~ even n'

展开双重否定,我们得出结论 n' 是偶数。

但是如何在 coq 中编写呢?

4

1 回答 1

2

去除双重否定的常用方法是引入“排中”公理,该公理在 中的名称下定义classicCoq.Logic.Classical_Prop并应用引理NNPP

但是,在这种特殊情况下,您可以通过显示 Prop 与布尔函数一致来使用称为反射evenb的技术(您可能还记得本书前面介绍的函数)。

(假设您处于 IndProp 的开头)您很快就会在该章后面看到以下定义:

Inductive reflect (P : Prop) : bool -> Prop :=
| ReflectT (H : P) : reflect P true
| ReflectF (H : ~ P) : reflect P false.

你可以证明这个说法

Lemma even_reflect : forall n : nat, reflect (even n) (evenb n).

然后使用它同时在 Prop 和布尔值(它们包含相同的信息,即 的(非)均匀性n)之间移动。这也意味着您可以在不使用classic公理的情况下对该特定属性进行经典推理。

我建议完成 IndProp 中 Reflection 部分的练习,然后尝试以下练习。(编辑:我在这里上传了完整的答案。)

(* Since `evenb` has a nontrivial recursion structure, you need the following lemma: *)
Lemma nat_ind2 :
  forall P : nat -> Prop,
  P 0 -> P 1 -> (forall n : nat, P n -> P (S (S n))) -> forall n : nat, P n.
Proof. fix IH 5. intros. destruct n as [| [| ]]; auto.
  apply H1. apply IH; auto. Qed.

(* This is covered in an earlier chapter *)
Lemma negb_involutive : forall x : bool, negb (negb x) = x.
Proof. intros []; auto. Qed.

(* This one too. *)
Lemma evenb_S : forall n : nat, evenb (S n) = negb (evenb n).
Proof. induction n.
  - auto.
  - rewrite IHn. simpl. destruct (evenb n); auto. Qed.

(* Exercises. *)
Lemma evenb_even : forall n : nat, evenb n = true -> even n.
Proof. induction n using nat_ind2.
  (* Fill in here *) Admitted.

Lemma evenb_odd : forall n : nat, evenb n = false -> ~ (even n).
Proof. induction n using nat_ind2.
  (* Fill in here *) Admitted.

Lemma even_reflect : forall n : nat, reflect (even n) (evenb n).
Proof. (* Fill in here. Hint: You don't need induction. *) Admitted.

Lemma even_iff_evenb : forall n, even n <-> evenb n = true.
Proof. (* Fill in here. Hint: use `reflect_iff` from IndProp. *) Admitted.

Theorem reflect_iff_false : forall P b, reflect P b -> (~ P <-> b = false).
Proof. (* Fill in here. *) Admitted.

Lemma n_even_iff_evenb : forall n, ~ (even n) <-> evenb n = false.
Proof. (* Fill in here. *) Admitted.

Lemma even_Sn_not_even_n : forall n,
    even (S n) <-> not (even n).
Proof. (* Fill in here.
  Hint: Now you can convert all the (non-)evenness properties to booleans,
  and then work with boolean logic! *) Admitted.
于 2019-05-29T08:25:12.740 回答