author | hoelzl |
Fri, 30 May 2014 14:55:10 +0200 | |
changeset 57129 | 7edb7550663e |
parent 56545 | 8f1e7596deb7 |
child 57418 | 6ab1c7cb0b8d |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Multivariate_Analysis/Determinants.thy |
2 |
Author: Amine Chaieb, University of Cambridge |
|
33175 | 3 |
*) |
4 |
||
5 |
header {* Traces, Determinant of square matrices and some properties *} |
|
6 |
||
7 |
theory Determinants |
|
44228
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
8 |
imports |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
9 |
Cartesian_Euclidean_Space |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
10 |
"~~/src/HOL/Library/Permutations" |
33175 | 11 |
begin |
12 |
||
13 |
subsection{* First some facts about products*} |
|
53253 | 14 |
|
15 |
lemma setprod_insert_eq: |
|
16 |
"finite A \<Longrightarrow> setprod f (insert a A) = (if a \<in> A then setprod f A else f a * setprod f A)" |
|
17 |
apply clarsimp |
|
18 |
apply (subgoal_tac "insert a A = A") |
|
19 |
apply auto |
|
20 |
done |
|
33175 | 21 |
|
22 |
lemma setprod_add_split: |
|
53854 | 23 |
fixes m n :: nat |
24 |
assumes mn: "m \<le> n + 1" |
|
25 |
shows "setprod f {m..n+p} = setprod f {m .. n} * setprod f {n+1..n+p}" |
|
53253 | 26 |
proof - |
53854 | 27 |
let ?A = "{m..n+p}" |
28 |
let ?B = "{m..n}" |
|
33175 | 29 |
let ?C = "{n+1..n+p}" |
53854 | 30 |
from mn have un: "?B \<union> ?C = ?A" |
31 |
by auto |
|
32 |
from mn have dj: "?B \<inter> ?C = {}" |
|
33 |
by auto |
|
34 |
have f: "finite ?B" "finite ?C" |
|
35 |
by simp_all |
|
33175 | 36 |
from setprod_Un_disjoint[OF f dj, of f, unfolded un] show ?thesis . |
37 |
qed |
|
38 |
||
39 |
||
53854 | 40 |
lemma setprod_offset: |
41 |
fixes m n :: nat |
|
42 |
shows "setprod f {m + p .. n + p} = setprod (\<lambda>i. f (i + p)) {m..n}" |
|
57129
7edb7550663e
introduce more powerful reindexing rules for big operators
hoelzl
parents:
56545
diff
changeset
|
43 |
by (rule setprod.reindex_bij_witness[where i="op + p" and j="\<lambda>i. i - p"]) auto |
33175 | 44 |
|
53253 | 45 |
lemma setprod_singleton: "setprod f {x} = f x" |
46 |
by simp |
|
33175 | 47 |
|
53854 | 48 |
lemma setprod_singleton_nat_seg: |
49 |
fixes n :: "'a::order" |
|
50 |
shows "setprod f {n..n} = f n" |
|
53253 | 51 |
by simp |
52 |
||
53 |
lemma setprod_numseg: |
|
54 |
"setprod f {m..0} = (if m = 0 then f 0 else 1)" |
|
55 |
"setprod f {m .. Suc n} = |
|
56 |
(if m \<le> Suc n then f (Suc n) * setprod f {m..n} else setprod f {m..n})" |
|
33175 | 57 |
by (auto simp add: atLeastAtMostSuc_conv) |
58 |
||
53253 | 59 |
lemma setprod_le: |
53854 | 60 |
fixes f g :: "'b \<Rightarrow> 'a::linordered_idom" |
53253 | 61 |
assumes fS: "finite S" |
53854 | 62 |
and fg: "\<forall>x\<in>S. f x \<ge> 0 \<and> f x \<le> g x" |
33175 | 63 |
shows "setprod f S \<le> setprod g S" |
53253 | 64 |
using fS fg |
65 |
apply (induct S) |
|
66 |
apply simp |
|
67 |
apply auto |
|
68 |
apply (rule mult_mono) |
|
69 |
apply (auto intro: setprod_nonneg) |
|
70 |
done |
|
33175 | 71 |
|
53854 | 72 |
(* FIXME: In Finite_Set there is a useless further assumption *) |
53253 | 73 |
lemma setprod_inversef: |
74 |
"finite A \<Longrightarrow> setprod (inverse \<circ> f) A = (inverse (setprod f A) :: 'a:: field_inverse_zero)" |
|
33175 | 75 |
apply (erule finite_induct) |
76 |
apply (simp) |
|
77 |
apply simp |
|
78 |
done |
|
79 |
||
53253 | 80 |
lemma setprod_le_1: |
53854 | 81 |
fixes f :: "'b \<Rightarrow> 'a::linordered_idom" |
53253 | 82 |
assumes fS: "finite S" |
53854 | 83 |
and f: "\<forall>x\<in>S. f x \<ge> 0 \<and> f x \<le> 1" |
33175 | 84 |
shows "setprod f S \<le> 1" |
53253 | 85 |
using setprod_le[OF fS f] unfolding setprod_1 . |
33175 | 86 |
|
53253 | 87 |
|
88 |
subsection {* Trace *} |
|
33175 | 89 |
|
53253 | 90 |
definition trace :: "'a::semiring_1^'n^'n \<Rightarrow> 'a" |
91 |
where "trace A = setsum (\<lambda>i. ((A$i)$i)) (UNIV::'n set)" |
|
33175 | 92 |
|
53854 | 93 |
lemma trace_0: "trace (mat 0) = 0" |
33175 | 94 |
by (simp add: trace_def mat_def) |
95 |
||
53854 | 96 |
lemma trace_I: "trace (mat 1 :: 'a::semiring_1^'n^'n) = of_nat(CARD('n))" |
33175 | 97 |
by (simp add: trace_def mat_def) |
98 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
99 |
lemma trace_add: "trace ((A::'a::comm_semiring_1^'n^'n) + B) = trace A + trace B" |
33175 | 100 |
by (simp add: trace_def setsum_addf) |
101 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
102 |
lemma trace_sub: "trace ((A::'a::comm_ring_1^'n^'n) - B) = trace A - trace B" |
33175 | 103 |
by (simp add: trace_def setsum_subtractf) |
104 |
||
53854 | 105 |
lemma trace_mul_sym: "trace ((A::'a::comm_semiring_1^'n^'m) ** B) = trace (B**A)" |
33175 | 106 |
apply (simp add: trace_def matrix_matrix_mult_def) |
107 |
apply (subst setsum_commute) |
|
53253 | 108 |
apply (simp add: mult_commute) |
109 |
done |
|
33175 | 110 |
|
53854 | 111 |
text {* Definition of determinant. *} |
33175 | 112 |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
113 |
definition det:: "'a::comm_ring_1^'n^'n \<Rightarrow> 'a" where |
53253 | 114 |
"det A = |
115 |
setsum (\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)) |
|
116 |
{p. p permutes (UNIV :: 'n set)}" |
|
33175 | 117 |
|
53854 | 118 |
text {* A few general lemmas we need below. *} |
33175 | 119 |
|
120 |
lemma setprod_permute: |
|
121 |
assumes p: "p permutes S" |
|
53854 | 122 |
shows "setprod f S = setprod (f \<circ> p) S" |
51489 | 123 |
using assms by (fact setprod.permute) |
33175 | 124 |
|
53253 | 125 |
lemma setproduct_permute_nat_interval: |
53854 | 126 |
fixes m n :: nat |
127 |
shows "p permutes {m..n} \<Longrightarrow> setprod f {m..n} = setprod (f \<circ> p) {m..n}" |
|
33175 | 128 |
by (blast intro!: setprod_permute) |
129 |
||
53854 | 130 |
text {* Basic determinant properties. *} |
33175 | 131 |
|
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
132 |
lemma det_transpose: "det (transpose A) = det (A::'a::comm_ring_1 ^'n^'n)" |
53253 | 133 |
proof - |
33175 | 134 |
let ?di = "\<lambda>A i j. A$i$j" |
135 |
let ?U = "(UNIV :: 'n set)" |
|
136 |
have fU: "finite ?U" by simp |
|
53253 | 137 |
{ |
138 |
fix p |
|
139 |
assume p: "p \<in> {p. p permutes ?U}" |
|
53854 | 140 |
from p have pU: "p permutes ?U" |
141 |
by blast |
|
33175 | 142 |
have sth: "sign (inv p) = sign p" |
44260
7784fa3232ce
Determinants.thy: avoid using mem_def/Collect_def
huffman
parents:
44228
diff
changeset
|
143 |
by (metis sign_inverse fU p mem_Collect_eq permutation_permutes) |
33175 | 144 |
from permutes_inj[OF pU] |
53854 | 145 |
have pi: "inj_on p ?U" |
146 |
by (blast intro: subset_inj_on) |
|
33175 | 147 |
from permutes_image[OF pU] |
53253 | 148 |
have "setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U = |
53854 | 149 |
setprod (\<lambda>i. ?di (transpose A) i (inv p i)) (p ` ?U)" |
150 |
by simp |
|
151 |
also have "\<dots> = setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) ?U" |
|
33175 | 152 |
unfolding setprod_reindex[OF pi] .. |
153 |
also have "\<dots> = setprod (\<lambda>i. ?di A i (p i)) ?U" |
|
53253 | 154 |
proof - |
155 |
{ |
|
156 |
fix i |
|
157 |
assume i: "i \<in> ?U" |
|
33175 | 158 |
from i permutes_inv_o[OF pU] permutes_in_image[OF pU] |
53854 | 159 |
have "((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) i = ?di A i (p i)" |
53253 | 160 |
unfolding transpose_def by (simp add: fun_eq_iff) |
161 |
} |
|
53854 | 162 |
then show "setprod ((\<lambda>i. ?di (transpose A) i (inv p i)) \<circ> p) ?U = |
163 |
setprod (\<lambda>i. ?di A i (p i)) ?U" |
|
164 |
by (auto intro: setprod_cong) |
|
33175 | 165 |
qed |
53253 | 166 |
finally have "of_int (sign (inv p)) * (setprod (\<lambda>i. ?di (transpose A) i (inv p i)) ?U) = |
53854 | 167 |
of_int (sign p) * (setprod (\<lambda>i. ?di A i (p i)) ?U)" |
168 |
using sth by simp |
|
53253 | 169 |
} |
170 |
then show ?thesis |
|
171 |
unfolding det_def |
|
172 |
apply (subst setsum_permutations_inverse) |
|
173 |
apply (rule setsum_cong2) |
|
174 |
apply blast |
|
175 |
done |
|
33175 | 176 |
qed |
177 |
||
178 |
lemma det_lowerdiagonal: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
179 |
fixes A :: "'a::comm_ring_1^('n::{finite,wellorder})^('n::{finite,wellorder})" |
33175 | 180 |
assumes ld: "\<And>i j. i < j \<Longrightarrow> A$i$j = 0" |
181 |
shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)" |
|
53253 | 182 |
proof - |
33175 | 183 |
let ?U = "UNIV:: 'n set" |
184 |
let ?PU = "{p. p permutes ?U}" |
|
185 |
let ?pp = "\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)" |
|
53854 | 186 |
have fU: "finite ?U" |
187 |
by simp |
|
33175 | 188 |
from finite_permutations[OF fU] have fPU: "finite ?PU" . |
53854 | 189 |
have id0: "{id} \<subseteq> ?PU" |
190 |
by (auto simp add: permutes_id) |
|
53253 | 191 |
{ |
192 |
fix p |
|
53854 | 193 |
assume p: "p \<in> ?PU - {id}" |
53253 | 194 |
from p have pU: "p permutes ?U" and pid: "p \<noteq> id" |
195 |
by blast+ |
|
196 |
from permutes_natset_le[OF pU] pid obtain i where i: "p i > i" |
|
197 |
by (metis not_le) |
|
198 |
from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" |
|
199 |
by blast |
|
200 |
from setprod_zero[OF fU ex] have "?pp p = 0" |
|
201 |
by simp |
|
202 |
} |
|
53854 | 203 |
then have p0: "\<forall>p \<in> ?PU - {id}. ?pp p = 0" |
53253 | 204 |
by blast |
33175 | 205 |
from setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis |
206 |
unfolding det_def by (simp add: sign_id) |
|
207 |
qed |
|
208 |
||
209 |
lemma det_upperdiagonal: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
210 |
fixes A :: "'a::comm_ring_1^'n::{finite,wellorder}^'n::{finite,wellorder}" |
33175 | 211 |
assumes ld: "\<And>i j. i > j \<Longrightarrow> A$i$j = 0" |
212 |
shows "det A = setprod (\<lambda>i. A$i$i) (UNIV:: 'n set)" |
|
53253 | 213 |
proof - |
33175 | 214 |
let ?U = "UNIV:: 'n set" |
215 |
let ?PU = "{p. p permutes ?U}" |
|
216 |
let ?pp = "(\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set))" |
|
53854 | 217 |
have fU: "finite ?U" |
218 |
by simp |
|
33175 | 219 |
from finite_permutations[OF fU] have fPU: "finite ?PU" . |
53854 | 220 |
have id0: "{id} \<subseteq> ?PU" |
221 |
by (auto simp add: permutes_id) |
|
53253 | 222 |
{ |
223 |
fix p |
|
53854 | 224 |
assume p: "p \<in> ?PU - {id}" |
53253 | 225 |
from p have pU: "p permutes ?U" and pid: "p \<noteq> id" |
226 |
by blast+ |
|
227 |
from permutes_natset_ge[OF pU] pid obtain i where i: "p i < i" |
|
228 |
by (metis not_le) |
|
53854 | 229 |
from ld[OF i] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" |
230 |
by blast |
|
231 |
from setprod_zero[OF fU ex] have "?pp p = 0" |
|
232 |
by simp |
|
53253 | 233 |
} |
234 |
then have p0: "\<forall>p \<in> ?PU -{id}. ?pp p = 0" |
|
235 |
by blast |
|
236 |
from setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis |
|
33175 | 237 |
unfolding det_def by (simp add: sign_id) |
238 |
qed |
|
239 |
||
240 |
lemma det_diagonal: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
241 |
fixes A :: "'a::comm_ring_1^'n^'n" |
33175 | 242 |
assumes ld: "\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0" |
243 |
shows "det A = setprod (\<lambda>i. A$i$i) (UNIV::'n set)" |
|
53253 | 244 |
proof - |
33175 | 245 |
let ?U = "UNIV:: 'n set" |
246 |
let ?PU = "{p. p permutes ?U}" |
|
247 |
let ?pp = "\<lambda>p. of_int (sign p) * setprod (\<lambda>i. A$i$p i) (UNIV :: 'n set)" |
|
248 |
have fU: "finite ?U" by simp |
|
249 |
from finite_permutations[OF fU] have fPU: "finite ?PU" . |
|
53854 | 250 |
have id0: "{id} \<subseteq> ?PU" |
251 |
by (auto simp add: permutes_id) |
|
53253 | 252 |
{ |
253 |
fix p |
|
254 |
assume p: "p \<in> ?PU - {id}" |
|
53854 | 255 |
then have "p \<noteq> id" |
256 |
by simp |
|
257 |
then obtain i where i: "p i \<noteq> i" |
|
258 |
unfolding fun_eq_iff by auto |
|
259 |
from ld [OF i [symmetric]] have ex:"\<exists>i \<in> ?U. A$i$p i = 0" |
|
260 |
by blast |
|
261 |
from setprod_zero [OF fU ex] have "?pp p = 0" |
|
262 |
by simp |
|
263 |
} |
|
264 |
then have p0: "\<forall>p \<in> ?PU - {id}. ?pp p = 0" |
|
265 |
by blast |
|
33175 | 266 |
from setsum_mono_zero_cong_left[OF fPU id0 p0] show ?thesis |
267 |
unfolding det_def by (simp add: sign_id) |
|
268 |
qed |
|
269 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
270 |
lemma det_I: "det (mat 1 :: 'a::comm_ring_1^'n^'n) = 1" |
53253 | 271 |
proof - |
33175 | 272 |
let ?A = "mat 1 :: 'a::comm_ring_1^'n^'n" |
273 |
let ?U = "UNIV :: 'n set" |
|
274 |
let ?f = "\<lambda>i j. ?A$i$j" |
|
53253 | 275 |
{ |
276 |
fix i |
|
277 |
assume i: "i \<in> ?U" |
|
53854 | 278 |
have "?f i i = 1" |
279 |
using i by (vector mat_def) |
|
53253 | 280 |
} |
281 |
then have th: "setprod (\<lambda>i. ?f i i) ?U = setprod (\<lambda>x. 1) ?U" |
|
33175 | 282 |
by (auto intro: setprod_cong) |
53253 | 283 |
{ |
284 |
fix i j |
|
285 |
assume i: "i \<in> ?U" and j: "j \<in> ?U" and ij: "i \<noteq> j" |
|
53854 | 286 |
have "?f i j = 0" using i j ij |
287 |
by (vector mat_def) |
|
53253 | 288 |
} |
53854 | 289 |
then have "det ?A = setprod (\<lambda>i. ?f i i) ?U" |
290 |
using det_diagonal by blast |
|
291 |
also have "\<dots> = 1" |
|
292 |
unfolding th setprod_1 .. |
|
33175 | 293 |
finally show ?thesis . |
294 |
qed |
|
295 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
296 |
lemma det_0: "det (mat 0 :: 'a::comm_ring_1^'n^'n) = 0" |
33175 | 297 |
by (simp add: det_def setprod_zero) |
298 |
||
299 |
lemma det_permute_rows: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
300 |
fixes A :: "'a::comm_ring_1^'n^'n" |
33175 | 301 |
assumes p: "p permutes (UNIV :: 'n::finite set)" |
53854 | 302 |
shows "det (\<chi> i. A$p i :: 'a^'n^'n) = of_int (sign p) * det A" |
33175 | 303 |
apply (simp add: det_def setsum_right_distrib mult_assoc[symmetric]) |
304 |
apply (subst sum_permutations_compose_right[OF p]) |
|
53253 | 305 |
proof (rule setsum_cong2) |
33175 | 306 |
let ?U = "UNIV :: 'n set" |
307 |
let ?PU = "{p. p permutes ?U}" |
|
53253 | 308 |
fix q |
309 |
assume qPU: "q \<in> ?PU" |
|
53854 | 310 |
have fU: "finite ?U" |
311 |
by simp |
|
53253 | 312 |
from qPU have q: "q permutes ?U" |
313 |
by blast |
|
33175 | 314 |
from p q have pp: "permutation p" and qp: "permutation q" |
315 |
by (metis fU permutation_permutes)+ |
|
316 |
from permutes_inv[OF p] have ip: "inv p permutes ?U" . |
|
53854 | 317 |
have "setprod (\<lambda>i. A$p i$ (q \<circ> p) i) ?U = setprod ((\<lambda>i. A$p i$(q \<circ> p) i) \<circ> inv p) ?U" |
53253 | 318 |
by (simp only: setprod_permute[OF ip, symmetric]) |
53854 | 319 |
also have "\<dots> = setprod (\<lambda>i. A $ (p \<circ> inv p) i $ (q \<circ> (p \<circ> inv p)) i) ?U" |
53253 | 320 |
by (simp only: o_def) |
321 |
also have "\<dots> = setprod (\<lambda>i. A$i$q i) ?U" |
|
322 |
by (simp only: o_def permutes_inverses[OF p]) |
|
53854 | 323 |
finally have thp: "setprod (\<lambda>i. A$p i$ (q \<circ> p) i) ?U = setprod (\<lambda>i. A$i$q i) ?U" |
53253 | 324 |
by blast |
53854 | 325 |
show "of_int (sign (q \<circ> p)) * setprod (\<lambda>i. A$ p i$ (q \<circ> p) i) ?U = |
53253 | 326 |
of_int (sign p) * of_int (sign q) * setprod (\<lambda>i. A$i$q i) ?U" |
33175 | 327 |
by (simp only: thp sign_compose[OF qp pp] mult_commute of_int_mult) |
328 |
qed |
|
329 |
||
330 |
lemma det_permute_columns: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
331 |
fixes A :: "'a::comm_ring_1^'n^'n" |
33175 | 332 |
assumes p: "p permutes (UNIV :: 'n set)" |
333 |
shows "det(\<chi> i j. A$i$ p j :: 'a^'n^'n) = of_int (sign p) * det A" |
|
53253 | 334 |
proof - |
33175 | 335 |
let ?Ap = "\<chi> i j. A$i$ p j :: 'a^'n^'n" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
336 |
let ?At = "transpose A" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
337 |
have "of_int (sign p) * det A = det (transpose (\<chi> i. transpose A $ p i))" |
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
338 |
unfolding det_permute_rows[OF p, of ?At] det_transpose .. |
33175 | 339 |
moreover |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
340 |
have "?Ap = transpose (\<chi> i. transpose A $ p i)" |
44228
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
341 |
by (simp add: transpose_def vec_eq_iff) |
53854 | 342 |
ultimately show ?thesis |
343 |
by simp |
|
33175 | 344 |
qed |
345 |
||
346 |
lemma det_identical_rows: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
347 |
fixes A :: "'a::linordered_idom^'n^'n" |
33175 | 348 |
assumes ij: "i \<noteq> j" |
53253 | 349 |
and r: "row i A = row j A" |
33175 | 350 |
shows "det A = 0" |
351 |
proof- |
|
53253 | 352 |
have tha: "\<And>(a::'a) b. a = b \<Longrightarrow> b = - a \<Longrightarrow> a = 0" |
33175 | 353 |
by simp |
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
44457
diff
changeset
|
354 |
have th1: "of_int (-1) = - 1" by simp |
33175 | 355 |
let ?p = "Fun.swap i j id" |
356 |
let ?A = "\<chi> i. A $ ?p i" |
|
56545 | 357 |
from r have "A = ?A" by (simp add: vec_eq_iff row_def Fun.swap_def) |
53253 | 358 |
then have "det A = det ?A" by simp |
33175 | 359 |
moreover have "det A = - det ?A" |
360 |
by (simp add: det_permute_rows[OF permutes_swap_id] sign_swap_id ij th1) |
|
361 |
ultimately show "det A = 0" by (metis tha) |
|
362 |
qed |
|
363 |
||
364 |
lemma det_identical_columns: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
365 |
fixes A :: "'a::linordered_idom^'n^'n" |
33175 | 366 |
assumes ij: "i \<noteq> j" |
53253 | 367 |
and r: "column i A = column j A" |
33175 | 368 |
shows "det A = 0" |
53253 | 369 |
apply (subst det_transpose[symmetric]) |
370 |
apply (rule det_identical_rows[OF ij]) |
|
371 |
apply (metis row_transpose r) |
|
372 |
done |
|
33175 | 373 |
|
374 |
lemma det_zero_row: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
375 |
fixes A :: "'a::{idom, ring_char_0}^'n^'n" |
33175 | 376 |
assumes r: "row i A = 0" |
377 |
shows "det A = 0" |
|
53253 | 378 |
using r |
379 |
apply (simp add: row_def det_def vec_eq_iff) |
|
380 |
apply (rule setsum_0') |
|
381 |
apply (auto simp: sign_nz) |
|
382 |
done |
|
33175 | 383 |
|
384 |
lemma det_zero_column: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
385 |
fixes A :: "'a::{idom,ring_char_0}^'n^'n" |
33175 | 386 |
assumes r: "column i A = 0" |
387 |
shows "det A = 0" |
|
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
388 |
apply (subst det_transpose[symmetric]) |
33175 | 389 |
apply (rule det_zero_row [of i]) |
53253 | 390 |
apply (metis row_transpose r) |
391 |
done |
|
33175 | 392 |
|
393 |
lemma det_row_add: |
|
394 |
fixes a b c :: "'n::finite \<Rightarrow> _ ^ 'n" |
|
395 |
shows "det((\<chi> i. if i = k then a i + b i else c i)::'a::comm_ring_1^'n^'n) = |
|
53253 | 396 |
det((\<chi> i. if i = k then a i else c i)::'a::comm_ring_1^'n^'n) + |
397 |
det((\<chi> i. if i = k then b i else c i)::'a::comm_ring_1^'n^'n)" |
|
53854 | 398 |
unfolding det_def vec_lambda_beta setsum_addf[symmetric] |
33175 | 399 |
proof (rule setsum_cong2) |
400 |
let ?U = "UNIV :: 'n set" |
|
401 |
let ?pU = "{p. p permutes ?U}" |
|
402 |
let ?f = "(\<lambda>i. if i = k then a i + b i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n" |
|
403 |
let ?g = "(\<lambda> i. if i = k then a i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n" |
|
404 |
let ?h = "(\<lambda> i. if i = k then b i else c i)::'n \<Rightarrow> 'a::comm_ring_1^'n" |
|
53253 | 405 |
fix p |
406 |
assume p: "p \<in> ?pU" |
|
33175 | 407 |
let ?Uk = "?U - {k}" |
53854 | 408 |
from p have pU: "p permutes ?U" |
409 |
by blast |
|
410 |
have kU: "?U = insert k ?Uk" |
|
411 |
by blast |
|
53253 | 412 |
{ |
413 |
fix j |
|
414 |
assume j: "j \<in> ?Uk" |
|
33175 | 415 |
from j have "?f j $ p j = ?g j $ p j" and "?f j $ p j= ?h j $ p j" |
53253 | 416 |
by simp_all |
417 |
} |
|
33175 | 418 |
then have th1: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?g i $ p i) ?Uk" |
419 |
and th2: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?h i $ p i) ?Uk" |
|
420 |
apply - |
|
421 |
apply (rule setprod_cong, simp_all)+ |
|
422 |
done |
|
53854 | 423 |
have th3: "finite ?Uk" "k \<notin> ?Uk" |
424 |
by auto |
|
33175 | 425 |
have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?f i $ p i) (insert k ?Uk)" |
426 |
unfolding kU[symmetric] .. |
|
53854 | 427 |
also have "\<dots> = ?f k $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk" |
33175 | 428 |
apply (rule setprod_insert) |
429 |
apply simp |
|
53253 | 430 |
apply blast |
431 |
done |
|
432 |
also have "\<dots> = (a k $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk) + (b k$ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk)" |
|
433 |
by (simp add: field_simps) |
|
434 |
also have "\<dots> = (a k $ p k * setprod (\<lambda>i. ?g i $ p i) ?Uk) + (b k$ p k * setprod (\<lambda>i. ?h i $ p i) ?Uk)" |
|
435 |
by (metis th1 th2) |
|
33175 | 436 |
also have "\<dots> = setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk) + setprod (\<lambda>i. ?h i $ p i) (insert k ?Uk)" |
437 |
unfolding setprod_insert[OF th3] by simp |
|
53854 | 438 |
finally have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?g i $ p i) ?U + setprod (\<lambda>i. ?h i $ p i) ?U" |
439 |
unfolding kU[symmetric] . |
|
53253 | 440 |
then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U = |
441 |
of_int (sign p) * setprod (\<lambda>i. ?g i $ p i) ?U + of_int (sign p) * setprod (\<lambda>i. ?h i $ p i) ?U" |
|
36350 | 442 |
by (simp add: field_simps) |
33175 | 443 |
qed |
444 |
||
445 |
lemma det_row_mul: |
|
446 |
fixes a b :: "'n::finite \<Rightarrow> _ ^ 'n" |
|
447 |
shows "det((\<chi> i. if i = k then c *s a i else b i)::'a::comm_ring_1^'n^'n) = |
|
53253 | 448 |
c * det((\<chi> i. if i = k then a i else b i)::'a::comm_ring_1^'n^'n)" |
449 |
unfolding det_def vec_lambda_beta setsum_right_distrib |
|
33175 | 450 |
proof (rule setsum_cong2) |
451 |
let ?U = "UNIV :: 'n set" |
|
452 |
let ?pU = "{p. p permutes ?U}" |
|
453 |
let ?f = "(\<lambda>i. if i = k then c*s a i else b i)::'n \<Rightarrow> 'a::comm_ring_1^'n" |
|
454 |
let ?g = "(\<lambda> i. if i = k then a i else b i)::'n \<Rightarrow> 'a::comm_ring_1^'n" |
|
53253 | 455 |
fix p |
456 |
assume p: "p \<in> ?pU" |
|
33175 | 457 |
let ?Uk = "?U - {k}" |
53854 | 458 |
from p have pU: "p permutes ?U" |
459 |
by blast |
|
460 |
have kU: "?U = insert k ?Uk" |
|
461 |
by blast |
|
53253 | 462 |
{ |
463 |
fix j |
|
464 |
assume j: "j \<in> ?Uk" |
|
53854 | 465 |
from j have "?f j $ p j = ?g j $ p j" |
466 |
by simp |
|
53253 | 467 |
} |
33175 | 468 |
then have th1: "setprod (\<lambda>i. ?f i $ p i) ?Uk = setprod (\<lambda>i. ?g i $ p i) ?Uk" |
469 |
apply - |
|
53253 | 470 |
apply (rule setprod_cong) |
471 |
apply simp_all |
|
33175 | 472 |
done |
53854 | 473 |
have th3: "finite ?Uk" "k \<notin> ?Uk" |
474 |
by auto |
|
33175 | 475 |
have "setprod (\<lambda>i. ?f i $ p i) ?U = setprod (\<lambda>i. ?f i $ p i) (insert k ?Uk)" |
476 |
unfolding kU[symmetric] .. |
|
477 |
also have "\<dots> = ?f k $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk" |
|
478 |
apply (rule setprod_insert) |
|
479 |
apply simp |
|
53253 | 480 |
apply blast |
481 |
done |
|
482 |
also have "\<dots> = (c*s a k) $ p k * setprod (\<lambda>i. ?f i $ p i) ?Uk" |
|
483 |
by (simp add: field_simps) |
|
33175 | 484 |
also have "\<dots> = c* (a k $ p k * setprod (\<lambda>i. ?g i $ p i) ?Uk)" |
485 |
unfolding th1 by (simp add: mult_ac) |
|
486 |
also have "\<dots> = c* (setprod (\<lambda>i. ?g i $ p i) (insert k ?Uk))" |
|
53253 | 487 |
unfolding setprod_insert[OF th3] by simp |
488 |
finally have "setprod (\<lambda>i. ?f i $ p i) ?U = c* (setprod (\<lambda>i. ?g i $ p i) ?U)" |
|
489 |
unfolding kU[symmetric] . |
|
490 |
then show "of_int (sign p) * setprod (\<lambda>i. ?f i $ p i) ?U = |
|
491 |
c * (of_int (sign p) * setprod (\<lambda>i. ?g i $ p i) ?U)" |
|
36350 | 492 |
by (simp add: field_simps) |
33175 | 493 |
qed |
494 |
||
495 |
lemma det_row_0: |
|
496 |
fixes b :: "'n::finite \<Rightarrow> _ ^ 'n" |
|
497 |
shows "det((\<chi> i. if i = k then 0 else b i)::'a::comm_ring_1^'n^'n) = 0" |
|
53253 | 498 |
using det_row_mul[of k 0 "\<lambda>i. 1" b] |
499 |
apply simp |
|
500 |
apply (simp only: vector_smult_lzero) |
|
501 |
done |
|
33175 | 502 |
|
503 |
lemma det_row_operation: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
504 |
fixes A :: "'a::linordered_idom^'n^'n" |
33175 | 505 |
assumes ij: "i \<noteq> j" |
506 |
shows "det (\<chi> k. if k = i then row i A + c *s row j A else row k A) = det A" |
|
53253 | 507 |
proof - |
33175 | 508 |
let ?Z = "(\<chi> k. if k = i then row j A else row k A) :: 'a ^'n^'n" |
509 |
have th: "row i ?Z = row j ?Z" by (vector row_def) |
|
510 |
have th2: "((\<chi> k. if k = i then row i A else row k A) :: 'a^'n^'n) = A" |
|
511 |
by (vector row_def) |
|
512 |
show ?thesis |
|
513 |
unfolding det_row_add [of i] det_row_mul[of i] det_identical_rows[OF ij th] th2 |
|
514 |
by simp |
|
515 |
qed |
|
516 |
||
517 |
lemma det_row_span: |
|
36593
fb69c8cd27bd
define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents:
36585
diff
changeset
|
518 |
fixes A :: "real^'n^'n" |
33175 | 519 |
assumes x: "x \<in> span {row j A |j. j \<noteq> i}" |
520 |
shows "det (\<chi> k. if k = i then row i A + x else row k A) = det A" |
|
53253 | 521 |
proof - |
33175 | 522 |
let ?U = "UNIV :: 'n set" |
523 |
let ?S = "{row j A |j. j \<noteq> i}" |
|
524 |
let ?d = "\<lambda>x. det (\<chi> k. if k = i then x else row k A)" |
|
525 |
let ?P = "\<lambda>x. ?d (row i A + x) = det A" |
|
53253 | 526 |
{ |
527 |
fix k |
|
53854 | 528 |
have "(if k = i then row i A + 0 else row k A) = row k A" |
529 |
by simp |
|
53253 | 530 |
} |
33175 | 531 |
then have P0: "?P 0" |
532 |
apply - |
|
533 |
apply (rule cong[of det, OF refl]) |
|
53253 | 534 |
apply (vector row_def) |
535 |
done |
|
33175 | 536 |
moreover |
53253 | 537 |
{ |
538 |
fix c z y |
|
539 |
assume zS: "z \<in> ?S" and Py: "?P y" |
|
53854 | 540 |
from zS obtain j where j: "z = row j A" "i \<noteq> j" |
541 |
by blast |
|
33175 | 542 |
let ?w = "row i A + y" |
53854 | 543 |
have th0: "row i A + (c*s z + y) = ?w + c*s z" |
544 |
by vector |
|
33175 | 545 |
have thz: "?d z = 0" |
546 |
apply (rule det_identical_rows[OF j(2)]) |
|
53253 | 547 |
using j |
548 |
apply (vector row_def) |
|
549 |
done |
|
550 |
have "?d (row i A + (c*s z + y)) = ?d (?w + c*s z)" |
|
551 |
unfolding th0 .. |
|
552 |
then have "?P (c*s z + y)" |
|
553 |
unfolding thz Py det_row_mul[of i] det_row_add[of i] |
|
554 |
by simp |
|
555 |
} |
|
33175 | 556 |
ultimately show ?thesis |
557 |
apply - |
|
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
558 |
apply (rule span_induct_alt[of ?P ?S, OF P0, folded scalar_mult_eq_scaleR]) |
33175 | 559 |
apply blast |
560 |
apply (rule x) |
|
561 |
done |
|
562 |
qed |
|
563 |
||
53854 | 564 |
text {* |
565 |
May as well do this, though it's a bit unsatisfactory since it ignores |
|
566 |
exact duplicates by considering the rows/columns as a set. |
|
567 |
*} |
|
33175 | 568 |
|
569 |
lemma det_dependent_rows: |
|
36593
fb69c8cd27bd
define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents:
36585
diff
changeset
|
570 |
fixes A:: "real^'n^'n" |
33175 | 571 |
assumes d: "dependent (rows A)" |
572 |
shows "det A = 0" |
|
53253 | 573 |
proof - |
33175 | 574 |
let ?U = "UNIV :: 'n set" |
575 |
from d obtain i where i: "row i A \<in> span (rows A - {row i A})" |
|
576 |
unfolding dependent_def rows_def by blast |
|
53253 | 577 |
{ |
578 |
fix j k |
|
579 |
assume jk: "j \<noteq> k" and c: "row j A = row k A" |
|
580 |
from det_identical_rows[OF jk c] have ?thesis . |
|
581 |
} |
|
33175 | 582 |
moreover |
53253 | 583 |
{ |
584 |
assume H: "\<And> i j. i \<noteq> j \<Longrightarrow> row i A \<noteq> row j A" |
|
33175 | 585 |
have th0: "- row i A \<in> span {row j A|j. j \<noteq> i}" |
586 |
apply (rule span_neg) |
|
587 |
apply (rule set_rev_mp) |
|
588 |
apply (rule i) |
|
589 |
apply (rule span_mono) |
|
53253 | 590 |
using H i |
591 |
apply (auto simp add: rows_def) |
|
592 |
done |
|
33175 | 593 |
from det_row_span[OF th0] |
594 |
have "det A = det (\<chi> k. if k = i then 0 *s 1 else row k A)" |
|
595 |
unfolding right_minus vector_smult_lzero .. |
|
36593
fb69c8cd27bd
define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents:
36585
diff
changeset
|
596 |
with det_row_mul[of i "0::real" "\<lambda>i. 1"] |
53253 | 597 |
have "det A = 0" by simp |
598 |
} |
|
33175 | 599 |
ultimately show ?thesis by blast |
600 |
qed |
|
601 |
||
53253 | 602 |
lemma det_dependent_columns: |
603 |
assumes d: "dependent (columns (A::real^'n^'n))" |
|
604 |
shows "det A = 0" |
|
605 |
by (metis d det_dependent_rows rows_transpose det_transpose) |
|
33175 | 606 |
|
53854 | 607 |
text {* Multilinearity and the multiplication formula. *} |
33175 | 608 |
|
44228
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
609 |
lemma Cart_lambda_cong: "(\<And>x. f x = g x) \<Longrightarrow> (vec_lambda f::'a^'n) = (vec_lambda g :: 'a^'n)" |
53253 | 610 |
by (rule iffD1[OF vec_lambda_unique]) vector |
33175 | 611 |
|
612 |
lemma det_linear_row_setsum: |
|
613 |
assumes fS: "finite S" |
|
53253 | 614 |
shows "det ((\<chi> i. if i = k then setsum (a i) S else c i)::'a::comm_ring_1^'n^'n) = |
615 |
setsum (\<lambda>j. det ((\<chi> i. if i = k then a i j else c i)::'a^'n^'n)) S" |
|
616 |
proof (induct rule: finite_induct[OF fS]) |
|
617 |
case 1 |
|
618 |
then show ?case |
|
619 |
apply simp |
|
620 |
unfolding setsum_empty det_row_0[of k] |
|
621 |
apply rule |
|
622 |
done |
|
33175 | 623 |
next |
624 |
case (2 x F) |
|
53253 | 625 |
then show ?case |
626 |
by (simp add: det_row_add cong del: if_weak_cong) |
|
33175 | 627 |
qed |
628 |
||
629 |
lemma finite_bounded_functions: |
|
630 |
assumes fS: "finite S" |
|
631 |
shows "finite {f. (\<forall>i \<in> {1.. (k::nat)}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1 .. k} \<longrightarrow> f i = i)}" |
|
53253 | 632 |
proof (induct k) |
33175 | 633 |
case 0 |
53854 | 634 |
have th: "{f. \<forall>i. f i = i} = {id}" |
635 |
by auto |
|
636 |
show ?case |
|
637 |
by (auto simp add: th) |
|
33175 | 638 |
next |
639 |
case (Suc k) |
|
640 |
let ?f = "\<lambda>(y::nat,g) i. if i = Suc k then y else g i" |
|
641 |
let ?S = "?f ` (S \<times> {f. (\<forall>i\<in>{1..k}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1..k} \<longrightarrow> f i = i)})" |
|
642 |
have "?S = {f. (\<forall>i\<in>{1.. Suc k}. f i \<in> S) \<and> (\<forall>i. i \<notin> {1.. Suc k} \<longrightarrow> f i = i)}" |
|
643 |
apply (auto simp add: image_iff) |
|
644 |
apply (rule_tac x="x (Suc k)" in bexI) |
|
645 |
apply (rule_tac x = "\<lambda>i. if i = Suc k then i else x i" in exI) |
|
44457
d366fa5551ef
declare euclidean_simps [simp] at the point they are proved;
huffman
parents:
44260
diff
changeset
|
646 |
apply auto |
33175 | 647 |
done |
648 |
with finite_imageI[OF finite_cartesian_product[OF fS Suc.hyps(1)], of ?f] |
|
53854 | 649 |
show ?case |
650 |
by metis |
|
33175 | 651 |
qed |
652 |
||
653 |
||
53854 | 654 |
lemma eq_id_iff[simp]: "(\<forall>x. f x = x) \<longleftrightarrow> f = id" |
655 |
by auto |
|
33175 | 656 |
|
657 |
lemma det_linear_rows_setsum_lemma: |
|
53854 | 658 |
assumes fS: "finite S" |
659 |
and fT: "finite T" |
|
660 |
shows "det ((\<chi> i. if i \<in> T then setsum (a i) S else c i):: 'a::comm_ring_1^'n^'n) = |
|
53253 | 661 |
setsum (\<lambda>f. det((\<chi> i. if i \<in> T then a i (f i) else c i)::'a^'n^'n)) |
662 |
{f. (\<forall>i \<in> T. f i \<in> S) \<and> (\<forall>i. i \<notin> T \<longrightarrow> f i = i)}" |
|
663 |
using fT |
|
664 |
proof (induct T arbitrary: a c set: finite) |
|
33175 | 665 |
case empty |
53253 | 666 |
have th0: "\<And>x y. (\<chi> i. if i \<in> {} then x i else y i) = (\<chi> i. y i)" |
667 |
by vector |
|
53854 | 668 |
from empty.prems show ?case |
669 |
unfolding th0 by simp |
|
33175 | 670 |
next |
671 |
case (insert z T a c) |
|
672 |
let ?F = "\<lambda>T. {f. (\<forall>i \<in> T. f i \<in> S) \<and> (\<forall>i. i \<notin> T \<longrightarrow> f i = i)}" |
|
673 |
let ?h = "\<lambda>(y,g) i. if i = z then y else g i" |
|
674 |
let ?k = "\<lambda>h. (h(z),(\<lambda>i. if i = z then i else h i))" |
|
675 |
let ?s = "\<lambda> k a c f. det((\<chi> i. if i \<in> T then a i (f i) else c i)::'a^'n^'n)" |
|
57129
7edb7550663e
introduce more powerful reindexing rules for big operators
hoelzl
parents:
56545
diff
changeset
|
676 |
let ?c = "\<lambda>j i. if i = z then a i j else c i" |
53253 | 677 |
have thif: "\<And>a b c d. (if a \<or> b then c else d) = (if a then c else if b then c else d)" |
678 |
by simp |
|
33175 | 679 |
have thif2: "\<And>a b c d e. (if a then b else if c then d else e) = |
53253 | 680 |
(if c then (if a then b else d) else (if a then b else e))" |
681 |
by simp |
|
682 |
from `z \<notin> T` have nz: "\<And>i. i \<in> T \<Longrightarrow> i = z \<longleftrightarrow> False" |
|
683 |
by auto |
|
33175 | 684 |
have "det (\<chi> i. if i \<in> insert z T then setsum (a i) S else c i) = |
53253 | 685 |
det (\<chi> i. if i = z then setsum (a i) S else if i \<in> T then setsum (a i) S else c i)" |
33175 | 686 |
unfolding insert_iff thif .. |
53253 | 687 |
also have "\<dots> = (\<Sum>j\<in>S. det (\<chi> i. if i \<in> T then setsum (a i) S else if i = z then a i j else c i))" |
33175 | 688 |
unfolding det_linear_row_setsum[OF fS] |
689 |
apply (subst thif2) |
|
53253 | 690 |
using nz |
691 |
apply (simp cong del: if_weak_cong cong add: if_cong) |
|
692 |
done |
|
33175 | 693 |
finally have tha: |
694 |
"det (\<chi> i. if i \<in> insert z T then setsum (a i) S else c i) = |
|
695 |
(\<Sum>(j, f)\<in>S \<times> ?F T. det (\<chi> i. if i \<in> T then a i (f i) |
|
696 |
else if i = z then a i j |
|
697 |
else c i))" |
|
53253 | 698 |
unfolding insert.hyps unfolding setsum_cartesian_product by blast |
33175 | 699 |
show ?case unfolding tha |
700 |
using `z \<notin> T` |
|
57129
7edb7550663e
introduce more powerful reindexing rules for big operators
hoelzl
parents:
56545
diff
changeset
|
701 |
by (intro setsum.reindex_bij_witness[where i="?k" and j="?h"]) |
7edb7550663e
introduce more powerful reindexing rules for big operators
hoelzl
parents:
56545
diff
changeset
|
702 |
(auto intro!: cong[OF refl[of det]] simp: vec_eq_iff) |
33175 | 703 |
qed |
704 |
||
705 |
lemma det_linear_rows_setsum: |
|
53854 | 706 |
fixes S :: "'n::finite set" |
707 |
assumes fS: "finite S" |
|
53253 | 708 |
shows "det (\<chi> i. setsum (a i) S) = |
709 |
setsum (\<lambda>f. det (\<chi> i. a i (f i) :: 'a::comm_ring_1 ^ 'n^'n)) {f. \<forall>i. f i \<in> S}" |
|
710 |
proof - |
|
711 |
have th0: "\<And>x y. ((\<chi> i. if i \<in> (UNIV:: 'n set) then x i else y i) :: 'a^'n^'n) = (\<chi> i. x i)" |
|
712 |
by vector |
|
713 |
from det_linear_rows_setsum_lemma[OF fS, of "UNIV :: 'n set" a, unfolded th0, OF finite] |
|
714 |
show ?thesis by simp |
|
33175 | 715 |
qed |
716 |
||
717 |
lemma matrix_mul_setsum_alt: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
718 |
fixes A B :: "'a::comm_ring_1^'n^'n" |
33175 | 719 |
shows "A ** B = (\<chi> i. setsum (\<lambda>k. A$i$k *s B $ k) (UNIV :: 'n set))" |
720 |
by (vector matrix_matrix_mult_def setsum_component) |
|
721 |
||
722 |
lemma det_rows_mul: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
723 |
"det((\<chi> i. c i *s a i)::'a::comm_ring_1^'n^'n) = |
53253 | 724 |
setprod (\<lambda>i. c i) (UNIV:: 'n set) * det((\<chi> i. a i)::'a^'n^'n)" |
33175 | 725 |
proof (simp add: det_def setsum_right_distrib cong add: setprod_cong, rule setsum_cong2) |
726 |
let ?U = "UNIV :: 'n set" |
|
727 |
let ?PU = "{p. p permutes ?U}" |
|
53253 | 728 |
fix p |
729 |
assume pU: "p \<in> ?PU" |
|
33175 | 730 |
let ?s = "of_int (sign p)" |
53253 | 731 |
from pU have p: "p permutes ?U" |
732 |
by blast |
|
33175 | 733 |
have "setprod (\<lambda>i. c i * a i $ p i) ?U = setprod c ?U * setprod (\<lambda>i. a i $ p i) ?U" |
734 |
unfolding setprod_timesf .. |
|
735 |
then show "?s * (\<Prod>xa\<in>?U. c xa * a xa $ p xa) = |
|
53854 | 736 |
setprod c ?U * (?s* (\<Prod>xa\<in>?U. a xa $ p xa))" |
737 |
by (simp add: field_simps) |
|
33175 | 738 |
qed |
739 |
||
740 |
lemma det_mul: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
741 |
fixes A B :: "'a::linordered_idom^'n^'n" |
33175 | 742 |
shows "det (A ** B) = det A * det B" |
53253 | 743 |
proof - |
33175 | 744 |
let ?U = "UNIV :: 'n set" |
745 |
let ?F = "{f. (\<forall>i\<in> ?U. f i \<in> ?U) \<and> (\<forall>i. i \<notin> ?U \<longrightarrow> f i = i)}" |
|
746 |
let ?PU = "{p. p permutes ?U}" |
|
53854 | 747 |
have fU: "finite ?U" |
748 |
by simp |
|
749 |
have fF: "finite ?F" |
|
750 |
by (rule finite) |
|
53253 | 751 |
{ |
752 |
fix p |
|
753 |
assume p: "p permutes ?U" |
|
33175 | 754 |
have "p \<in> ?F" unfolding mem_Collect_eq permutes_in_image[OF p] |
53253 | 755 |
using p[unfolded permutes_def] by simp |
756 |
} |
|
53854 | 757 |
then have PUF: "?PU \<subseteq> ?F" by blast |
53253 | 758 |
{ |
759 |
fix f |
|
760 |
assume fPU: "f \<in> ?F - ?PU" |
|
53854 | 761 |
have fUU: "f ` ?U \<subseteq> ?U" |
762 |
using fPU by auto |
|
53253 | 763 |
from fPU have f: "\<forall>i \<in> ?U. f i \<in> ?U" "\<forall>i. i \<notin> ?U \<longrightarrow> f i = i" "\<not>(\<forall>y. \<exists>!x. f x = y)" |
764 |
unfolding permutes_def by auto |
|
33175 | 765 |
|
766 |
let ?A = "(\<chi> i. A$i$f i *s B$f i) :: 'a^'n^'n" |
|
767 |
let ?B = "(\<chi> i. B$f i) :: 'a^'n^'n" |
|
53253 | 768 |
{ |
769 |
assume fni: "\<not> inj_on f ?U" |
|
33175 | 770 |
then obtain i j where ij: "f i = f j" "i \<noteq> j" |
771 |
unfolding inj_on_def by blast |
|
772 |
from ij |
|
53854 | 773 |
have rth: "row i ?B = row j ?B" |
774 |
by (vector row_def) |
|
33175 | 775 |
from det_identical_rows[OF ij(2) rth] |
776 |
have "det (\<chi> i. A$i$f i *s B$f i) = 0" |
|
53253 | 777 |
unfolding det_rows_mul by simp |
778 |
} |
|
33175 | 779 |
moreover |
53253 | 780 |
{ |
781 |
assume fi: "inj_on f ?U" |
|
33175 | 782 |
from f fi have fith: "\<And>i j. f i = f j \<Longrightarrow> i = j" |
783 |
unfolding inj_on_def by metis |
|
784 |
note fs = fi[unfolded surjective_iff_injective_gen[OF fU fU refl fUU, symmetric]] |
|
53253 | 785 |
{ |
786 |
fix y |
|
53854 | 787 |
from fs f have "\<exists>x. f x = y" |
788 |
by blast |
|
789 |
then obtain x where x: "f x = y" |
|
790 |
by blast |
|
53253 | 791 |
{ |
792 |
fix z |
|
793 |
assume z: "f z = y" |
|
53854 | 794 |
from fith x z have "z = x" |
795 |
by metis |
|
53253 | 796 |
} |
53854 | 797 |
with x have "\<exists>!x. f x = y" |
798 |
by blast |
|
53253 | 799 |
} |
53854 | 800 |
with f(3) have "det (\<chi> i. A$i$f i *s B$f i) = 0" |
801 |
by blast |
|
53253 | 802 |
} |
53854 | 803 |
ultimately have "det (\<chi> i. A$i$f i *s B$f i) = 0" |
804 |
by blast |
|
53253 | 805 |
} |
53854 | 806 |
then have zth: "\<forall> f\<in> ?F - ?PU. det (\<chi> i. A$i$f i *s B$f i) = 0" |
53253 | 807 |
by simp |
808 |
{ |
|
809 |
fix p |
|
810 |
assume pU: "p \<in> ?PU" |
|
53854 | 811 |
from pU have p: "p permutes ?U" |
812 |
by blast |
|
33175 | 813 |
let ?s = "\<lambda>p. of_int (sign p)" |
53253 | 814 |
let ?f = "\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) * (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))" |
33175 | 815 |
have "(setsum (\<lambda>q. ?s q * |
53253 | 816 |
(\<Prod>i\<in> ?U. (\<chi> i. A $ i $ p i *s B $ p i :: 'a^'n^'n) $ i $ q i)) ?PU) = |
817 |
(setsum (\<lambda>q. ?s p * (\<Prod>i\<in> ?U. A $ i $ p i) * (?s q * (\<Prod>i\<in> ?U. B $ i $ q i))) ?PU)" |
|
33175 | 818 |
unfolding sum_permutations_compose_right[OF permutes_inv[OF p], of ?f] |
53854 | 819 |
proof (rule setsum_cong2) |
53253 | 820 |
fix q |
821 |
assume qU: "q \<in> ?PU" |
|
53854 | 822 |
then have q: "q permutes ?U" |
823 |
by blast |
|
33175 | 824 |
from p q have pp: "permutation p" and pq: "permutation q" |
825 |
unfolding permutation_permutes by auto |
|
826 |
have th00: "of_int (sign p) * of_int (sign p) = (1::'a)" |
|
827 |
"\<And>a. of_int (sign p) * (of_int (sign p) * a) = a" |
|
53854 | 828 |
unfolding mult_assoc[symmetric] |
829 |
unfolding of_int_mult[symmetric] |
|
33175 | 830 |
by (simp_all add: sign_idempotent) |
53854 | 831 |
have ths: "?s q = ?s p * ?s (q \<circ> inv p)" |
33175 | 832 |
using pp pq permutation_inverse[OF pp] sign_inverse[OF pp] |
833 |
by (simp add: th00 mult_ac sign_idempotent sign_compose) |
|
53854 | 834 |
have th001: "setprod (\<lambda>i. B$i$ q (inv p i)) ?U = setprod ((\<lambda>i. B$i$ q (inv p i)) \<circ> p) ?U" |
33175 | 835 |
by (rule setprod_permute[OF p]) |
53253 | 836 |
have thp: "setprod (\<lambda>i. (\<chi> i. A$i$p i *s B$p i :: 'a^'n^'n) $i $ q i) ?U = |
837 |
setprod (\<lambda>i. A$i$p i) ?U * setprod (\<lambda>i. B$i$ q (inv p i)) ?U" |
|
33175 | 838 |
unfolding th001 setprod_timesf[symmetric] o_def permutes_inverses[OF p] |
839 |
apply (rule setprod_cong[OF refl]) |
|
53253 | 840 |
using permutes_in_image[OF q] |
841 |
apply vector |
|
842 |
done |
|
843 |
show "?s q * setprod (\<lambda>i. (((\<chi> i. A$i$p i *s B$p i) :: 'a^'n^'n)$i$q i)) ?U = |
|
53854 | 844 |
?s p * (setprod (\<lambda>i. A$i$p i) ?U) * (?s (q \<circ> inv p) * setprod (\<lambda>i. B$i$(q \<circ> inv p) i) ?U)" |
33175 | 845 |
using ths thp pp pq permutation_inverse[OF pp] sign_inverse[OF pp] |
36350 | 846 |
by (simp add: sign_nz th00 field_simps sign_idempotent sign_compose) |
33175 | 847 |
qed |
848 |
} |
|
849 |
then have th2: "setsum (\<lambda>f. det (\<chi> i. A$i$f i *s B$f i)) ?PU = det A * det B" |
|
850 |
unfolding det_def setsum_product |
|
851 |
by (rule setsum_cong2) |
|
852 |
have "det (A**B) = setsum (\<lambda>f. det (\<chi> i. A $ i $ f i *s B $ f i)) ?F" |
|
53854 | 853 |
unfolding matrix_mul_setsum_alt det_linear_rows_setsum[OF fU] |
854 |
by simp |
|
33175 | 855 |
also have "\<dots> = setsum (\<lambda>f. det (\<chi> i. A$i$f i *s B$f i)) ?PU" |
856 |
using setsum_mono_zero_cong_left[OF fF PUF zth, symmetric] |
|
857 |
unfolding det_rows_mul by auto |
|
858 |
finally show ?thesis unfolding th2 . |
|
859 |
qed |
|
860 |
||
53854 | 861 |
text {* Relation to invertibility. *} |
33175 | 862 |
|
863 |
lemma invertible_left_inverse: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
864 |
fixes A :: "real^'n^'n" |
33175 | 865 |
shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). B** A = mat 1)" |
866 |
by (metis invertible_def matrix_left_right_inverse) |
|
867 |
||
868 |
lemma invertible_righ_inverse: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
869 |
fixes A :: "real^'n^'n" |
33175 | 870 |
shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). A** B = mat 1)" |
871 |
by (metis invertible_def matrix_left_right_inverse) |
|
872 |
||
873 |
lemma invertible_det_nz: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
874 |
fixes A::"real ^'n^'n" |
33175 | 875 |
shows "invertible A \<longleftrightarrow> det A \<noteq> 0" |
53253 | 876 |
proof - |
877 |
{ |
|
878 |
assume "invertible A" |
|
33175 | 879 |
then obtain B :: "real ^'n^'n" where B: "A ** B = mat 1" |
880 |
unfolding invertible_righ_inverse by blast |
|
53854 | 881 |
then have "det (A ** B) = det (mat 1 :: real ^'n^'n)" |
882 |
by simp |
|
883 |
then have "det A \<noteq> 0" |
|
884 |
by (simp add: det_mul det_I) algebra |
|
53253 | 885 |
} |
33175 | 886 |
moreover |
53253 | 887 |
{ |
888 |
assume H: "\<not> invertible A" |
|
33175 | 889 |
let ?U = "UNIV :: 'n set" |
53854 | 890 |
have fU: "finite ?U" |
891 |
by simp |
|
33175 | 892 |
from H obtain c i where c: "setsum (\<lambda>i. c i *s row i A) ?U = 0" |
53854 | 893 |
and iU: "i \<in> ?U" |
894 |
and ci: "c i \<noteq> 0" |
|
33175 | 895 |
unfolding invertible_righ_inverse |
53854 | 896 |
unfolding matrix_right_invertible_independent_rows |
897 |
by blast |
|
53253 | 898 |
have *: "\<And>(a::real^'n) b. a + b = 0 \<Longrightarrow> -a = b" |
33175 | 899 |
apply (drule_tac f="op + (- a)" in cong[OF refl]) |
900 |
apply (simp only: ab_left_minus add_assoc[symmetric]) |
|
901 |
apply simp |
|
902 |
done |
|
903 |
from c ci |
|
904 |
have thr0: "- row i A = setsum (\<lambda>j. (1/ c i) *s (c j *s row j A)) (?U - {i})" |
|
905 |
unfolding setsum_diff1'[OF fU iU] setsum_cmul |
|
906 |
apply - |
|
907 |
apply (rule vector_mul_lcancel_imp[OF ci]) |
|
44457
d366fa5551ef
declare euclidean_simps [simp] at the point they are proved;
huffman
parents:
44260
diff
changeset
|
908 |
apply (auto simp add: field_simps) |
53854 | 909 |
unfolding * |
910 |
apply rule |
|
911 |
done |
|
33175 | 912 |
have thr: "- row i A \<in> span {row j A| j. j \<noteq> i}" |
913 |
unfolding thr0 |
|
914 |
apply (rule span_setsum) |
|
915 |
apply simp |
|
916 |
apply (rule ballI) |
|
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
917 |
apply (rule span_mul [where 'a="real^'n", folded scalar_mult_eq_scaleR])+ |
33175 | 918 |
apply (rule span_superset) |
919 |
apply auto |
|
920 |
done |
|
921 |
let ?B = "(\<chi> k. if k = i then 0 else row k A) :: real ^'n^'n" |
|
922 |
have thrb: "row i ?B = 0" using iU by (vector row_def) |
|
923 |
have "det A = 0" |
|
924 |
unfolding det_row_span[OF thr, symmetric] right_minus |
|
53253 | 925 |
unfolding det_zero_row[OF thrb] .. |
926 |
} |
|
53854 | 927 |
ultimately show ?thesis |
928 |
by blast |
|
33175 | 929 |
qed |
930 |
||
53854 | 931 |
text {* Cramer's rule. *} |
33175 | 932 |
|
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
933 |
lemma cramer_lemma_transpose: |
53854 | 934 |
fixes A:: "real^'n^'n" |
935 |
and x :: "real^'n" |
|
33175 | 936 |
shows "det ((\<chi> i. if i = k then setsum (\<lambda>i. x$i *s row i A) (UNIV::'n set) |
53854 | 937 |
else row i A)::real^'n^'n) = x$k * det A" |
33175 | 938 |
(is "?lhs = ?rhs") |
53253 | 939 |
proof - |
33175 | 940 |
let ?U = "UNIV :: 'n set" |
941 |
let ?Uk = "?U - {k}" |
|
53854 | 942 |
have U: "?U = insert k ?Uk" |
943 |
by blast |
|
944 |
have fUk: "finite ?Uk" |
|
945 |
by simp |
|
946 |
have kUk: "k \<notin> ?Uk" |
|
947 |
by simp |
|
33175 | 948 |
have th00: "\<And>k s. x$k *s row k A + s = (x$k - 1) *s row k A + row k A + s" |
36350 | 949 |
by (vector field_simps) |
53854 | 950 |
have th001: "\<And>f k . (\<lambda>x. if x = k then f k else f x) = f" |
951 |
by auto |
|
33175 | 952 |
have "(\<chi> i. row i A) = A" by (vector row_def) |
53253 | 953 |
then have thd1: "det (\<chi> i. row i A) = det A" |
954 |
by simp |
|
33175 | 955 |
have thd0: "det (\<chi> i. if i = k then row k A + (\<Sum>i \<in> ?Uk. x $ i *s row i A) else row i A) = det A" |
956 |
apply (rule det_row_span) |
|
56196
32b7eafc5a52
remove unnecessary finiteness assumptions from lemmas about setsum
huffman
parents:
53854
diff
changeset
|
957 |
apply (rule span_setsum) |
33175 | 958 |
apply (rule ballI) |
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
959 |
apply (rule span_mul [where 'a="real^'n", folded scalar_mult_eq_scaleR])+ |
33175 | 960 |
apply (rule span_superset) |
961 |
apply auto |
|
962 |
done |
|
963 |
show "?lhs = x$k * det A" |
|
964 |
apply (subst U) |
|
965 |
unfolding setsum_insert[OF fUk kUk] |
|
966 |
apply (subst th00) |
|
967 |
unfolding add_assoc |
|
968 |
apply (subst det_row_add) |
|
969 |
unfolding thd0 |
|
970 |
unfolding det_row_mul |
|
971 |
unfolding th001[of k "\<lambda>i. row i A"] |
|
53253 | 972 |
unfolding thd1 |
973 |
apply (simp add: field_simps) |
|
974 |
done |
|
33175 | 975 |
qed |
976 |
||
977 |
lemma cramer_lemma: |
|
36593
fb69c8cd27bd
define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents:
36585
diff
changeset
|
978 |
fixes A :: "real^'n^'n" |
fb69c8cd27bd
define linear algebra concepts using scaleR instead of (op *s); generalized many lemmas, though a few theorems that used to work on type int^'n are a bit less general
huffman
parents:
36585
diff
changeset
|
979 |
shows "det((\<chi> i j. if j = k then (A *v x)$i else A$i$j):: real^'n^'n) = x$k * det A" |
53253 | 980 |
proof - |
33175 | 981 |
let ?U = "UNIV :: 'n set" |
53253 | 982 |
have *: "\<And>c. setsum (\<lambda>i. c i *s row i (transpose A)) ?U = setsum (\<lambda>i. c i *s column i A) ?U" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
983 |
by (auto simp add: row_transpose intro: setsum_cong2) |
53854 | 984 |
show ?thesis |
985 |
unfolding matrix_mult_vsum |
|
53253 | 986 |
unfolding cramer_lemma_transpose[of k x "transpose A", unfolded det_transpose, symmetric] |
987 |
unfolding *[of "\<lambda>i. x$i"] |
|
988 |
apply (subst det_transpose[symmetric]) |
|
989 |
apply (rule cong[OF refl[of det]]) |
|
990 |
apply (vector transpose_def column_def row_def) |
|
991 |
done |
|
33175 | 992 |
qed |
993 |
||
994 |
lemma cramer: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
995 |
fixes A ::"real^'n^'n" |
33175 | 996 |
assumes d0: "det A \<noteq> 0" |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
35542
diff
changeset
|
997 |
shows "A *v x = b \<longleftrightarrow> x = (\<chi> k. det(\<chi> i j. if j=k then b$i else A$i$j) / det A)" |
53253 | 998 |
proof - |
33175 | 999 |
from d0 obtain B where B: "A ** B = mat 1" "B ** A = mat 1" |
53854 | 1000 |
unfolding invertible_det_nz[symmetric] invertible_def |
1001 |
by blast |
|
1002 |
have "(A ** B) *v b = b" |
|
1003 |
by (simp add: B matrix_vector_mul_lid) |
|
1004 |
then have "A *v (B *v b) = b" |
|
1005 |
by (simp add: matrix_vector_mul_assoc) |
|
1006 |
then have xe: "\<exists>x. A *v x = b" |
|
1007 |
by blast |
|
53253 | 1008 |
{ |
1009 |
fix x |
|
1010 |
assume x: "A *v x = b" |
|
1011 |
have "x = (\<chi> k. det(\<chi> i j. if j=k then b$i else A$i$j) / det A)" |
|
1012 |
unfolding x[symmetric] |
|
1013 |
using d0 by (simp add: vec_eq_iff cramer_lemma field_simps) |
|
1014 |
} |
|
53854 | 1015 |
with xe show ?thesis |
1016 |
by auto |
|
33175 | 1017 |
qed |
1018 |
||
53854 | 1019 |
text {* Orthogonality of a transformation and matrix. *} |
33175 | 1020 |
|
1021 |
definition "orthogonal_transformation f \<longleftrightarrow> linear f \<and> (\<forall>v w. f v \<bullet> f w = v \<bullet> w)" |
|
1022 |
||
53253 | 1023 |
lemma orthogonal_transformation: |
1024 |
"orthogonal_transformation f \<longleftrightarrow> linear f \<and> (\<forall>(v::real ^_). norm (f v) = norm v)" |
|
33175 | 1025 |
unfolding orthogonal_transformation_def |
1026 |
apply auto |
|
1027 |
apply (erule_tac x=v in allE)+ |
|
35542 | 1028 |
apply (simp add: norm_eq_sqrt_inner) |
53253 | 1029 |
apply (simp add: dot_norm linear_add[symmetric]) |
1030 |
done |
|
33175 | 1031 |
|
53253 | 1032 |
definition "orthogonal_matrix (Q::'a::semiring_1^'n^'n) \<longleftrightarrow> |
1033 |
transpose Q ** Q = mat 1 \<and> Q ** transpose Q = mat 1" |
|
33175 | 1034 |
|
53253 | 1035 |
lemma orthogonal_matrix: "orthogonal_matrix (Q:: real ^'n^'n) \<longleftrightarrow> transpose Q ** Q = mat 1" |
33175 | 1036 |
by (metis matrix_left_right_inverse orthogonal_matrix_def) |
1037 |
||
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1038 |
lemma orthogonal_matrix_id: "orthogonal_matrix (mat 1 :: _^'n^'n)" |
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
1039 |
by (simp add: orthogonal_matrix_def transpose_mat matrix_mul_lid) |
33175 | 1040 |
|
1041 |
lemma orthogonal_matrix_mul: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1042 |
fixes A :: "real ^'n^'n" |
33175 | 1043 |
assumes oA : "orthogonal_matrix A" |
53253 | 1044 |
and oB: "orthogonal_matrix B" |
33175 | 1045 |
shows "orthogonal_matrix(A ** B)" |
1046 |
using oA oB |
|
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
1047 |
unfolding orthogonal_matrix matrix_transpose_mul |
33175 | 1048 |
apply (subst matrix_mul_assoc) |
1049 |
apply (subst matrix_mul_assoc[symmetric]) |
|
53253 | 1050 |
apply (simp add: matrix_mul_rid) |
1051 |
done |
|
33175 | 1052 |
|
1053 |
lemma orthogonal_transformation_matrix: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1054 |
fixes f:: "real^'n \<Rightarrow> real^'n" |
33175 | 1055 |
shows "orthogonal_transformation f \<longleftrightarrow> linear f \<and> orthogonal_matrix(matrix f)" |
1056 |
(is "?lhs \<longleftrightarrow> ?rhs") |
|
53253 | 1057 |
proof - |
33175 | 1058 |
let ?mf = "matrix f" |
1059 |
let ?ot = "orthogonal_transformation f" |
|
1060 |
let ?U = "UNIV :: 'n set" |
|
1061 |
have fU: "finite ?U" by simp |
|
1062 |
let ?m1 = "mat 1 :: real ^'n^'n" |
|
53253 | 1063 |
{ |
1064 |
assume ot: ?ot |
|
33175 | 1065 |
from ot have lf: "linear f" and fd: "\<forall>v w. f v \<bullet> f w = v \<bullet> w" |
1066 |
unfolding orthogonal_transformation_def orthogonal_matrix by blast+ |
|
53253 | 1067 |
{ |
1068 |
fix i j |
|
35150
082fa4bd403d
Rename transp to transpose in HOL-Multivariate_Analysis. (by himmelma)
hoelzl
parents:
35028
diff
changeset
|
1069 |
let ?A = "transpose ?mf ** ?mf" |
33175 | 1070 |
have th0: "\<And>b (x::'a::comm_ring_1). (if b then 1 else 0)*x = (if b then x else 0)" |
1071 |
"\<And>b (x::'a::comm_ring_1). x*(if b then 1 else 0) = (if b then x else 0)" |
|
1072 |
by simp_all |
|
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
1073 |
from fd[rule_format, of "axis i 1" "axis j 1", unfolded matrix_works[OF lf, symmetric] dot_matrix_vector_mul] |
33175 | 1074 |
have "?A$i$j = ?m1 $ i $ j" |
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
1075 |
by (simp add: inner_vec_def matrix_matrix_mult_def columnvector_def rowvector_def |
53253 | 1076 |
th0 setsum_delta[OF fU] mat_def axis_def) |
1077 |
} |
|
53854 | 1078 |
then have "orthogonal_matrix ?mf" |
1079 |
unfolding orthogonal_matrix |
|
53253 | 1080 |
by vector |
53854 | 1081 |
with lf have ?rhs |
1082 |
by blast |
|
53253 | 1083 |
} |
33175 | 1084 |
moreover |
53253 | 1085 |
{ |
1086 |
assume lf: "linear f" and om: "orthogonal_matrix ?mf" |
|
33175 | 1087 |
from lf om have ?lhs |
1088 |
unfolding orthogonal_matrix_def norm_eq orthogonal_transformation |
|
1089 |
unfolding matrix_works[OF lf, symmetric] |
|
1090 |
apply (subst dot_matrix_vector_mul) |
|
53253 | 1091 |
apply (simp add: dot_matrix_product matrix_mul_lid) |
1092 |
done |
|
1093 |
} |
|
53854 | 1094 |
ultimately show ?thesis |
1095 |
by blast |
|
33175 | 1096 |
qed |
1097 |
||
1098 |
lemma det_orthogonal_matrix: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
1099 |
fixes Q:: "'a::linordered_idom^'n^'n" |
33175 | 1100 |
assumes oQ: "orthogonal_matrix Q" |
1101 |
shows "det Q = 1 \<or> det Q = - 1" |
|
53253 | 1102 |
proof - |
33175 | 1103 |
have th: "\<And>x::'a. x = 1 \<or> x = - 1 \<longleftrightarrow> x*x = 1" (is "\<And>x::'a. ?ths x") |
53253 | 1104 |
proof - |
33175 | 1105 |
fix x:: 'a |
53854 | 1106 |
have th0: "x * x - 1 = (x - 1) * (x + 1)" |
53253 | 1107 |
by (simp add: field_simps) |
33175 | 1108 |
have th1: "\<And>(x::'a) y. x = - y \<longleftrightarrow> x + y = 0" |
53253 | 1109 |
apply (subst eq_iff_diff_eq_0) |
1110 |
apply simp |
|
1111 |
done |
|
53854 | 1112 |
have "x * x = 1 \<longleftrightarrow> x * x - 1 = 0" |
1113 |
by simp |
|
1114 |
also have "\<dots> \<longleftrightarrow> x = 1 \<or> x = - 1" |
|
1115 |
unfolding th0 th1 by simp |
|
33175 | 1116 |
finally show "?ths x" .. |
1117 |
qed |
|
53253 | 1118 |
from oQ have "Q ** transpose Q = mat 1" |
1119 |
by (metis orthogonal_matrix_def) |
|
1120 |
then have "det (Q ** transpose Q) = det (mat 1:: 'a^'n^'n)" |
|
1121 |
by simp |
|
1122 |
then have "det Q * det Q = 1" |
|
1123 |
by (simp add: det_mul det_I det_transpose) |
|
33175 | 1124 |
then show ?thesis unfolding th . |
1125 |
qed |
|
1126 |
||
53854 | 1127 |
text {* Linearity of scaling, and hence isometry, that preserves origin. *} |
1128 |
||
33175 | 1129 |
lemma scaling_linear: |
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1130 |
fixes f :: "real ^'n \<Rightarrow> real ^'n" |
53253 | 1131 |
assumes f0: "f 0 = 0" |
1132 |
and fd: "\<forall>x y. dist (f x) (f y) = c * dist x y" |
|
33175 | 1133 |
shows "linear f" |
53253 | 1134 |
proof - |
1135 |
{ |
|
1136 |
fix v w |
|
1137 |
{ |
|
1138 |
fix x |
|
1139 |
note fd[rule_format, of x 0, unfolded dist_norm f0 diff_0_right] |
|
1140 |
} |
|
33175 | 1141 |
note th0 = this |
53077 | 1142 |
have "f v \<bullet> f w = c\<^sup>2 * (v \<bullet> w)" |
33175 | 1143 |
unfolding dot_norm_neg dist_norm[symmetric] |
1144 |
unfolding th0 fd[rule_format] by (simp add: power2_eq_square field_simps)} |
|
1145 |
note fc = this |
|
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
1146 |
show ?thesis |
53600
8fda7ad57466
make 'linear' into a sublocale of 'bounded_linear';
huffman
parents:
53253
diff
changeset
|
1147 |
unfolding linear_iff vector_eq[where 'a="real^'n"] scalar_mult_eq_scaleR |
50526
899c9c4e4a4c
Remove the indexed basis from the definition of euclidean spaces and only use the set of Basis vectors
hoelzl
parents:
47108
diff
changeset
|
1148 |
by (simp add: inner_add fc field_simps) |
33175 | 1149 |
qed |
1150 |
||
1151 |
lemma isometry_linear: |
|
53253 | 1152 |
"f (0:: real^'n) = (0:: real^'n) \<Longrightarrow> \<forall>x y. dist(f x) (f y) = dist x y \<Longrightarrow> linear f" |
1153 |
by (rule scaling_linear[where c=1]) simp_all |
|
33175 | 1154 |
|
53854 | 1155 |
text {* Hence another formulation of orthogonal transformation. *} |
33175 | 1156 |
|
1157 |
lemma orthogonal_transformation_isometry: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1158 |
"orthogonal_transformation f \<longleftrightarrow> f(0::real^'n) = (0::real^'n) \<and> (\<forall>x y. dist(f x) (f y) = dist x y)" |
33175 | 1159 |
unfolding orthogonal_transformation |
1160 |
apply (rule iffI) |
|
1161 |
apply clarify |
|
1162 |
apply (clarsimp simp add: linear_0 linear_sub[symmetric] dist_norm) |
|
1163 |
apply (rule conjI) |
|
1164 |
apply (rule isometry_linear) |
|
1165 |
apply simp |
|
1166 |
apply simp |
|
1167 |
apply clarify |
|
1168 |
apply (erule_tac x=v in allE) |
|
1169 |
apply (erule_tac x=0 in allE) |
|
53253 | 1170 |
apply (simp add: dist_norm) |
1171 |
done |
|
33175 | 1172 |
|
53854 | 1173 |
text {* Can extend an isometry from unit sphere. *} |
33175 | 1174 |
|
1175 |
lemma isometry_sphere_extend: |
|
34291
4e896680897e
finite annotation on cartesian product is now implicit.
hoelzl
parents:
34289
diff
changeset
|
1176 |
fixes f:: "real ^'n \<Rightarrow> real ^'n" |
33175 | 1177 |
assumes f1: "\<forall>x. norm x = 1 \<longrightarrow> norm (f x) = 1" |
53253 | 1178 |
and fd1: "\<forall> x y. norm x = 1 \<longrightarrow> norm y = 1 \<longrightarrow> dist (f x) (f y) = dist x y" |
33175 | 1179 |
shows "\<exists>g. orthogonal_transformation g \<and> (\<forall>x. norm x = 1 \<longrightarrow> g x = f x)" |
53253 | 1180 |
proof - |
1181 |
{ |
|
1182 |
fix x y x' y' x0 y0 x0' y0' :: "real ^'n" |
|
1183 |
assume H: |
|
1184 |
"x = norm x *\<^sub>R x0" |
|
1185 |
"y = norm y *\<^sub>R y0" |
|
1186 |
"x' = norm x *\<^sub>R x0'" "y' = norm y *\<^sub>R y0'" |
|
1187 |
"norm x0 = 1" "norm x0' = 1" "norm y0 = 1" "norm y0' = 1" |
|
1188 |
"norm(x0' - y0') = norm(x0 - y0)" |
|
53854 | 1189 |
then have *: "x0 \<bullet> y0 = x0' \<bullet> y0' + y0' \<bullet> x0' - y0 \<bullet> x0 " |
53253 | 1190 |
by (simp add: norm_eq norm_eq_1 inner_add inner_diff) |
33175 | 1191 |
have "norm(x' - y') = norm(x - y)" |
1192 |
apply (subst H(1)) |
|
1193 |
apply (subst H(2)) |
|
1194 |
apply (subst H(3)) |
|
1195 |
apply (subst H(4)) |
|
1196 |
using H(5-9) |
|
1197 |
apply (simp add: norm_eq norm_eq_1) |
|
53854 | 1198 |
apply (simp add: inner_diff scalar_mult_eq_scaleR) |
1199 |
unfolding * |
|
53253 | 1200 |
apply (simp add: field_simps) |
1201 |
done |
|
1202 |
} |
|
33175 | 1203 |
note th0 = this |
44228
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1204 |
let ?g = "\<lambda>x. if x = 0 then 0 else norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)" |
53253 | 1205 |
{ |
1206 |
fix x:: "real ^'n" |
|
1207 |
assume nx: "norm x = 1" |
|
53854 | 1208 |
have "?g x = f x" |
1209 |
using nx by auto |
|
53253 | 1210 |
} |
1211 |
then have thfg: "\<forall>x. norm x = 1 \<longrightarrow> ?g x = f x" |
|
1212 |
by blast |
|
53854 | 1213 |
have g0: "?g 0 = 0" |
1214 |
by simp |
|
53253 | 1215 |
{ |
1216 |
fix x y :: "real ^'n" |
|
1217 |
{ |
|
1218 |
assume "x = 0" "y = 0" |
|
53854 | 1219 |
then have "dist (?g x) (?g y) = dist x y" |
1220 |
by simp |
|
53253 | 1221 |
} |
33175 | 1222 |
moreover |
53253 | 1223 |
{ |
1224 |
assume "x = 0" "y \<noteq> 0" |
|
33175 | 1225 |
then have "dist (?g x) (?g y) = dist x y" |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
35542
diff
changeset
|
1226 |
apply (simp add: dist_norm) |
33175 | 1227 |
apply (rule f1[rule_format]) |
53253 | 1228 |
apply (simp add: field_simps) |
1229 |
done |
|
1230 |
} |
|
33175 | 1231 |
moreover |
53253 | 1232 |
{ |
1233 |
assume "x \<noteq> 0" "y = 0" |
|
33175 | 1234 |
then have "dist (?g x) (?g y) = dist x y" |
36362
06475a1547cb
fix lots of looping simp calls and other warnings
huffman
parents:
35542
diff
changeset
|
1235 |
apply (simp add: dist_norm) |
33175 | 1236 |
apply (rule f1[rule_format]) |
53253 | 1237 |
apply (simp add: field_simps) |
1238 |
done |
|
1239 |
} |
|
33175 | 1240 |
moreover |
53253 | 1241 |
{ |
1242 |
assume z: "x \<noteq> 0" "y \<noteq> 0" |
|
1243 |
have th00: |
|
1244 |
"x = norm x *\<^sub>R (inverse (norm x) *\<^sub>R x)" |
|
1245 |
"y = norm y *\<^sub>R (inverse (norm y) *\<^sub>R y)" |
|
1246 |
"norm x *\<^sub>R f ((inverse (norm x) *\<^sub>R x)) = norm x *\<^sub>R f (inverse (norm x) *\<^sub>R x)" |
|
44228
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1247 |
"norm y *\<^sub>R f (inverse (norm y) *\<^sub>R y) = norm y *\<^sub>R f (inverse (norm y) *\<^sub>R y)" |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1248 |
"norm (inverse (norm x) *\<^sub>R x) = 1" |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1249 |
"norm (f (inverse (norm x) *\<^sub>R x)) = 1" |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1250 |
"norm (inverse (norm y) *\<^sub>R y) = 1" |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1251 |
"norm (f (inverse (norm y) *\<^sub>R y)) = 1" |
5f974bead436
get Multivariate_Analysis/Determinants.thy compiled and working again
huffman
parents:
41959
diff
changeset
|
1252 |
"norm (f (inverse (norm x) *\<^sub>R x) - f (inverse (norm y) *\<^sub>R y)) = |
53253 | 1253 |
norm (inverse (norm x) *\<^sub>R x - inverse (norm y) *\<^sub>R y)" |
33175 | 1254 |
using z |
44457
d366fa5551ef
declare euclidean_simps [simp] at the point they are proved;
huffman
parents:
44260
diff
changeset
|
1255 |
by (auto simp add: field_simps intro: f1[rule_format] fd1[rule_format, unfolded dist_norm]) |
33175 | 1256 |
from z th0[OF th00] have "dist (?g x) (?g y) = dist x y" |
53253 | 1257 |
by (simp add: dist_norm) |
1258 |
} |
|
53854 | 1259 |
ultimately have "dist (?g x) (?g y) = dist x y" |
1260 |
by blast |
|
53253 | 1261 |
} |
33175 | 1262 |
note thd = this |
1263 |
show ?thesis |
|
1264 |
apply (rule exI[where x= ?g]) |
|
1265 |
unfolding orthogonal_transformation_isometry |
|
53253 | 1266 |
using g0 thfg thd |
1267 |
apply metis |
|
1268 |
done |
|
33175 | 1269 |
qed |
1270 |
||
53854 | 1271 |
text {* Rotation, reflection, rotoinversion. *} |
33175 | 1272 |
|
1273 |
definition "rotation_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = 1" |
|
1274 |
definition "rotoinversion_matrix Q \<longleftrightarrow> orthogonal_matrix Q \<and> det Q = - 1" |
|
1275 |
||
1276 |
lemma orthogonal_rotation_or_rotoinversion: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34291
diff
changeset
|
1277 |
fixes Q :: "'a::linordered_idom^'n^'n" |
33175 | 1278 |
shows " orthogonal_matrix Q \<longleftrightarrow> rotation_matrix Q \<or> rotoinversion_matrix Q" |
1279 |
by (metis rotoinversion_matrix_def rotation_matrix_def det_orthogonal_matrix) |
|
53253 | 1280 |
|
53854 | 1281 |
text {* Explicit formulas for low dimensions. *} |
33175 | 1282 |
|
53253 | 1283 |
lemma setprod_1: "setprod f {(1::nat)..1} = f 1" |
1284 |
by simp |
|
33175 | 1285 |
|
1286 |
lemma setprod_2: "setprod f {(1::nat)..2} = f 1 * f 2" |
|
40077 | 1287 |
by (simp add: eval_nat_numeral setprod_numseg mult_commute) |
53253 | 1288 |
|
33175 | 1289 |
lemma setprod_3: "setprod f {(1::nat)..3} = f 1 * f 2 * f 3" |
40077 | 1290 |
by (simp add: eval_nat_numeral setprod_numseg mult_commute) |
33175 | 1291 |
|
1292 |
lemma det_1: "det (A::'a::comm_ring_1^1^1) = A$1$1" |
|
44457
d366fa5551ef
declare euclidean_simps [simp] at the point they are proved;
huffman
parents:
44260
diff
changeset
|
1293 |
by (simp add: det_def sign_id) |
33175 | 1294 |
|
1295 |
lemma det_2: "det (A::'a::comm_ring_1^2^2) = A$1$1 * A$2$2 - A$1$2 * A$2$1" |
|
53253 | 1296 |
proof - |
33175 | 1297 |
have f12: "finite {2::2}" "1 \<notin> {2::2}" by auto |
1298 |
show ?thesis |
|
53253 | 1299 |
unfolding det_def UNIV_2 |
1300 |
unfolding setsum_over_permutations_insert[OF f12] |
|
1301 |
unfolding permutes_sing |
|
1302 |
by (simp add: sign_swap_id sign_id swap_id_eq) |
|
33175 | 1303 |
qed |
1304 |
||
53253 | 1305 |
lemma det_3: |
1306 |
"det (A::'a::comm_ring_1^3^3) = |
|
1307 |
A$1$1 * A$2$2 * A$3$3 + |
|
1308 |
A$1$2 * A$2$3 * A$3$1 + |
|
1309 |
A$1$3 * A$2$1 * A$3$2 - |
|
1310 |
A$1$1 * A$2$3 * A$3$2 - |
|
1311 |
A$1$2 * A$2$1 * A$3$3 - |
|
1312 |
A$1$3 * A$2$2 * A$3$1" |
|
1313 |
proof - |
|
53854 | 1314 |
have f123: "finite {2::3, 3}" "1 \<notin> {2::3, 3}" |
1315 |
by auto |
|
1316 |
have f23: "finite {3::3}" "2 \<notin> {3::3}" |
|
1317 |
by auto |
|
33175 | 1318 |
|
1319 |
show ?thesis |
|
53253 | 1320 |
unfolding det_def UNIV_3 |
1321 |
unfolding setsum_over_permutations_insert[OF f123] |
|
1322 |
unfolding setsum_over_permutations_insert[OF f23] |
|
1323 |
unfolding permutes_sing |
|
1324 |
by (simp add: sign_swap_id permutation_swap_id sign_compose sign_id swap_id_eq) |
|
33175 | 1325 |
qed |
1326 |
||
1327 |
end |