coq - 为 coq 中的记录导出规范结构(ssreflect)
问题描述
鉴于以下假设:
Variable A : finType.
Variable B : finType.
Variable C : finType.
以及定义为的记录:
Record example := Example {
example_A : A;
example_B : B;
example_C : C;
}.
直觉上,这个例子似乎也必须是 of finType
。
查看其他代码库,我看到人们finType
使用表单的构造仅使用一个非证明项导出记录
Definition <record>_subType := Eval hnf in [subtype for <record-accessor>].
Definition <record>_finMixin := Eval hnf in [finMixin of <record> by <:].
但在这种情况下,记录有多个字段。
是否有一种自动方法可以为记录派生 fintype,如果没有,如何为记录派生 fintype?
解决方案
数学组件中的许多接口实现可以通过显示您的类型是实现该接口的某些其他类型的缩回来派生。在您的示例中,我们只需将记录转换为元组。
From mathcomp Require Import
ssreflect ssrfun ssrbool ssrnat eqtype seq choice fintype.
Variables A B C : finType.
Record example := Example {
example_A : A;
example_B : B;
example_C : C
}.
Definition prod_of_example e :=
let: Example a b c := e in (a, b, c).
Definition example_of_prod p :=
let: (a, b, c) := p in Example a b c.
Lemma prod_of_exampleK : cancel prod_of_example example_of_prod.
Proof. by case. Qed.
Definition example_eqMixin :=
CanEqMixin prod_of_exampleK.
Canonical example_eqType :=
Eval hnf in EqType example example_eqMixin.
Definition example_choiceMixin :=
CanChoiceMixin prod_of_exampleK.
Canonical example_choiceType :=
Eval hnf in ChoiceType example example_choiceMixin.
Definition example_countMixin :=
CanCountMixin prod_of_exampleK.
Canonical example_countType :=
Eval hnf in CountType example example_countMixin.
Definition example_finMixin :=
CanFinMixin prod_of_exampleK.
Canonical example_finType :=
Eval hnf in FinType example example_finMixin.
在此代码段的末尾,example
被声明为finType
. (请注意,所有其他声明eqType
,choiceType
等也是必需的,因为finType
它是这些声明的子类。)
推荐阅读
- ansible - Ansible:检查变量是否包含列表或字典
- python - 如何将我上传的图像从 html 页面传递到烧瓶?
- kubernetes - Kubernetes 负载均衡器 EKS SSL 终止问题
- azure-devops - Connect-PnPOnline 不适用于构建代理
- sqlite - SQLITE - 圆形时间戳和计数
- firebase - npm run build on Vue 项目将 base_url 填充为未定义
- matlab - 我想比较使用网格算法重建的图像。我如何用 MATLAB 做到这一点?
- php - 如何查询每行的 COMMENTS 表,然后查询 REPLIES TABLE 并在 JSON 回显之前将每个结果附加到 COMMENTS 中?
- django - 如何使用 Django 设置 Current_company_flag
- jquery - iframe 无法访问 url