Debian Codegraph @

src/Algebra/Operations/CommutativeMonoid.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- This module is DEPRECATED.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Algebra
10 open import Data.List.Base as List using (List; []; _∷_; _++_)
11 open import Data.Fin.Base using (Fin; zero)
12 open import Data.Nat.Base as ℕ using (ℕ; zero; suc)
13 open import Function.Base using (_∘_)
14 open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_)
15 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
16
17 module Algebra.Operations.CommutativeMonoid
18 {s₁ s₂} (CM : CommutativeMonoid s₁ s₂)
19 where
20
21 {-# WARNING_ON_IMPORT
22 "Algebra.Operations.CommutativeMonoid was deprecated in v1.5.
23 Use Algebra.Properties.CommutativeMonoid.(Sum/Mult/Exp)(.TCOptimised) instead."
24 #-}
25
26 open CommutativeMonoid CM
27 renaming
28 ( _∙_ to _+_
29 ; ε to 0#
30 ; identityʳ to +-identityʳ
31 ; identityˡ to +-identityˡ
32 ; ∙-cong to +-cong
33 ; ∙-congˡ to +-congˡ
34 ; assoc to +-assoc
35 )
36
37 open import Relation.Binary.Reasoning.Setoid setoid
38
39 ------------------------------------------------------------------------
40 -- Multiplication
41
42 infixr 8 _×_ _×′_
43
44 _×_ : ℕ → Carrier → Carrier
45 0 × x = 0#
46 suc n × x = x + (n × x)
47
48 _×′_ : ℕ → Carrier → Carrier
49 0 ×′ x = 0#
50 1 ×′ x = x
51 suc n ×′ x = x + n ×′ x
52
53 ------------------------------------------------------------------------
54 -- Properties of _×_
55
56 ×-congʳ : ∀ n → (n ×_) Preserves _≈_ ⟶ _≈_
57 ×-congʳ 0 x≈x′ = refl
58 ×-congʳ (suc n) x≈x′ = +-cong x≈x′ (×-congʳ n x≈x′)
59
60 ×-cong : _×_ Preserves₂ _≡_ ⟶ _≈_ ⟶ _≈_
61 ×-cong {u} ≡.refl x≈x′ = ×-congʳ u x≈x′
62
63 -- _×_ is homomorphic with respect to _ℕ+_/_+_.
64
65 ×-homo-+ : ∀ c m n → (m ℕ.+ n) × c ≈ m × c + n × c
66 ×-homo-+ c 0 n = sym (+-identityˡ (n × c))
67 ×-homo-+ c (suc m) n = begin
68 c + (m ℕ.+ n) × c ≈⟨ +-cong refl (×-homo-+ c m n) ⟩
69 c + (m × c + n × c) ≈⟨ sym (+-assoc c (m × c) (n × c)) ⟩
70 c + m × c + n × c ∎
71
72 ------------------------------------------------------------------------
73 -- Properties of _×′_
74
75 1+×′ : ∀ n x → suc n ×′ x ≈ x + n ×′ x
76 1+×′ 0 x = sym (+-identityʳ x)
77 1+×′ (suc n) x = refl
78
79 -- _×_ and _×′_ are extensionally equal (up to the setoid
80 -- equivalence).
81
82 ×≈×′ : ∀ n x → n × x ≈ n ×′ x
83 ×≈×′ 0 x = refl
84 ×≈×′ (suc n) x = begin
85 x + n × x ≈⟨ +-congˡ (×≈×′ n x) ⟩
86 x + n ×′ x ≈⟨ sym (1+×′ n x) ⟩
87 suc n ×′ x ∎
88
89 -- _×′_ is homomorphic with respect to _ℕ+_/_+_.
90
91 ×′-homo-+ : ∀ c m n → (m ℕ.+ n) ×′ c ≈ m ×′ c + n ×′ c
92 ×′-homo-+ c m n = begin
93 (m ℕ.+ n) ×′ c ≈⟨ sym (×≈×′ (m ℕ.+ n) c) ⟩
94 (m ℕ.+ n) × c ≈⟨ ×-homo-+ c m n ⟩
95 m × c + n × c ≈⟨ +-cong (×≈×′ m c) (×≈×′ n c) ⟩
96 m ×′ c + n ×′ c ∎
97
98 -- _×′_ preserves equality.
99
100 ×′-cong : _×′_ Preserves₂ _≡_ ⟶ _≈_ ⟶ _≈_
101 ×′-cong {n} {_} {x} {y} ≡.refl x≈y = begin
102 n ×′ x ≈⟨ sym (×≈×′ n x) ⟩
103 n × x ≈⟨ ×-congʳ n x≈y ⟩
104 n × y ≈⟨ ×≈×′ n y ⟩
105 n ×′ y ∎