在假设中应用依赖类型的构造函数

时间:2018-02-03 06:50:18

标签: coq

考虑以下归纳定义:

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失败。为什么?我怎样才能让它发挥作用?

3 个答案:

答案 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

这使得推理正确;所以它不会引入不一致。