Coq:当只有一种情况时,对集合的道具执行反转

Coq:当只有一种情况时,对集合的道具执行反转,coq,dependent-type,coq-tactic,ltac,Coq,Dependent Type,Coq Tactic,Ltac,假设我有一些编程语言,具有“has-type”关系和“small-step”关系 Inductive type : Set := | Nat : type | Bool : type. Inductive tm : Set := | num : nat -> tm | plus : tm -> tm -> tm | lt : tm -> tm -> tm | ifthen : tm -> tm -> tm -> tm. Inductive ha

假设我有一些编程语言,具有“has-type”关系和“small-step”关系

Inductive type : Set :=
| Nat : type
| Bool : type.

Inductive tm : Set :=
| num : nat -> tm
| plus : tm -> tm -> tm
| lt : tm -> tm -> tm
| ifthen : tm -> tm -> tm -> tm.

Inductive hasType : tm -> type -> Prop :=
| hasTypeNum :
    forall n, hasType (num n) Nat
| hasTypePlus:
    forall tm1 tm2,
      hasType tm1 Nat ->
      hasType tm2 Nat ->
      hasType (plus tm1 tm2) Nat
| hasTypeLt:
    forall tm1 tm2,
      hasType tm1 Nat ->
      hasType tm2 Nat ->
      hasType (lt tm1 tm2) Bool
| hasTypeIfThen:
    forall tm1 tm2 tm3,
      hasType tm1 Bool ->
      hasType tm2 Nat ->
      hasType tm3 Nat ->
      hasType (ifthen tm1 tm2 tm3) Nat.

Inductive SmallStep : tm -> tm -> Prop :=
  ...

Definition is_value (t : tm) := ...
这里的关键细节是,对于每个术语变体,只有一个可能匹配的HasType变体

假设我想证明一个进步引理,但我也想从中提取一个解释器

Lemma progress_interp: 
  forall tm t, 
  hasType tm t -> 
  (is_value tm = false) -> 
  {tm2 | SmallStep tm tm2}.
intro; induction tm0; intros; inversion H.
这就产生了错误
反转需要对排序集进行案例分析,这是归纳定义hasType不允许的。

我理解它为什么这样做:
inversion
对sort
Prop
的值执行案例分析,我们不能这样做,因为它在提取的代码中被擦除

但是,因为术语变量和类型派生规则之间存在一对一的对应关系,所以我们实际上不必在运行时执行任何分析

理想情况下,我可以应用一组如下所示的引理:

plusInv: forall e t, hasType e t ->
  (forall e1 e2, e = plus e1 e2 -> hasType e1 Nat /\ hasType e2 Nat ).
每个例子都会有一个这样的引理(或者一个单独的引理是这些例子的结合)

我已经研究了
派生反转
,但它似乎并没有达到我在这里寻找的效果,尽管我可能没有正确地理解它


有没有办法进行这种“只有一个案例的案例分析?”或者得到
Prop
证明所隐含的等式,这样我就只能在解释器中写出可能的案例?通过Ltac或派生机制,可以自动导出这些引理吗?

我认为
eexists
会起到作用:存在变量应该在sigma类型的证明过程中的某个点上填充(在这里,你可以自由使用
hasType
假设的
反转
).

引理
加上_inv
可以通过对类型
tm
的案例分析而不是对类型
hasType
的案例分析来获得

Lemma plus_inv : forall e t, hasType e t ->
  (forall e1 e2, e = plus e1 e2 -> hasType e1 Nat /\ hasType e2 Nat ).
Proof.
intros e; case e; try (intros; discriminate).
intros e1 e2 t h; inversion h; intros e5 e6 heq; inversion heq; subst; auto.
Qed.
您的主要目标
进度证明\u interp
很可能可以执行 通过对
tm
结构的归纳,也可以得出结论。这相当于将解释器直接作为gallina递归函数编写


你的问题有第二部分:这可以自动化吗。答案可能是肯定的。我建议使用软件包或软件包。这两个包都可以作为opam包使用。

我过去曾尝试过这一点,但在统一失败时经常会遇到问题,因为存在的解决方案不在它的范围内。是否有一个通用的解决方法?我认为
eexists
不是答案。如果这确实有效,那么逻辑系统的一致性(也与提取有关)将面临风险。我编辑了
plus_inv
:CoqThanks不接受前面的语句。对我来说,真正的关键是使它自动化,因为我所处理的语言比我在这里使用的玩具语言要多得多。我将看看模板Coq,它似乎非常有用!