| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Instantiates the ring solver, using the natural numbers as the |
| 5 |
-- coefficient "ring" |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Algebra using (RawRing; CommutativeSemiring ) |
| 11 |
import Algebra.Properties.Semiring.Mult as SemiringMultiplication |
| 12 |
open import Data.Maybe.Base using (Maybe; just; nothing; map) |
| 13 |
|
| 14 |
module Algebra.Solver.Ring.NaturalCoefficients |
| 15 |
{r₁ r₂} (R : CommutativeSemiring r₁ r₂) |
| 16 |
(open CommutativeSemiring R) |
| 17 |
(open SemiringMultiplication semiring using () renaming (_×_ to _×ᵤ_)) |
| 18 |
(dec : ∀ m n → Maybe (m ×ᵤ 1# ≈ n ×ᵤ 1#)) where |
| 19 |
|
| 20 |
open import Algebra.Solver.Ring.AlmostCommutativeRing |
| 21 |
open import Data.Nat.Base as ℕ using (ℕ; _+_; _*_) |
| 22 |
open import Data.Product.Base using (module Σ) |
| 23 |
open import Function.Base using (id) |
| 24 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_) |
| 25 |
|
| 26 |
open import Algebra.Properties.Semiring.Mult.TCOptimised semiring |
| 27 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 28 |
|
| 29 |
private |
| 30 |
|
| 31 |
-- The coefficient "ring". |
| 32 |
|
| 33 |
ℕ-ring : RawRing _ _ |
| 34 |
ℕ-ring = record |
| 35 |
{ Carrier = ℕ |
| 36 |
; _≈_ = _≡_ |
| 37 |
; _+_ = ℕ._+_ |
| 38 |
; _*_ = ℕ._*_ |
| 39 |
; -_ = id |
| 40 |
; 0# = 0 |
| 41 |
; 1# = 1 |
| 42 |
} |
| 43 |
|
| 44 |
-- There is a homomorphism from ℕ to R. |
| 45 |
-- |
| 46 |
-- Note that the optimised _×_ is used rather than unoptimised _×ᵤ_. |
| 47 |
-- If _×ᵤ_ were used, then Function.Related.TypeIsomorphisms.test |
| 48 |
-- would fail to type-check. |
| 49 |
|
| 50 |
homomorphism : ℕ-ring -Raw-AlmostCommutative⟶ fromCommutativeSemiring R |
| 51 |
homomorphism = record |
| 52 |
{ ⟦_⟧ = λ n → n × 1# |
| 53 |
; +-homo = ×-homo-+ 1# |
| 54 |
; *-homo = ×1-homo-* |
| 55 |
; -‿homo = λ _ → refl |
| 56 |
; 0-homo = refl |
| 57 |
; 1-homo = refl |
| 58 |
} |
| 59 |
|
| 60 |
-- Equality of certain expressions can be decided. |
| 61 |
|
| 62 |
dec′ : ∀ m n → Maybe (m × 1# ≈ n × 1#) |
| 63 |
dec′ m n = map to (dec m n) |
| 64 |
where |
| 65 |
to : m ×ᵤ 1# ≈ n ×ᵤ 1# → m × 1# ≈ n × 1# |
| 66 |
to m≈n = begin |
| 67 |
m × 1# ≈⟨ ×ᵤ≈× m 1# ⟨ |
| 68 |
m ×ᵤ 1# ≈⟨ m≈n ⟩ |
| 69 |
n ×ᵤ 1# ≈⟨ ×ᵤ≈× n 1# ⟩ |
| 70 |
n × 1# ∎ |
| 71 |
|
| 72 |
-- The instantiation. |
| 73 |
|
| 74 |
open import Algebra.Solver.Ring _ _ homomorphism dec′ public |