Coq 具有依赖类型的析构函数

Coq 具有依赖类型的析构函数,coq,theorem-proving,Coq,Theorem Proving,我为编译器定义了几种归纳类型,我正在验证这种形式 Inductive types := Int | Char | Symbol | Bool. Inductive val : types -> Type := | T : val Bool | F : val Bool | Num : nat -> val Int ... Inductive exp : types -> Type := | If : forall {t}, val Bool -> exp t -

我为编译器定义了几种归纳类型,我正在验证这种形式

Inductive types := Int | Char | Symbol | Bool.
Inductive val : types -> Type := 
| T : val Bool
| F : val Bool
| Num : nat -> val Int
...

Inductive exp : types -> Type :=
   | If : forall {t}, val Bool -> exp t -> exp t -> exp t
   etc...
这很好,简化了很多事情,直到我试图证明一些定理,比如

Theorem example : forall t test (b1 b2 : exp t),
    eval (If test b1 b2) = eval b1
    \/ eval (If test b1 b2) = eval b2.
现在我想用<代码>破坏测试进行微不足道的案例分析,因为只有2个案例,即代码> T 和<代码> f>代码>。但是如果我尝试这样做,我会得到一个错误,通知我
destruct
策略会生成类型错误的术语。确实如此


有没有类似于destruct的策略,可以让我在输入良好的条件下进行案例分析,并自动分派那些输入不良的条件?我怀疑这是不可能的,在这种情况下,处理这类证明的正确方法是什么?

由于您没有提供代码,我不会尝试确保这是可行的,但其要点是执行依赖反转,传递应使用的类型:

dependent inversion test with (
  fun t v =>
  match t as _t return val _t -> Prop with
  | Bool => fun v => eval (If v b1 b2) = eval b1 \/ eval (If v b1 b2) = eval b2
  | _    => fun v => False
  end v
).
这基本上相当于编写您自己的依赖模式匹配,即上面的
with
子句中的内容就是您的返回注释

这在某种程度上相当于这样做:

refine (
  match test as _test in val _t return
    match _t as __t return val __t -> Prop with
    | Bool => fun test => eval (If test b1 b2) = eval b1 \/ eval (If test b1 b2) = eval b2
    | _    => fun _    => _t = Bool -> False
    end _test
  with
  | T => _
  | F => _
  | _ => _
  end
); try discriminate.