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

Commit a783a47

Browse files
committed
feat(data/matrix/{basic, block}): missing lemmas on conj_transpose (#8303)
This also moves some imports around to make the star operator on vectors available in matrix/basic.lean This is a follow up to #8291
1 parent 66055dd commit a783a47

File tree

4 files changed

+121
-14
lines changed

4 files changed

+121
-14
lines changed

src/algebra/star/algebra.lean

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ Authors: Scott Morrison
55
-/
66
import algebra.algebra.basic
77
import algebra.star.basic
8+
import algebra.star.pi
89

910
/-!
1011
# Star algebras
1112
1213
Introduces the notion of a star algebra over a star ring.
1314
-/
1415

15-
universes u v
16+
universes u v w
1617

1718
/--
1819
A star algebra `A` over a star ring `R` is an algebra which is a star ring,
@@ -30,3 +31,16 @@ class star_algebra (R : Type u) (A : Type v)
3031
(r : R) (a : A) :
3132
star (r • a) = star r • star a :=
3233
star_algebra.star_smul r a
34+
35+
namespace pi
36+
37+
variable {I : Type u} -- The indexing type
38+
variable {f : I → Type v} -- The family of types already equipped with instances
39+
40+
instance {R : Type w}
41+
[comm_semiring R] [Π i, semiring (f i)] [Π i, algebra R (f i)]
42+
[star_ring R] [Π i, star_ring (f i)] [Π i, star_algebra R (f i)] :
43+
star_algebra R (Π i, f i) :=
44+
{ star_smul := λ r x, funext $ λ _, star_smul _ _ }
45+
46+
end pi

src/algebra/star/pi.lean

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ Copyright (c) 2021 Eric Wieser. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Eric Wieser
55
-/
6-
import algebra.star.algebra
6+
import algebra.star.basic
7+
import algebra.ring.pi
78

89
/-!
910
# `star` on pi types
1011
1112
We put a `has_star` structure on pi types that operates elementwise, such that it describes the
1213
complex conjugation of vectors.
14+
15+
Note that `pi.star_algebra` is in a different file to avoid pulling in everything from
16+
`algebra/algebra/basic`.
1317
-/
1418

1519
universes u v w
@@ -33,10 +37,4 @@ instance [Π i, semiring (f i)] [Π i, star_ring (f i)] : star_ring (Π i, f i)
3337
{ star_add := λ _ _, funext $ λ _, star_add _ _,
3438
..(by apply_instance : star_monoid (Π i, f i)) }
3539

36-
instance {R : Type w}
37-
[comm_semiring R] [Π i, semiring (f i)] [Π i, algebra R (f i)]
38-
[star_ring R] [Π i, star_ring (f i)] [Π i, star_algebra R (f i)] :
39-
star_algebra R (Π i, f i) :=
40-
{ star_smul := λ r x, funext $ λ _, star_smul _ _ }
41-
4240
end pi

src/data/matrix/basic.lean

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import algebra.big_operators.pi
77
import algebra.module.pi
88
import algebra.module.linear_map
99
import algebra.big_operators.ring
10-
import algebra.star.basic
10+
import algebra.star.pi
1111
import data.equiv.ring
1212
import data.fintype.card
1313
import data.matrix.dmatrix
@@ -315,6 +315,18 @@ by simp [dot_product, finset.smul_sum, smul_mul_assoc]
315315
dot_product v (x • w) = x • dot_product v w :=
316316
by simp [dot_product, finset.smul_sum, mul_smul_comm]
317317

318+
lemma star_dot_product_star [semiring α] [star_ring α] (v w : m → α) :
319+
dot_product (star v) (star w) = star (dot_product w v) :=
320+
by simp [dot_product]
321+
322+
lemma star_dot_product [semiring α] [star_ring α] (v w : m → α) :
323+
dot_product (star v) w = star (dot_product (star w) v) :=
324+
by simp [dot_product]
325+
326+
lemma dot_product_star [semiring α] [star_ring α] (v w : m → α) :
327+
dot_product v (star w) = star (dot_product w (star v)) :=
328+
by simp [dot_product]
329+
318330
end dot_product
319331

320332
/-- `M ⬝ N` is the usual product of matrices `M` and `N`, i.e. we have that
@@ -1172,9 +1184,14 @@ by { ext, refl }
11721184
@[simp] lemma row_apply (v : m → α) (i j) : matrix.row v i j = v j := rfl
11731185

11741186
@[simp]
1175-
lemma transpose_col (v : m → α) : (matrix.col v).transpose = matrix.row v := by {ext, refl}
1187+
lemma transpose_col (v : m → α) : (matrix.col v) = matrix.row v := by { ext, refl }
11761188
@[simp]
1177-
lemma transpose_row (v : m → α) : (matrix.row v).transpose = matrix.col v := by {ext, refl}
1189+
lemma transpose_row (v : m → α) : (matrix.row v)ᵀ = matrix.col v := by { ext, refl }
1190+
1191+
@[simp]
1192+
lemma conj_transpose_col [has_star α] (v : m → α) : (col v)ᴴ = row (star v) := by { ext, refl }
1193+
@[simp]
1194+
lemma conj_transpose_row [has_star α] (v : m → α) : (row v)ᴴ = col (star v) := by { ext, refl }
11781195

11791196
lemma row_vec_mul [semiring α] (M : matrix m n α) (v : m → α) :
11801197
matrix.row (matrix.vec_mul v M) = matrix.row v ⬝ M := by {ext, refl}
@@ -1232,6 +1249,22 @@ begin
12321249
{ rwa [update_column_ne h, if_neg h] }
12331250
end
12341251

1252+
lemma map_update_row [decidable_eq n] (f : α → β) :
1253+
map (update_row M i b) f = update_row (M.map f) i (f ∘ b) :=
1254+
begin
1255+
ext i' j',
1256+
rw [update_row_apply, map_apply, map_apply, update_row_apply],
1257+
exact apply_ite f _ _ _,
1258+
end
1259+
1260+
lemma map_update_column [decidable_eq m] (f : α → β) :
1261+
map (update_column M j c) f = update_column (M.map f) j (f ∘ c) :=
1262+
begin
1263+
ext i' j',
1264+
rw [update_column_apply, map_apply, map_apply, update_column_apply],
1265+
exact apply_ite f _ _ _,
1266+
end
1267+
12351268
lemma update_row_transpose [decidable_eq m] : update_row Mᵀ j c = (update_column M j c)ᵀ :=
12361269
begin
12371270
ext i' j,
@@ -1246,6 +1279,22 @@ begin
12461279
refl
12471280
end
12481281

1282+
lemma update_row_conj_transpose [decidable_eq m] [has_star α] :
1283+
update_row Mᴴ j (star c) = (update_column M j c)ᴴ :=
1284+
begin
1285+
rw [conj_transpose, conj_transpose, transpose_map, transpose_map, update_row_transpose,
1286+
map_update_column],
1287+
refl,
1288+
end
1289+
1290+
lemma update_column_conj_transpose [decidable_eq n] [has_star α] :
1291+
update_column Mᴴ i (star b) = (update_row M i b)ᴴ :=
1292+
begin
1293+
rw [conj_transpose, conj_transpose, transpose_map, transpose_map, update_column_transpose,
1294+
map_update_row],
1295+
refl,
1296+
end
1297+
12491298
@[simp] lemma update_row_eq_self [decidable_eq m]
12501299
(A : matrix m n α) {i : m} :
12511300
A.update_row i (A i) = A :=

src/data/matrix/block.lean

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import data.matrix.basic
2020
variables {l m n o : Type*} [fintype l] [fintype m] [fintype n] [fintype o]
2121
variables {m' : o → Type*} [∀ i, fintype (m' i)]
2222
variables {n' : o → Type*} [∀ i, fintype (n' i)]
23-
variables {R : Type*} {S : Type*} {α : Type*}
23+
variables {R : Type*} {S : Type*} {α : Type*} {β : Type*}
2424

2525
open_locale matrix
2626

@@ -101,13 +101,27 @@ rfl
101101
(from_blocks A B C D).to_blocks₂₂ = D :=
102102
rfl
103103

104+
lemma from_blocks_map
105+
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) (f : α → β) :
106+
(from_blocks A B C D).map f = from_blocks (A.map f) (B.map f) (C.map f) (D.map f) :=
107+
begin
108+
ext i j, rcases i; rcases j; simp [from_blocks],
109+
end
110+
104111
lemma from_blocks_transpose
105112
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
106113
(from_blocks A B C D)ᵀ = from_blocks Aᵀ Cᵀ Bᵀ Dᵀ :=
107114
begin
108115
ext i j, rcases i; rcases j; simp [from_blocks],
109116
end
110117

118+
lemma from_blocks_conj_transpose [has_star α]
119+
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
120+
(from_blocks A B C D)ᴴ = from_blocks Aᴴ Cᴴ Bᴴ Dᴴ :=
121+
begin
122+
simp only [conj_transpose, from_blocks_transpose, from_blocks_map]
123+
end
124+
111125
/-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then
112126
`to_block M p q` is the corresponding block matrix. -/
113127
def to_block (M : matrix m n α) (p : m → Prop) [decidable_pred p]
@@ -191,7 +205,7 @@ variables (M N : o → matrix m n α) [decidable_eq o]
191205

192206
section has_zero
193207

194-
variables [has_zero α]
208+
variables [has_zero α] [has_zero β]
195209

196210
/-- `matrix.block_diagonal M` turns a homogenously-indexed collection of matrices
197211
`M : o → matrix m n α'` into a `m × o`-by-`n × o` block matrix which has the entries of `M` along
@@ -215,6 +229,14 @@ lemma block_diagonal_apply_ne (i j) {k k'} (h : k ≠ k') :
215229
block_diagonal M (i, k) (j, k') = 0 :=
216230
if_neg h
217231

232+
lemma block_diagonal_map (f : α → β) (hf : f 0 = 0) :
233+
(block_diagonal M).map f = block_diagonal (λ k, (M k).map f) :=
234+
begin
235+
ext,
236+
simp only [map_apply, block_diagonal_apply, eq_comm],
237+
rw [apply_ite f, hf],
238+
end
239+
218240
@[simp] lemma block_diagonal_transpose :
219241
(block_diagonal M)ᵀ = block_diagonal (λ k, (M k)ᵀ) :=
220242
begin
@@ -225,6 +247,14 @@ begin
225247
{ refl }
226248
end
227249

250+
@[simp] lemma block_diagonal_conj_transpose
251+
{α : Type*} [semiring α] [star_ring α] (M : o → matrix m n α) :
252+
(block_diagonal M)ᴴ = block_diagonal (λ k, (M k)ᴴ) :=
253+
begin
254+
simp only [conj_transpose, block_diagonal_transpose],
255+
rw block_diagonal_map _ star (star_zero α),
256+
end
257+
228258
@[simp] lemma block_diagonal_zero :
229259
block_diagonal (0 : o → matrix m n α) = 0 :=
230260
by { ext, simp [block_diagonal_apply] }
@@ -284,7 +314,7 @@ variables (M N : Π i, matrix (m' i) (n' i) α) [decidable_eq o]
284314

285315
section has_zero
286316

287-
variables [has_zero α]
317+
variables [has_zero α] [has_zero β]
288318

289319
/-- `matrix.block_diagonal' M` turns `M : Π i, matrix (m i) (n i) α` into a
290320
`Σ i, m i`-by-`Σ i, n i` block matrix which has the entries of `M` along the diagonal
@@ -317,6 +347,14 @@ lemma block_diagonal'_apply_ne {k k'} (i j) (h : k ≠ k') :
317347
block_diagonal' M ⟨k, i⟩ ⟨k', j⟩ = 0 :=
318348
dif_neg h
319349

350+
lemma block_diagonal'_map (f : α → β) (hf : f 0 = 0) :
351+
(block_diagonal' M).map f = block_diagonal' (λ k, (M k).map f) :=
352+
begin
353+
ext,
354+
simp only [map_apply, block_diagonal'_apply, eq_comm],
355+
rw [apply_dite f, hf],
356+
end
357+
320358
@[simp] lemma block_diagonal'_transpose :
321359
(block_diagonal' M)ᵀ = block_diagonal' (λ k, (M k)ᵀ) :=
322360
begin
@@ -330,6 +368,14 @@ begin
330368
{ refl }
331369
end
332370

371+
@[simp] lemma block_diagonal'_conj_transpose {α} [semiring α] [star_ring α]
372+
(M : Π i, matrix (m' i) (n' i) α) :
373+
(block_diagonal' M)ᴴ = block_diagonal' (λ k, (M k)ᴴ) :=
374+
begin
375+
simp only [conj_transpose, block_diagonal'_transpose],
376+
exact block_diagonal'_map _ star (star_zero α),
377+
end
378+
333379
@[simp] lemma block_diagonal'_zero :
334380
block_diagonal' (0 : Π i, matrix (m' i) (n' i) α) = 0 :=
335381
by { ext, simp [block_diagonal'_apply] }

0 commit comments

Comments
 (0)