| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Ways to give instances of certain structures where some fields can |
| 5 |
-- be given in terms of others. Re-exported via `Algebra`. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Algebra.Core |
| 11 |
open import Algebra.Consequences.Setoid |
| 12 |
open import Data.Product.Base using (_,_; proj₁; proj₂) |
| 13 |
open import Level using (_⊔_) |
| 14 |
open import Relation.Binary.Core using (Rel) |
| 15 |
open import Relation.Binary.Bundles using (Setoid) |
| 16 |
open import Relation.Binary.Structures using (IsEquivalence) |
| 17 |
|
| 18 |
module Algebra.Structures.Biased |
| 19 |
{a ℓ} {A : Set a} -- The underlying set |
| 20 |
(_≈_ : Rel A ℓ) -- The underlying equality relation |
| 21 |
where |
| 22 |
|
| 23 |
open import Algebra.Definitions _≈_ |
| 24 |
open import Algebra.Structures _≈_ |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- IsCommutativeMonoid |
| 28 |
|
| 29 |
record IsCommutativeMonoidˡ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where |
| 30 |
field |
| 31 |
isSemigroup : IsSemigroup ∙ |
| 32 |
identityˡ : LeftIdentity ε ∙ |
| 33 |
comm : Commutative ∙ |
| 34 |
|
| 35 |
isCommutativeMonoid : IsCommutativeMonoid ∙ ε |
| 36 |
isCommutativeMonoid = record |
| 37 |
{ isMonoid = record |
| 38 |
{ isSemigroup = isSemigroup |
| 39 |
; identity = comm∧idˡ⇒id setoid comm identityˡ |
| 40 |
} |
| 41 |
; comm = comm |
| 42 |
} where open IsSemigroup isSemigroup |
| 43 |
|
| 44 |
open IsCommutativeMonoidˡ public |
| 45 |
using () renaming (isCommutativeMonoid to isCommutativeMonoidˡ) |
| 46 |
|
| 47 |
|
| 48 |
record IsCommutativeMonoidʳ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where |
| 49 |
field |
| 50 |
isSemigroup : IsSemigroup ∙ |
| 51 |
identityʳ : RightIdentity ε ∙ |
| 52 |
comm : Commutative ∙ |
| 53 |
|
| 54 |
isCommutativeMonoid : IsCommutativeMonoid ∙ ε |
| 55 |
isCommutativeMonoid = record |
| 56 |
{ isMonoid = record |
| 57 |
{ isSemigroup = isSemigroup |
| 58 |
; identity = comm∧idʳ⇒id setoid comm identityʳ |
| 59 |
} |
| 60 |
; comm = comm |
| 61 |
} where open IsSemigroup isSemigroup |
| 62 |
|
| 63 |
open IsCommutativeMonoidʳ public |
| 64 |
using () renaming (isCommutativeMonoid to isCommutativeMonoidʳ) |
| 65 |
|
| 66 |
------------------------------------------------------------------------ |
| 67 |
-- IsSemiringWithoutOne |
| 68 |
|
| 69 |
record IsSemiringWithoutOne* (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where |
| 70 |
field |
| 71 |
+-isCommutativeMonoid : IsCommutativeMonoid + 0# |
| 72 |
*-isSemigroup : IsSemigroup * |
| 73 |
distrib : * DistributesOver + |
| 74 |
zero : Zero 0# * |
| 75 |
|
| 76 |
isSemiringWithoutOne : IsSemiringWithoutOne + * 0# |
| 77 |
isSemiringWithoutOne = record |
| 78 |
{ +-isCommutativeMonoid = +-isCommutativeMonoid |
| 79 |
; *-cong = ∙-cong |
| 80 |
; *-assoc = assoc |
| 81 |
; distrib = distrib |
| 82 |
; zero = zero |
| 83 |
} where open IsSemigroup *-isSemigroup |
| 84 |
|
| 85 |
open IsSemiringWithoutOne* public |
| 86 |
using () renaming (isSemiringWithoutOne to isSemiringWithoutOne*) |
| 87 |
|
| 88 |
------------------------------------------------------------------------ |
| 89 |
-- IsNearSemiring |
| 90 |
|
| 91 |
record IsNearSemiring* (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where |
| 92 |
field |
| 93 |
+-isMonoid : IsMonoid + 0# |
| 94 |
*-isSemigroup : IsSemigroup * |
| 95 |
distribʳ : * DistributesOverʳ + |
| 96 |
zeroˡ : LeftZero 0# * |
| 97 |
|
| 98 |
isNearSemiring : IsNearSemiring + * 0# |
| 99 |
isNearSemiring = record |
| 100 |
{ +-isMonoid = +-isMonoid |
| 101 |
; *-cong = ∙-cong |
| 102 |
; *-assoc = assoc |
| 103 |
; distribʳ = distribʳ |
| 104 |
; zeroˡ = zeroˡ |
| 105 |
} where open IsSemigroup *-isSemigroup |
| 106 |
|
| 107 |
open IsNearSemiring* public |
| 108 |
using () renaming (isNearSemiring to isNearSemiring*) |
| 109 |
|
| 110 |
------------------------------------------------------------------------ |
| 111 |
-- IsSemiringWithoutAnnihilatingZero |
| 112 |
|
| 113 |
record IsSemiringWithoutAnnihilatingZero* (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where |
| 114 |
field |
| 115 |
+-isCommutativeMonoid : IsCommutativeMonoid + 0# |
| 116 |
*-isMonoid : IsMonoid * 1# |
| 117 |
distrib : * DistributesOver + |
| 118 |
|
| 119 |
isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero + * 0# 1# |
| 120 |
isSemiringWithoutAnnihilatingZero = record |
| 121 |
{ +-isCommutativeMonoid = +-isCommutativeMonoid |
| 122 |
; *-cong = ∙-cong |
| 123 |
; *-assoc = assoc |
| 124 |
; *-identity = identity |
| 125 |
; distrib = distrib |
| 126 |
} where open IsMonoid *-isMonoid |
| 127 |
|
| 128 |
open IsSemiringWithoutAnnihilatingZero* public |
| 129 |
using () renaming (isSemiringWithoutAnnihilatingZero to isSemiringWithoutAnnihilatingZero*) |
| 130 |
|
| 131 |
------------------------------------------------------------------------ |
| 132 |
-- IsCommutativeSemiring |
| 133 |
|
| 134 |
record IsCommutativeSemiringˡ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where |
| 135 |
field |
| 136 |
+-isCommutativeMonoid : IsCommutativeMonoid + 0# |
| 137 |
*-isCommutativeMonoid : IsCommutativeMonoid * 1# |
| 138 |
distribʳ : * DistributesOverʳ + |
| 139 |
zeroˡ : LeftZero 0# * |
| 140 |
|
| 141 |
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1# |
| 142 |
isCommutativeSemiring = record |
| 143 |
{ isSemiring = record |
| 144 |
{ isSemiringWithoutAnnihilatingZero = record |
| 145 |
{ +-isCommutativeMonoid = +-isCommutativeMonoid |
| 146 |
; *-cong = *.∙-cong |
| 147 |
; *-assoc = *.assoc |
| 148 |
; *-identity = *.identity |
| 149 |
; distrib = comm∧distrʳ⇒distr +.setoid +.∙-cong *.comm distribʳ |
| 150 |
} |
| 151 |
; zero = comm∧zeˡ⇒ze +.setoid *.comm zeroˡ |
| 152 |
} |
| 153 |
; *-comm = *.comm |
| 154 |
} |
| 155 |
where |
| 156 |
module + = IsCommutativeMonoid +-isCommutativeMonoid |
| 157 |
module * = IsCommutativeMonoid *-isCommutativeMonoid |
| 158 |
|
| 159 |
open IsCommutativeSemiringˡ public |
| 160 |
using () renaming (isCommutativeSemiring to isCommutativeSemiringˡ) |
| 161 |
|
| 162 |
|
| 163 |
record IsCommutativeSemiringʳ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where |
| 164 |
field |
| 165 |
+-isCommutativeMonoid : IsCommutativeMonoid + 0# |
| 166 |
*-isCommutativeMonoid : IsCommutativeMonoid * 1# |
| 167 |
distribˡ : * DistributesOverˡ + |
| 168 |
zeroʳ : RightZero 0# * |
| 169 |
|
| 170 |
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1# |
| 171 |
isCommutativeSemiring = record |
| 172 |
{ isSemiring = record |
| 173 |
{ isSemiringWithoutAnnihilatingZero = record |
| 174 |
{ +-isCommutativeMonoid = +-isCommutativeMonoid |
| 175 |
; *-cong = *.∙-cong |
| 176 |
; *-assoc = *.assoc |
| 177 |
; *-identity = *.identity |
| 178 |
; distrib = comm∧distrˡ⇒distr +.setoid +.∙-cong *.comm distribˡ |
| 179 |
} |
| 180 |
; zero = comm∧zeʳ⇒ze +.setoid *.comm zeroʳ |
| 181 |
} |
| 182 |
; *-comm = *.comm |
| 183 |
} |
| 184 |
where |
| 185 |
module + = IsCommutativeMonoid +-isCommutativeMonoid |
| 186 |
module * = IsCommutativeMonoid *-isCommutativeMonoid |
| 187 |
|
| 188 |
open IsCommutativeSemiringʳ public |
| 189 |
using () renaming (isCommutativeSemiring to isCommutativeSemiringʳ) |
| 190 |
|
| 191 |
|
| 192 |
------------------------------------------------------------------------ |
| 193 |
-- IsRing |
| 194 |
|
| 195 |
record IsRing* (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where |
| 196 |
field |
| 197 |
+-isAbelianGroup : IsAbelianGroup + 0# -_ |
| 198 |
*-isMonoid : IsMonoid * 1# |
| 199 |
distrib : * DistributesOver + |
| 200 |
zero : Zero 0# * |
| 201 |
|
| 202 |
isRing : IsRing + * -_ 0# 1# |
| 203 |
isRing = record |
| 204 |
{ +-isAbelianGroup = +-isAbelianGroup |
| 205 |
; *-cong = ∙-cong |
| 206 |
; *-assoc = assoc |
| 207 |
; *-identity = identity |
| 208 |
; distrib = distrib |
| 209 |
} where open IsMonoid *-isMonoid |
| 210 |
|
| 211 |
open IsRing* public |
| 212 |
using () renaming (isRing to isRing*) |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
------------------------------------------------------------------------ |
| 217 |
-- Deprecated |
| 218 |
------------------------------------------------------------------------ |
| 219 |
|
| 220 |
-- Version 2.0 |
| 221 |
|
| 222 |
-- We can recover a ring without proving that 0# annihilates *. |
| 223 |
record IsRingWithoutAnnihilatingZero (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) |
| 224 |
: Set (a ⊔ ℓ) where |
| 225 |
field |
| 226 |
+-isAbelianGroup : IsAbelianGroup + 0# -_ |
| 227 |
*-isMonoid : IsMonoid * 1# |
| 228 |
distrib : * DistributesOver + |
| 229 |
|
| 230 |
module + = IsAbelianGroup +-isAbelianGroup |
| 231 |
module * = IsMonoid *-isMonoid |
| 232 |
|
| 233 |
open + using (setoid) renaming (∙-cong to +-cong) |
| 234 |
open * using () renaming (∙-cong to *-cong) |
| 235 |
|
| 236 |
zeroˡ : LeftZero 0# * |
| 237 |
zeroˡ = assoc∧distribʳ∧idʳ∧invʳ⇒zeˡ setoid |
| 238 |
+-cong *-cong +.assoc (proj₂ distrib) +.identityʳ +.inverseʳ |
| 239 |
|
| 240 |
zeroʳ : RightZero 0# * |
| 241 |
zeroʳ = assoc∧distribˡ∧idʳ∧invʳ⇒zeʳ setoid |
| 242 |
+-cong *-cong +.assoc (proj₁ distrib) +.identityʳ +.inverseʳ |
| 243 |
|
| 244 |
zero : Zero 0# * |
| 245 |
zero = (zeroˡ , zeroʳ) |
| 246 |
|
| 247 |
isRing : IsRing + * -_ 0# 1# |
| 248 |
isRing = record |
| 249 |
{ +-isAbelianGroup = +-isAbelianGroup |
| 250 |
; *-cong = *.∙-cong |
| 251 |
; *-assoc = *.assoc |
| 252 |
; *-identity = *.identity |
| 253 |
; distrib = distrib |
| 254 |
} |
| 255 |
|
| 256 |
open IsRingWithoutAnnihilatingZero public |
| 257 |
using () renaming (isRing to isRingWithoutAnnihilatingZero) |
| 258 |
|
| 259 |
{-# WARNING_ON_USAGE IsRingWithoutAnnihilatingZero |
| 260 |
"Warning: IsRingWithoutAnnihilatingZero was deprecated in v2.0. |
| 261 |
Please use the standard `IsRing` instead." |
| 262 |
#-} |
| 263 |
{-# WARNING_ON_USAGE isRingWithoutAnnihilatingZero |
| 264 |
"Warning: isRingWithoutAnnihilatingZero was deprecated in v2.0. |
| 265 |
Please use the standard `isRing` instead." |
| 266 |
#-} |
| 267 |
|
| 268 |
-- Version 2.1 |
| 269 |
|
| 270 |
-- issue #2253 |
| 271 |
{-# WARNING_ON_USAGE IsRing* |
| 272 |
"Warning: IsRing* was deprecated in v2.1. |
| 273 |
Please use the standard `IsRing` instead." |
| 274 |
#-} |
| 275 |
{-# WARNING_ON_USAGE isRing* |
| 276 |
"Warning: isRing* was deprecated in v2.1. |
| 277 |
Please use the standard `isRing` instead." |
| 278 |
#-} |