Coq 当我知道head不能失败时,我可以避免使用选项A吗?
我是ATP的新手,但肯定很有动力。 我开始处理依赖类型。我参与了一个项目,我定义了(有限和无限)序列的类型Coq 当我知道head不能失败时,我可以避免使用选项A吗?,coq,convoy-pattern,Coq,Convoy Pattern,我是ATP的新手,但肯定很有动力。 我开始处理依赖类型。我参与了一个项目,我定义了(有限和无限)序列的类型 Inductive sequence {X : Type} : Type := | FinSeq (x : list X) | InfSeq (f : nat -> X). 现在我想定义一个非空序列的头部 Lemma aux_hd : forall {A : Type} (l : list A), 0 < Datatypes.length l -&
Inductive sequence {X : Type} : Type :=
| FinSeq (x : list X)
| InfSeq (f : nat -> X).
现在我想定义一个非空序列的头部
Lemma aux_hd : forall {A : Type} (l : list A),
0 < Datatypes.length l -> @hd_error A l = None -> False.
Proof. destruct l.
+ simpl. lia.
+ simpl. intros S. discriminate.
Qed.
Definition Hd {A : Type} (l : list A) : 0 < Datatypes.length l -> A :=
match (hd_error l) with
| Some a => (fun _ => a)
| None => fun pf => match (aux_hd l pf ??) with end
end.
Definition Head {A : Type} (s :sequence) (H : 0 << length s),
match s with
| FinSeq x => Hd x H
| InfSeq f => f 0 end.
引理aux_hd:forall{A:Type}(l:list A),
0@Hd\u error A l=None
,因为我们已经在这样一个匹配分支中。我相信这应该很容易
在上一个定义中,我有一个类似的问题,因为我不知道如何转换H,对于第一个匹配分支的特定情况,我知道length s=Datatypes.length x
,因此,0
最后,我省略了关于的细节,当你在某件事情上匹配时,所有额外的证据都必须作为参数传递给匹配(这是CPDT中描述的“护航模式”) 在
Hd
中,您希望记住Hd_error l=None
,将其作为参数传递。这有点棘手,因为您必须使用return
子句显式注释match
(在更简单的情况下为您推断):
非常感谢你!
Definition Hd {A : Type} (l : list A) : 0 < Datatypes.length l -> A :=
match (hd_error l) as X return hd_error l = X -> 0 < Datatypes.length l -> A with
| Some a => (fun _ _ => a)
| None => fun pf1 pf2 => match (aux_hd l pf2 pf1) with end
end eq_refl.
Definition Head {A : Type} (s :sequence) (H : 0 << length s) :=
match s return (0 << length s) -> _ with
| FinSeq x => fun H => Hd x H
| InfSeq f => fun _ => f 0
end H.