| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Flipping the arguments of a binary operation preserves many of its |
| 5 |
-- algebraic properties. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
module Algebra.Construct.Flip.Op where |
| 11 |
|
| 12 |
open import Algebra.Core |
| 13 |
open import Algebra.Bundles |
| 14 |
import Algebra.Definitions as Def |
| 15 |
import Algebra.Structures as Str |
| 16 |
import Algebra.Consequences.Setoid as Consequences |
| 17 |
import Data.Product as Prod |
| 18 |
import Data.Sum as Sum |
| 19 |
open import Function.Base using (flip) |
| 20 |
open import Level using (Level) |
| 21 |
open import Relation.Binary.Core using (Rel; _Preserves₂_⟶_⟶_) |
| 22 |
open import Relation.Binary.Definitions using (Symmetric) |
| 23 |
|
| 24 |
private |
| 25 |
variable |
| 26 |
a ℓ : Level |
| 27 |
A : Set a |
| 28 |
≈ : Rel A ℓ |
| 29 |
ε : A |
| 30 |
⁻¹ : Op₁ A |
| 31 |
∙ : Op₂ A |
| 32 |
|
| 33 |
------------------------------------------------------------------------ |
| 34 |
-- Properties |
| 35 |
|
| 36 |
preserves₂ : (∼ ≈ ≋ : Rel A ℓ) → |
| 37 |
∙ Preserves₂ ∼ ⟶ ≈ ⟶ ≋ → (flip ∙) Preserves₂ ≈ ⟶ ∼ ⟶ ≋ |
| 38 |
preserves₂ _ _ _ pres = flip pres |
| 39 |
|
| 40 |
module ∙-Properties (≈ : Rel A ℓ) (∙ : Op₂ A) where |
| 41 |
|
| 42 |
open Def ≈ |
| 43 |
|
| 44 |
associative : Symmetric ≈ → Associative ∙ → Associative (flip ∙) |
| 45 |
associative sym assoc x y z = sym (assoc z y x) |
| 46 |
|
| 47 |
identity : Identity ε ∙ → Identity ε (flip ∙) |
| 48 |
identity id = Prod.swap id |
| 49 |
|
| 50 |
commutative : Commutative ∙ → Commutative (flip ∙) |
| 51 |
commutative comm = flip comm |
| 52 |
|
| 53 |
selective : Selective ∙ → Selective (flip ∙) |
| 54 |
selective sel x y = Sum.swap (sel y x) |
| 55 |
|
| 56 |
idempotent : Idempotent ∙ → Idempotent (flip ∙) |
| 57 |
idempotent idem = idem |
| 58 |
|
| 59 |
inverse : Inverse ε ⁻¹ ∙ → Inverse ε ⁻¹ (flip ∙) |
| 60 |
inverse inv = Prod.swap inv |
| 61 |
|
| 62 |
zero : Zero ε ∙ → Zero ε (flip ∙) |
| 63 |
zero zer = Prod.swap zer |
| 64 |
|
| 65 |
module *-Properties (≈ : Rel A ℓ) (* + : Op₂ A) where |
| 66 |
|
| 67 |
open Def ≈ |
| 68 |
|
| 69 |
distributes : * DistributesOver + → (flip *) DistributesOver + |
| 70 |
distributes distrib = Prod.swap distrib |
| 71 |
|
| 72 |
------------------------------------------------------------------------ |
| 73 |
-- Structures |
| 74 |
|
| 75 |
module _ {≈ : Rel A ℓ} {∙ : Op₂ A} where |
| 76 |
|
| 77 |
open Def ≈ |
| 78 |
open Str ≈ |
| 79 |
open ∙-Properties ≈ ∙ |
| 80 |
|
| 81 |
isMagma : IsMagma ∙ → IsMagma (flip ∙) |
| 82 |
isMagma m = record |
| 83 |
{ isEquivalence = isEquivalence |
| 84 |
; ∙-cong = preserves₂ ≈ ≈ ≈ ∙-cong |
| 85 |
} |
| 86 |
where open IsMagma m |
| 87 |
|
| 88 |
isSelectiveMagma : IsSelectiveMagma ∙ → IsSelectiveMagma (flip ∙) |
| 89 |
isSelectiveMagma m = record |
| 90 |
{ isMagma = isMagma m.isMagma |
| 91 |
; sel = selective m.sel |
| 92 |
} |
| 93 |
where module m = IsSelectiveMagma m |
| 94 |
|
| 95 |
isCommutativeMagma : IsCommutativeMagma ∙ → IsCommutativeMagma (flip ∙) |
| 96 |
isCommutativeMagma m = record |
| 97 |
{ isMagma = isMagma m.isMagma |
| 98 |
; comm = commutative m.comm |
| 99 |
} |
| 100 |
where module m = IsCommutativeMagma m |
| 101 |
|
| 102 |
isSemigroup : IsSemigroup ∙ → IsSemigroup (flip ∙) |
| 103 |
isSemigroup s = record |
| 104 |
{ isMagma = isMagma s.isMagma |
| 105 |
; assoc = associative s.sym s.assoc |
| 106 |
} |
| 107 |
where module s = IsSemigroup s |
| 108 |
|
| 109 |
isBand : IsBand ∙ → IsBand (flip ∙) |
| 110 |
isBand b = record |
| 111 |
{ isSemigroup = isSemigroup b.isSemigroup |
| 112 |
; idem = b.idem |
| 113 |
} |
| 114 |
where module b = IsBand b |
| 115 |
|
| 116 |
isCommutativeSemigroup : IsCommutativeSemigroup ∙ → |
| 117 |
IsCommutativeSemigroup (flip ∙) |
| 118 |
isCommutativeSemigroup s = record |
| 119 |
{ isSemigroup = isSemigroup s.isSemigroup |
| 120 |
; comm = commutative s.comm |
| 121 |
} |
| 122 |
where module s = IsCommutativeSemigroup s |
| 123 |
|
| 124 |
isUnitalMagma : IsUnitalMagma ∙ ε → IsUnitalMagma (flip ∙) ε |
| 125 |
isUnitalMagma m = record |
| 126 |
{ isMagma = isMagma m.isMagma |
| 127 |
; identity = identity m.identity |
| 128 |
} |
| 129 |
where module m = IsUnitalMagma m |
| 130 |
|
| 131 |
isMonoid : IsMonoid ∙ ε → IsMonoid (flip ∙) ε |
| 132 |
isMonoid m = record |
| 133 |
{ isSemigroup = isSemigroup m.isSemigroup |
| 134 |
; identity = identity m.identity |
| 135 |
} |
| 136 |
where module m = IsMonoid m |
| 137 |
|
| 138 |
isCommutativeMonoid : IsCommutativeMonoid ∙ ε → |
| 139 |
IsCommutativeMonoid (flip ∙) ε |
| 140 |
isCommutativeMonoid m = record |
| 141 |
{ isMonoid = isMonoid m.isMonoid |
| 142 |
; comm = commutative m.comm |
| 143 |
} |
| 144 |
where module m = IsCommutativeMonoid m |
| 145 |
|
| 146 |
isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid ∙ ε → |
| 147 |
IsIdempotentCommutativeMonoid (flip ∙) ε |
| 148 |
isIdempotentCommutativeMonoid m = record |
| 149 |
{ isCommutativeMonoid = isCommutativeMonoid m.isCommutativeMonoid |
| 150 |
; idem = idempotent m.idem |
| 151 |
} |
| 152 |
where module m = IsIdempotentCommutativeMonoid m |
| 153 |
|
| 154 |
isInvertibleMagma : IsInvertibleMagma ∙ ε ⁻¹ → |
| 155 |
IsInvertibleMagma (flip ∙) ε ⁻¹ |
| 156 |
isInvertibleMagma m = record |
| 157 |
{ isMagma = isMagma m.isMagma |
| 158 |
; inverse = inverse m.inverse |
| 159 |
; ⁻¹-cong = m.⁻¹-cong |
| 160 |
} |
| 161 |
where module m = IsInvertibleMagma m |
| 162 |
|
| 163 |
isInvertibleUnitalMagma : IsInvertibleUnitalMagma ∙ ε ⁻¹ → |
| 164 |
IsInvertibleUnitalMagma (flip ∙) ε ⁻¹ |
| 165 |
isInvertibleUnitalMagma m = record |
| 166 |
{ isInvertibleMagma = isInvertibleMagma m.isInvertibleMagma |
| 167 |
; identity = identity m.identity |
| 168 |
} |
| 169 |
where module m = IsInvertibleUnitalMagma m |
| 170 |
|
| 171 |
isGroup : IsGroup ∙ ε ⁻¹ → IsGroup (flip ∙) ε ⁻¹ |
| 172 |
isGroup g = record |
| 173 |
{ isMonoid = isMonoid g.isMonoid |
| 174 |
; inverse = inverse g.inverse |
| 175 |
; ⁻¹-cong = g.⁻¹-cong |
| 176 |
} |
| 177 |
where module g = IsGroup g |
| 178 |
|
| 179 |
isAbelianGroup : IsAbelianGroup ∙ ε ⁻¹ → IsAbelianGroup (flip ∙) ε ⁻¹ |
| 180 |
isAbelianGroup g = record |
| 181 |
{ isGroup = isGroup g.isGroup |
| 182 |
; comm = commutative g.comm |
| 183 |
} |
| 184 |
where module g = IsAbelianGroup g |
| 185 |
|
| 186 |
module _ {≈ : Rel A ℓ} {+ * : Op₂ A} {0# 1# : A} where |
| 187 |
|
| 188 |
open Str ≈ |
| 189 |
open ∙-Properties ≈ * |
| 190 |
open *-Properties ≈ * + |
| 191 |
|
| 192 |
isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero + * 0# 1# → |
| 193 |
IsSemiringWithoutAnnihilatingZero + (flip *) 0# 1# |
| 194 |
isSemiringWithoutAnnihilatingZero r = record |
| 195 |
{ +-isCommutativeMonoid = r.+-isCommutativeMonoid |
| 196 |
; *-cong = preserves₂ ≈ ≈ ≈ r.*-cong |
| 197 |
; *-assoc = associative r.sym r.*-assoc |
| 198 |
; *-identity = identity r.*-identity |
| 199 |
; distrib = distributes r.distrib |
| 200 |
} |
| 201 |
where module r = IsSemiringWithoutAnnihilatingZero r |
| 202 |
|
| 203 |
isSemiring : IsSemiring + * 0# 1# → IsSemiring + (flip *) 0# 1# |
| 204 |
isSemiring r = record |
| 205 |
{ isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero r.isSemiringWithoutAnnihilatingZero |
| 206 |
; zero = zero r.zero |
| 207 |
} |
| 208 |
where module r = IsSemiring r |
| 209 |
|
| 210 |
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1# → |
| 211 |
IsCommutativeSemiring + (flip *) 0# 1# |
| 212 |
isCommutativeSemiring r = record |
| 213 |
{ isSemiring = isSemiring r.isSemiring |
| 214 |
; *-comm = commutative r.*-comm |
| 215 |
} |
| 216 |
where module r = IsCommutativeSemiring r |
| 217 |
|
| 218 |
isCancellativeCommutativeSemiring : IsCancellativeCommutativeSemiring + * 0# 1# → |
| 219 |
IsCancellativeCommutativeSemiring + (flip *) 0# 1# |
| 220 |
isCancellativeCommutativeSemiring r = record |
| 221 |
{ isCommutativeSemiring = isCommutativeSemiring r.isCommutativeSemiring |
| 222 |
; *-cancelˡ-nonZero = Consequences.comm∧almostCancelˡ⇒almostCancelʳ r.setoid r.*-comm r.*-cancelˡ-nonZero |
| 223 |
} |
| 224 |
where module r = IsCancellativeCommutativeSemiring r |
| 225 |
|
| 226 |
isIdempotentSemiring : IsIdempotentSemiring + * 0# 1# → |
| 227 |
IsIdempotentSemiring + (flip *) 0# 1# |
| 228 |
isIdempotentSemiring r = record |
| 229 |
{ isSemiring = isSemiring r.isSemiring |
| 230 |
; +-idem = r.+-idem |
| 231 |
} |
| 232 |
where module r = IsIdempotentSemiring r |
| 233 |
|
| 234 |
isQuasiring : IsQuasiring + * 0# 1# → IsQuasiring + (flip *) 0# 1# |
| 235 |
isQuasiring r = record |
| 236 |
{ +-isMonoid = r.+-isMonoid |
| 237 |
; *-cong = preserves₂ ≈ ≈ ≈ r.*-cong |
| 238 |
; *-assoc = associative r.sym r.*-assoc |
| 239 |
; *-identity = identity r.*-identity |
| 240 |
; distrib = distributes r.distrib |
| 241 |
; zero = zero r.zero |
| 242 |
} |
| 243 |
where module r = IsQuasiring r |
| 244 |
|
| 245 |
module _ {≈ : Rel A ℓ} {+ * : Op₂ A} { - : Op₁ A} {0# : A} where |
| 246 |
|
| 247 |
open Str ≈ |
| 248 |
open ∙-Properties ≈ * |
| 249 |
open *-Properties ≈ * + |
| 250 |
|
| 251 |
isRingWithoutOne : IsRingWithoutOne + * - 0# → IsRingWithoutOne + (flip *) - 0# |
| 252 |
isRingWithoutOne r = record |
| 253 |
{ +-isAbelianGroup = r.+-isAbelianGroup |
| 254 |
; *-cong = preserves₂ ≈ ≈ ≈ r.*-cong |
| 255 |
; *-assoc = associative r.sym r.*-assoc |
| 256 |
; distrib = distributes r.distrib |
| 257 |
} |
| 258 |
where module r = IsRingWithoutOne r |
| 259 |
|
| 260 |
module _ {≈ : Rel A ℓ} {+ * : Op₂ A} { - : Op₁ A} {0# 1# : A} where |
| 261 |
|
| 262 |
open Str ≈ |
| 263 |
open ∙-Properties ≈ * |
| 264 |
open *-Properties ≈ * + |
| 265 |
|
| 266 |
isNonAssociativeRing : IsNonAssociativeRing + * - 0# 1# → |
| 267 |
IsNonAssociativeRing + (flip *) - 0# 1# |
| 268 |
isNonAssociativeRing r = record |
| 269 |
{ +-isAbelianGroup = r.+-isAbelianGroup |
| 270 |
; *-cong = preserves₂ ≈ ≈ ≈ r.*-cong |
| 271 |
; *-identity = identity r.*-identity |
| 272 |
; distrib = distributes r.distrib |
| 273 |
; zero = zero r.zero |
| 274 |
} |
| 275 |
where module r = IsNonAssociativeRing r |
| 276 |
|
| 277 |
isNearring : IsNearring + * 0# 1# - → IsNearring + (flip *) 0# 1# - |
| 278 |
isNearring r = record |
| 279 |
{ isQuasiring = isQuasiring r.isQuasiring |
| 280 |
; +-inverse = r.+-inverse |
| 281 |
; ⁻¹-cong = r.⁻¹-cong |
| 282 |
} |
| 283 |
where module r = IsNearring r |
| 284 |
|
| 285 |
isRing : IsRing + * - 0# 1# → IsRing + (flip *) - 0# 1# |
| 286 |
isRing r = record |
| 287 |
{ +-isAbelianGroup = r.+-isAbelianGroup |
| 288 |
; *-cong = preserves₂ ≈ ≈ ≈ r.*-cong |
| 289 |
; *-assoc = associative r.sym r.*-assoc |
| 290 |
; *-identity = identity r.*-identity |
| 291 |
; distrib = distributes r.distrib |
| 292 |
} |
| 293 |
where module r = IsRing r |
| 294 |
|
| 295 |
isCommutativeRing : IsCommutativeRing + * - 0# 1# → |
| 296 |
IsCommutativeRing + (flip *) - 0# 1# |
| 297 |
isCommutativeRing r = record |
| 298 |
{ isRing = isRing r.isRing |
| 299 |
; *-comm = commutative r.*-comm |
| 300 |
} |
| 301 |
where module r = IsCommutativeRing r |
| 302 |
|
| 303 |
|
| 304 |
------------------------------------------------------------------------ |
| 305 |
-- Bundles |
| 306 |
|
| 307 |
magma : Magma a ℓ → Magma a ℓ |
| 308 |
magma m = record { isMagma = isMagma m.isMagma } |
| 309 |
where module m = Magma m |
| 310 |
|
| 311 |
commutativeMagma : CommutativeMagma a ℓ → CommutativeMagma a ℓ |
| 312 |
commutativeMagma m = record |
| 313 |
{ isCommutativeMagma = isCommutativeMagma m.isCommutativeMagma |
| 314 |
} |
| 315 |
where module m = CommutativeMagma m |
| 316 |
|
| 317 |
selectiveMagma : SelectiveMagma a ℓ → SelectiveMagma a ℓ |
| 318 |
selectiveMagma m = record |
| 319 |
{ isSelectiveMagma = isSelectiveMagma m.isSelectiveMagma |
| 320 |
} |
| 321 |
where module m = SelectiveMagma m |
| 322 |
|
| 323 |
semigroup : Semigroup a ℓ → Semigroup a ℓ |
| 324 |
semigroup s = record { isSemigroup = isSemigroup s.isSemigroup } |
| 325 |
where module s = Semigroup s |
| 326 |
|
| 327 |
band : Band a ℓ → Band a ℓ |
| 328 |
band b = record { isBand = isBand b.isBand } |
| 329 |
where module b = Band b |
| 330 |
|
| 331 |
commutativeSemigroup : CommutativeSemigroup a ℓ → CommutativeSemigroup a ℓ |
| 332 |
commutativeSemigroup s = record |
| 333 |
{ isCommutativeSemigroup = isCommutativeSemigroup s.isCommutativeSemigroup |
| 334 |
} |
| 335 |
where module s = CommutativeSemigroup s |
| 336 |
|
| 337 |
unitalMagma : UnitalMagma a ℓ → UnitalMagma a ℓ |
| 338 |
unitalMagma m = record |
| 339 |
{ isUnitalMagma = isUnitalMagma m.isUnitalMagma |
| 340 |
} |
| 341 |
where module m = UnitalMagma m |
| 342 |
|
| 343 |
monoid : Monoid a ℓ → Monoid a ℓ |
| 344 |
monoid m = record { isMonoid = isMonoid m.isMonoid } |
| 345 |
where module m = Monoid m |
| 346 |
|
| 347 |
commutativeMonoid : CommutativeMonoid a ℓ → CommutativeMonoid a ℓ |
| 348 |
commutativeMonoid m = record |
| 349 |
{ isCommutativeMonoid = isCommutativeMonoid m.isCommutativeMonoid |
| 350 |
} |
| 351 |
where module m = CommutativeMonoid m |
| 352 |
|
| 353 |
idempotentCommutativeMonoid : IdempotentCommutativeMonoid a ℓ → |
| 354 |
IdempotentCommutativeMonoid a ℓ |
| 355 |
idempotentCommutativeMonoid m = record |
| 356 |
{ isIdempotentCommutativeMonoid = |
| 357 |
isIdempotentCommutativeMonoid m.isIdempotentCommutativeMonoid |
| 358 |
} |
| 359 |
where module m = IdempotentCommutativeMonoid m |
| 360 |
|
| 361 |
invertibleMagma : InvertibleMagma a ℓ → InvertibleMagma a ℓ |
| 362 |
invertibleMagma m = record |
| 363 |
{ isInvertibleMagma = isInvertibleMagma m.isInvertibleMagma |
| 364 |
} |
| 365 |
where module m = InvertibleMagma m |
| 366 |
|
| 367 |
invertibleUnitalMagma : InvertibleUnitalMagma a ℓ → InvertibleUnitalMagma a ℓ |
| 368 |
invertibleUnitalMagma m = record |
| 369 |
{ isInvertibleUnitalMagma = isInvertibleUnitalMagma m.isInvertibleUnitalMagma |
| 370 |
} |
| 371 |
where module m = InvertibleUnitalMagma m |
| 372 |
|
| 373 |
group : Group a ℓ → Group a ℓ |
| 374 |
group g = record { isGroup = isGroup g.isGroup } |
| 375 |
where module g = Group g |
| 376 |
|
| 377 |
abelianGroup : AbelianGroup a ℓ → AbelianGroup a ℓ |
| 378 |
abelianGroup g = record { isAbelianGroup = isAbelianGroup g.isAbelianGroup } |
| 379 |
where module g = AbelianGroup g |
| 380 |
|
| 381 |
semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero a ℓ → |
| 382 |
SemiringWithoutAnnihilatingZero a ℓ |
| 383 |
semiringWithoutAnnihilatingZero r = record |
| 384 |
{ isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero r.isSemiringWithoutAnnihilatingZero } |
| 385 |
where module r = SemiringWithoutAnnihilatingZero r |
| 386 |
|
| 387 |
semiring : Semiring a ℓ → Semiring a ℓ |
| 388 |
semiring r = record { isSemiring = isSemiring r.isSemiring } |
| 389 |
where module r = Semiring r |
| 390 |
|
| 391 |
commutativeSemiring : CommutativeSemiring a ℓ → CommutativeSemiring a ℓ |
| 392 |
commutativeSemiring r = record |
| 393 |
{ isCommutativeSemiring = isCommutativeSemiring r.isCommutativeSemiring } |
| 394 |
where module r = CommutativeSemiring r |
| 395 |
|
| 396 |
cancellativeCommutativeSemiring : CancellativeCommutativeSemiring a ℓ → |
| 397 |
CancellativeCommutativeSemiring a ℓ |
| 398 |
cancellativeCommutativeSemiring r = record |
| 399 |
{ isCancellativeCommutativeSemiring = isCancellativeCommutativeSemiring r.isCancellativeCommutativeSemiring } |
| 400 |
where module r = CancellativeCommutativeSemiring r |
| 401 |
|
| 402 |
idempotentSemiring : IdempotentSemiring a ℓ → IdempotentSemiring a ℓ |
| 403 |
idempotentSemiring r = record |
| 404 |
{ isIdempotentSemiring = isIdempotentSemiring r.isIdempotentSemiring } |
| 405 |
where module r = IdempotentSemiring r |
| 406 |
|
| 407 |
quasiring : Quasiring a ℓ → Quasiring a ℓ |
| 408 |
quasiring r = record { isQuasiring = isQuasiring r.isQuasiring } |
| 409 |
where module r = Quasiring r |
| 410 |
|
| 411 |
ringWithoutOne : RingWithoutOne a ℓ → RingWithoutOne a ℓ |
| 412 |
ringWithoutOne r = record { isRingWithoutOne = isRingWithoutOne r.isRingWithoutOne } |
| 413 |
where module r = RingWithoutOne r |
| 414 |
|
| 415 |
nonAssociativeRing : NonAssociativeRing a ℓ → NonAssociativeRing a ℓ |
| 416 |
nonAssociativeRing r = record |
| 417 |
{ isNonAssociativeRing = isNonAssociativeRing r.isNonAssociativeRing } |
| 418 |
where module r = NonAssociativeRing r |
| 419 |
|
| 420 |
nearring : Nearring a ℓ → Nearring a ℓ |
| 421 |
nearring r = record { isNearring = isNearring r.isNearring } |
| 422 |
where module r = Nearring r |
| 423 |
|
| 424 |
ring : Ring a ℓ → Ring a ℓ |
| 425 |
ring r = record { isRing = isRing r.isRing } |
| 426 |
where module r = Ring r |
| 427 |
|
| 428 |
commutativeRing : CommutativeRing a ℓ → CommutativeRing a ℓ |
| 429 |
commutativeRing r = record { isCommutativeRing = isCommutativeRing r.isCommutativeRing } |
| 430 |
where module r = CommutativeRing r |