Debian Codegraph @

src/Relation/Binary/Construct/Closure/ReflexiveTransitive/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Some properties of reflexive transitive closures.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties where
10
11 open import Function.Base using (id; _∘_; _$_)
12 open import Relation.Binary.Core using (Rel; _=[_]⇒_; _⇒_)
13 open import Relation.Binary.Bundles using (Preorder)
14 open import Relation.Binary.Structures using (IsPreorder)
15 open import Relation.Binary.Definitions using (Transitive; Reflexive)
16 open import Relation.Binary.Construct.Closure.ReflexiveTransitive
17 using (Star; _◅_; _◅◅_; gmap; fold; ε)
18 open import Relation.Binary.PropositionalEquality.Core as ≡
19 using (_≡_; refl; sym; cong; cong₂)
20 import Relation.Binary.PropositionalEquality.Properties as ≡
21 import Relation.Binary.Reasoning.Preorder as ≲-Reasoning
22 open import Relation.Binary.Reasoning.Syntax
23
24 ------------------------------------------------------------------------
25 -- _◅◅_
26
27 module _ {i t} {I : Set i} {T : Rel I t} where
28
29 ◅◅-assoc : ∀ {i j k l}
30 (xs : Star T i j) (ys : Star T j k) (zs : Star T k l) →
31 (xs ◅◅ ys) ◅◅ zs ≡ xs ◅◅ (ys ◅◅ zs)
32 ◅◅-assoc ε ys zs = refl
33 ◅◅-assoc (x ◅ xs) ys zs = cong (_◅_ x) (◅◅-assoc xs ys zs)
34
35 ------------------------------------------------------------------------
36 -- gmap
37
38 gmap-id : ∀ {i t} {I : Set i} {T : Rel I t} {i j} (xs : Star T i j) →
39 gmap id id xs ≡ xs
40 gmap-id ε = refl
41 gmap-id (x ◅ xs) = cong (_◅_ x) (gmap-id xs)
42
43 gmap-∘ : ∀ {i t} {I : Set i} {T : Rel I t}
44 {j u} {J : Set j} {U : Rel J u}
45 {k v} {K : Set k} {V : Rel K v}
46 (f : J → K) (g : U =[ f ]⇒ V)
47 (f′ : I → J) (g′ : T =[ f′ ]⇒ U)
48 {i j} (xs : Star T i j) →
49 (gmap {U = V} f g ∘ gmap f′ g′) xs ≡ gmap (f ∘ f′) (g ∘ g′) xs
50 gmap-∘ f g f′ g′ ε = refl
51 gmap-∘ f g f′ g′ (x ◅ xs) = cong (_◅_ (g (g′ x))) (gmap-∘ f g f′ g′ xs)
52
53 gmap-◅◅ : ∀ {i t j u}
54 {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u}
55 (f : I → J) (g : T =[ f ]⇒ U)
56 {i j k} (xs : Star T i j) (ys : Star T j k) →
57 gmap {U = U} f g (xs ◅◅ ys) ≡ gmap f g xs ◅◅ gmap f g ys
58 gmap-◅◅ f g ε ys = refl
59 gmap-◅◅ f g (x ◅ xs) ys = cong (_◅_ (g x)) (gmap-◅◅ f g xs ys)
60
61 gmap-cong : ∀ {i t j u}
62 {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u}
63 (f : I → J) (g : T =[ f ]⇒ U) (g′ : T =[ f ]⇒ U) →
64 (∀ {i j} (x : T i j) → g x ≡ g′ x) →
65 ∀ {i j} (xs : Star T i j) →
66 gmap {U = U} f g xs ≡ gmap f g′ xs
67 gmap-cong f g g′ eq ε = refl
68 gmap-cong f g g′ eq (x ◅ xs) = cong₂ _◅_ (eq x) (gmap-cong f g g′ eq xs)
69
70 ------------------------------------------------------------------------
71 -- fold
72
73 fold-◅◅ : ∀ {i p} {I : Set i}
74 (P : Rel I p) (_⊕_ : Transitive P) (∅ : Reflexive P) →
75 (∀ {i j} (x : P i j) → (∅ ⊕ x) ≡ x) →
76 (∀ {i j k l} (x : P i j) (y : P j k) (z : P k l) →
77 ((x ⊕ y) ⊕ z) ≡ (x ⊕ (y ⊕ z))) →
78 ∀ {i j k} (xs : Star P i j) (ys : Star P j k) →
79 fold P _⊕_ ∅ (xs ◅◅ ys) ≡ (fold P _⊕_ ∅ xs ⊕ fold P _⊕_ ∅ ys)
80 fold-◅◅ P _⊕_ ∅ left-unit assoc ε ys = sym (left-unit _)
81 fold-◅◅ P _⊕_ ∅ left-unit assoc (x ◅ xs) ys = begin
82 (x ⊕ fold P _⊕_ ∅ (xs ◅◅ ys)) ≡⟨ cong (_⊕_ x) $
83 fold-◅◅ P _⊕_ ∅ left-unit assoc xs ys ⟩
84 (x ⊕ (fold P _⊕_ ∅ xs ⊕ fold P _⊕_ ∅ ys)) ≡⟨ sym (assoc x _ _) ⟩
85 ((x ⊕ fold P _⊕_ ∅ xs) ⊕ fold P _⊕_ ∅ ys) ∎
86 where open ≡.≡-Reasoning
87
88 ------------------------------------------------------------------------
89 -- Relational properties
90
91 module _ {i t} {I : Set i} (T : Rel I t) where
92
93 reflexive : _≡_ ⇒ Star T
94 reflexive refl = ε
95
96 trans : Transitive (Star T)
97 trans = _◅◅_
98
99 isPreorder : IsPreorder _≡_ (Star T)
100 isPreorder = record
101 { isEquivalence = ≡.isEquivalence
102 ; reflexive = reflexive
103 ; trans = trans
104 }
105
106 preorder : Preorder _ _ _
107 preorder = record
108 { _≈_ = _≡_
109 ; _≲_ = Star T
110 ; isPreorder = isPreorder
111 }
112
113 ------------------------------------------------------------------------
114 -- Preorder reasoning for Star
115
116 module StarReasoning {i t} {I : Set i} (T : Rel I t) where
117 private module Base = ≲-Reasoning (preorder T)
118
119 open Base public
120 hiding (step-≈; step-≈˘; step-≈-⟩; step-≈-⟨; step-∼; step-≲)
121 renaming (≲-go to ⟶-go)
122
123 open ⟶-syntax _IsRelatedTo_ _IsRelatedTo_ (⟶-go ∘ (_◅ ε)) public
124 open ⟶*-syntax _IsRelatedTo_ _IsRelatedTo_ ⟶-go public