Debian Codegraph @

src/Algebra/Properties/Monoid/Mult.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Multiplication over a monoid (i.e. repeated addition)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Algebra.Bundles using (Monoid)
10 open import Data.Nat.Base as ℕ using (ℕ; zero; suc; NonZero)
11 open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_)
12 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
13
14 module Algebra.Properties.Monoid.Mult {a ℓ} (M : Monoid a ℓ) where
15
16 -- View of the monoid operator as addition
17 open Monoid M
18 renaming
19 ( _∙_ to _+_
20 ; ∙-cong to +-cong
21 ; ∙-congʳ to +-congʳ
22 ; ∙-congˡ to +-congˡ
23 ; identityˡ to +-identityˡ
24 ; identityʳ to +-identityʳ
25 ; assoc to +-assoc
26 ; ε to 0#
27 )
28
29 open import Relation.Binary.Reasoning.Setoid setoid
30
31 open import Algebra.Definitions _≈_
32
33 ------------------------------------------------------------------------
34 -- Definition
35
36 open import Algebra.Definitions.RawMonoid rawMonoid public
37 using (_×_)
38
39 ------------------------------------------------------------------------
40 -- Properties of _×_
41
42 ×-congʳ : ∀ n → (n ×_) Preserves _≈_ ⟶ _≈_
43 ×-congʳ 0 x≈x′ = refl
44 ×-congʳ (suc n) x≈x′ = +-cong x≈x′ (×-congʳ n x≈x′)
45
46 ×-cong : _×_ Preserves₂ _≡_ ⟶ _≈_ ⟶ _≈_
47 ×-cong {n} ≡.refl x≈x′ = ×-congʳ n x≈x′
48
49 ×-congˡ : ∀ {x} → (_× x) Preserves _≡_ ⟶ _≈_
50 ×-congˡ m≡n = ×-cong m≡n refl
51
52 -- _×_ is homomorphic with respect to _ℕ+_/_+_.
53
54 ×-homo-0 : ∀ x → 0 × x ≈ 0#
55 ×-homo-0 x = refl
56
57 ×-homo-1 : ∀ x → 1 × x ≈ x
58 ×-homo-1 = +-identityʳ
59
60 ×-homo-+ : ∀ x m n → (m ℕ.+ n) × x ≈ m × x + n × x
61 ×-homo-+ x 0 n = sym (+-identityˡ (n × x))
62 ×-homo-+ x (suc m) n = begin
63 x + (m ℕ.+ n) × x ≈⟨ +-cong refl (×-homo-+ x m n) ⟩
64 x + (m × x + n × x) ≈⟨ sym (+-assoc x (m × x) (n × x)) ⟩
65 x + m × x + n × x ∎
66
67 ×-idem : ∀ {c} → _+_ IdempotentOn c →
68 ∀ n → .{{_ : NonZero n}} → n × c ≈ c
69 ×-idem {c} idem (suc zero) = +-identityʳ c
70 ×-idem {c} idem (suc n@(suc _)) = begin
71 c + (n × c) ≈⟨ +-congˡ (×-idem idem n ) ⟩
72 c + c ≈⟨ idem ⟩
73 c ∎
74
75 ×-assocˡ : ∀ x m n → m × (n × x) ≈ (m ℕ.* n) × x
76 ×-assocˡ x zero n = refl
77 ×-assocˡ x (suc m) n = begin
78 n × x + m × n × x ≈⟨ +-congˡ (×-assocˡ x m n) ⟩
79 n × x + (m ℕ.* n) × x ≈⟨ ×-homo-+ x n (m ℕ.* n) ⟨
80 (suc m ℕ.* n) × x ∎