Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >「SF-LC」11 Rel

「SF-LC」11 Rel

作者头像
零式的天空
发布于 2022-03-14 06:42:23
发布于 2022-03-14 06:42:23
39000
代码可运行
举报
文章被收录于专栏:零域Blog零域Blog
运行总次数:0
代码可运行

relation 与injective/surjective/bijective function 等相关的知识在 5. Tactics 里,为了避免每次都要 grep 我在这里写一下。

Relations

Recalling Relation

from FCT/TAPL/Wiki…

a possible connection between the components of a k-tuple.

I have been long confused with Unary Relations vs. Binary Relation on the Same Set (homogeneous relation) I thought they were same…but turns out they are totally different!

Unary/1-place relation is Predicate or Property!

Either defined via set X ⊆ P or x ∈ P, or defined via function P : X -> Bool or P : X -> {⊥, ⊤}. (usually used in Math. Logic)

Property = Indicator Fn = characteristic Fn = Boolean Predicate Fn = Predicate

Binary Relation/2-place relation

Defined via two sets : R ⊆ X × Y or x, y ∈ R or xRy. (where x ∈ X, y ∈ Y.) or via function R: X × Y -> Bool.

Homogeneous Relation 同类(的)关系

Specifically! when X = Y, is called a homogeneous relation:

Noticed that we are still concerning relations of 2 elements!!, but they are from the same Set! (while 1-place relation concerning only 1 element.)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
RX × X
xRy where x ∈ X, y ∈ X

it’s written/spoken Binary relation on/over Set X. Properties e.g. reflexive, symmetric, transitive, are all properties of “Homogeneous Relation”!

Back to Coq

“relation” is a general idea. but in Coq standard lib it means “binary relation on a set X”

Coq identifier relation will always refer to a binary relation between some set and itself.

it’s defined as a family of Prop parameterized by two elements of X:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition relation (X: Type) := XX → Prop.

Check le : nat -> nat -> Prop.
Check le : relation nat.

Basic Properties

ways to classifying relations. so theorems can be proved generically about certain sorts of relations

It’s pretty fun to see all mathematical things defined in Coq! (much more constructive)

Partial Function

function is defined as a special kind of binary relation.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition partial_function {X: Type} (R: relation X) :=
  ∀x y1 y2 : X, R x y1 → R x y2 → y1 = y2.

meaning that foreach input x ∈ X, there is a unique y ∈ Y corresponded.

But this only establish a partial function. because it doesn’t say anything about totality, to define total function, we require f map every x ∈ X.

totally different with total function but ask the binary relation holds between every pair.

Reflexive

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition transitive {X: Type} (R: relation X) :=
  ∀a b c : X, (R a b)  (R b c)  (R a c).

Transitive

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition transitive {X: Type} (R: relation X) :=
  ∀a b c : X, (R a b)  (R b c)  (R a c).

Symmetric & Antisymmetric

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition symmetric {X: Type} (R: relation X) :=
  ∀a b : X, (R a b)  (R b a).
  
Definition antisymmetric {X: Type} (R: relation X) :=
  ∀a b : X, (R a b)  (R b a) → a = b.
Antisymmetric vs Asymmetric vs Non-symmetric (反对称 vs. 非对称 vs. 不-对称)

A relation is asymmetric if and only if it is both antisymmetric and irreflexive e.g. <= is neither symmetric nor asymmetric, but it’s antisymmetric… 反对称: 可以自反 (只能 reflexive 时对称) <= 非对称: 不能自反 < 不对称: 不是对称

Equivalence

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition equivalence {X:Type} (R: relation X) :=
  (reflexive R)  (symmetric R)  (transitive R).

Partial Orders

A partial order under which every pair of elements is comparable is called a total order or linear order In the Coq standard library it’s called just order for short:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition order {X:Type} (R: relation X) :=
  (reflexive R)  (antisymmetric R)  (transitive R).

Preorders

a.k.a quasiorder

The subtyping relations are usually preorders.

(TAPL p185) because of the record permutation rule…there are many pairs of distinct types where each is a subtype of the other.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Definition preorder {X:Type} (R: relation X) :=
  (reflexive R)  (transitive R).

Reflexive, Transitive Closure

Closure#Binary_relation_closures) Closure can be considered as Operations on bin-rel

As properties such as reflexive, transitive, the blah blah Closure are only talking about “homogeneous relations” i.e., Relation on a SINGLE set.

Reflexive Closure

Def. smallest reflexive relation on X containing R.

Operationally, as a = operator on a binary relation R:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
R= R{(x, x) | x ∈ X}

and this obviously satisfy R⁼ ⊇ R.

Transitive Closure

Def. smallest transitive relation on X containing R.

Operationally, as a + operator on a binary relation R:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
R+ = R{ (x1,xn) | n > 1  (x1,x2), ..., (xn-1,xn)R }

We can also constructively and inductively definition using R^i where i = i-transitivity away.

Reflexive, Transitive Closure

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
R* = R⁼ ∪ R+

Why is it useful?

The idea is that a relation is extended s.t. the derived relation has the (reflexsive and) transitive property. — Prof. Arthur e.g. the “descendant” relation is the transitive closure of the “child” relation, the “derives-star (⇒⋆)” relation is the reflexive-transitive closure of the “derives (⇒)” relation. the “ε-closure” relation is the reflexive-transitive closure of the “ε-transition” relation. the “Kleene-star (Σ⋆)” relation is the reflexive-transitive closure of the “concatentation” relation.

Another way is to think them as “set closed under some operation”.

Back to Coq

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Inductive clos_refl_trans {A: Type} (R: relation A) : relation A :=
  | rt_step x y (H : R x y) : clos_refl_trans R x y        (** original relation **)
  | rt_refl x : clos_refl_trans R x x                      (** reflexive  xRx              **)
  | rt_trans x y z                                         (** transitive xRy ∧ yRz → xRz  **)
        (Hxy : clos_refl_trans R x y)
        (Hyz : clos_refl_trans R y z) :
        clos_refl_trans R x z.

The above version will generate 2 IHs in rt_trans case. (since the proof tree has 2 branches).

Here is a better “linked-list”-ish one. (we will exclusively use this style)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Inductive clos_refl_trans_1n {A : Type} (R : relation A) (x : A) : A → Prop :=
  | rt1n_refl : clos_refl_trans_1n R x x
  | rt1n_trans (y z : A)
      (Hxy   : R x y) 
      (Hrest : clos_refl_trans_1n R y z) :
      clos_refl_trans_1n R x z.

In later chapter, we will define a decorator multi that can take any binary relation on a set and return its closure relation:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Inductive multi (X : Type) (R : relation X) : relation X :=
  | multi_refl : forall x     : X,                         multi R x x
  | multi_step : forall x y z : X, R x y -> multi R y z -> multi R x z

We name it step, standing for doing one step of this relation, and then we still have the rest (sub-structure) satisfied the closure relation.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
「SF-LC」5 Tactics
It also works with conditional hypotheses:
零式的天空
2022/03/14
5340
「SF-LC」8 Maps
From now on, importing from std lib. (but should not notice much difference)
零式的天空
2022/03/14
3410
「SF-PLF」1 Equiv
Some module (e.g.Map) not found either maunally make map.vo or proof general can solve that.
零式的天空
2022/03/02
4930
「SF-PLF」5 Smallstep
not just input state get mapped to output state. but also intermediate state (which could be observed by concurrent code!)
零式的天空
2022/03/02
5950
「SF-LC」12 Imp
A weird convention through out all IMP is:
零式的天空
2022/03/14
1.7K0
「SF-PLF」6 Types
The toy lang from SmallStep is too “safe” to demonstrate any runtime (or dynamic) type errors. — 运行时类型错误 So that’s add some operations (common church numeral ones), and bool type.
零式的天空
2022/03/02
4460
「SF-LC」9 ProofObjects
So the book material is designed to be gradually reveal the facts that
零式的天空
2022/03/14
5570
「SF-LC」4 Poly
Until today, We were living in the monomorphic world of Coq. So if we want a list, we have to define it for each type:
零式的天空
2022/03/14
1.3K0
「SF-LC」7 Ind Prop
we can write an Inductive definition of the even property!
零式的天空
2022/03/14
6550
「SF-LC」6 Logic
The equality operator = is also a function that returns a Prop. (property: equality)
零式的天空
2022/03/14
5920
「SF-LC」10 IndPrinciples
P only need to fullfill l : the_type but not n:nat since we are proving property of the_type.
零式的天空
2022/03/14
7530
「SF-PLF」7 Stlc
“Base Types”, only Bool for now. — 基类型 …again, exactly following TAPL.
零式的天空
2022/03/02
3630
Memcache知识点梳理
Beliefsets are used in JACK to maintain an agent’s beliefs about the world.
全栈程序员站长
2021/08/19
1.7K0
「SF-LC」3 List
Pair of Numbers Q: Why name inductive? A: Inductive means building things bottom-up, it doesn’t have
零式的天空
2022/03/14
4210
「SF-LC」1 Basics
The .v code is a gorgeous example of literal programming and the compiled .html website is full-fledged. So this note is intended to be NOT self-contained and only focus on things I found essential or interesting. This note is intended to be very personal and potentially mix English with Chinese (You can Lol) So yeah. Don’t expect it to be well organized and well written. I posted it on blog mainly for my own references purpose. The quotes could either come from the book or saying from someone (even including me).
零式的天空
2022/03/14
4000
「SF-LC」2 Induction
Whether or not it can be just simpl. depending on the definition of orb.
零式的天空
2022/03/14
4310
「SF-PLF」11. TypeChecking
首先我们需要 check equality for types. 这里非常简单,如果是 SystemF 会麻烦很多,对 ∀ 要做 local nameless 或者 alpha renaming:
零式的天空
2022/03/02
2770
「SF-LC」13 ImpParser
basically, parser combinator (But 非常麻烦 in Coq)
零式的天空
2022/03/14
3680
「SF-LC」15 Extraction
如果不做任何处理的话…生成的 ml 里的 nat 则都会是 Church Numeral…
零式的天空
2022/03/14
5230
「SF-PLF」13 References
computational effects - “side effects” of computation - impure features
零式的天空
2022/03/02
2590
相关推荐
「SF-LC」5 Tactics
更多 >
LV.1
这个人很懒,什么都没有留下~
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验