Debian Codegraph @

src/Tactic/RingSolver/Core/Expression.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- A type for expressions over a raw ring.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Tactic.RingSolver.Core.Expression where
10
11 open import Data.Nat.Base using (ℕ)
12 open import Data.Fin.Base using (Fin)
13 open import Data.Vec.Base as Vec using (Vec)
14
15 open import Algebra
16
17 infixl 6 _⊕_
18 infixl 7 _⊗_
19 infixr 8 _⊛_
20 infix 8 ⊝_
21
22 data Expr {a} (A : Set a) (n : ℕ) : Set a where
23 Κ : A → Expr A n -- Constant
24 Ι : Fin n → Expr A n -- Variable
25 _⊕_ : Expr A n → Expr A n → Expr A n -- Addition
26 _⊗_ : Expr A n → Expr A n → Expr A n -- Multiplication
27 _⊛_ : Expr A n → ℕ → Expr A n -- Exponentiation
28 ⊝_ : Expr A n → Expr A n -- Negation
29
30
31 module Eval
32 {ℓ₁ ℓ₂} (rawRing : RawRing ℓ₁ ℓ₂)
33 (open RawRing rawRing)
34 {a} {A : Set a} (⟦_⟧ᵣ : A → Carrier) where
35
36 open import Algebra.Definitions.RawSemiring rawSemiring
37 using (_^′_)
38
39 ⟦_⟧ : ∀ {n} → Expr A n → Vec Carrier n → Carrier
40 ⟦ Κ x ⟧ ρ = ⟦ x ⟧ᵣ
41 ⟦ Ι x ⟧ ρ = Vec.lookup ρ x
42 ⟦ x ⊕ y ⟧ ρ = ⟦ x ⟧ ρ + ⟦ y ⟧ ρ
43 ⟦ x ⊗ y ⟧ ρ = ⟦ x ⟧ ρ * ⟦ y ⟧ ρ
44 ⟦ ⊝ x ⟧ ρ = - ⟦ x ⟧ ρ
45 ⟦ x ⊛ i ⟧ ρ = ⟦ x ⟧ ρ ^′ i