Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
/- | |
Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. | |
Released under Apache 2.0 license as described in the file LICENSE. | |
Authors: Johannes HΓΆlzl, Patrick Massot, Casper Putz, Anne Baanen | |
-/ | |
import linear_algebra.matrix.determinant | |
/-! | |
# Changing the index type of a matrix | |
This file concerns the map `matrix.reindex`, mapping a `m` by `n` matrix | |
to an `m'` by `n'` matrix, as long as `m β m'` and `n β n'`. | |
## Main definitions | |
* `matrix.reindex_linear_equiv R A`: `matrix.reindex` is an `R`-linear equivalence between | |
`A`-matrices. | |
* `matrix.reindex_alg_equiv R`: `matrix.reindex` is an `R`-algebra equivalence between `R`-matrices. | |
## Tags | |
matrix, reindex | |
-/ | |
namespace matrix | |
open equiv | |
open_locale matrix | |
variables {l m n o : Type*} {l' m' n' o' : Type*} {m'' n'' : Type*} | |
variables (R A : Type*) | |
section add_comm_monoid | |
variables [semiring R] [add_comm_monoid A] [module R A] | |
/-- The natural map that reindexes a matrix's rows and columns with equivalent types, | |
`matrix.reindex`, is a linear equivalence. -/ | |
def reindex_linear_equiv (eβ : m β m') (eβ : n β n') : matrix m n A ββ[R] matrix m' n' A := | |
{ map_add' := Ξ» _ _, rfl, | |
map_smul' := Ξ» _ _, rfl, | |
..(reindex eβ eβ)} | |
@[simp] lemma reindex_linear_equiv_apply | |
(eβ : m β m') (eβ : n β n') (M : matrix m n A) : | |
reindex_linear_equiv R A eβ eβ M = reindex eβ eβ M := | |
rfl | |
@[simp] lemma reindex_linear_equiv_symm (eβ : m β m') (eβ : n β n') : | |
(reindex_linear_equiv R A eβ eβ).symm = reindex_linear_equiv R A eβ.symm eβ.symm := | |
rfl | |
@[simp] lemma reindex_linear_equiv_refl_refl : | |
reindex_linear_equiv R A (equiv.refl m) (equiv.refl n) = linear_equiv.refl R _ := | |
linear_equiv.ext $ Ξ» _, rfl | |
lemma reindex_linear_equiv_trans (eβ : m β m') (eβ : n β n') (eβ' : m' β m'') | |
(eβ' : n' β n'') : (reindex_linear_equiv R A eβ eβ).trans (reindex_linear_equiv R A eβ' eβ') = | |
(reindex_linear_equiv R A (eβ.trans eβ') (eβ.trans eβ') : _ ββ[R] _) := | |
by { ext, refl } | |
lemma reindex_linear_equiv_comp (eβ : m β m') (eβ : n β n') (eβ' : m' β m'') | |
(eβ' : n' β n'') : | |
(reindex_linear_equiv R A eβ' eβ') β (reindex_linear_equiv R A eβ eβ) | |
= reindex_linear_equiv R A (eβ.trans eβ') (eβ.trans eβ') := | |
by { rw [β reindex_linear_equiv_trans], refl } | |
lemma reindex_linear_equiv_comp_apply (eβ : m β m') (eβ : n β n') (eβ' : m' β m'') | |
(eβ' : n' β n'') (M : matrix m n A) : | |
(reindex_linear_equiv R A eβ' eβ') (reindex_linear_equiv R A eβ eβ M) = | |
reindex_linear_equiv R A (eβ.trans eβ') (eβ.trans eβ') M := | |
minor_minor _ _ _ _ _ | |
lemma reindex_linear_equiv_one [decidable_eq m] [decidable_eq m'] [has_one A] | |
(e : m β m') : (reindex_linear_equiv R A e e (1 : matrix m m A)) = 1 := | |
minor_one_equiv e.symm | |
end add_comm_monoid | |
section semiring | |
variables [semiring R] [semiring A] [module R A] | |
lemma reindex_linear_equiv_mul [fintype n] [fintype n'] | |
(eβ : m β m') (eβ : n β n') (eβ : o β o') (M : matrix m n A) (N : matrix n o A) : | |
reindex_linear_equiv R A eβ eβ M β¬ reindex_linear_equiv R A eβ eβ N = | |
reindex_linear_equiv R A eβ eβ (M β¬ N) := | |
minor_mul_equiv M N _ _ _ | |
lemma mul_reindex_linear_equiv_one [fintype n] [fintype o] [decidable_eq o] (eβ : o β n) | |
(eβ : o β n') (M : matrix m n A) : M.mul (reindex_linear_equiv R A eβ eβ 1) = | |
reindex_linear_equiv R A (equiv.refl m) (eβ.symm.trans eβ) M := | |
mul_minor_one _ _ _ | |
end semiring | |
section algebra | |
variables [comm_semiring R] [fintype n] [fintype m] [decidable_eq m] [decidable_eq n] | |
/-- | |
For square matrices with coefficients in commutative semirings, the natural map that reindexes | |
a matrix's rows and columns with equivalent types, `matrix.reindex`, is an equivalence of algebras. | |
-/ | |
def reindex_alg_equiv (e : m β n) : matrix m m R ββ[R] matrix n n R := | |
{ to_fun := reindex e e, | |
map_mul' := Ξ» a b, (reindex_linear_equiv_mul R R e e e a b).symm, | |
commutes' := Ξ» r, by simp [algebra_map, algebra.to_ring_hom, minor_smul], | |
..(reindex_linear_equiv R R e e) } | |
@[simp] lemma reindex_alg_equiv_apply (e : m β n) (M : matrix m m R) : | |
reindex_alg_equiv R e M = reindex e e M := | |
rfl | |
@[simp] lemma reindex_alg_equiv_symm (e : m β n) : | |
(reindex_alg_equiv R e).symm = reindex_alg_equiv R e.symm := | |
rfl | |
@[simp] lemma reindex_alg_equiv_refl : reindex_alg_equiv R (equiv.refl m) = alg_equiv.refl := | |
alg_equiv.ext $ Ξ» _, rfl | |
lemma reindex_alg_equiv_mul (e : m β n) (M : matrix m m R) (N : matrix m m R) : | |
reindex_alg_equiv R e (M β¬ N) = reindex_alg_equiv R e M β¬ reindex_alg_equiv R e N := | |
(reindex_alg_equiv R e).map_mul M N | |
end algebra | |
/-- Reindexing both indices along the same equivalence preserves the determinant. | |
For the `simp` version of this lemma, see `det_minor_equiv_self`. | |
-/ | |
lemma det_reindex_linear_equiv_self [comm_ring R] [fintype m] [decidable_eq m] | |
[fintype n] [decidable_eq n] (e : m β n) (M : matrix m m R) : | |
det (reindex_linear_equiv R R e e M) = det M := | |
det_reindex_self e M | |
/-- Reindexing both indices along the same equivalence preserves the determinant. | |
For the `simp` version of this lemma, see `det_minor_equiv_self`. | |
-/ | |
lemma det_reindex_alg_equiv [comm_ring R] [fintype m] [decidable_eq m] [fintype n] [decidable_eq n] | |
(e : m β n) (A : matrix m m R) : | |
det (reindex_alg_equiv R e A) = det A := | |
det_reindex_self e A | |
end matrix | |