Debian Codegraph @

src/Algebra/Solver/Monoid/Expression.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- A solver for equations over monoids
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Algebra.Bundles.Raw using (RawMonoid)
10
11 module Algebra.Solver.Monoid.Expression {c ℓ} (M : RawMonoid c ℓ) where
12
13 open import Data.Fin.Base using (Fin)
14 open import Data.Nat.Base using (ℕ)
15 open import Data.Vec.Base using (Vec; lookup)
16 open import Level using (suc; _⊔_)
17 open import Relation.Binary.Definitions using (DecidableEquality)
18
19 open RawMonoid M
20
21 private
22 variable
23 n : ℕ
24
25 ------------------------------------------------------------------------
26 -- Monoid expressions
27
28 -- There is one constructor for every operation, plus one for
29 -- variables; there may be at most n variables.
30
31 infixr 5 _⊕_
32
33 data Expr (n : ℕ) : Set where
34 var : Fin n → Expr n
35 id : Expr n
36 _⊕_ : Expr n → Expr n → Expr n
37
38 -- An environment contains one value for every variable.
39
40 Env : ℕ → Set _
41 Env n = Vec Carrier n
42
43 -- The semantics of an expression is a function from an environment to
44 -- a value.
45
46 ⟦_⟧ : Expr n → Env n → Carrier
47 ⟦ var x ⟧ ρ = lookup ρ x
48 ⟦ id ⟧ ρ = ε
49 ⟦ e₁ ⊕ e₂ ⟧ ρ = ⟦ e₁ ⟧ ρ ∙ ⟦ e₂ ⟧ ρ
50
51 ------------------------------------------------------------------------
52 -- API for normal expressions
53
54 record NormalAPI a : Set (suc a ⊔ c ⊔ ℓ) where
55 infix 5 _≟_
56
57 field
58
59 -- The type of normal forms.
60 Normal : ℕ → Set a
61 -- We can decide if two normal forms are /syntactically/ equal.
62 _≟_ : DecidableEquality (Normal n)
63 -- A normaliser.
64 normalise : Expr n → Normal n
65 -- The semantics of a normal form.
66 ⟦_⟧⇓ : Normal n → Env n → Carrier
67 -- The normaliser preserves the semantics of the expression.
68 correct : ∀ e ρ → ⟦ normalise {n = n} e ⟧⇓ ρ ≈ ⟦ e ⟧ ρ
69