even_Sn_not_even_n-在另一个假设中应用1个假设

时间:2019-05-29 06:05:41

标签: coq logical-foundations

不幸的是,我再次被困住了:

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编写呢?

1 个答案:

答案 0 :(得分:2)

去除双重否定的常用方法是引入“排除的中间”公理(在Coq.Logic.Classical_Prop中以名称classic定义,并应用引理NNPP

>

但是,在这种特殊情况下,您可以通过显示Prop与布尔函数一致来使用 reflection 技术(您可能还记得前面介绍的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中“反射”部分下的练习,然后尝试以下练习:

(* 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.