Debian Codegraph @

src/Codata/Sized/Cowriter/Bisimilarity.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Bisimilarity for Cowriter
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --sized-types #-}
8
9 module Codata.Sized.Cowriter.Bisimilarity where
10
11 open import Level using (Level; _⊔_)
12 open import Size using (Size; ∞)
13 open import Codata.Sized.Thunk using (Thunk; Thunk^R; force)
14 open import Codata.Sized.Cowriter using (Cowriter; _∷_;[_])
15 open import Relation.Binary.Core using (REL; Rel)
16 open import Relation.Binary.Bundles using (Setoid)
17 open import Relation.Binary.Structures using (IsEquivalence)
18 open import Relation.Binary.Definitions
19 using (Reflexive; Symmetric; Transitive; Sym; Trans)
20 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
21 import Relation.Binary.PropositionalEquality.Properties as ≡ using (setoid)
22
23 private
24 variable
25 a b c p q pq r s rs v w x : Level
26 A : Set a
27 B : Set b
28 C : Set c
29 V : Set v
30 W : Set w
31 X : Set x
32 i : Size
33
34 data Bisim {V : Set v} {W : Set w} {A : Set a} {B : Set b}
35 (R : REL V W r) (S : REL A B s) (i : Size) :
36 REL (Cowriter V A ∞) (Cowriter W B ∞) (r ⊔ s ⊔ v ⊔ w ⊔ a ⊔ b) where
37 [_] : ∀ {a b} → S a b → Bisim R S i [ a ] [ b ]
38 _∷_ : ∀ {x y xs ys} → R x y → Thunk^R (Bisim R S) i xs ys →
39 Bisim R S i (x ∷ xs) (y ∷ ys)
40
41 infixr 5 _∷_
42
43 module _ {R : Rel W r} {S : Rel A s}
44 (refl^R : Reflexive R) (refl^S : Reflexive S) where
45
46 reflexive : Reflexive (Bisim R S i)
47 reflexive {x = [ a ]} = [ refl^S ]
48 reflexive {x = w ∷ ws} = refl^R ∷ λ where .force → reflexive
49
50 module _ {R : REL V W r} {S : REL W V s} {P : REL A B p} {Q : REL B A q}
51 (sym^RS : Sym R S) (sym^PQ : Sym P Q) where
52
53 symmetric : Sym (Bisim R P i) (Bisim S Q i)
54 symmetric [ a ] = [ sym^PQ a ]
55 symmetric (p ∷ ps) = sym^RS p ∷ λ where .force → symmetric (ps .force)
56
57
58 module _ {R : REL V W r} {S : REL W X s} {RS : REL V X rs}
59 {P : REL A B p} {Q : REL B C q} {PQ : REL A C pq}
60 (trans^RS : Trans R S RS) (trans^PQ : Trans P Q PQ) where
61
62 transitive : Trans (Bisim R P i) (Bisim S Q i) (Bisim RS PQ i)
63 transitive [ p ] [ q ] = [ trans^PQ p q ]
64 transitive (p ∷ ps) (q ∷ qs) =
65 trans^RS p q ∷ λ where .force → transitive (ps .force) (qs .force)
66
67 -- Pointwise Equality as a Bisimilarity
68 ------------------------------------------------------------------------
69
70 module _ {W : Set w} {A : Set a} where
71
72 infix 1 _⊢_≈_
73 _⊢_≈_ : ∀ i → Cowriter W A ∞ → Cowriter W A ∞ → Set (a ⊔ w)
74 _⊢_≈_ = Bisim _≡_ _≡_
75
76 refl : Reflexive (i ⊢_≈_)
77 refl = reflexive ≡.refl ≡.refl
78
79 fromEq : ∀ {as bs} → as ≡ bs → i ⊢ as ≈ bs
80 fromEq ≡.refl = refl
81
82 sym : Symmetric (i ⊢_≈_)
83 sym = symmetric ≡.sym ≡.sym
84
85 trans : Transitive (i ⊢_≈_)
86 trans = transitive ≡.trans ≡.trans
87
88 module _ {R : Rel W r} {S : Rel A s}
89 (equiv^R : IsEquivalence R) (equiv^S : IsEquivalence S) where
90
91 private
92 module equiv^R = IsEquivalence equiv^R
93 module equiv^S = IsEquivalence equiv^S
94
95 isEquivalence : IsEquivalence (Bisim R S i)
96 isEquivalence = record
97 { refl = reflexive equiv^R.refl equiv^S.refl
98 ; sym = symmetric equiv^R.sym equiv^S.sym
99 ; trans = transitive equiv^R.trans equiv^S.trans
100 }
101
102 setoid : Setoid w r → Setoid a s → Size → Setoid (w ⊔ a) (w ⊔ a ⊔ r ⊔ s)
103 setoid R S i = record
104 { isEquivalence = isEquivalence (Setoid.isEquivalence R)
105 (Setoid.isEquivalence S) {i = i}
106 }
107
108 module ≈-Reasoning {W : Set w} {A : Set a} {i} where
109
110 open import Relation.Binary.Reasoning.Setoid
111 (setoid (≡.setoid W) (≡.setoid A) i) public