| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Some properties about parities |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Parity.Properties where |
| 10 |
|
| 11 |
open import Algebra.Bundles |
| 12 |
open import Data.Nat.Base as ℕ using (zero; suc; parity) |
| 13 |
open import Data.Parity.Base as ℙ using (Parity; 0ℙ; 1ℙ; _⁻¹; toSign; fromSign) |
| 14 |
open import Data.Product.Base using (_,_) |
| 15 |
open import Data.Sign.Base as 𝕊 |
| 16 |
using (Sign; +; -; _*_; opposite; *-rawMagma; *-1-rawMonoid; *-1-rawGroup) |
| 17 |
open import Function.Base using (_$_; id) |
| 18 |
open import Function.Definitions |
| 19 |
using (Injective; Surjective; Inverseʳ; Inverseˡ) |
| 20 |
open import Function.Consequences.Propositional |
| 21 |
using (inverseʳ⇒injective; inverseˡ⇒surjective) |
| 22 |
open import Level using (0ℓ) |
| 23 |
open import Relation.Binary |
| 24 |
using (Decidable; DecidableEquality; Setoid; DecSetoid; IsDecEquivalence) |
| 25 |
open import Relation.Binary.PropositionalEquality.Core |
| 26 |
using (_≡_; _≢_; refl; sym; cong; cong₂) |
| 27 |
open import Relation.Binary.PropositionalEquality.Properties |
| 28 |
using (module ≡-Reasoning; setoid; isEquivalence; decSetoid; isDecEquivalence) |
| 29 |
open import Relation.Nullary.Decidable.Core using (yes; no) |
| 30 |
open import Relation.Nullary.Negation.Core using (contradiction) |
| 31 |
|
| 32 |
open import Algebra.Structures {A = Parity} _≡_ |
| 33 |
open import Algebra.Definitions {A = Parity} _≡_ |
| 34 |
open import Algebra.Consequences.Propositional |
| 35 |
using (selfInverse⇒involutive; selfInverse⇒injective; comm∧distrˡ⇒distrʳ) |
| 36 |
open import Algebra.Morphism.Structures |
| 37 |
|
| 38 |
------------------------------------------------------------------------ |
| 39 |
-- Equality |
| 40 |
|
| 41 |
infix 4 _≟_ |
| 42 |
|
| 43 |
_≟_ : DecidableEquality Parity |
| 44 |
1ℙ ≟ 1ℙ = yes refl |
| 45 |
1ℙ ≟ 0ℙ = no λ() |
| 46 |
0ℙ ≟ 1ℙ = no λ() |
| 47 |
0ℙ ≟ 0ℙ = yes refl |
| 48 |
|
| 49 |
≡-setoid : Setoid 0ℓ 0ℓ |
| 50 |
≡-setoid = setoid Parity |
| 51 |
|
| 52 |
≡-decSetoid : DecSetoid 0ℓ 0ℓ |
| 53 |
≡-decSetoid = decSetoid _≟_ |
| 54 |
|
| 55 |
≡-isDecEquivalence : IsDecEquivalence _≡_ |
| 56 |
≡-isDecEquivalence = isDecEquivalence _≟_ |
| 57 |
|
| 58 |
------------------------------------------------------------------------ |
| 59 |
-- _⁻¹ |
| 60 |
|
| 61 |
-- Algebraic properties of _⁻¹ |
| 62 |
|
| 63 |
⁻¹-selfInverse : SelfInverse _⁻¹ |
| 64 |
⁻¹-selfInverse { 1ℙ } { 0ℙ } refl = refl |
| 65 |
⁻¹-selfInverse { 0ℙ } { 1ℙ } refl = refl |
| 66 |
|
| 67 |
⁻¹-involutive : Involutive _⁻¹ |
| 68 |
⁻¹-involutive = selfInverse⇒involutive ⁻¹-selfInverse |
| 69 |
|
| 70 |
⁻¹-injective : Injective _≡_ _≡_ _⁻¹ |
| 71 |
⁻¹-injective = selfInverse⇒injective ⁻¹-selfInverse |
| 72 |
|
| 73 |
------------------------------------------------------------------------ |
| 74 |
-- other properties of _⁻¹ |
| 75 |
|
| 76 |
p≢p⁻¹ : ∀ p → p ≢ p ⁻¹ |
| 77 |
p≢p⁻¹ 1ℙ () |
| 78 |
p≢p⁻¹ 0ℙ () |
| 79 |
|
| 80 |
------------------------------------------------------------------------ |
| 81 |
-- ⁻¹ and _+_ |
| 82 |
|
| 83 |
p+p⁻¹≡1ℙ : ∀ p → p ℙ.+ p ⁻¹ ≡ 1ℙ |
| 84 |
p+p⁻¹≡1ℙ 0ℙ = refl |
| 85 |
p+p⁻¹≡1ℙ 1ℙ = refl |
| 86 |
|
| 87 |
p⁻¹+p≡1ℙ : ∀ p → p ⁻¹ ℙ.+ p ≡ 1ℙ |
| 88 |
p⁻¹+p≡1ℙ 0ℙ = refl |
| 89 |
p⁻¹+p≡1ℙ 1ℙ = refl |
| 90 |
|
| 91 |
------------------------------------------------------------------------ |
| 92 |
-- ⁻¹ and _*_ |
| 93 |
|
| 94 |
p*p⁻¹≡0ℙ : ∀ p → p ℙ.* p ⁻¹ ≡ 0ℙ |
| 95 |
p*p⁻¹≡0ℙ 0ℙ = refl |
| 96 |
p*p⁻¹≡0ℙ 1ℙ = refl |
| 97 |
|
| 98 |
p⁻¹*p≡0ℙ : ∀ p → p ⁻¹ ℙ.* p ≡ 0ℙ |
| 99 |
p⁻¹*p≡0ℙ 0ℙ = refl |
| 100 |
p⁻¹*p≡0ℙ 1ℙ = refl |
| 101 |
|
| 102 |
------------------------------------------------------------------------ |
| 103 |
-- _+_ |
| 104 |
|
| 105 |
-- Algebraic properties of _+_ |
| 106 |
|
| 107 |
p+p≡0ℙ : ∀ p → p ℙ.+ p ≡ 0ℙ |
| 108 |
p+p≡0ℙ 0ℙ = refl |
| 109 |
p+p≡0ℙ 1ℙ = refl |
| 110 |
|
| 111 |
+-identityˡ : LeftIdentity 0ℙ ℙ._+_ |
| 112 |
+-identityˡ _ = refl |
| 113 |
|
| 114 |
+-identityʳ : RightIdentity 0ℙ ℙ._+_ |
| 115 |
+-identityʳ 1ℙ = refl |
| 116 |
+-identityʳ 0ℙ = refl |
| 117 |
|
| 118 |
+-identity : Identity 0ℙ ℙ._+_ |
| 119 |
+-identity = +-identityˡ , +-identityʳ |
| 120 |
|
| 121 |
+-comm : Commutative ℙ._+_ |
| 122 |
+-comm 0ℙ 0ℙ = refl |
| 123 |
+-comm 0ℙ 1ℙ = refl |
| 124 |
+-comm 1ℙ 0ℙ = refl |
| 125 |
+-comm 1ℙ 1ℙ = refl |
| 126 |
|
| 127 |
+-assoc : Associative ℙ._+_ |
| 128 |
+-assoc 0ℙ 0ℙ _ = refl |
| 129 |
+-assoc 0ℙ 1ℙ _ = refl |
| 130 |
+-assoc 1ℙ 0ℙ _ = refl |
| 131 |
+-assoc 1ℙ 1ℙ 0ℙ = refl |
| 132 |
+-assoc 1ℙ 1ℙ 1ℙ = refl |
| 133 |
|
| 134 |
+-cancelʳ-≡ : RightCancellative ℙ._+_ |
| 135 |
+-cancelʳ-≡ _ 1ℙ 1ℙ _ = refl |
| 136 |
+-cancelʳ-≡ _ 1ℙ 0ℙ eq = contradiction (sym eq) (p≢p⁻¹ _) |
| 137 |
+-cancelʳ-≡ _ 0ℙ 1ℙ eq = contradiction eq (p≢p⁻¹ _) |
| 138 |
+-cancelʳ-≡ _ 0ℙ 0ℙ _ = refl |
| 139 |
|
| 140 |
+-cancelˡ-≡ : LeftCancellative ℙ._+_ |
| 141 |
+-cancelˡ-≡ 1ℙ _ _ eq = ⁻¹-injective eq |
| 142 |
+-cancelˡ-≡ 0ℙ _ _ eq = eq |
| 143 |
|
| 144 |
+-cancel-≡ : Cancellative ℙ._+_ |
| 145 |
+-cancel-≡ = +-cancelˡ-≡ , +-cancelʳ-≡ |
| 146 |
|
| 147 |
+-inverse : Inverse 0ℙ id ℙ._+_ |
| 148 |
+-inverse = p+p≡0ℙ , p+p≡0ℙ |
| 149 |
|
| 150 |
------------------------------------------------------------------------ |
| 151 |
-- Bundles |
| 152 |
|
| 153 |
+-isMagma : IsMagma ℙ._+_ |
| 154 |
+-isMagma = record |
| 155 |
{ isEquivalence = isEquivalence |
| 156 |
; ∙-cong = cong₂ ℙ._+_ |
| 157 |
} |
| 158 |
|
| 159 |
+-magma : Magma 0ℓ 0ℓ |
| 160 |
+-magma = record |
| 161 |
{ isMagma = +-isMagma |
| 162 |
} |
| 163 |
|
| 164 |
+-isSemigroup : IsSemigroup ℙ._+_ |
| 165 |
+-isSemigroup = record |
| 166 |
{ isMagma = +-isMagma |
| 167 |
; assoc = +-assoc |
| 168 |
} |
| 169 |
|
| 170 |
+-semigroup : Semigroup 0ℓ 0ℓ |
| 171 |
+-semigroup = record |
| 172 |
{ isSemigroup = +-isSemigroup |
| 173 |
} |
| 174 |
|
| 175 |
+-isCommutativeSemigroup : IsCommutativeSemigroup ℙ._+_ |
| 176 |
+-isCommutativeSemigroup = record |
| 177 |
{ isSemigroup = +-isSemigroup |
| 178 |
; comm = +-comm |
| 179 |
} |
| 180 |
|
| 181 |
+-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ |
| 182 |
+-commutativeSemigroup = record |
| 183 |
{ isCommutativeSemigroup = +-isCommutativeSemigroup |
| 184 |
} |
| 185 |
|
| 186 |
+-0-isMonoid : IsMonoid ℙ._+_ 0ℙ |
| 187 |
+-0-isMonoid = record |
| 188 |
{ isSemigroup = +-isSemigroup |
| 189 |
; identity = +-identity |
| 190 |
} |
| 191 |
|
| 192 |
+-0-monoid : Monoid 0ℓ 0ℓ |
| 193 |
+-0-monoid = record |
| 194 |
{ isMonoid = +-0-isMonoid |
| 195 |
} |
| 196 |
|
| 197 |
+-0-isCommutativeMonoid : IsCommutativeMonoid ℙ._+_ 0ℙ |
| 198 |
+-0-isCommutativeMonoid = record |
| 199 |
{ isMonoid = +-0-isMonoid |
| 200 |
; comm = +-comm |
| 201 |
} |
| 202 |
|
| 203 |
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ |
| 204 |
+-0-commutativeMonoid = record |
| 205 |
{ isCommutativeMonoid = +-0-isCommutativeMonoid |
| 206 |
} |
| 207 |
|
| 208 |
+-0-isGroup : IsGroup ℙ._+_ 0ℙ id |
| 209 |
+-0-isGroup = record |
| 210 |
{ isMonoid = +-0-isMonoid |
| 211 |
; inverse = +-inverse |
| 212 |
; ⁻¹-cong = id |
| 213 |
} |
| 214 |
|
| 215 |
+-0-group : Group 0ℓ 0ℓ |
| 216 |
+-0-group = record |
| 217 |
{ isGroup = +-0-isGroup |
| 218 |
} |
| 219 |
|
| 220 |
+-0-isAbelianGroup : IsAbelianGroup ℙ._+_ 0ℙ id |
| 221 |
+-0-isAbelianGroup = record |
| 222 |
{ isGroup = +-0-isGroup |
| 223 |
; comm = +-comm |
| 224 |
} |
| 225 |
|
| 226 |
+-0-abelianGroup : AbelianGroup 0ℓ 0ℓ |
| 227 |
+-0-abelianGroup = record |
| 228 |
{ isAbelianGroup = +-0-isAbelianGroup |
| 229 |
} |
| 230 |
|
| 231 |
------------------------------------------------------------------------ |
| 232 |
-- _*_ |
| 233 |
|
| 234 |
-- Algebraic properties of _*_ |
| 235 |
|
| 236 |
*-idem : Idempotent ℙ._*_ |
| 237 |
*-idem 0ℙ = refl |
| 238 |
*-idem 1ℙ = refl |
| 239 |
|
| 240 |
*-comm : Commutative ℙ._*_ |
| 241 |
*-comm 0ℙ 0ℙ = refl |
| 242 |
*-comm 0ℙ 1ℙ = refl |
| 243 |
*-comm 1ℙ 0ℙ = refl |
| 244 |
*-comm 1ℙ 1ℙ = refl |
| 245 |
|
| 246 |
*-assoc : Associative ℙ._*_ |
| 247 |
*-assoc 0ℙ 0ℙ _ = refl |
| 248 |
*-assoc 0ℙ 1ℙ _ = refl |
| 249 |
*-assoc 1ℙ 0ℙ _ = refl |
| 250 |
*-assoc 1ℙ 1ℙ 0ℙ = refl |
| 251 |
*-assoc 1ℙ 1ℙ 1ℙ = refl |
| 252 |
|
| 253 |
*-distribˡ-+ : ℙ._*_ DistributesOverˡ ℙ._+_ |
| 254 |
*-distribˡ-+ 0ℙ q r = refl |
| 255 |
*-distribˡ-+ 1ℙ 0ℙ 0ℙ = refl |
| 256 |
*-distribˡ-+ 1ℙ 0ℙ 1ℙ = refl |
| 257 |
*-distribˡ-+ 1ℙ 1ℙ 0ℙ = refl |
| 258 |
*-distribˡ-+ 1ℙ 1ℙ 1ℙ = refl |
| 259 |
|
| 260 |
*-distribʳ-+ : ℙ._*_ DistributesOverʳ ℙ._+_ |
| 261 |
*-distribʳ-+ = comm∧distrˡ⇒distrʳ *-comm *-distribˡ-+ |
| 262 |
|
| 263 |
*-distrib-+ : ℙ._*_ DistributesOver ℙ._+_ |
| 264 |
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+ |
| 265 |
|
| 266 |
*-zeroˡ : LeftZero 0ℙ ℙ._*_ |
| 267 |
*-zeroˡ p = refl |
| 268 |
|
| 269 |
*-zeroʳ : RightZero 0ℙ ℙ._*_ |
| 270 |
*-zeroʳ p = *-comm p 0ℙ |
| 271 |
|
| 272 |
*-zero : Zero 0ℙ ℙ._*_ |
| 273 |
*-zero = *-zeroˡ , *-zeroʳ |
| 274 |
|
| 275 |
*-identityˡ : LeftIdentity 1ℙ ℙ._*_ |
| 276 |
*-identityˡ _ = refl |
| 277 |
|
| 278 |
*-identityʳ : RightIdentity 1ℙ ℙ._*_ |
| 279 |
*-identityʳ 1ℙ = refl |
| 280 |
*-identityʳ 0ℙ = refl |
| 281 |
|
| 282 |
*-identity : Identity 1ℙ ℙ._*_ |
| 283 |
*-identity = *-identityˡ , *-identityʳ |
| 284 |
|
| 285 |
------------------------------------------------------------------------ |
| 286 |
-- Structures and Bundles |
| 287 |
|
| 288 |
*-isMagma : IsMagma ℙ._*_ |
| 289 |
*-isMagma = record |
| 290 |
{ isEquivalence = isEquivalence |
| 291 |
; ∙-cong = cong₂ ℙ._*_ |
| 292 |
} |
| 293 |
|
| 294 |
*-magma : Magma 0ℓ 0ℓ |
| 295 |
*-magma = record |
| 296 |
{ isMagma = *-isMagma |
| 297 |
} |
| 298 |
|
| 299 |
*-isSemigroup : IsSemigroup ℙ._*_ |
| 300 |
*-isSemigroup = record |
| 301 |
{ isMagma = *-isMagma |
| 302 |
; assoc = *-assoc |
| 303 |
} |
| 304 |
|
| 305 |
*-semigroup : Semigroup 0ℓ 0ℓ |
| 306 |
*-semigroup = record |
| 307 |
{ isSemigroup = *-isSemigroup |
| 308 |
} |
| 309 |
|
| 310 |
*-isCommutativeSemigroup : IsCommutativeSemigroup ℙ._*_ |
| 311 |
*-isCommutativeSemigroup = record |
| 312 |
{ isSemigroup = *-isSemigroup |
| 313 |
; comm = *-comm |
| 314 |
} |
| 315 |
|
| 316 |
*-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ |
| 317 |
*-commutativeSemigroup = record |
| 318 |
{ isCommutativeSemigroup = *-isCommutativeSemigroup |
| 319 |
} |
| 320 |
|
| 321 |
*-1-isMonoid : IsMonoid ℙ._*_ 1ℙ |
| 322 |
*-1-isMonoid = record |
| 323 |
{ isSemigroup = *-isSemigroup |
| 324 |
; identity = *-identity |
| 325 |
} |
| 326 |
|
| 327 |
*-1-monoid : Monoid 0ℓ 0ℓ |
| 328 |
*-1-monoid = record |
| 329 |
{ isMonoid = *-1-isMonoid |
| 330 |
} |
| 331 |
|
| 332 |
*-1-isCommutativeMonoid : IsCommutativeMonoid ℙ._*_ 1ℙ |
| 333 |
*-1-isCommutativeMonoid = record |
| 334 |
{ isMonoid = *-1-isMonoid |
| 335 |
; comm = *-comm |
| 336 |
} |
| 337 |
|
| 338 |
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ |
| 339 |
*-1-commutativeMonoid = record |
| 340 |
{ isCommutativeMonoid = *-1-isCommutativeMonoid |
| 341 |
} |
| 342 |
|
| 343 |
+-*-isSemiring : IsSemiring ℙ._+_ ℙ._*_ 0ℙ 1ℙ |
| 344 |
+-*-isSemiring = record |
| 345 |
{ isSemiringWithoutAnnihilatingZero = record |
| 346 |
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid |
| 347 |
; *-cong = cong₂ ℙ._*_ |
| 348 |
; *-assoc = *-assoc |
| 349 |
; *-identity = *-identity |
| 350 |
; distrib = *-distrib-+ |
| 351 |
} |
| 352 |
; zero = *-zero |
| 353 |
} |
| 354 |
|
| 355 |
+-*-semiring : Semiring 0ℓ 0ℓ |
| 356 |
+-*-semiring = record |
| 357 |
{ isSemiring = +-*-isSemiring |
| 358 |
} |
| 359 |
|
| 360 |
+-*-isCommutativeSemiring : IsCommutativeSemiring ℙ._+_ ℙ._*_ 0ℙ 1ℙ |
| 361 |
+-*-isCommutativeSemiring = record |
| 362 |
{ isSemiring = +-*-isSemiring |
| 363 |
; *-comm = *-comm |
| 364 |
} |
| 365 |
|
| 366 |
+-*-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ |
| 367 |
+-*-commutativeSemiring = record |
| 368 |
{ isCommutativeSemiring = +-*-isCommutativeSemiring |
| 369 |
} |
| 370 |
|
| 371 |
+-*-isRing : IsRing ℙ._+_ ℙ._*_ id 0ℙ 1ℙ |
| 372 |
+-*-isRing = record |
| 373 |
{ +-isAbelianGroup = +-0-isAbelianGroup |
| 374 |
; *-cong = cong₂ ℙ._*_ |
| 375 |
; *-assoc = *-assoc |
| 376 |
; *-identity = *-identity |
| 377 |
; distrib = *-distrib-+ |
| 378 |
} |
| 379 |
|
| 380 |
+-*-ring : Ring 0ℓ 0ℓ |
| 381 |
+-*-ring = record |
| 382 |
{ isRing = +-*-isRing |
| 383 |
} |
| 384 |
|
| 385 |
+-*-isCommutativeRing : IsCommutativeRing ℙ._+_ ℙ._*_ id 0ℙ 1ℙ |
| 386 |
+-*-isCommutativeRing = record |
| 387 |
{ isRing = +-*-isRing |
| 388 |
; *-comm = *-comm |
| 389 |
} |
| 390 |
|
| 391 |
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ |
| 392 |
+-*-commutativeRing = record |
| 393 |
{ isCommutativeRing = +-*-isCommutativeRing |
| 394 |
} |
| 395 |
|
| 396 |
------------------------------------------------------------------------ |
| 397 |
-- relating Parity and Sign |
| 398 |
|
| 399 |
+-homo-* : ∀ p q → toSign (p ℙ.+ q) ≡ (toSign p) 𝕊.* (toSign q) |
| 400 |
+-homo-* 0ℙ 0ℙ = refl |
| 401 |
+-homo-* 0ℙ 1ℙ = refl |
| 402 |
+-homo-* 1ℙ 0ℙ = refl |
| 403 |
+-homo-* 1ℙ 1ℙ = refl |
| 404 |
|
| 405 |
⁻¹-homo-opposite : ∀ p → toSign (p ⁻¹) ≡ 𝕊.opposite (toSign p) |
| 406 |
⁻¹-homo-opposite 0ℙ = refl |
| 407 |
⁻¹-homo-opposite 1ℙ = refl |
| 408 |
|
| 409 |
toSign-inverseʳ : Inverseʳ _≡_ _≡_ toSign fromSign |
| 410 |
toSign-inverseʳ {0ℙ} refl = refl |
| 411 |
toSign-inverseʳ {1ℙ} refl = refl |
| 412 |
|
| 413 |
toSign-inverseˡ : Inverseˡ _≡_ _≡_ toSign fromSign |
| 414 |
toSign-inverseˡ { 𝕊.+ } refl = refl |
| 415 |
toSign-inverseˡ { 𝕊.- } refl = refl |
| 416 |
|
| 417 |
toSign-injective : Injective _≡_ _≡_ toSign |
| 418 |
toSign-injective = inverseʳ⇒injective toSign toSign-inverseʳ |
| 419 |
|
| 420 |
toSign-surjective : Surjective _≡_ _≡_ toSign |
| 421 |
toSign-surjective = inverseˡ⇒surjective toSign-inverseˡ |
| 422 |
|
| 423 |
toSign-isMagmaHomomorphism : IsMagmaHomomorphism ℙ.+-rawMagma 𝕊.*-rawMagma toSign |
| 424 |
toSign-isMagmaHomomorphism = record |
| 425 |
{ isRelHomomorphism = record |
| 426 |
{ cong = cong toSign } |
| 427 |
; homo = +-homo-* |
| 428 |
} |
| 429 |
|
| 430 |
toSign-isMagmaMonomorphism : IsMagmaMonomorphism ℙ.+-rawMagma 𝕊.*-rawMagma toSign |
| 431 |
toSign-isMagmaMonomorphism = record |
| 432 |
{ isMagmaHomomorphism = toSign-isMagmaHomomorphism |
| 433 |
; injective = toSign-injective |
| 434 |
} |
| 435 |
|
| 436 |
toSign-isMagmaIsomorphism : IsMagmaIsomorphism ℙ.+-rawMagma 𝕊.*-rawMagma toSign |
| 437 |
toSign-isMagmaIsomorphism = record |
| 438 |
{ isMagmaMonomorphism = toSign-isMagmaMonomorphism |
| 439 |
; surjective = toSign-surjective |
| 440 |
} |
| 441 |
|
| 442 |
toSign-isMonoidHomomorphism : IsMonoidHomomorphism ℙ.+-0-rawMonoid 𝕊.*-1-rawMonoid toSign |
| 443 |
toSign-isMonoidHomomorphism = record |
| 444 |
{ isMagmaHomomorphism = toSign-isMagmaHomomorphism |
| 445 |
; ε-homo = refl |
| 446 |
} |
| 447 |
|
| 448 |
toSign-isMonoidMonomorphism : IsMonoidMonomorphism ℙ.+-0-rawMonoid 𝕊.*-1-rawMonoid toSign |
| 449 |
toSign-isMonoidMonomorphism = record |
| 450 |
{ isMonoidHomomorphism = toSign-isMonoidHomomorphism |
| 451 |
; injective = toSign-injective |
| 452 |
} |
| 453 |
|
| 454 |
toSign-isMonoidIsomorphism : IsMonoidIsomorphism ℙ.+-0-rawMonoid 𝕊.*-1-rawMonoid toSign |
| 455 |
toSign-isMonoidIsomorphism = record |
| 456 |
{ isMonoidMonomorphism = toSign-isMonoidMonomorphism |
| 457 |
; surjective = toSign-surjective |
| 458 |
} |
| 459 |
|
| 460 |
toSign-isGroupHomomorphism : IsGroupHomomorphism ℙ.+-0-rawGroup 𝕊.*-1-rawGroup toSign |
| 461 |
toSign-isGroupHomomorphism = record |
| 462 |
{ isMonoidHomomorphism = toSign-isMonoidHomomorphism |
| 463 |
; ⁻¹-homo = ⁻¹-homo-opposite |
| 464 |
} |
| 465 |
|
| 466 |
toSign-isGroupMonomorphism : IsGroupMonomorphism ℙ.+-0-rawGroup 𝕊.*-1-rawGroup toSign |
| 467 |
toSign-isGroupMonomorphism = record |
| 468 |
{ isGroupHomomorphism = toSign-isGroupHomomorphism |
| 469 |
; injective = toSign-injective |
| 470 |
} |
| 471 |
|
| 472 |
toSign-isGroupIsomorphism : IsGroupIsomorphism ℙ.+-0-rawGroup 𝕊.*-1-rawGroup toSign |
| 473 |
toSign-isGroupIsomorphism = record |
| 474 |
{ isGroupMonomorphism = toSign-isGroupMonomorphism |
| 475 |
; surjective = toSign-surjective |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
------------------------------------------------------------------------ |
| 480 |
-- Relating Nat and Parity |
| 481 |
|
| 482 |
-- successor and (_⁻¹) |
| 483 |
|
| 484 |
suc-homo-⁻¹ : ∀ n → (parity (suc n)) ⁻¹ ≡ parity n |
| 485 |
suc-homo-⁻¹ zero = refl |
| 486 |
suc-homo-⁻¹ (suc n) = ⁻¹-selfInverse (suc-homo-⁻¹ n) |
| 487 |
|
| 488 |
-- parity is a _+_ homomorphism |
| 489 |
|
| 490 |
+-homo-+ : ∀ m n → parity (m ℕ.+ n) ≡ parity m ℙ.+ parity n |
| 491 |
+-homo-+ zero n = refl |
| 492 |
+-homo-+ (suc m) n = begin |
| 493 |
parity (suc m ℕ.+ n) ≡⟨ suc-+-homo-⁻¹ m n ⟩ |
| 494 |
(parity m) ⁻¹ ℙ.+ parity n ≡⟨ cong (ℙ._+ parity n) (suc-homo-⁻¹ (suc m)) ⟩ |
| 495 |
parity (suc m) ℙ.+ parity n ∎ |
| 496 |
where |
| 497 |
open ≡-Reasoning |
| 498 |
suc-+-homo-⁻¹ : ∀ m n → parity (suc m ℕ.+ n) ≡ (parity m) ⁻¹ ℙ.+ parity n |
| 499 |
suc-+-homo-⁻¹ zero n = sym (suc-homo-⁻¹ (suc n)) |
| 500 |
suc-+-homo-⁻¹ (suc m) n = begin |
| 501 |
parity (suc (suc m) ℕ.+ n) ≡⟨⟩ |
| 502 |
parity (m ℕ.+ n) ≡⟨ +-homo-+ m n ⟩ |
| 503 |
parity m ℙ.+ parity n ≡⟨ cong (ℙ._+ parity n) (sym (suc-homo-⁻¹ m)) ⟩ |
| 504 |
(parity (suc m)) ⁻¹ ℙ.+ parity n ∎ |
| 505 |
|
| 506 |
-- parity is a _*_ homomorphism |
| 507 |
|
| 508 |
*-homo-* : ∀ m n → parity (m ℕ.* n) ≡ parity m ℙ.* parity n |
| 509 |
*-homo-* zero n = refl |
| 510 |
*-homo-* (suc m) n = begin |
| 511 |
parity (suc m ℕ.* n) ≡⟨⟩ |
| 512 |
parity (n ℕ.+ m ℕ.* n) ≡⟨ +-homo-+ n (m ℕ.* n) ⟩ |
| 513 |
q ℙ.+ parity (m ℕ.* n) ≡⟨ cong (q ℙ.+_) (*-homo-* m n) ⟩ |
| 514 |
q ℙ.+ (p ℙ.* q) ≡⟨ lemma p q ⟩ |
| 515 |
(p ⁻¹) ℙ.* q ≡⟨⟩ |
| 516 |
(parity m) ⁻¹ ℙ.* q ≡⟨ cong (ℙ._* q) (suc-homo-⁻¹ (suc m)) ⟩ |
| 517 |
parity (suc m) ℙ.* q ≡⟨⟩ |
| 518 |
parity (suc m) ℙ.* parity n ∎ |
| 519 |
where |
| 520 |
open ≡-Reasoning |
| 521 |
p = parity m |
| 522 |
q = parity n |
| 523 |
-- this lemma simplifies things a lot |
| 524 |
lemma : ∀ p q → q ℙ.+ (p ℙ.* q) ≡ (p ⁻¹) ℙ.* q |
| 525 |
lemma 0ℙ 0ℙ = refl |
| 526 |
lemma 0ℙ 1ℙ = refl |
| 527 |
lemma 1ℙ 0ℙ = refl |
| 528 |
lemma 1ℙ 1ℙ = refl |
| 529 |
|
| 530 |
------------------------------------------------------------------------ |
| 531 |
-- parity is a Semiring homomorphism from Nat to Parity |
| 532 |
|
| 533 |
parity-isMagmaHomomorphism : IsMagmaHomomorphism ℕ.+-rawMagma ℙ.+-rawMagma parity |
| 534 |
parity-isMagmaHomomorphism = record |
| 535 |
{ isRelHomomorphism = record |
| 536 |
{ cong = cong parity } |
| 537 |
; homo = +-homo-+ |
| 538 |
} |
| 539 |
|
| 540 |
parity-isMonoidHomomorphism : IsMonoidHomomorphism ℕ.+-0-rawMonoid ℙ.+-0-rawMonoid parity |
| 541 |
parity-isMonoidHomomorphism = record |
| 542 |
{ isMagmaHomomorphism = parity-isMagmaHomomorphism |
| 543 |
; ε-homo = refl |
| 544 |
} |
| 545 |
|
| 546 |
parity-isNearSemiringHomomorphism : IsNearSemiringHomomorphism ℕ.+-*-rawNearSemiring ℙ.+-*-rawNearSemiring parity |
| 547 |
parity-isNearSemiringHomomorphism = record |
| 548 |
{ +-isMonoidHomomorphism = parity-isMonoidHomomorphism |
| 549 |
; *-homo = *-homo-* |
| 550 |
} |
| 551 |
|
| 552 |
parity-isSemiringHomomorphism : IsSemiringHomomorphism ℕ.+-*-rawSemiring ℙ.+-*-rawSemiring parity |
| 553 |
parity-isSemiringHomomorphism = record |
| 554 |
{ isNearSemiringHomomorphism = parity-isNearSemiringHomomorphism |
| 555 |
; 1#-homo = refl |
| 556 |
} |