首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从注入到“性质”中获得一种类型的可判定的总订单

从注入到“性质”中获得一种类型的可判定的总订单
EN

Stack Overflow用户
提问于 2017-11-06 02:34:43
回答 1查看 154关注 0票数 6

由于自然数支持可判定的全序,注入nat_of_ascii (a : ascii) : natascii类型上产生可判定的全序。用Coq表达这一点的简洁、惯用的方式是什么?(有或没有类型类、模块等)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-06 06:53:56

这样的过程是相当例行的,并将取决于您选择的库。对于order.v,基于数学-comp,这个过程完全是机械的--事实上,我们将在后面为类型开发一个通用结构,并将其注入到总订单中。

代码语言:javascript
复制
From Coq Require Import Ascii String ssreflect ssrfun ssrbool.
From mathcomp Require Import eqtype choice ssrnat.
Require Import order.

Import Order.Syntax.
Import Order.Theory.

Lemma ascii_of_natK : cancel nat_of_ascii ascii_of_nat.
Proof. exact: ascii_nat_embedding. Qed.

(* Declares ascii to be a member of the eq class *)
Definition ascii_eqMixin := CanEqMixin ascii_of_natK.
Canonical ascii_eqType := EqType _ ascii_eqMixin.

(* Declares ascii to be a member of the choice class *)
Definition ascii_choiceMixin := CanChoiceMixin ascii_of_natK.
Canonical ascii_choiceType := ChoiceType _ ascii_choiceMixin.

(* Specific stuff for the order library *)
Definition ascii_display : unit. Proof. exact: tt. Qed.

Open Scope order_scope.

(* We use the order from nat *)
Definition lea x y := nat_of_ascii x <= nat_of_ascii y.
Definition lta x y := ~~ (lea y x).

Lemma lea_ltNeq x y : lta x y = (x != y) && (lea x y).
Proof.
rewrite /lta /lea leNgt negbK lt_neqAle.
by rewrite (inj_eq (can_inj ascii_of_natK)).
Qed.
Lemma lea_refl : reflexive lea.
Proof. by move=> x; apply: le_refl. Qed.
Lemma lea_trans : transitive lea.
Proof. by move=> x y z; apply: le_trans. Qed.
Lemma lea_anti : antisymmetric lea.
Proof. by move=> x y /le_anti /(can_inj ascii_of_natK). Qed.
Lemma lea_total : total lea.
Proof. by move=> x y; apply: le_total. Qed.

(* We can now declare ascii to belong to the order class. We must declare its
   subclasses first. *)
Definition asciiPOrderMixin :=
  POrderMixin lea_ltNeq lea_refl lea_anti lea_trans.

Canonical asciiPOrderType  := POrderType ascii_display ascii asciiPOrderMixin.

Definition asciiLatticeMixin := Order.TotalLattice.Mixin lea_total.
Canonical asciiLatticeType := LatticeType ascii asciiLatticeMixin.
Canonical asciiOrderType := OrderType ascii lea_total.

请注意,为ascii提供一个order实例可以让我们访问一个很大的总订单理论,加上运算符等等.然而,total本身的定义相当简单:

代码语言:javascript
复制
"<= is total" == x <= y || y <= x

其中<=是一个“可判定的关系”,当然,我们假定,对于特定类型,平等的可判定性。具体来说,对于任意的关系:

代码语言:javascript
复制
Definition total (T: Type) (r : T -> T -> bool) := forall x y, r x y || r y x.

因此,如果T是和order,并且满足total,那么您就完成了。

更广泛地说,您可以定义一个泛型原则来使用注入构建这样的类型:

代码语言:javascript
复制
Section InjOrder.

Context {display : unit}.
Local Notation orderType := (orderType display).
Variable (T : orderType) (U : eqType) (f : U -> T) (f_inj : injective f).

Open Scope order_scope.

Let le x y := f x <= f y.
Let lt x y := ~~ (f y <= f x).
Lemma CO_le_ltNeq x y: lt x y = (x != y) && (le x y).
Proof. by rewrite /lt /le leNgt negbK lt_neqAle (inj_eq f_inj). Qed.
Lemma CO_le_refl : reflexive le. Proof. by move=> x; apply: le_refl. Qed.
Lemma CO_le_trans : transitive le. Proof. by move=> x y z; apply: le_trans. Qed.
Lemma CO_le_anti : antisymmetric le. Proof. by move=> x y /le_anti /f_inj. Qed.

Definition InjOrderMixin : porderMixin U :=
  POrderMixin CO_le_ltNeq CO_le_refl CO_le_anti CO_le_trans.
End InjOrder.

然后,按照以下方式重写ascii实例:

代码语言:javascript
复制
Definition ascii_display : unit. Proof. exact: tt. Qed.
Definition ascii_porderMixin := InjOrderMixin (can_inj ascii_of_natK).
Canonical asciiPOrderType := POrderType ascii_display ascii ascii_porderMixin.

Lemma lea_total : @total ascii (<=%O)%O.
Proof. by move=> x y; apply: le_total. Qed.

Definition asciiLatticeMixin := Order.TotalLattice.Mixin lea_total.
Canonical asciiLatticeType := LatticeType ascii asciiLatticeMixin.
Canonical asciiOrderType := OrderType ascii lea_total.
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47128936

复制
相关文章

相似问题

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