考虑以下归纳定义:
Inductive T (n : nat) : nat -> Prop :=
| c1 : T n n.
这有效:
Theorem a : T 1 1.
Proof.
apply c1.
Qed.
但这并不是:
Theorem b : T 1 1 -> True.
Proof.
intros H.
apply c1 in H.
对apply
的两次调用似乎都与我相同,但后者与Error: Statement without assumptions
失败。为什么?我怎样才能让它发挥作用?
答案 0 :(得分:1)
This question arose from my poor understanding of the apply
tactic. @gallais's comment made me realize why apply c1 in H
doesn't really make sense. The tactic essentially works as a function application on H
and c1 H
doesn't really make sense. For future reference, this is an example in which apply in
would make sense. If we had another constructor c2
like this:
Inductive T (n : nat) : nat -> Prop :=
| c1 : T n n
| c2 : forall x, T n x -> T n (S x).
Then apply c2 in H
would transform something of type T n x
into something of type T n (S x)
, for example:
Theorem b : T 1 1 -> True.
Proof.
intros H.
apply c2 in H.
transforms the hypothesis H : T 1 1
into H : T 1 2
.
答案 1 :(得分:0)
证明H
或证明H -> True
之间存在差异。 Coq标准库已经定义了True
的证明,称为I.
因此:
Theorem b : T 1 1 -> True.
Proof.
intros; apply I.
Qed.
但请注意:
Theorem prove_I : forall p : Prop, p -> True.
Proof.
intros; apply I.
Qed.
结果H -> True
无法证明H
,两种类型的居民之间没有相关性。
答案 2 :(得分:0)
apply
策略在应用于目标或假设时的工作方式不同。应用H : A -> B
具有以下语义:
B
,那么在A
apply H.
H1 : A
,则会在H1 : B
之后将其转换为apply H in H1
这使得推理正确;所以它不会引入不一致。