@@ -33,6 +33,10 @@ open import Relation.Nullary.Decidable using (Dec)
3333open CommutativeMonoid M
3434open EqReasoning setoid
3535
36+ private
37+ variable
38+ n : ℕ
39+
3640------------------------------------------------------------------------
3741-- Monoid expressions
3842
@@ -55,7 +59,7 @@ Env n = Vec Carrier n
5559-- The semantics of an expression is a function from an environment to
5660-- a value.
5761
58- ⟦_⟧ : ∀ {n} → Expr n → Env n → Carrier
62+ ⟦_⟧ : Expr n → Env n → Carrier
5963⟦ var x ⟧ ρ = lookup ρ x
6064⟦ id ⟧ ρ = ε
6165⟦ e₁ ⊕ e₂ ⟧ ρ = ⟦ e₁ ⟧ ρ ∙ ⟦ e₂ ⟧ ρ
@@ -70,27 +74,27 @@ Normal n = Vec ℕ n
7074
7175-- The semantics of a normal form.
7276
73- ⟦_⟧⇓ : ∀ {n} → Normal n → Env n → Carrier
77+ ⟦_⟧⇓ : Normal n → Env n → Carrier
7478⟦ [] ⟧⇓ _ = ε
75- ⟦ n ∷ v ⟧⇓ (a ∷ ρ) = fold (⟦ v ⟧⇓ ρ) (λ b → a ∙ b ) n
79+ ⟦ n ∷ v ⟧⇓ (a ∷ ρ) = fold (⟦ v ⟧⇓ ρ) (a ∙_ ) n
7680
7781------------------------------------------------------------------------
7882-- Constructions on normal forms
7983
8084-- The empty bag.
8185
82- empty : ∀ {n} → Normal n
83- empty = replicate 0
86+ empty : Normal n
87+ empty = replicate _ 0
8488
8589-- A singleton bag.
8690
87- sg : ∀ {n} (i : Fin n) → Normal n
91+ sg : (i : Fin n) → Normal n
8892sg zero = 1 ∷ empty
8993sg (suc i) = 0 ∷ sg i
9094
9195-- The composition of normal forms.
9296
93- _•_ : ∀ {n} (v w : Normal n) → Normal n
97+ _•_ : (v w : Normal n) → Normal n
9498[] • [] = []
9599(l ∷ v) • (m ∷ w) = l + m ∷ v • w
96100
@@ -99,13 +103,13 @@ _•_ : ∀{n} (v w : Normal n) → Normal n
99103
100104-- The empty bag stands for the unit ε.
101105
102- empty-correct : ∀ {n} (ρ : Env n) → ⟦ empty ⟧⇓ ρ ≈ ε
106+ empty-correct : (ρ : Env n) → ⟦ empty ⟧⇓ ρ ≈ ε
103107empty-correct [] = refl
104108empty-correct (a ∷ ρ) = empty-correct ρ
105109
106110-- The singleton bag stands for a single variable.
107111
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
109113sg-correct zero (x ∷ ρ) = begin
110114 x ∙ ⟦ empty ⟧⇓ ρ ≈⟨ ∙-congˡ (empty-correct ρ) ⟩
111115 x ∙ ε ≈⟨ identityʳ _ ⟩
@@ -114,7 +118,7 @@ sg-correct (suc x) (m ∷ ρ) = sg-correct x ρ
114118
115119-- Normal form composition corresponds to the composition of the monoid.
116120
117- comp-correct : ∀ {n} (v w : Normal n) (ρ : Env n) →
121+ comp-correct : (v w : Normal n) (ρ : Env n) →
118122 ⟦ v • w ⟧⇓ ρ ≈ (⟦ v ⟧⇓ ρ ∙ ⟦ w ⟧⇓ ρ)
119123comp-correct [] [] ρ = sym (identityˡ _)
120124comp-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 ρ)
136140
137141-- A normaliser.
138142
139- normalise : ∀ {n} → Expr n → Normal n
143+ normalise : Expr n → Normal n
140144normalise (var x) = sg x
141145normalise id = empty
142146normalise (e₁ ⊕ e₂) = normalise e₁ • normalise e₂
143147
144148-- The normaliser preserves the semantics of the expression.
145149
146- normalise-correct : ∀ {n} (e : Expr n) (ρ : Env n) →
150+ normalise-correct : (e : Expr n) (ρ : Env n) →
147151 ⟦ normalise e ⟧⇓ ρ ≈ ⟦ e ⟧ ρ
148152normalise-correct (var x) ρ = sg-correct x ρ
149153normalise-correct id ρ = empty-correct ρ
@@ -171,14 +175,14 @@ open module R = Reflection
171175
172176infix 5 _≟_
173177
174- _≟_ : ∀ {n} (nf₁ nf₂ : Normal n) → Dec (nf₁ ≡ nf₂)
178+ _≟_ : (nf₁ nf₂ : Normal n) → Dec (nf₁ ≡ nf₂)
175179nf₁ ≟ nf₂ = Dec.map Pointwise-≡↔≡ (decidable ℕ._≟_ nf₁ nf₂)
176180 where open Pointwise
177181
178182-- We can also give a sound, but not necessarily complete, procedure
179183-- for determining if two expressions have the same semantics.
180184
181- prove′ : ∀ {n} (e₁ e₂ : Expr n) → Maybe (∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
185+ prove′ : (e₁ e₂ : Expr n) → Maybe (∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
182186prove′ e₁ e₂ =
183187 Maybe.map lemma (decToMaybe (normalise e₁ ≟ normalise e₂))
184188 where
0 commit comments