Coq 归纳定义的稠密向量引理

Coq 归纳定义的稠密向量引理,coq,Coq,受StackOverflow的另一个问题的启发,我将密集向量定义为带有选项a类型元素的向量,该元素只包含一些元素,并且没有无元素 Require Import Vector. Section Dense. Variable A:Type. Inductive Is_dense : forall n, t (option A) n -> Prop := | snil : Is_dense 0 (nil _) | scons: forall n s, Is_dense n s

受StackOverflow的另一个问题的启发,我将密集向量定义为带有
选项a
类型元素的向量,该元素只包含
一些
元素,并且没有
元素

Require Import Vector.
Section Dense.
  Variable A:Type.

  Inductive Is_dense : forall n, t (option A) n -> Prop :=
  | snil : Is_dense 0 (nil _)
  | scons: forall n s, Is_dense n s -> forall a, Is_dense (S n) (cons _ (Some a) _ s).
我如何证明以下两个引理

  Lemma Is_dense_tl: forall n (s: t (option A) (S n)),
                     Is_dense (S n) s -> Is_dense n (tl s).


而且,在第一个引理中,当我做
inversion s.
时,我得到了
s
的构造函数使用的元素
hn'X
,但是我怎么能得到一个等式,声明
s=cons(选项A)hn'X

因为类型依赖性,
inversion
不能直接生成您期望的结果,因为一般来说这不是真的。然而,对于一个类型的大家族来说,这是正确的,它们的相等性是可判定的。在您的情况下,如果您提供了在
nat
上的相等是可判定的(并且是可判定的),则可以应用
Eqdep\u dec.inj\u pair2\u eq\u dec
来获得所需的相等

下面是第一个引理的证明:

Lemma Is_dense_tl: forall n (s: t (option A) (S n)),
                     Is_dense (S n) s -> Is_dense n (tl s).
Proof.
intros n s hs.
inversion hs; subst; clear hs.
apply Eqdep_dec.inj_pair2_eq_dec in H0.
- now rewrite <- H0; simpl.
- (* insert proof of decidablity *) admit.
Qed.
引理是稠密的\u tl:forall n(s:t(选项A)(sn)),
Is_稠密(sn)S->Is_稠密n(tls)。
证明。
介绍。
反转hs;subst;清除hs。
在H0中使用Eqdep\u dec.inj\u pair2\u eq\u dec。

-现在重写谢谢!对于
nat
,它需要一个可判定性证明,而不是
a
,因此使用
Arith.Peano_dec.eq_nat_dec.
很容易,但是,当我尝试对第二个引理使用
inversion hs.
时,我得到了错误
错误:反转需要对排序类型进行案例分析,这是归纳定义不允许的。
为什么可以在第一个引理中使用反转而在第二个引理中不使用?将
A
类型
更改为
后,在第二个引理中,我能做
倒装。怎么搞的?有没有比改变定义更激进的解决方案?
Lemma Is_dense_tl: forall n (s: t (option A) (S n)),
                     Is_dense (S n) s -> Is_dense n (tl s).
Proof.
intros n s hs.
inversion hs; subst; clear hs.
apply Eqdep_dec.inj_pair2_eq_dec in H0.
- now rewrite <- H0; simpl.
- (* insert proof of decidablity *) admit.
Qed.