首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coq“车队模式”

Coq“车队模式”
EN

Stack Overflow用户
提问于 2015-06-25 04:37:14
回答 1查看 721关注 0票数 3

我试图使用“护航模式”来保持3个变量(两个参数和返回值)之间的依赖性:

代码语言:javascript
复制
Require Import Vector.

(* "sparse" vector type *)
Notation svector A n := (Vector.t (option A) n).

Fixpoint svector_is_dense {A} {n} (v:svector A n) : Prop :=
  match v with
  | Vector.nil => True
  | Vector.cons (None) _ _ => False
  | Vector.cons (Some _) _ xs => svector_is_dense xs
  end.

Lemma svector_tl_dense {A} {n} {v: svector A (S n)}:
  svector_is_dense v -> svector_is_dense (Vector.tl v).
Admitted.

Lemma svector_hd {A} {n} (v:svector A (S n)): svector_is_dense v -> A.
Admitted.

Fixpoint vector_from_svector {A} {n} {v:svector A n} (D:svector_is_dense v): Vector.t A n :=
  match n return (svector A n) -> (svector_is_dense v) -> (Vector.t A n) with
  | O => fun _ _ => @Vector.nil A
  | (S p) => fun v0 D0 => Vector.cons
                            (svector_hd v0 D0)
                            (vector_from_svector (Vector.tl v) (svector_tl_dense D))
  end v D.

这个问题出现在最后的定义中。有什么建议可以解释为什么不起作用吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-25 07:15:27

你做得差不多没错。问题在您的return子句中,它是不依赖的。你需要的是

代码语言:javascript
复制
match n return forall (w: svector A n), (svector_is_dense w) -> (Vector.t A n) with

因此,D0不是svector_is_dense v类型,而是svector_is_dense v0类型。

顺便说一下,在第二个构造函数中,我猜您指的是Vector.tl v0svector_tl_dense D0。下面是我所写的完整术语(不要介意cons中的附加cons,我还没有引发激活):

代码语言:javascript
复制
Fixpoint vector_from_svector {A} {n} {v:svector A n} (D:svector_is_dense v): Vector.t A n :=
  match n return forall (w:svector A n), (svector_is_dense w) -> (Vector.t A n) with
  | O => fun _ _ => @Vector.nil A
  | (S p) => fun v0 D0 => Vector.cons _
                            (svector_hd v0 D0) _
                            (vector_from_svector (svector_tl_dense D0))
  end v D.
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31041297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档