# HG changeset patch # User paulson # Date 1525905071 -3600 # Node ID 763f5a8f3f7f01c87cd287219302f5957c359aa9 # Parent f6a22490cca8f50abe4bbae8299fee0bcc814f0c# Parent cfe796bf59dad42fdc55e8243c08de400448e593 merged diff -r f6a22490cca8 -r 763f5a8f3f7f src/HOL/Analysis/Determinants.thy --- a/src/HOL/Analysis/Determinants.thy Wed May 09 22:25:24 2018 +0200 +++ b/src/HOL/Analysis/Determinants.thy Wed May 09 23:31:11 2018 +0100 @@ -33,26 +33,14 @@ apply (simp add: mult.commute) done -text \Definition of determinant.\ +subsubsection \Definition of determinant\ definition det:: "'a::comm_ring_1^'n^'n \ 'a" where "det A = sum (\p. of_int (sign p) * prod (\i. A$i$p i) (UNIV :: 'n set)) {p. p permutes (UNIV :: 'n set)}" -text \A few general lemmas we need below.\ - -lemma prod_permute: - assumes p: "p permutes S" - shows "prod f S = prod (f \ p) S" - using assms by (fact prod.permute) - -lemma product_permute_nat_interval: - fixes m n :: nat - shows "p permutes {m..n} \ prod f {m..n} = prod (f \ p) {m..n}" - by (blast intro!: prod_permute) - -text \Basic determinant properties.\ +text \Basic determinant properties\ lemma det_transpose [simp]: "det (transpose A) = det (A::'a::comm_ring_1 ^'n^'n)" proof - @@ -77,15 +65,10 @@ unfolding prod.reindex[OF pi] .. also have "\ = prod (\i. ?di A i (p i)) ?U" proof - - { - fix i - assume i: "i \ ?U" - from i permutes_inv_o[OF pU] permutes_in_image[OF pU] - have "((\i. ?di (transpose A) i (inv p i)) \ p) i = ?di A i (p i)" - unfolding transpose_def by (simp add: fun_eq_iff) - } - then show "prod ((\i. ?di (transpose A) i (inv p i)) \ p) ?U = - prod (\i. ?di A i (p i)) ?U" + have "((\i. ?di (transpose A) i (inv p i)) \ p) i = ?di A i (p i)" if "i \ ?U" for i + using that permutes_inv_o[OF pU] permutes_in_image[OF pU] + unfolding transpose_def by (simp add: fun_eq_iff) + then show "prod ((\i. ?di (transpose A) i (inv p i)) \ p) ?U = prod (\i. ?di A i (p i)) ?U" by (auto intro: prod.cong) qed finally have "of_int (sign (inv p)) * (prod (\i. ?di (transpose A) i (inv p i)) ?U) = @@ -94,11 +77,7 @@ } then show ?thesis unfolding det_def - apply (subst sum_permutations_inverse) - apply (rule sum.cong) - apply (rule refl) - apply blast - done + by (subst sum_permutations_inverse) (blast intro: sum.cong elim: ) qed lemma det_lowerdiagonal: @@ -111,24 +90,20 @@ let ?pp = "\p. of_int (sign p) * prod (\i. A$i$p i) (UNIV :: 'n set)" have fU: "finite ?U" by simp - from finite_permutations[OF fU] have fPU: "finite ?PU" . have id0: "{id} \ ?PU" by (auto simp add: permutes_id) - { + have p0: "\p \ ?PU - {id}. ?pp p = 0" + proof fix p - assume p: "p \ ?PU - {id}" - from p have pU: "p permutes ?U" and pid: "p \ id" - by blast+ - from permutes_natset_le[OF pU] pid obtain i where i: "p i > i" - by (metis not_le) - from ld[OF i] have ex:"\i \ ?U. A$i$p i = 0" + assume "p \ ?PU - {id}" + then obtain i where i: "p i > i" + by clarify (meson leI permutes_natset_le) + from ld[OF i] have "\i \ ?U. A$i$p i = 0" by blast - from prod_zero[OF fU ex] have "?pp p = 0" - by simp - } - then have p0: "\p \ ?PU - {id}. ?pp p = 0" - by blast - from sum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis + with prod_zero[OF fU] show "?pp p = 0" + by force + qed + from sum.mono_neutral_cong_left[OF finite_permutations[OF fU] id0 p0] show ?thesis unfolding det_def by (simp add: sign_id) qed @@ -142,24 +117,20 @@ let ?pp = "(\p. of_int (sign p) * prod (\i. A$i$p i) (UNIV :: 'n set))" have fU: "finite ?U" by simp - from finite_permutations[OF fU] have fPU: "finite ?PU" . have id0: "{id} \ ?PU" by (auto simp add: permutes_id) - { + have p0: "\p \ ?PU -{id}. ?pp p = 0" + proof fix p assume p: "p \ ?PU - {id}" - from p have pU: "p permutes ?U" and pid: "p \ id" - by blast+ - from permutes_natset_ge[OF pU] pid obtain i where i: "p i < i" - by (metis not_le) - from ld[OF i] have ex:"\i \ ?U. A$i$p i = 0" + then obtain i where i: "p i < i" + by clarify (meson leI permutes_natset_ge) + from ld[OF i] have "\i \ ?U. A$i$p i = 0" by blast - from prod_zero[OF fU ex] have "?pp p = 0" - by simp - } - then have p0: "\p \ ?PU -{id}. ?pp p = 0" - by blast - from sum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis + with prod_zero[OF fU] show "?pp p = 0" + by force + qed + from sum.mono_neutral_cong_left[OF finite_permutations[OF fU] id0 p0] show ?thesis unfolding det_def by (simp add: sign_id) qed @@ -175,20 +146,17 @@ from finite_permutations[OF fU] have fPU: "finite ?PU" . have id0: "{id} \ ?PU" by (auto simp add: permutes_id) - { + have p0: "\p \ ?PU - {id}. ?pp p = 0" + proof fix p assume p: "p \ ?PU - {id}" - then have "p \ id" - by simp then obtain i where i: "p i \ i" - unfolding fun_eq_iff by auto - from ld [OF i [symmetric]] have ex:"\i \ ?U. A$i$p i = 0" - by blast - from prod_zero [OF fU ex] have "?pp p = 0" - by simp - } - then have p0: "\p \ ?PU - {id}. ?pp p = 0" - by blast + by fastforce + with ld have "\i \ ?U. A$i$p i = 0" + by (metis UNIV_I) + with prod_zero [OF fU] show "?pp p = 0" + by force + qed from sum.mono_neutral_cong_left[OF fPU id0 p0] show ?thesis unfolding det_def by (simp add: sign_id) qed @@ -203,32 +171,38 @@ fixes A :: "'a::comm_ring_1^'n^'n" assumes p: "p permutes (UNIV :: 'n::finite set)" shows "det (\ i. A$p i :: 'a^'n^'n) = of_int (sign p) * det A" - apply (simp add: det_def sum_distrib_left mult.assoc[symmetric]) - apply (subst sum_permutations_compose_right[OF p]) -proof (rule sum.cong) +proof - let ?U = "UNIV :: 'n set" let ?PU = "{p. p permutes ?U}" - fix q - assume qPU: "q \ ?PU" - have fU: "finite ?U" - by simp - from qPU have q: "q permutes ?U" - by blast - from p q have pp: "permutation p" and qp: "permutation q" - by (metis fU permutation_permutes)+ - from permutes_inv[OF p] have ip: "inv p permutes ?U" . - have "prod (\i. A$p i$ (q \ p) i) ?U = prod ((\i. A$p i$(q \ p) i) \ inv p) ?U" - by (simp only: prod_permute[OF ip, symmetric]) - also have "\ = prod (\i. A $ (p \ inv p) i $ (q \ (p \ inv p)) i) ?U" - by (simp only: o_def) - also have "\ = prod (\i. A$i$q i) ?U" - by (simp only: o_def permutes_inverses[OF p]) - finally have thp: "prod (\i. A$p i$ (q \ p) i) ?U = prod (\i. A$i$q i) ?U" - by blast - show "of_int (sign (q \ p)) * prod (\i. A$ p i$ (q \ p) i) ?U = - of_int (sign p) * of_int (sign q) * prod (\i. A$i$q i) ?U" - by (simp only: thp sign_compose[OF qp pp] mult.commute of_int_mult) -qed rule + have *: "(\q\?PU. of_int (sign (q \ p)) * (\i\?U. A $ p i $ (q \ p) i)) = + (\n\?PU. of_int (sign p) * of_int (sign n) * (\i\?U. A $ i $ n i))" + proof (rule sum.cong) + fix q + assume qPU: "q \ ?PU" + have fU: "finite ?U" + by simp + from qPU have q: "q permutes ?U" + by blast + have "prod (\i. A$p i$ (q \ p) i) ?U = prod ((\i. A$p i$(q \ p) i) \ inv p) ?U" + by (simp only: prod.permute[OF permutes_inv[OF p], symmetric]) + also have "\ = prod (\i. A $ (p \ inv p) i $ (q \ (p \ inv p)) i) ?U" + by (simp only: o_def) + also have "\ = prod (\i. A$i$q i) ?U" + by (simp only: o_def permutes_inverses[OF p]) + finally have thp: "prod (\i. A$p i$ (q \ p) i) ?U = prod (\i. A$i$q i) ?U" + by blast + from p q have pp: "permutation p" and qp: "permutation q" + by (metis fU permutation_permutes)+ + show "of_int (sign (q \ p)) * prod (\i. A$ p i$ (q \ p) i) ?U = + of_int (sign p) * of_int (sign q) * prod (\i. A$i$q i) ?U" + by (simp only: thp sign_compose[OF qp pp] mult.commute of_int_mult) + qed auto + show ?thesis + apply (simp add: det_def sum_distrib_left mult.assoc[symmetric]) + apply (subst sum_permutations_compose_right[OF p]) + apply (rule *) + done +qed lemma det_permute_columns: fixes A :: "'a::comm_ring_1^'n^'n" @@ -279,19 +253,19 @@ also have "... = - sign x" using sign_tjk by simp also have "... \ sign x" unfolding sign_def by simp finally have "sign (?t_jk \ x) \ sign x" and "(?t_jk \ x) \ ?S2" - by (auto, metis (lifting, full_types) mem_Collect_eq x) + using x by force+ } - hence disjoint: "?S1 \ ?S2 = {}" by (auto, metis sign_def) + hence disjoint: "?S1 \ ?S2 = {}" + by (force simp: sign_def) have PU_decomposition: "?PU = ?S1 \ ?S2" proof (auto) fix x assume x: "x permutes ?U" and "\p. p permutes ?U \ x = Fun.swap j k id \ p \ \ evenperm p" - from this obtain p where p: "p permutes UNIV" and x_eq: "x = Fun.swap j k id \ p" + then obtain p where p: "p permutes UNIV" and x_eq: "x = Fun.swap j k id \ p" and odd_p: "\ evenperm p" - by (metis (no_types) comp_assoc id_comp inv_swap_id permutes_compose - permutes_inv_o(1) tjk_permutes) + by (metis (mono_tags) id_o o_assoc permutes_compose swap_id_idempotent tjk_permutes) thus "evenperm x" - by (metis evenperm_comp evenperm_swap finite_class.finite_UNIV + by (meson evenperm_comp evenperm_swap finite_class.finite_UNIV jk permutation_permutes permutation_swap_id) next fix p assume p: "p permutes ?U" @@ -328,13 +302,9 @@ lemma det_identical_rows: fixes A :: "'a::comm_ring_1^'n^'n" - assumes ij: "i \ j" - and r: "row i A = row j A" + assumes ij: "i \ j" and r: "row i A = row j A" shows "det A = 0" - apply (subst det_transpose[symmetric]) - apply (rule det_identical_columns[OF ij]) - apply (metis column_transpose r) - done + by (metis column_transpose det_identical_columns det_transpose ij r) lemma det_zero_row: fixes A :: "'a::{idom, ring_char_0}^'n^'n" and F :: "'b::{field}^'m^'m" @@ -366,38 +336,27 @@ by blast have kU: "?U = insert k ?Uk" by blast - { - fix j - assume j: "j \ ?Uk" - from j have "?f j $ p j = ?g j $ p j" and "?f j $ p j= ?h j $ p j" - by simp_all - } - then have th1: "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?g i $ p i) ?Uk" - and th2: "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?h i $ p i) ?Uk" - apply - - apply (rule prod.cong, simp_all)+ - done - have th3: "finite ?Uk" "k \ ?Uk" + have eq: "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?g i $ p i) ?Uk" + "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?h i $ p i) ?Uk" + by auto + have Uk: "finite ?Uk" "k \ ?Uk" by auto have "prod (\i. ?f i $ p i) ?U = prod (\i. ?f i $ p i) (insert k ?Uk)" unfolding kU[symmetric] .. also have "\ = ?f k $ p k * prod (\i. ?f i $ p i) ?Uk" - apply (rule prod.insert) - apply simp - apply blast - done + by (rule prod.insert) auto also have "\ = (a k $ p k * prod (\i. ?f i $ p i) ?Uk) + (b k$ p k * prod (\i. ?f i $ p i) ?Uk)" by (simp add: field_simps) also have "\ = (a k $ p k * prod (\i. ?g i $ p i) ?Uk) + (b k$ p k * prod (\i. ?h i $ p i) ?Uk)" - by (metis th1 th2) + by (metis eq) also have "\ = prod (\i. ?g i $ p i) (insert k ?Uk) + prod (\i. ?h i $ p i) (insert k ?Uk)" - unfolding prod.insert[OF th3] by simp + unfolding prod.insert[OF Uk] by simp finally have "prod (\i. ?f i $ p i) ?U = prod (\i. ?g i $ p i) ?U + prod (\i. ?h i $ p i) ?U" unfolding kU[symmetric] . then show "of_int (sign p) * prod (\i. ?f i $ p i) ?U = of_int (sign p) * prod (\i. ?g i $ p i) ?U + of_int (sign p) * prod (\i. ?h i $ p i) ?U" by (simp add: field_simps) -qed rule +qed auto lemma det_row_mul: fixes a b :: "'n::finite \ _ ^ 'n" @@ -416,38 +375,25 @@ by blast have kU: "?U = insert k ?Uk" by blast - { - fix j - assume j: "j \ ?Uk" - from j have "?f j $ p j = ?g j $ p j" - by simp - } - then have th1: "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?g i $ p i) ?Uk" - apply - - apply (rule prod.cong) - apply simp_all - done - have th3: "finite ?Uk" "k \ ?Uk" + have eq: "prod (\i. ?f i $ p i) ?Uk = prod (\i. ?g i $ p i) ?Uk" + by (auto simp: ) + have Uk: "finite ?Uk" "k \ ?Uk" by auto have "prod (\i. ?f i $ p i) ?U = prod (\i. ?f i $ p i) (insert k ?Uk)" unfolding kU[symmetric] .. also have "\ = ?f k $ p k * prod (\i. ?f i $ p i) ?Uk" - apply (rule prod.insert) - apply simp - apply blast - done + by (rule prod.insert) auto also have "\ = (c*s a k) $ p k * prod (\i. ?f i $ p i) ?Uk" by (simp add: field_simps) also have "\ = c* (a k $ p k * prod (\i. ?g i $ p i) ?Uk)" - unfolding th1 by (simp add: ac_simps) + unfolding eq by (simp add: ac_simps) also have "\ = c* (prod (\i. ?g i $ p i) (insert k ?Uk))" - unfolding prod.insert[OF th3] by simp + unfolding prod.insert[OF Uk] by simp finally have "prod (\i. ?f i $ p i) ?U = c* (prod (\i. ?g i $ p i) ?U)" unfolding kU[symmetric] . - then show "of_int (sign p) * prod (\i. ?f i $ p i) ?U = - c * (of_int (sign p) * prod (\i. ?g i $ p i) ?U)" + then show "of_int (sign p) * prod (\i. ?f i $ p i) ?U = c * (of_int (sign p) * prod (\i. ?g i $ p i) ?U)" by (simp add: field_simps) -qed rule +qed auto lemma det_row_0: fixes b :: "'n::finite \ _ ^ 'n" @@ -478,16 +424,10 @@ using x proof (induction rule: vec.span_induct_alt) case base - { - fix k - have "(if k = i then row i A + 0 else row k A) = row k A" - by simp - } + have "(if k = i then row i A + 0 else row k A) = row k A" for k + by simp then show ?case - apply - - apply (rule cong[of det, OF refl]) - apply (vector row_def) - done + by (simp add: row_def) next case (step c z y) then obtain j where j: "z = row j A" "i \ j" @@ -531,29 +471,24 @@ let ?U = "UNIV :: 'n set" from d obtain i where i: "row i A \ vec.span (rows A - {row i A})" unfolding vec.dependent_def rows_def by blast - { - fix j k - assume jk: "j \ k" and c: "row j A = row k A" - from det_identical_rows[OF jk c] have ?thesis . - } - moreover - { - assume H: "\ i j. i \ j \ row i A \ row j A" - have th0: "- row i A \ vec.span {row j A|j. j \ i}" - apply (rule vec.span_neg) - apply (rule set_rev_mp) - apply (rule i) - apply (rule vec.span_mono) - using H i - apply (auto simp add: rows_def) - done - from det_row_span[OF th0] + show ?thesis + proof (cases "\i j. i \ j \ row i A \ row j A") + case True + with i have "vec.span (rows A - {row i A}) \ vec.span {row j A |j. j \ i}" + by (auto simp add: rows_def intro!: vec.span_mono) + then have "- row i A \ vec.span {row j A|j. j \ i}" + by (meson i subsetCE vec.span_neg) + from det_row_span[OF this] have "det A = det (\ k. if k = i then 0 *s 1 else row k A)" unfolding right_minus vector_smult_lzero .. - with det_row_mul[of i "0::'a" "\i. 1"] - have "det A = 0" by simp - } - ultimately show ?thesis by blast + with det_row_mul[of i 0 "\i. 1"] + show ?thesis by simp + next + case False + then obtain j k where jk: "j \ k" "row j A = row k A" + by auto + from det_identical_rows[OF jk] show ?thesis . + qed qed lemma det_dependent_columns: @@ -561,45 +496,35 @@ shows "det A = 0" by (metis d det_dependent_rows rows_transpose det_transpose) -text \Multilinearity and the multiplication formula.\ +text \Multilinearity and the multiplication formula\ lemma Cart_lambda_cong: "(\x. f x = g x) \ (vec_lambda f::'a^'n) = (vec_lambda g :: 'a^'n)" - by (rule iffD1[OF vec_lambda_unique]) vector + by auto lemma det_linear_row_sum: assumes fS: "finite S" shows "det ((\ i. if i = k then sum (a i) S else c i)::'a::comm_ring_1^'n^'n) = sum (\j. det ((\ i. if i = k then a i j else c i)::'a^'n^'n)) S" -proof (induct rule: finite_induct[OF fS]) - case 1 - then show ?case - apply simp - unfolding sum.empty det_row_0[of k] - apply rule - done -next - case (2 x F) - then show ?case - by (simp add: det_row_add cong del: if_weak_cong) -qed + using fS by (induct rule: finite_induct; simp add: det_row_0 det_row_add cong: if_cong) lemma finite_bounded_functions: assumes fS: "finite S" shows "finite {f. (\i \ {1.. (k::nat)}. f i \ S) \ (\i. i \ {1 .. k} \ f i = i)}" proof (induct k) case 0 - have th: "{f. \i. f i = i} = {id}" + have *: "{f. \i. f i = i} = {id}" by auto show ?case - by (auto simp add: th) + by (auto simp add: *) next case (Suc k) let ?f = "\(y::nat,g) i. if i = Suc k then y else g i" let ?S = "?f ` (S \ {f. (\i\{1..k}. f i \ S) \ (\i. i \ {1..k} \ f i = i)})" have "?S = {f. (\i\{1.. Suc k}. f i \ S) \ (\i. i \ {1.. Suc k} \ f i = i)}" apply (auto simp add: image_iff) - apply (rule_tac x="x (Suc k)" in bexI) - apply (rule_tac x = "\i. if i = Suc k then i else x i" in exI) + apply (rename_tac f) + apply (rule_tac x="f (Suc k)" in bexI) + apply (rule_tac x = "\i. if i = Suc k then i else f i" in exI) apply auto done with finite_imageI[OF finite_cartesian_product[OF fS Suc.hyps(1)], of ?f] @@ -633,17 +558,14 @@ have thif2: "\a b c d e. (if a then b else if c then d else e) = (if c then (if a then b else d) else (if a then b else e))" by simp - from \z \ T\ have nz: "\i. i \ T \ i = z \ False" + from \z \ T\ have nz: "\i. i \ T \ i \ z" by auto have "det (\ i. if i \ insert z T then sum (a i) S else c i) = det (\ i. if i = z then sum (a i) S else if i \ T then sum (a i) S else c i)" unfolding insert_iff thif .. also have "\ = (\j\S. det (\ i. if i \ T then sum (a i) S else if i = z then a i j else c i))" unfolding det_linear_row_sum[OF fS] - apply (subst thif2) - using nz - apply (simp cong del: if_weak_cong cong add: if_cong) - done + by (subst thif2) (simp add: nz cong: if_cong) finally have tha: "det (\ i. if i \ insert z T then sum (a i) S else c i) = (\(j, f)\S \ ?F T. det (\ i. if i \ T then a i (f i) @@ -696,18 +618,10 @@ shows "det (A ** B) = det A * det B" proof - let ?U = "UNIV :: 'n set" - let ?F = "{f. (\i\ ?U. f i \ ?U) \ (\i. i \ ?U \ f i = i)}" + let ?F = "{f. (\i \ ?U. f i \ ?U) \ (\i. i \ ?U \ f i = i)}" let ?PU = "{p. p permutes ?U}" - have fU: "finite ?U" + have "p \ ?F" if "p permutes ?U" for p by simp - have fF: "finite ?F" - by (rule finite) - { - fix p - assume p: "p permutes ?U" - have "p \ ?F" unfolding mem_Collect_eq permutes_in_image[OF p] - using p[unfolded permutes_def] by simp - } then have PUF: "?PU \ ?F" by blast { fix f @@ -723,34 +637,20 @@ assume fni: "\ inj_on f ?U" then obtain i j where ij: "f i = f j" "i \ j" unfolding inj_on_def by blast - from ij - have rth: "row i ?B = row j ?B" + then have "row i ?B = row j ?B" by (vector row_def) - from det_identical_rows[OF ij(2) rth] + with det_identical_rows[OF ij(2)] have "det (\ i. A$i$f i *s B$f i) = 0" - unfolding det_rows_mul by simp + unfolding det_rows_mul by force } moreover { assume fi: "inj_on f ?U" from f fi have fith: "\i j. f i = f j \ i = j" unfolding inj_on_def by metis - note fs = fi[unfolded surjective_iff_injective_gen[OF fU fU refl fUU, symmetric]] - { - fix y - from fs f have "\x. f x = y" - by blast - then obtain x where x: "f x = y" - by blast - { - fix z - assume z: "f z = y" - from fith x z have "z = x" - by metis - } - with x have "\!x. f x = y" - by blast - } + note fs = fi[unfolded surjective_iff_injective_gen[OF finite finite refl fUU, symmetric]] + have "\!x. f x = y" for y + using fith fs by blast with f(3) have "det (\ i. A$i$f i *s B$f i) = 0" by blast } @@ -784,9 +684,9 @@ by (simp_all add: sign_idempotent) have ths: "?s q = ?s p * ?s (q \ inv p)" using pp pq permutation_inverse[OF pp] sign_inverse[OF pp] - by (simp add: th00 ac_simps sign_idempotent sign_compose) + by (simp add: th00 ac_simps sign_idempotent sign_compose) have th001: "prod (\i. B$i$ q (inv p i)) ?U = prod ((\i. B$i$ q (inv p i)) \ p) ?U" - by (rule prod_permute[OF p]) + by (rule prod.permute[OF p]) have thp: "prod (\i. (\ i. A$i$p i *s B$p i :: 'a^'n^'n) $i $ q i) ?U = prod (\i. A$i$p i) ?U * prod (\i. B$i$ q (inv p i)) ?U" unfolding th001 prod.distrib[symmetric] o_def permutes_inverses[OF p] @@ -804,64 +704,51 @@ unfolding det_def sum_product by (rule sum.cong [OF refl]) have "det (A**B) = sum (\f. det (\ i. A $ i $ f i *s B $ f i)) ?F" - unfolding matrix_mul_sum_alt det_linear_rows_sum[OF fU] + unfolding matrix_mul_sum_alt det_linear_rows_sum[OF finite] by simp also have "\ = sum (\f. det (\ i. A$i$f i *s B$f i)) ?PU" - using sum.mono_neutral_cong_left[OF fF PUF zth, symmetric] + using sum.mono_neutral_cong_left[OF finite PUF zth, symmetric] unfolding det_rows_mul by auto finally show ?thesis unfolding th2 . qed -subsection \Relation to invertibility.\ +subsection \Relation to invertibility\ lemma invertible_det_nz: fixes A::"'a::{field}^'n^'n" shows "invertible A \ det A \ 0" -proof - - { - assume "invertible A" - then obtain B :: "'a^'n^'n" where B: "A ** B = mat 1" - unfolding invertible_right_inverse by blast - then have "det (A ** B) = det (mat 1 :: 'a^'n^'n)" - by simp - then have "det A \ 0" - by (simp add: det_mul) algebra - } - moreover - { - assume H: "\ invertible A" - let ?U = "UNIV :: 'n set" - have fU: "finite ?U" - by simp - from H obtain c i where c: "sum (\i. c i *s row i A) ?U = 0" - and iU: "i \ ?U" - and ci: "c i \ 0" - unfolding invertible_right_inverse - unfolding matrix_right_invertible_independent_rows - by blast - have thr0: "- row i A = sum (\j. (1/ c i) *s (c j *s row j A)) (?U - {i})" - unfolding sum_cmul - using c ci - by (auto simp add: sum.remove[OF fU iU] eq_vector_fraction_iff add_eq_0_iff) - have thr: "- row i A \ vec.span {row j A| j. j \ i}" - unfolding thr0 - apply (rule vec.span_sum) - apply simp - apply (rule vec.span_scale) - apply (rule vec.span_base) - apply auto - done - let ?B = "(\ k. if k = i then 0 else row k A) :: 'a^'n^'n" - have thrb: "row i ?B = 0" using iU by (vector row_def) - have "det A = 0" - unfolding det_row_span[OF thr, symmetric] right_minus - unfolding det_zero_row(2)[OF thrb] .. - } - ultimately show ?thesis +proof (cases "invertible A") + case True + then obtain B :: "'a^'n^'n" where B: "A ** B = mat 1" + unfolding invertible_right_inverse by blast + then have "det (A ** B) = det (mat 1 :: 'a^'n^'n)" + by simp + then show ?thesis + by (metis True det_I det_mul mult_zero_left one_neq_zero) +next + case False + let ?U = "UNIV :: 'n set" + have fU: "finite ?U" + by simp + from False obtain c i where c: "sum (\i. c i *s row i A) ?U = 0" and iU: "i \ ?U" and ci: "c i \ 0" + unfolding invertible_right_inverse matrix_right_invertible_independent_rows by blast + have thr0: "- row i A = sum (\j. (1/ c i) *s (c j *s row j A)) (?U - {i})" + unfolding sum_cmul using c ci + by (auto simp add: sum.remove[OF fU iU] eq_vector_fraction_iff add_eq_0_iff) + have thr: "- row i A \ vec.span {row j A| j. j \ i}" + unfolding thr0 by (auto intro: vec.span_base vec.span_scale vec.span_sum) + let ?B = "(\ k. if k = i then 0 else row k A) :: 'a^'n^'n" + have thrb: "row i ?B = 0" using iU by (vector row_def) + have "det A = 0" + unfolding det_row_span[OF thr, symmetric] right_minus + unfolding det_zero_row(2)[OF thrb] .. + then show ?thesis + by (simp add: False) qed + lemma det_nz_iff_inj_gen: fixes f :: "'a::field^'n \ 'a::field^'n" assumes "Vector_Spaces.linear ( *s) ( *s) f" @@ -975,7 +862,7 @@ vec.linear_injective_left_inverse vec.linear_surjective_right_inverse) -subsection \Cramer's rule.\ +subsection \Cramer's rule\ lemma cramer_lemma_transpose: fixes A:: "real^'n^'n" @@ -988,8 +875,6 @@ let ?Uk = "?U - {k}" have U: "?U = insert k ?Uk" by blast - have fUk: "finite ?Uk" - by simp have kUk: "k \ ?Uk" by simp have th00: "\k s. x$k *s row k A + s = (x$k - 1) *s row k A + row k A + s" @@ -1000,15 +885,10 @@ then have thd1: "det (\ i. row i A) = det A" by simp have thd0: "det (\ i. if i = k then row k A + (\i \ ?Uk. x $ i *s row i A) else row i A) = det A" - apply (rule det_row_span) - apply (rule vec.span_sum) - apply (rule vec.span_scale) - apply (rule vec.span_base) - apply auto - done + by (force intro: det_row_span vec.span_sum vec.span_scale vec.span_base) show "?lhs = x$k * det A" apply (subst U) - unfolding sum.insert[OF fUk kUk] + unfolding sum.insert[OF finite kUk] apply (subst th00) unfolding add.assoc apply (subst det_row_add) @@ -1154,7 +1034,7 @@ let ?m1 = "mat 1 :: real ^'n^'n" { assume ot: ?ot - from ot have lf: "Vector_Spaces.linear ( *s) ( *s) f" and fd: "\v w. f v \ f w = v \ w" + from ot have lf: "Vector_Spaces.linear ( *s) ( *s) f" and fd: "\v w. f v \ f w = v \ w" unfolding orthogonal_transformation_def orthogonal_matrix linear_def scalar_mult_eq_scaleR by blast+ { @@ -1163,7 +1043,7 @@ have th0: "\b (x::'a::comm_ring_1). (if b then 1 else 0)*x = (if b then x else 0)" "\b (x::'a::comm_ring_1). x*(if b then 1 else 0) = (if b then x else 0)" by simp_all - from fd[rule_format, of "axis i 1" "axis j 1", + from fd[of "axis i 1" "axis j 1", simplified matrix_works[OF lf, symmetric] dot_matrix_vector_mul] have "?A$i$j = ?m1 $ i $ j" by (simp add: inner_vec_def matrix_matrix_mult_def columnvector_def rowvector_def @@ -1235,25 +1115,22 @@ proof - { fix v w - { - fix x - note fd[rule_format, of x 0, unfolded dist_norm f0 diff_0_right] - } - note th0 = this - have "f v \ f w = c\<^sup>2 * (v \ w)" + have "norm (f x) = c * norm x" for x + by (metis dist_0_norm f0 fd) + then have "f v \ f w = c\<^sup>2 * (v \ w)" unfolding dot_norm_neg dist_norm[symmetric] - unfolding th0 fd[rule_format] by (simp add: power2_eq_square field_simps)} - note fc = this - show ?thesis + by (simp add: fd power2_eq_square field_simps) + } + then show ?thesis unfolding linear_iff vector_eq[where 'a="'a"] scalar_mult_eq_scaleR - by (simp add: inner_add fc field_simps) + by (simp add: inner_add field_simps) qed lemma isometry_linear: "f (0::'a::real_inner) = (0::'a) \ \x y. dist(f x) (f y) = dist x y \ linear f" by (rule scaling_linear[where c=1]) simp_all -text \Hence another formulation of orthogonal transformation.\ +text \Hence another formulation of orthogonal transformation\ lemma orthogonal_transformation_isometry: "orthogonal_transformation f \ f(0::'a::real_inner) = (0::'a) \ (\x y. dist(f x) (f y) = dist x y)" @@ -1498,7 +1375,7 @@ shows " orthogonal_matrix Q \ rotation_matrix Q \ rotoinversion_matrix Q" by (metis rotoinversion_matrix_def rotation_matrix_def det_orthogonal_matrix) -text \Explicit formulas for low dimensions.\ +text \Explicit formulas for low dimensions\ lemma prod_neutral_const: "prod f {(1::nat)..1} = f 1" by simp @@ -1544,7 +1421,7 @@ by (simp add: sign_swap_id permutation_swap_id sign_compose sign_id swap_id_eq) qed -text\ Slightly stronger results giving rotation, but only in two or more dimensions.\ +text\ Slightly stronger results giving rotation, but only in two or more dimensions\ lemma rotation_matrix_exists_basis: fixes a :: "real^'n"