| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Basic auxiliary definitions for semiring-like structures |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Algebra.Bundles using (RawSemiring) |
| 10 |
|
| 11 |
module Algebra.Definitions.RawSemiring {a ℓ} (M : RawSemiring a ℓ) where |
| 12 |
|
| 13 |
open import Data.Sum.Base using (_⊎_) |
| 14 |
open import Data.Nat.Base using (ℕ; zero; suc) |
| 15 |
open import Level using (_⊔_) |
| 16 |
open import Relation.Binary.Core using (Rel) |
| 17 |
open RawSemiring M renaming (Carrier to A) |
| 18 |
|
| 19 |
------------------------------------------------------------------------ |
| 20 |
-- Definitions over _+_ |
| 21 |
|
| 22 |
open import Algebra.Definitions.RawMonoid +-rawMonoid public |
| 23 |
using |
| 24 |
( _×_ -- : ℕ → A → A |
| 25 |
; _×′_ -- : ℕ → A → A |
| 26 |
; sum -- : Vector A n → A |
| 27 |
) |
| 28 |
|
| 29 |
------------------------------------------------------------------------ |
| 30 |
-- Definitions over _*_ |
| 31 |
|
| 32 |
open import Algebra.Definitions.RawMonoid *-rawMonoid as Mult public |
| 33 |
using |
| 34 |
( _∣_ |
| 35 |
; _∤_ |
| 36 |
) |
| 37 |
renaming |
| 38 |
( sum to product |
| 39 |
) |
| 40 |
|
| 41 |
-- Unlike `sum` to `product`, can't simply rename multiplication to |
| 42 |
-- exponentation as the argument order is reversed. |
| 43 |
|
| 44 |
-- Standard exponentiation |
| 45 |
|
| 46 |
infixr 8 _^_ |
| 47 |
_^_ : A → ℕ → A |
| 48 |
x ^ n = n Mult.× x |
| 49 |
|
| 50 |
-- Exponentiation optimised for type-checking |
| 51 |
|
| 52 |
infixr 8 _^′_ |
| 53 |
_^′_ : A → ℕ → A |
| 54 |
x ^′ n = n Mult.×′ x |
| 55 |
{-# INLINE _^′_ #-} |
| 56 |
|
| 57 |
-- Exponentiation optimised for tail-recursion |
| 58 |
|
| 59 |
infixr 8 _^[_]*_ _^ᵗ_ |
| 60 |
|
| 61 |
_^[_]*_ : A → ℕ → A → A |
| 62 |
x ^[ zero ]* y = y |
| 63 |
x ^[ suc n ]* y = x ^[ n ]* (x * y) |
| 64 |
|
| 65 |
_^ᵗ_ : A → ℕ → A |
| 66 |
x ^ᵗ n = x ^[ n ]* 1# |
| 67 |
|
| 68 |
------------------------------------------------------------------------ |
| 69 |
-- Primality |
| 70 |
|
| 71 |
Coprime : Rel A (a ⊔ ℓ) |
| 72 |
Coprime x y = ∀ {z} → z ∣ x → z ∣ y → z ∣ 1# |
| 73 |
|
| 74 |
record Irreducible (p : A) : Set (a ⊔ ℓ) where |
| 75 |
constructor mkIrred |
| 76 |
field |
| 77 |
p∤1 : p ∤ 1# |
| 78 |
split-∣1 : ∀ {x y} → p ≈ (x * y) → x ∣ 1# ⊎ y ∣ 1# |
| 79 |
|
| 80 |
record Prime (p : A) : Set (a ⊔ ℓ) where |
| 81 |
constructor mkPrime |
| 82 |
field |
| 83 |
p≉0 : p ≉ 0# |
| 84 |
p∤1 : p ∤ 1# |
| 85 |
split-∣ : ∀ {x y} → p ∣ x * y → p ∣ x ⊎ p ∣ y |