You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Coq中依赖类型向量Forall的正确态射签名求解

Coq中Vector.Forall的参数化态射正确签名

要让@Forall D成为参数化态射,需修正签名以匹配它的类型——(D -> Prop) -> forall n : nat, t D n -> Prop。核心是要对向量长度n做全称量化,因为Forall会针对任意长度的向量生成对应的谓词。

正确的签名写法如下:

Add Parametric Morphism : (@Forall D)
    with signature (R ==> iff) ==> (forall n, Forall2 R ==> iff)
     as morph1.

完整证明代码

From Coq Require Import Vector Morphisms Setoid.

Parameter D : Type.
Parameter R : relation D.

Add Parametric Morphism : (@Forall D)
    with signature (R ==> iff) ==> (forall n, Forall2 R ==> iff)
     as morph1.
Proof.
  intros P Q Hpq n v1 v2 Hr.
  rewrite 2 Forall_nth_order.
  rewrite Forall2_nth_order in Hr.
  split; intros Hf i Hi; eapply Hpq; eauto.
  Unshelve.
  all: assumption.
Qed.

说明

  • 原尝试失败的原因是签名未覆盖Forall返回值中对n的全称量化,修正后的签名用forall n, Forall2 R ==> iff匹配forall n, t D n -> Prop这一层类型。
  • 证明逻辑和固定长度版本morph2基本一致,仅多了对n的引入步骤。

内容的提问来源于stack exchange,提问作者pjm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 13:28:14