@@ -154,8 +154,16 @@ section diagonal
154
154
variables [decidable_eq n]
155
155
156
156
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
157
- if `i ≠ j`. -/
158
- def diagonal [has_zero α] (d : n → α) : matrix n n α := λ i j, if i = j then d i else 0
157
+ if `i ≠ j`.
158
+
159
+ Note that bundled versions exist as:
160
+ * `matrix.diagonal_add_monoid_hom`
161
+ * `matrix.diagonal_linear_map`
162
+ * `matrix.diagonal_ring_hom`
163
+ * `matrix.diagonal_alg_hom`
164
+ -/
165
+ def diagonal [has_zero α] (d : n → α) : matrix n n α
166
+ | i j := if i = j then d i else 0
159
167
160
168
@[simp] theorem diagonal_apply_eq [has_zero α] {d : n → α} (i : n) : (diagonal d) i i = d i :=
161
169
by simp [diagonal]
@@ -166,8 +174,11 @@ by simp [diagonal]
166
174
theorem diagonal_apply_ne' [has_zero α] {d : n → α} {i j : n} (h : j ≠ i) :
167
175
(diagonal d) i j = 0 := diagonal_apply_ne h.symm
168
176
177
+ lemma diagonal_injective [has_zero α] : function.injective (diagonal : (n → α) → matrix n n α) :=
178
+ λ d₁ d₂ h, funext $ λ i, by simpa using matrix.ext_iff.mpr h i i
179
+
169
180
@[simp] theorem diagonal_zero [has_zero α] : (diagonal (λ _, 0 ) : matrix n n α) = 0 :=
170
- by simp [diagonal]; refl
181
+ by { ext, simp [diagonal] }
171
182
172
183
@[simp] lemma diagonal_transpose [has_zero α] (v : n → α) :
173
184
(diagonal v)ᵀ = diagonal v :=
@@ -178,10 +189,35 @@ begin
178
189
{ simp [h, transpose, diagonal_apply_ne' h] }
179
190
end
180
191
181
- @[simp] theorem diagonal_add [add_monoid α] (d₁ d₂ : n → α) :
192
+ @[simp] theorem diagonal_add [add_zero_class α] (d₁ d₂ : n → α) :
182
193
diagonal d₁ + diagonal d₂ = diagonal (λ i, d₁ i + d₂ i) :=
183
194
by ext i j; by_cases h : i = j; simp [h]
184
195
196
+ @[simp] theorem diagonal_smul [monoid R] [add_monoid α] [distrib_mul_action R α] (r : R)
197
+ (d : n → α) :
198
+ diagonal (r • d) = r • diagonal d :=
199
+ by ext i j; by_cases h : i = j; simp [h]
200
+
201
+ variables (n α)
202
+
203
+ /-- `matrix.diagonal` as an `add_monoid_hom`. -/
204
+ @[simps]
205
+ def diagonal_add_monoid_hom [add_zero_class α] : (n → α) →+ matrix n n α :=
206
+ { to_fun := diagonal,
207
+ map_zero' := diagonal_zero,
208
+ map_add' := λ x y, (diagonal_add x y).symm,}
209
+
210
+ variables (R)
211
+
212
+ /-- `matrix.diagonal` as a `linear_map`. -/
213
+ @[simps]
214
+ def diagonal_linear_map [semiring R] [add_comm_monoid α] [module R α] :
215
+ (n → α) →ₗ[R] matrix n n α :=
216
+ { map_smul' := diagonal_smul,
217
+ .. diagonal_add_monoid_hom n α,}
218
+
219
+ variables {n α R}
220
+
185
221
@[simp] lemma diagonal_map [has_zero α] [has_zero β] {f : α → β} (h : f 0 = 0 ) {d : n → α} :
186
222
(diagonal d).map f = diagonal (λ m, f (d m)) :=
187
223
by { ext, simp only [diagonal, map_apply], split_ifs; simp [h], }
@@ -354,7 +390,7 @@ theorem mul_apply' [has_mul α] [add_comm_monoid α] {M : matrix l m α} {N : ma
354
390
355
391
@[simp] theorem diagonal_neg [decidable_eq n] [add_group α] (d : n → α) :
356
392
-diagonal d = diagonal (λ i, -d i) :=
357
- by ext i j; by_cases i = j; simp [h]
393
+ ((diagonal_add_monoid_hom n α).map_neg d).symm
358
394
359
395
lemma sum_apply [add_comm_monoid α] (i : m) (j : n)
360
396
(s : finset β) (g : β → matrix m n α) :
@@ -446,6 +482,16 @@ lemma map_mul {L : matrix m n α} {M : matrix n o α} [non_assoc_semiring β] {f
446
482
(L ⬝ M).map f = L.map f ⬝ M.map f :=
447
483
by { ext, simp [mul_apply, ring_hom.map_sum], }
448
484
485
+ variables (α n)
486
+
487
+ /-- `matrix.diagonal` as a `ring_hom`. -/
488
+ @[simps]
489
+ def diagonal_ring_hom [decidable_eq n] : (n → α) →+* matrix n n α :=
490
+ { to_fun := diagonal,
491
+ map_one' := diagonal_one,
492
+ map_mul' := λ _ _, (diagonal_mul_diagonal' _ _).symm,
493
+ .. diagonal_add_monoid_hom n α }
494
+
449
495
end non_assoc_semiring
450
496
451
497
section non_unital_semiring
768
814
@[simp] lemma algebra_map_eq_smul (r : R) :
769
815
algebra_map R (matrix n n R) r = r • (1 : matrix n n R) := rfl
770
816
817
+ variables (R)
818
+
819
+ /-- `matrix.diagonal` as an `alg_hom`. -/
820
+ @[simps]
821
+ def diagonal_alg_hom : (n → α) →ₐ[R] matrix n n α :=
822
+ { to_fun := diagonal,
823
+ commutes' := λ r, by { ext, rw [algebra_map_matrix_apply, diagonal, pi.algebra_map_apply] },
824
+ .. diagonal_ring_hom n α }
825
+
771
826
end algebra
772
827
773
828
/-- For two vectors `w` and `v`, `vec_mul_vec w v i j` is defined to be `w i * v j`.
0 commit comments