state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
W✝ X✝ Y✝ Z✝ : Mat_ C
f : W✝ ⟶ X✝
g : X✝ ⟶ Y✝
h : Y✝ ⟶ Z✝
⊢ (f ≫ g) ≫ h = f ≫ g ≫ h
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
|
apply DMatrix.ext
|
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
|
Mathlib.CategoryTheory.Preadditive.Mat.106_0.xG9GKY7NTklnF73
|
instance : Category.{v₁} (Mat_ C) where
Hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case a
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
W✝ X✝ Y✝ Z✝ : Mat_ C
f : W✝ ⟶ X✝
g : X✝ ⟶ Y✝
h : Y✝ ⟶ Z✝
⊢ ∀ (i : W✝.ι) (j : Z✝.ι), ((f ≫ g) ≫ h) i j = (f ≫ g ≫ h) i j
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
|
intros
|
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
|
Mathlib.CategoryTheory.Preadditive.Mat.106_0.xG9GKY7NTklnF73
|
instance : Category.{v₁} (Mat_ C) where
Hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case a
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
W✝ X✝ Y✝ Z✝ : Mat_ C
f : W✝ ⟶ X✝
g : X✝ ⟶ Y✝
h : Y✝ ⟶ Z✝
i✝ : W✝.ι
j✝ : Z✝.ι
⊢ ((f ≫ g) ≫ h) i✝ j✝ = (f ≫ g ≫ h) i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
|
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
|
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
|
Mathlib.CategoryTheory.Preadditive.Mat.106_0.xG9GKY7NTklnF73
|
instance : Category.{v₁} (Mat_ C) where
Hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case a
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
W✝ X✝ Y✝ Z✝ : Mat_ C
f : W✝ ⟶ X✝
g : X✝ ⟶ Y✝
h : Y✝ ⟶ Z✝
i✝ : W✝.ι
j✝ : Z✝.ι
⊢ ∑ x : Y✝.ι, ∑ x_1 : X✝.ι, f i✝ x_1 ≫ g x_1 x ≫ h x j✝ = ∑ x : X✝.ι, ∑ j : Y✝.ι, f i✝ x ≫ g x j ≫ h j j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
|
rw [Finset.sum_comm]
|
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
|
Mathlib.CategoryTheory.Preadditive.Mat.106_0.xG9GKY7NTklnF73
|
instance : Category.{v₁} (Mat_ C) where
Hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i : M.ι
⊢ 𝟙 M i i = 𝟙 (X M i)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by
|
simp [id_apply]
|
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by
|
Mathlib.CategoryTheory.Preadditive.Mat.136_0.xG9GKY7NTklnF73
|
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
h : i ≠ j
⊢ 𝟙 M i j = 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
|
simp [id_apply, h]
|
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
|
Mathlib.CategoryTheory.Preadditive.Mat.141_0.xG9GKY7NTklnF73
|
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N : Mat_ C
⊢ AddCommGroup (M ⟶ N)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
|
change AddCommGroup (DMatrix M.ι N.ι _)
|
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
|
Mathlib.CategoryTheory.Preadditive.Mat.167_0.xG9GKY7NTklnF73
|
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N : Mat_ C
⊢ AddCommGroup (DMatrix M.ι N.ι fun i j => (fun i j => X M i ⟶ X N j) i j)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
|
infer_instance
|
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
|
Mathlib.CategoryTheory.Preadditive.Mat.167_0.xG9GKY7NTklnF73
|
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N K : Mat_ C
f f' : M ⟶ N
g : N ⟶ K
⊢ (f + f') ≫ g = f ≫ g + f' ≫ g
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by
|
ext
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by
|
Mathlib.CategoryTheory.Preadditive.Mat.177_0.xG9GKY7NTklnF73
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N K : Mat_ C
f f' : M ⟶ N
g : N ⟶ K
i✝ : M.ι
j✝ : K.ι
⊢ ((f + f') ≫ g) i✝ j✝ = (f ≫ g + f' ≫ g) i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext;
|
simp [Finset.sum_add_distrib]
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext;
|
Mathlib.CategoryTheory.Preadditive.Mat.177_0.xG9GKY7NTklnF73
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N K : Mat_ C
f : M ⟶ N
g g' : N ⟶ K
⊢ f ≫ (g + g') = f ≫ g + f ≫ g'
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by
|
ext
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by
|
Mathlib.CategoryTheory.Preadditive.Mat.177_0.xG9GKY7NTklnF73
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M N K : Mat_ C
f : M ⟶ N
g g' : N ⟶ K
i✝ : M.ι
j✝ : K.ι
⊢ (f ≫ (g + g')) i✝ j✝ = (f ≫ g + f ≫ g') i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext;
|
simp [Finset.sum_add_distrib]
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext;
|
Mathlib.CategoryTheory.Preadditive.Mat.177_0.xG9GKY7NTklnF73
|
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
y : (f j).ι
⊢ (fun i j_1 => X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) i ⟶ X (f j) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
|
refine' if h : x.1 = j then _ else 0
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
y : (f j).ι
h : x.fst = j
⊢ (fun i j_1 => X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) i ⟶ X (f j) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
|
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
y : (f j).ι
h : x.fst = j
h' : h ▸ x.snd = y
⊢ (fun i j_1 => X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) i ⟶ X (f j) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
|
apply eqToHom
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case p
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
y : (f j).ι
h : x.fst = j
h' : h ▸ x.snd = y
⊢ X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
|
substs h h'
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case p
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
x : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
⊢ X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f x.fst) ((_ : x.fst = x.fst) ▸ x.snd)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
|
rfl
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (f j).ι
y : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
⊢ (fun i j_1 => X (f j) i ⟶ X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
|
refine' if h : y.1 = j then _ else 0
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (f j).ι
y : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
h : y.fst = j
⊢ (fun i j_1 => X (f j) i ⟶ X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
|
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (f j).ι
y : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
h : y.fst = j
h' : h ▸ y.snd = x
⊢ (fun i j_1 => X (f j) i ⟶ X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) j_1) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
|
apply eqToHom
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case p
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (f j).ι
y : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
h : y.fst = j
h' : h ▸ y.snd = x
⊢ X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
|
substs h h'
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case p
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
y : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι
⊢ X (f y.fst) ((_ : y.fst = y.fst) ▸ y.snd) = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
|
rfl
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
⊢ (fun j x y =>
if h : y.fst = j then
if h' : h ▸ y.snd = x then
eqToHom (_ : X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y)
else 0
else 0)
j ≫
(fun j x y =>
if h : x.fst = j then
if h' : h ▸ x.snd = y then
eqToHom (_ : X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y)
else 0
else 0)
j' =
if h : j = j' then eqToHom (_ : f j = f j') else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
|
ext x y
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ ((fun j x y =>
if h : y.fst = j then
if h' : h ▸ y.snd = x then
eqToHom (_ : X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y)
else 0
else 0)
j ≫
(fun j x y =>
if h : x.fst = j then
if h' : h ▸ x.snd = y then
eqToHom (_ : X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y)
else 0
else 0)
j')
x y =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
|
dsimp
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (∑ j_1 : (j : Fin n) × (f j).ι,
(if h : j_1.fst = j then if h' : h ▸ j_1.snd = x then eqToHom (_ : X (f j) x = X (f j_1.fst) j_1.snd) else 0
else 0) ≫
if h : j_1.fst = j' then if h' : h ▸ j_1.snd = y then eqToHom (_ : X (f j_1.fst) j_1.snd = X (f j') y) else 0
else 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
|
simp_rw [dite_comp, comp_dite]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (∑ x_1 : (j : Fin n) × (f j).ι,
if h : x_1.fst = j then
if h_1 : (_ : x_1.fst = j) ▸ x_1.snd = x then
if h_2 : x_1.fst = j' then
if h_3 : (_ : x_1.fst = j') ▸ x_1.snd = y then
eqToHom (_ : X (f j) x = X (f x_1.fst) x_1.snd) ≫ eqToHom (_ : X (f x_1.fst) x_1.snd = X (f j') y)
else eqToHom (_ : X (f j) x = X (f x_1.fst) x_1.snd) ≫ 0
else eqToHom (_ : X (f j) x = X (f x_1.fst) x_1.snd) ≫ 0
else
if h : x_1.fst = j' then
if h_2 : (_ : x_1.fst = j') ▸ x_1.snd = y then 0 ≫ eqToHom (_ : X (f x_1.fst) x_1.snd = X (f j') y)
else 0 ≫ 0
else 0 ≫ 0
else
if h : x_1.fst = j' then
if h_1 : (_ : x_1.fst = j') ▸ x_1.snd = y then 0 ≫ eqToHom (_ : X (f x_1.fst) x_1.snd = X (f j') y) else 0 ≫ 0
else 0 ≫ 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
|
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (∑ x_1 : (j : Fin n) × (f j).ι,
if h : x_1.fst = j then
if h_1 : (_ : x_1.fst = j) ▸ x_1.snd = x then
if h_2 : x_1.fst = j' then
if h_3 : (_ : x_1.fst = j') ▸ x_1.snd = y then eqToHom (_ : X (f j) x = X (f j') y) else 0
else 0
else 0
else 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
|
erw [Finset.sum_sigma]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (∑ a : Fin n,
∑ s in (fun x => Finset.univ) a,
if h : { fst := a, snd := s }.fst = j then
if h_1 : (_ : { fst := a, snd := s }.fst = j) ▸ { fst := a, snd := s }.snd = x then
if h_2 : { fst := a, snd := s }.fst = j' then
if h_3 : (_ : { fst := a, snd := s }.fst = j') ▸ { fst := a, snd := s }.snd = y then
eqToHom (_ : X (f j) x = X (f j') y)
else 0
else 0
else 0
else 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
|
dsimp
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (∑ a : Fin n,
∑ s : (f a).ι,
if h : a = j then
if h_1 : (_ : a = j) ▸ s = x then
if h_2 : a = j' then if h_3 : (_ : a = j') ▸ s = y then eqToHom (_ : X (f j) x = X (f j') y) else 0 else 0
else 0
else 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
|
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
⊢ (if h : j = j' then if h_1 : (_ : j = j') ▸ x = y then eqToHom (_ : X (f j) x = X (f j') y) else 0 else 0) =
dite (j = j') (fun h => eqToHom (_ : f j = f j')) (fun h => 0) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
|
split_ifs with h h'
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
h : j = j'
h' : (_ : j = j') ▸ x = y
⊢ eqToHom (_ : X (f j) x = X (f j') y) = eqToHom (_ : f j = f j') x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
·
|
substs h h'
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x : (f j).ι
⊢ eqToHom (_ : X (f j) x = X (f j) ((_ : j = j) ▸ x)) = eqToHom (_ : f j = f j) x ((_ : j = j) ▸ x)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
|
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
h : j = j'
h' : ¬(_ : j = j') ▸ x = y
⊢ 0 = eqToHom (_ : f j = f j') x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
·
|
subst h
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j : Fin n
x y : (f j).ι
h' : ¬(_ : j = j) ▸ x = y
⊢ 0 = eqToHom (_ : f j = f j) x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
|
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
j j' : Fin n
x : (f j).ι
y : (f j').ι
h : ¬j = j'
⊢ 0 = OfNat.ofNat 0 x y
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
·
|
rfl
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
⊢ ∑ j : Fin n,
Bicone.π
(Bicone.mk (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd)
(fun j x y =>
if h : x.fst = j then
if h' : h ▸ x.snd = y then
eqToHom (_ : X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y)
else 0
else 0)
fun j x y =>
if h : y.fst = j then
if h' : h ▸ y.snd = x then
eqToHom (_ : X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y)
else 0
else 0)
j ≫
Bicone.ι
(Bicone.mk (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd)
(fun j x y =>
if h : x.fst = j then
if h' : h ▸ x.snd = y then
eqToHom (_ : X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y)
else 0
else 0)
fun j x y =>
if h : y.fst = j then
if h' : h ▸ y.snd = x then
eqToHom (_ : X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y)
else 0
else 0)
j =
𝟙
(Bicone.mk (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd)
(fun j x y =>
if h : x.fst = j then
if h' : h ▸ x.snd = y then
eqToHom (_ : X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) x = X (f j) y)
else 0
else 0)
fun j x y =>
if h : y.fst = j then
if h' : h ▸ y.snd = x then
eqToHom (_ : X (f j) x = X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) y)
else 0
else 0).pt
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
|
dsimp
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
⊢ (∑ j : Fin n,
(fun x y =>
if h : x.fst = j then if h' : h ▸ x.snd = y then eqToHom (_ : X (f x.fst) x.snd = X (f j) y) else 0 else 0) ≫
fun x y =>
if h : y.fst = j then if h' : h ▸ y.snd = x then eqToHom (_ : X (f j) x = X (f y.fst) y.snd) else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
|
ext1 ⟨i, j⟩
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
⊢ ∀ (j_1 : (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd).ι),
Finset.sum Finset.univ
(fun j =>
(fun x y =>
if h : x.fst = j then if h' : h ▸ x.snd = y then eqToHom (_ : X (f x.fst) x.snd = X (f j) y) else 0
else 0) ≫
fun x y =>
if h : y.fst = j then if h' : h ▸ y.snd = x then eqToHom (_ : X (f j) x = X (f y.fst) y.snd) else 0 else 0)
{ fst := i, snd := j } j_1 =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } j_1
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
|
rintro ⟨i', j'⟩
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ Finset.sum Finset.univ
(fun j =>
(fun x y =>
if h : x.fst = j then if h' : h ▸ x.snd = y then eqToHom (_ : X (f x.fst) x.snd = X (f j) y) else 0
else 0) ≫
fun x y =>
if h : y.fst = j then if h' : h ▸ y.snd = x then eqToHom (_ : X (f j) x = X (f y.fst) y.snd) else 0 else 0)
{ fst := i, snd := j } { fst := i', snd := j' } =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
|
rw [Finset.sum_apply, Finset.sum_apply]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ∑ c : Fin n,
((fun x y =>
if h : x.fst = c then if h' : h ▸ x.snd = y then eqToHom (_ : X (f x.fst) x.snd = X (f c) y) else 0
else 0) ≫
fun x y =>
if h : y.fst = c then if h' : h ▸ y.snd = x then eqToHom (_ : X (f c) x = X (f y.fst) y.snd) else 0 else 0)
{ fst := i, snd := j } { fst := i', snd := j' } =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
|
dsimp
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ (∑ c : Fin n,
∑ j_1 : (f c).ι,
(if h : i = c then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f c) j_1) else 0 else 0) ≫
if h : i' = c then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f c) j_1 = X (f i') j') else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
|
rw [Finset.sum_eq_single i]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ (∑ j_1 : (f i).ι,
(if h : i = i then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f i) j_1) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f i) j_1 = X (f i') j') else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ∀ b ∈ Finset.univ,
b ≠ i →
(∑ j_1 : (f b).ι,
(if h : i = b then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f b) j_1) else 0 else 0) ≫
if h : i' = b then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f b) j_1 = X (f i') j') else 0 else 0) =
0
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ i ∉ Finset.univ →
(∑ j_1 : (f i).ι,
(if h : i = i then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f i) j_1) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f i) j_1 = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i];
|
rotate_left
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i];
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ∀ b ∈ Finset.univ,
b ≠ i →
(∑ j_1 : (f b).ι,
(if h : i = b then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f b) j_1) else 0 else 0) ≫
if h : i' = b then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f b) j_1 = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
·
|
intro b _ hb
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : Fin n
a✝ : b ∈ Finset.univ
hb : b ≠ i
⊢ (∑ j_1 : (f b).ι,
(if h : i = b then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f b) j_1) else 0 else 0) ≫
if h : i' = b then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f b) j_1 = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
|
apply Finset.sum_eq_zero
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : Fin n
a✝ : b ∈ Finset.univ
hb : b ≠ i
⊢ ∀ x ∈ Finset.univ,
((if h : i = b then if h' : h ▸ j = x then eqToHom (_ : X (f i) j = X (f b) x) else 0 else 0) ≫
if h : i' = b then if h' : h ▸ j' = x then eqToHom (_ : X (f b) x = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
|
intro x _
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : Fin n
a✝¹ : b ∈ Finset.univ
hb : b ≠ i
x : (f b).ι
a✝ : x ∈ Finset.univ
⊢ ((if h : i = b then if h' : h ▸ j = x then eqToHom (_ : X (f i) j = X (f b) x) else 0 else 0) ≫
if h : i' = b then if h' : h ▸ j' = x then eqToHom (_ : X (f b) x = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
|
rw [dif_neg hb.symm, zero_comp]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ i ∉ Finset.univ →
(∑ j_1 : (f i).ι,
(if h : i = i then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f i) j_1) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f i) j_1 = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
·
|
intro hi
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
hi : i ∉ Finset.univ
⊢ (∑ j_1 : (f i).ι,
(if h : i = i then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f i) j_1) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f i) j_1 = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
|
simp at hi
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ (∑ j_1 : (f i).ι,
(if h : i = i then if h' : h ▸ j = j_1 then eqToHom (_ : X (f i) j = X (f i) j_1) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j_1 then eqToHom (_ : X (f i) j_1 = X (f i') j') else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
|
rw [Finset.sum_eq_single j]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ((if h : i = i then if h' : h ▸ j = j then eqToHom (_ : X (f i) j = X (f i) j) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ∀ b ∈ Finset.univ,
b ≠ j →
((if h : i = i then if h' : h ▸ j = b then eqToHom (_ : X (f i) j = X (f i) b) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = b then eqToHom (_ : X (f i) b = X (f i') j') else 0 else 0) =
0
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ j ∉ Finset.univ →
((if h : i = i then if h' : h ▸ j = j then eqToHom (_ : X (f i) j = X (f i) j) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j];
|
rotate_left
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j];
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ∀ b ∈ Finset.univ,
b ≠ j →
((if h : i = i then if h' : h ▸ j = b then eqToHom (_ : X (f i) j = X (f i) b) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = b then eqToHom (_ : X (f i) b = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
·
|
intro b _ hb
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : (f i).ι
a✝ : b ∈ Finset.univ
hb : b ≠ j
⊢ ((if h : i = i then if h' : h ▸ j = b then eqToHom (_ : X (f i) j = X (f i) b) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = b then eqToHom (_ : X (f i) b = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
|
rw [dif_pos rfl, dif_neg, zero_comp]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀.hnc
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : (f i).ι
a✝ : b ∈ Finset.univ
hb : b ≠ j
⊢ ¬(_ : i = i) ▸ j = b
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
|
simp only
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₀.hnc
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
b : (f i).ι
a✝ : b ∈ Finset.univ
hb : b ≠ j
⊢ ¬j = b
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
|
tauto
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ j ∉ Finset.univ →
((if h : i = i then if h' : h ▸ j = j then eqToHom (_ : X (f i) j = X (f i) j) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
·
|
intro hj
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
hj : j ∉ Finset.univ
⊢ ((if h : i = i then if h' : h ▸ j = j then eqToHom (_ : X (f i) j = X (f i) j) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
|
simp at hj
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ ((if h : i = i then if h' : h ▸ j = j then eqToHom (_ : X (f i) j = X (f i) j) else 0 else 0) ≫
if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
𝟙 (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } { fst := i', snd := j' }
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
|
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
⊢ (if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
if h : i = i' ∧ HEq j j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
|
by_cases h : i' = i
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
h : i' = i
⊢ (if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
if h : i = i' ∧ HEq j j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
·
|
subst h
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' j : (f i').ι
⊢ (if h : i' = i' then if h' : h ▸ j' = j then eqToHom (_ : X (f i') j = X (f i') j') else 0 else 0) =
if h : i' = i' ∧ HEq j j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
|
rw [dif_pos rfl]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' j : (f i').ι
⊢ (if h' : (_ : i' = i') ▸ j' = j then eqToHom (_ : X (f i') j = X (f i') j') else 0) =
if h : i' = i' ∧ HEq j j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
|
simp only [heq_eq_eq, true_and]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' j : (f i').ι
⊢ (if h' : j' = j then eqToHom (_ : X (f i') j = X (f i') j') else 0) =
if h : j = j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
|
by_cases h : j' = j
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' j : (f i').ι
h : j' = j
⊢ (if h' : j' = j then eqToHom (_ : X (f i') j = X (f i') j') else 0) =
if h : j = j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
·
|
subst h
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case pos
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' : (f i').ι
⊢ (if h' : j' = j' then eqToHom (_ : X (f i') j' = X (f i') j') else 0) =
if h : j' = j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
|
simp
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i' : Fin n
j' j : (f i').ι
h : ¬j' = j
⊢ (if h' : j' = j then eqToHom (_ : X (f i') j = X (f i') j') else 0) =
if h : j = j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
·
|
rw [dif_neg h, dif_neg (Ne.symm h)]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
h : ¬i' = i
⊢ (if h : i' = i then if h' : h ▸ j' = j then eqToHom (_ : X (f i) j = X (f i') j') else 0 else 0) =
if h : i = i' ∧ HEq j j' then
eqToHom
(_ :
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i, snd := j } =
X (mk ((j : Fin n) × (f j).ι) fun p => X (f p.fst) p.snd) { fst := i', snd := j' })
else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
·
|
rw [dif_neg h, dif_neg]
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
·
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case neg.hnc
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
n : ℕ
f : Fin n → Mat_ C
i : Fin n
j : (f i).ι
i' : Fin n
j' : (f i').ι
h : ¬i' = i
⊢ ¬(i = i' ∧ HEq j j')
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
|
tauto
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
|
Mathlib.CategoryTheory.Preadditive.Mat.183_0.xG9GKY7NTklnF73
|
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
M : Mat_ C
⊢ (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by
|
cases M
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case mk
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
⊢ (mapMat_ (𝟭 C)).obj (Mat_.mk ι✝ X✝) = (𝟭 (Mat_ C)).obj (Mat_.mk ι✝ X✝)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M;
|
rfl
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M;
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
M N : Mat_ C
f : M ⟶ N
⊢ (mapMat_ (𝟭 C)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) N).hom =
((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) M).hom ≫ (𝟭 (Mat_ C)).map f
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
|
ext
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
M N : Mat_ C
f : M ⟶ N
i✝ : ((mapMat_ (𝟭 C)).obj M).ι
j✝ : ((𝟭 (Mat_ C)).obj N).ι
⊢ ((mapMat_ (𝟭 C)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) N).hom) i✝ j✝ =
(((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) M).hom ≫ (𝟭 (Mat_ C)).map f) i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
|
cases M
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
N : Mat_ C
j✝ : ((𝟭 (Mat_ C)).obj N).ι
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
f : Mat_.mk ι✝ X✝ ⟶ N
i✝ : ((mapMat_ (𝟭 C)).obj (Mat_.mk ι✝ X✝)).ι
⊢ ((mapMat_ (𝟭 C)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) N).hom) i✝ j✝ =
(((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) (Mat_.mk ι✝ X✝)).hom ≫ (𝟭 (Mat_ C)).map f) i✝
j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M;
|
cases N
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M;
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝³ : Category.{v₁, u₁} C
inst✝² : Preadditive C
D : Type u_1
inst✝¹ : Category.{v₁, u_1} D
inst✝ : Preadditive D
ι✝¹ : Type
fintype✝¹ : Fintype ι✝¹
X✝¹ : ι✝¹ → C
i✝ : ((mapMat_ (𝟭 C)).obj (Mat_.mk ι✝¹ X✝¹)).ι
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
j✝ : ((𝟭 (Mat_ C)).obj (Mat_.mk ι✝ X✝)).ι
f : Mat_.mk ι✝¹ X✝¹ ⟶ Mat_.mk ι✝ X✝
⊢ ((mapMat_ (𝟭 C)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) (Mat_.mk ι✝ X✝)).hom) i✝
j✝ =
(((fun M => eqToIso (_ : (mapMat_ (𝟭 C)).obj M = (𝟭 (Mat_ C)).obj M)) (Mat_.mk ι✝¹ X✝¹)).hom ≫ (𝟭 (Mat_ C)).map f)
i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
|
simp [comp_dite, dite_comp]
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
|
Mathlib.CategoryTheory.Preadditive.Mat.276_0.xG9GKY7NTklnF73
|
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C)
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
M : Mat_ C
⊢ (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by
|
cases M
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case mk
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
⊢ (mapMat_ (F ⋙ G)).obj (Mat_.mk ι✝ X✝) = (mapMat_ F ⋙ mapMat_ G).obj (Mat_.mk ι✝ X✝)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M;
|
rfl
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M;
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
M N : Mat_ C
f : M ⟶ N
⊢ (mapMat_ (F ⋙ G)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) N).hom =
((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) M).hom ≫
(mapMat_ F ⋙ mapMat_ G).map f
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
|
ext
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
M N : Mat_ C
f : M ⟶ N
i✝ : ((mapMat_ (F ⋙ G)).obj M).ι
j✝ : ((mapMat_ F ⋙ mapMat_ G).obj N).ι
⊢ ((mapMat_ (F ⋙ G)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) N).hom)
i✝ j✝ =
(((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) M).hom ≫
(mapMat_ F ⋙ mapMat_ G).map f)
i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
|
cases M
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
N : Mat_ C
j✝ : ((mapMat_ F ⋙ mapMat_ G).obj N).ι
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
f : Mat_.mk ι✝ X✝ ⟶ N
i✝ : ((mapMat_ (F ⋙ G)).obj (Mat_.mk ι✝ X✝)).ι
⊢ ((mapMat_ (F ⋙ G)).map f ≫ ((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) N).hom)
i✝ j✝ =
(((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) (Mat_.mk ι✝ X✝)).hom ≫
(mapMat_ F ⋙ mapMat_ G).map f)
i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M;
|
cases N
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M;
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.mk.mk
C : Type u₁
inst✝⁷ : Category.{v₁, u₁} C
inst✝⁶ : Preadditive C
D : Type u_1
inst✝⁵ : Category.{v₁, u_1} D
inst✝⁴ : Preadditive D
E : Type u_2
inst✝³ : Category.{v₁, u_2} E
inst✝² : Preadditive E
F : C ⥤ D
inst✝¹ : Additive F
G : D ⥤ E
inst✝ : Additive G
ι✝¹ : Type
fintype✝¹ : Fintype ι✝¹
X✝¹ : ι✝¹ → C
i✝ : ((mapMat_ (F ⋙ G)).obj (Mat_.mk ι✝¹ X✝¹)).ι
ι✝ : Type
fintype✝ : Fintype ι✝
X✝ : ι✝ → C
j✝ : ((mapMat_ F ⋙ mapMat_ G).obj (Mat_.mk ι✝ X✝)).ι
f : Mat_.mk ι✝¹ X✝¹ ⟶ Mat_.mk ι✝ X✝
⊢ ((mapMat_ (F ⋙ G)).map f ≫
((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) (Mat_.mk ι✝ X✝)).hom)
i✝ j✝ =
(((fun M => eqToIso (_ : (mapMat_ (F ⋙ G)).obj M = (mapMat_ F ⋙ mapMat_ G).obj M)) (Mat_.mk ι✝¹ X✝¹)).hom ≫
(mapMat_ F ⋙ mapMat_ G).map f)
i✝ j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
|
simp [comp_dite, dite_comp]
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
|
Mathlib.CategoryTheory.Preadditive.Mat.287_0.xG9GKY7NTklnF73
|
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
x✝ : C
⊢ { obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map (𝟙 x✝) =
𝟙 ({ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.obj x✝)
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by
|
ext ⟨⟩
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by
|
Mathlib.CategoryTheory.Preadditive.Mat.303_0.xG9GKY7NTklnF73
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.unit
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
x✝ : C
j✝ : ({ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.obj x✝).ι
⊢ { obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map (𝟙 x✝) PUnit.unit j✝ =
𝟙 ({ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.obj x✝) PUnit.unit j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩;
|
simp
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩;
|
Mathlib.CategoryTheory.Preadditive.Mat.303_0.xG9GKY7NTklnF73
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
X✝ Y✝ Z✝ : C
x✝¹ : X✝ ⟶ Y✝
x✝ : Y✝ ⟶ Z✝
⊢ { obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map (x✝¹ ≫ x✝) =
{ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map x✝¹ ≫
{ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map x✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by
|
ext ⟨⟩
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by
|
Mathlib.CategoryTheory.Preadditive.Mat.303_0.xG9GKY7NTklnF73
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case H.unit
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
X✝ Y✝ Z✝ : C
x✝¹ : X✝ ⟶ Y✝
x✝ : Y✝ ⟶ Z✝
j✝ : ({ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.obj Z✝).ι
⊢ { obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map (x✝¹ ≫ x✝) PUnit.unit j✝ =
({ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map x✝¹ ≫
{ obj := fun X => mk PUnit.{1} fun x => X, map := fun {X Y} f x x => f }.map x✝)
PUnit.unit j✝
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩;
|
simp
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩;
|
Mathlib.CategoryTheory.Preadditive.Mat.303_0.xG9GKY7NTklnF73
|
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
⊢ ((biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫
biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) =
𝟙 M
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
|
simp only [biproduct.lift_desc]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
⊢ (∑ j : M.ι,
(fun j_1 k => if h : j_1 = j then eqToHom (_ : X M j_1 = X M j) else 0) ≫ fun j_1 k =>
if h : j = k then eqToHom (_ : X M j = X M k) else 0) =
𝟙 M
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
|
funext i j
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ Finset.sum Finset.univ
(fun j =>
(fun j_1 k => if h : j_1 = j then eqToHom (_ : X M j_1 = X M j) else 0) ≫ fun j_1 k =>
if h : j = k then eqToHom (_ : X M j = X M k) else 0)
i j =
𝟙 M i j
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
|
dsimp [id_def]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ Finset.sum Finset.univ
(fun j =>
(fun j_1 k => if h : j_1 = j then eqToHom (_ : X M j_1 = X M j) else 0) ≫ fun j_1 k =>
if h : j = k then eqToHom (_ : X M j = X M k) else 0)
i j =
if h : i = j then eqToHom (_ : X M i = X M j) else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
|
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ ((fun j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫ fun j k =>
if h : i = k then eqToHom (_ : X M i = X M k) else 0)
i j =
if h : i = j then eqToHom (_ : X M i = X M j) else 0
case h.h.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ ∀ b ∈ Finset.univ,
b ≠ i →
((fun j k => if h : j = b then eqToHom (_ : X M j = X M b) else 0) ≫ fun j k =>
if h : b = k then eqToHom (_ : X M b = X M k) else 0)
i j =
0
case h.h.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ i ∉ Finset.univ →
((fun j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫ fun j k =>
if h : i = k then eqToHom (_ : X M i = X M k) else 0)
i j =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i];
|
rotate_left
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i];
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ ∀ b ∈ Finset.univ,
b ≠ i →
((fun j k => if h : j = b then eqToHom (_ : X M j = X M b) else 0) ≫ fun j k =>
if h : b = k then eqToHom (_ : X M b = X M k) else 0)
i j =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
·
|
intro b _ hb
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
·
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j b : M.ι
a✝ : b ∈ Finset.univ
hb : b ≠ i
⊢ ((fun j k => if h : j = b then eqToHom (_ : X M j = X M b) else 0) ≫ fun j k =>
if h : b = k then eqToHom (_ : X M b = X M k) else 0)
i j =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
|
dsimp
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j b : M.ι
a✝ : b ∈ Finset.univ
hb : b ≠ i
⊢ (∑ j_1 in {PUnit.unit},
(if h : i = b then eqToHom (_ : X M i = X M b) else 0) ≫ if h : b = j then eqToHom (_ : X M b = X M j) else 0) =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
|
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₀
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j b : M.ι
a✝ : b ∈ Finset.univ
hb : b ≠ i
⊢ ((if h : i = b then eqToHom (_ : X M i = X M b) else 0) ≫ if h : b = j then eqToHom (_ : X M b = X M j) else 0) = 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
|
rw [dif_neg hb.symm, zero_comp]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ i ∉ Finset.univ →
((fun j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫ fun j k =>
if h : i = k then eqToHom (_ : X M i = X M k) else 0)
i j =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
·
|
intro h
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
·
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h.h₁
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
h : i ∉ Finset.univ
⊢ ((fun j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫ fun j k =>
if h : i = k then eqToHom (_ : X M i = X M k) else 0)
i j =
0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
|
simp at h
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case h.h
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ ((fun j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫ fun j k =>
if h : i = k then eqToHom (_ : X M i = X M k) else 0)
i j =
if h : i = j then eqToHom (_ : X M i = X M j) else 0
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
|
simp
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
⊢ ((biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) ≫
biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) =
𝟙 (⨁ fun i => (embedding C).obj (X M i))
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
|
apply biproduct.hom_ext
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case w
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
⊢ ∀ (j : M.ι),
((biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) ≫
biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫
biproduct.π (fun i => (embedding C).obj (X M i)) j =
𝟙 (⨁ fun i => (embedding C).obj (X M i)) ≫ biproduct.π (fun i => (embedding C).obj (X M i)) j
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
|
intro i
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case w
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i : M.ι
⊢ ((biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) ≫
biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫
biproduct.π (fun i => (embedding C).obj (X M i)) i =
𝟙 (⨁ fun i => (embedding C).obj (X M i)) ≫ biproduct.π (fun i => (embedding C).obj (X M i)) i
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
|
apply biproduct.hom_ext'
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case w.w
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i : M.ι
⊢ ∀ (j : M.ι),
biproduct.ι (fun i => (embedding C).obj (X M i)) j ≫
((biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) ≫
biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫
biproduct.π (fun i => (embedding C).obj (X M i)) i =
biproduct.ι (fun i => (embedding C).obj (X M i)) j ≫
𝟙 (⨁ fun i => (embedding C).obj (X M i)) ≫ biproduct.π (fun i => (embedding C).obj (X M i)) i
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
apply biproduct.hom_ext'
|
intro j
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
apply biproduct.hom_ext'
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
case w.w
C : Type u₁
inst✝¹ : Category.{v₁, u₁} C
inst✝ : Preadditive C
M : Mat_ C
i j : M.ι
⊢ biproduct.ι (fun i => (embedding C).obj (X M i)) j ≫
((biproduct.desc fun i j k => if h : i = k then eqToHom (_ : X M i = X M k) else 0) ≫
biproduct.lift fun i j k => if h : j = i then eqToHom (_ : X M j = X M i) else 0) ≫
biproduct.π (fun i => (embedding C).obj (X M i)) i =
biproduct.ι (fun i => (embedding C).obj (X M i)) j ≫
𝟙 (⨁ fun i => (embedding C).obj (X M i)) ≫ biproduct.π (fun i => (embedding C).obj (X M i)) i
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Basic
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.CategoryTheory.Limits.Shapes.Biproducts
import Mathlib.CategoryTheory.Preadditive.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.Data.Matrix.DMatrix
import Mathlib.Data.Matrix.Basic
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.CategoryTheory.Preadditive.SingleObj
import Mathlib.Algebra.Opposites
#align_import category_theory.preadditive.Mat from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Matrices over a category.
When `C` is a preadditive category, `Mat_ C` is the preadditive category
whose objects are finite tuples of objects in `C`, and
whose morphisms are matrices of morphisms from `C`.
There is a functor `Mat_.embedding : C ⥤ Mat_ C` sending morphisms to one-by-one matrices.
`Mat_ C` has finite biproducts.
## The additive envelope
We show that this construction is the "additive envelope" of `C`,
in the sense that any additive functor `F : C ⥤ D` to a category `D` with biproducts
lifts to a functor `Mat_.lift F : Mat_ C ⥤ D`,
Moreover, this functor is unique (up to natural isomorphisms) amongst functors `L : Mat_ C ⥤ D`
such that `embedding C ⋙ L ≅ F`.
(As we don't have 2-category theory, we can't explicitly state that `Mat_ C` is
the initial object in the 2-category of categories under `C` which have biproducts.)
As a consequence, when `C` already has finite biproducts we have `Mat_ C ≌ C`.
## Future work
We should provide a more convenient `Mat R`, when `R` is a ring,
as a category with objects `n : FinType`,
and whose morphisms are matrices with components in `R`.
Ideally this would conveniently interact with both `Mat_` and `Matrix`.
-/
open CategoryTheory CategoryTheory.Preadditive
open scoped BigOperators Classical
noncomputable section
namespace CategoryTheory
universe w v₁ v₂ u₁ u₂
variable (C : Type u₁) [Category.{v₁} C] [Preadditive C]
/-- An object in `Mat_ C` is a finite tuple of objects in `C`.
-/
structure Mat_ where
ι : Type
[fintype : Fintype ι]
X : ι → C
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_ CategoryTheory.Mat_
attribute [instance] Mat_.fintype
namespace Mat_
variable {C}
-- porting note: removed @[nolint has_nonempty_instance]
/-- A morphism in `Mat_ C` is a dependently typed matrix of morphisms. -/
def Hom (M N : Mat_ C) : Type v₁ :=
DMatrix M.ι N.ι fun i j => M.X i ⟶ N.X j
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom CategoryTheory.Mat_.Hom
namespace Hom
/-- The identity matrix consists of identity morphisms on the diagonal, and zeros elsewhere. -/
def id (M : Mat_ C) : Hom M M := fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.id CategoryTheory.Mat_.Hom.id
/-- Composition of matrices using matrix multiplication. -/
def comp {M N K : Mat_ C} (f : Hom M N) (g : Hom N K) : Hom M K := fun i k =>
∑ j : N.ι, f i j ≫ g j k
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.hom.comp CategoryTheory.Mat_.Hom.comp
end Hom
section
attribute [local simp] Hom.id Hom.comp
instance : Category.{v₁} (Mat_ C) where
Hom := Hom
id := Hom.id
comp f g := f.comp g
id_comp f := by simp (config := { unfoldPartialApp := true }) [dite_comp]
comp_id f := by simp (config := { unfoldPartialApp := true }) [comp_dite]
assoc f g h := by
apply DMatrix.ext
intros
simp_rw [Hom.comp, sum_comp, comp_sum, Category.assoc]
rw [Finset.sum_comm]
-- porting note: added because `DMatrix.ext` is not triggered automatically
-- See https://github.com/leanprover-community/mathlib4/issues/5229
@[ext]
theorem hom_ext {M N : Mat_ C} (f g : M ⟶ N) (H : ∀ i j, f i j = g i j) : f = g :=
DMatrix.ext_iff.mp H
theorem id_def (M : Mat_ C) :
(𝟙 M : Hom M M) = fun i j => if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_def CategoryTheory.Mat_.id_def
theorem id_apply (M : Mat_ C) (i j : M.ι) :
(𝟙 M : Hom M M) i j = if h : i = j then eqToHom (congr_arg M.X h) else 0 :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply CategoryTheory.Mat_.id_apply
@[simp]
theorem id_apply_self (M : Mat_ C) (i : M.ι) : (𝟙 M : Hom M M) i i = 𝟙 _ := by simp [id_apply]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_self CategoryTheory.Mat_.id_apply_self
@[simp]
theorem id_apply_of_ne (M : Mat_ C) (i j : M.ι) (h : i ≠ j) : (𝟙 M : Hom M M) i j = 0 := by
simp [id_apply, h]
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.id_apply_of_ne CategoryTheory.Mat_.id_apply_of_ne
theorem comp_def {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) :
f ≫ g = fun i k => ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_def CategoryTheory.Mat_.comp_def
@[simp]
theorem comp_apply {M N K : Mat_ C} (f : M ⟶ N) (g : N ⟶ K) (i k) :
(f ≫ g) i k = ∑ j : N.ι, f i j ≫ g j k :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.comp_apply CategoryTheory.Mat_.comp_apply
instance (M N : Mat_ C) : Inhabited (M ⟶ N) :=
⟨fun i j => (0 : M.X i ⟶ N.X j)⟩
end
-- porting note: to ease the construction of the preadditive structure, the `AddCommGroup`
-- was introduced separately and the lemma `add_apply` was moved upwards
instance (M N : Mat_ C) : AddCommGroup (M ⟶ N) := by
change AddCommGroup (DMatrix M.ι N.ι _)
infer_instance
@[simp]
theorem add_apply {M N : Mat_ C} (f g : M ⟶ N) (i j) : (f + g) i j = f i j + g i j :=
rfl
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.add_apply CategoryTheory.Mat_.add_apply
instance : Preadditive (Mat_ C) where
add_comp M N K f f' g := by ext; simp [Finset.sum_add_distrib]
comp_add M N K f g g' := by ext; simp [Finset.sum_add_distrib]
open CategoryTheory.Limits
/-- We now prove that `Mat_ C` has finite biproducts.
Be warned, however, that `Mat_ C` is not necessarily Krull-Schmidt,
and so the internal indexing of a biproduct may have nothing to do with the external indexing,
even though the construction we give uses a sigma type.
See however `isoBiproductEmbedding`.
-/
instance hasFiniteBiproducts : HasFiniteBiproducts (Mat_ C) where
out n :=
{ has_biproduct := fun f =>
hasBiproduct_of_total
{ pt := ⟨Σ j, (f j).ι, fun p => (f p.1).X p.2⟩
π := fun j x y => by
refine' if h : x.1 = j then _ else 0
refine' if h' : @Eq.ndrec (Fin n) x.1 (fun j => (f j).ι) x.2 _ h = y then _ else 0
apply eqToHom
substs h h'
rfl
-- Notice we were careful not to use `subst` until we had a goal in `Prop`.
ι := fun j x y => by
refine' if h : y.1 = j then _ else 0
refine' if h' : @Eq.ndrec _ y.1 (fun j => (f j).ι) y.2 _ h = x then _ else 0
apply eqToHom
substs h h'
rfl
ι_π := fun j j' => by
ext x y
dsimp
simp_rw [dite_comp, comp_dite]
simp only [ite_self, dite_eq_ite, dif_ctx_congr, Limits.comp_zero, Limits.zero_comp,
eqToHom_trans, Finset.sum_congr]
erw [Finset.sum_sigma]
dsimp
simp only [if_congr, if_true, dif_ctx_congr, Finset.sum_dite_irrel, Finset.mem_univ,
Finset.sum_const_zero, Finset.sum_congr, Finset.sum_dite_eq']
split_ifs with h h'
· substs h h'
simp only [CategoryTheory.eqToHom_refl, CategoryTheory.Mat_.id_apply_self]
· subst h
rw [eqToHom_refl, id_apply_of_ne _ _ _ h']
· rfl }
(by
dsimp
ext1 ⟨i, j⟩
rintro ⟨i', j'⟩
rw [Finset.sum_apply, Finset.sum_apply]
dsimp
rw [Finset.sum_eq_single i]; rotate_left
· intro b _ hb
apply Finset.sum_eq_zero
intro x _
rw [dif_neg hb.symm, zero_comp]
· intro hi
simp at hi
rw [Finset.sum_eq_single j]; rotate_left
· intro b _ hb
rw [dif_pos rfl, dif_neg, zero_comp]
simp only
tauto
· intro hj
simp at hj
simp only [eqToHom_refl, dite_eq_ite, ite_true, Category.id_comp, ne_eq,
Sigma.mk.inj_iff, not_and, id_def]
by_cases h : i' = i
· subst h
rw [dif_pos rfl]
simp only [heq_eq_eq, true_and]
by_cases h : j' = j
· subst h
simp
· rw [dif_neg h, dif_neg (Ne.symm h)]
· rw [dif_neg h, dif_neg]
tauto) }
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.has_finite_biproducts CategoryTheory.Mat_.hasFiniteBiproducts
end Mat_
namespace Functor
variable {C} {D : Type*} [Category.{v₁} D] [Preadditive D]
attribute [local simp] Mat_.id_apply eqToHom_map
/-- A functor induces a functor of matrix categories.
-/
@[simps]
def mapMat_ (F : C ⥤ D) [Functor.Additive F] : Mat_ C ⥤ Mat_ D where
obj M := ⟨M.ι, fun i => F.obj (M.X i)⟩
map f i j := F.map (f i j)
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_ CategoryTheory.Functor.mapMat_
/-- The identity functor induces the identity functor on matrix categories.
-/
@[simps!]
def mapMatId : (𝟭 C).mapMat_ ≅ 𝟭 (Mat_ C) :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_id CategoryTheory.Functor.mapMatId
/-- Composite functors induce composite functors on matrix categories.
-/
@[simps!]
def mapMatComp {E : Type*} [Category.{v₁} E] [Preadditive E] (F : C ⥤ D) [Functor.Additive F]
(G : D ⥤ E) [Functor.Additive G] : (F ⋙ G).mapMat_ ≅ F.mapMat_ ⋙ G.mapMat_ :=
NatIso.ofComponents (fun M => eqToIso (by cases M; rfl)) fun {M N} f => by
ext
cases M; cases N
simp [comp_dite, dite_comp]
set_option linter.uppercaseLean3 false in
#align category_theory.functor.map_Mat_comp CategoryTheory.Functor.mapMatComp
end Functor
namespace Mat_
/-- The embedding of `C` into `Mat_ C` as one-by-one matrices.
(We index the summands by `punit`.) -/
@[simps]
def embedding : C ⥤ Mat_ C where
obj X := ⟨PUnit, fun _ => X⟩
map f _ _ := f
map_id _ := by ext ⟨⟩; simp
map_comp _ _ := by ext ⟨⟩; simp
set_option linter.uppercaseLean3 false in
#align category_theory.Mat_.embedding CategoryTheory.Mat_.embedding
namespace Embedding
instance : Faithful (embedding C) where
map_injective h := congr_fun (congr_fun h PUnit.unit) PUnit.unit
instance : Full (embedding C) where preimage f := f PUnit.unit PUnit.unit
instance : Functor.Additive (embedding C) where
end Embedding
instance [Inhabited C] : Inhabited (Mat_ C) :=
⟨(embedding C).obj default⟩
open CategoryTheory.Limits
variable {C}
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
apply biproduct.hom_ext'
intro j
|
simp only [Category.id_comp, Category.assoc, biproduct.lift_π, biproduct.ι_desc_assoc,
biproduct.ι_π]
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom := biproduct.lift fun i j k => if h : j = i then eqToHom (congr_arg M.X h) else 0
inv := biproduct.desc fun i j k => if h : i = k then eqToHom (congr_arg M.X h) else 0
hom_inv_id := by
simp only [biproduct.lift_desc]
funext i j
dsimp [id_def]
rw [Finset.sum_apply, Finset.sum_apply, Finset.sum_eq_single i]; rotate_left
· intro b _ hb
dsimp
simp only [Finset.sum_const, Finset.card_singleton, one_smul]
rw [dif_neg hb.symm, zero_comp]
· intro h
simp at h
simp
inv_hom_id := by
apply biproduct.hom_ext
intro i
apply biproduct.hom_ext'
intro j
|
Mathlib.CategoryTheory.Preadditive.Mat.332_0.xG9GKY7NTklnF73
|
/-- Every object in `Mat_ C` is isomorphic to the biproduct of its summands.
-/
@[simps]
def isoBiproductEmbedding (M : Mat_ C) : M ≅ ⨁ fun i => (embedding C).obj (M.X i) where
hom
|
Mathlib_CategoryTheory_Preadditive_Mat
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.