| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Properties of functions, such as associativity and commutativity |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- The contents of this module should be accessed via `Algebra`, unless |
| 8 |
-- you want to parameterise it via the equality relation. |
| 9 |
|
| 10 |
-- Note that very few of the element arguments are made implicit here, |
| 11 |
-- as we do not assume that the Agda can infer either the right or left |
| 12 |
-- argument of the binary operators. This is despite the fact that the |
| 13 |
-- library defines most of its concrete operators (e.g. in |
| 14 |
-- `Data.Nat.Base`) as being left-biased. |
| 15 |
|
| 16 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 17 |
|
| 18 |
open import Relation.Binary.Core using (Rel) |
| 19 |
|
| 20 |
module Algebra.Definitions |
| 21 |
{a ℓ} {A : Set a} -- The underlying set |
| 22 |
(_≈_ : Rel A ℓ) -- The underlying equality |
| 23 |
where |
| 24 |
|
| 25 |
open import Algebra.Core using (Op₁; Op₂) |
| 26 |
open import Data.Product.Base using (_×_; ∃-syntax) |
| 27 |
open import Data.Sum.Base using (_⊎_) |
| 28 |
open import Relation.Binary.Definitions using (Monotonic₁; Monotonic₂) |
| 29 |
open import Relation.Nullary.Negation.Core using (¬_) |
| 30 |
|
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- Properties of operations |
| 34 |
|
| 35 |
Congruent₁ : Op₁ A → Set _ |
| 36 |
Congruent₁ = Monotonic₁ _≈_ _≈_ |
| 37 |
|
| 38 |
Congruent₂ : Op₂ A → Set _ |
| 39 |
Congruent₂ = Monotonic₂ _≈_ _≈_ _≈_ |
| 40 |
|
| 41 |
LeftCongruent : Op₂ A → Set _ |
| 42 |
LeftCongruent _∙_ = ∀ {x} → Congruent₁ (x ∙_) |
| 43 |
|
| 44 |
RightCongruent : Op₂ A → Set _ |
| 45 |
RightCongruent _∙_ = ∀ {x} → Congruent₁ (_∙ x) |
| 46 |
|
| 47 |
Associative : Op₂ A → Set _ |
| 48 |
Associative _∙_ = ∀ x y z → ((x ∙ y) ∙ z) ≈ (x ∙ (y ∙ z)) |
| 49 |
|
| 50 |
Commutative : Op₂ A → Set _ |
| 51 |
Commutative _∙_ = ∀ x y → (x ∙ y) ≈ (y ∙ x) |
| 52 |
|
| 53 |
LeftIdentity : A → Op₂ A → Set _ |
| 54 |
LeftIdentity e _∙_ = ∀ x → (e ∙ x) ≈ x |
| 55 |
|
| 56 |
RightIdentity : A → Op₂ A → Set _ |
| 57 |
RightIdentity e _∙_ = ∀ x → (x ∙ e) ≈ x |
| 58 |
|
| 59 |
Identity : A → Op₂ A → Set _ |
| 60 |
Identity e ∙ = (LeftIdentity e ∙) × (RightIdentity e ∙) |
| 61 |
|
| 62 |
LeftZero : A → Op₂ A → Set _ |
| 63 |
LeftZero z _∙_ = ∀ x → (z ∙ x) ≈ z |
| 64 |
|
| 65 |
RightZero : A → Op₂ A → Set _ |
| 66 |
RightZero z _∙_ = ∀ x → (x ∙ z) ≈ z |
| 67 |
|
| 68 |
Zero : A → Op₂ A → Set _ |
| 69 |
Zero z ∙ = (LeftZero z ∙) × (RightZero z ∙) |
| 70 |
|
| 71 |
LeftInverse : A → Op₁ A → Op₂ A → Set _ |
| 72 |
LeftInverse e _⁻¹ _∙_ = ∀ x → ((x ⁻¹) ∙ x) ≈ e |
| 73 |
|
| 74 |
RightInverse : A → Op₁ A → Op₂ A → Set _ |
| 75 |
RightInverse e _⁻¹ _∙_ = ∀ x → (x ∙ (x ⁻¹)) ≈ e |
| 76 |
|
| 77 |
Inverse : A → Op₁ A → Op₂ A → Set _ |
| 78 |
Inverse e ⁻¹ ∙ = (LeftInverse e ⁻¹) ∙ × (RightInverse e ⁻¹ ∙) |
| 79 |
|
| 80 |
-- For structures in which not every element has an inverse (e.g. Fields) |
| 81 |
LeftInvertible : A → Op₂ A → A → Set _ |
| 82 |
LeftInvertible e _∙_ x = ∃[ x⁻¹ ] (x⁻¹ ∙ x) ≈ e |
| 83 |
|
| 84 |
RightInvertible : A → Op₂ A → A → Set _ |
| 85 |
RightInvertible e _∙_ x = ∃[ x⁻¹ ] (x ∙ x⁻¹) ≈ e |
| 86 |
|
| 87 |
-- NB: this is not quite the same as |
| 88 |
-- LeftInvertible e ∙ x × RightInvertible e ∙ x |
| 89 |
-- since the left and right inverses have to coincide. |
| 90 |
Invertible : A → Op₂ A → A → Set _ |
| 91 |
Invertible e _∙_ x = ∃[ x⁻¹ ] (x⁻¹ ∙ x) ≈ e × (x ∙ x⁻¹) ≈ e |
| 92 |
|
| 93 |
LeftConical : A → Op₂ A → Set _ |
| 94 |
LeftConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → x ≈ e |
| 95 |
|
| 96 |
RightConical : A → Op₂ A → Set _ |
| 97 |
RightConical e _∙_ = ∀ x y → (x ∙ y) ≈ e → y ≈ e |
| 98 |
|
| 99 |
Conical : A → Op₂ A → Set _ |
| 100 |
Conical e ∙ = (LeftConical e ∙) × (RightConical e ∙) |
| 101 |
|
| 102 |
infix 4 _DistributesOverˡ_ _DistributesOverʳ_ _DistributesOver_ |
| 103 |
|
| 104 |
_DistributesOverˡ_ : Op₂ A → Op₂ A → Set _ |
| 105 |
_*_ DistributesOverˡ _+_ = |
| 106 |
∀ x y z → (x * (y + z)) ≈ ((x * y) + (x * z)) |
| 107 |
|
| 108 |
_DistributesOverʳ_ : Op₂ A → Op₂ A → Set _ |
| 109 |
_*_ DistributesOverʳ _+_ = |
| 110 |
∀ x y z → ((y + z) * x) ≈ ((y * x) + (z * x)) |
| 111 |
|
| 112 |
_DistributesOver_ : Op₂ A → Op₂ A → Set _ |
| 113 |
* DistributesOver + = (* DistributesOverˡ +) × (* DistributesOverʳ +) |
| 114 |
|
| 115 |
infix 4 _MiddleFourExchange_ _IdempotentOn_ _Absorbs_ |
| 116 |
|
| 117 |
_MiddleFourExchange_ : Op₂ A → Op₂ A → Set _ |
| 118 |
_*_ MiddleFourExchange _+_ = |
| 119 |
∀ w x y z → ((w + x) * (y + z)) ≈ ((w + y) * (x + z)) |
| 120 |
|
| 121 |
_IdempotentOn_ : Op₂ A → A → Set _ |
| 122 |
_∙_ IdempotentOn x = (x ∙ x) ≈ x |
| 123 |
|
| 124 |
Idempotent : Op₂ A → Set _ |
| 125 |
Idempotent ∙ = ∀ x → ∙ IdempotentOn x |
| 126 |
|
| 127 |
IdempotentFun : Op₁ A → Set _ |
| 128 |
IdempotentFun f = ∀ x → f (f x) ≈ f x |
| 129 |
|
| 130 |
Selective : Op₂ A → Set _ |
| 131 |
Selective _∙_ = ∀ x y → (x ∙ y) ≈ x ⊎ (x ∙ y) ≈ y |
| 132 |
|
| 133 |
_Absorbs_ : Op₂ A → Op₂ A → Set _ |
| 134 |
_∙_ Absorbs _∘_ = ∀ x y → (x ∙ (x ∘ y)) ≈ x |
| 135 |
|
| 136 |
Absorptive : Op₂ A → Op₂ A → Set _ |
| 137 |
Absorptive ∙ ∘ = (∙ Absorbs ∘) × (∘ Absorbs ∙) |
| 138 |
|
| 139 |
SelfInverse : Op₁ A → Set _ |
| 140 |
SelfInverse f = ∀ {x y} → f x ≈ y → f y ≈ x |
| 141 |
|
| 142 |
Involutive : Op₁ A → Set _ |
| 143 |
Involutive f = ∀ x → f (f x) ≈ x |
| 144 |
|
| 145 |
LeftCancellative : Op₂ A → Set _ |
| 146 |
LeftCancellative _•_ = ∀ x y z → (x • y) ≈ (x • z) → y ≈ z |
| 147 |
|
| 148 |
RightCancellative : Op₂ A → Set _ |
| 149 |
RightCancellative _•_ = ∀ x y z → (y • x) ≈ (z • x) → y ≈ z |
| 150 |
|
| 151 |
Cancellative : Op₂ A → Set _ |
| 152 |
Cancellative _•_ = (LeftCancellative _•_) × (RightCancellative _•_) |
| 153 |
|
| 154 |
AlmostLeftCancellative : A → Op₂ A → Set _ |
| 155 |
AlmostLeftCancellative e _•_ = ∀ x y z → ¬ x ≈ e → (x • y) ≈ (x • z) → y ≈ z |
| 156 |
|
| 157 |
AlmostRightCancellative : A → Op₂ A → Set _ |
| 158 |
AlmostRightCancellative e _•_ = ∀ x y z → ¬ x ≈ e → (y • x) ≈ (z • x) → y ≈ z |
| 159 |
|
| 160 |
AlmostCancellative : A → Op₂ A → Set _ |
| 161 |
AlmostCancellative e _•_ = AlmostLeftCancellative e _•_ × AlmostRightCancellative e _•_ |
| 162 |
|
| 163 |
Interchangable : Op₂ A → Op₂ A → Set _ |
| 164 |
Interchangable _∘_ _∙_ = ∀ w x y z → ((w ∙ x) ∘ (y ∙ z)) ≈ ((w ∘ y) ∙ (x ∘ z)) |
| 165 |
|
| 166 |
LeftDividesˡ : Op₂ A → Op₂ A → Set _ |
| 167 |
LeftDividesˡ _∙_ _\\_ = ∀ x y → (x ∙ (x \\ y)) ≈ y |
| 168 |
|
| 169 |
LeftDividesʳ : Op₂ A → Op₂ A → Set _ |
| 170 |
LeftDividesʳ _∙_ _\\_ = ∀ x y → (x \\ (x ∙ y)) ≈ y |
| 171 |
|
| 172 |
RightDividesˡ : Op₂ A → Op₂ A → Set _ |
| 173 |
RightDividesˡ _∙_ _//_ = ∀ x y → ((y // x) ∙ x) ≈ y |
| 174 |
|
| 175 |
RightDividesʳ : Op₂ A → Op₂ A → Set _ |
| 176 |
RightDividesʳ _∙_ _//_ = ∀ x y → ((y ∙ x) // x) ≈ y |
| 177 |
|
| 178 |
LeftDivides : Op₂ A → Op₂ A → Set _ |
| 179 |
LeftDivides ∙ \\ = (LeftDividesˡ ∙ \\) × (LeftDividesʳ ∙ \\) |
| 180 |
|
| 181 |
RightDivides : Op₂ A → Op₂ A → Set _ |
| 182 |
RightDivides ∙ // = (RightDividesˡ ∙ //) × (RightDividesʳ ∙ //) |
| 183 |
|
| 184 |
StarRightExpansive : A → Op₂ A → Op₂ A → Op₁ A → Set _ |
| 185 |
StarRightExpansive e _+_ _∙_ _* = ∀ x → (e + (x ∙ (x *))) ≈ (x *) |
| 186 |
|
| 187 |
StarLeftExpansive : A → Op₂ A → Op₂ A → Op₁ A → Set _ |
| 188 |
StarLeftExpansive e _+_ _∙_ _* = ∀ x → (e + ((x *) ∙ x)) ≈ (x *) |
| 189 |
|
| 190 |
StarExpansive : A → Op₂ A → Op₂ A → Op₁ A → Set _ |
| 191 |
StarExpansive e _+_ _∙_ _* = (StarLeftExpansive e _+_ _∙_ _*) × (StarRightExpansive e _+_ _∙_ _*) |
| 192 |
|
| 193 |
StarLeftDestructive : Op₂ A → Op₂ A → Op₁ A → Set _ |
| 194 |
StarLeftDestructive _+_ _∙_ _* = ∀ a b x → (b + (a ∙ x)) ≈ x → ((a *) ∙ b) ≈ x |
| 195 |
|
| 196 |
StarRightDestructive : Op₂ A → Op₂ A → Op₁ A → Set _ |
| 197 |
StarRightDestructive _+_ _∙_ _* = ∀ a b x → (b + (x ∙ a)) ≈ x → (b ∙ (a *)) ≈ x |
| 198 |
|
| 199 |
StarDestructive : Op₂ A → Op₂ A → Op₁ A → Set _ |
| 200 |
StarDestructive _+_ _∙_ _* = (StarLeftDestructive _+_ _∙_ _*) × (StarRightDestructive _+_ _∙_ _*) |
| 201 |
|
| 202 |
LeftAlternative : Op₂ A → Set _ |
| 203 |
LeftAlternative _∙_ = ∀ x y → ((x ∙ x) ∙ y) ≈ (x ∙ (x ∙ y)) |
| 204 |
|
| 205 |
RightAlternative : Op₂ A → Set _ |
| 206 |
RightAlternative _∙_ = ∀ x y → (x ∙ (y ∙ y)) ≈ ((x ∙ y) ∙ y) |
| 207 |
|
| 208 |
Alternative : Op₂ A → Set _ |
| 209 |
Alternative _∙_ = (LeftAlternative _∙_ ) × (RightAlternative _∙_) |
| 210 |
|
| 211 |
Flexible : Op₂ A → Set _ |
| 212 |
Flexible _∙_ = ∀ x y → ((x ∙ y) ∙ x) ≈ (x ∙ (y ∙ x)) |
| 213 |
|
| 214 |
Medial : Op₂ A → Set _ |
| 215 |
Medial _∙_ = ∀ x y u z → ((x ∙ y) ∙ (u ∙ z)) ≈ ((x ∙ u) ∙ (y ∙ z)) |
| 216 |
|
| 217 |
LeftSemimedial : Op₂ A → Set _ |
| 218 |
LeftSemimedial _∙_ = ∀ x y z → ((x ∙ x) ∙ (y ∙ z)) ≈ ((x ∙ y) ∙ (x ∙ z)) |
| 219 |
|
| 220 |
RightSemimedial : Op₂ A → Set _ |
| 221 |
RightSemimedial _∙_ = ∀ x y z → ((y ∙ z) ∙ (x ∙ x)) ≈ ((y ∙ x) ∙ (z ∙ x)) |
| 222 |
|
| 223 |
Semimedial : Op₂ A → Set _ |
| 224 |
Semimedial _∙_ = (LeftSemimedial _∙_) × (RightSemimedial _∙_) |
| 225 |
|
| 226 |
LeftBol : Op₂ A → Set _ |
| 227 |
LeftBol _∙_ = ∀ x y z → (x ∙ (y ∙ (x ∙ z))) ≈ ((x ∙ (y ∙ x)) ∙ z ) |
| 228 |
|
| 229 |
RightBol : Op₂ A → Set _ |
| 230 |
RightBol _∙_ = ∀ x y z → (((z ∙ x) ∙ y) ∙ x) ≈ (z ∙ ((x ∙ y) ∙ x)) |
| 231 |
|
| 232 |
MiddleBol : Op₂ A → Op₂ A → Op₂ A → Set _ |
| 233 |
MiddleBol _∙_ _\\_ _//_ = ∀ x y z → (x ∙ ((y ∙ z) \\ x)) ≈ ((x // z) ∙ (y \\ x)) |
| 234 |
|
| 235 |
Identical : Op₂ A → Set _ |
| 236 |
Identical _∙_ = ∀ x y z → ((z ∙ x) ∙ (y ∙ z)) ≈ (z ∙ ((x ∙ y) ∙ z)) |