626 apply (auto simp add: image_iff) |
626 apply (auto simp add: image_iff) |
627 apply (rule_tac x="x + y" in bexI, auto) |
627 apply (rule_tac x="x + y" in bexI, auto) |
628 apply (rule_tac x="c *\<^sub>R x" in bexI, auto) |
628 apply (rule_tac x="c *\<^sub>R x" in bexI, auto) |
629 done |
629 done |
630 |
630 |
|
631 lemma subspace_linear_vimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace (f -` S)" |
|
632 by (auto simp add: subspace_def linear_def linear_0[of f]) |
|
633 |
631 lemma subspace_linear_preimage: "linear f ==> subspace S ==> subspace {x. f x \<in> S}" |
634 lemma subspace_linear_preimage: "linear f ==> subspace S ==> subspace {x. f x \<in> S}" |
632 by (auto simp add: subspace_def linear_def linear_0[of f]) |
635 by (auto simp add: subspace_def linear_def linear_0[of f]) |
633 |
636 |
634 lemma subspace_trivial: "subspace {0}" |
637 lemma subspace_trivial: "subspace {0}" |
635 by (simp add: subspace_def) |
638 by (simp add: subspace_def) |
636 |
639 |
637 lemma (in real_vector) subspace_inter: "subspace A \<Longrightarrow> subspace B ==> subspace (A \<inter> B)" |
640 lemma (in real_vector) subspace_inter: "subspace A \<Longrightarrow> subspace B ==> subspace (A \<inter> B)" |
638 by (simp add: subspace_def) |
641 by (simp add: subspace_def) |
|
642 |
|
643 lemma subspace_Times: "\<lbrakk>subspace A; subspace B\<rbrakk> \<Longrightarrow> subspace (A \<times> B)" |
|
644 unfolding subspace_def zero_prod_def by simp |
|
645 |
|
646 text {* Properties of span. *} |
639 |
647 |
640 lemma (in real_vector) span_mono: "A \<subseteq> B ==> span A \<subseteq> span B" |
648 lemma (in real_vector) span_mono: "A \<subseteq> B ==> span A \<subseteq> span B" |
641 by (metis span_def hull_mono) |
649 by (metis span_def hull_mono) |
642 |
650 |
643 lemma (in real_vector) subspace_span: "subspace(span S)" |
651 lemma (in real_vector) subspace_span: "subspace(span S)" |
653 "x\<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S" |
661 "x\<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S" |
654 "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S" |
662 "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S" |
655 by (metis span_def hull_subset subset_eq) |
663 by (metis span_def hull_subset subset_eq) |
656 (metis subspace_span subspace_def)+ |
664 (metis subspace_span subspace_def)+ |
657 |
665 |
658 lemma (in real_vector) span_induct: assumes SP: "\<And>x. x \<in> S ==> x \<in> P" |
666 lemma span_unique: |
659 and P: "subspace P" and x: "x \<in> span S" shows "x \<in> P" |
667 "\<lbrakk>S \<subseteq> T; subspace T; \<And>T'. \<lbrakk>S \<subseteq> T'; subspace T'\<rbrakk> \<Longrightarrow> T \<subseteq> T'\<rbrakk> \<Longrightarrow> span S = T" |
|
668 unfolding span_def by (rule hull_unique) |
|
669 |
|
670 lemma span_minimal: "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> span S \<subseteq> T" |
|
671 unfolding span_def by (rule hull_minimal) |
|
672 |
|
673 lemma (in real_vector) span_induct: |
|
674 assumes x: "x \<in> span S" and P: "subspace P" and SP: "\<And>x. x \<in> S ==> x \<in> P" |
|
675 shows "x \<in> P" |
660 proof- |
676 proof- |
661 from SP have SP': "S \<subseteq> P" by (simp add: subset_eq) |
677 from SP have SP': "S \<subseteq> P" by (simp add: subset_eq) |
662 from x hull_minimal[where S=subspace, OF SP' P, unfolded span_def[symmetric]] |
678 from x hull_minimal[where S=subspace, OF SP' P, unfolded span_def[symmetric]] |
663 show "x \<in> P" by (metis subset_eq) |
679 show "x \<in> P" by (metis subset_eq) |
664 qed |
680 qed |
786 apply (subgoal_tac "(x + y) - x \<in> span S", simp) |
802 apply (subgoal_tac "(x + y) - x \<in> span S", simp) |
787 by (simp only: span_add span_sub) |
803 by (simp only: span_add span_sub) |
788 |
804 |
789 text {* Mapping under linear image. *} |
805 text {* Mapping under linear image. *} |
790 |
806 |
791 lemma span_linear_image: assumes lf: "linear f" |
807 lemma image_subset_iff_subset_vimage: "f ` A \<subseteq> B \<longleftrightarrow> A \<subseteq> f -` B" |
|
808 by auto (* TODO: move *) |
|
809 |
|
810 lemma span_linear_image: |
|
811 assumes lf: "linear f" |
792 shows "span (f ` S) = f ` (span S)" |
812 shows "span (f ` S) = f ` (span S)" |
793 proof- |
813 proof (rule span_unique) |
794 {fix x |
814 show "f ` S \<subseteq> f ` span S" |
795 assume x: "x \<in> span (f ` S)" |
815 by (intro image_mono span_inc) |
796 have "x \<in> f ` span S" |
816 show "subspace (f ` span S)" |
797 apply (rule span_induct[where x=x and S = "f ` S"]) |
817 using lf subspace_span by (rule subspace_linear_image) |
798 apply (clarsimp simp add: image_iff) |
818 next |
799 apply (frule span_superset) |
819 fix T assume "f ` S \<subseteq> T" and "subspace T" thus "f ` span S \<subseteq> T" |
800 apply blast |
820 unfolding image_subset_iff_subset_vimage |
801 apply (rule subspace_linear_image[OF lf]) |
821 by (intro span_minimal subspace_linear_vimage lf) |
802 apply (rule subspace_span) |
822 qed |
803 apply (rule x) |
823 |
804 done} |
824 lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
805 moreover |
825 proof (rule span_unique) |
806 {fix x assume x: "x \<in> span S" |
826 show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
807 have "x \<in> {x. f x \<in> span (f ` S)}" |
827 by safe (force intro: span_clauses)+ |
808 apply (rule span_induct[where S=S]) |
828 next |
809 apply simp |
829 have "linear (\<lambda>(a, b). a + b)" |
810 apply (rule span_superset) |
830 by (simp add: linear_def scaleR_add_right) |
811 apply simp |
831 moreover have "subspace (span A \<times> span B)" |
812 apply (rule subspace_linear_preimage[OF lf subspace_span, of "f ` S"]) |
832 by (intro subspace_Times subspace_span) |
813 apply (rule x) |
833 ultimately show "subspace ((\<lambda>(a, b). a + b) ` (span A \<times> span B))" |
814 done |
834 by (rule subspace_linear_image) |
815 hence "f x \<in> span (f ` S)" by simp |
835 next |
816 } |
836 fix T assume "A \<union> B \<subseteq> T" and "subspace T" |
817 ultimately show ?thesis by blast |
837 thus "(\<lambda>(a, b). a + b) ` (span A \<times> span B) \<subseteq> T" |
|
838 by (auto intro!: subspace_add elim: span_induct) |
818 qed |
839 qed |
819 |
840 |
820 text {* The key breakdown property. *} |
841 text {* The key breakdown property. *} |
|
842 |
|
843 lemma span_singleton: "span {x} = range (\<lambda>k. k *\<^sub>R x)" |
|
844 proof (rule span_unique) |
|
845 show "{x} \<subseteq> range (\<lambda>k. k *\<^sub>R x)" |
|
846 by (fast intro: scaleR_one [symmetric]) |
|
847 show "subspace (range (\<lambda>k. k *\<^sub>R x))" |
|
848 unfolding subspace_def |
|
849 by (auto intro: scaleR_add_left [symmetric]) |
|
850 fix T assume "{x} \<subseteq> T" and "subspace T" thus "range (\<lambda>k. k *\<^sub>R x) \<subseteq> T" |
|
851 unfolding subspace_def by auto |
|
852 qed |
|
853 |
|
854 lemma span_insert: |
|
855 "span (insert a S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}" |
|
856 proof - |
|
857 have "span ({a} \<union> S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}" |
|
858 unfolding span_union span_singleton |
|
859 apply safe |
|
860 apply (rule_tac x=k in exI, simp) |
|
861 apply (erule rev_image_eqI [OF SigmaI [OF rangeI]]) |
|
862 apply simp |
|
863 apply (rule right_minus) |
|
864 done |
|
865 thus ?thesis by simp |
|
866 qed |
821 |
867 |
822 lemma span_breakdown: |
868 lemma span_breakdown: |
823 assumes bS: "b \<in> S" and aS: "a \<in> span S" |
869 assumes bS: "b \<in> S" and aS: "a \<in> span S" |
824 shows "\<exists>k. a - k *\<^sub>R b \<in> span (S - {b})" (is "?P a") |
870 shows "\<exists>k. a - k *\<^sub>R b \<in> span (S - {b})" |
825 proof- |
871 using assms span_insert [of b "S - {b}"] |
826 {fix x assume xS: "x \<in> S" |
872 by (simp add: insert_absorb) |
827 {assume ab: "x = b" |
|
828 then have "?P x" |
|
829 apply simp |
|
830 apply (rule exI[where x="1"], simp) |
|
831 by (rule span_0)} |
|
832 moreover |
|
833 {assume ab: "x \<noteq> b" |
|
834 then have "?P x" using xS |
|
835 apply - |
|
836 apply (rule exI[where x=0]) |
|
837 apply (rule span_superset) |
|
838 by simp} |
|
839 ultimately have "x \<in> Collect ?P" by blast} |
|
840 moreover have "subspace (Collect ?P)" |
|
841 unfolding subspace_def |
|
842 apply auto |
|
843 apply (rule exI[where x=0]) |
|
844 using span_0[of "S - {b}"] |
|
845 apply simp |
|
846 apply (rule_tac x="k + ka" in exI) |
|
847 apply (subgoal_tac "x + y - (k + ka) *\<^sub>R b = (x - k*\<^sub>R b) + (y - ka *\<^sub>R b)") |
|
848 apply (simp only: ) |
|
849 apply (rule span_add) |
|
850 apply assumption+ |
|
851 apply (simp add: algebra_simps) |
|
852 apply (rule_tac x= "c*k" in exI) |
|
853 apply (subgoal_tac "c *\<^sub>R x - (c * k) *\<^sub>R b = c*\<^sub>R (x - k*\<^sub>R b)") |
|
854 apply (simp only: ) |
|
855 apply (rule span_mul) |
|
856 apply assumption |
|
857 by (simp add: algebra_simps) |
|
858 ultimately have "a \<in> Collect ?P" using aS by (rule span_induct) |
|
859 thus "?P a" by simp |
|
860 qed |
|
861 |
873 |
862 lemma span_breakdown_eq: |
874 lemma span_breakdown_eq: |
863 "x \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. (x - k *\<^sub>R a) \<in> span S)" (is "?lhs \<longleftrightarrow> ?rhs") |
875 "x \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. (x - k *\<^sub>R a) \<in> span S)" |
864 proof- |
876 by (simp add: span_insert) |
865 {assume x: "x \<in> span (insert a S)" |
|
866 from x span_breakdown[of "a" "insert a S" "x"] |
|
867 have ?rhs apply clarsimp |
|
868 apply (rule_tac x= "k" in exI) |
|
869 apply (rule set_rev_mp[of _ "span (S - {a})" _]) |
|
870 apply assumption |
|
871 apply (rule span_mono) |
|
872 apply blast |
|
873 done} |
|
874 moreover |
|
875 { fix k assume k: "x - k *\<^sub>R a \<in> span S" |
|
876 have eq: "x = (x - k *\<^sub>R a) + k *\<^sub>R a" by simp |
|
877 have "(x - k *\<^sub>R a) + k *\<^sub>R a \<in> span (insert a S)" |
|
878 apply (rule span_add) |
|
879 apply (rule set_rev_mp[of _ "span S" _]) |
|
880 apply (rule k) |
|
881 apply (rule span_mono) |
|
882 apply blast |
|
883 apply (rule span_mul) |
|
884 apply (rule span_superset) |
|
885 apply blast |
|
886 done |
|
887 then have ?lhs using eq by metis} |
|
888 ultimately show ?thesis by blast |
|
889 qed |
|
890 |
877 |
891 text {* Hence some "reversal" results. *} |
878 text {* Hence some "reversal" results. *} |
892 |
879 |
893 lemma in_span_insert: |
880 lemma in_span_insert: |
894 assumes a: "a \<in> span (insert b S)" and na: "a \<notin> span S" |
881 assumes a: "a \<in> span (insert b S)" and na: "a \<notin> span S" |
941 apply (rule na) |
928 apply (rule na) |
942 done |
929 done |
943 |
930 |
944 text {* Transitivity property. *} |
931 text {* Transitivity property. *} |
945 |
932 |
|
933 lemma span_redundant: "x \<in> span S \<Longrightarrow> span (insert x S) = span S" |
|
934 unfolding span_def by (rule hull_redundant) |
|
935 |
946 lemma span_trans: |
936 lemma span_trans: |
947 assumes x: "x \<in> span S" and y: "y \<in> span (insert x S)" |
937 assumes x: "x \<in> span S" and y: "y \<in> span (insert x S)" |
948 shows "y \<in> span S" |
938 shows "y \<in> span S" |
949 proof- |
939 using assms by (simp only: span_redundant) |
950 from span_breakdown[of x "insert x S" y, OF insertI1 y] |
|
951 obtain k where k: "y -k*\<^sub>R x \<in> span (S - {x})" by auto |
|
952 have eq: "y = (y - k *\<^sub>R x) + k *\<^sub>R x" by simp |
|
953 show ?thesis |
|
954 apply (subst eq) |
|
955 apply (rule span_add) |
|
956 apply (rule set_rev_mp) |
|
957 apply (rule k) |
|
958 apply (rule span_mono) |
|
959 apply blast |
|
960 apply (rule span_mul) |
|
961 by (rule x) |
|
962 qed |
|
963 |
940 |
964 lemma span_insert_0[simp]: "span (insert 0 S) = span S" |
941 lemma span_insert_0[simp]: "span (insert 0 S) = span S" |
965 using span_mono[of S "insert 0 S"] by (auto intro: span_trans span_0) |
942 by (simp only: span_redundant span_0) |
966 |
943 |
967 text {* An explicit expansion is sometimes needed. *} |
944 text {* An explicit expansion is sometimes needed. *} |
968 |
945 |
969 lemma span_explicit: |
946 lemma span_explicit: |
970 "span P = {y. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = y}" |
947 "span P = {y. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *\<^sub>R v) S = y}" |
1090 hence "y \<in> ?rhs" by auto} |
1067 hence "y \<in> ?rhs" by auto} |
1091 moreover |
1068 moreover |
1092 {fix y u assume u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y" |
1069 {fix y u assume u: "setsum (\<lambda>v. u v *\<^sub>R v) S = y" |
1093 then have "y \<in> span S" using fS unfolding span_explicit by auto} |
1070 then have "y \<in> span S" using fS unfolding span_explicit by auto} |
1094 ultimately show ?thesis by blast |
1071 ultimately show ?thesis by blast |
1095 qed |
|
1096 |
|
1097 lemma Int_Un_cancel: "(A \<union> B) \<inter> A = A" "(A \<union> B) \<inter> B = B" by auto |
|
1098 |
|
1099 lemma span_union: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
|
1100 proof safe |
|
1101 fix x assume "x \<in> span (A \<union> B)" |
|
1102 then obtain S u where S: "finite S" "S \<subseteq> A \<union> B" and x: "x = (\<Sum>v\<in>S. u v *\<^sub>R v)" |
|
1103 unfolding span_explicit by auto |
|
1104 |
|
1105 let ?Sa = "\<Sum>v\<in>S\<inter>A. u v *\<^sub>R v" |
|
1106 let ?Sb = "(\<Sum>v\<in>S\<inter>(B - A). u v *\<^sub>R v)" |
|
1107 show "x \<in> (\<lambda>(a, b). a + b) ` (span A \<times> span B)" |
|
1108 proof |
|
1109 show "x = (case (?Sa, ?Sb) of (a, b) \<Rightarrow> a + b)" |
|
1110 unfolding x using S |
|
1111 by (simp, subst setsum_Un_disjoint[symmetric]) (auto intro!: setsum_cong) |
|
1112 |
|
1113 from S have "?Sa \<in> span A" unfolding span_explicit |
|
1114 by (auto intro!: exI[of _ "S \<inter> A"]) |
|
1115 moreover from S have "?Sb \<in> span B" unfolding span_explicit |
|
1116 by (auto intro!: exI[of _ "S \<inter> (B - A)"]) |
|
1117 ultimately show "(?Sa, ?Sb) \<in> span A \<times> span B" by simp |
|
1118 qed |
|
1119 next |
|
1120 fix a b assume "a \<in> span A" and "b \<in> span B" |
|
1121 then obtain Sa ua Sb ub where span: |
|
1122 "finite Sa" "Sa \<subseteq> A" "a = (\<Sum>v\<in>Sa. ua v *\<^sub>R v)" |
|
1123 "finite Sb" "Sb \<subseteq> B" "b = (\<Sum>v\<in>Sb. ub v *\<^sub>R v)" |
|
1124 unfolding span_explicit by auto |
|
1125 let "?u v" = "(if v \<in> Sa then ua v else 0) + (if v \<in> Sb then ub v else 0)" |
|
1126 from span have "finite (Sa \<union> Sb)" "Sa \<union> Sb \<subseteq> A \<union> B" |
|
1127 and "a + b = (\<Sum>v\<in>(Sa\<union>Sb). ?u v *\<^sub>R v)" |
|
1128 unfolding setsum_addf scaleR_left_distrib |
|
1129 by (auto simp add: if_distrib cond_application_beta setsum_cases Int_Un_cancel) |
|
1130 thus "a + b \<in> span (A \<union> B)" |
|
1131 unfolding span_explicit by (auto intro!: exI[of _ ?u]) |
|
1132 qed |
1072 qed |
1133 |
1073 |
1134 text {* This is useful for building a basis step-by-step. *} |
1074 text {* This is useful for building a basis step-by-step. *} |
1135 |
1075 |
1136 lemma independent_insert: |
1076 lemma independent_insert: |