-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNonReflective.agda
More file actions
81 lines (68 loc) · 3.1 KB
/
NonReflective.agda
File metadata and controls
81 lines (68 loc) · 3.1 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-
This module is almost exactly the same as the Tactic.RingSolver.NonReflective in
the Agda Standard Library as of commit 84dcc85. The key difference is that this
version allows the user to use a coefficient ring other than the carrier ring
(given via homomorphism), while that version does not.
Without this change, the solver does not function well with real numbers since
we are forced to use the reals as the coefficient ring and the carrier ring.
Using the rationals for coefficients fixes our problems. The main change comes from
the ring solver's original documentation at
https://oisdk.github.io/agda-ring-solver/Polynomial.Solver.html,
where Raw.Carrier is used instead of Carrier.
-}
{-# OPTIONS --without-K --safe #-}
open import Tactic.RingSolver.Core.AlmostCommutativeRing
open import Tactic.RingSolver.Core.Polynomial.Parameters
module NonReflective
{ℓ₁ ℓ₂ ℓ₃ ℓ₄}
(homo : Homomorphism ℓ₁ ℓ₂ ℓ₃ ℓ₄)
(let open Homomorphism homo)
where
open import Algebra.Morphism
open import Function
open import Data.Bool.Base using (Bool; true; false; T; if_then_else_)
open import Data.Maybe.Base
open import Data.Empty using (⊥-elim)
open import Data.Nat.Base using (ℕ)
open import Data.Product
open import Data.Vec hiding (_⊛_)
open import Data.Vec.N-ary
open import Tactic.RingSolver.Core.Expression
open import Algebra.Properties.Semiring.Exp.TCOptimised semiring
myMorphism : _
myMorphism = _-Raw-AlmostCommutative⟶_.⟦_⟧ morphism
open Eval (AlmostCommutativeRing.rawRing to) myMorphism
open import Tactic.RingSolver.Core.Polynomial.Base from
norm : ∀ {n} -> Expr Raw.Carrier n -> Poly n
norm (Κ x) = κ x
norm (Ι x) = ι x
norm (x ⊕ y) = norm x ⊞ norm y
norm (x ⊗ y) = norm x ⊠ norm y
norm (x ⊛ i) = norm x ⊡ i
norm (⊝ x) = ⊟ norm x
⟦_⇓⟧ : ∀ {n} → Expr Raw.Carrier n → Vec Carrier n → Carrier
⟦ expr ⇓⟧ = ⟦ norm expr ⟧ₚ where
open import Tactic.RingSolver.Core.Polynomial.Semantics homo
renaming (⟦_⟧ to ⟦_⟧ₚ)
correct : ∀ {n} -> (e : Expr Raw.Carrier n) -> (ρ : Vec Carrier n) -> ⟦ e ⇓⟧ ρ ≈ ⟦ e ⟧ ρ
correct {n} = go
where
open import Tactic.RingSolver.Core.Polynomial.Homomorphism homo
go : ∀ (expr : Expr Raw.Carrier n) ρ → ⟦ expr ⇓⟧ ρ ≈ ⟦ expr ⟧ ρ
go (Κ x) ρ = κ-hom x ρ
go (Ι x) ρ = ι-hom x ρ
go (x ⊕ y) ρ = ⊞-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ +-cong ⟩ go y ρ)
go (x ⊗ y) ρ = ⊠-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ *-cong ⟩ go y ρ)
go (x ⊛ i) ρ = ⊡-hom (norm x) i ρ ⟨ trans ⟩ ^-congˡ i (go x ρ)
go (⊝ x) ρ = ⊟-hom (norm x) ρ ⟨ trans ⟩ -‿cong (go x ρ)
open import Relation.Binary.Reflection setoid Ι ⟦_⟧ ⟦_⇓⟧ correct public
{-
We are using the ⊖ notation instead of ⊝ (notice the former has a longer line) because
of a parsing error when using the latter.
-}
infixl 6 _⊖_
_⊖_ : ∀ {n : ℕ} ->
Expr Raw.Carrier n ->
Expr Raw.Carrier n ->
Expr Raw.Carrier n
x ⊖ y = x ⊕ (⊝ y)