forked from jonsterling/agda-calf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CostMonoid.agda
166 lines (136 loc) · 4.43 KB
/
CostMonoid.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{-# OPTIONS --without-K #-}
-- Definition of a cost monoid.
open import Relation.Binary using (Rel; _Preserves_⟶_; _Preserves₂_⟶_⟶_)
module Calf.CostMonoid where
open import Level using (Level; 0ℓ; suc; _⊔_)
open import Algebra.Core
open import Relation.Binary.PropositionalEquality using (_≡_; resp₂)
open import Data.Product
module _ {ℂ : Set} where
Relation = Rel ℂ 0ℓ
private
_≈_ : Relation
_≈_ = _≡_
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_ public
open import Relation.Binary.Structures _≈_
record IsMonotone (_∙_ : Op₂ ℂ) (_≤_ : Relation) (isPreorder : IsPreorder _≤_) : Set where
field
∙-mono-≤ : _∙_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
open IsPreorder isPreorder
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
∙-monoˡ-≤ : ∀ n → (_∙ n) Preserves _≤_ ⟶ _≤_
∙-monoˡ-≤ n m≤o = ∙-mono-≤ m≤o (≤-refl {n})
∙-monoʳ-≤ : ∀ n → (n ∙_) Preserves _≤_ ⟶ _≤_
∙-monoʳ-≤ n m≤o = ∙-mono-≤ (≤-refl {n}) m≤o
record IsCostMonoid (zero : ℂ) (_+_ : Op₂ ℂ) (_≤_ : Relation) : Set where
field
isMonoid : IsMonoid _+_ zero
isPreorder : IsPreorder _≤_
isMonotone : IsMonotone _+_ _≤_ isPreorder
open IsMonoid isMonoid public
using ()
renaming (
identityˡ to +-identityˡ;
identityʳ to +-identityʳ;
assoc to +-assoc
)
open IsPreorder isPreorder public
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
open IsMonotone isMonotone public
renaming (
∙-mono-≤ to +-mono-≤;
∙-monoˡ-≤ to +-monoˡ-≤;
∙-monoʳ-≤ to +-monoʳ-≤
)
record IsParCostMonoid (𝟘 : ℂ) (_⊕_ : Op₂ ℂ) (_⊗_ : Op₂ ℂ) (_≤_ : Relation) : Set where
field
isMonoid : IsMonoid _⊕_ 𝟘
isCommutativeMonoid : IsCommutativeMonoid _⊗_ 𝟘
isPreorder : IsPreorder _≤_
isMonotone-⊕ : IsMonotone _⊕_ _≤_ isPreorder
isMonotone-⊗ : IsMonotone _⊗_ _≤_ isPreorder
open IsMonoid isMonoid public
using ()
renaming (
identityˡ to ⊕-identityˡ;
identityʳ to ⊕-identityʳ;
assoc to ⊕-assoc
)
open IsCommutativeMonoid isCommutativeMonoid public
using ()
renaming (
identityˡ to ⊗-identityˡ;
identityʳ to ⊗-identityʳ;
assoc to ⊗-assoc;
comm to ⊗-comm
)
open IsPreorder isPreorder public
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
open IsMonotone isMonotone-⊕ public
renaming (
∙-mono-≤ to ⊕-mono-≤;
∙-monoˡ-≤ to ⊕-monoˡ-≤;
∙-monoʳ-≤ to ⊕-monoʳ-≤
)
open IsMonotone isMonotone-⊗ public
renaming (
∙-mono-≤ to ⊗-mono-≤;
∙-monoˡ-≤ to ⊗-monoˡ-≤;
∙-monoʳ-≤ to ⊗-monoʳ-≤
)
record CostMonoid : Set₁ where
infixl 6 _+_
field
ℂ : Set
zero : ℂ
_+_ : Op₂ ℂ
_≤_ : Relation
isCostMonoid : IsCostMonoid zero _+_ _≤_
open IsCostMonoid isCostMonoid public
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
isPreorder
≤-trans
(resp₂ _≤_)
(λ h → h)
≤-trans
≤-trans
public
hiding (step-≈; step-≈˘; step-<)
record ParCostMonoid : Set₁ where
infixl 7 _⊗_
infixl 6 _⊕_
field
ℂ : Set
𝟘 : ℂ
_⊕_ : Op₂ ℂ
_⊗_ : Op₂ ℂ
_≤_ : Relation
isParCostMonoid : IsParCostMonoid 𝟘 _⊕_ _⊗_ _≤_
open IsParCostMonoid isParCostMonoid public
costMonoid : CostMonoid
costMonoid = record
{ ℂ = ℂ
; _+_ = _⊕_
; zero = 𝟘
; _≤_ = _≤_
; isCostMonoid = record
{ isMonoid = isMonoid
; isPreorder = isPreorder
; isMonotone = isMonotone-⊕
}
}
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
isPreorder
≤-trans
(resp₂ _≤_)
(λ h → h)
≤-trans
≤-trans
public
hiding (step-≈; step-≈˘; step-<)