aboutsummaryrefslogtreecommitdiff
path: root/Data/Mat/Util.agda
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2026-03-26 16:00:15 -0500
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2026-03-26 16:00:15 -0500
commite5f84dbe58056f2b57244f0498074ce9aea978b7 (patch)
treeb696a040279919ca16b8daa55d3be0418a8c6e7f /Data/Mat/Util.agda
parent348f5615631fff3279049ab930fd51ec4442f44f (diff)
Add cocartesian structure to category of matrices
Diffstat (limited to 'Data/Mat/Util.agda')
-rw-r--r--Data/Mat/Util.agda16
1 files changed, 10 insertions, 6 deletions
diff --git a/Data/Mat/Util.agda b/Data/Mat/Util.agda
index b7aedd2..4570b44 100644
--- a/Data/Mat/Util.agda
+++ b/Data/Mat/Util.agda
@@ -7,9 +7,9 @@ import Data.Vec.Relation.Binary.Equality.Setoid as ≋
import Data.Vec.Relation.Binary.Pointwise.Inductive as PW
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning
-open import Data.Nat using (ℕ)
+open import Data.Nat using (ℕ; _+_)
open import Data.Setoid using (∣_∣)
-open import Data.Vec using (Vec; zipWith; foldr; map; replicate)
+open import Data.Vec using (Vec; zipWith; foldr; map; replicate; _++_)
open import Level using (Level)
open import Relation.Binary using (Rel; Setoid; Monotonic₂)
open import Relation.Binary.PropositionalEquality as ≡ using (_≗_; _≡_; module ≡-Reasoning)
@@ -27,16 +27,16 @@ transpose : Vec (Vec A n) m → Vec (Vec A m) n
transpose [] = replicate _ []
transpose (row ∷ mat) = zipWith _∷_ row (transpose mat)
-transpose-empty : (m : ℕ) → transpose (replicate {A = Vec A zero} m []) ≡ []
-transpose-empty zero = ≡.refl
-transpose-empty (suc m) = ≡.cong (zipWith _∷_ []) (transpose-empty m)
+transpose-empty : (m : ℕ) (E : Vec (Vec A 0) m) → transpose E ≡ []
+transpose-empty zero [] = ≡.refl
+transpose-empty (suc m) ([] ∷ E) = ≡.cong (zipWith _∷_ []) (transpose-empty m E)
transpose-zipWith : (V : Vec A m) (M : Vec (Vec A n) m) → transpose (zipWith _∷_ V M) ≡ V ∷ transpose M
transpose-zipWith [] [] = ≡.refl
transpose-zipWith (x ∷ V) (M₀ ∷ M) = ≡.cong (zipWith _∷_ (x ∷ M₀)) (transpose-zipWith V M)
transpose-involutive : (M : Vec (Vec A n) m) → transpose (transpose M) ≡ M
-transpose-involutive {n} [] = transpose-empty n
+transpose-involutive {n} [] = transpose-empty n (replicate n [])
transpose-involutive (V ∷ M) = begin
transpose (zipWith _∷_ V (transpose M)) ≡⟨ transpose-zipWith V (transpose M) ⟩
V ∷ transpose (transpose M) ≡⟨ ≡.cong (V ∷_) (transpose-involutive M) ⟩
@@ -48,6 +48,10 @@ map-replicate : (x : A) (v : Vec B n) → map (λ _ → x) v ≡ replicate n x
map-replicate x [] = ≡.refl
map-replicate x (y ∷ v) = ≡.cong (x ∷_) (map-replicate x v)
+replicate-++ : (n m : ℕ) (x : A) → replicate n x ++ replicate m x ≡ replicate (n + m) x
+replicate-++ zero _ x = ≡.refl
+replicate-++ (suc n) m x = ≡.cong (x ∷_) (replicate-++ n m x)
+
zipWith-map-map
: (f : A → C)
(g : B → D)