forked from agda/agda-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpression.agda
45 lines (35 loc) · 1.42 KB
/
Expression.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
------------------------------------------------------------------------
-- The Agda standard library
--
-- A type for expressions over a raw ring.
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
module Tactic.RingSolver.Core.Expression where
open import Data.Nat.Base using (ℕ)
open import Data.Fin.Base using (Fin)
open import Data.Vec.Base as Vec using (Vec)
open import Algebra
infixl 6 _⊕_
infixl 7 _⊗_
infixr 8 _⊛_
infix 8 ⊝_
data Expr {a} (A : Set a) (n : ℕ) : Set a where
Κ : A → Expr A n -- Constant
Ι : Fin n → Expr A n -- Variable
_⊕_ : Expr A n → Expr A n → Expr A n -- Addition
_⊗_ : Expr A n → Expr A n → Expr A n -- Multiplication
_⊛_ : Expr A n → ℕ → Expr A n -- Exponentiation
⊝_ : Expr A n → Expr A n -- Negation
module Eval
{ℓ₁ ℓ₂} (rawRing : RawRing ℓ₁ ℓ₂)
(open RawRing rawRing)
{a} {A : Set a} (⟦_⟧ᵣ : A → Carrier) where
open import Algebra.Definitions.RawSemiring rawSemiring
using (_^′_)
⟦_⟧ : ∀ {n} → Expr A n → Vec Carrier n → Carrier
⟦ Κ x ⟧ ρ = ⟦ x ⟧ᵣ
⟦ Ι x ⟧ ρ = Vec.lookup ρ x
⟦ x ⊕ y ⟧ ρ = ⟦ x ⟧ ρ + ⟦ y ⟧ ρ
⟦ x ⊗ y ⟧ ρ = ⟦ x ⟧ ρ * ⟦ y ⟧ ρ
⟦ ⊝ x ⟧ ρ = - ⟦ x ⟧ ρ
⟦ x ⊛ i ⟧ ρ = ⟦ x ⟧ ρ ^′ i