@@ -33,6 +33,10 @@ open import Relation.Nullary.Decidable using (Dec)
33
33
open CommutativeMonoid M
34
34
open EqReasoning setoid
35
35
36
+ private
37
+ variable
38
+ n : ℕ
39
+
36
40
------------------------------------------------------------------------
37
41
-- Monoid expressions
38
42
@@ -55,7 +59,7 @@ Env n = Vec Carrier n
55
59
-- The semantics of an expression is a function from an environment to
56
60
-- a value.
57
61
58
- ⟦_⟧ : ∀ {n} → Expr n → Env n → Carrier
62
+ ⟦_⟧ : Expr n → Env n → Carrier
59
63
⟦ var x ⟧ ρ = lookup ρ x
60
64
⟦ id ⟧ ρ = ε
61
65
⟦ e₁ ⊕ e₂ ⟧ ρ = ⟦ e₁ ⟧ ρ ∙ ⟦ e₂ ⟧ ρ
@@ -70,27 +74,27 @@ Normal n = Vec ℕ n
70
74
71
75
-- The semantics of a normal form.
72
76
73
- ⟦_⟧⇓ : ∀ {n} → Normal n → Env n → Carrier
77
+ ⟦_⟧⇓ : Normal n → Env n → Carrier
74
78
⟦ [] ⟧⇓ _ = ε
75
- ⟦ n ∷ v ⟧⇓ (a ∷ ρ) = fold (⟦ v ⟧⇓ ρ) (λ b → a ∙ b ) n
79
+ ⟦ n ∷ v ⟧⇓ (a ∷ ρ) = fold (⟦ v ⟧⇓ ρ) (a ∙_ ) n
76
80
77
81
------------------------------------------------------------------------
78
82
-- Constructions on normal forms
79
83
80
84
-- The empty bag.
81
85
82
- empty : ∀ {n} → Normal n
83
- empty = replicate 0
86
+ empty : Normal n
87
+ empty = replicate _ 0
84
88
85
89
-- A singleton bag.
86
90
87
- sg : ∀ {n} (i : Fin n) → Normal n
91
+ sg : (i : Fin n) → Normal n
88
92
sg zero = 1 ∷ empty
89
93
sg (suc i) = 0 ∷ sg i
90
94
91
95
-- The composition of normal forms.
92
96
93
- _•_ : ∀ {n} (v w : Normal n) → Normal n
97
+ _•_ : (v w : Normal n) → Normal n
94
98
[] • [] = []
95
99
(l ∷ v) • (m ∷ w) = l + m ∷ v • w
96
100
@@ -99,13 +103,13 @@ _•_ : ∀{n} (v w : Normal n) → Normal n
99
103
100
104
-- The empty bag stands for the unit ε.
101
105
102
- empty-correct : ∀ {n} (ρ : Env n) → ⟦ empty ⟧⇓ ρ ≈ ε
106
+ empty-correct : (ρ : Env n) → ⟦ empty ⟧⇓ ρ ≈ ε
103
107
empty-correct [] = refl
104
108
empty-correct (a ∷ ρ) = empty-correct ρ
105
109
106
110
-- The singleton bag stands for a single variable.
107
111
108
- sg-correct : ∀ {n} (x : Fin n) (ρ : Env n) → ⟦ sg x ⟧⇓ ρ ≈ lookup ρ x
112
+ sg-correct : (x : Fin n) (ρ : Env n) → ⟦ sg x ⟧⇓ ρ ≈ lookup ρ x
109
113
sg-correct zero (x ∷ ρ) = begin
110
114
x ∙ ⟦ empty ⟧⇓ ρ ≈⟨ ∙-congˡ (empty-correct ρ) ⟩
111
115
x ∙ ε ≈⟨ identityʳ _ ⟩
@@ -114,7 +118,7 @@ sg-correct (suc x) (m ∷ ρ) = sg-correct x ρ
114
118
115
119
-- Normal form composition corresponds to the composition of the monoid.
116
120
117
- comp-correct : ∀ {n} (v w : Normal n) (ρ : Env n) →
121
+ comp-correct : (v w : Normal n) (ρ : Env n) →
118
122
⟦ v • w ⟧⇓ ρ ≈ (⟦ v ⟧⇓ ρ ∙ ⟦ w ⟧⇓ ρ)
119
123
comp-correct [] [] ρ = sym (identityˡ _)
120
124
comp-correct (l ∷ v) (m ∷ w) (a ∷ ρ) = lemma l m (comp-correct v w ρ)
@@ -136,14 +140,14 @@ comp-correct (l ∷ v) (m ∷ w) (a ∷ ρ) = lemma l m (comp-correct v w ρ)
136
140
137
141
-- A normaliser.
138
142
139
- normalise : ∀ {n} → Expr n → Normal n
143
+ normalise : Expr n → Normal n
140
144
normalise (var x) = sg x
141
145
normalise id = empty
142
146
normalise (e₁ ⊕ e₂) = normalise e₁ • normalise e₂
143
147
144
148
-- The normaliser preserves the semantics of the expression.
145
149
146
- normalise-correct : ∀ {n} (e : Expr n) (ρ : Env n) →
150
+ normalise-correct : (e : Expr n) (ρ : Env n) →
147
151
⟦ normalise e ⟧⇓ ρ ≈ ⟦ e ⟧ ρ
148
152
normalise-correct (var x) ρ = sg-correct x ρ
149
153
normalise-correct id ρ = empty-correct ρ
@@ -171,14 +175,14 @@ open module R = Reflection
171
175
172
176
infix 5 _≟_
173
177
174
- _≟_ : ∀ {n} (nf₁ nf₂ : Normal n) → Dec (nf₁ ≡ nf₂)
178
+ _≟_ : (nf₁ nf₂ : Normal n) → Dec (nf₁ ≡ nf₂)
175
179
nf₁ ≟ nf₂ = Dec.map Pointwise-≡↔≡ (decidable ℕ._≟_ nf₁ nf₂)
176
180
where open Pointwise
177
181
178
182
-- We can also give a sound, but not necessarily complete, procedure
179
183
-- for determining if two expressions have the same semantics.
180
184
181
- prove′ : ∀ {n} (e₁ e₂ : Expr n) → Maybe (∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
185
+ prove′ : (e₁ e₂ : Expr n) → Maybe (∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
182
186
prove′ e₁ e₂ =
183
187
Maybe.map lemma (decToMaybe (normalise e₁ ≟ normalise e₂))
184
188
where
0 commit comments