| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some properties about signs |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Sign.Properties where |
| 10 |
|
| 11 |
open import Algebra.Bundles |
| 12 |
using (Magma; Semigroup; CommutativeSemigroup; Monoid; CommutativeMonoid |
| 13 |
; Group; AbelianGroup) |
| 14 |
open import Data.Sign.Base using (Sign; opposite; _*_; +; -) |
| 15 |
open import Data.Product.Base using (_,_) |
| 16 |
open import Function.Base using (_$_; id) |
| 17 |
open import Function.Definitions using (Injective) |
| 18 |
open import Level using (0ℓ) |
| 19 |
open import Relation.Binary.Definitions using (Decidable; DecidableEquality) |
| 20 |
open import Relation.Binary.Structures using (IsDecEquivalence) |
| 21 |
open import Relation.Binary.Bundles using (Setoid; DecSetoid) |
| 22 |
open import Relation.Binary.PropositionalEquality.Core |
| 23 |
using (_≡_; refl; _≢_; sym; cong₂) |
| 24 |
open import Relation.Binary.PropositionalEquality.Properties |
| 25 |
using (setoid; decSetoid; isDecEquivalence; isEquivalence) |
| 26 |
open import Relation.Nullary.Decidable using (yes; no) |
| 27 |
open import Relation.Nullary.Negation.Core using (contradiction) |
| 28 |
|
| 29 |
open import Algebra.Structures {A = Sign} _≡_ |
| 30 |
open import Algebra.Definitions {A = Sign} _≡_ |
| 31 |
open import Algebra.Consequences.Propositional |
| 32 |
using (selfInverse⇒involutive; selfInverse⇒injective) |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- Equality |
| 36 |
|
| 37 |
infix 4 _≟_ |
| 38 |
|
| 39 |
_≟_ : DecidableEquality Sign |
| 40 |
- ≟ - = yes refl |
| 41 |
- ≟ + = no λ() |
| 42 |
+ ≟ - = no λ() |
| 43 |
+ ≟ + = yes refl |
| 44 |
|
| 45 |
≡-setoid : Setoid 0ℓ 0ℓ |
| 46 |
≡-setoid = setoid Sign |
| 47 |
|
| 48 |
≡-decSetoid : DecSetoid 0ℓ 0ℓ |
| 49 |
≡-decSetoid = decSetoid _≟_ |
| 50 |
|
| 51 |
≡-isDecEquivalence : IsDecEquivalence _≡_ |
| 52 |
≡-isDecEquivalence = isDecEquivalence _≟_ |
| 53 |
|
| 54 |
------------------------------------------------------------------------ |
| 55 |
-- opposite |
| 56 |
|
| 57 |
-- Algebraic properties of opposite |
| 58 |
|
| 59 |
opposite-selfInverse : SelfInverse opposite |
| 60 |
opposite-selfInverse { - } { + } refl = refl |
| 61 |
opposite-selfInverse { + } { - } refl = refl |
| 62 |
|
| 63 |
opposite-involutive : Involutive opposite |
| 64 |
opposite-involutive = selfInverse⇒involutive opposite-selfInverse |
| 65 |
|
| 66 |
opposite-injective : Injective _≡_ _≡_ opposite |
| 67 |
opposite-injective = selfInverse⇒injective opposite-selfInverse |
| 68 |
|
| 69 |
|
| 70 |
------------------------------------------------------------------------ |
| 71 |
-- other properties of opposite |
| 72 |
|
| 73 |
s≢opposite[s] : ∀ s → s ≢ opposite s |
| 74 |
s≢opposite[s] - () |
| 75 |
s≢opposite[s] + () |
| 76 |
|
| 77 |
------------------------------------------------------------------------ |
| 78 |
-- _*_ |
| 79 |
|
| 80 |
-- Algebraic properties of _*_ |
| 81 |
|
| 82 |
s*s≡+ : ∀ s → s * s ≡ + |
| 83 |
s*s≡+ + = refl |
| 84 |
s*s≡+ - = refl |
| 85 |
|
| 86 |
*-identityˡ : LeftIdentity + _*_ |
| 87 |
*-identityˡ _ = refl |
| 88 |
|
| 89 |
*-identityʳ : RightIdentity + _*_ |
| 90 |
*-identityʳ - = refl |
| 91 |
*-identityʳ + = refl |
| 92 |
|
| 93 |
*-identity : Identity + _*_ |
| 94 |
*-identity = *-identityˡ , *-identityʳ |
| 95 |
|
| 96 |
*-comm : Commutative _*_ |
| 97 |
*-comm + + = refl |
| 98 |
*-comm + - = refl |
| 99 |
*-comm - + = refl |
| 100 |
*-comm - - = refl |
| 101 |
|
| 102 |
*-assoc : Associative _*_ |
| 103 |
*-assoc + + _ = refl |
| 104 |
*-assoc + - _ = refl |
| 105 |
*-assoc - + _ = refl |
| 106 |
*-assoc - - + = refl |
| 107 |
*-assoc - - - = refl |
| 108 |
|
| 109 |
*-cancelʳ-≡ : RightCancellative _*_ |
| 110 |
*-cancelʳ-≡ _ - - _ = refl |
| 111 |
*-cancelʳ-≡ _ - + eq = contradiction (sym eq) (s≢opposite[s] _) |
| 112 |
*-cancelʳ-≡ _ + - eq = contradiction eq (s≢opposite[s] _) |
| 113 |
*-cancelʳ-≡ _ + + _ = refl |
| 114 |
|
| 115 |
*-cancelˡ-≡ : LeftCancellative _*_ |
| 116 |
*-cancelˡ-≡ - _ _ eq = opposite-injective eq |
| 117 |
*-cancelˡ-≡ + _ _ eq = eq |
| 118 |
|
| 119 |
*-cancel-≡ : Cancellative _*_ |
| 120 |
*-cancel-≡ = *-cancelˡ-≡ , *-cancelʳ-≡ |
| 121 |
|
| 122 |
*-inverse : Inverse + id _*_ |
| 123 |
*-inverse = s*s≡+ , s*s≡+ |
| 124 |
|
| 125 |
*-isMagma : IsMagma _*_ |
| 126 |
*-isMagma = record |
| 127 |
{ isEquivalence = isEquivalence |
| 128 |
; ∙-cong = cong₂ _*_ |
| 129 |
} |
| 130 |
|
| 131 |
*-magma : Magma 0ℓ 0ℓ |
| 132 |
*-magma = record |
| 133 |
{ isMagma = *-isMagma |
| 134 |
} |
| 135 |
|
| 136 |
*-isSemigroup : IsSemigroup _*_ |
| 137 |
*-isSemigroup = record |
| 138 |
{ isMagma = *-isMagma |
| 139 |
; assoc = *-assoc |
| 140 |
} |
| 141 |
|
| 142 |
*-semigroup : Semigroup 0ℓ 0ℓ |
| 143 |
*-semigroup = record |
| 144 |
{ isSemigroup = *-isSemigroup |
| 145 |
} |
| 146 |
|
| 147 |
*-isCommutativeSemigroup : IsCommutativeSemigroup _*_ |
| 148 |
*-isCommutativeSemigroup = record |
| 149 |
{ isSemigroup = *-isSemigroup |
| 150 |
; comm = *-comm |
| 151 |
} |
| 152 |
|
| 153 |
*-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ |
| 154 |
*-commutativeSemigroup = record |
| 155 |
{ isCommutativeSemigroup = *-isCommutativeSemigroup |
| 156 |
} |
| 157 |
|
| 158 |
*-isMonoid : IsMonoid _*_ + |
| 159 |
*-isMonoid = record |
| 160 |
{ isSemigroup = *-isSemigroup |
| 161 |
; identity = *-identity |
| 162 |
} |
| 163 |
|
| 164 |
*-monoid : Monoid 0ℓ 0ℓ |
| 165 |
*-monoid = record |
| 166 |
{ isMonoid = *-isMonoid |
| 167 |
} |
| 168 |
|
| 169 |
*-isCommutativeMonoid : IsCommutativeMonoid _*_ + |
| 170 |
*-isCommutativeMonoid = record |
| 171 |
{ isMonoid = *-isMonoid |
| 172 |
; comm = *-comm |
| 173 |
} |
| 174 |
|
| 175 |
*-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ |
| 176 |
*-commutativeMonoid = record |
| 177 |
{ isCommutativeMonoid = *-isCommutativeMonoid |
| 178 |
} |
| 179 |
|
| 180 |
*-isGroup : IsGroup _*_ + id |
| 181 |
*-isGroup = record |
| 182 |
{ isMonoid = *-isMonoid |
| 183 |
; inverse = *-inverse |
| 184 |
; ⁻¹-cong = id |
| 185 |
} |
| 186 |
|
| 187 |
*-group : Group 0ℓ 0ℓ |
| 188 |
*-group = record |
| 189 |
{ isGroup = *-isGroup |
| 190 |
} |
| 191 |
|
| 192 |
*-isAbelianGroup : IsAbelianGroup _*_ + id |
| 193 |
*-isAbelianGroup = record |
| 194 |
{ isGroup = *-isGroup |
| 195 |
; comm = *-comm |
| 196 |
} |
| 197 |
|
| 198 |
*-abelianGroup : AbelianGroup 0ℓ 0ℓ |
| 199 |
*-abelianGroup = record |
| 200 |
{ isAbelianGroup = *-isAbelianGroup |
| 201 |
} |
| 202 |
|
| 203 |
-- Other properties of _*_ |
| 204 |
|
| 205 |
s*opposite[s]≡- : ∀ s → s * opposite s ≡ - |
| 206 |
s*opposite[s]≡- + = refl |
| 207 |
s*opposite[s]≡- - = refl |
| 208 |
|
| 209 |
opposite[s]*s≡- : ∀ s → opposite s * s ≡ - |
| 210 |
opposite[s]*s≡- + = refl |
| 211 |
opposite[s]*s≡- - = refl |