| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Exponentiation defined over a semiring as repeated multiplication |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Algebra.Bundles using (Semiring) |
| 10 |
|
| 11 |
module Algebra.Properties.Semiring.Exp |
| 12 |
{a ℓ} (S : Semiring a ℓ) where |
| 13 |
|
| 14 |
open import Data.Nat.Base as ℕ using (ℕ; zero; suc) |
| 15 |
open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_) |
| 16 |
open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) |
| 17 |
import Data.Nat.Properties as ℕ using (*-comm) |
| 18 |
|
| 19 |
-- Need to see almost everything, including setoid |
| 20 |
open Semiring S |
| 21 |
|
| 22 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 23 |
import Algebra.Properties.Monoid.Mult *-monoid as Mult |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
-- Definition |
| 27 |
|
| 28 |
open import Algebra.Definitions.RawSemiring rawSemiring public |
| 29 |
using (_^_) |
| 30 |
|
| 31 |
------------------------------------------------------------------------ |
| 32 |
-- Properties |
| 33 |
|
| 34 |
^-congˡ : ∀ n → (_^ n) Preserves _≈_ ⟶ _≈_ |
| 35 |
^-congˡ = Mult.×-congʳ |
| 36 |
|
| 37 |
^-cong : _^_ Preserves₂ _≈_ ⟶ _≡_ ⟶ _≈_ |
| 38 |
^-cong x≈y u≡v = Mult.×-cong u≡v x≈y |
| 39 |
|
| 40 |
^-congʳ : ∀ x → (x ^_) Preserves _≡_ ⟶ _≈_ |
| 41 |
^-congʳ x = Mult.×-congˡ |
| 42 |
|
| 43 |
-- xᵐ⁺ⁿ ≈ xᵐxⁿ |
| 44 |
^-homo-* : ∀ x m n → x ^ (m ℕ.+ n) ≈ (x ^ m) * (x ^ n) |
| 45 |
^-homo-* = Mult.×-homo-+ |
| 46 |
|
| 47 |
-- (xᵐ)ⁿ≈xᵐ*ⁿ |
| 48 |
^-assocʳ : ∀ x m n → (x ^ m) ^ n ≈ x ^ (m ℕ.* n) |
| 49 |
^-assocʳ x m n rewrite ℕ.*-comm m n = Mult.×-assocˡ x n m |
| 50 |
|
| 51 |
------------------------------------------------------------------------ |
| 52 |
-- A lemma using commutativity, needed for the Binomial Theorem |
| 53 |
|
| 54 |
y*x^m*y^n≈x^m*y^[n+1] : ∀ {x} {y} (x*y≈y*x : x * y ≈ y * x) → |
| 55 |
∀ m n → y * (x ^ m * y ^ n) ≈ x ^ m * y ^ suc n |
| 56 |
y*x^m*y^n≈x^m*y^[n+1] {x} {y} x*y≈y*x = helper |
| 57 |
where |
| 58 |
helper : ∀ m n → y * (x ^ m * y ^ n) ≈ x ^ m * y ^ suc n |
| 59 |
helper zero n = begin |
| 60 |
y * (x ^ ℕ.zero * y ^ n) ≡⟨⟩ |
| 61 |
y * (1# * y ^ n) ≈⟨ *-congˡ (*-identityˡ (y ^ n)) ⟩ |
| 62 |
y * (y ^ n) ≡⟨⟩ |
| 63 |
y ^ (suc n) ≈⟨ *-identityˡ (y ^ suc n) ⟨ |
| 64 |
1# * y ^ (suc n) ≡⟨⟩ |
| 65 |
x ^ ℕ.zero * y ^ (suc n) ∎ |
| 66 |
helper (suc m) n = begin |
| 67 |
y * (x ^ suc m * y ^ n) ≡⟨⟩ |
| 68 |
y * ((x * x ^ m) * y ^ n) ≈⟨ *-congˡ (*-assoc x (x ^ m) (y ^ n)) ⟩ |
| 69 |
y * (x * (x ^ m * y ^ n)) ≈⟨ *-assoc y x (x ^ m * y ^ n) ⟨ |
| 70 |
y * x * (x ^ m * y ^ n) ≈⟨ *-congʳ x*y≈y*x ⟨ |
| 71 |
x * y * (x ^ m * y ^ n) ≈⟨ *-assoc x y _ ⟩ |
| 72 |
x * (y * (x ^ m * y ^ n)) ≈⟨ *-congˡ (helper m n) ⟩ |
| 73 |
x * (x ^ m * y ^ suc n) ≈⟨ *-assoc x (x ^ m) (y ^ suc n) ⟨ |
| 74 |
(x * x ^ m) * y ^ suc n ≡⟨⟩ |
| 75 |
x ^ suc m * y ^ suc n ∎ |