| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Substituting equalities for binary relations |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- For more general transformations between algebraic structures see |
| 8 |
-- `Algebra.Morphisms`. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
open import Data.Product.Base as Product |
| 13 |
open import Relation.Binary.Core using (Rel; _⇔_) |
| 14 |
|
| 15 |
module Algebra.Construct.Subst.Equality |
| 16 |
{a ℓ₁ ℓ₂} {A : Set a} {≈₁ : Rel A ℓ₁} {≈₂ : Rel A ℓ₂} |
| 17 |
(equiv@(to , from) : ≈₁ ⇔ ≈₂) |
| 18 |
where |
| 19 |
|
| 20 |
open import Algebra.Definitions |
| 21 |
open import Algebra.Structures |
| 22 |
import Data.Sum.Base as Sum |
| 23 |
open import Function.Base using (id; _∘_) |
| 24 |
open import Relation.Binary.Construct.Subst.Equality equiv |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Definitions |
| 28 |
|
| 29 |
cong₁ : ∀ {⁻¹} → Congruent₁ ≈₁ ⁻¹ → Congruent₁ ≈₂ ⁻¹ |
| 30 |
cong₁ cong x≈y = to (cong (from x≈y)) |
| 31 |
|
| 32 |
cong₂ : ∀ {∙} → Congruent₂ ≈₁ ∙ → Congruent₂ ≈₂ ∙ |
| 33 |
cong₂ cong u≈v x≈y = to (cong (from u≈v) (from x≈y)) |
| 34 |
|
| 35 |
assoc : ∀ {∙} → Associative ≈₁ ∙ → Associative ≈₂ ∙ |
| 36 |
assoc assoc x y z = to (assoc x y z) |
| 37 |
|
| 38 |
comm : ∀ {∙} → Commutative ≈₁ ∙ → Commutative ≈₂ ∙ |
| 39 |
comm comm x y = to (comm x y) |
| 40 |
|
| 41 |
idem : ∀ {∙} → Idempotent ≈₁ ∙ → Idempotent ≈₂ ∙ |
| 42 |
idem idem x = to (idem x) |
| 43 |
|
| 44 |
sel : ∀ {∙} → Selective ≈₁ ∙ → Selective ≈₂ ∙ |
| 45 |
sel sel x y = Sum.map to to (sel x y) |
| 46 |
|
| 47 |
identity : ∀ {∙ e} → Identity ≈₁ e ∙ → Identity ≈₂ e ∙ |
| 48 |
identity = Product.map (to ∘_) (to ∘_) |
| 49 |
|
| 50 |
inverse : ∀ {∙ e ⁻¹} → Inverse ≈₁ ⁻¹ ∙ e → Inverse ≈₂ ⁻¹ ∙ e |
| 51 |
inverse = Product.map (to ∘_) (to ∘_) |
| 52 |
|
| 53 |
absorptive : ∀ {∙ ◦} → Absorptive ≈₁ ∙ ◦ → Absorptive ≈₂ ∙ ◦ |
| 54 |
absorptive = Product.map (λ f x y → to (f x y)) (λ f x y → to (f x y)) |
| 55 |
|
| 56 |
distribˡ : ∀ {∙ ◦} → _DistributesOverˡ_ ≈₁ ∙ ◦ → _DistributesOverˡ_ ≈₂ ∙ ◦ |
| 57 |
distribˡ distribˡ x y z = to (distribˡ x y z) |
| 58 |
|
| 59 |
distribʳ : ∀ {∙ ◦} → _DistributesOverʳ_ ≈₁ ∙ ◦ → _DistributesOverʳ_ ≈₂ ∙ ◦ |
| 60 |
distribʳ distribʳ x y z = to (distribʳ x y z) |
| 61 |
|
| 62 |
distrib : ∀ {∙ ◦} → _DistributesOver_ ≈₁ ∙ ◦ → _DistributesOver_ ≈₂ ∙ ◦ |
| 63 |
distrib {∙} {◦} = Product.map (distribˡ {∙} {◦}) (distribʳ {∙} {◦}) |
| 64 |
|
| 65 |
------------------------------------------------------------------------ |
| 66 |
-- Structures |
| 67 |
|
| 68 |
isMagma : ∀ {∙} → IsMagma ≈₁ ∙ → IsMagma ≈₂ ∙ |
| 69 |
isMagma S = record |
| 70 |
{ isEquivalence = isEquivalence S.isEquivalence |
| 71 |
; ∙-cong = cong₂ S.∙-cong |
| 72 |
} where module S = IsMagma S |
| 73 |
|
| 74 |
isSemigroup : ∀ {∙} → IsSemigroup ≈₁ ∙ → IsSemigroup ≈₂ ∙ |
| 75 |
isSemigroup {∙} S = record |
| 76 |
{ isMagma = isMagma S.isMagma |
| 77 |
; assoc = assoc {∙} S.assoc |
| 78 |
} where module S = IsSemigroup S |
| 79 |
|
| 80 |
isBand : ∀ {∙} → IsBand ≈₁ ∙ → IsBand ≈₂ ∙ |
| 81 |
isBand {∙} S = record |
| 82 |
{ isSemigroup = isSemigroup S.isSemigroup |
| 83 |
; idem = idem {∙} S.idem |
| 84 |
} where module S = IsBand S |
| 85 |
|
| 86 |
isSelectiveMagma : ∀ {∙} → IsSelectiveMagma ≈₁ ∙ → IsSelectiveMagma ≈₂ ∙ |
| 87 |
isSelectiveMagma S = record |
| 88 |
{ isMagma = isMagma S.isMagma |
| 89 |
; sel = sel S.sel |
| 90 |
} where module S = IsSelectiveMagma S |
| 91 |
|
| 92 |
isMonoid : ∀ {∙ ε} → IsMonoid ≈₁ ∙ ε → IsMonoid ≈₂ ∙ ε |
| 93 |
isMonoid S = record |
| 94 |
{ isSemigroup = isSemigroup S.isSemigroup |
| 95 |
; identity = Product.map (to ∘_) (to ∘_) S.identity |
| 96 |
} where module S = IsMonoid S |
| 97 |
|
| 98 |
isCommutativeMonoid : ∀ {∙ ε} → |
| 99 |
IsCommutativeMonoid ≈₁ ∙ ε → IsCommutativeMonoid ≈₂ ∙ ε |
| 100 |
isCommutativeMonoid S = record |
| 101 |
{ isMonoid = isMonoid S.isMonoid |
| 102 |
; comm = comm S.comm |
| 103 |
} where module S = IsCommutativeMonoid S |
| 104 |
|
| 105 |
isIdempotentCommutativeMonoid : ∀ {∙ ε} → |
| 106 |
IsIdempotentCommutativeMonoid ≈₁ ∙ ε → |
| 107 |
IsIdempotentCommutativeMonoid ≈₂ ∙ ε |
| 108 |
isIdempotentCommutativeMonoid {∙} S = record |
| 109 |
{ isCommutativeMonoid = isCommutativeMonoid S.isCommutativeMonoid |
| 110 |
; idem = to ∘ S.idem |
| 111 |
} where module S = IsIdempotentCommutativeMonoid S |
| 112 |
|
| 113 |
isGroup : ∀ {∙ ε ⁻¹} → IsGroup ≈₁ ∙ ε ⁻¹ → IsGroup ≈₂ ∙ ε ⁻¹ |
| 114 |
isGroup S = record |
| 115 |
{ isMonoid = isMonoid S.isMonoid |
| 116 |
; inverse = Product.map (to ∘_) (to ∘_) S.inverse |
| 117 |
; ⁻¹-cong = cong₁ S.⁻¹-cong |
| 118 |
} where module S = IsGroup S |
| 119 |
|
| 120 |
isAbelianGroup : ∀ {∙ ε ⁻¹} → |
| 121 |
IsAbelianGroup ≈₁ ∙ ε ⁻¹ → IsAbelianGroup ≈₂ ∙ ε ⁻¹ |
| 122 |
isAbelianGroup S = record |
| 123 |
{ isGroup = isGroup S.isGroup |
| 124 |
; comm = comm S.comm |
| 125 |
} where module S = IsAbelianGroup S |
| 126 |
|
| 127 |
isNearSemiring : ∀ {+ * 0#} → |
| 128 |
IsNearSemiring ≈₁ + * 0# → IsNearSemiring ≈₂ + * 0# |
| 129 |
isNearSemiring {* = *} S = record |
| 130 |
{ +-isMonoid = isMonoid S.+-isMonoid |
| 131 |
; *-cong = cong₂ S.*-cong |
| 132 |
; *-assoc = assoc {*} S.*-assoc |
| 133 |
; distribʳ = λ x y z → to (S.distribʳ x y z) |
| 134 |
; zeroˡ = to ∘ S.zeroˡ |
| 135 |
} where module S = IsNearSemiring S |
| 136 |
|
| 137 |
isSemiringWithoutOne : ∀ {+ * 0#} → |
| 138 |
IsSemiringWithoutOne ≈₁ + * 0# → IsSemiringWithoutOne ≈₂ + * 0# |
| 139 |
isSemiringWithoutOne {+} {*} S = record |
| 140 |
{ +-isCommutativeMonoid = isCommutativeMonoid S.+-isCommutativeMonoid |
| 141 |
; *-cong = cong₂ S.*-cong |
| 142 |
; *-assoc = assoc {*} S.*-assoc |
| 143 |
; distrib = distrib {*} {+} S.distrib |
| 144 |
; zero = Product.map (to ∘_) (to ∘_) S.zero |
| 145 |
} where module S = IsSemiringWithoutOne S |
| 146 |
|
| 147 |
isCommutativeSemiringWithoutOne : ∀ {+ * 0#} → |
| 148 |
IsCommutativeSemiringWithoutOne ≈₁ + * 0# → |
| 149 |
IsCommutativeSemiringWithoutOne ≈₂ + * 0# |
| 150 |
isCommutativeSemiringWithoutOne S = record |
| 151 |
{ isSemiringWithoutOne = isSemiringWithoutOne S.isSemiringWithoutOne |
| 152 |
; *-comm = comm S.*-comm |
| 153 |
} where module S = IsCommutativeSemiringWithoutOne S |