| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Multiplication over a monoid (i.e. repeated addition) optimised for |
| 5 |
-- type checking. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Algebra.Bundles using (CommutativeMonoid) |
| 11 |
open import Data.Nat.Base as ℕ using (ℕ; zero; suc) |
| 12 |
open import Relation.Binary.Core using (_Preserves_⟶_; _Preserves₂_⟶_⟶_) |
| 13 |
|
| 14 |
module Algebra.Properties.CommutativeMonoid.Mult.TCOptimised |
| 15 |
{a ℓ} (M : CommutativeMonoid a ℓ) where |
| 16 |
|
| 17 |
open CommutativeMonoid M renaming |
| 18 |
( _∙_ to _+_ |
| 19 |
; ∙-cong to +-cong |
| 20 |
; ∙-congˡ to +-congˡ |
| 21 |
; ∙-congʳ to +-congʳ |
| 22 |
; identityˡ to +-identityˡ |
| 23 |
; identityʳ to +-identityʳ |
| 24 |
; assoc to +-assoc |
| 25 |
; ε to 0# |
| 26 |
) |
| 27 |
|
| 28 |
open import Algebra.Properties.CommutativeMonoid.Mult M as U |
| 29 |
using () renaming (_×_ to _×ᵤ_) |
| 30 |
|
| 31 |
open import Relation.Binary.Reasoning.Setoid setoid |
| 32 |
|
| 33 |
------------------------------------------------------------------------ |
| 34 |
-- Re-export definition and properties for monoids |
| 35 |
|
| 36 |
open import Algebra.Properties.Monoid.Mult.TCOptimised monoid public |
| 37 |
|
| 38 |
------------------------------------------------------------------------ |
| 39 |
-- Properties |
| 40 |
|
| 41 |
×-distrib-+ : ∀ x y n → n × (x + y) ≈ n × x + n × y |
| 42 |
×-distrib-+ x y n = begin |
| 43 |
n × (x + y) ≈⟨ ×ᵤ≈× n (x + y) ⟨ |
| 44 |
n ×ᵤ (x + y) ≈⟨ U.×-distrib-+ x y n ⟩ |
| 45 |
n ×ᵤ x + n ×ᵤ y ≈⟨ +-cong (×ᵤ≈× n x) (×ᵤ≈× n y) ⟩ |
| 46 |
n × x + n × y ∎ |