1
------------------------------------------------------------------------
2
-- Some defined operations (multiplication by natural number and
4
------------------------------------------------------------------------
8
module Algebra.Operations (s : Semiring) where
10
open Semiring s hiding (zero)
11
open import Data.Nat using (zero; suc; ℕ)
12
open import Data.Function
13
open import Relation.Binary
14
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
15
import Relation.Binary.EqReasoning as EqR
18
------------------------------------------------------------------------
21
-- Multiplication by natural number.
25
_×_ : ℕ → Carrier → Carrier
33
_^_ : Carrier → ℕ → Carrier
37
------------------------------------------------------------------------
40
×-cong : _×_ Preserves₂ _≡_ ⟶ _≈_ ⟶ _≈_
41
×-cong {n} {n'} {x} {x'} n≡n' x≈x' = begin
42
n × x ≈⟨ reflexive $ PropEq.cong (λ n → n × x) n≡n' ⟩
43
n' × x ≈⟨ ×-congʳ n' x≈x' ⟩
46
×-congʳ : ∀ n → (_×_ n) Preserves _≈_ ⟶ _≈_
47
×-congʳ zero x≈x' = refl
48
×-congʳ (suc n) x≈x' = x≈x' ⟨ +-cong ⟩ ×-congʳ n x≈x'
50
^-cong : _^_ Preserves₂ _≈_ ⟶ _≡_ ⟶ _≈_
51
^-cong {x} {x'} {n} {n'} x≈x' n≡n' = begin
52
x ^ n ≈⟨ reflexive $ PropEq.cong (_^_ x) n≡n' ⟩
53
x ^ n' ≈⟨ ^-congˡ n' x≈x' ⟩
56
^-congˡ : ∀ n → (λ x → x ^ n) Preserves _≈_ ⟶ _≈_
57
^-congˡ zero x≈x' = refl
58
^-congˡ (suc n) x≈x' = x≈x' ⟨ *-cong ⟩ ^-congˡ n x≈x'