File size: 9,410 Bytes
4a56cd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import OAI.LinearAlgebra.Moore.Derivative
import OAI.LinearAlgebra.Moore.Normalize

/-! Infinitesimal congruence and inverse linearization of the Moore determinant. -/

namespace OAI.LinearAlgebra.Moore

open Matrix

noncomputable def complexDetDifferential {I : Type*} [Fintype I] [DecidableEq I]
    (M N : Matrix I I β„‚) : β„‚ :=
  βˆ‘ Οƒ : Equiv.Perm I, ((Equiv.Perm.sign Οƒ : β„€) : β„‚) *
    βˆ‘ i : I, (∏ j ∈ Finset.univ.erase i, M (Οƒ j) j) * N (Οƒ i) i

theorem hasDerivAt_complexDet_path {I : Type*} [Fintype I] [DecidableEq I]
    (M : ℝ β†’ Matrix I I β„‚) (N : Matrix I I β„‚) (t : ℝ)
    (h : βˆ€ i j, HasDerivAt (fun s => M s i j) (N i j) t) :
    HasDerivAt (fun s => (M s).det) (complexDetDifferential (M t) N) t := by
  simp only [Matrix.det_apply', complexDetDifferential]
  apply HasDerivAt.fun_sum
  intro Οƒ _
  apply HasDerivAt.const_mul
  simpa only [smul_eq_mul] using
    (HasDerivAt.fun_finsetProd (u := Finset.univ) (fun i _ => h (Οƒ i) i))

theorem complexDetDifferential_one {I : Type*} [Fintype I] [DecidableEq I]
    (N : Matrix I I β„‚) : complexDetDifferential 1 N = N.trace := by
  classical
  have hex (σ : Equiv.Perm I) (hσ : σ ≠ 1) (i : I) :
      βˆƒ j, j β‰  i ∧ Οƒ j β‰  j := by
    by_contra h
    push Not at h
    apply hσ
    apply Equiv.ext
    intro j
    by_cases hj : j = i
    Β· subst j
      by_cases hi : Οƒ i = i
      Β· exact hi
      Β· exact Οƒ.injective (h (Οƒ i) hi)
    Β· exact h j hj
  unfold complexDetDifferential
  rw [Finset.sum_eq_single (1 : Equiv.Perm I)]
  Β· simp [Matrix.trace, Matrix.one_apply]
  · intro σ _ hσ
    apply mul_eq_zero.mpr
    right
    apply Finset.sum_eq_zero
    intro i _
    obtain ⟨j, hji, hj⟩ := hex Οƒ hΟƒ i
    have hp : (∏ l ∈ Finset.univ.erase i, (1 : Matrix I I β„‚) (Οƒ l) l) = 0 := by
      apply Finset.prod_eq_zero (Finset.mem_erase.mpr ⟨hji, Finset.mem_univ _⟩)
      simp [hj]
    rw [hp, zero_mul]
  Β· simp

theorem hasDerivAt_complexDet_identity {I : Type*} [Fintype I] [DecidableEq I]
    (M : ℝ β†’ Matrix I I β„‚) (N : Matrix I I β„‚) (t : ℝ) (hM : M t = 1)
    (h : βˆ€ i j, HasDerivAt (fun s => M s i j) (N i j) t) :
    HasDerivAt (fun s => (M s).det) N.trace t := by
  have hd := hasDerivAt_complexDet_path M N t h
  rw [hM, complexDetDifferential_one] at hd
  exact hd

theorem hasDerivAt_quaternionMatrix_mul {I J K : Type*} [Fintype J]
    (A : ℝ β†’ Matrix I J (Quaternion ℝ)) (B : ℝ β†’ Matrix J K (Quaternion ℝ))
    (D : Matrix I J (Quaternion ℝ)) (E : Matrix J K (Quaternion ℝ)) (t : ℝ)
    (hA : βˆ€ i j, HasDerivAt (fun s => A s i j) (D i j) t)
    (hB : βˆ€ j k, HasDerivAt (fun s => B s j k) (E j k) t) :
    βˆ€ i k, HasDerivAt (fun s => (A s * B s) i k)
      ((D * B t + A t * E) i k) t := by
  intro i k
  have h := HasDerivAt.fun_sum (u := Finset.univ) (fun j _ => (hA i j).mul (hB j k))
  simpa only [Matrix.mul_apply, Matrix.add_apply, Finset.sum_add_distrib, Pi.mul_apply] using! h

def quaternionStarLinear : Quaternion ℝ β†’β‚—[ℝ] Quaternion ℝ where
  toFun := star
  map_add' := star_add
  map_smul' s q := by
    ext <;> simp

noncomputable def quaternionStarCLM : Quaternion ℝ β†’L[ℝ] Quaternion ℝ :=
  quaternionStarLinear.toContinuousLinearMap

theorem hasDerivAt_quaternionMatrix_star {I J : Type*}
    (A : ℝ β†’ Matrix I J (Quaternion ℝ)) (D : Matrix I J (Quaternion ℝ)) (t : ℝ)
    (hA : βˆ€ i j, HasDerivAt (fun s => A s i j) (D i j) t) :
    βˆ€ j i, HasDerivAt (fun s => (A s)α΄΄ j i) (Dα΄΄ j i) t := by
  intro j i
  exact quaternionStarCLM.hasFDerivAt.comp_hasDerivAt t (hA i j)

theorem quaternionMatrix_real_smul (s : ℝ) (q : Quaternion ℝ) :
    quaternionMatrix (s β€’ q) = s β€’ quaternionMatrix q := by
  ext i j
  fin_cases i <;> fin_cases j <;> apply Complex.ext <;> simp [quaternionMatrix]

theorem complexify_real_smul {I J : Type*} (s : ℝ) (A : Matrix I J (Quaternion ℝ)) :
    complexify (s β€’ A) = s β€’ complexify A := by
  ext ⟨i, a⟩ ⟨j, b⟩
  exact congrArg (fun M : Matrix (Fin 2) (Fin 2) β„‚ => M a b)
    (quaternionMatrix_real_smul s (A i j))

theorem complexify_trace_real (n : β„•) (A : Matrix (Fin n) (Fin n) (Quaternion ℝ)) :
    (complexify A).trace.re = 2 * βˆ‘ i : Fin n, (A i i).re := by
  simp [Matrix.trace, Fintype.sum_prod_type, Fin.sum_univ_two, complexify, quaternionMatrix,
    Finset.mul_sum, two_mul]

/-- Differentiate the exact congruence law at the identity. This identity is
valid without positivity or invertibility assumptions. -/
theorem mooreDifferential_congruence (n : β„•)
    (A E : Matrix (Fin n) (Fin n) (Quaternion ℝ)) :
    mooreDifferential n A (E * A + A * Eα΄΄) =
      (complexify E).trace.re * mooreDet n A := by
  let B : ℝ β†’ Matrix (Fin n) (Fin n) (Quaternion ℝ) := fun s => 1 + s β€’ E
  have hB0 : B 0 = 1 := by simp [B]
  have hB : βˆ€ i j, HasDerivAt (fun s => B s i j) (E i j) 0 := by
    intro i j
    change HasDerivAt (fun s : ℝ => (1 : Matrix (Fin n) (Fin n) (Quaternion ℝ)) i j +
      s β€’ E i j) (E i j) 0
    convert! ((hasDerivAt_id (0 : ℝ)).smul_const (E i j)).const_add
      ((1 : Matrix (Fin n) (Fin n) (Quaternion ℝ)) i j) using 1
    simp
  have hBA : βˆ€ i j, HasDerivAt (fun s => (B s * A) i j) ((E * A) i j) 0 := by
    have h := hasDerivAt_quaternionMatrix_mul B (fun _ => A) E 0 0 hB
      (fun i j => hasDerivAt_const 0 (A i j))
    simpa only [hB0, Matrix.mul_zero, add_zero] using h
  have hF : βˆ€ i j, HasDerivAt (fun s => (B s * A * (B s)α΄΄) i j)
      ((E * A + A * Eα΄΄) i j) 0 := by
    have h := hasDerivAt_quaternionMatrix_mul (fun s => B s * A) (fun s => (B s)α΄΄)
      (E * A) Eα΄΄ 0 hBA (hasDerivAt_quaternionMatrix_star B E 0 hB)
    simpa only [hB0, Matrix.conjTranspose_one, Matrix.mul_one, Matrix.one_mul] using h
  have hm := hasDerivAt_mooreDet_path n (fun s => B s * A * (B s)α΄΄) (E * A + A * Eα΄΄) 0 hF
  simp only [hB0, Matrix.conjTranspose_one, Matrix.mul_one, Matrix.one_mul] at hm
  have hCB (s : ℝ) : complexify (B s) = 1 + s β€’ complexify E := by
    dsimp only [B]
    rw [complexify_add, complexify_one, complexify_real_smul]
  have hC : βˆ€ i j : Fin n Γ— Fin 2,
      HasDerivAt (fun s => complexify (B s) i j) (complexify E i j) 0 := by
    intro i j
    simp only [hCB]
    change HasDerivAt (fun s : ℝ => (1 : Matrix (Fin n Γ— Fin 2) (Fin n Γ— Fin 2) β„‚) i j +
      s β€’ complexify E i j) (complexify E i j) 0
    convert! ((hasDerivAt_id (0 : ℝ)).smul_const (complexify E i j)).const_add
      ((1 : Matrix (Fin n Γ— Fin 2) (Fin n Γ— Fin 2) β„‚) i j) using 1
    simp
  have hd := hasDerivAt_complexDet_identity (fun s => complexify (B s)) (complexify E) 0
    (by rw [hB0, complexify_one]) hC
  have hr := (Complex.reCLM.hasFDerivAt.comp_hasDerivAt 0 hd).mul_const (mooreDet n A)
  have hf : (fun s => mooreDet n (B s * A * (B s)α΄΄)) =
      fun s => (complexify (B s)).det.re * mooreDet n A := by
    funext s
    exact mooreDet_congruence n A (B s)
  rw [hf] at hm
  exact hm.unique hr

theorem quaternionMatrix_conjTranspose_real_smul {I J : Type*}
    (s : ℝ) (A : Matrix I J (Quaternion ℝ)) : (s β€’ A)α΄΄ = s β€’ Aα΄΄ := by
  apply Matrix.ext
  intro i j
  exact quaternionStarLinear.map_smul s (A j i)

theorem quaternionRealTrace_mul_comm (n : β„•)
    (A B : Matrix (Fin n) (Fin n) (Quaternion ℝ)) :
    (βˆ‘ i, ((A * B) i i).re) = βˆ‘ i, ((B * A) i i).re := by
  have h := congrArg Complex.re (Matrix.trace_mul_comm (complexify A) (complexify B))
  rw [← complexify_mul, ← complexify_mul, complexify_trace_real, complexify_trace_real] at h
  linarith

/-- The exact inverse-trace linearization on the Hermitian locus. `C` is an
explicit two-sided inverse of `A`, avoiding any commutative-matrix inverse
convention for quaternionic matrices. -/
theorem mooreDifferential_inverse (n : β„•)
    (A D C : Matrix (Fin n) (Fin n) (Quaternion ℝ))
    (hA : A.IsHermitian) (hD : D.IsHermitian) (hAC : A * C = 1) (hCA : C * A = 1) :
    mooreDifferential n A D = mooreDet n A * βˆ‘ i, ((C * D) i i).re := by
  have hAe : Aα΄΄ = A := hA
  have hDe : Dα΄΄ = D := hD
  have hCe : Cα΄΄ = C := by
    have hleft : Cα΄΄ * A = 1 := by
      simpa only [Matrix.conjTranspose_mul, Matrix.conjTranspose_one, hAe] using
        congrArg Matrix.conjTranspose hAC
    calc
      Cα΄΄ = Cα΄΄ * (A * C) := by rw [hAC, Matrix.mul_one]
      _ = (Cα΄΄ * A) * C := (Matrix.mul_assoc _ _ _).symm
      _ = C := by rw [hleft, Matrix.one_mul]
  let E : Matrix (Fin n) (Fin n) (Quaternion ℝ) := (1 / 2 : ℝ) β€’ (D * C)
  have hEL : E * A = (1 / 2 : ℝ) β€’ D := by
    dsimp only [E]
    rw [Matrix.smul_mul, Matrix.mul_assoc, hCA, Matrix.mul_one]
  have hER : A * Eα΄΄ = (1 / 2 : ℝ) β€’ D := by
    dsimp only [E]
    rw [quaternionMatrix_conjTranspose_real_smul, Matrix.conjTranspose_mul, hCe, hDe,
      Matrix.mul_smul, ← Matrix.mul_assoc, hAC, Matrix.one_mul]
  have hE : E * A + A * Eα΄΄ = D := by
    rw [hEL, hER, ← add_smul]
    norm_num
  have htrace : (complexify E).trace.re = βˆ‘ i, ((C * D) i i).re := by
    rw [complexify_trace_real]
    calc
      2 * βˆ‘ i : Fin n, (E i i).re = 2 * βˆ‘ i : Fin n, (1 / 2 : ℝ) * ((D * C) i i).re := rfl
      _ = βˆ‘ i : Fin n, ((D * C) i i).re := by rw [← Finset.mul_sum]; ring
      _ = _ := quaternionRealTrace_mul_comm n D C
  have h := mooreDifferential_congruence n A E
  rw [hE, htrace] at h
  exact h.trans (mul_comm _ _)

end OAI.LinearAlgebra.Moore