474 assume "f ` S \<subseteq> T" and "subspace T" |
481 assume "f ` S \<subseteq> T" and "subspace T" |
475 then show "f ` span S \<subseteq> T" |
482 then show "f ` span S \<subseteq> T" |
476 unfolding image_subset_iff_subset_vimage |
483 unfolding image_subset_iff_subset_vimage |
477 by (intro span_minimal subspace_linear_vimage lf) |
484 by (intro span_minimal subspace_linear_vimage lf) |
478 qed |
485 qed |
|
486 |
|
487 lemma spans_image: |
|
488 assumes lf: "linear f" |
|
489 and VB: "V \<subseteq> span B" |
|
490 shows "f ` V \<subseteq> span (f ` B)" |
|
491 unfolding span_linear_image[OF lf] by (metis VB image_mono) |
479 |
492 |
480 lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
493 lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
481 proof (rule span_unique) |
494 proof (rule span_unique) |
482 show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
495 show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
483 by safe (force intro: span_clauses)+ |
496 by safe (force intro: span_clauses)+ |
978 |
991 |
979 lemma linear_independent_extend: |
992 lemma linear_independent_extend: |
980 "independent B \<Longrightarrow> \<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)" |
993 "independent B \<Longrightarrow> \<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)" |
981 using linear_independent_extend_subspace[of B f] by auto |
994 using linear_independent_extend_subspace[of B f] by auto |
982 |
995 |
|
996 text \<open>Linear functions are equal on a subspace if they are on a spanning set.\<close> |
|
997 |
|
998 lemma subspace_kernel: |
|
999 assumes lf: "linear f" |
|
1000 shows "subspace {x. f x = 0}" |
|
1001 apply (simp add: subspace_def) |
|
1002 apply (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf]) |
|
1003 done |
|
1004 |
|
1005 lemma linear_eq_0_span: |
|
1006 assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0" |
|
1007 shows "\<forall>x \<in> span B. f x = 0" |
|
1008 using f0 subspace_kernel[OF lf] |
|
1009 by (rule span_induct') |
|
1010 |
|
1011 lemma linear_eq_0: "linear f \<Longrightarrow> S \<subseteq> span B \<Longrightarrow> \<forall>x\<in>B. f x = 0 \<Longrightarrow> \<forall>x\<in>S. f x = 0" |
|
1012 using linear_eq_0_span[of f B] by auto |
|
1013 |
|
1014 lemma linear_eq_span: "linear f \<Longrightarrow> linear g \<Longrightarrow> \<forall>x\<in>B. f x = g x \<Longrightarrow> \<forall>x \<in> span B. f x = g x" |
|
1015 using linear_eq_0_span[of "\<lambda>x. f x - g x" B] by (auto simp: linear_compose_sub) |
|
1016 |
|
1017 lemma linear_eq: "linear f \<Longrightarrow> linear g \<Longrightarrow> S \<subseteq> span B \<Longrightarrow> \<forall>x\<in>B. f x = g x \<Longrightarrow> \<forall>x\<in>S. f x = g x" |
|
1018 using linear_eq_span[of f g B] by auto |
|
1019 |
983 text \<open>The degenerate case of the Exchange Lemma.\<close> |
1020 text \<open>The degenerate case of the Exchange Lemma.\<close> |
984 |
1021 |
985 lemma spanning_subset_independent: |
1022 lemma spanning_subset_independent: |
986 assumes BA: "B \<subseteq> A" |
1023 assumes BA: "B \<subseteq> A" |
987 and iA: "independent A" |
1024 and iA: "independent A" |
1017 then have "x \<in> B" by blast |
1054 then have "x \<in> B" by blast |
1018 } |
1055 } |
1019 then show "A \<subseteq> B" by blast |
1056 then show "A \<subseteq> B" by blast |
1020 qed |
1057 qed |
1021 |
1058 |
|
1059 text \<open>Relation between bases and injectivity/surjectivity of map.\<close> |
|
1060 |
|
1061 lemma spanning_surjective_image: |
|
1062 assumes us: "UNIV \<subseteq> span S" |
|
1063 and lf: "linear f" |
|
1064 and sf: "surj f" |
|
1065 shows "UNIV \<subseteq> span (f ` S)" |
|
1066 proof - |
|
1067 have "UNIV \<subseteq> f ` UNIV" |
|
1068 using sf by (auto simp add: surj_def) |
|
1069 also have " \<dots> \<subseteq> span (f ` S)" |
|
1070 using spans_image[OF lf us] . |
|
1071 finally show ?thesis . |
|
1072 qed |
|
1073 |
|
1074 lemma independent_inj_on_image: |
|
1075 assumes iS: "independent S" |
|
1076 and lf: "linear f" |
|
1077 and fi: "inj_on f (span S)" |
|
1078 shows "independent (f ` S)" |
|
1079 proof - |
|
1080 { |
|
1081 fix a |
|
1082 assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})" |
|
1083 have eq: "f ` S - {f a} = f ` (S - {a})" |
|
1084 using fi \<open>a\<in>S\<close> by (auto simp add: inj_on_def span_superset) |
|
1085 from a have "f a \<in> f ` span (S - {a})" |
|
1086 unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast |
|
1087 then have "a \<in> span (S - {a})" |
|
1088 by (rule inj_on_image_mem_iff_alt[OF fi, rotated]) |
|
1089 (insert span_mono[of "S - {a}" S], auto intro: span_superset \<open>a\<in>S\<close>) |
|
1090 with a(1) iS have False |
|
1091 by (simp add: dependent_def) |
|
1092 } |
|
1093 then show ?thesis |
|
1094 unfolding dependent_def by blast |
|
1095 qed |
|
1096 |
|
1097 lemma independent_injective_image: |
|
1098 "independent S \<Longrightarrow> linear f \<Longrightarrow> inj f \<Longrightarrow> independent (f ` S)" |
|
1099 using independent_inj_on_image[of S f] by (auto simp: subset_inj_on) |
|
1100 |
|
1101 text \<open>Detailed theorems about left and right invertibility in general case.\<close> |
|
1102 |
|
1103 lemma linear_inj_on_left_inverse: |
|
1104 assumes lf: "linear f" and fi: "inj_on f (span S)" |
|
1105 shows "\<exists>g. range g \<subseteq> span S \<and> linear g \<and> (\<forall>x\<in>span S. g (f x) = x)" |
|
1106 proof - |
|
1107 obtain B where "independent B" "B \<subseteq> S" "S \<subseteq> span B" |
|
1108 using maximal_independent_subset[of S] by auto |
|
1109 then have "span S = span B" |
|
1110 unfolding span_eq by (auto simp: span_superset) |
|
1111 with linear_independent_extend_subspace[OF independent_inj_on_image, OF \<open>independent B\<close> lf] fi |
|
1112 obtain g where g: "linear g" "\<forall>x\<in>f ` B. g x = inv_into B f x" "range g = span (inv_into B f ` f ` B)" |
|
1113 by fastforce |
|
1114 have fB: "inj_on f B" |
|
1115 using fi by (auto simp: \<open>span S = span B\<close> intro: subset_inj_on span_superset) |
|
1116 |
|
1117 have "\<forall>x\<in>span B. g (f x) = x" |
|
1118 proof (intro linear_eq_span) |
|
1119 show "linear (\<lambda>x. x)" "linear (\<lambda>x. g (f x))" |
|
1120 using linear_id linear_compose[OF \<open>linear f\<close> \<open>linear g\<close>] by (auto simp: id_def comp_def) |
|
1121 show "\<forall>x \<in> B. g (f x) = x" |
|
1122 using g fi \<open>span S = span B\<close> by (auto simp: fB) |
|
1123 qed |
|
1124 moreover |
|
1125 have "inv_into B f ` f ` B \<subseteq> B" |
|
1126 by (auto simp: fB) |
|
1127 then have "range g \<subseteq> span S" |
|
1128 unfolding g \<open>span S = span B\<close> by (intro span_mono) |
|
1129 ultimately show ?thesis |
|
1130 using \<open>span S = span B\<close> \<open>linear g\<close> by auto |
|
1131 qed |
|
1132 |
|
1133 lemma linear_injective_left_inverse: "linear f \<Longrightarrow> inj f \<Longrightarrow> \<exists>g. linear g \<and> g \<circ> f = id" |
|
1134 using linear_inj_on_left_inverse[of f UNIV] by (auto simp: fun_eq_iff span_UNIV) |
|
1135 |
|
1136 lemma linear_surj_right_inverse: |
|
1137 assumes lf: "linear f" and sf: "span T \<subseteq> f`span S" |
|
1138 shows "\<exists>g. range g \<subseteq> span S \<and> linear g \<and> (\<forall>x\<in>span T. f (g x) = x)" |
|
1139 proof - |
|
1140 obtain B where "independent B" "B \<subseteq> T" "T \<subseteq> span B" |
|
1141 using maximal_independent_subset[of T] by auto |
|
1142 then have "span T = span B" |
|
1143 unfolding span_eq by (auto simp: span_superset) |
|
1144 |
|
1145 from linear_independent_extend_subspace[OF \<open>independent B\<close>, of "inv_into (span S) f"] |
|
1146 obtain g where g: "linear g" "\<forall>x\<in>B. g x = inv_into (span S) f x" "range g = span (inv_into (span S) f`B)" |
|
1147 by auto |
|
1148 moreover have "x \<in> B \<Longrightarrow> f (inv_into (span S) f x) = x" for x |
|
1149 using \<open>B \<subseteq> T\<close> \<open>span T \<subseteq> f`span S\<close> by (intro f_inv_into_f) (auto intro: span_superset) |
|
1150 ultimately have "\<forall>x\<in>B. f (g x) = x" |
|
1151 by auto |
|
1152 then have "\<forall>x\<in>span B. f (g x) = x" |
|
1153 using linear_id linear_compose[OF \<open>linear g\<close> \<open>linear f\<close>] |
|
1154 by (intro linear_eq_span) (auto simp: id_def comp_def) |
|
1155 moreover have "inv_into (span S) f ` B \<subseteq> span S" |
|
1156 using \<open>B \<subseteq> T\<close> \<open>span T \<subseteq> f`span S\<close> by (auto intro: inv_into_into span_superset) |
|
1157 then have "range g \<subseteq> span S" |
|
1158 unfolding g by (intro span_minimal subspace_span) auto |
|
1159 ultimately show ?thesis |
|
1160 using \<open>linear g\<close> \<open>span T = span B\<close> by auto |
|
1161 qed |
|
1162 |
|
1163 lemma linear_surjective_right_inverse: "linear f \<Longrightarrow> surj f \<Longrightarrow> \<exists>g. linear g \<and> f \<circ> g = id" |
|
1164 using linear_surj_right_inverse[of f UNIV UNIV] |
|
1165 by (auto simp: span_UNIV fun_eq_iff) |
|
1166 |
1022 text \<open>The general case of the Exchange Lemma, the key to what follows.\<close> |
1167 text \<open>The general case of the Exchange Lemma, the key to what follows.\<close> |
1023 |
1168 |
1024 lemma exchange_lemma: |
1169 lemma exchange_lemma: |
1025 assumes f:"finite t" |
1170 assumes f:"finite t" |
1026 and i: "independent s" |
1171 and i: "independent s" |
1027 and sp: "s \<subseteq> span t" |
1172 and sp: "s \<subseteq> span t" |
1028 shows "\<exists>t'. card t' = card t \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
1173 shows "\<exists>t'. card t' = card t \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
1029 thm maximal_independent_subset_extend[OF _ i, of "s \<union> t"] |
|
1030 using f i sp |
1174 using f i sp |
1031 proof (induct "card (t - s)" arbitrary: s t rule: less_induct) |
1175 proof (induct "card (t - s)" arbitrary: s t rule: less_induct) |
1032 case less |
1176 case less |
1033 note ft = \<open>finite t\<close> and s = \<open>independent s\<close> and sp = \<open>s \<subseteq> span t\<close> |
1177 note ft = \<open>finite t\<close> and s = \<open>independent s\<close> and sp = \<open>s \<subseteq> span t\<close> |
1034 let ?P = "\<lambda>t'. card t' = card t \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
1178 let ?P = "\<lambda>t'. card t' = card t \<and> finite t' \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'" |
2056 apply (auto simp add: span_linear_image spans_image subset_image_iff) |
2194 apply (auto simp add: span_linear_image spans_image subset_image_iff) |
2057 done |
2195 done |
2058 also have "\<dots> \<le> dim S" |
2196 also have "\<dots> \<le> dim S" |
2059 using card_image_le[OF fB(1)] fB by simp |
2197 using card_image_le[OF fB(1)] fB by simp |
2060 finally show ?thesis . |
2198 finally show ?thesis . |
2061 qed |
|
2062 |
|
2063 text \<open>Relation between bases and injectivity/surjectivity of map.\<close> |
|
2064 |
|
2065 lemma spanning_surjective_image: |
|
2066 assumes us: "UNIV \<subseteq> span S" |
|
2067 and lf: "linear f" |
|
2068 and sf: "surj f" |
|
2069 shows "UNIV \<subseteq> span (f ` S)" |
|
2070 proof - |
|
2071 have "UNIV \<subseteq> f ` UNIV" |
|
2072 using sf by (auto simp add: surj_def) |
|
2073 also have " \<dots> \<subseteq> span (f ` S)" |
|
2074 using spans_image[OF lf us] . |
|
2075 finally show ?thesis . |
|
2076 qed |
|
2077 |
|
2078 lemma independent_injective_image: |
|
2079 assumes iS: "independent S" |
|
2080 and lf: "linear f" |
|
2081 and fi: "inj f" |
|
2082 shows "independent (f ` S)" |
|
2083 proof - |
|
2084 { |
|
2085 fix a |
|
2086 assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})" |
|
2087 have eq: "f ` S - {f a} = f ` (S - {a})" |
|
2088 using fi by (auto simp add: inj_on_def) |
|
2089 from a have "f a \<in> f ` span (S - {a})" |
|
2090 unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast |
|
2091 then have "a \<in> span (S - {a})" |
|
2092 using fi by (auto simp add: inj_on_def) |
|
2093 with a(1) iS have False |
|
2094 by (simp add: dependent_def) |
|
2095 } |
|
2096 then show ?thesis |
|
2097 unfolding dependent_def by blast |
|
2098 qed |
2199 qed |
2099 |
2200 |
2100 text \<open>Picking an orthogonal replacement for a spanning set.\<close> |
2201 text \<open>Picking an orthogonal replacement for a spanning set.\<close> |
2101 |
2202 |
2102 lemma vector_sub_project_orthogonal: |
2203 lemma vector_sub_project_orthogonal: |
2410 finally have gS: "g ` S = T" . |
2507 finally have gS: "g ` S = T" . |
2411 from g(1) gS giS show ?thesis |
2508 from g(1) gS giS show ?thesis |
2412 by blast |
2509 by blast |
2413 qed |
2510 qed |
2414 |
2511 |
2415 text \<open>Linear functions are equal on a subspace if they are on a spanning set.\<close> |
|
2416 |
|
2417 lemma subspace_kernel: |
|
2418 assumes lf: "linear f" |
|
2419 shows "subspace {x. f x = 0}" |
|
2420 apply (simp add: subspace_def) |
|
2421 apply (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf]) |
|
2422 done |
|
2423 |
|
2424 lemma linear_eq_0_span: |
|
2425 assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0" |
|
2426 shows "\<forall>x \<in> span B. f x = 0" |
|
2427 using f0 subspace_kernel[OF lf] |
|
2428 by (rule span_induct') |
|
2429 |
|
2430 lemma linear_eq_0: |
|
2431 assumes lf: "linear f" |
|
2432 and SB: "S \<subseteq> span B" |
|
2433 and f0: "\<forall>x\<in>B. f x = 0" |
|
2434 shows "\<forall>x\<in>S. f x = 0" |
|
2435 by (metis linear_eq_0_span[OF lf] subset_eq SB f0) |
|
2436 |
|
2437 lemma linear_eq: |
|
2438 assumes lf: "linear f" |
|
2439 and lg: "linear g" |
|
2440 and S: "S \<subseteq> span B" |
|
2441 and fg: "\<forall>x\<in>B. f x = g x" |
|
2442 shows "\<forall>x\<in>S. f x = g x" |
|
2443 proof - |
|
2444 let ?h = "\<lambda>x. f x - g x" |
|
2445 from fg have fg': "\<forall>x\<in> B. ?h x = 0" by simp |
|
2446 from linear_eq_0[OF linear_compose_sub[OF lf lg] S fg'] |
|
2447 show ?thesis by simp |
|
2448 qed |
|
2449 |
|
2450 lemma linear_eq_stdbasis: |
2512 lemma linear_eq_stdbasis: |
2451 fixes f :: "'a::euclidean_space \<Rightarrow> _" |
2513 fixes f :: "'a::euclidean_space \<Rightarrow> _" |
2452 assumes lf: "linear f" |
2514 assumes lf: "linear f" |
2453 and lg: "linear g" |
2515 and lg: "linear g" |
2454 and fg: "\<forall>b\<in>Basis. f b = g b" |
2516 and fg: "\<forall>b\<in>Basis. f b = g b" |
2490 assumes bf: "bilinear f" |
2552 assumes bf: "bilinear f" |
2491 and bg: "bilinear g" |
2553 and bg: "bilinear g" |
2492 and fg: "\<forall>i\<in>Basis. \<forall>j\<in>Basis. f i j = g i j" |
2554 and fg: "\<forall>i\<in>Basis. \<forall>j\<in>Basis. f i j = g i j" |
2493 shows "f = g" |
2555 shows "f = g" |
2494 using bilinear_eq[OF bf bg equalityD2[OF span_Basis] equalityD2[OF span_Basis] fg] by blast |
2556 using bilinear_eq[OF bf bg equalityD2[OF span_Basis] equalityD2[OF span_Basis] fg] by blast |
2495 |
|
2496 text \<open>Detailed theorems about left and right invertibility in general case.\<close> |
|
2497 |
|
2498 lemma linear_injective_left_inverse: |
|
2499 fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" |
|
2500 assumes lf: "linear f" |
|
2501 and fi: "inj f" |
|
2502 shows "\<exists>g. linear g \<and> g \<circ> f = id" |
|
2503 proof - |
|
2504 from linear_independent_extend[OF independent_injective_image, OF independent_Basis, OF lf fi] |
|
2505 obtain h :: "'b \<Rightarrow> 'a" where h: "linear h" "\<forall>x \<in> f ` Basis. h x = inv f x" |
|
2506 by blast |
|
2507 from h(2) have th: "\<forall>i\<in>Basis. (h \<circ> f) i = id i" |
|
2508 using inv_o_cancel[OF fi, unfolded fun_eq_iff id_def o_def] |
|
2509 by auto |
|
2510 from linear_eq_stdbasis[OF linear_compose[OF lf h(1)] linear_id th] |
|
2511 have "h \<circ> f = id" . |
|
2512 then show ?thesis |
|
2513 using h(1) by blast |
|
2514 qed |
|
2515 |
|
2516 lemma linear_surjective_right_inverse: |
|
2517 fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" |
|
2518 assumes lf: "linear f" |
|
2519 and sf: "surj f" |
|
2520 shows "\<exists>g. linear g \<and> f \<circ> g = id" |
|
2521 proof - |
|
2522 from linear_independent_extend[OF independent_Basis[where 'a='b],of "inv f"] |
|
2523 obtain h :: "'b \<Rightarrow> 'a" where h: "linear h" "\<forall>x\<in>Basis. h x = inv f x" |
|
2524 by blast |
|
2525 from h(2) have th: "\<forall>i\<in>Basis. (f \<circ> h) i = id i" |
|
2526 using sf by (auto simp add: surj_iff_all) |
|
2527 from linear_eq_stdbasis[OF linear_compose[OF h(1) lf] linear_id th] |
|
2528 have "f \<circ> h = id" . |
|
2529 then show ?thesis |
|
2530 using h(1) by blast |
|
2531 qed |
|
2532 |
2557 |
2533 text \<open>An injective map @{typ "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"} is also surjective.\<close> |
2558 text \<open>An injective map @{typ "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"} is also surjective.\<close> |
2534 |
2559 |
2535 lemma linear_injective_imp_surjective: |
2560 lemma linear_injective_imp_surjective: |
2536 fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" |
2561 fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space" |