我试图编写一个类型为forall n, option (n = 1)
.
我选择option
作为reflect
避免给出否定案例证明的替代方法。所以Some
扮演角色ReflectT
持有证明,None
而不持有否定证明。
Definition is_1 n: bool:=
match n with
1 => true |
_ => false
end.
Lemma is_1_complete : forall n, is_1 n = true -> n = 1.
intros.
destruct n. simpl in H. discriminate.
destruct n. reflexivity.
simpl in H. discriminate.
Qed.
Lemma a_nat_is_1_or_not: forall n, option (n = 1).
intros.
cut (is_1 n = true -> n = 1).
-
intros.
destruct n. exact None.
destruct n. simpl in H. exact (Some (H (eq_refl))).
exact None.
-
exact (is_1_complete n).
Qed.
我已经完成了战术。a_nat_is_1_or_not
是证明。我想我可以直接写定义,所以我尝试了。
Definition a_nat_is_1_or_not' n: option (n = 1) :=
match is_1 n with
true => Some (is_1_complete n eq_refl)
| false => None
end.
但是 Coq 说
Error:
In environment
n : nat
The term "eq_refl" has type "is_1 n = is_1 n"
while it is expected to have type "is_1 n = true" (cannot unify "is_1 n" and
"true").
在自身模式匹配的情况下似乎无法is_1 n
统一。true
true
所以我尝试了一个更简单的例子。
Definition every_true_is_I x: x = I :=
match x with
I => eq_refl
end.
有用。
a_nat_is_1_or_not'
和 和有什么不一样every_truer_is_I
?我错过了什么吗?我能做些什么来写一个有效的定义forall n, is_1 n = true -> n = 1.
?