如何使 coq 简化蕴涵假设中的表达式
How to make coq simplify expressions inside an implication hypothesis
我试图证明以下引理:
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.
+ unfold not. intros H. induction n as [|n' E' IHn].
-
Qed.
这是我最后得到的:
1 subgoal (ID 173)
H : even 0 -> False
============================
even 1
我希望 coq 计算 "even 0" 为真,"even 1" 为假。我尝试了 simpl
、apply ev_0 in H.
,但它们给出了错误。怎么办?
回答题目
simpl in H.
真实答案
上面的代码是行不通的。
《逻辑基础》一书中 even
的定义是:
Inductive even : nat → Prop :=
| ev_0 : even 0
| ev_SS (n : nat) (H : even n) : even (S (S n)).
even 0
是 Prop,不是布尔值。看起来您混淆了类型 True
和 False
以及布尔值 true
和 false
。它们是完全不同的东西,并且在 Coq 的逻辑下不可互换。简而言之,even 0
不会简化为 true
或 True
或任何东西。它只是 even 0
. 如果你想证明 even 0
在逻辑上是正确的,你应该构造一个该类型的值。
我不记得当时在 LF 中有哪些战术可用,但这里有一些可能性:
(* Since you know `ev_0` is a value of type `even 0`,
construct `False` from H and destruct it.
This is an example of forward proof. *)
set (contra := H ev_0). destruct contra.
(* ... or, in one step: *)
destruct (H ev_0).
(* We all know `even 1` is logically false,
so change the goal to `False` and work from there.
This is an example of backward proof. *)
exfalso. apply H. apply ev_0.
我试图证明以下引理:
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.
+ unfold not. intros H. induction n as [|n' E' IHn].
-
Qed.
这是我最后得到的:
1 subgoal (ID 173)
H : even 0 -> False
============================
even 1
我希望 coq 计算 "even 0" 为真,"even 1" 为假。我尝试了 simpl
、apply ev_0 in H.
,但它们给出了错误。怎么办?
回答题目
simpl in H.
真实答案
上面的代码是行不通的。
《逻辑基础》一书中 even
的定义是:
Inductive even : nat → Prop :=
| ev_0 : even 0
| ev_SS (n : nat) (H : even n) : even (S (S n)).
even 0
是 Prop,不是布尔值。看起来您混淆了类型 True
和 False
以及布尔值 true
和 false
。它们是完全不同的东西,并且在 Coq 的逻辑下不可互换。简而言之,even 0
不会简化为 true
或 True
或任何东西。它只是 even 0
. 如果你想证明 even 0
在逻辑上是正确的,你应该构造一个该类型的值。
我不记得当时在 LF 中有哪些战术可用,但这里有一些可能性:
(* Since you know `ev_0` is a value of type `even 0`,
construct `False` from H and destruct it.
This is an example of forward proof. *)
set (contra := H ev_0). destruct contra.
(* ... or, in one step: *)
destruct (H ev_0).
(* We all know `even 1` is logically false,
so change the goal to `False` and work from there.
This is an example of backward proof. *)
exfalso. apply H. apply ev_0.