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