Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 90475a9

Browse files
committed
refactor(data/matrix): put std_basis_matrix in its own file (#9088)
The authors here are recovered from the git history. I've avoided the temptation to generalize typeclasses in this PR; the lemmas are copied to this file unmodified.
1 parent 9568977 commit 90475a9

File tree

4 files changed

+96
-77
lines changed

4 files changed

+96
-77
lines changed

src/data/matrix/basic.lean

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,82 +1048,6 @@ by { ext, rw [←diagonal_one, vec_mul_diagonal, mul_one] }
10481048

10491049
end non_assoc_semiring
10501050

1051-
section semiring
1052-
variables [semiring α]
1053-
1054-
variables [decidable_eq m] [decidable_eq n]
1055-
1056-
/--
1057-
`std_basis_matrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column,
1058-
and zeroes elsewhere.
1059-
-/
1060-
def std_basis_matrix (i : m) (j : n) (a : α) : matrix m n α :=
1061-
(λ i' j', if i' = i ∧ j' = j then a else 0)
1062-
1063-
@[simp] lemma smul_std_basis_matrix (i : m) (j : n) (a b : α) :
1064-
b • std_basis_matrix i j a = std_basis_matrix i j (b • a) :=
1065-
by { unfold std_basis_matrix, ext, simp }
1066-
1067-
@[simp] lemma std_basis_matrix_zero (i : m) (j : n) :
1068-
std_basis_matrix i j (0 : α) = 0 :=
1069-
by { unfold std_basis_matrix, ext, simp }
1070-
1071-
lemma std_basis_matrix_add (i : m) (j : n) (a b : α) :
1072-
std_basis_matrix i j (a + b) = std_basis_matrix i j a + std_basis_matrix i j b :=
1073-
begin
1074-
unfold std_basis_matrix, ext,
1075-
split_ifs with h; simp [h],
1076-
end
1077-
1078-
lemma matrix_eq_sum_std_basis (x : matrix n m α) [fintype n] [fintype m] :
1079-
x = ∑ (i : n) (j : m), std_basis_matrix i j (x i j) :=
1080-
begin
1081-
ext, symmetry,
1082-
iterate 2 { rw finset.sum_apply },
1083-
convert fintype.sum_eq_single i _,
1084-
{ simp [std_basis_matrix] },
1085-
{ intros j hj,
1086-
simp [std_basis_matrix, hj.symm] }
1087-
end
1088-
1089-
-- TODO: tie this up with the `basis` machinery of linear algebra
1090-
-- this is not completely trivial because we are indexing by two types, instead of one
1091-
1092-
-- TODO: add `std_basis_vec`
1093-
lemma std_basis_eq_basis_mul_basis (i : m) (j : n) :
1094-
std_basis_matrix i j 1 = vec_mul_vec (λ i', ite (i = i') 1 0) (λ j', ite (j = j') 1 0) :=
1095-
begin
1096-
ext, norm_num [std_basis_matrix, vec_mul_vec],
1097-
split_ifs; tauto,
1098-
end
1099-
1100-
-- todo: the old proof used fintypes, I don't know `finsupp` but this feels generalizable
1101-
@[elab_as_eliminator] protected lemma induction_on' [fintype n]
1102-
{X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
1103-
(h_zero : M 0)
1104-
(h_add : ∀p q, M p → M q → M (p + q))
1105-
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
1106-
M m :=
1107-
begin
1108-
rw [matrix_eq_sum_std_basis m, ← finset.sum_product'],
1109-
apply finset.sum_induction _ _ h_add h_zero,
1110-
{ intros, apply h_std_basis, }
1111-
end
1112-
1113-
@[elab_as_eliminator] protected lemma induction_on [fintype n]
1114-
[nonempty n] {X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
1115-
(h_add : ∀p q, M p → M q → M (p + q))
1116-
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
1117-
M m :=
1118-
matrix.induction_on' m
1119-
begin
1120-
have i : n := classical.choice (by assumption),
1121-
simpa using h_std_basis i i 0,
1122-
end
1123-
h_add h_std_basis
1124-
1125-
end semiring
1126-
11271051
section ring
11281052

11291053
variables [ring α]

src/data/matrix/basis.lean

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/-
2+
Copyright (c) 2020 Jalex Stark. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jalex Stark, Scott Morrison, Eric Wieser
5+
-/
6+
import data.matrix.basic
7+
8+
/-!
9+
# Matrices with a single non-zero element.
10+
11+
This file provides `matrix.std_basis_matrix`.
12+
-/
13+
14+
variables {l m n : Type*}
15+
variables {R α : Type*}
16+
17+
namespace matrix
18+
open_locale matrix
19+
open_locale big_operators
20+
21+
variables [decidable_eq l] [decidable_eq m] [decidable_eq n]
22+
23+
variables [semiring α]
24+
25+
/--
26+
`std_basis_matrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column,
27+
and zeroes elsewhere.
28+
-/
29+
def std_basis_matrix (i : m) (j : n) (a : α) : matrix m n α :=
30+
(λ i' j', if i' = i ∧ j' = j then a else 0)
31+
32+
@[simp] lemma smul_std_basis_matrix (i : m) (j : n) (a b : α) :
33+
b • std_basis_matrix i j a = std_basis_matrix i j (b • a) :=
34+
by { unfold std_basis_matrix, ext, simp }
35+
36+
@[simp] lemma std_basis_matrix_zero (i : m) (j : n) :
37+
std_basis_matrix i j (0 : α) = 0 :=
38+
by { unfold std_basis_matrix, ext, simp }
39+
40+
lemma std_basis_matrix_add (i : m) (j : n) (a b : α) :
41+
std_basis_matrix i j (a + b) = std_basis_matrix i j a + std_basis_matrix i j b :=
42+
begin
43+
unfold std_basis_matrix, ext,
44+
split_ifs with h; simp [h],
45+
end
46+
47+
lemma matrix_eq_sum_std_basis (x : matrix n m α) [fintype n] [fintype m] :
48+
x = ∑ (i : n) (j : m), std_basis_matrix i j (x i j) :=
49+
begin
50+
ext, symmetry,
51+
iterate 2 { rw finset.sum_apply },
52+
convert fintype.sum_eq_single i _,
53+
{ simp [std_basis_matrix] },
54+
{ intros j hj,
55+
simp [std_basis_matrix, hj.symm] }
56+
end
57+
58+
-- TODO: tie this up with the `basis` machinery of linear algebra
59+
-- this is not completely trivial because we are indexing by two types, instead of one
60+
61+
-- TODO: add `std_basis_vec`
62+
lemma std_basis_eq_basis_mul_basis (i : m) (j : n) :
63+
std_basis_matrix i j 1 = vec_mul_vec (λ i', ite (i = i') 1 0) (λ j', ite (j = j') 1 0) :=
64+
begin
65+
ext, norm_num [std_basis_matrix, vec_mul_vec],
66+
split_ifs; tauto,
67+
end
68+
69+
-- todo: the old proof used fintypes, I don't know `finsupp` but this feels generalizable
70+
@[elab_as_eliminator] protected lemma induction_on' [fintype n]
71+
{X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
72+
(h_zero : M 0)
73+
(h_add : ∀p q, M p → M q → M (p + q))
74+
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
75+
M m :=
76+
begin
77+
rw [matrix_eq_sum_std_basis m, ← finset.sum_product'],
78+
apply finset.sum_induction _ _ h_add h_zero,
79+
{ intros, apply h_std_basis, }
80+
end
81+
82+
@[elab_as_eliminator] protected lemma induction_on [fintype n]
83+
[nonempty n] {X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
84+
(h_add : ∀p q, M p → M q → M (p + q))
85+
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
86+
M m :=
87+
matrix.induction_on' m
88+
begin
89+
have i : n := classical.choice (by assumption),
90+
simpa using h_std_basis i i 0,
91+
end
92+
h_add h_std_basis
93+
94+
end matrix

src/ring_theory/matrix_algebra.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2020 Scott Morrison. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Scott Morrison
55
-/
6-
import data.matrix.basic
6+
import data.matrix.basis
77
import ring_theory.tensor_product
88

99
/-!

src/ring_theory/polynomial_algebra.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Scott Morrison
55
-/
66
import ring_theory.matrix_algebra
77
import data.polynomial.algebra_map
8+
import data.matrix.basis
89

910
/-!
1011
# Algebra isomorphism between matrices of polynomials and polynomials of matrices

0 commit comments

Comments
 (0)