annotate paper/src/RelOp.agda.replaced @ 19:046b2b20d6c7 default tip

fix
author ryokka
date Mon, 09 Mar 2020 11:25:49 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
ryokka
parents:
diff changeset
1 {-@$\#$@ OPTIONS --universe-polymorphism @$\#$@-}
ryokka
parents:
diff changeset
2
ryokka
parents:
diff changeset
3 open import Level
ryokka
parents:
diff changeset
4 open import Data.Empty
ryokka
parents:
diff changeset
5 open import Data.Product
ryokka
parents:
diff changeset
6 open import Data.Nat.Base
ryokka
parents:
diff changeset
7 open import Data.Sum
ryokka
parents:
diff changeset
8 open import Data.Unit
ryokka
parents:
diff changeset
9 open import Relation.Binary
ryokka
parents:
diff changeset
10 open import Relation.Binary.Core
ryokka
parents:
diff changeset
11 open import Relation.Nullary
ryokka
parents:
diff changeset
12 open import utilities
ryokka
parents:
diff changeset
13
ryokka
parents:
diff changeset
14 module RelOp (S : Set) where
ryokka
parents:
diff changeset
15
ryokka
parents:
diff changeset
16 data Id {l} {X : Set} : Rel X l where
ryokka
parents:
diff changeset
17 ref : {x : X} @$\rightarrow$@ Id x x
ryokka
parents:
diff changeset
18
ryokka
parents:
diff changeset
19 -- substId1 | x == y & P(x) => P(y)
ryokka
parents:
diff changeset
20 substId1 : @$\forall$@ {l} @$\rightarrow$@ {X : Set} @$\rightarrow$@ {x y : X} @$\rightarrow$@
ryokka
parents:
diff changeset
21 Id {l} x y @$\rightarrow$@ (P : Pred X) @$\rightarrow$@ P x @$\rightarrow$@ P y
ryokka
parents:
diff changeset
22 substId1 ref P q = q
ryokka
parents:
diff changeset
23
ryokka
parents:
diff changeset
24 -- substId2 | x == y & P(y) => P(x)
ryokka
parents:
diff changeset
25 substId2 : @$\forall$@ {l} @$\rightarrow$@ {X : Set} @$\rightarrow$@ {x y : X} @$\rightarrow$@
ryokka
parents:
diff changeset
26 Id {l} x y @$\rightarrow$@ (P : Pred X) @$\rightarrow$@ P y @$\rightarrow$@ P x
ryokka
parents:
diff changeset
27 substId2 ref P q = q
ryokka
parents:
diff changeset
28
ryokka
parents:
diff changeset
29 -- for X ⊆ S (formally, X : Pred S)
ryokka
parents:
diff changeset
30 -- delta X = { (a, a) | a ∈ X }
ryokka
parents:
diff changeset
31 delta : @$\forall$@ {l} @$\rightarrow$@ Pred S @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
32 delta X a b = X a @$\times$@ Id a b
ryokka
parents:
diff changeset
33
ryokka
parents:
diff changeset
34 -- deltaGlob = delta S
ryokka
parents:
diff changeset
35 deltaGlob : @$\forall$@ {l} @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
36 deltaGlob = delta (@$\lambda$@ (s : S) @$\rightarrow$@ @$\top$@)
ryokka
parents:
diff changeset
37
ryokka
parents:
diff changeset
38 -- emptyRel = \varnothing
ryokka
parents:
diff changeset
39 emptyRel : Rel S Level.zero
ryokka
parents:
diff changeset
40 emptyRel a b = @$\bot$@
ryokka
parents:
diff changeset
41
ryokka
parents:
diff changeset
42 -- comp R1 R2 = R2 ∘ R1 (= R1; R2)
ryokka
parents:
diff changeset
43 comp : @$\forall$@ {l} @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
44 comp R1 R2 a b = ∃ (@$\lambda$@ (a' : S) @$\rightarrow$@ R1 a a' @$\times$@ R2 a' b)
ryokka
parents:
diff changeset
45
ryokka
parents:
diff changeset
46 -- union R1 R2 = R1 ∪ R2
ryokka
parents:
diff changeset
47 union : @$\forall$@ {l} @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
48 union R1 R2 a b = R1 a b ⊎ R2 a b
ryokka
parents:
diff changeset
49
ryokka
parents:
diff changeset
50 -- repeat n R = R^n
ryokka
parents:
diff changeset
51 repeat : @$\forall$@ {l} @$\rightarrow$@ @$\mathbb{N}$@ @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
52 repeat @$\mathbb{N}$@.zero R = deltaGlob
ryokka
parents:
diff changeset
53 repeat (@$\mathbb{N}$@.suc m) R = comp (repeat m R) R
ryokka
parents:
diff changeset
54
ryokka
parents:
diff changeset
55 -- unionInf f = ⋃_{n ∈ ω} f(n)
ryokka
parents:
diff changeset
56 unionInf : @$\forall$@ {l} @$\rightarrow$@ (@$\mathbb{N}$@ @$\rightarrow$@ Rel S l) @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
57 unionInf f a b = ∃ (@$\lambda$@ (n : @$\mathbb{N}$@) @$\rightarrow$@ f n a b)
ryokka
parents:
diff changeset
58 -- restPre X R = { (s1,s2) ∈ R | s1 ∈ X }
ryokka
parents:
diff changeset
59 restPre : @$\forall$@ {l} @$\rightarrow$@ Pred S @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
60 restPre X R a b = X a @$\times$@ R a b
ryokka
parents:
diff changeset
61
ryokka
parents:
diff changeset
62 -- restPost X R = { (s1,s2) ∈ R | s2 ∈ X }
ryokka
parents:
diff changeset
63 restPost : @$\forall$@ {l} @$\rightarrow$@ Pred S @$\rightarrow$@ Rel S l @$\rightarrow$@ Rel S l
ryokka
parents:
diff changeset
64 restPost X R a b = R a b @$\times$@ X b
ryokka
parents:
diff changeset
65
ryokka
parents:
diff changeset
66 deltaRestPre : (X : Pred S) @$\rightarrow$@ (R : Rel S Level.zero) @$\rightarrow$@ (a b : S) @$\rightarrow$@
ryokka
parents:
diff changeset
67 Iff (restPre X R a b) (comp (delta X) R a b)
ryokka
parents:
diff changeset
68 deltaRestPre X R a b
ryokka
parents:
diff changeset
69 = (@$\lambda$@ (h : restPre X R a b) @$\rightarrow$@ a , (proj@$\_{1}$@ h , ref) , proj@$\_{2}$@ h) ,
ryokka
parents:
diff changeset
70 @$\lambda$@ (h : comp (delta X) R a b) @$\rightarrow$@ proj@$\_{1}$@ (proj@$\_{1}$@ (proj@$\_{2}$@ h)) ,
ryokka
parents:
diff changeset
71 substId2
ryokka
parents:
diff changeset
72 (proj@$\_{2}$@ (proj@$\_{1}$@ (proj@$\_{2}$@ h)))
ryokka
parents:
diff changeset
73 (@$\lambda$@ z @$\rightarrow$@ R z b) (proj@$\_{2}$@ (proj@$\_{2}$@ h))
ryokka
parents:
diff changeset
74
ryokka
parents:
diff changeset
75 deltaRestPost : (X : Pred S) @$\rightarrow$@ (R : Rel S Level.zero) @$\rightarrow$@ (a b : S) @$\rightarrow$@
ryokka
parents:
diff changeset
76 Iff (restPost X R a b) (comp R (delta X) a b)
ryokka
parents:
diff changeset
77 deltaRestPost X R a b
ryokka
parents:
diff changeset
78 = (@$\lambda$@ (h : restPost X R a b) @$\rightarrow$@ b , proj@$\_{1}$@ h , proj@$\_{2}$@ h , ref) ,
ryokka
parents:
diff changeset
79 @$\lambda$@ (h : comp R (delta X) a b) @$\rightarrow$@
ryokka
parents:
diff changeset
80 substId1 (proj@$\_{2}$@ (proj@$\_{2}$@ (proj@$\_{2}$@ h))) (R a) (proj@$\_{1}$@ (proj@$\_{2}$@ h)) ,
ryokka
parents:
diff changeset
81 substId1 (proj@$\_{2}$@ (proj@$\_{2}$@ (proj@$\_{2}$@ h))) X (proj@$\_{1}$@ (proj@$\_{2}$@ (proj@$\_{2}$@ h)))