added Johannes' generalizations Modules.thy and Vector_Spaces.thy; adapted HOL and HOL-Analysis accordingly
authorimmler
Wed May 02 13:49:38 2018 +0200 (12 months ago)
changeset 68072493b818e8e10
parent 68001 0a2a1b6507c1
child 68073 fad29d2a17a5
added Johannes' generalizations Modules.thy and Vector_Spaces.thy; adapted HOL and HOL-Analysis accordingly
CONTRIBUTORS
NEWS
src/HOL/Algebra/Congruence.thy
src/HOL/Algebra/Group.thy
src/HOL/Algebra/Order.thy
src/HOL/Analysis/Bochner_Integration.thy
src/HOL/Analysis/Bounded_Linear_Function.thy
src/HOL/Analysis/Cartesian_Euclidean_Space.thy
src/HOL/Analysis/Cartesian_Space.thy
src/HOL/Analysis/Change_Of_Vars.thy
src/HOL/Analysis/Connected.thy
src/HOL/Analysis/Convex_Euclidean_Space.thy
src/HOL/Analysis/Derivative.thy
src/HOL/Analysis/Determinants.thy
src/HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy
src/HOL/Analysis/Euclidean_Space.thy
src/HOL/Analysis/Finite_Cartesian_Product.thy
src/HOL/Analysis/Further_Topology.thy
src/HOL/Analysis/Henstock_Kurzweil_Integration.thy
src/HOL/Analysis/Homeomorphism.thy
src/HOL/Analysis/Inner_Product.thy
src/HOL/Analysis/Linear_Algebra.thy
src/HOL/Analysis/Path_Connected.thy
src/HOL/Analysis/Polytope.thy
src/HOL/Analysis/Product_Vector.thy
src/HOL/Analysis/Sigma_Algebra.thy
src/HOL/Analysis/Starlike.thy
src/HOL/Analysis/Topology_Euclidean_Space.thy
src/HOL/Analysis/Weierstrass_Theorems.thy
src/HOL/Computational_Algebra/Formal_Power_Series.thy
src/HOL/FuncSet.thy
src/HOL/HOL.thy
src/HOL/Hull.thy
src/HOL/Library/FuncSet.thy
src/HOL/Library/Library.thy
src/HOL/Metis_Examples/Abstraction.thy
src/HOL/Metis_Examples/Tarski.thy
src/HOL/Modules.thy
src/HOL/Number_Theory/Prime_Powers.thy
src/HOL/Real_Vector_Spaces.thy
src/HOL/Vector_Spaces.thy
src/HOL/ex/Ballot.thy
src/HOL/ex/Birthday_Paradox.thy
src/HOL/ex/Tarski.thy
     1.1 --- a/CONTRIBUTORS	Wed Apr 18 21:12:50 2018 +0100
     1.2 +++ b/CONTRIBUTORS	Wed May 02 13:49:38 2018 +0200
     1.3 @@ -6,6 +6,12 @@
     1.4  Contributions to this Isabelle version
     1.5  --------------------------------------
     1.6  
     1.7 +* April 2018: Jose Divasón (Universidad de la Rioja),
     1.8 +  Jesús Aransay (Universidad de la Rioja), Johannes Hölzl (VU Amsterdam),
     1.9 +  Fabian Immler (TUM)
    1.10 +  Generalizations in the formalization of linear algebra.
    1.11 +
    1.12 +
    1.13  * March 2018: Florian Haftmann
    1.14    Abstract bit operations push_bit, push_take, push_drop, alongside
    1.15    with an algebraic foundation for bit strings and word types in
     2.1 --- a/NEWS	Wed Apr 18 21:12:50 2018 +0100
     2.2 +++ b/NEWS	Wed May 02 13:49:38 2018 +0200
     2.3 @@ -257,6 +257,15 @@
     2.4  * The relator rel_filter on filters has been strengthened to its 
     2.5  canonical categorical definition with better properties. INCOMPATIBILITY.
     2.6  
     2.7 +* Generalized linear algebra involving linear, span, dependent, dim
     2.8 +from type class real_vector to locales module and vector_space.
     2.9 +Renamed:
    2.10 +  - span_inc ~> span_superset
    2.11 +  - span_superset ~> span_base
    2.12 +  - span_eq ~> span_eq_iff
    2.13 +INCOMPATIBILITY.
    2.14 +
    2.15 +
    2.16  * HOL-Algebra: renamed (^) to [^]
    2.17  
    2.18  * Session HOL-Analysis: Moebius functions, the Riemann mapping
     3.1 --- a/src/HOL/Algebra/Congruence.thy	Wed Apr 18 21:12:50 2018 +0100
     3.2 +++ b/src/HOL/Algebra/Congruence.thy	Wed May 02 13:49:38 2018 +0200
     3.3 @@ -4,9 +4,8 @@
     3.4  *)
     3.5  
     3.6  theory Congruence
     3.7 -imports 
     3.8 -  Main
     3.9 -  "HOL-Library.FuncSet"
    3.10 +  imports
    3.11 +    Main HOL.FuncSet
    3.12  begin
    3.13  
    3.14  section \<open>Objects\<close>
     4.1 --- a/src/HOL/Algebra/Group.thy	Wed Apr 18 21:12:50 2018 +0100
     4.2 +++ b/src/HOL/Algebra/Group.thy	Wed May 02 13:49:38 2018 +0200
     4.3 @@ -5,7 +5,7 @@
     4.4  *)
     4.5  
     4.6  theory Group
     4.7 -imports Complete_Lattice "HOL-Library.FuncSet"
     4.8 +imports Complete_Lattice HOL.FuncSet
     4.9  begin
    4.10  
    4.11  section \<open>Monoids and Groups\<close>
     5.1 --- a/src/HOL/Algebra/Order.thy	Wed Apr 18 21:12:50 2018 +0100
     5.2 +++ b/src/HOL/Algebra/Order.thy	Wed May 02 13:49:38 2018 +0200
     5.3 @@ -7,9 +7,8 @@
     5.4  *)
     5.5  
     5.6  theory Order
     5.7 -imports 
     5.8 -  "HOL-Library.FuncSet"
     5.9 -  Congruence
    5.10 +  imports
    5.11 +    Congruence
    5.12  begin
    5.13  
    5.14  section \<open>Orders\<close>
     6.1 --- a/src/HOL/Analysis/Bochner_Integration.thy	Wed Apr 18 21:12:50 2018 +0100
     6.2 +++ b/src/HOL/Analysis/Bochner_Integration.thy	Wed May 02 13:49:38 2018 +0200
     6.3 @@ -394,17 +394,19 @@
     6.4      by (simp add: sum.distrib[symmetric] scaleR_add_right)
     6.5  qed
     6.6  
     6.7 -lemma (in linear) simple_bochner_integral_linear:
     6.8 +lemma simple_bochner_integral_linear:
     6.9 +  assumes "linear f"
    6.10    assumes g: "simple_bochner_integrable M g"
    6.11    shows "simple_bochner_integral M (\<lambda>x. f (g x)) = f (simple_bochner_integral M g)"
    6.12  proof -
    6.13 +  interpret linear f by fact
    6.14    from g have "simple_bochner_integral M (\<lambda>x. f (g x)) =
    6.15      (\<Sum>y\<in>g ` space M. measure M {x \<in> space M. g x = y} *\<^sub>R f y)"
    6.16      by (intro simple_bochner_integral_partition)
    6.17         (auto simp: simple_bochner_integrable_compose2[where p="\<lambda>x y. f x"] zero
    6.18               elim: simple_bochner_integrable.cases)
    6.19    also have "\<dots> = f (simple_bochner_integral M g)"
    6.20 -    by (simp add: simple_bochner_integral_def sum scaleR)
    6.21 +    by (simp add: simple_bochner_integral_def sum scale)
    6.22    finally show ?thesis .
    6.23  qed
    6.24  
    6.25 @@ -412,8 +414,7 @@
    6.26    assumes f: "simple_bochner_integrable M f"
    6.27    shows "simple_bochner_integral M (\<lambda>x. - f x) = - simple_bochner_integral M f"
    6.28  proof -
    6.29 -  interpret linear uminus by unfold_locales auto
    6.30 -  from f show ?thesis
    6.31 +  from linear_uminus f show ?thesis
    6.32      by (rule simple_bochner_integral_linear)
    6.33  qed
    6.34  
    6.35 @@ -646,7 +647,7 @@
    6.36  
    6.37    assume "(\<lambda>i. simple_bochner_integral M (s i)) \<longlonglongrightarrow> x"
    6.38    with s show "(\<lambda>i. simple_bochner_integral M (\<lambda>x. T (s i x))) \<longlonglongrightarrow> T x"
    6.39 -    by (auto intro!: T.tendsto simp: T.simple_bochner_integral_linear)
    6.40 +    by (auto intro!: T.tendsto simp: simple_bochner_integral_linear T.linear_axioms)
    6.41  qed
    6.42  
    6.43  lemma has_bochner_integral_zero[intro]: "has_bochner_integral M (\<lambda>x. 0) 0"
     7.1 --- a/src/HOL/Analysis/Bounded_Linear_Function.thy	Wed Apr 18 21:12:50 2018 +0100
     7.2 +++ b/src/HOL/Analysis/Bounded_Linear_Function.thy	Wed May 02 13:49:38 2018 +0200
     7.3 @@ -529,7 +529,7 @@
     7.4  lemma Blinfun_eq_matrix: "bounded_linear f \<Longrightarrow> Blinfun f = blinfun_of_matrix (\<lambda>i j. f j \<bullet> i)"
     7.5    by (intro blinfun_euclidean_eqI)
     7.6       (auto simp: blinfun_of_matrix_apply bounded_linear_Blinfun_apply inner_Basis if_distrib
     7.7 -      cond_application_beta sum.delta' euclidean_representation
     7.8 +      if_distribR sum.delta' euclidean_representation
     7.9        cong: if_cong)
    7.10  
    7.11  text \<open>TODO: generalize (via \<open>compact_cball\<close>)?\<close>
     8.1 --- a/src/HOL/Analysis/Cartesian_Euclidean_Space.thy	Wed Apr 18 21:12:50 2018 +0100
     8.2 +++ b/src/HOL/Analysis/Cartesian_Euclidean_Space.thy	Wed May 02 13:49:38 2018 +0200
     8.3 @@ -1,19 +1,9 @@
     8.4  section \<open>Instantiates the finite Cartesian product of Euclidean spaces as a Euclidean space\<close>
     8.5  
     8.6  theory Cartesian_Euclidean_Space
     8.7 -imports Finite_Cartesian_Product Derivative
     8.8 +imports Cartesian_Space Derivative
     8.9  begin
    8.10  
    8.11 -lemma norm_le_componentwise:
    8.12 -   "(\<And>b. b \<in> Basis \<Longrightarrow> abs(x \<bullet> b) \<le> abs(y \<bullet> b)) \<Longrightarrow> norm x \<le> norm y"
    8.13 -  by (auto simp: norm_le euclidean_inner [of x x] euclidean_inner [of y y] abs_le_square_iff power2_eq_square intro!: sum_mono)
    8.14 -
    8.15 -lemma norm_le_componentwise_cart:
    8.16 -  fixes x :: "real^'n"
    8.17 -  shows "(\<And>i. abs(x$i) \<le> abs(y$i)) \<Longrightarrow> norm x \<le> norm y"
    8.18 -  unfolding cart_eq_inner_axis
    8.19 -  by (rule norm_le_componentwise) (metis axis_index)
    8.20 -  
    8.21  lemma subspace_special_hyperplane: "subspace {x. x $ k = 0}"
    8.22    by (simp add: subspace_def)
    8.23  
    8.24 @@ -31,254 +21,9 @@
    8.25    qed simp
    8.26  qed simp
    8.27  
    8.28 -subsection\<open>Basic componentwise operations on vectors\<close>
    8.29 -
    8.30 -instantiation vec :: (times, finite) times
    8.31 -begin
    8.32 -
    8.33 -definition "( * ) \<equiv> (\<lambda> x y.  (\<chi> i. (x$i) * (y$i)))"
    8.34 -instance ..
    8.35 -
    8.36 -end
    8.37 -
    8.38 -instantiation vec :: (one, finite) one
    8.39 -begin
    8.40 -
    8.41 -definition "1 \<equiv> (\<chi> i. 1)"
    8.42 -instance ..
    8.43 -
    8.44 -end
    8.45 -
    8.46 -instantiation vec :: (ord, finite) ord
    8.47 -begin
    8.48 -
    8.49 -definition "x \<le> y \<longleftrightarrow> (\<forall>i. x$i \<le> y$i)"
    8.50 -definition "x < (y::'a^'b) \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
    8.51 -instance ..
    8.52 -
    8.53 -end
    8.54 -
    8.55 -text\<open>The ordering on one-dimensional vectors is linear.\<close>
    8.56 -
    8.57 -class cart_one =
    8.58 -  assumes UNIV_one: "card (UNIV :: 'a set) = Suc 0"
    8.59 -begin
    8.60 -
    8.61 -subclass finite
    8.62 -proof
    8.63 -  from UNIV_one show "finite (UNIV :: 'a set)"
    8.64 -    by (auto intro!: card_ge_0_finite)
    8.65 -qed
    8.66 -
    8.67 -end
    8.68 -
    8.69 -instance vec:: (order, finite) order
    8.70 -  by standard (auto simp: less_eq_vec_def less_vec_def vec_eq_iff
    8.71 -      intro: order.trans order.antisym order.strict_implies_order)
    8.72 -
    8.73 -instance vec :: (linorder, cart_one) linorder
    8.74 -proof
    8.75 -  obtain a :: 'b where all: "\<And>P. (\<forall>i. P i) \<longleftrightarrow> P a"
    8.76 -  proof -
    8.77 -    have "card (UNIV :: 'b set) = Suc 0" by (rule UNIV_one)
    8.78 -    then obtain b :: 'b where "UNIV = {b}" by (auto iff: card_Suc_eq)
    8.79 -    then have "\<And>P. (\<forall>i\<in>UNIV. P i) \<longleftrightarrow> P b" by auto
    8.80 -    then show thesis by (auto intro: that)
    8.81 -  qed
    8.82 -  fix x y :: "'a^'b::cart_one"
    8.83 -  note [simp] = less_eq_vec_def less_vec_def all vec_eq_iff field_simps
    8.84 -  show "x \<le> y \<or> y \<le> x" by auto
    8.85 -qed
    8.86 -
    8.87 -text\<open>Constant Vectors\<close>
    8.88 -
    8.89 -definition "vec x = (\<chi> i. x)"
    8.90 -
    8.91  lemma interval_cbox_cart: "{a::real^'n..b} = cbox a b"
    8.92    by (auto simp add: less_eq_vec_def mem_box Basis_vec_def inner_axis)
    8.93  
    8.94 -text\<open>Also the scalar-vector multiplication.\<close>
    8.95 -
    8.96 -definition vector_scalar_mult:: "'a::times \<Rightarrow> 'a ^ 'n \<Rightarrow> 'a ^ 'n" (infixl "*s" 70)
    8.97 -  where "c *s x = (\<chi> i. c * (x$i))"
    8.98 -
    8.99 -
   8.100 -subsection \<open>A naive proof procedure to lift really trivial arithmetic stuff from the basis of the vector space\<close>
   8.101 -
   8.102 -lemma sum_cong_aux:
   8.103 -  "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> sum f A = sum g A"
   8.104 -  by (auto intro: sum.cong)
   8.105 -
   8.106 -hide_fact (open) sum_cong_aux
   8.107 -
   8.108 -method_setup vector = \<open>
   8.109 -let
   8.110 -  val ss1 =
   8.111 -    simpset_of (put_simpset HOL_basic_ss @{context}
   8.112 -      addsimps [@{thm sum.distrib} RS sym,
   8.113 -      @{thm sum_subtractf} RS sym, @{thm sum_distrib_left},
   8.114 -      @{thm sum_distrib_right}, @{thm sum_negf} RS sym])
   8.115 -  val ss2 =
   8.116 -    simpset_of (@{context} addsimps
   8.117 -             [@{thm plus_vec_def}, @{thm times_vec_def},
   8.118 -              @{thm minus_vec_def}, @{thm uminus_vec_def},
   8.119 -              @{thm one_vec_def}, @{thm zero_vec_def}, @{thm vec_def},
   8.120 -              @{thm scaleR_vec_def},
   8.121 -              @{thm vec_lambda_beta}, @{thm vector_scalar_mult_def}])
   8.122 -  fun vector_arith_tac ctxt ths =
   8.123 -    simp_tac (put_simpset ss1 ctxt)
   8.124 -    THEN' (fn i => resolve_tac ctxt @{thms Cartesian_Euclidean_Space.sum_cong_aux} i
   8.125 -         ORELSE resolve_tac ctxt @{thms sum.neutral} i
   8.126 -         ORELSE simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm vec_eq_iff}]) i)
   8.127 -    (* THEN' TRY o clarify_tac HOL_cs  THEN' (TRY o rtac @{thm iffI}) *)
   8.128 -    THEN' asm_full_simp_tac (put_simpset ss2 ctxt addsimps ths)
   8.129 -in
   8.130 -  Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (vector_arith_tac ctxt ths))
   8.131 -end
   8.132 -\<close> "lift trivial vector statements to real arith statements"
   8.133 -
   8.134 -lemma vec_0[simp]: "vec 0 = 0" by vector
   8.135 -lemma vec_1[simp]: "vec 1 = 1" by vector
   8.136 -
   8.137 -lemma vec_inj[simp]: "vec x = vec y \<longleftrightarrow> x = y" by vector
   8.138 -
   8.139 -lemma vec_in_image_vec: "vec x \<in> (vec ` S) \<longleftrightarrow> x \<in> S" by auto
   8.140 -
   8.141 -lemma vec_add: "vec(x + y) = vec x + vec y"  by vector
   8.142 -lemma vec_sub: "vec(x - y) = vec x - vec y" by vector
   8.143 -lemma vec_cmul: "vec(c * x) = c *s vec x " by vector
   8.144 -lemma vec_neg: "vec(- x) = - vec x " by vector
   8.145 -
   8.146 -lemma vec_scaleR: "vec(c * x) = c *\<^sub>R vec x"
   8.147 -  by vector
   8.148 -
   8.149 -lemma vec_sum:
   8.150 -  assumes "finite S"
   8.151 -  shows "vec(sum f S) = sum (vec \<circ> f) S"
   8.152 -  using assms
   8.153 -proof induct
   8.154 -  case empty
   8.155 -  then show ?case by simp
   8.156 -next
   8.157 -  case insert
   8.158 -  then show ?case by (auto simp add: vec_add)
   8.159 -qed
   8.160 -
   8.161 -text\<open>Obvious "component-pushing".\<close>
   8.162 -
   8.163 -lemma vec_component [simp]: "vec x $ i = x"
   8.164 -  by vector
   8.165 -
   8.166 -lemma vector_mult_component [simp]: "(x * y)$i = x$i * y$i"
   8.167 -  by vector
   8.168 -
   8.169 -lemma vector_smult_component [simp]: "(c *s y)$i = c * (y$i)"
   8.170 -  by vector
   8.171 -
   8.172 -lemma cond_component: "(if b then x else y)$i = (if b then x$i else y$i)" by vector
   8.173 -
   8.174 -lemmas vector_component =
   8.175 -  vec_component vector_add_component vector_mult_component
   8.176 -  vector_smult_component vector_minus_component vector_uminus_component
   8.177 -  vector_scaleR_component cond_component
   8.178 -
   8.179 -
   8.180 -subsection \<open>Some frequently useful arithmetic lemmas over vectors\<close>
   8.181 -
   8.182 -instance vec :: (semigroup_mult, finite) semigroup_mult
   8.183 -  by standard (vector mult.assoc)
   8.184 -
   8.185 -instance vec :: (monoid_mult, finite) monoid_mult
   8.186 -  by standard vector+
   8.187 -
   8.188 -instance vec :: (ab_semigroup_mult, finite) ab_semigroup_mult
   8.189 -  by standard (vector mult.commute)
   8.190 -
   8.191 -instance vec :: (comm_monoid_mult, finite) comm_monoid_mult
   8.192 -  by standard vector
   8.193 -
   8.194 -instance vec :: (semiring, finite) semiring
   8.195 -  by standard (vector field_simps)+
   8.196 -
   8.197 -instance vec :: (semiring_0, finite) semiring_0
   8.198 -  by standard (vector field_simps)+
   8.199 -instance vec :: (semiring_1, finite) semiring_1
   8.200 -  by standard vector
   8.201 -instance vec :: (comm_semiring, finite) comm_semiring
   8.202 -  by standard (vector field_simps)+
   8.203 -
   8.204 -instance vec :: (comm_semiring_0, finite) comm_semiring_0 ..
   8.205 -instance vec :: (cancel_comm_monoid_add, finite) cancel_comm_monoid_add ..
   8.206 -instance vec :: (semiring_0_cancel, finite) semiring_0_cancel ..
   8.207 -instance vec :: (comm_semiring_0_cancel, finite) comm_semiring_0_cancel ..
   8.208 -instance vec :: (ring, finite) ring ..
   8.209 -instance vec :: (semiring_1_cancel, finite) semiring_1_cancel ..
   8.210 -instance vec :: (comm_semiring_1, finite) comm_semiring_1 ..
   8.211 -
   8.212 -instance vec :: (ring_1, finite) ring_1 ..
   8.213 -
   8.214 -instance vec :: (real_algebra, finite) real_algebra
   8.215 -  by standard (simp_all add: vec_eq_iff)
   8.216 -
   8.217 -instance vec :: (real_algebra_1, finite) real_algebra_1 ..
   8.218 -
   8.219 -lemma of_nat_index: "(of_nat n :: 'a::semiring_1 ^'n)$i = of_nat n"
   8.220 -proof (induct n)
   8.221 -  case 0
   8.222 -  then show ?case by vector
   8.223 -next
   8.224 -  case Suc
   8.225 -  then show ?case by vector
   8.226 -qed
   8.227 -
   8.228 -lemma one_index [simp]: "(1 :: 'a :: one ^ 'n) $ i = 1"
   8.229 -  by vector
   8.230 -
   8.231 -lemma neg_one_index [simp]: "(- 1 :: 'a :: {one, uminus} ^ 'n) $ i = - 1"
   8.232 -  by vector
   8.233 -
   8.234 -instance vec :: (semiring_char_0, finite) semiring_char_0
   8.235 -proof
   8.236 -  fix m n :: nat
   8.237 -  show "inj (of_nat :: nat \<Rightarrow> 'a ^ 'b)"
   8.238 -    by (auto intro!: injI simp add: vec_eq_iff of_nat_index)
   8.239 -qed
   8.240 -
   8.241 -instance vec :: (numeral, finite) numeral ..
   8.242 -instance vec :: (semiring_numeral, finite) semiring_numeral ..
   8.243 -
   8.244 -lemma numeral_index [simp]: "numeral w $ i = numeral w"
   8.245 -  by (induct w) (simp_all only: numeral.simps vector_add_component one_index)
   8.246 -
   8.247 -lemma neg_numeral_index [simp]: "- numeral w $ i = - numeral w"
   8.248 -  by (simp only: vector_uminus_component numeral_index)
   8.249 -
   8.250 -instance vec :: (comm_ring_1, finite) comm_ring_1 ..
   8.251 -instance vec :: (ring_char_0, finite) ring_char_0 ..
   8.252 -
   8.253 -lemma vector_smult_assoc: "a *s (b *s x) = ((a::'a::semigroup_mult) * b) *s x"
   8.254 -  by (vector mult.assoc)
   8.255 -lemma vector_sadd_rdistrib: "((a::'a::semiring) + b) *s x = a *s x + b *s x"
   8.256 -  by (vector field_simps)
   8.257 -lemma vector_add_ldistrib: "(c::'a::semiring) *s (x + y) = c *s x + c *s y"
   8.258 -  by (vector field_simps)
   8.259 -lemma vector_smult_lzero[simp]: "(0::'a::mult_zero) *s x = 0" by vector
   8.260 -lemma vector_smult_lid[simp]: "(1::'a::monoid_mult) *s x = x" by vector
   8.261 -lemma vector_ssub_ldistrib: "(c::'a::ring) *s (x - y) = c *s x - c *s y"
   8.262 -  by (vector field_simps)
   8.263 -lemma vector_smult_rneg: "(c::'a::ring) *s -x = -(c *s x)" by vector
   8.264 -lemma vector_smult_lneg: "- (c::'a::ring) *s x = -(c *s x)" by vector
   8.265 -lemma vector_sneg_minus1: "-x = (-1::'a::ring_1) *s x" by vector
   8.266 -lemma vector_smult_rzero[simp]: "c *s 0 = (0::'a::mult_zero ^ 'n)" by vector
   8.267 -lemma vector_sub_rdistrib: "((a::'a::ring) - b) *s x = a *s x - b *s x"
   8.268 -  by (vector field_simps)
   8.269 -
   8.270 -lemma vec_eq[simp]: "(vec m = vec n) \<longleftrightarrow> (m = n)"
   8.271 -  by (simp add: vec_eq_iff)
   8.272 -
   8.273 -lemma linear_vec [simp]: "linear vec"
   8.274 -  by (simp add: linearI vec_add vec_eq_iff)
   8.275 -
   8.276  lemma differentiable_vec:
   8.277    fixes S :: "'a::euclidean_space set"
   8.278    shows "vec differentiable_on S"
   8.279 @@ -296,73 +41,6 @@
   8.280          "box (vec a) (vec b) = {} \<longleftrightarrow> box a b = {}"
   8.281    by (auto simp: Basis_vec_def mem_box box_eq_empty inner_axis)
   8.282  
   8.283 -lemma norm_eq_0_imp: "norm x = 0 ==> x = (0::real ^'n)" by (metis norm_eq_zero)
   8.284 -
   8.285 -lemma norm_axis_1 [simp]: "norm (axis m (1::real)) = 1"
   8.286 -  by (simp add: inner_axis' norm_eq_1)
   8.287 -
   8.288 -lemma vector_mul_eq_0[simp]: "(a *s x = 0) \<longleftrightarrow> a = (0::'a::idom) \<or> x = 0"
   8.289 -  by vector
   8.290 -
   8.291 -lemma vector_mul_lcancel[simp]: "a *s x = a *s y \<longleftrightarrow> a = (0::real) \<or> x = y"
   8.292 -  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_ssub_ldistrib)
   8.293 -
   8.294 -lemma vector_mul_rcancel[simp]: "a *s x = b *s x \<longleftrightarrow> (a::real) = b \<or> x = 0"
   8.295 -  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_sub_rdistrib)
   8.296 -
   8.297 -lemma vector_mul_lcancel_imp: "a \<noteq> (0::real) ==>  a *s x = a *s y ==> (x = y)"
   8.298 -  by (metis vector_mul_lcancel)
   8.299 -
   8.300 -lemma vector_mul_rcancel_imp: "x \<noteq> 0 \<Longrightarrow> (a::real) *s x = b *s x ==> a = b"
   8.301 -  by (metis vector_mul_rcancel)
   8.302 -
   8.303 -lemma component_le_norm_cart: "\<bar>x$i\<bar> \<le> norm x"
   8.304 -  apply (simp add: norm_vec_def)
   8.305 -  apply (rule member_le_L2_set, simp_all)
   8.306 -  done
   8.307 -
   8.308 -lemma norm_bound_component_le_cart: "norm x \<le> e ==> \<bar>x$i\<bar> \<le> e"
   8.309 -  by (metis component_le_norm_cart order_trans)
   8.310 -
   8.311 -lemma norm_bound_component_lt_cart: "norm x < e ==> \<bar>x$i\<bar> < e"
   8.312 -  by (metis component_le_norm_cart le_less_trans)
   8.313 -
   8.314 -lemma norm_le_l1_cart: "norm x \<le> sum(\<lambda>i. \<bar>x$i\<bar>) UNIV"
   8.315 -  by (simp add: norm_vec_def L2_set_le_sum)
   8.316 -
   8.317 -lemma scalar_mult_eq_scaleR [simp]: "c *s x = c *\<^sub>R x"
   8.318 -  unfolding scaleR_vec_def vector_scalar_mult_def by simp
   8.319 -
   8.320 -lemma dist_mul[simp]: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y"
   8.321 -  unfolding dist_norm scalar_mult_eq_scaleR
   8.322 -  unfolding scaleR_right_diff_distrib[symmetric] by simp
   8.323 -
   8.324 -lemma sum_component [simp]:
   8.325 -  fixes f:: " 'a \<Rightarrow> ('b::comm_monoid_add) ^'n"
   8.326 -  shows "(sum f S)$i = sum (\<lambda>x. (f x)$i) S"
   8.327 -proof (cases "finite S")
   8.328 -  case True
   8.329 -  then show ?thesis by induct simp_all
   8.330 -next
   8.331 -  case False
   8.332 -  then show ?thesis by simp
   8.333 -qed
   8.334 -
   8.335 -lemma sum_eq: "sum f S = (\<chi> i. sum (\<lambda>x. (f x)$i ) S)"
   8.336 -  by (simp add: vec_eq_iff)
   8.337 -
   8.338 -lemma sum_cmul:
   8.339 -  fixes f:: "'c \<Rightarrow> ('a::semiring_1)^'n"
   8.340 -  shows "sum (\<lambda>x. c *s f x) S = c *s sum f S"
   8.341 -  by (simp add: vec_eq_iff sum_distrib_left)
   8.342 -
   8.343 -lemma sum_norm_allsubsets_bound_cart:
   8.344 -  fixes f:: "'a \<Rightarrow> real ^'n"
   8.345 -  assumes fP: "finite P" and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (sum f Q) \<le> e"
   8.346 -  shows "sum (\<lambda>x. norm (f x)) P \<le> 2 * real CARD('n) *  e"
   8.347 -  using sum_norm_allsubsets_bound[OF assms]
   8.348 -  by simp
   8.349 -
   8.350  subsection\<open>Closures and interiors of halfspaces\<close>
   8.351  
   8.352  lemma interior_halfspace_le [simp]:
   8.353 @@ -497,270 +175,50 @@
   8.354      by force
   8.355  qed
   8.356  
   8.357 -subsection \<open>Matrix operations\<close>
   8.358 -
   8.359 -text\<open>Matrix notation. NB: an MxN matrix is of type @{typ "'a^'n^'m"}, not @{typ "'a^'m^'n"}\<close>
   8.360 -
   8.361 -definition map_matrix::"('a \<Rightarrow> 'b) \<Rightarrow> (('a, 'i::finite)vec, 'j::finite) vec \<Rightarrow> (('b, 'i)vec, 'j) vec" where
   8.362 -  "map_matrix f x = (\<chi> i j. f (x $ i $ j))"
   8.363 -
   8.364 -lemma nth_map_matrix[simp]: "map_matrix f x $ i $ j = f (x $ i $ j)"
   8.365 -  by (simp add: map_matrix_def)
   8.366 -
   8.367 -definition matrix_matrix_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'p^'n \<Rightarrow> 'a ^ 'p ^'m"
   8.368 -    (infixl "**" 70)
   8.369 -  where "m ** m' == (\<chi> i j. sum (\<lambda>k. ((m$i)$k) * ((m'$k)$j)) (UNIV :: 'n set)) ::'a ^ 'p ^'m"
   8.370 -
   8.371 -definition matrix_vector_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n \<Rightarrow> 'a ^ 'm"
   8.372 -    (infixl "*v" 70)
   8.373 -  where "m *v x \<equiv> (\<chi> i. sum (\<lambda>j. ((m$i)$j) * (x$j)) (UNIV ::'n set)) :: 'a^'m"
   8.374 -
   8.375 -definition vector_matrix_mult :: "'a ^ 'm \<Rightarrow> ('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n "
   8.376 -    (infixl "v*" 70)
   8.377 -  where "v v* m == (\<chi> j. sum (\<lambda>i. ((m$i)$j) * (v$i)) (UNIV :: 'm set)) :: 'a^'n"
   8.378 -
   8.379 -definition "(mat::'a::zero => 'a ^'n^'n) k = (\<chi> i j. if i = j then k else 0)"
   8.380 -definition transpose where
   8.381 -  "(transpose::'a^'n^'m \<Rightarrow> 'a^'m^'n) A = (\<chi> i j. ((A$j)$i))"
   8.382 -definition "(row::'m => 'a ^'n^'m \<Rightarrow> 'a ^'n) i A = (\<chi> j. ((A$i)$j))"
   8.383 -definition "(column::'n =>'a^'n^'m =>'a^'m) j A = (\<chi> i. ((A$i)$j))"
   8.384 -definition "rows(A::'a^'n^'m) = { row i A | i. i \<in> (UNIV :: 'm set)}"
   8.385 -definition "columns(A::'a^'n^'m) = { column i A | i. i \<in> (UNIV :: 'n set)}"
   8.386 -
   8.387 -lemma mat_0[simp]: "mat 0 = 0" by (vector mat_def)
   8.388 -lemma matrix_add_ldistrib: "(A ** (B + C)) = (A ** B) + (A ** C)"
   8.389 -  by (vector matrix_matrix_mult_def sum.distrib[symmetric] field_simps)
   8.390 -
   8.391 -lemma matrix_mul_lid [simp]:
   8.392 -  fixes A :: "'a::semiring_1 ^ 'm ^ 'n"
   8.393 -  shows "mat 1 ** A = A"
   8.394 -  apply (simp add: matrix_matrix_mult_def mat_def)
   8.395 -  apply vector
   8.396 -  apply (auto simp only: if_distrib cond_application_beta sum.delta'[OF finite]
   8.397 -    mult_1_left mult_zero_left if_True UNIV_I)
   8.398 -  done
   8.399 -
   8.400 -lemma matrix_mul_rid [simp]:
   8.401 -  fixes A :: "'a::semiring_1 ^ 'm ^ 'n"
   8.402 -  shows "A ** mat 1 = A"
   8.403 -  apply (simp add: matrix_matrix_mult_def mat_def)
   8.404 -  apply vector
   8.405 -  apply (auto simp only: if_distrib cond_application_beta sum.delta[OF finite]
   8.406 -    mult_1_right mult_zero_right if_True UNIV_I cong: if_cong)
   8.407 -  done
   8.408 -
   8.409 -lemma matrix_mul_assoc: "A ** (B ** C) = (A ** B) ** C"
   8.410 -  apply (vector matrix_matrix_mult_def sum_distrib_left sum_distrib_right mult.assoc)
   8.411 -  apply (subst sum.swap)
   8.412 -  apply simp
   8.413 -  done
   8.414 -
   8.415 -lemma matrix_vector_mul_assoc: "A *v (B *v x) = (A ** B) *v x"
   8.416 -  apply (vector matrix_matrix_mult_def matrix_vector_mult_def
   8.417 -    sum_distrib_left sum_distrib_right mult.assoc)
   8.418 -  apply (subst sum.swap)
   8.419 -  apply simp
   8.420 -  done
   8.421 -
   8.422 -lemma matrix_vector_mul_lid [simp]: "mat 1 *v x = (x::'a::semiring_1 ^ 'n)"
   8.423 -  apply (vector matrix_vector_mult_def mat_def)
   8.424 -  apply (simp add: if_distrib cond_application_beta sum.delta' cong del: if_weak_cong)
   8.425 -  done
   8.426 -
   8.427 -lemma matrix_transpose_mul:
   8.428 -    "transpose(A ** B) = transpose B ** transpose (A::'a::comm_semiring_1^_^_)"
   8.429 -  by (simp add: matrix_matrix_mult_def transpose_def vec_eq_iff mult.commute)
   8.430 -
   8.431 -lemma matrix_eq:
   8.432 -  fixes A B :: "'a::semiring_1 ^ 'n ^ 'm"
   8.433 -  shows "A = B \<longleftrightarrow>  (\<forall>x. A *v x = B *v x)" (is "?lhs \<longleftrightarrow> ?rhs")
   8.434 -  apply auto
   8.435 -  apply (subst vec_eq_iff)
   8.436 -  apply clarify
   8.437 -  apply (clarsimp simp add: matrix_vector_mult_def if_distrib cond_application_beta vec_eq_iff cong del: if_weak_cong)
   8.438 -  apply (erule_tac x="axis ia 1" in allE)
   8.439 -  apply (erule_tac x="i" in allE)
   8.440 -  apply (auto simp add: if_distrib cond_application_beta axis_def
   8.441 -    sum.delta[OF finite] cong del: if_weak_cong)
   8.442 -  done
   8.443 -
   8.444 -lemma matrix_vector_mul_component: "((A::real^_^_) *v x)$k = (A$k) \<bullet> x"
   8.445 -  by (simp add: matrix_vector_mult_def inner_vec_def)
   8.446 -
   8.447 -lemma dot_lmul_matrix: "((x::real ^_) v* A) \<bullet> y = x \<bullet> (A *v y)"
   8.448 -  apply (simp add: inner_vec_def matrix_vector_mult_def vector_matrix_mult_def sum_distrib_right sum_distrib_left ac_simps)
   8.449 -  apply (subst sum.swap)
   8.450 -  apply simp
   8.451 -  done
   8.452 -
   8.453 -lemma transpose_mat [simp]: "transpose (mat n) = mat n"
   8.454 -  by (vector transpose_def mat_def)
   8.455 -
   8.456 -lemma transpose_transpose [simp]: "transpose(transpose A) = A"
   8.457 -  by (vector transpose_def)
   8.458 -
   8.459 -lemma row_transpose [simp]:
   8.460 -  fixes A:: "'a::semiring_1^_^_"
   8.461 -  shows "row i (transpose A) = column i A"
   8.462 -  by (simp add: row_def column_def transpose_def vec_eq_iff)
   8.463 -
   8.464 -lemma column_transpose [simp]:
   8.465 -  fixes A:: "'a::semiring_1^_^_"
   8.466 -  shows "column i (transpose A) = row i A"
   8.467 -  by (simp add: row_def column_def transpose_def vec_eq_iff)
   8.468 -
   8.469 -lemma rows_transpose [simp]: "rows(transpose (A::'a::semiring_1^_^_)) = columns A"
   8.470 -  by (auto simp add: rows_def columns_def row_transpose intro: set_eqI)
   8.471 -
   8.472 -lemma columns_transpose [simp]: "columns(transpose (A::'a::semiring_1^_^_)) = rows A"
   8.473 -  by (metis transpose_transpose rows_transpose)
   8.474 -
   8.475  lemma matrix_mult_transpose_dot_column:
   8.476    fixes A :: "real^'n^'n"
   8.477 -  shows "transpose A ** A = (\<chi> i j. (column i A) \<bullet> (column j A))"
   8.478 +  shows "transpose A ** A = (\<chi> i j. inner (column i A) (column j A))"
   8.479    by (simp add: matrix_matrix_mult_def vec_eq_iff transpose_def column_def inner_vec_def)
   8.480  
   8.481  lemma matrix_mult_transpose_dot_row:
   8.482    fixes A :: "real^'n^'n"
   8.483 -  shows "A ** transpose A = (\<chi> i j. (row i A) \<bullet> (row j A))"
   8.484 +  shows "A ** transpose A = (\<chi> i j. inner (row i A) (row j A))"
   8.485    by (simp add: matrix_matrix_mult_def vec_eq_iff transpose_def row_def inner_vec_def)
   8.486  
   8.487  text\<open>Two sometimes fruitful ways of looking at matrix-vector multiplication.\<close>
   8.488  
   8.489 -lemma matrix_mult_dot: "A *v x = (\<chi> i. A$i \<bullet> x)"
   8.490 +lemma matrix_mult_dot: "A *v x = (\<chi> i. inner (A$i) x)"
   8.491    by (simp add: matrix_vector_mult_def inner_vec_def)
   8.492  
   8.493 -lemma matrix_mult_sum:
   8.494 -  "(A::'a::comm_semiring_1^'n^'m) *v x = sum (\<lambda>i. (x$i) *s column i A) (UNIV:: 'n set)"
   8.495 -  by (simp add: matrix_vector_mult_def vec_eq_iff column_def mult.commute)
   8.496 -
   8.497 -lemma vector_componentwise:
   8.498 -  "(x::'a::ring_1^'n) = (\<chi> j. \<Sum>i\<in>UNIV. (x$i) * (axis i 1 :: 'a^'n) $ j)"
   8.499 -  by (simp add: axis_def if_distrib sum.If_cases vec_eq_iff)
   8.500 -
   8.501 -lemma basis_expansion: "sum (\<lambda>i. (x$i) *s axis i 1) UNIV = (x::('a::ring_1) ^'n)"
   8.502 -  by (auto simp add: axis_def vec_eq_iff if_distrib sum.If_cases cong del: if_weak_cong)
   8.503 -
   8.504 -lemma linear_componentwise_expansion:
   8.505 -  fixes f:: "real ^'m \<Rightarrow> real ^ _"
   8.506 -  assumes lf: "linear f"
   8.507 -  shows "(f x)$j = sum (\<lambda>i. (x$i) * (f (axis i 1)$j)) (UNIV :: 'm set)" (is "?lhs = ?rhs")
   8.508 -proof -
   8.509 -  let ?M = "(UNIV :: 'm set)"
   8.510 -  let ?N = "(UNIV :: 'n set)"
   8.511 -  have "?rhs = (sum (\<lambda>i.(x$i) *\<^sub>R f (axis i 1) ) ?M)$j"
   8.512 -    unfolding sum_component by simp
   8.513 -  then show ?thesis
   8.514 -    unfolding linear_sum_mul[OF lf, symmetric]
   8.515 -    unfolding scalar_mult_eq_scaleR[symmetric]
   8.516 -    unfolding basis_expansion
   8.517 -    by simp
   8.518 -qed
   8.519 -
   8.520 -subsection\<open>Inverse matrices  (not necessarily square)\<close>
   8.521 -
   8.522 -definition
   8.523 -  "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
   8.524 -
   8.525 -definition
   8.526 -  "matrix_inv(A:: 'a::semiring_1^'n^'m) =
   8.527 -    (SOME A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
   8.528 -
   8.529 -text\<open>Correspondence between matrices and linear operators.\<close>
   8.530 -
   8.531 -definition matrix :: "('a::{plus,times, one, zero}^'m \<Rightarrow> 'a ^ 'n) \<Rightarrow> 'a^'m^'n"
   8.532 -  where "matrix f = (\<chi> i j. (f(axis j 1))$i)"
   8.533 -
   8.534 -lemma matrix_id_mat_1: "matrix id = mat 1"
   8.535 -  by (simp add: mat_def matrix_def axis_def)
   8.536 -
   8.537 -lemma matrix_scaleR: "(matrix (( *\<^sub>R) r)) = mat r"
   8.538 -  by (simp add: mat_def matrix_def axis_def if_distrib cong: if_cong)
   8.539 -
   8.540 -lemma matrix_vector_mul_linear: "linear(\<lambda>x. A *v (x::real ^ _))"
   8.541 -  by (simp add: linear_iff matrix_vector_mult_def vec_eq_iff
   8.542 -      field_simps sum_distrib_left sum.distrib)
   8.543 -
   8.544 -lemma
   8.545 -  fixes A :: "real^'n^'m"
   8.546 -  shows matrix_vector_mult_linear_continuous_at [continuous_intros]: "isCont (( *v) A) z"
   8.547 -    and matrix_vector_mult_linear_continuous_on [continuous_intros]: "continuous_on S (( *v) A)"
   8.548 -  by (simp_all add: linear_linear linear_continuous_at linear_continuous_on matrix_vector_mul_linear)
   8.549 -
   8.550 -lemma matrix_vector_mult_add_distrib [algebra_simps]:
   8.551 -  "A *v (x + y) = A *v x + A *v y"
   8.552 -  by (vector matrix_vector_mult_def sum.distrib distrib_left)
   8.553 -
   8.554 -lemma matrix_vector_mult_diff_distrib [algebra_simps]:
   8.555 -  fixes A :: "'a::ring_1^'n^'m"
   8.556 -  shows "A *v (x - y) = A *v x - A *v y"
   8.557 -  by (vector matrix_vector_mult_def sum_subtractf right_diff_distrib)
   8.558 -
   8.559 -lemma matrix_vector_mult_scaleR[algebra_simps]:
   8.560 -  fixes A :: "real^'n^'m"
   8.561 -  shows "A *v (c *\<^sub>R x) = c *\<^sub>R (A *v x)"
   8.562 -  using linear_iff matrix_vector_mul_linear by blast
   8.563 -
   8.564 -lemma matrix_vector_mult_0_right [simp]: "A *v 0 = 0"
   8.565 -  by (simp add: matrix_vector_mult_def vec_eq_iff)
   8.566 -
   8.567 -lemma matrix_vector_mult_0 [simp]: "0 *v w = 0"
   8.568 -  by (simp add: matrix_vector_mult_def vec_eq_iff)
   8.569 -
   8.570 -lemma matrix_vector_mult_add_rdistrib [algebra_simps]:
   8.571 -  "(A + B) *v x = (A *v x) + (B *v x)"
   8.572 -  by (vector matrix_vector_mult_def sum.distrib distrib_right)
   8.573 -
   8.574 -lemma matrix_vector_mult_diff_rdistrib [algebra_simps]:
   8.575 -  fixes A :: "'a :: ring_1^'n^'m"
   8.576 -  shows "(A - B) *v x = (A *v x) - (B *v x)"
   8.577 -  by (vector matrix_vector_mult_def sum_subtractf left_diff_distrib)
   8.578 -
   8.579 -lemma matrix_works:
   8.580 -  assumes lf: "linear f"
   8.581 -  shows "matrix f *v x = f (x::real ^ 'n)"
   8.582 -  apply (simp add: matrix_def matrix_vector_mult_def vec_eq_iff mult.commute)
   8.583 -  by (simp add: linear_componentwise_expansion lf)
   8.584 -
   8.585 -lemma matrix_vector_mul: "linear f ==> f = (\<lambda>x. matrix f *v (x::real ^ 'n))"
   8.586 -  by (simp add: ext matrix_works)
   8.587 -
   8.588 -declare matrix_vector_mul [symmetric, simp]
   8.589 -
   8.590 -lemma matrix_of_matrix_vector_mul [simp]: "matrix(\<lambda>x. A *v (x :: real ^ 'n)) = A"
   8.591 -  by (simp add: matrix_eq matrix_vector_mul_linear matrix_works)
   8.592 -
   8.593 -lemma matrix_compose:
   8.594 -  assumes lf: "linear (f::real^'n \<Rightarrow> real^'m)"
   8.595 -    and lg: "linear (g::real^'m \<Rightarrow> real^_)"
   8.596 -  shows "matrix (g \<circ> f) = matrix g ** matrix f"
   8.597 -  using lf lg linear_compose[OF lf lg] matrix_works[OF linear_compose[OF lf lg]]
   8.598 -  by (simp add: matrix_eq matrix_works matrix_vector_mul_assoc[symmetric] o_def)
   8.599 -
   8.600 -lemma matrix_vector_column:
   8.601 -  "(A::'a::comm_semiring_1^'n^_) *v x = sum (\<lambda>i. (x$i) *s ((transpose A)$i)) (UNIV:: 'n set)"
   8.602 -  by (simp add: matrix_vector_mult_def transpose_def vec_eq_iff mult.commute)
   8.603 -
   8.604  lemma adjoint_matrix: "adjoint(\<lambda>x. (A::real^'n^'m) *v x) = (\<lambda>x. transpose A *v x)"
   8.605    apply (rule adjoint_unique)
   8.606    apply (simp add: transpose_def inner_vec_def matrix_vector_mult_def
   8.607      sum_distrib_right sum_distrib_left)
   8.608    apply (subst sum.swap)
   8.609 -  apply (auto simp add: ac_simps)
   8.610 +  apply (simp add:  ac_simps)
   8.611    done
   8.612  
   8.613  lemma matrix_adjoint: assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'m)"
   8.614    shows "matrix(adjoint f) = transpose(matrix f)"
   8.615 -  apply (subst matrix_vector_mul[OF lf])
   8.616 -  unfolding adjoint_matrix matrix_of_matrix_vector_mul
   8.617 -  apply rule
   8.618 -  done
   8.619 +proof -
   8.620 +  have "matrix(adjoint f) = matrix(adjoint (( *v) (matrix f)))"
   8.621 +    by (simp add: lf)
   8.622 +  also have "\<dots> = transpose(matrix f)"
   8.623 +    unfolding adjoint_matrix matrix_of_matrix_vector_mul
   8.624 +    apply rule
   8.625 +    done
   8.626 +  finally show ?thesis .
   8.627 +qed
   8.628  
   8.629 -lemma inj_matrix_vector_mult:
   8.630 -  fixes A::"'a::field^'n^'m"
   8.631 -  assumes "invertible A"
   8.632 -  shows "inj (( *v) A)"
   8.633 -  by (metis assms inj_on_inverseI invertible_def matrix_vector_mul_assoc matrix_vector_mul_lid)
   8.634 +lemma matrix_vector_mul_bounded_linear[intro, simp]: "bounded_linear (( *v) A)" for A :: "real^'n^'m"
   8.635 +  using matrix_vector_mul_linear[of A]
   8.636 +  by (simp add: linear_conv_bounded_linear linear_matrix_vector_mul_eq)
   8.637 +
   8.638 +lemma
   8.639 +  fixes A :: "real^'n^'m"
   8.640 +  shows matrix_vector_mult_linear_continuous_at [continuous_intros]: "isCont (( *v) A) z"
   8.641 +    and matrix_vector_mult_linear_continuous_on [continuous_intros]: "continuous_on S (( *v) A)"
   8.642 +  by (simp_all add: linear_continuous_at linear_continuous_on)
   8.643  
   8.644  
   8.645  subsection\<open>Some bounds on components etc. relative to operator norm\<close>
   8.646 @@ -769,12 +227,10 @@
   8.647    fixes A :: "real^'n^'m"
   8.648    shows "norm(column i A) \<le> onorm(( *v) A)"
   8.649  proof -
   8.650 -  have bl: "bounded_linear (( *v) A)"
   8.651 -    by (simp add: linear_linear matrix_vector_mul_linear)
   8.652    have "norm (\<chi> j. A $ j $ i) \<le> norm (A *v axis i 1)"
   8.653      by (simp add: matrix_mult_dot cart_eq_inner_axis)
   8.654    also have "\<dots> \<le> onorm (( *v) A)"
   8.655 -    using onorm [OF bl, of "axis i 1"] by auto
   8.656 +    using onorm [OF matrix_vector_mul_bounded_linear, of A "axis i 1"] by auto
   8.657    finally have "norm (\<chi> j. A $ j $ i) \<le> onorm (( *v) A)" .
   8.658    then show ?thesis
   8.659      unfolding column_def .
   8.660 @@ -794,7 +250,7 @@
   8.661  lemma component_le_onorm:
   8.662    fixes f :: "real^'m \<Rightarrow> real^'n"
   8.663    shows "linear f \<Longrightarrow> \<bar>matrix f $ i $ j\<bar> \<le> onorm f"
   8.664 -  by (metis matrix_component_le_onorm matrix_vector_mul)
   8.665 +  by (metis linear_matrix_vector_mul_eq matrix_component_le_onorm matrix_vector_mul)
   8.666  
   8.667  lemma onorm_le_matrix_component_sum:
   8.668    fixes A :: "real^'n^'m"
   8.669 @@ -892,16 +348,8 @@
   8.670  lemma vector_sub_project_orthogonal_cart: "(b::real^'n) \<bullet> (x - ((b \<bullet> x) / (b \<bullet> b)) *s b) = 0"
   8.671    unfolding inner_simps scalar_mult_eq_scaleR by auto
   8.672  
   8.673 -lemma left_invertible_transpose:
   8.674 -  "(\<exists>(B). B ** transpose (A) = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). A ** B = mat 1)"
   8.675 -  by (metis matrix_transpose_mul transpose_mat transpose_transpose)
   8.676 -
   8.677 -lemma right_invertible_transpose:
   8.678 -  "(\<exists>(B). transpose (A) ** B = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). B ** A = mat 1)"
   8.679 -  by (metis matrix_transpose_mul transpose_mat transpose_transpose)
   8.680 -
   8.681  lemma matrix_left_invertible_injective:
   8.682 -  fixes A :: "real^'n^'m"
   8.683 +  fixes A :: "'a::field^'n^'m"
   8.684    shows "(\<exists>B. B ** A = mat 1) \<longleftrightarrow> inj (( *v) A)"
   8.685  proof safe
   8.686    fix B
   8.687 @@ -911,34 +359,29 @@
   8.688        by (metis B matrix_vector_mul_assoc matrix_vector_mul_lid)
   8.689  next
   8.690    assume "inj (( *v) A)"
   8.691 -  with linear_injective_left_inverse[OF matrix_vector_mul_linear]
   8.692 -  obtain g where "linear g" and g: "g \<circ> ( *v) A = id"
   8.693 +  from vec.linear_injective_left_inverse[OF matrix_vector_mul_linear_gen this]
   8.694 +  obtain g where "Vector_Spaces.linear ( *s) ( *s) g" and g: "g \<circ> ( *v) A = id"
   8.695      by blast
   8.696    have "matrix g ** A = mat 1"
   8.697 -    by (metis \<open>linear g\<close> g matrix_compose matrix_id_mat_1 matrix_of_matrix_vector_mul matrix_vector_mul_linear)
   8.698 +    by (metis matrix_vector_mul_linear_gen \<open>Vector_Spaces.linear ( *s) ( *s) g\<close> g matrix_compose_gen
   8.699 +        matrix_eq matrix_id_mat_1 matrix_vector_mul(1))
   8.700    then show "\<exists>B. B ** A = mat 1"
   8.701      by metis
   8.702  qed
   8.703  
   8.704 -lemma matrix_left_invertible_ker:
   8.705 -  "(\<exists>B. (B::real ^'m^'n) ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x. A *v x = 0 \<longrightarrow> x = 0)"
   8.706 -  unfolding matrix_left_invertible_injective
   8.707 -  using linear_injective_0[OF matrix_vector_mul_linear, of A]
   8.708 -  by (simp add: inj_on_def)
   8.709 -
   8.710  lemma matrix_right_invertible_surjective:
   8.711 -  "(\<exists>B. (A::real^'n^'m) ** (B::real^'m^'n) = mat 1) \<longleftrightarrow> surj (\<lambda>x. A *v x)"
   8.712 +  "(\<exists>B. (A::'a::field^'n^'m) ** (B::'a::field^'m^'n) = mat 1) \<longleftrightarrow> surj (\<lambda>x. A *v x)"
   8.713  proof -
   8.714 -  { fix B :: "real ^'m^'n"
   8.715 +  { fix B :: "'a ^'m^'n"
   8.716      assume AB: "A ** B = mat 1"
   8.717 -    { fix x :: "real ^ 'm"
   8.718 +    { fix x :: "'a ^ 'm"
   8.719        have "A *v (B *v x) = x"
   8.720 -        by (simp add: matrix_vector_mul_lid matrix_vector_mul_assoc AB) }
   8.721 +        by (simp add: matrix_vector_mul_assoc AB) }
   8.722      hence "surj (( *v) A)" unfolding surj_def by metis }
   8.723    moreover
   8.724    { assume sf: "surj (( *v) A)"
   8.725 -    from linear_surjective_right_inverse[OF matrix_vector_mul_linear sf]
   8.726 -    obtain g:: "real ^'m \<Rightarrow> real ^'n" where g: "linear g" "( *v) A \<circ> g = id"
   8.727 +    from vec.linear_surjective_right_inverse[OF _ this]
   8.728 +    obtain g:: "'a ^'m \<Rightarrow> 'a ^'n" where g: "Vector_Spaces.linear ( *s) ( *s) g" "( *v) A \<circ> g = id"
   8.729        by blast
   8.730  
   8.731      have "A ** (matrix g) = mat 1"
   8.732 @@ -946,69 +389,32 @@
   8.733          matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)]
   8.734        using g(2) unfolding o_def fun_eq_iff id_def
   8.735        .
   8.736 -    hence "\<exists>B. A ** (B::real^'m^'n) = mat 1" by blast
   8.737 +    hence "\<exists>B. A ** (B::'a^'m^'n) = mat 1" by blast
   8.738    }
   8.739    ultimately show ?thesis unfolding surj_def by blast
   8.740  qed
   8.741  
   8.742 -lemma matrix_left_invertible_independent_columns:
   8.743 -  fixes A :: "real^'n^'m"
   8.744 -  shows "(\<exists>(B::real ^'m^'n). B ** A = mat 1) \<longleftrightarrow>
   8.745 -      (\<forall>c. sum (\<lambda>i. c i *s column i A) (UNIV :: 'n set) = 0 \<longrightarrow> (\<forall>i. c i = 0))"
   8.746 -    (is "?lhs \<longleftrightarrow> ?rhs")
   8.747 -proof -
   8.748 -  let ?U = "UNIV :: 'n set"
   8.749 -  { assume k: "\<forall>x. A *v x = 0 \<longrightarrow> x = 0"
   8.750 -    { fix c i
   8.751 -      assume c: "sum (\<lambda>i. c i *s column i A) ?U = 0" and i: "i \<in> ?U"
   8.752 -      let ?x = "\<chi> i. c i"
   8.753 -      have th0:"A *v ?x = 0"
   8.754 -        using c
   8.755 -        unfolding matrix_mult_sum vec_eq_iff
   8.756 -        by auto
   8.757 -      from k[rule_format, OF th0] i
   8.758 -      have "c i = 0" by (vector vec_eq_iff)}
   8.759 -    hence ?rhs by blast }
   8.760 -  moreover
   8.761 -  { assume H: ?rhs
   8.762 -    { fix x assume x: "A *v x = 0"
   8.763 -      let ?c = "\<lambda>i. ((x$i ):: real)"
   8.764 -      from H[rule_format, of ?c, unfolded matrix_mult_sum[symmetric], OF x]
   8.765 -      have "x = 0" by vector }
   8.766 -  }
   8.767 -  ultimately show ?thesis unfolding matrix_left_invertible_ker by blast
   8.768 -qed
   8.769 -
   8.770 -lemma matrix_right_invertible_independent_rows:
   8.771 -  fixes A :: "real^'n^'m"
   8.772 -  shows "(\<exists>(B::real^'m^'n). A ** B = mat 1) \<longleftrightarrow>
   8.773 -    (\<forall>c. sum (\<lambda>i. c i *s row i A) (UNIV :: 'm set) = 0 \<longrightarrow> (\<forall>i. c i = 0))"
   8.774 -  unfolding left_invertible_transpose[symmetric]
   8.775 -    matrix_left_invertible_independent_columns
   8.776 -  by (simp add: column_transpose)
   8.777 -
   8.778  lemma matrix_right_invertible_span_columns:
   8.779 -  "(\<exists>(B::real ^'n^'m). (A::real ^'m^'n) ** B = mat 1) \<longleftrightarrow>
   8.780 -    span (columns A) = UNIV" (is "?lhs = ?rhs")
   8.781 +  "(\<exists>(B::'a::field ^'n^'m). (A::'a ^'m^'n) ** B = mat 1) \<longleftrightarrow>
   8.782 +    vec.span (columns A) = UNIV" (is "?lhs = ?rhs")
   8.783  proof -
   8.784    let ?U = "UNIV :: 'm set"
   8.785    have fU: "finite ?U" by simp
   8.786 -  have lhseq: "?lhs \<longleftrightarrow> (\<forall>y. \<exists>(x::real^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y)"
   8.787 +  have lhseq: "?lhs \<longleftrightarrow> (\<forall>y. \<exists>(x::'a^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y)"
   8.788      unfolding matrix_right_invertible_surjective matrix_mult_sum surj_def
   8.789      apply (subst eq_commute)
   8.790      apply rule
   8.791      done
   8.792 -  have rhseq: "?rhs \<longleftrightarrow> (\<forall>x. x \<in> span (columns A))" by blast
   8.793 +  have rhseq: "?rhs \<longleftrightarrow> (\<forall>x. x \<in> vec.span (columns A))" by blast
   8.794    { assume h: ?lhs
   8.795 -    { fix x:: "real ^'n"
   8.796 -      from h[unfolded lhseq, rule_format, of x] obtain y :: "real ^'m"
   8.797 +    { fix x:: "'a ^'n"
   8.798 +      from h[unfolded lhseq, rule_format, of x] obtain y :: "'a ^'m"
   8.799          where y: "sum (\<lambda>i. (y$i) *s column i A) ?U = x" by blast
   8.800 -      have "x \<in> span (columns A)"
   8.801 +      have "x \<in> vec.span (columns A)"
   8.802          unfolding y[symmetric]
   8.803 -        apply (rule span_sum)
   8.804 -        unfolding scalar_mult_eq_scaleR
   8.805 -        apply (rule span_mul)
   8.806 -        apply (rule span_superset)
   8.807 +        apply (rule vec.span_sum)
   8.808 +        apply (rule vec.span_scale)
   8.809 +        apply (rule vec.span_base)
   8.810          unfolding columns_def
   8.811          apply blast
   8.812          done
   8.813 @@ -1016,22 +422,24 @@
   8.814      then have ?rhs unfolding rhseq by blast }
   8.815    moreover
   8.816    { assume h:?rhs
   8.817 -    let ?P = "\<lambda>(y::real ^'n). \<exists>(x::real^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y"
   8.818 +    let ?P = "\<lambda>(y::'a ^'n). \<exists>(x::'a^'m). sum (\<lambda>i. (x$i) *s column i A) ?U = y"
   8.819      { fix y
   8.820 -      have "?P y"
   8.821 -      proof (rule span_induct_alt[of ?P "columns A", folded scalar_mult_eq_scaleR])
   8.822 -        show "\<exists>x::real ^ 'm. sum (\<lambda>i. (x$i) *s column i A) ?U = 0"
   8.823 +      have "y \<in> vec.span (columns A)"
   8.824 +        unfolding h by blast
   8.825 +      then have "?P y"
   8.826 +      proof (induction rule: vec.span_induct_alt)
   8.827 +        show "\<exists>x::'a ^ 'm. sum (\<lambda>i. (x$i) *s column i A) ?U = 0"
   8.828            by (rule exI[where x=0], simp)
   8.829        next
   8.830          fix c y1 y2
   8.831          assume y1: "y1 \<in> columns A" and y2: "?P y2"
   8.832          from y1 obtain i where i: "i \<in> ?U" "y1 = column i A"
   8.833            unfolding columns_def by blast
   8.834 -        from y2 obtain x:: "real ^'m" where
   8.835 +        from y2 obtain x:: "'a ^'m" where
   8.836            x: "sum (\<lambda>i. (x$i) *s column i A) ?U = y2" by blast
   8.837 -        let ?x = "(\<chi> j. if j = i then c + (x$i) else (x$j))::real^'m"
   8.838 +        let ?x = "(\<chi> j. if j = i then c + (x$i) else (x$j))::'a^'m"
   8.839          show "?P (c*s y1 + y2)"
   8.840 -        proof (rule exI[where x= "?x"], vector, auto simp add: i x[symmetric] if_distrib distrib_left cond_application_beta cong del: if_weak_cong)
   8.841 +        proof (rule exI[where x= "?x"], vector, auto simp add: i x[symmetric] if_distrib distrib_left if_distribR cong del: if_weak_cong)
   8.842            fix j
   8.843            have th: "\<forall>xa \<in> ?U. (if xa = i then (c + (x$i)) * ((column xa A)$j)
   8.844                else (x$xa) * ((column xa A$j))) = (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))"
   8.845 @@ -1049,9 +457,6 @@
   8.846            finally show "sum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j)
   8.847              else (x$xa) * ((column xa A$j))) ?U = c * ((column i A)$j) + sum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" .
   8.848          qed
   8.849 -      next
   8.850 -        show "y \<in> span (columns A)"
   8.851 -          unfolding h by blast
   8.852        qed
   8.853      }
   8.854      then have ?lhs unfolding lhseq ..
   8.855 @@ -1059,41 +464,20 @@
   8.856    ultimately show ?thesis by blast
   8.857  qed
   8.858  
   8.859 -lemma matrix_left_invertible_span_rows:
   8.860 -  "(\<exists>(B::real^'m^'n). B ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> span (rows A) = UNIV"
   8.861 +lemma matrix_left_invertible_span_rows_gen:
   8.862 +  "(\<exists>(B::'a^'m^'n). B ** (A::'a::field^'n^'m) = mat 1) \<longleftrightarrow> vec.span (rows A) = UNIV"
   8.863    unfolding right_invertible_transpose[symmetric]
   8.864    unfolding columns_transpose[symmetric]
   8.865    unfolding matrix_right_invertible_span_columns
   8.866    ..
   8.867  
   8.868 +lemma matrix_left_invertible_span_rows:
   8.869 +  "(\<exists>(B::real^'m^'n). B ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> span (rows A) = UNIV"
   8.870 +  using matrix_left_invertible_span_rows_gen[of A] by (simp add: span_vec_eq)
   8.871 +
   8.872 +
   8.873  text \<open>The same result in terms of square matrices.\<close>
   8.874  
   8.875 -lemma matrix_left_right_inverse:
   8.876 -  fixes A A' :: "real ^'n^'n"
   8.877 -  shows "A ** A' = mat 1 \<longleftrightarrow> A' ** A = mat 1"
   8.878 -proof -
   8.879 -  { fix A A' :: "real ^'n^'n"
   8.880 -    assume AA': "A ** A' = mat 1"
   8.881 -    have sA: "surj (( *v) A)"
   8.882 -      unfolding surj_def
   8.883 -      apply clarify
   8.884 -      apply (rule_tac x="(A' *v y)" in exI)
   8.885 -      apply (simp add: matrix_vector_mul_assoc AA' matrix_vector_mul_lid)
   8.886 -      done
   8.887 -    from linear_surjective_isomorphism[OF matrix_vector_mul_linear sA]
   8.888 -    obtain f' :: "real ^'n \<Rightarrow> real ^'n"
   8.889 -      where f': "linear f'" "\<forall>x. f' (A *v x) = x" "\<forall>x. A *v f' x = x" by blast
   8.890 -    have th: "matrix f' ** A = mat 1"
   8.891 -      by (simp add: matrix_eq matrix_works[OF f'(1)]
   8.892 -          matrix_vector_mul_assoc[symmetric] matrix_vector_mul_lid f'(2)[rule_format])
   8.893 -    hence "(matrix f' ** A) ** A' = mat 1 ** A'" by simp
   8.894 -    hence "matrix f' = A'"
   8.895 -      by (simp add: matrix_mul_assoc[symmetric] AA' matrix_mul_rid matrix_mul_lid)
   8.896 -    hence "matrix f' ** A = A' ** A" by simp
   8.897 -    hence "A' ** A = mat 1" by (simp add: th)
   8.898 -  }
   8.899 -  then show ?thesis by blast
   8.900 -qed
   8.901  
   8.902  text \<open>Considering an n-element vector as an n-by-1 or 1-by-n matrix.\<close>
   8.903  
   8.904 @@ -1338,8 +722,8 @@
   8.905    using connected_ivt_hyperplane[of s x y "axis k 1" a]
   8.906    by (auto simp add: inner_axis inner_commute)
   8.907  
   8.908 -lemma subspace_substandard_cart: "subspace {x::real^_. (\<forall>i. P i \<longrightarrow> x$i = 0)}"
   8.909 -  unfolding subspace_def by auto
   8.910 +lemma subspace_substandard_cart: "vec.subspace {x. (\<forall>i. P i \<longrightarrow> x$i = 0)}"
   8.911 +  unfolding vec.subspace_def by auto
   8.912  
   8.913  lemma closed_substandard_cart:
   8.914    "closed {x::'a::real_normed_vector ^ 'n. \<forall>i. P i \<longrightarrow> x$i = 0}"
   8.915 @@ -1351,32 +735,49 @@
   8.916      unfolding Collect_all_eq by (simp add: closed_INT)
   8.917  qed
   8.918  
   8.919 -lemma dim_substandard_cart: "dim {x::real^'n. \<forall>i. i \<notin> d \<longrightarrow> x$i = 0} = card d"
   8.920 -  (is "dim ?A = _")
   8.921 -proof -
   8.922 -  let ?a = "\<lambda>x. axis x 1 :: real^'n"
   8.923 -  have *: "{x. \<forall>i\<in>Basis. i \<notin> ?a ` d \<longrightarrow> x \<bullet> i = 0} = ?A"
   8.924 -    by (auto simp: image_iff Basis_vec_def axis_eq_axis inner_axis)
   8.925 -  have "?a ` d \<subseteq> Basis"
   8.926 -    by (auto simp: Basis_vec_def)
   8.927 -  thus ?thesis
   8.928 -    using dim_substandard[of "?a ` d"] card_image[of ?a d]
   8.929 -    by (auto simp: axis_eq_axis inj_on_def *)
   8.930 -qed
   8.931 +lemma dim_substandard_cart: "vec.dim {x::'a::field^'n. \<forall>i. i \<notin> d \<longrightarrow> x$i = 0} = card d"
   8.932 +  (is "vec.dim ?A = _")
   8.933 +proof (rule vec.dim_unique)
   8.934 +  let ?B = "((\<lambda>x. axis x 1) ` d)"
   8.935 +  have subset_basis: "?B \<subseteq> cart_basis"
   8.936 +    by (auto simp: cart_basis_def)
   8.937 +  show "?B \<subseteq> ?A"
   8.938 +    by (auto simp: axis_def)
   8.939 +  show "vec.independent ((\<lambda>x. axis x 1) ` d)"
   8.940 +    using subset_basis
   8.941 +    by (rule vec.independent_mono[OF vec.independent_Basis])
   8.942 +  have "x \<in> vec.span ?B" if "\<forall>i. i \<notin> d \<longrightarrow> x $ i = 0" for x::"'a^'n"
   8.943 +  proof -
   8.944 +    have "finite ?B"
   8.945 +      using subset_basis finite_cart_basis
   8.946 +      by (rule finite_subset)
   8.947 +    have "x = (\<Sum>i\<in>UNIV. x $ i *s axis i 1)"
   8.948 +      by (rule basis_expansion[symmetric])
   8.949 +    also have "\<dots> = (\<Sum>i\<in>d. (x $ i) *s axis i 1)"
   8.950 +      by (rule sum.mono_neutral_cong_right) (auto simp: that)
   8.951 +    also have "\<dots> \<in> vec.span ?B"
   8.952 +      by (simp add: vec.span_sum vec.span_clauses)
   8.953 +    finally show "x \<in> vec.span ?B" .
   8.954 +  qed
   8.955 +  then show "?A \<subseteq> vec.span ?B" by auto
   8.956 +qed (simp add: card_image inj_on_def axis_eq_axis)
   8.957 +
   8.958 +lemma dim_subset_UNIV_cart_gen:
   8.959 +  fixes S :: "('a::field^'n) set"
   8.960 +  shows "vec.dim S \<le> CARD('n)"
   8.961 +  by (metis vec.dim_eq_full vec.dim_subset_UNIV vec.span_UNIV vec_dim_card)
   8.962  
   8.963  lemma dim_subset_UNIV_cart:
   8.964    fixes S :: "(real^'n) set"
   8.965    shows "dim S \<le> CARD('n)"
   8.966 -  by (metis dim_subset_UNIV DIM_cart DIM_real mult.right_neutral)
   8.967 +  using dim_subset_UNIV_cart_gen[of S] by (simp add: dim_vec_eq)
   8.968  
   8.969  lemma affinity_inverses:
   8.970    assumes m0: "m \<noteq> (0::'a::field)"
   8.971    shows "(\<lambda>x. m *s x + c) \<circ> (\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) = id"
   8.972    "(\<lambda>x. inverse(m) *s x + (-(inverse(m) *s c))) \<circ> (\<lambda>x. m *s x + c) = id"
   8.973    using m0
   8.974 -  apply (auto simp add: fun_eq_iff vector_add_ldistrib diff_conv_add_uminus simp del: add_uminus_conv_diff)
   8.975 -  apply (simp_all add: vector_smult_lneg[symmetric] vector_smult_assoc vector_sneg_minus1 [symmetric])
   8.976 -  done
   8.977 +  by (auto simp add: fun_eq_iff vector_add_ldistrib diff_conv_add_uminus simp del: add_uminus_conv_diff)
   8.978  
   8.979  lemma vector_affinity_eq:
   8.980    assumes m0: "(m::'a::field) \<noteq> 0"
   8.981 @@ -1580,13 +981,18 @@
   8.982  
   8.983  text\<open>Equivalence of row and column rank is taken from George Mackiw's paper, Mathematics Magazine 1995, p. 285.\<close>
   8.984  
   8.985 +lemma matrix_vector_mult_in_columnspace_gen:
   8.986 +  fixes A :: "'a::field^'n^'m"
   8.987 +  shows "(A *v x) \<in> vec.span(columns A)"
   8.988 +  apply (simp add: matrix_vector_column columns_def transpose_def column_def)
   8.989 +  apply (intro vec.span_sum vec.span_scale)
   8.990 +  apply (force intro: vec.span_base)
   8.991 +  done
   8.992 +
   8.993  lemma matrix_vector_mult_in_columnspace:
   8.994    fixes A :: "real^'n^'m"
   8.995    shows "(A *v x) \<in> span(columns A)"
   8.996 -  apply (simp add: matrix_vector_column columns_def transpose_def column_def)
   8.997 -  apply (intro span_sum span_mul)
   8.998 -  apply (force intro: span_superset)
   8.999 -  done
  8.1000 +  using matrix_vector_mult_in_columnspace_gen[of A x] by (simp add: span_vec_eq)
  8.1001  
  8.1002  lemma orthogonal_nullspace_rowspace:
  8.1003    fixes A :: "real^'n^'m"
  8.1004 @@ -1608,16 +1014,20 @@
  8.1005  lemma nullspace_inter_rowspace:
  8.1006    fixes A :: "real^'n^'m"
  8.1007    shows "A *v x = 0 \<and> x \<in> span(rows A) \<longleftrightarrow> x = 0"
  8.1008 -  using orthogonal_nullspace_rowspace orthogonal_self by auto
  8.1009 +  using orthogonal_nullspace_rowspace orthogonal_self span_zero matrix_vector_mult_0_right
  8.1010 +  by blast
  8.1011  
  8.1012  lemma matrix_vector_mul_injective_on_rowspace:
  8.1013    fixes A :: "real^'n^'m"
  8.1014    shows "\<lbrakk>A *v x = A *v y; x \<in> span(rows A); y \<in> span(rows A)\<rbrakk> \<Longrightarrow> x = y"
  8.1015    using nullspace_inter_rowspace [of A "x-y"]
  8.1016 -  by (metis eq_iff_diff_eq_0 matrix_vector_mult_diff_distrib span_diff)
  8.1017 +  by (metis diff_eq_diff_eq diff_self matrix_vector_mult_diff_distrib span_diff)
  8.1018  
  8.1019 -definition rank :: "real^'n^'m=>nat"
  8.1020 -  where "rank A \<equiv> dim(columns A)"
  8.1021 +definition rank :: "'a::field^'n^'m=>nat"
  8.1022 +  where row_rank_def_gen: "rank A \<equiv> vec.dim(rows A)"
  8.1023 +
  8.1024 +lemma row_rank_def: "rank A = dim (rows A)" for A::"real^'n^'m"
  8.1025 +  by (auto simp: row_rank_def_gen dim_vec_eq)
  8.1026  
  8.1027  lemma dim_rows_le_dim_columns:
  8.1028    fixes A :: "real^'n^'m"
  8.1029 @@ -1628,31 +1038,35 @@
  8.1030      obtain B where "independent B" "span(rows A) \<subseteq> span B"
  8.1031                and B: "B \<subseteq> span(rows A)""card B = dim (span(rows A))"
  8.1032        using basis_exists [of "span(rows A)"] by blast
  8.1033 -    with span_subspace have eq: "span B = span(rows A)"
  8.1034 -      by auto
  8.1035 +    then have eq: "span B = span(rows A)"
  8.1036 +      using span_subspace subspace_span by blast
  8.1037      then have inj: "inj_on (( *v) A) (span B)"
  8.1038 -      using inj_on_def matrix_vector_mul_injective_on_rowspace by blast
  8.1039 +      by (simp add: inj_on_def matrix_vector_mul_injective_on_rowspace)
  8.1040      then have ind: "independent (( *v) A ` B)"
  8.1041 -      by (rule independent_inj_on_image [OF \<open>independent B\<close> matrix_vector_mul_linear])
  8.1042 -    then have "finite (( *v) A ` B) \<and> card (( *v) A ` B) \<le> dim (( *v) A ` B)"
  8.1043 -      by (rule independent_bound_general)
  8.1044 -    then show ?thesis
  8.1045 -      by (metis (no_types, lifting) B ind inj eq card_image image_subset_iff independent_card_le_dim inj_on_subset matrix_vector_mult_in_columnspace)
  8.1046 +      by (rule linear_independent_injective_image [OF Finite_Cartesian_Product.matrix_vector_mul_linear \<open>independent B\<close>])
  8.1047 +    have "dim (span (rows A)) \<le> card (( *v) A ` B)"
  8.1048 +      unfolding B(2)[symmetric]
  8.1049 +      using inj
  8.1050 +      by (auto simp: card_image inj_on_subset span_superset)
  8.1051 +    also have "\<dots> \<le> dim (span (columns A))"
  8.1052 +      using _ ind
  8.1053 +      by (rule independent_card_le_dim) (auto intro!: matrix_vector_mult_in_columnspace)
  8.1054 +    finally show ?thesis .
  8.1055    qed
  8.1056    then show ?thesis
  8.1057 -    by simp
  8.1058 +    by (simp add: dim_span)
  8.1059  qed
  8.1060  
  8.1061 -lemma rank_row:
  8.1062 +lemma column_rank_def:
  8.1063    fixes A :: "real^'n^'m"
  8.1064 -  shows "rank A = dim(rows A)"
  8.1065 -  unfolding rank_def
  8.1066 -  by (metis dim_rows_le_dim_columns columns_transpose dual_order.antisym rows_transpose)
  8.1067 +  shows "rank A = dim(columns A)"
  8.1068 +  unfolding row_rank_def
  8.1069 +  by (metis columns_transpose dim_rows_le_dim_columns le_antisym rows_transpose)
  8.1070  
  8.1071  lemma rank_transpose:
  8.1072    fixes A :: "real^'n^'m"
  8.1073    shows "rank(transpose A) = rank A"
  8.1074 -  by (metis rank_def rank_row rows_transpose)
  8.1075 +  by (metis column_rank_def row_rank_def rows_transpose)
  8.1076  
  8.1077  lemma matrix_vector_mult_basis:
  8.1078    fixes A :: "real^'n^'m"
  8.1079 @@ -1667,22 +1081,26 @@
  8.1080  lemma rank_dim_range:
  8.1081    fixes A :: "real^'n^'m"
  8.1082    shows "rank A = dim(range (\<lambda>x. A *v x))"
  8.1083 -  unfolding rank_def
  8.1084 +  unfolding column_rank_def
  8.1085  proof (rule span_eq_dim)
  8.1086 -  show "span (columns A) = span (range (( *v) A))"
  8.1087 -    apply (auto simp: columns_image_basis span_linear_image matrix_vector_mul_linear)
  8.1088 -    by (metis columns_image_basis matrix_vector_mul_linear matrix_vector_mult_in_columnspace span_linear_image)
  8.1089 +  have "span (columns A) \<subseteq> span (range (( *v) A))" (is "?l \<subseteq> ?r")
  8.1090 +    by (simp add: columns_image_basis image_subsetI span_mono)
  8.1091 +  then show "?l = ?r"
  8.1092 +    by (metis (no_types, lifting) image_subset_iff matrix_vector_mult_in_columnspace
  8.1093 +        span_eq span_span)
  8.1094  qed
  8.1095  
  8.1096  lemma rank_bound:
  8.1097    fixes A :: "real^'n^'m"
  8.1098    shows "rank A \<le> min CARD('m) (CARD('n))"
  8.1099 -  by (metis (mono_tags, hide_lams) min.bounded_iff DIM_cart DIM_real dim_subset_UNIV mult.right_neutral rank_def rank_transpose)
  8.1100 +  by (metis (mono_tags, lifting) dim_subset_UNIV_cart min.bounded_iff
  8.1101 +      column_rank_def row_rank_def)
  8.1102  
  8.1103  lemma full_rank_injective:
  8.1104    fixes A :: "real^'n^'m"
  8.1105    shows "rank A = CARD('n) \<longleftrightarrow> inj (( *v) A)"
  8.1106 -  by (simp add: matrix_left_invertible_injective [symmetric] matrix_left_invertible_span_rows rank_row dim_eq_full [symmetric])
  8.1107 +  by (simp add: matrix_left_invertible_injective [symmetric] matrix_left_invertible_span_rows row_rank_def
  8.1108 +      dim_eq_full [symmetric] card_cart_basis vec.dimension_def)
  8.1109  
  8.1110  lemma full_rank_surjective:
  8.1111    fixes A :: "real^'n^'m"
  8.1112 @@ -1703,10 +1121,10 @@
  8.1113    shows "(\<exists>x. (x \<noteq> 0) \<and> A *v x = 0) \<longleftrightarrow> ~(rank A = CARD('n))"
  8.1114    by (meson matrix_left_invertible_injective full_rank_injective matrix_left_invertible_ker)
  8.1115  
  8.1116 -lemma rank_eq_0: "rank A = 0 \<longleftrightarrow> A = 0" and rank_0 [simp]: "rank 0 = 0"
  8.1117 +lemma rank_eq_0: "rank A = 0 \<longleftrightarrow> A = 0" and rank_0 [simp]: "rank (0::real^'n^'m) = 0"
  8.1118 +  for A :: "real^'n^'m"
  8.1119    by (auto simp: rank_dim_range matrix_eq)
  8.1120  
  8.1121 -
  8.1122  lemma rank_mul_le_right:
  8.1123    fixes A :: "real^'n^'m" and B :: "real^'p^'n"
  8.1124    shows "rank(A ** B) \<le> rank B"
  8.1125 @@ -1714,7 +1132,7 @@
  8.1126    have "rank(A ** B) \<le> dim (( *v) A ` range (( *v) B))"
  8.1127      by (auto simp: rank_dim_range image_comp o_def matrix_vector_mul_assoc)
  8.1128    also have "\<dots> \<le> rank B"
  8.1129 -    by (simp add: rank_dim_range matrix_vector_mul_linear dim_image_le)
  8.1130 +    by (simp add: rank_dim_range dim_image_le)
  8.1131    finally show ?thesis .
  8.1132  qed
  8.1133  
  8.1134 @@ -1845,4 +1263,4 @@
  8.1135    bounded_linear.uniform_limit[OF bounded_linear_vec_nth]
  8.1136    bounded_linear.uniform_limit[OF bounded_linear_component_cart]
  8.1137  
  8.1138 -end
  8.1139 +end
  8.1140 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/HOL/Analysis/Cartesian_Space.thy	Wed May 02 13:49:38 2018 +0200
     9.3 @@ -0,0 +1,312 @@
     9.4 +(* Title:   Cartesian_Space.thy
     9.5 +   Author:  Amine Chaieb, University of Cambridge
     9.6 +   Author:  Jose Divasón <jose.divasonm at unirioja.es>
     9.7 +   Author:  Jesús Aransay <jesus-maria.aransay at unirioja.es>
     9.8 +   Author:  Johannes Hölzl, VU Amsterdam
     9.9 +   Author:  Fabian Immler, TUM
    9.10 +*)
    9.11 +theory Cartesian_Space
    9.12 +  imports
    9.13 +    Finite_Cartesian_Product Linear_Algebra
    9.14 +begin
    9.15 +
    9.16 +definition "cart_basis = {axis i 1 | i. i\<in>UNIV}"
    9.17 +
    9.18 +lemma finite_cart_basis: "finite (cart_basis)" unfolding cart_basis_def
    9.19 +  using finite_Atleast_Atmost_nat by fastforce
    9.20 +
    9.21 +lemma card_cart_basis: "card (cart_basis::('a::zero_neq_one^'i) set) = CARD('i)"
    9.22 +  unfolding cart_basis_def Setcompr_eq_image
    9.23 +  by (rule card_image) (auto simp: inj_on_def axis_eq_axis)
    9.24 +
    9.25 +interpretation vec: vector_space "( *s) "
    9.26 +  by unfold_locales (vector algebra_simps)+
    9.27 +
    9.28 +lemma independent_cart_basis:
    9.29 +  "vec.independent (cart_basis)"
    9.30 +proof (rule vec.independent_if_scalars_zero)
    9.31 +  show "finite (cart_basis)" using finite_cart_basis .
    9.32 +  fix f::"('a, 'b) vec \<Rightarrow> 'a" and x::"('a, 'b) vec"
    9.33 +  assume eq_0: "(\<Sum>x\<in>cart_basis. f x *s x) = 0" and x_in: "x \<in> cart_basis"
    9.34 +  obtain i where x: "x = axis i 1" using x_in unfolding cart_basis_def by auto
    9.35 +  have sum_eq_0: "(\<Sum>x\<in>(cart_basis) - {x}. f x * (x $ i)) = 0"
    9.36 +  proof (rule sum.neutral, rule ballI)
    9.37 +    fix xa assume xa: "xa \<in> cart_basis - {x}"
    9.38 +    obtain a where a: "xa = axis a 1" and a_not_i: "a \<noteq> i"
    9.39 +      using xa x unfolding cart_basis_def by auto
    9.40 +    have "xa $ i = 0" unfolding a axis_def using a_not_i by auto
    9.41 +    thus "f xa * xa $ i = 0" by simp
    9.42 +  qed
    9.43 +  have "0 = (\<Sum>x\<in>cart_basis. f x *s x) $ i" using eq_0 by simp
    9.44 +  also have "... = (\<Sum>x\<in>cart_basis. (f x *s x) $ i)" unfolding sum_component ..
    9.45 +  also have "... = (\<Sum>x\<in>cart_basis. f x * (x $ i))" unfolding vector_smult_component ..
    9.46 +  also have "... = f x * (x $ i) + (\<Sum>x\<in>(cart_basis) - {x}. f x * (x $ i))"
    9.47 +    by (rule sum.remove[OF finite_cart_basis x_in])
    9.48 +  also have "... =  f x * (x $ i)" unfolding sum_eq_0 by simp
    9.49 +  also have "... = f x" unfolding x axis_def by auto
    9.50 +  finally show "f x = 0" ..
    9.51 +qed
    9.52 +
    9.53 +lemma span_cart_basis:
    9.54 +  "vec.span (cart_basis) = UNIV"
    9.55 +proof (auto)
    9.56 +  fix x::"('a, 'b) vec"
    9.57 +  let ?f="\<lambda>v. x $ (THE i. v = axis i 1)"
    9.58 +  show "x \<in> vec.span (cart_basis)"
    9.59 +    apply (unfold vec.span_finite[OF finite_cart_basis])
    9.60 +    apply (rule image_eqI[of _ _ ?f])
    9.61 +     apply (subst  vec_eq_iff)
    9.62 +     apply clarify
    9.63 +  proof -
    9.64 +    fix i::'b
    9.65 +    let ?w = "axis i (1::'a)"
    9.66 +    have the_eq_i: "(THE a. ?w = axis a 1) = i"
    9.67 +      by (rule the_equality, auto simp: axis_eq_axis)
    9.68 +    have sum_eq_0: "(\<Sum>v\<in>(cart_basis) - {?w}. x $ (THE i. v = axis i 1) * v $ i) = 0"
    9.69 +    proof (rule sum.neutral, rule ballI)
    9.70 +      fix xa::"('a, 'b) vec"
    9.71 +      assume xa: "xa \<in> cart_basis - {?w}"
    9.72 +      obtain j where j: "xa = axis j 1" and i_not_j: "i \<noteq> j" using xa unfolding cart_basis_def by auto
    9.73 +      have the_eq_j: "(THE i. xa = axis i 1) = j"
    9.74 +      proof (rule the_equality)
    9.75 +        show "xa = axis j 1" using j .
    9.76 +        show "\<And>i. xa = axis i 1 \<Longrightarrow> i = j" by (metis axis_eq_axis j zero_neq_one)
    9.77 +      qed
    9.78 +      show "x $ (THE i. xa = axis i 1) * xa $ i = 0"
    9.79 +        apply (subst (2) j)
    9.80 +        unfolding the_eq_j unfolding axis_def using i_not_j by simp
    9.81 +    qed
    9.82 +    have "(\<Sum>v\<in>cart_basis. x $ (THE i. v = axis i 1) *s v) $ i =
    9.83 +  (\<Sum>v\<in>cart_basis. (x $ (THE i. v = axis i 1) *s v) $ i)" unfolding sum_component ..
    9.84 +    also have "... = (\<Sum>v\<in>cart_basis. x $ (THE i. v = axis i 1) * v $ i)"
    9.85 +      unfolding vector_smult_component ..
    9.86 +    also have "... = x $ (THE a. ?w = axis a 1) * ?w $ i + (\<Sum>v\<in>(cart_basis) - {?w}. x $ (THE i. v = axis i 1) * v $ i)"
    9.87 +      by (rule sum.remove[OF finite_cart_basis], auto simp add: cart_basis_def)
    9.88 +    also have "... = x $ (THE a. ?w = axis a 1) * ?w $ i" unfolding sum_eq_0 by simp
    9.89 +    also have "... = x $ i" unfolding the_eq_i unfolding axis_def by auto
    9.90 +    finally show "x $ i = (\<Sum>v\<in>cart_basis. x $ (THE i. v = axis i 1) *s v) $ i" by simp
    9.91 +  qed simp
    9.92 +qed
    9.93 +
    9.94 +(*Some interpretations:*)
    9.95 +interpretation vec: finite_dimensional_vector_space "( *s)" "cart_basis"
    9.96 +  by (unfold_locales, auto simp add: finite_cart_basis independent_cart_basis span_cart_basis)
    9.97 +
    9.98 +lemma matrix_vector_mul_linear_gen[intro, simp]:
    9.99 +  "Vector_Spaces.linear ( *s) ( *s) (( *v) A)"
   9.100 +  by unfold_locales
   9.101 +    (vector matrix_vector_mult_def sum.distrib algebra_simps)+
   9.102 +
   9.103 +lemma linear_componentwise:
   9.104 +  fixes f:: "'a::field ^'m \<Rightarrow> 'a ^ 'n"
   9.105 +  assumes lf: "Vector_Spaces.linear ( *s) ( *s) f"
   9.106 +  shows "(f x)$j = sum (\<lambda>i. (x$i) * (f (axis i 1)$j)) (UNIV :: 'm set)" (is "?lhs = ?rhs")
   9.107 +proof -
   9.108 +  interpret lf: Vector_Spaces.linear "( *s)" "( *s)" f
   9.109 +    using lf .
   9.110 +  let ?M = "(UNIV :: 'm set)"
   9.111 +  let ?N = "(UNIV :: 'n set)"
   9.112 +  have fM: "finite ?M" by simp
   9.113 +  have "?rhs = (sum (\<lambda>i. (x$i) *s (f (axis i 1))) ?M)$j"
   9.114 +    unfolding sum_component by simp
   9.115 +  then show ?thesis
   9.116 +    unfolding lf.sum[symmetric] lf.scale[symmetric]
   9.117 +    unfolding basis_expansion by auto
   9.118 +qed
   9.119 +
   9.120 +interpretation vec: Vector_Spaces.linear "( *s)" "( *s)" "( *v) A"
   9.121 +  using matrix_vector_mul_linear_gen.
   9.122 +
   9.123 +interpretation vec: finite_dimensional_vector_space_pair "( *s)" cart_basis "( *s)" cart_basis ..
   9.124 +
   9.125 +lemma matrix_works:
   9.126 +  assumes lf: "Vector_Spaces.linear ( *s) ( *s) f"
   9.127 +  shows "matrix f *v x = f (x::'a::field ^ 'n)"
   9.128 +  apply (simp add: matrix_def matrix_vector_mult_def vec_eq_iff mult.commute)
   9.129 +  apply clarify
   9.130 +  apply (rule linear_componentwise[OF lf, symmetric])
   9.131 +  done
   9.132 +
   9.133 +lemma matrix_of_matrix_vector_mul[simp]: "matrix(\<lambda>x. A *v (x :: 'a::field ^ 'n)) = A"
   9.134 +  by (simp add: matrix_eq matrix_works)
   9.135 +
   9.136 +lemma matrix_compose_gen:
   9.137 +  assumes lf: "Vector_Spaces.linear ( *s) ( *s) (f::'a::{field}^'n \<Rightarrow> 'a^'m)"
   9.138 +    and lg: "Vector_Spaces.linear ( *s) ( *s) (g::'a^'m \<Rightarrow> 'a^_)"
   9.139 +  shows "matrix (g o f) = matrix g ** matrix f"
   9.140 +  using lf lg Vector_Spaces.linear_compose[OF lf lg] matrix_works[OF Vector_Spaces.linear_compose[OF lf lg]]
   9.141 +  by (simp add: matrix_eq matrix_works matrix_vector_mul_assoc[symmetric] o_def)
   9.142 +
   9.143 +lemma matrix_compose:
   9.144 +  assumes "linear (f::real^'n \<Rightarrow> real^'m)" "linear (g::real^'m \<Rightarrow> real^_)"
   9.145 +  shows "matrix (g o f) = matrix g ** matrix f"
   9.146 +  using matrix_compose_gen[of f g] assms
   9.147 +  by (simp add: linear_def scalar_mult_eq_scaleR)
   9.148 +
   9.149 +lemma matrix_left_invertible_injective:
   9.150 +  "(\<exists>B. (B::'a::field^'m^'n) ** (A::'a::field^'n^'m) = mat 1)
   9.151 +    \<longleftrightarrow> (\<forall>x y. A *v x = A *v y \<longrightarrow> x = y)"
   9.152 +proof -
   9.153 +  { fix B:: "'a^'m^'n" and x y assume B: "B ** A = mat 1" and xy: "A *v x = A*v y"
   9.154 +    from xy have "B*v (A *v x) = B *v (A*v y)" by simp
   9.155 +    hence "x = y"
   9.156 +      unfolding matrix_vector_mul_assoc B matrix_vector_mul_lid . }
   9.157 +  moreover
   9.158 +  { assume A: "\<forall>x y. A *v x = A *v y \<longrightarrow> x = y"
   9.159 +    hence i: "inj (( *v) A)" unfolding inj_on_def by auto
   9.160 +    from vec.linear_exists_left_inverse_on[OF matrix_vector_mul_linear_gen vec.subspace_UNIV i]
   9.161 +    obtain g where g: "Vector_Spaces.linear ( *s) ( *s) g" "g o (( *v) A) = id" by (auto simp: id_def module_hom_iff_linear o_def)
   9.162 +    have "matrix g ** A = mat 1"
   9.163 +      unfolding matrix_eq matrix_vector_mul_lid matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)]
   9.164 +      using g(2) by (metis comp_apply id_apply)
   9.165 +    then have "\<exists>B. (B::'a::{field}^'m^'n) ** A = mat 1" by blast }
   9.166 +  ultimately show ?thesis by blast
   9.167 +qed
   9.168 +
   9.169 +lemma matrix_left_invertible_ker:
   9.170 +  "(\<exists>B. (B::'a::{field} ^'m^'n) ** (A::'a::{field}^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x. A *v x = 0 \<longrightarrow> x = 0)"
   9.171 +  unfolding matrix_left_invertible_injective
   9.172 +  using vec.inj_on_iff_eq_0[OF vec.subspace_UNIV, of A]
   9.173 +  by (simp add: inj_on_def)
   9.174 +
   9.175 +lemma matrix_left_invertible_independent_columns:
   9.176 +  fixes A :: "'a::{field}^'n^'m"
   9.177 +  shows "(\<exists>(B::'a ^'m^'n). B ** A = mat 1) \<longleftrightarrow>
   9.178 +      (\<forall>c. sum (\<lambda>i. c i *s column i A) (UNIV :: 'n set) = 0 \<longrightarrow> (\<forall>i. c i = 0))"
   9.179 +    (is "?lhs \<longleftrightarrow> ?rhs")
   9.180 +proof -
   9.181 +  let ?U = "UNIV :: 'n set"
   9.182 +  { assume k: "\<forall>x. A *v x = 0 \<longrightarrow> x = 0"
   9.183 +    { fix c i
   9.184 +      assume c: "sum (\<lambda>i. c i *s column i A) ?U = 0" and i: "i \<in> ?U"
   9.185 +      let ?x = "\<chi> i. c i"
   9.186 +      have th0:"A *v ?x = 0"
   9.187 +        using c
   9.188 +        by (vector matrix_mult_sum)
   9.189 +      from k[rule_format, OF th0] i
   9.190 +      have "c i = 0" by (vector vec_eq_iff)}
   9.191 +    hence ?rhs by blast }
   9.192 +  moreover
   9.193 +  { assume H: ?rhs
   9.194 +    { fix x assume x: "A *v x = 0"
   9.195 +      let ?c = "\<lambda>i. ((x$i ):: 'a)"
   9.196 +      from H[rule_format, of ?c, unfolded matrix_mult_sum[symmetric], OF x]
   9.197 +      have "x = 0" by vector }
   9.198 +  }
   9.199 +  ultimately show ?thesis unfolding matrix_left_invertible_ker by auto
   9.200 +qed
   9.201 +
   9.202 +lemma left_invertible_transpose:
   9.203 +  "(\<exists>(B). B ** transpose (A) = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). A ** B = mat 1)"
   9.204 +  by (metis matrix_transpose_mul transpose_mat transpose_transpose)
   9.205 +
   9.206 +lemma right_invertible_transpose:
   9.207 +  "(\<exists>(B). transpose (A) ** B = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B). B ** A = mat 1)"
   9.208 +  by (metis matrix_transpose_mul transpose_mat transpose_transpose)
   9.209 +
   9.210 +lemma matrix_right_invertible_independent_rows:
   9.211 +  fixes A :: "'a::{field}^'n^'m"
   9.212 +  shows "(\<exists>(B::'a^'m^'n). A ** B = mat 1) \<longleftrightarrow>
   9.213 +    (\<forall>c. sum (\<lambda>i. c i *s row i A) (UNIV :: 'm set) = 0 \<longrightarrow> (\<forall>i. c i = 0))"
   9.214 +  unfolding left_invertible_transpose[symmetric]
   9.215 +    matrix_left_invertible_independent_columns
   9.216 +  by (simp add:)
   9.217 +
   9.218 +lemma matrix_left_right_inverse:
   9.219 +  fixes A A' :: "'a::{field}^'n^'n"
   9.220 +  shows "A ** A' = mat 1 \<longleftrightarrow> A' ** A = mat 1"
   9.221 +proof -
   9.222 +  { fix A A' :: "'a ^'n^'n"
   9.223 +    assume AA': "A ** A' = mat 1"
   9.224 +    have sA: "surj (( *v) A)"
   9.225 +      unfolding surj_def
   9.226 +      apply clarify
   9.227 +      apply (rule_tac x="(A' *v y)" in exI)
   9.228 +      apply (simp add: matrix_vector_mul_assoc AA')
   9.229 +      done
   9.230 +    from vec.linear_surjective_isomorphism[OF matrix_vector_mul_linear_gen sA]
   9.231 +    obtain f' :: "'a ^'n \<Rightarrow> 'a ^'n"
   9.232 +      where f': "Vector_Spaces.linear ( *s) ( *s) f'" "\<forall>x. f' (A *v x) = x" "\<forall>x. A *v f' x = x" by blast
   9.233 +    have th: "matrix f' ** A = mat 1"
   9.234 +      by (simp add: matrix_eq matrix_works[OF f'(1)]
   9.235 +          matrix_vector_mul_assoc[symmetric] f'(2)[rule_format])
   9.236 +    hence "(matrix f' ** A) ** A' = mat 1 ** A'" by simp
   9.237 +    hence "matrix f' = A'"
   9.238 +      by (simp add: matrix_mul_assoc[symmetric] AA')
   9.239 +    hence "matrix f' ** A = A' ** A" by simp
   9.240 +    hence "A' ** A = mat 1" by (simp add: th)
   9.241 +  }
   9.242 +  then show ?thesis by blast
   9.243 +qed
   9.244 +
   9.245 +lemma invertible_left_inverse:
   9.246 +  fixes A :: "'a::{field}^'n^'n"
   9.247 +  shows "invertible A \<longleftrightarrow> (\<exists>(B::'a^'n^'n). B ** A = mat 1)"
   9.248 +  by (metis invertible_def matrix_left_right_inverse)
   9.249 +
   9.250 +  lemma invertible_right_inverse:
   9.251 +  fixes A :: "'a::{field}^'n^'n"
   9.252 +  shows "invertible A \<longleftrightarrow> (\<exists>(B::'a^'n^'n). A** B = mat 1)"
   9.253 +  by (metis invertible_def matrix_left_right_inverse)
   9.254 +
   9.255 +(*Finally, some interesting theorems and interpretations that don't appear in any file of the
   9.256 +  library.*)
   9.257 +
   9.258 +locale linear_first_finite_dimensional_vector_space =
   9.259 +  l?: Vector_Spaces.linear scaleB scaleC f +
   9.260 +  B?: finite_dimensional_vector_space scaleB BasisB
   9.261 +  for scaleB :: "('a::field => 'b::ab_group_add => 'b)" (infixr "*b" 75)
   9.262 +  and scaleC :: "('a => 'c::ab_group_add => 'c)" (infixr "*c" 75)
   9.263 +  and BasisB :: "('b set)"
   9.264 +  and f :: "('b=>'c)"
   9.265 +
   9.266 +lemma vec_dim_card: "vec.dim (UNIV::('a::{field}^'n) set) = CARD ('n)"
   9.267 +proof -
   9.268 +  let ?f="\<lambda>i::'n. axis i (1::'a)"
   9.269 +  have "vec.dim (UNIV::('a::{field}^'n) set) = card (cart_basis::('a^'n) set)"
   9.270 +    unfolding vec.dim_UNIV ..
   9.271 +  also have "... = card ({i. i\<in> UNIV}::('n) set)"
   9.272 +    proof (rule bij_betw_same_card[of ?f, symmetric], unfold bij_betw_def, auto)
   9.273 +      show "inj (\<lambda>i::'n. axis i (1::'a))"  by (simp add: inj_on_def axis_eq_axis)
   9.274 +      fix i::'n
   9.275 +      show "axis i 1 \<in> cart_basis" unfolding cart_basis_def by auto
   9.276 +      fix x::"'a^'n"
   9.277 +      assume "x \<in> cart_basis"
   9.278 +      thus "x \<in> range (\<lambda>i. axis i 1)" unfolding cart_basis_def by auto
   9.279 +    qed
   9.280 +  also have "... = CARD('n)" by auto
   9.281 +  finally show ?thesis .
   9.282 +qed
   9.283 +
   9.284 +interpretation vector_space_over_itself: vector_space "( *) :: 'a::field => 'a => 'a"
   9.285 +  by unfold_locales (simp_all add: algebra_simps)
   9.286 +
   9.287 +lemmas [simp del] = vector_space_over_itself.scale_scale
   9.288 +
   9.289 +interpretation vector_space_over_itself: finite_dimensional_vector_space
   9.290 +  "( *) :: 'a::field => 'a => 'a" "{1}"
   9.291 +  by unfold_locales (auto simp: vector_space_over_itself.span_singleton)
   9.292 +
   9.293 +lemma dimension_eq_1[code_unfold]: "vector_space_over_itself.dimension TYPE('a::field)= 1"
   9.294 +  unfolding vector_space_over_itself.dimension_def by simp
   9.295 +
   9.296 +lemma linear_matrix_vector_mul_eq:
   9.297 +  "Vector_Spaces.linear ( *s) ( *s) f \<longleftrightarrow> linear (f :: real^'n \<Rightarrow> real ^'m)"
   9.298 +  by (simp add: scalar_mult_eq_scaleR linear_def)
   9.299 +
   9.300 +lemma matrix_vector_mul[simp]:
   9.301 +  "Vector_Spaces.linear ( *s) ( *s) g \<Longrightarrow> (\<lambda>y. matrix g *v y) = g"
   9.302 +  "linear f \<Longrightarrow> (\<lambda>x. matrix f *v x) = f"
   9.303 +  "bounded_linear f \<Longrightarrow> (\<lambda>x. matrix f *v x) = f"
   9.304 +  for f :: "real^'n \<Rightarrow> real ^'m"
   9.305 +  by (simp_all add: ext matrix_works linear_matrix_vector_mul_eq linear_linear)
   9.306 +
   9.307 +lemma span_vec_eq: "vec.span X = span X"
   9.308 +  and dim_vec_eq: "vec.dim X = dim X"
   9.309 +  and dependent_vec_eq: "vec.dependent X = dependent X"
   9.310 +  and subspace_vec_eq: "vec.subspace X = subspace X"
   9.311 +  for X::"(real^'n) set"
   9.312 +  unfolding span_raw_def dim_raw_def dependent_raw_def subspace_raw_def
   9.313 +  by (auto simp: scalar_mult_eq_scaleR)
   9.314 +
   9.315 +end
   9.316 \ No newline at end of file
    10.1 --- a/src/HOL/Analysis/Change_Of_Vars.thy	Wed Apr 18 21:12:50 2018 +0100
    10.2 +++ b/src/HOL/Analysis/Change_Of_Vars.thy	Wed May 02 13:49:38 2018 +0200
    10.3 @@ -179,6 +179,10 @@
    10.4      by (rule induct_matrix_elementary) (auto intro: assms *)
    10.5  qed
    10.6  
    10.7 +lemma matrix_vector_mult_matrix_matrix_mult_compose:
    10.8 +  "( *v) (A ** B) = ( *v) A \<circ> ( *v) B"
    10.9 +  by (auto simp: matrix_vector_mul_assoc)
   10.10 +
   10.11  lemma induct_linear_elementary:
   10.12    fixes f :: "real^'n \<Rightarrow> real^'n"
   10.13    assumes "linear f"
   10.14 @@ -194,12 +198,15 @@
   10.15      fix A B
   10.16      assume "P (( *v) A)" and "P (( *v) B)"
   10.17      then show "P (( *v) (A ** B))"
   10.18 -      by (metis (no_types, lifting) comp linear_compose matrix_compose matrix_eq matrix_vector_mul matrix_vector_mul_linear)
   10.19 +      by (auto simp add: matrix_vector_mult_matrix_matrix_mult_compose matrix_vector_mul_linear
   10.20 +          intro!: comp)
   10.21    next
   10.22      fix A :: "real^'n^'n" and i
   10.23      assume "row i A = 0"
   10.24 -    then show "P (( *v) A)"
   10.25 -      by (metis inner_zero_left matrix_vector_mul_component matrix_vector_mul_linear row_def vec_eq_iff vec_lambda_beta zeroes)
   10.26 +    show "P (( *v) A)"
   10.27 +      using matrix_vector_mul_linear
   10.28 +      by (rule zeroes[where i=i])
   10.29 +        (metis \<open>row i A = 0\<close> inner_zero_left matrix_vector_mul_component row_def vec_lambda_eta)
   10.30    next
   10.31      fix A :: "real^'n^'n"
   10.32      assume 0: "\<And>i j. i \<noteq> j \<Longrightarrow> A $ i $ j = 0"
   10.33 @@ -246,7 +253,7 @@
   10.34                 = measure lebesgue (cbox a b)" (is "?Q")
   10.35  proof -
   10.36    have lin: "linear ?f"
   10.37 -    by (force simp: plus_vec_def scaleR_vec_def algebra_simps intro: linearI)
   10.38 +    by (rule linearI) (auto simp: plus_vec_def scaleR_vec_def algebra_simps)
   10.39    show fab: "?f ` cbox a b \<in> lmeasurable"
   10.40      by (simp add: lin measurable_linear_image_interval)
   10.41    let ?c = "\<chi> i. if i = m then b$m + b$n else b$i"
   10.42 @@ -474,7 +481,7 @@
   10.43      then have "\<not> inj f"
   10.44        by (metis (full_types) linear_injective_imp_surjective one_neq_zero surjE vec_component)
   10.45      have detf: "det (matrix f) = 0"
   10.46 -      by (metis "0" \<open>linear f\<close> invertible_det_nz invertible_right_inverse matrix_right_invertible_surjective matrix_vector_mul surjE vec_component)
   10.47 +      using \<open>\<not> inj f\<close> det_nz_iff_inj[OF \<open>linear f\<close>] by blast
   10.48      show "f ` S \<in> lmeasurable \<and> ?Q f S"
   10.49      proof
   10.50        show "f ` S \<in> lmeasurable"
   10.51 @@ -500,7 +507,7 @@
   10.52      assume "m \<noteq> n" and "S \<in> lmeasurable"
   10.53      let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i"
   10.54      have lin: "linear ?h"
   10.55 -      by (simp add: plus_vec_def scaleR_vec_def linearI)
   10.56 +      by (rule linearI) (simp_all add: plus_vec_def scaleR_vec_def)
   10.57      have meq: "measure lebesgue ((\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i) ` cbox a b)
   10.58               = measure lebesgue (cbox a b)" for a b
   10.59      proof (cases "cbox a b = {}")
   10.60 @@ -532,7 +539,7 @@
   10.61      assume "m \<noteq> n" and "S \<in> lmeasurable"
   10.62      let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. if i = m then v $ m + v $ n else v $ i"
   10.63      have lin: "linear ?h"
   10.64 -      by (auto simp: algebra_simps plus_vec_def scaleR_vec_def vec_eq_iff intro: linearI)
   10.65 +      by (rule linearI) (auto simp: algebra_simps plus_vec_def scaleR_vec_def vec_eq_iff)
   10.66      consider "m < n" | " n < m"
   10.67        using \<open>m \<noteq> n\<close> less_linear by blast
   10.68      then have 1: "det(matrix ?h) = 1"
   10.69 @@ -997,11 +1004,11 @@
   10.70                then show ?thesis
   10.71                proof (rule_tac x="(y - x) /\<^sub>R r" in bexI)
   10.72                  have "f' x ((y - x) /\<^sub>R r) = f' x (y - x) /\<^sub>R r"
   10.73 -                  by (simp add: lin linear_cmul)
   10.74 +                  by (simp add: lin linear_scale)
   10.75                  then have "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) = norm (f' x (y - x) /\<^sub>R r - (f y - f x) /\<^sub>R r)"
   10.76                    by (simp add: dist_norm)
   10.77                  also have "\<dots> = norm (f' x (y - x) - (f y - f x)) / r"
   10.78 -                  using \<open>r > 0\<close> by (simp add: real_vector.scale_right_diff_distrib [symmetric] divide_simps)
   10.79 +                  using \<open>r > 0\<close> by (simp add: scale_right_diff_distrib [symmetric] divide_simps)
   10.80                  also have "\<dots> \<le> norm (f y - (f x + f' x (y - x))) / norm (y - x)"
   10.81                    using that \<open>r > 0\<close> False by (simp add: algebra_simps divide_simps dist_norm norm_minus_commute mult_right_mono)
   10.82                  also have "\<dots> < k"
   10.83 @@ -1610,8 +1617,9 @@
   10.84      and lb: "\<And>v. v \<noteq> 0 \<Longrightarrow> (\<exists>k>0. \<forall>e>0. \<exists>x. x \<in> S - {0} \<and> norm x < e \<and> k * norm x \<le> \<bar>v \<bullet> x\<bar>)"
   10.85    shows "f x = 0"
   10.86  proof -
   10.87 +  interpret linear f by fact
   10.88    have "dim {x. f x = 0} \<le> DIM('a)"
   10.89 -    using dim_subset_UNIV by blast
   10.90 +    by (rule dim_subset_UNIV)
   10.91    moreover have False if less: "dim {x. f x = 0} < DIM('a)"
   10.92    proof -
   10.93      obtain d where "d \<noteq> 0" and d: "\<And>y. f y = 0 \<Longrightarrow> d \<bullet> y = 0"
   10.94 @@ -1662,7 +1670,7 @@
   10.95          with lim0 \<alpha> have "((\<lambda>x. f x /\<^sub>R norm x) \<circ> (\<alpha> \<circ> \<rho>)) \<longlonglongrightarrow> 0"
   10.96            by (force simp: tendsto_at_iff_sequentially)
   10.97          then show "(f \<circ> (\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>) \<longlonglongrightarrow> 0"
   10.98 -          by (simp add: o_def linear_cmul \<open>linear f\<close>)
   10.99 +          by (simp add: o_def scale)
  10.100        qed
  10.101      qed
  10.102      ultimately show False
  10.103 @@ -1671,7 +1679,9 @@
  10.104    ultimately have dim: "dim {x. f x = 0} = DIM('a)"
  10.105      by force
  10.106    then show ?thesis
  10.107 -    by (metis (mono_tags, lifting) UNIV_I assms(1) dim_eq_full linear_eq_0_span mem_Collect_eq)
  10.108 +    using dim_eq_full
  10.109 +    by (metis (mono_tags, lifting) eq_0_on_span eucl.span_Basis linear_axioms linear_eq_stdbasis
  10.110 +        mem_Collect_eq module_hom_zero span_base span_raw_def)
  10.111  qed
  10.112  
  10.113  lemma lemma_partial_derivatives:
  10.114 @@ -1950,11 +1960,12 @@
  10.115                unfolding subspace_def convergent_eq_Cauchy [symmetric]
  10.116                  by (force simp: algebra_simps intro: tendsto_intros)
  10.117              then have CA_eq: "?CA = span ?CA"
  10.118 -              by (metis span_eq)
  10.119 +              by (metis span_eq_iff)
  10.120              also have "\<dots> = UNIV"
  10.121              proof -
  10.122                have "dim ?CA \<le> CARD('m)"
  10.123 -                by (rule dim_subset_UNIV_cart)
  10.124 +                using dim_subset_UNIV[of ?CA]
  10.125 +                by auto
  10.126                moreover have "False" if less: "dim ?CA < CARD('m)"
  10.127                proof -
  10.128                  obtain d where "d \<noteq> 0" and d: "\<And>y. y \<in> span ?CA \<Longrightarrow> orthogonal d y"
  10.129 @@ -2102,7 +2113,9 @@
  10.130            have lin_df: "linear (f' x)"
  10.131                 and lim_df: "((\<lambda>y. (1 / norm (y - x)) *\<^sub>R (f y - (f x + f' x (y - x)))) \<longlongrightarrow> 0) (at x within S)"
  10.132              using \<open>x \<in> S\<close> assms by (auto simp: has_derivative_within linear_linear)
  10.133 -          moreover have "(matrix (f' x) - B) *v w = 0" for w
  10.134 +          moreover
  10.135 +          interpret linear "f' x" by fact
  10.136 +          have "(matrix (f' x) - B) *v w = 0" for w
  10.137            proof (rule lemma_partial_derivatives [of "( *v) (matrix (f' x) - B)"])
  10.138              show "linear (( *v) (matrix (f' x) - B))"
  10.139                by (rule matrix_vector_mul_linear)
  10.140 @@ -2124,7 +2137,8 @@
  10.141                      fix k :: "nat"
  10.142                      assume "0 \<le> k"
  10.143                      have "0 \<le> onorm (( *v) (A k - B))"
  10.144 -                      by (simp add: linear_linear onorm_pos_le matrix_vector_mul_linear)
  10.145 +                      using matrix_vector_mul_bounded_linear
  10.146 +                      by (rule onorm_pos_le)
  10.147                      then show "norm (onorm (( *v) (A k - B))) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>(A k - B) $ i $ j\<bar>)"
  10.148                        by (simp add: onorm_le_matrix_component_sum del: vector_minus_component)
  10.149                    qed
  10.150 @@ -2174,11 +2188,11 @@
  10.151                then show "((\<lambda>y. (matrix (f' x) - B) *v (y - x) /\<^sub>R
  10.152                             norm (y - x) - (f x + f' x (y - x) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0)
  10.153                            (at x within S)"
  10.154 -                by (simp add: algebra_simps lin_df linear_diff matrix_vector_mul_linear)
  10.155 +                by (simp add: algebra_simps diff lin_df matrix_vector_mul_linear scalar_mult_eq_scaleR)
  10.156              qed
  10.157            qed (use x in \<open>simp; auto simp: not_less\<close>)
  10.158            ultimately have "f' x = ( *v) B"
  10.159 -            by (force simp: algebra_simps)
  10.160 +            by (force simp: algebra_simps scalar_mult_eq_scaleR)
  10.161            show "matrix (f' x) $ m $ n \<le> b"
  10.162            proof (rule tendsto_upperbound [of "\<lambda>i. (A i $ m $ n)" _ sequentially])
  10.163              show "(\<lambda>i. A i $ m $ n) \<longlonglongrightarrow> matrix (f' x) $ m $ n"
  10.164 @@ -2228,11 +2242,11 @@
  10.165                  have "linear (f' x)"
  10.166                    using True f has_derivative_linear by blast
  10.167                  then have "norm (f' x (y - x) - B *v (y - x)) = norm ((matrix (f' x) - B) *v (y - x))"
  10.168 -                  by (metis matrix_vector_mul matrix_vector_mult_diff_rdistrib)
  10.169 +                  by (simp add: matrix_vector_mult_diff_rdistrib)
  10.170                  also have "\<dots> \<le> (e * norm (y - x)) / 2"
  10.171                  proof (rule split246)
  10.172                    have "norm ((?A - B) *v (y - x)) / norm (y - x) \<le> onorm(\<lambda>x. (?A - B) *v x)"
  10.173 -                    by (simp add: le_onorm linear_linear matrix_vector_mul_linear)
  10.174 +                    by (rule le_onorm) auto
  10.175                    also have  "\<dots> < e/6"
  10.176                      by (rule Bo_e6)
  10.177                    finally have "norm ((?A - B) *v (y - x)) / norm (y - x) < e / 6" .
  10.178 @@ -2445,7 +2459,8 @@
  10.179        moreover have "\<exists>t\<in>T -` P. norm (inv T x - t) \<le> e"
  10.180        proof
  10.181          have "T (inv T x - inv T t) = x - t"
  10.182 -          using T linear_diff orthogonal_transformation_def by fastforce
  10.183 +          using T linear_diff orthogonal_transformation_def
  10.184 +          by (metis (no_types, hide_lams) Tinv)
  10.185          then have "norm (inv T x - inv T t) = norm (x - t)"
  10.186            by (metis T orthogonal_transformation_norm)
  10.187          then show "norm (inv T x - inv T t) \<le> e"
  10.188 @@ -2473,7 +2488,7 @@
  10.189              and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  10.190  proof -
  10.191    obtain a where "a \<noteq> 0" "P \<subseteq> {x. a \<bullet> x = 0}"
  10.192 -    using lowdim_subset_hyperplane [of P] P span_inc by auto
  10.193 +    using lowdim_subset_hyperplane [of P] P span_base by auto
  10.194    then obtain S where S: "S \<in> lmeasurable"
  10.195      and subS: "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
  10.196      and mS: "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
  10.197 @@ -2566,7 +2581,8 @@
  10.198        obtain x where x: "x \<in> S \<inter> cbox u v" "cbox u v \<subseteq> ball x (r x)"
  10.199          using \<open>K \<in> \<D>\<close> covered uv by blast
  10.200        then have "dim (range (f' x)) < ?n"
  10.201 -        using rank_dim_range [of "matrix (f' x)"] lin_f' rank by fastforce
  10.202 +        using rank_dim_range [of "matrix (f' x)"] x rank[of x]
  10.203 +        by (auto simp: matrix_works scalar_mult_eq_scaleR lin_f')
  10.204        then obtain T where T: "T \<in> lmeasurable"
  10.205              and subT: "{z. norm(z - f x) \<le> (2 * B) * norm(v - u) \<and> (\<exists>t \<in> range (f' x). norm(z - f x - t) \<le> d * norm(v - u))} \<subseteq> T"
  10.206              and measT: "?\<mu> T \<le> (2 * (d * norm(v - u))) * (2 * ((2 * B) * norm(v - u))) ^ (?n - 1)"
  10.207 @@ -2586,8 +2602,8 @@
  10.208              using r [of x y] x \<open>y \<in> S\<close> by blast
  10.209            have yx_le: "norm (y - x) \<le> norm (v - u)"
  10.210            proof (rule norm_le_componentwise_cart)
  10.211 -            show "\<bar>(y - x) $ i\<bar> \<le> \<bar>(v - u) $ i\<bar>" for i
  10.212 -            using x y by (force simp: mem_box_cart dest!: spec [where x=i])
  10.213 +            show "norm ((y - x) $ i) \<le> norm ((v - u) $ i)" for i
  10.214 +              using x y by (force simp: mem_box_cart dest!: spec [where x=i])
  10.215            qed
  10.216            have *: "\<lbrakk>norm(y - x - z) \<le> d; norm z \<le> B; d \<le> B\<rbrakk> \<Longrightarrow> norm(y - x) \<le> 2 * B"
  10.217              for x y z :: "real^'n::_" and d B
  10.218 @@ -3177,8 +3193,8 @@
  10.219          if "x \<in> T" for x
  10.220        proof -
  10.221          have "matrix (h' x) ** matrix (g' (h x)) = mat 1"
  10.222 -          using that id matrix_compose
  10.223 -          by (metis der_g gh has_derivative_linear left_inverse_linear matrix_id_mat_1)
  10.224 +          using that id[OF that] der_g[of "h x"] gh[OF that] left_inverse_linear has_derivative_linear
  10.225 +          by (subst matrix_compose[symmetric]) (force simp: matrix_id_mat_1 has_derivative_linear)+
  10.226          then have "\<bar>det (matrix (h' x))\<bar> * \<bar>det (matrix (g' (h x)))\<bar> = 1"
  10.227            by (metis abs_1 abs_mult det_I det_mul)
  10.228          then show ?thesis
    11.1 --- a/src/HOL/Analysis/Connected.thy	Wed Apr 18 21:12:50 2018 +0100
    11.2 +++ b/src/HOL/Analysis/Connected.thy	Wed May 02 13:49:38 2018 +0200
    11.3 @@ -4141,13 +4141,13 @@
    11.4  
    11.5  lemma closed_span [iff]: "closed (span s)"
    11.6    for s :: "'a::euclidean_space set"
    11.7 -  by (simp add: closed_subspace)
    11.8 +  by (simp add: closed_subspace subspace_span)
    11.9  
   11.10  lemma dim_closure [simp]: "dim (closure s) = dim s" (is "?dc = ?d")
   11.11    for s :: "'a::euclidean_space set"
   11.12  proof -
   11.13    have "?dc \<le> ?d"
   11.14 -    using closure_minimal[OF span_inc, of s]
   11.15 +    using closure_minimal[OF span_superset, of s]
   11.16      using closed_subspace[OF subspace_span, of s]
   11.17      using dim_subset[of "closure s" "span s"]
   11.18      by simp
    12.1 --- a/src/HOL/Analysis/Convex_Euclidean_Space.thy	Wed Apr 18 21:12:50 2018 +0100
    12.2 +++ b/src/HOL/Analysis/Convex_Euclidean_Space.thy	Wed May 02 13:49:38 2018 +0200
    12.3 @@ -28,50 +28,6 @@
    12.4      done
    12.5  qed
    12.6  
    12.7 -lemma dim_image_eq:
    12.8 -  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
    12.9 -  assumes lf: "linear f"
   12.10 -    and fi: "inj_on f (span S)"
   12.11 -  shows "dim (f ` S) = dim (S::'n::euclidean_space set)"
   12.12 -proof -
   12.13 -  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
   12.14 -    using basis_exists[of S] by auto
   12.15 -  then have "span S = span B"
   12.16 -    using span_mono[of B S] span_mono[of S "span B"] span_span[of B] by auto
   12.17 -  then have "independent (f ` B)"
   12.18 -    using independent_inj_on_image[of B f] B assms by auto
   12.19 -  moreover have "card (f ` B) = card B"
   12.20 -    using assms card_image[of f B] subset_inj_on[of f "span S" B] B span_inc by auto
   12.21 -  moreover have "(f ` B) \<subseteq> (f ` S)"
   12.22 -    using B by auto
   12.23 -  ultimately have "dim (f ` S) \<ge> dim S"
   12.24 -    using independent_card_le_dim[of "f ` B" "f ` S"] B by auto
   12.25 -  then show ?thesis
   12.26 -    using dim_image_le[of f S] assms by auto
   12.27 -qed
   12.28 -
   12.29 -lemma linear_injective_on_subspace_0:
   12.30 -  assumes lf: "linear f"
   12.31 -    and "subspace S"
   12.32 -  shows "inj_on f S \<longleftrightarrow> (\<forall>x \<in> S. f x = 0 \<longrightarrow> x = 0)"
   12.33 -proof -
   12.34 -  have "inj_on f S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f x = f y \<longrightarrow> x = y)"
   12.35 -    by (simp add: inj_on_def)
   12.36 -  also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f x - f y = 0 \<longrightarrow> x - y = 0)"
   12.37 -    by simp
   12.38 -  also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y \<in> S. f (x - y) = 0 \<longrightarrow> x - y = 0)"
   12.39 -    by (simp add: linear_diff[OF lf])
   12.40 -  also have "\<dots> \<longleftrightarrow> (\<forall>x \<in> S. f x = 0 \<longrightarrow> x = 0)"
   12.41 -    using \<open>subspace S\<close> subspace_def[of S] subspace_diff[of S] by auto
   12.42 -  finally show ?thesis .
   12.43 -qed
   12.44 -
   12.45 -lemma subspace_Inter: "\<forall>s \<in> f. subspace s \<Longrightarrow> subspace (\<Inter>f)"
   12.46 -  unfolding subspace_def by auto
   12.47 -
   12.48 -lemma span_eq[simp]: "span s = s \<longleftrightarrow> subspace s"
   12.49 -  unfolding span_def by (rule hull_eq) (rule subspace_Inter)
   12.50 -
   12.51  lemma substdbasis_expansion_unique:
   12.52    assumes d: "d \<subseteq> Basis"
   12.53    shows "(\<Sum>i\<in>d. f i *\<^sub>R i) = (x::'a::euclidean_space) \<longleftrightarrow>
   12.54 @@ -105,20 +61,16 @@
   12.55      moreover from * have "x = (norm x/e) *\<^sub>R y"
   12.56        by auto
   12.57      ultimately have "x \<in> span (cball 0 e)"
   12.58 -      using span_mul[of y "cball 0 e" "norm x/e"] span_inc[of "cball 0 e"]
   12.59 -      by (simp add: span_superset)
   12.60 +      using span_scale[of y "cball 0 e" "norm x/e"]
   12.61 +        span_superset[of "cball 0 e"]
   12.62 +      by (simp add: span_base)
   12.63    }
   12.64    then have "span (cball 0 e) = (UNIV :: 'n::euclidean_space set)"
   12.65      by auto
   12.66    then show ?thesis
   12.67 -    using dim_span[of "cball (0 :: 'n::euclidean_space) e"] by (auto simp add: dim_UNIV)
   12.68 -qed
   12.69 -
   12.70 -lemma indep_card_eq_dim_span:
   12.71 -  fixes B :: "'n::euclidean_space set"
   12.72 -  assumes "independent B"
   12.73 -  shows "finite B \<and> card B = dim (span B)"
   12.74 -  using assms basis_card_eq_dim[of B "span B"] span_inc by auto
   12.75 +    using dim_span[of "cball (0 :: 'n::euclidean_space) e"]
   12.76 +    by auto
   12.77 +qed
   12.78  
   12.79  lemma sum_not_0: "sum f A \<noteq> 0 \<Longrightarrow> \<exists>a \<in> A. f a \<noteq> 0"
   12.80    by (rule ccontr) auto
   12.81 @@ -1218,57 +1170,6 @@
   12.82      shows "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> convex (f ` s) \<longleftrightarrow> convex s"
   12.83      by (metis (no_types) convex_linear_image convex_linear_vimage inj_vimage_image_eq)
   12.84  
   12.85 -lemma basis_to_basis_subspace_isomorphism:
   12.86 -  assumes s: "subspace (S:: ('n::euclidean_space) set)"
   12.87 -    and t: "subspace (T :: ('m::euclidean_space) set)"
   12.88 -    and d: "dim S = dim T"
   12.89 -    and B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
   12.90 -    and C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T"
   12.91 -  shows "\<exists>f. linear f \<and> f ` B = C \<and> f ` S = T \<and> inj_on f S"
   12.92 -proof -
   12.93 -  from B independent_bound have fB: "finite B"
   12.94 -    by blast
   12.95 -  from C independent_bound have fC: "finite C"
   12.96 -    by blast
   12.97 -  from B(4) C(4) card_le_inj[of B C] d obtain f where
   12.98 -    f: "f ` B \<subseteq> C" "inj_on f B" using \<open>finite B\<close> \<open>finite C\<close> by auto
   12.99 -  from linear_independent_extend[OF B(2)] obtain g where
  12.100 -    g: "linear g" "\<forall>x \<in> B. g x = f x" by blast
  12.101 -  from inj_on_iff_eq_card[OF fB, of f] f(2)
  12.102 -  have "card (f ` B) = card B" by simp
  12.103 -  with B(4) C(4) have ceq: "card (f ` B) = card C" using d
  12.104 -    by simp
  12.105 -  have "g ` B = f ` B" using g(2)
  12.106 -    by (auto simp add: image_iff)
  12.107 -  also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
  12.108 -  finally have gBC: "g ` B = C" .
  12.109 -  have gi: "inj_on g B" using f(2) g(2)
  12.110 -    by (auto simp add: inj_on_def)
  12.111 -  note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
  12.112 -  {
  12.113 -    fix x y
  12.114 -    assume x: "x \<in> S" and y: "y \<in> S" and gxy: "g x = g y"
  12.115 -    from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B"
  12.116 -      by blast+
  12.117 -    from gxy have th0: "g (x - y) = 0"
  12.118 -      by (simp add: linear_diff[OF g(1)])
  12.119 -    have th1: "x - y \<in> span B" using x' y'
  12.120 -      by (metis span_diff)
  12.121 -    have "x = y" using g0[OF th1 th0] by simp
  12.122 -  }
  12.123 -  then have giS: "inj_on g S" unfolding inj_on_def by blast
  12.124 -  from span_subspace[OF B(1,3) s]
  12.125 -  have "g ` S = span (g ` B)"
  12.126 -    by (simp add: span_linear_image[OF g(1)])
  12.127 -  also have "\<dots> = span C"
  12.128 -    unfolding gBC ..
  12.129 -  also have "\<dots> = T"
  12.130 -    using span_subspace[OF C(1,3) t] .
  12.131 -  finally have gS: "g ` S = T" .
  12.132 -  from g(1) gS giS gBC show ?thesis
  12.133 -    by blast
  12.134 -qed
  12.135 -
  12.136  lemma closure_bounded_linear_image_subset:
  12.137    assumes f: "bounded_linear f"
  12.138    shows "f ` closure S \<subseteq> closure (f ` S)"
  12.139 @@ -1820,19 +1721,13 @@
  12.140    assume as: "finite t" "t \<noteq> {}" "t \<subseteq> insert a s" "sum u t = 1" "(\<Sum>v\<in>t. u v *\<^sub>R v) = x"
  12.141    have "(\<lambda>x. x - a) ` (t - {a}) \<subseteq> {x - a |x. x \<in> s}"
  12.142      using as(3) by auto
  12.143 -  then show "\<exists>v. x = a + v \<and> (\<exists>S u. finite S \<and> S \<subseteq> {x - a |x. x \<in> s} \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = v)"
  12.144 +  then show "\<exists>v. x = a + v \<and> (\<exists>S u. v = (\<Sum>v\<in>S. u v *\<^sub>R v) \<and> finite S \<and> S \<subseteq> {x - a |x. x \<in> s} )"
  12.145      apply (rule_tac x="x - a" in exI)
  12.146      apply (rule conjI, simp)
  12.147      apply (rule_tac x="(\<lambda>x. x - a) ` (t - {a})" in exI)
  12.148      apply (rule_tac x="\<lambda>x. u (x + a)" in exI)
  12.149 -    apply (rule conjI) using as(1) apply simp
  12.150 -    apply (erule conjI)
  12.151 -    using as(1)
  12.152 -    apply (simp add: sum.reindex[unfolded inj_on_def] scaleR_right_diff_distrib
  12.153 -      sum_subtractf scaleR_left.sum[symmetric] sum_diff1 scaleR_left_diff_distrib)
  12.154 -    unfolding as
  12.155 -    apply simp
  12.156 -    done
  12.157 +    by (simp_all add: as sum.reindex[unfolded inj_on_def] scaleR_right_diff_distrib
  12.158 +        sum_subtractf scaleR_left.sum[symmetric] sum_diff1 scaleR_left_diff_distrib)
  12.159  qed
  12.160  
  12.161  lemma affine_hull_insert_span:
  12.162 @@ -2113,7 +2008,7 @@
  12.163    unfolding cone_def by auto
  12.164  
  12.165  lemma subspace_imp_cone: "subspace S \<Longrightarrow> cone S"
  12.166 -  by (simp add: cone_def subspace_mul)
  12.167 +  by (simp add: cone_def subspace_scale)
  12.168  
  12.169  
  12.170  subsubsection \<open>Conic hull\<close>
  12.171 @@ -3153,10 +3048,10 @@
  12.172    using subspace_imp_affine affine_imp_convex by auto
  12.173  
  12.174  lemma affine_hull_subset_span: "(affine hull s) \<subseteq> (span s)"
  12.175 -  by (metis hull_minimal span_inc subspace_imp_affine subspace_span)
  12.176 +  by (metis hull_minimal span_superset subspace_imp_affine subspace_span)
  12.177  
  12.178  lemma convex_hull_subset_span: "(convex hull s) \<subseteq> (span s)"
  12.179 -  by (metis hull_minimal span_inc subspace_imp_convex subspace_span)
  12.180 +  by (metis hull_minimal span_superset subspace_imp_convex subspace_span)
  12.181  
  12.182  lemma convex_hull_subset_affine_hull: "(convex hull s) \<subseteq> (affine hull s)"
  12.183    by (metis affine_affine_hull affine_imp_convex hull_minimal hull_subset)
  12.184 @@ -3289,7 +3184,7 @@
  12.185      apply (rule subset_le_dim)
  12.186      unfolding subset_eq
  12.187      using \<open>a\<in>s\<close>
  12.188 -    apply (auto simp add:span_superset span_diff)
  12.189 +    apply (auto simp add:span_base span_diff)
  12.190      done
  12.191    also have "\<dots> < dim s + 1" by auto
  12.192    also have "\<dots> \<le> card (s - {a})"
  12.193 @@ -3660,45 +3555,7 @@
  12.194    then show ?thesis by auto
  12.195  qed
  12.196  
  12.197 -lemma independent_finite:
  12.198 -  fixes B :: "'n::euclidean_space set"
  12.199 -  assumes "independent B"
  12.200 -  shows "finite B"
  12.201 -  using affine_dependent_imp_dependent[of B] aff_independent_finite[of B] assms
  12.202 -  by auto
  12.203 -
  12.204 -lemma subspace_dim_equal:
  12.205 -  assumes "subspace (S :: ('n::euclidean_space) set)"
  12.206 -    and "subspace T"
  12.207 -    and "S \<subseteq> T"
  12.208 -    and "dim S \<ge> dim T"
  12.209 -  shows "S = T"
  12.210 -proof -
  12.211 -  obtain B where B: "B \<le> S" "independent B \<and> S \<subseteq> span B" "card B = dim S"
  12.212 -    using basis_exists[of S] by auto
  12.213 -  then have "span B \<subseteq> S"
  12.214 -    using span_mono[of B S] span_eq[of S] assms by metis
  12.215 -  then have "span B = S"
  12.216 -    using B by auto
  12.217 -  have "dim S = dim T"
  12.218 -    using assms dim_subset[of S T] by auto
  12.219 -  then have "T \<subseteq> span B"
  12.220 -    using card_eq_dim[of B T] B independent_finite assms by auto
  12.221 -  then show ?thesis
  12.222 -    using assms \<open>span B = S\<close> by auto
  12.223 -qed
  12.224 -
  12.225 -corollary dim_eq_span:
  12.226 -  fixes S :: "'a::euclidean_space set"
  12.227 -  shows "\<lbrakk>S \<subseteq> T; dim T \<le> dim S\<rbrakk> \<Longrightarrow> span S = span T"
  12.228 -by (simp add: span_mono subspace_dim_equal subspace_span)
  12.229 -
  12.230 -lemma dim_eq_full:
  12.231 -    fixes S :: "'a :: euclidean_space set"
  12.232 -    shows "dim S = DIM('a) \<longleftrightarrow> span S = UNIV"
  12.233 -apply (rule iffI)
  12.234 - apply (metis dim_eq_span dim_subset_UNIV span_Basis span_span subset_UNIV)
  12.235 -by (metis dim_UNIV dim_span)
  12.236 +lemmas independent_finite = independent_imp_finite
  12.237  
  12.238  lemma span_substd_basis:
  12.239    assumes d: "d \<subseteq> Basis"
  12.240 @@ -3710,9 +3567,10 @@
  12.241    moreover have s: "subspace ?B"
  12.242      using subspace_substandard[of "\<lambda>i. i \<notin> d"] .
  12.243    ultimately have "span d \<subseteq> ?B"
  12.244 -    using span_mono[of d "?B"] span_eq[of "?B"] by blast
  12.245 +    using span_mono[of d "?B"] span_eq_iff[of "?B"] by blast
  12.246    moreover have *: "card d \<le> dim (span d)"
  12.247 -    using independent_card_le_dim[of d "span d"] independent_substdbasis[OF assms] span_inc[of d]
  12.248 +    using independent_card_le_dim[of d "span d"] independent_substdbasis[OF assms]
  12.249 +      span_superset[of d]
  12.250      by auto
  12.251    moreover from * have "dim ?B \<le> dim (span d)"
  12.252      using dim_substandard[OF assms] by auto
  12.253 @@ -3727,7 +3585,7 @@
  12.254      f ` span B = {x. \<forall>i\<in>Basis. i \<notin> d \<longrightarrow> x \<bullet> i = 0} \<and> inj_on f (span B) \<and> d \<subseteq> Basis"
  12.255  proof -
  12.256    have B: "card B = dim B"
  12.257 -    using dim_unique[of B B "card B"] assms span_inc[of B] by auto
  12.258 +    using dim_unique[of B B "card B"] assms span_superset[of B] by auto
  12.259    have "dim B \<le> card (Basis :: 'a set)"
  12.260      using dim_subset_UNIV[of B] by simp
  12.261    from ex_card[OF this] obtain d :: "'a set" where d: "d \<subseteq> Basis" and t: "card d = dim B"
  12.262 @@ -3738,13 +3596,13 @@
  12.263      apply (rule subspace_span)
  12.264      apply (rule subspace_substandard)
  12.265      defer
  12.266 -    apply (rule span_inc)
  12.267 +    apply (rule span_superset)
  12.268      apply (rule assms)
  12.269      defer
  12.270      unfolding dim_span[of B]
  12.271      apply(rule B)
  12.272      unfolding span_substd_basis[OF d, symmetric]
  12.273 -    apply (rule span_inc)
  12.274 +    apply (rule span_superset)
  12.275      apply (rule independent_substdbasis[OF d])
  12.276      apply rule
  12.277      apply assumption
  12.278 @@ -4032,7 +3890,7 @@
  12.279    have "a \<bullet> w = a \<bullet> c" if "span ((+) (- c) ` S) \<subseteq> {x. a \<bullet> x = 0}" "w \<in> S" for w
  12.280    proof -
  12.281      have "w-c \<in> span ((+) (- c) ` S)"
  12.282 -      by (simp add: span_superset \<open>w \<in> S\<close>)
  12.283 +      by (simp add: span_base \<open>w \<in> S\<close>)
  12.284      with that have "w-c \<in> {x. a \<bullet> x = 0}"
  12.285        by blast
  12.286      then show ?thesis
  12.287 @@ -4052,10 +3910,10 @@
  12.288    have 1: "{b - a|b. b \<in> (S - {a})} \<subseteq> {x - a|x. x \<in> S}" by auto
  12.289    have 2: "x - a \<in> span {b - a |b. b \<in> S - {a}}" if "x \<in> S" for x
  12.290    proof (cases "x = a")
  12.291 -    case True then show ?thesis by simp
  12.292 +    case True then show ?thesis by (simp add: span_clauses)
  12.293    next
  12.294      case False then show ?thesis
  12.295 -      using assms by (blast intro: span_superset that)
  12.296 +      using assms by (blast intro: span_base that)
  12.297    qed
  12.298    have "\<not> affine_dependent (insert a S)"
  12.299      by (simp add: assms insert_absorb)
  12.300 @@ -5072,7 +4930,7 @@
  12.301        then have "y \<in> S"
  12.302          using assms y hull_subset[of S] affine_hull_subset_span
  12.303            inj_on_image_mem_iff [OF \<open>inj_on f (span S)\<close>]
  12.304 -        by (metis Int_iff span_inc subsetCE)
  12.305 +        by (metis Int_iff span_superset subsetCE)
  12.306      }
  12.307      then have "z \<in> f ` (rel_interior S)"
  12.308        using mem_rel_interior_cball[of x S] \<open>e > 0\<close> x by auto
  12.309 @@ -5107,7 +4965,7 @@
  12.310          using assms linear_diff[of f x xy] linear_conv_bounded_linear[of f] by auto
  12.311        moreover have *: "x - xy \<in> span S"
  12.312          using subspace_diff[of "span S" x xy] subspace_span \<open>x \<in> S\<close> xy
  12.313 -          affine_hull_subset_span[of S] span_inc
  12.314 +          affine_hull_subset_span[of S] span_superset
  12.315          by auto
  12.316        moreover from * have "e1 * norm (x - xy) \<le> norm (f (x - xy))"
  12.317          using e1 by auto
  12.318 @@ -6070,7 +5928,7 @@
  12.319  proof -
  12.320    from separating_hyperplane_set_0[OF convex_differences[OF assms(2,1)]]
  12.321    obtain a where "a \<noteq> 0" "\<forall>x\<in>{x - y |x y. x \<in> t \<and> y \<in> s}. 0 \<le> inner a x"
  12.322 -    using assms(3-5) by fastforce
  12.323 +    using assms(3-5) by force
  12.324    then have *: "\<And>x y. x \<in> t \<Longrightarrow> y \<in> s \<Longrightarrow> inner a y \<le> inner a x"
  12.325      by (force simp add: inner_diff)
  12.326    then have bdd: "bdd_above (((\<bullet>) a)`s)"
  12.327 @@ -6152,7 +6010,7 @@
  12.328  
  12.329  lemma convex_hull_scaling:
  12.330    "convex hull ((\<lambda>x. c *\<^sub>R x) ` s) = (\<lambda>x. c *\<^sub>R x) ` (convex hull s)"
  12.331 -  using linear_scaleR by (rule convex_hull_linear_image [symmetric])
  12.332 +  by (simp add: convex_hull_linear_image)
  12.333  
  12.334  lemma convex_hull_affinity:
  12.335    "convex hull ((\<lambda>x. a + c *\<^sub>R x) ` s) = (\<lambda>x. a + c *\<^sub>R x) ` (convex hull s)"
  12.336 @@ -6730,8 +6588,10 @@
  12.337    shows "connected s \<longleftrightarrow> convex s"
  12.338  proof -
  12.339    obtain f:: "'a \<Rightarrow> real" where linf: "linear f" and "inj f"
  12.340 -    using subspace_isomorphism [where 'a = 'a and 'b = real]
  12.341 -    by (metis DIM_real dim_UNIV subspace_UNIV assms)
  12.342 +    using subspace_isomorphism[OF subspace_UNIV subspace_UNIV,
  12.343 +        where 'a='a and 'b=real]
  12.344 +    unfolding Euclidean_Space.dim_UNIV
  12.345 +    by (auto simp: assms)
  12.346    then have "f -` (f ` s) = s"
  12.347      by (simp add: inj_vimage_image_eq)
  12.348    then show ?thesis
  12.349 @@ -6739,7 +6599,7 @@
  12.350  qed
  12.351  
  12.352  lemma is_interval_cball_1[intro, simp]: "is_interval (cball a b)" for a b::real
  12.353 -  by (auto simp: is_interval_convex_1 convex_cball)
  12.354 +  by (simp add: is_interval_convex_1)
  12.355  
  12.356  
  12.357  subsection%unimportant \<open>Another intermediate value theorem formulation\<close>
  12.358 @@ -6909,7 +6769,7 @@
  12.359    also have "\<dots> = (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` (convex hull {0, 1}))"
  12.360      by (simp only: convex_hull_eq_real_cbox zero_le_one)
  12.361    also have "\<dots> = (\<Sum>i\<in>Basis. convex hull ((\<lambda>x. x *\<^sub>R i) ` {0, 1}))"
  12.362 -    by (simp only: convex_hull_linear_image linear_scaleR_left)
  12.363 +    by (simp add: convex_hull_linear_image)
  12.364    also have "\<dots> = convex hull (\<Sum>i\<in>Basis. (\<lambda>x. x *\<^sub>R i) ` {0, 1})"
  12.365      by (simp only: convex_hull_set_sum)
  12.366    also have "\<dots> = convex hull {x. \<forall>i\<in>Basis. x\<bullet>i \<in> {0, 1}}"
    13.1 --- a/src/HOL/Analysis/Derivative.thy	Wed Apr 18 21:12:50 2018 +0100
    13.2 +++ b/src/HOL/Analysis/Derivative.thy	Wed May 02 13:49:38 2018 +0200
    13.3 @@ -400,7 +400,7 @@
    13.4      apply (rule linear_eq_stdbasis)
    13.5      unfolding linear_conv_bounded_linear
    13.6      apply (rule as(1,2)[THEN conjunct1])+
    13.7 -  proof (rule, rule ccontr)
    13.8 +  proof (rule ccontr)
    13.9      fix i :: 'a
   13.10      assume i: "i \<in> Basis"
   13.11      define e where "e = norm (f' i - f'' i)"
   13.12 @@ -1605,28 +1605,6 @@
   13.13    We could put \<open>f' \<circ> g = I\<close> but this happens to fit with the minimal linear
   13.14    algebra theory I've set up so far.\<close>
   13.15  
   13.16 -(* move  before left_inverse_linear in Euclidean_Space*)
   13.17 -
   13.18 -lemma right_inverse_linear:
   13.19 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a"
   13.20 -  assumes lf: "linear f"
   13.21 -    and gf: "f \<circ> g = id"
   13.22 -  shows "linear g"
   13.23 -proof -
   13.24 -  from gf have fi: "surj f"
   13.25 -    by (auto simp add: surj_def o_def id_def) metis
   13.26 -  from linear_surjective_isomorphism[OF lf fi]
   13.27 -  obtain h:: "'a \<Rightarrow> 'a" where h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x"
   13.28 -    by blast
   13.29 -  have "h = g"
   13.30 -    apply (rule ext)
   13.31 -    using gf h(2,3)
   13.32 -    apply (simp add: o_def id_def fun_eq_iff)
   13.33 -    apply metis
   13.34 -    done
   13.35 -  with h(1) show ?thesis by blast
   13.36 -qed
   13.37 -
   13.38  lemma has_derivative_inverse_strong:
   13.39    fixes f :: "'n::euclidean_space \<Rightarrow> 'n"
   13.40    assumes "open s"
   13.41 @@ -2778,7 +2756,7 @@
   13.42      "\<forall>\<^sub>F n in sequentially. ((\<lambda>x. \<Sum>i<n. ?e i x) \<longlongrightarrow> A) ?F"
   13.43      by eventually_elim
   13.44        (auto intro!: tendsto_eq_intros
   13.45 -        simp: power_0_left if_distrib cond_application_beta sum.delta
   13.46 +        simp: power_0_left if_distrib if_distribR sum.delta
   13.47          cong: if_cong)
   13.48    ultimately
   13.49    have [tendsto_intros]: "((\<lambda>x. \<Sum>i. ?e i x) \<longlongrightarrow> A) ?F"
    14.1 --- a/src/HOL/Analysis/Determinants.thy	Wed Apr 18 21:12:50 2018 +0100
    14.2 +++ b/src/HOL/Analysis/Determinants.thy	Wed May 02 13:49:38 2018 +0200
    14.3 @@ -246,52 +246,106 @@
    14.4      by simp
    14.5  qed
    14.6  
    14.7 -lemma det_identical_rows:
    14.8 -  fixes A :: "'a::linordered_idom^'n^'n"
    14.9 -  assumes ij: "i \<noteq> j"
   14.10 -    and r: "row i A = row j A"
   14.11 +lemma det_identical_columns:
   14.12 +  fixes A :: "'a::comm_ring_1^'n^'n"
   14.13 +  assumes jk: "j \<noteq> k"
   14.14 +    and r: "column j A = column k A"
   14.15    shows "det A = 0"
   14.16 -proof-
   14.17 -  have tha: "\<And>(a::'a) b. a = b \<Longrightarrow> b = - a \<Longrightarrow> a = 0"
   14.18 -    by simp
   14.19 -  have th1: "of_int (-1) = - 1" by simp
   14.20 -  let ?p = "Fun.swap i j id"
   14.21 -  let ?A = "\<chi> i. A $ ?p i"
   14.22 -  from r have "A = ?A" by (simp add: vec_eq_iff row_def Fun.swap_def)
   14.23 -  then have "det A = det ?A" by simp
   14.24 -  moreover have "det A = - det ?A"
   14.25 -    by (simp add: det_permute_rows[OF permutes_swap_id] sign_swap_id ij th1)
   14.26 -  ultimately show "det A = 0" by (metis tha)
   14.27 +proof -
   14.28 +  let ?U="UNIV::'n set"
   14.29 +  let ?t_jk="Fun.swap j k id"
   14.30 +  let ?PU="{p. p permutes ?U}"
   14.31 +  let ?S1="{p. p\<in>?PU \<and> evenperm p}"
   14.32 +  let ?S2="{(?t_jk \<circ> p) |p. p \<in>?S1}"
   14.33 +  let ?f="\<lambda>p. of_int (sign p) * (\<Prod>i\<in>UNIV. A $ i $ p i)"
   14.34 +  let ?g="\<lambda>p. ?t_jk \<circ> p"
   14.35 +  have g_S1: "?S2 = ?g` ?S1" by auto
   14.36 +  have inj_g: "inj_on ?g ?S1"
   14.37 +  proof (unfold inj_on_def, auto)
   14.38 +    fix x y assume x: "x permutes ?U" and even_x: "evenperm x"
   14.39 +      and y: "y permutes ?U" and even_y: "evenperm y" and eq: "?t_jk \<circ> x = ?t_jk \<circ> y"
   14.40 +    show "x = y" by (metis (hide_lams, no_types) comp_assoc eq id_comp swap_id_idempotent)
   14.41 +  qed
   14.42 +  have tjk_permutes: "?t_jk permutes ?U" unfolding permutes_def swap_id_eq by (auto,metis)
   14.43 +  have tjk_eq: "\<forall>i l. A $ i $ ?t_jk l  =  A $ i $ l"
   14.44 +    using r jk
   14.45 +    unfolding column_def vec_eq_iff swap_id_eq by fastforce
   14.46 +  have sign_tjk: "sign ?t_jk = -1" using sign_swap_id[of j k] jk by auto
   14.47 +  {fix x
   14.48 +    assume x: "x\<in> ?S1"
   14.49 +    have "sign (?t_jk \<circ> x) = sign (?t_jk) * sign x"
   14.50 +      by (metis (lifting) finite_class.finite_UNIV mem_Collect_eq
   14.51 +          permutation_permutes permutation_swap_id sign_compose x)
   14.52 +    also have "... = - sign x" using sign_tjk by simp
   14.53 +    also have "... \<noteq> sign x" unfolding sign_def by simp
   14.54 +    finally have "sign (?t_jk \<circ> x) \<noteq> sign x" and "(?t_jk \<circ> x) \<in> ?S2"
   14.55 +      by (auto, metis (lifting, full_types) mem_Collect_eq x)
   14.56 +  }
   14.57 +  hence disjoint: "?S1 \<inter> ?S2 = {}" by (auto, metis sign_def)
   14.58 +  have PU_decomposition: "?PU = ?S1 \<union> ?S2"
   14.59 +  proof (auto)
   14.60 +    fix x
   14.61 +    assume x: "x permutes ?U" and "\<forall>p. p permutes ?U \<longrightarrow> x = Fun.swap j k id \<circ> p \<longrightarrow> \<not> evenperm p"
   14.62 +    from this obtain p where p: "p permutes UNIV" and x_eq: "x = Fun.swap j k id \<circ> p"
   14.63 +      and odd_p: "\<not> evenperm p"
   14.64 +      by (metis (no_types) comp_assoc id_comp inv_swap_id permutes_compose
   14.65 +          permutes_inv_o(1) tjk_permutes)
   14.66 +    thus "evenperm x"
   14.67 +      by (metis evenperm_comp evenperm_swap finite_class.finite_UNIV
   14.68 +          jk permutation_permutes permutation_swap_id)
   14.69 +  next
   14.70 +    fix p assume p: "p permutes ?U"
   14.71 +    show "Fun.swap j k id \<circ> p permutes UNIV" by (metis p permutes_compose tjk_permutes)
   14.72 +  qed
   14.73 +  have "sum ?f ?S2 = sum ((\<lambda>p. of_int (sign p) * (\<Prod>i\<in>UNIV. A $ i $ p i))
   14.74 +  \<circ> (\<circ>) (Fun.swap j k id)) {p \<in> {p. p permutes UNIV}. evenperm p}"
   14.75 +    unfolding g_S1 by (rule sum.reindex[OF inj_g])
   14.76 +  also have "... = sum (\<lambda>p. of_int (sign (?t_jk \<circ> p)) * (\<Prod>i\<in>UNIV. A $ i $ p i)) ?S1"
   14.77 +    unfolding o_def by (rule sum.cong, auto simp add: tjk_eq)
   14.78 +  also have "... = sum (\<lambda>p. - ?f p) ?S1"
   14.79 +  proof (rule sum.cong, auto)
   14.80 +    fix x assume x: "x permutes ?U"
   14.81 +      and even_x: "evenperm x"
   14.82 +    hence perm_x: "permutation x" and perm_tjk: "permutation ?t_jk"
   14.83 +      using permutation_permutes[of x] permutation_permutes[of ?t_jk] permutation_swap_id
   14.84 +      by (metis finite_code)+
   14.85 +    have "(sign (?t_jk \<circ> x)) = - (sign x)"
   14.86 +      unfolding sign_compose[OF perm_tjk perm_x] sign_tjk by auto
   14.87 +    thus "of_int (sign (?t_jk \<circ> x)) * (\<Prod>i\<in>UNIV. A $ i $ x i)
   14.88 +      = - (of_int (sign x) * (\<Prod>i\<in>UNIV. A $ i $ x i))"
   14.89 +      by auto
   14.90 +  qed
   14.91 +  also have "...= - sum ?f ?S1" unfolding sum_negf ..
   14.92 +  finally have *: "sum ?f ?S2 = - sum ?f ?S1" .
   14.93 +  have "det A = (\<Sum>p | p permutes UNIV. of_int (sign p) * (\<Prod>i\<in>UNIV. A $ i $ p i))"
   14.94 +    unfolding det_def ..
   14.95 +  also have "...= sum ?f ?S1 + sum ?f ?S2"
   14.96 +    by (subst PU_decomposition, rule sum.union_disjoint[OF _ _ disjoint], auto)
   14.97 +  also have "...= sum ?f ?S1 - sum ?f ?S1 " unfolding * by auto
   14.98 +  also have "...= 0" by simp
   14.99 +  finally show "det A = 0" by simp
  14.100  qed
  14.101  
  14.102 -lemma det_identical_columns:
  14.103 -  fixes A :: "'a::linordered_idom^'n^'n"
  14.104 +lemma det_identical_rows:
  14.105 +  fixes A :: "'a::comm_ring_1^'n^'n"
  14.106    assumes ij: "i \<noteq> j"
  14.107 -    and r: "column i A = column j A"
  14.108 +  and r: "row i A = row j A"
  14.109    shows "det A = 0"
  14.110    apply (subst det_transpose[symmetric])
  14.111 -  apply (rule det_identical_rows[OF ij])
  14.112 -  apply (metis row_transpose r)
  14.113 +  apply (rule det_identical_columns[OF ij])
  14.114 +  apply (metis column_transpose r)
  14.115    done
  14.116  
  14.117  lemma det_zero_row:
  14.118 -  fixes A :: "'a::{idom, ring_char_0}^'n^'n"
  14.119 -  assumes r: "row i A = 0"
  14.120 -  shows "det A = 0"
  14.121 -  using r
  14.122 -  apply (simp add: row_def det_def vec_eq_iff)
  14.123 -  apply (rule sum.neutral)
  14.124 -  apply (auto simp: sign_nz)
  14.125 -  done
  14.126 +  fixes A :: "'a::{idom, ring_char_0}^'n^'n" and F :: "'b::{field}^'m^'m"
  14.127 +  shows "row i A = 0 \<Longrightarrow> det A = 0" and "row j F = 0 \<Longrightarrow> det F = 0"
  14.128 +  by (force simp add: row_def det_def vec_eq_iff sign_nz intro!: sum.neutral)+
  14.129  
  14.130  lemma det_zero_column:
  14.131 -  fixes A :: "'a::{idom,ring_char_0}^'n^'n"
  14.132 -  assumes r: "column i A = 0"
  14.133 -  shows "det A = 0"
  14.134 -  apply (subst det_transpose[symmetric])
  14.135 -  apply (rule det_zero_row [of i])
  14.136 -  apply (metis row_transpose r)
  14.137 -  done
  14.138 +  fixes A :: "'a::{idom, ring_char_0}^'n^'n" and F :: "'b::{field}^'m^'m"
  14.139 +  shows "column i A = 0 \<Longrightarrow> det A = 0" and "column j F = 0 \<Longrightarrow> det F = 0"
  14.140 +  unfolding atomize_conj atomize_imp
  14.141 +  by (metis det_transpose det_zero_row row_transpose)
  14.142  
  14.143  lemma det_row_add:
  14.144    fixes a b c :: "'n::finite \<Rightarrow> _ ^ 'n"
  14.145 @@ -404,7 +458,7 @@
  14.146    done
  14.147  
  14.148  lemma det_row_operation:
  14.149 -  fixes A :: "'a::linordered_idom^'n^'n"
  14.150 +  fixes A :: "'a::{comm_ring_1}^'n^'n"
  14.151    assumes ij: "i \<noteq> j"
  14.152    shows "det (\<chi> k. if k = i then row i A + c *s row j A else row k A) = det A"
  14.153  proof -
  14.154 @@ -418,50 +472,35 @@
  14.155  qed
  14.156  
  14.157  lemma det_row_span:
  14.158 -  fixes A :: "real^'n^'n"
  14.159 -  assumes x: "x \<in> span {row j A |j. j \<noteq> i}"
  14.160 +  fixes A :: "'a::{field}^'n^'n"
  14.161 +  assumes x: "x \<in> vec.span {row j A |j. j \<noteq> i}"
  14.162    shows "det (\<chi> k. if k = i then row i A + x else row k A) = det A"
  14.163 -proof -
  14.164 -  let ?U = "UNIV :: 'n set"
  14.165 -  let ?S = "{row j A |j. j \<noteq> i}"
  14.166 +  using x
  14.167 +proof (induction rule: vec.span_induct_alt)
  14.168 +  case 1
  14.169 +  then show ?case
  14.170 +    by (rule cong[of det, OF refl]) (vector row_def)
  14.171 +next
  14.172 +  case (2 c z y)
  14.173 +  note zS = 2(1)
  14.174 +    and Py = 2(2)
  14.175    let ?d = "\<lambda>x. det (\<chi> k. if k = i then x else row k A)"
  14.176    let ?P = "\<lambda>x. ?d (row i A + x) = det A"
  14.177 -  {
  14.178 -    fix k
  14.179 -    have "(if k = i then row i A + 0 else row k A) = row k A"
  14.180 -      by simp
  14.181 -  }
  14.182 -  then have P0: "?P 0"
  14.183 -    apply -
  14.184 -    apply (rule cong[of det, OF refl])
  14.185 +  from zS obtain j where j: "z = row j A" "i \<noteq> j"
  14.186 +    by blast
  14.187 +  let ?w = "row i A + y"
  14.188 +  have th0: "row i A + (c*s z + y) = ?w + c*s z"
  14.189 +    by vector
  14.190 +  have thz: "?d z = 0"
  14.191 +    apply (rule det_identical_rows[OF j(2)])
  14.192 +    using j
  14.193      apply (vector row_def)
  14.194      done
  14.195 -  moreover
  14.196 -  {
  14.197 -    fix c z y
  14.198 -    assume zS: "z \<in> ?S" and Py: "?P y"
  14.199 -    from zS obtain j where j: "z = row j A" "i \<noteq> j"
  14.200 -      by blast
  14.201 -    let ?w = "row i A + y"
  14.202 -    have th0: "row i A + (c*s z + y) = ?w + c*s z"
  14.203 -      by vector
  14.204 -    have thz: "?d z = 0"
  14.205 -      apply (rule det_identical_rows[OF j(2)])
  14.206 -      using j
  14.207 -      apply (vector row_def)
  14.208 -      done
  14.209 -    have "?d (row i A + (c*s z + y)) = ?d (?w + c*s z)"
  14.210 -      unfolding th0 ..
  14.211 -    then have "?P (c*s z + y)"
  14.212 -      unfolding thz Py det_row_mul[of i] det_row_add[of i]
  14.213 -      by simp
  14.214 -  }
  14.215 -  ultimately show ?thesis
  14.216 -    apply -
  14.217 -    apply (rule span_induct_alt[of ?P ?S, OF P0, folded scalar_mult_eq_scaleR])
  14.218 -    apply blast
  14.219 -    apply (rule x)
  14.220 -    done
  14.221 +  have "?d (row i A + (c*s z + y)) = ?d (?w + c*s z)"
  14.222 +    unfolding th0 ..
  14.223 +  then show ?case
  14.224 +    unfolding thz Py det_row_mul[of i] det_row_add[of i]
  14.225 +    by simp
  14.226  qed
  14.227  
  14.228  lemma matrix_id [simp]: "det (matrix id) = 1"
  14.229 @@ -469,7 +508,7 @@
  14.230  
  14.231  lemma det_matrix_scaleR [simp]: "det (matrix ((( *\<^sub>R) r)) :: real^'n^'n) = r ^ CARD('n::finite)"
  14.232    apply (subst det_diagonal)
  14.233 -   apply (auto simp: matrix_def mat_def prod_constant)
  14.234 +   apply (auto simp: matrix_def mat_def)
  14.235    apply (simp add: cart_eq_inner_axis inner_axis_axis)
  14.236    done
  14.237  
  14.238 @@ -479,13 +518,13 @@
  14.239  \<close>
  14.240  
  14.241  lemma det_dependent_rows:
  14.242 -  fixes A:: "real^'n^'n"
  14.243 -  assumes d: "dependent (rows A)"
  14.244 +  fixes A:: "'a::{field}^'n^'n"
  14.245 +  assumes d: "vec.dependent (rows A)"
  14.246    shows "det A = 0"
  14.247  proof -
  14.248    let ?U = "UNIV :: 'n set"
  14.249 -  from d obtain i where i: "row i A \<in> span (rows A - {row i A})"
  14.250 -    unfolding dependent_def rows_def by blast
  14.251 +  from d obtain i where i: "row i A \<in> vec.span (rows A - {row i A})"
  14.252 +    unfolding vec.dependent_def rows_def by blast
  14.253    {
  14.254      fix j k
  14.255      assume jk: "j \<noteq> k" and c: "row j A = row k A"
  14.256 @@ -494,25 +533,25 @@
  14.257    moreover
  14.258    {
  14.259      assume H: "\<And> i j. i \<noteq> j \<Longrightarrow> row i A \<noteq> row j A"
  14.260 -    have th0: "- row i A \<in> span {row j A|j. j \<noteq> i}"
  14.261 -      apply (rule span_neg)
  14.262 +    have th0: "- row i A \<in> vec.span {row j A|j. j \<noteq> i}"
  14.263 +      apply (rule vec.span_neg)
  14.264        apply (rule set_rev_mp)
  14.265        apply (rule i)
  14.266 -      apply (rule span_mono)
  14.267 +      apply (rule vec.span_mono)
  14.268        using H i
  14.269        apply (auto simp add: rows_def)
  14.270        done
  14.271      from det_row_span[OF th0]
  14.272      have "det A = det (\<chi> k. if k = i then 0 *s 1 else row k A)"
  14.273        unfolding right_minus vector_smult_lzero ..
  14.274 -    with det_row_mul[of i "0::real" "\<lambda>i. 1"]
  14.275 +    with det_row_mul[of i "0::'a" "\<lambda>i. 1"]
  14.276      have "det A = 0" by simp
  14.277    }
  14.278    ultimately show ?thesis by blast
  14.279  qed
  14.280  
  14.281  lemma det_dependent_columns:
  14.282 -  assumes d: "dependent (columns (A::real^'n^'n))"
  14.283 +  assumes d: "vec.dependent (columns (A::real^'n^'n))"
  14.284    shows "det A = 0"
  14.285    by (metis d det_dependent_rows rows_transpose det_transpose)
  14.286  
  14.287 @@ -647,7 +686,7 @@
  14.288  qed rule
  14.289  
  14.290  lemma det_mul:
  14.291 -  fixes A B :: "'a::linordered_idom^'n^'n"
  14.292 +  fixes A B :: "'a::comm_ring_1^'n^'n"
  14.293    shows "det (A ** B) = det A * det B"
  14.294  proof -
  14.295    let ?U = "UNIV :: 'n set"
  14.296 @@ -767,30 +806,21 @@
  14.297    finally show ?thesis unfolding th2 .
  14.298  qed
  14.299  
  14.300 +
  14.301  subsection \<open>Relation to invertibility.\<close>
  14.302  
  14.303 -lemma invertible_left_inverse:
  14.304 -  fixes A :: "real^'n^'n"
  14.305 -  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). B** A = mat 1)"
  14.306 -  by (metis invertible_def matrix_left_right_inverse)
  14.307 -
  14.308 -lemma invertible_right_inverse:
  14.309 -  fixes A :: "real^'n^'n"
  14.310 -  shows "invertible A \<longleftrightarrow> (\<exists>(B::real^'n^'n). A** B = mat 1)"
  14.311 -  by (metis invertible_def matrix_left_right_inverse)
  14.312 -
  14.313  lemma invertible_det_nz:
  14.314 -  fixes A::"real ^'n^'n"
  14.315 +  fixes A::"'a::{field}^'n^'n"
  14.316    shows "invertible A \<longleftrightarrow> det A \<noteq> 0"
  14.317  proof -
  14.318    {
  14.319      assume "invertible A"
  14.320 -    then obtain B :: "real ^'n^'n" where B: "A ** B = mat 1"
  14.321 +    then obtain B :: "'a^'n^'n" where B: "A ** B = mat 1"
  14.322        unfolding invertible_right_inverse by blast
  14.323 -    then have "det (A ** B) = det (mat 1 :: real ^'n^'n)"
  14.324 +    then have "det (A ** B) = det (mat 1 :: 'a^'n^'n)"
  14.325        by simp
  14.326      then have "det A \<noteq> 0"
  14.327 -      by (simp add: det_mul det_I) algebra
  14.328 +      by (simp add: det_mul) algebra
  14.329    }
  14.330    moreover
  14.331    {
  14.332 @@ -804,37 +834,41 @@
  14.333        unfolding invertible_right_inverse
  14.334        unfolding matrix_right_invertible_independent_rows
  14.335        by blast
  14.336 -    have *: "\<And>(a::real^'n) b. a + b = 0 \<Longrightarrow> -a = b"
  14.337 +    have *: "\<And>(a::'a^'n) b. a + b = 0 \<Longrightarrow> -a = b"
  14.338        apply (drule_tac f="(+) (- a)" in cong[OF refl])
  14.339        apply (simp only: ab_left_minus add.assoc[symmetric])
  14.340        apply simp
  14.341        done
  14.342 +    from c ci
  14.343      have thr0: "- row i A = sum (\<lambda>j. (1/ c i) *s (c j *s row j A)) (?U - {i})"
  14.344 +      unfolding sum.remove[OF fU iU] sum_cmul
  14.345 +      apply -
  14.346        apply (rule vector_mul_lcancel_imp[OF ci])
  14.347 -      using c ci  unfolding sum.remove[OF fU iU] sum_cmul
  14.348 -      apply (auto simp add: field_simps *)
  14.349 +      apply (auto simp add: field_simps)
  14.350 +      unfolding *
  14.351 +      apply rule
  14.352        done
  14.353 -    have thr: "- row i A \<in> span {row j A| j. j \<noteq> i}"
  14.354 +    have thr: "- row i A \<in> vec.span {row j A| j. j \<noteq> i}"
  14.355        unfolding thr0
  14.356 -      apply (rule span_sum)
  14.357 +      apply (rule vec.span_sum)
  14.358        apply simp
  14.359 -      apply (rule span_mul [where 'a="real^'n"])
  14.360 -      apply (rule span_superset)
  14.361 +      apply (rule vec.span_scale[folded scalar_mult_eq_scaleR])+
  14.362 +      apply (rule vec.span_base)
  14.363        apply auto
  14.364        done
  14.365 -    let ?B = "(\<chi> k. if k = i then 0 else row k A) :: real ^'n^'n"
  14.366 +    let ?B = "(\<chi> k. if k = i then 0 else row k A) :: 'a^'n^'n"
  14.367      have thrb: "row i ?B = 0" using iU by (vector row_def)
  14.368      have "det A = 0"
  14.369        unfolding det_row_span[OF thr, symmetric] right_minus
  14.370 -      unfolding det_zero_row[OF thrb] ..
  14.371 +      unfolding det_zero_row(2)[OF thrb] ..
  14.372    }
  14.373    ultimately show ?thesis
  14.374      by blast
  14.375  qed
  14.376  
  14.377 -lemma det_nz_iff_inj:
  14.378 -  fixes f :: "real^'n \<Rightarrow> real^'n"
  14.379 -  assumes "linear f"
  14.380 +lemma det_nz_iff_inj_gen:
  14.381 +  fixes f :: "'a::field^'n \<Rightarrow> 'a::field^'n"
  14.382 +  assumes "Vector_Spaces.linear ( *s) ( *s) f"
  14.383    shows "det (matrix f) \<noteq> 0 \<longleftrightarrow> inj f"
  14.384  proof
  14.385    assume "det (matrix f) \<noteq> 0"
  14.386 @@ -843,10 +877,17 @@
  14.387  next
  14.388    assume "inj f"
  14.389    show "det (matrix f) \<noteq> 0"
  14.390 -    using linear_injective_left_inverse [OF assms \<open>inj f\<close>]
  14.391 -    by (metis assms invertible_det_nz invertible_left_inverse matrix_compose matrix_id_mat_1)
  14.392 +    using vec.linear_injective_left_inverse [OF assms \<open>inj f\<close>]
  14.393 +    by (metis assms invertible_det_nz invertible_left_inverse matrix_compose_gen matrix_id_mat_1)
  14.394  qed
  14.395  
  14.396 +lemma det_nz_iff_inj:
  14.397 +  fixes f :: "real^'n \<Rightarrow> real^'n"
  14.398 +  assumes "linear f"
  14.399 +  shows "det (matrix f) \<noteq> 0 \<longleftrightarrow> inj f"
  14.400 +  using det_nz_iff_inj_gen[of f] assms
  14.401 +  unfolding linear_matrix_vector_mul_eq .
  14.402 +
  14.403  lemma det_eq_0_rank:
  14.404    fixes A :: "real^'n^'n"
  14.405    shows "det A = 0 \<longleftrightarrow> rank A < CARD('n)"
  14.406 @@ -855,71 +896,88 @@
  14.407  
  14.408  subsubsection\<open>Invertibility of matrices and corresponding linear functions\<close>
  14.409  
  14.410 -lemma matrix_left_invertible:
  14.411 -  fixes f :: "real^'m \<Rightarrow> real^'n"
  14.412 -  assumes "linear f"
  14.413 -  shows "((\<exists>B. B ** matrix f = mat 1) \<longleftrightarrow> (\<exists>g. linear g \<and> g \<circ> f = id))"
  14.414 +lemma matrix_left_invertible_gen:
  14.415 +  fixes f :: "'a::field^'m \<Rightarrow> 'a::field^'n"
  14.416 +  assumes "Vector_Spaces.linear ( *s) ( *s) f"
  14.417 +  shows "((\<exists>B. B ** matrix f = mat 1) \<longleftrightarrow> (\<exists>g. Vector_Spaces.linear ( *s) ( *s) g \<and> g \<circ> f = id))"
  14.418  proof safe
  14.419    fix B
  14.420    assume 1: "B ** matrix f = mat 1"
  14.421 -  show "\<exists>g. linear g \<and> g \<circ> f = id"
  14.422 +  show "\<exists>g. Vector_Spaces.linear ( *s) ( *s) g \<and> g \<circ> f = id"
  14.423    proof (intro exI conjI)
  14.424 -    show "linear (\<lambda>y. B *v y)"
  14.425 -      by (simp add: matrix_vector_mul_linear)
  14.426 +    show "Vector_Spaces.linear ( *s) ( *s) (\<lambda>y. B *v y)"
  14.427 +      by (simp add:)
  14.428      show "(( *v) B) \<circ> f = id"
  14.429        unfolding o_def
  14.430 -      by (metis assms 1 eq_id_iff matrix_vector_mul matrix_vector_mul_assoc matrix_vector_mul_lid)
  14.431 +      by (metis assms 1 eq_id_iff matrix_vector_mul(1) matrix_vector_mul_assoc matrix_vector_mul_lid)
  14.432    qed
  14.433  next
  14.434    fix g
  14.435 -  assume "linear g" "g \<circ> f = id"
  14.436 +  assume "Vector_Spaces.linear ( *s) ( *s) g" "g \<circ> f = id"
  14.437    then have "matrix g ** matrix f = mat 1"
  14.438 -    by (metis assms matrix_compose matrix_id_mat_1)
  14.439 +    by (metis assms matrix_compose_gen matrix_id_mat_1)
  14.440    then show "\<exists>B. B ** matrix f = mat 1" ..
  14.441  qed
  14.442  
  14.443 -lemma matrix_right_invertible:
  14.444 -  fixes f :: "real^'m \<Rightarrow> real^'n"
  14.445 -  assumes "linear f"
  14.446 -  shows "((\<exists>B. matrix f ** B = mat 1) \<longleftrightarrow> (\<exists>g. linear g \<and> f \<circ> g = id))"
  14.447 +lemma matrix_left_invertible:
  14.448 +  "linear f \<Longrightarrow> ((\<exists>B. B ** matrix f = mat 1) \<longleftrightarrow> (\<exists>g. linear g \<and> g \<circ> f = id))" for f::"real^'m \<Rightarrow> real^'n"
  14.449 +  using matrix_left_invertible_gen[of f]
  14.450 +  by (auto simp: linear_matrix_vector_mul_eq)
  14.451 +
  14.452 +lemma matrix_right_invertible_gen:
  14.453 +  fixes f :: "'a::field^'m \<Rightarrow> 'a^'n"
  14.454 +  assumes "Vector_Spaces.linear ( *s) ( *s) f"
  14.455 +  shows "((\<exists>B. matrix f ** B = mat 1) \<longleftrightarrow> (\<exists>g. Vector_Spaces.linear ( *s) ( *s) g \<and> f \<circ> g = id))"
  14.456  proof safe
  14.457    fix B
  14.458    assume 1: "matrix f ** B = mat 1"
  14.459 -  show "\<exists>g. linear g \<and> f \<circ> g = id"
  14.460 +  show "\<exists>g. Vector_Spaces.linear ( *s) ( *s) g \<and> f \<circ> g = id"
  14.461    proof (intro exI conjI)
  14.462 -    show "linear (( *v) B)"
  14.463 -      by (simp add: matrix_vector_mul_linear)
  14.464 +    show "Vector_Spaces.linear ( *s) ( *s) (( *v) B)"
  14.465 +      by (simp add: )
  14.466      show "f \<circ> ( *v) B = id"
  14.467 -      by (metis 1 assms comp_apply eq_id_iff linear_id matrix_id_mat_1 matrix_vector_mul_assoc matrix_works)
  14.468 +      using 1 assms comp_apply eq_id_iff vec.linear_id matrix_id_mat_1 matrix_vector_mul_assoc matrix_works
  14.469 +      by (metis (no_types, hide_lams))
  14.470    qed
  14.471  next
  14.472    fix g
  14.473 -  assume "linear g" and "f \<circ> g = id"
  14.474 +  assume "Vector_Spaces.linear ( *s) ( *s) g" and "f \<circ> g = id"
  14.475    then have "matrix f ** matrix g = mat 1"
  14.476 -    by (metis assms matrix_compose matrix_id_mat_1)
  14.477 +    by (metis assms matrix_compose_gen matrix_id_mat_1)
  14.478    then show "\<exists>B. matrix f ** B = mat 1" ..
  14.479  qed
  14.480  
  14.481 +lemma matrix_right_invertible:
  14.482 +  "linear f \<Longrightarrow> ((\<exists>B. matrix f ** B = mat 1) \<longleftrightarrow> (\<exists>g. linear g \<and> f \<circ> g = id))" for f::"real^'m \<Rightarrow> real^'n"
  14.483 +  using matrix_right_invertible_gen[of f]
  14.484 +  by (auto simp: linear_matrix_vector_mul_eq)
  14.485 +
  14.486 +lemma matrix_invertible_gen:
  14.487 +  fixes f :: "'a::field^'m \<Rightarrow> 'a::field^'n"
  14.488 +  assumes "Vector_Spaces.linear ( *s) ( *s) f"
  14.489 +  shows  "invertible (matrix f) \<longleftrightarrow> (\<exists>g. Vector_Spaces.linear ( *s) ( *s) g \<and> f \<circ> g = id \<and> g \<circ> f = id)"
  14.490 +    (is "?lhs = ?rhs")
  14.491 +proof
  14.492 +  assume ?lhs then show ?rhs
  14.493 +    by (metis assms invertible_def left_right_inverse_eq matrix_left_invertible_gen matrix_right_invertible_gen)
  14.494 +next
  14.495 +  assume ?rhs then show ?lhs
  14.496 +    by (metis assms invertible_def matrix_compose_gen matrix_id_mat_1)
  14.497 +qed
  14.498 +
  14.499  lemma matrix_invertible:
  14.500 -  fixes f :: "real^'m \<Rightarrow> real^'n"
  14.501 -  assumes "linear f"
  14.502 -  shows  "invertible (matrix f) \<longleftrightarrow> (\<exists>g. linear g \<and> f \<circ> g = id \<and> g \<circ> f = id)"
  14.503 -    (is "?lhs = ?rhs")
  14.504 -proof
  14.505 -  assume ?lhs then show ?rhs
  14.506 -    by (metis assms invertible_def left_right_inverse_eq matrix_left_invertible matrix_right_invertible)
  14.507 -next
  14.508 -  assume ?rhs then show ?lhs
  14.509 -    by (metis assms invertible_def matrix_compose matrix_id_mat_1)
  14.510 -qed
  14.511 +  "linear f \<Longrightarrow> invertible (matrix f) \<longleftrightarrow> (\<exists>g. linear g \<and> f \<circ> g = id \<and> g \<circ> f = id)"
  14.512 +  for f::"real^'m \<Rightarrow> real^'n"
  14.513 +  using matrix_invertible_gen[of f]
  14.514 +  by (auto simp: linear_matrix_vector_mul_eq)
  14.515  
  14.516  lemma invertible_eq_bij:
  14.517 -  fixes m :: "real^'m^'n"
  14.518 +  fixes m :: "'a::field^'m^'n"
  14.519    shows "invertible m \<longleftrightarrow> bij (( *v) m)"
  14.520 -  using matrix_invertible [OF matrix_vector_mul_linear] o_bij
  14.521 -  apply (auto simp: bij_betw_def)
  14.522 -  by (metis left_right_inverse_eq  linear_injective_left_inverse [OF matrix_vector_mul_linear]
  14.523 -            linear_surjective_right_inverse[OF matrix_vector_mul_linear])
  14.524 +  using matrix_invertible_gen[OF matrix_vector_mul_linear_gen, of m, simplified matrix_of_matrix_vector_mul]
  14.525 +  by (metis bij_betw_def left_right_inverse_eq matrix_vector_mul_linear_gen o_bij
  14.526 +      vec.linear_injective_left_inverse vec.linear_surjective_right_inverse)
  14.527 +
  14.528  
  14.529  subsection \<open>Cramer's rule.\<close>
  14.530  
  14.531 @@ -947,9 +1005,9 @@
  14.532      by simp
  14.533    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"
  14.534      apply (rule det_row_span)
  14.535 -    apply (rule span_sum)
  14.536 -    apply (rule span_mul [where 'a="real^'n", folded scalar_mult_eq_scaleR])
  14.537 -    apply (rule span_superset)
  14.538 +    apply (rule vec.span_sum)
  14.539 +    apply (rule vec.span_scale)
  14.540 +    apply (rule vec.span_base)
  14.541      apply auto
  14.542      done
  14.543    show "?lhs = x$k * det A"
  14.544 @@ -972,7 +1030,7 @@
  14.545  proof -
  14.546    let ?U = "UNIV :: 'n set"
  14.547    have *: "\<And>c. sum (\<lambda>i. c i *s row i (transpose A)) ?U = sum (\<lambda>i. c i *s column i A) ?U"
  14.548 -    by (auto simp add: row_transpose intro: sum.cong)
  14.549 +    by (auto intro: sum.cong)
  14.550    show ?thesis
  14.551      unfolding matrix_mult_sum
  14.552      unfolding cramer_lemma_transpose[of k x "transpose A", unfolded det_transpose, symmetric]
  14.553 @@ -992,7 +1050,7 @@
  14.554      unfolding invertible_det_nz[symmetric] invertible_def
  14.555      by blast
  14.556    have "(A ** B) *v b = b"
  14.557 -    by (simp add: B matrix_vector_mul_lid)
  14.558 +    by (simp add: B)
  14.559    then have "A *v (B *v b) = b"
  14.560      by (simp add: matrix_vector_mul_assoc)
  14.561    then have xe: "\<exists>x. A *v x = b"
  14.562 @@ -1021,7 +1079,7 @@
  14.563    apply auto
  14.564    apply (erule_tac x=v in allE)+
  14.565    apply (simp add: norm_eq_sqrt_inner)
  14.566 -  apply (simp add: dot_norm  linear_add[symmetric])
  14.567 +  apply (simp add: dot_norm linear_add[symmetric])
  14.568    done
  14.569  
  14.570  lemma orthogonal_transformation_id [simp]: "orthogonal_transformation (\<lambda>x. x)"
  14.571 @@ -1033,7 +1091,7 @@
  14.572  
  14.573  lemma orthogonal_transformation_compose:
  14.574     "\<lbrakk>orthogonal_transformation f; orthogonal_transformation g\<rbrakk> \<Longrightarrow> orthogonal_transformation(f \<circ> g)"
  14.575 -  by (simp add: orthogonal_transformation_def linear_compose)
  14.576 +  by (auto simp add: orthogonal_transformation_def linear_compose)
  14.577  
  14.578  lemma orthogonal_transformation_neg:
  14.579    "orthogonal_transformation(\<lambda>x. -(f x)) \<longleftrightarrow> orthogonal_transformation f"
  14.580 @@ -1074,7 +1132,7 @@
  14.581    by (metis matrix_left_right_inverse orthogonal_matrix_def)
  14.582  
  14.583  lemma orthogonal_matrix_id: "orthogonal_matrix (mat 1 :: _^'n^'n)"
  14.584 -  by (simp add: orthogonal_matrix_def transpose_mat matrix_mul_lid)
  14.585 +  by (simp add: orthogonal_matrix_def)
  14.586  
  14.587  lemma orthogonal_matrix_mul:
  14.588    fixes A :: "real ^'n^'n"
  14.589 @@ -1085,7 +1143,7 @@
  14.590    unfolding orthogonal_matrix matrix_transpose_mul
  14.591    apply (subst matrix_mul_assoc)
  14.592    apply (subst matrix_mul_assoc[symmetric])
  14.593 -  apply (simp add: matrix_mul_rid)
  14.594 +  apply (simp add: )
  14.595    done
  14.596  
  14.597  lemma orthogonal_transformation_matrix:
  14.598 @@ -1100,8 +1158,9 @@
  14.599    let ?m1 = "mat 1 :: real ^'n^'n"
  14.600    {
  14.601      assume ot: ?ot
  14.602 -    from ot have lf: "linear f" and fd: "\<forall>v w. f v \<bullet> f w = v \<bullet> w"
  14.603 -      unfolding  orthogonal_transformation_def orthogonal_matrix by blast+
  14.604 +    from ot have lf: "Vector_Spaces.linear ( *s) ( *s) f" and fd: "\<forall>v w. f v \<bullet> f w = v \<bullet> w"
  14.605 +      unfolding orthogonal_transformation_def orthogonal_matrix linear_def scalar_mult_eq_scaleR
  14.606 +      by blast+
  14.607      {
  14.608        fix i j
  14.609        let ?A = "transpose ?mf ** ?mf"
  14.610 @@ -1118,20 +1177,21 @@
  14.611        unfolding orthogonal_matrix
  14.612        by vector
  14.613      with lf have ?rhs
  14.614 +      unfolding linear_def scalar_mult_eq_scaleR
  14.615        by blast
  14.616    }
  14.617    moreover
  14.618    {
  14.619 -    assume lf: "linear f" and om: "orthogonal_matrix ?mf"
  14.620 +    assume lf: "Vector_Spaces.linear ( *s) ( *s) f" and om: "orthogonal_matrix ?mf"
  14.621      from lf om have ?lhs
  14.622        apply (simp only: orthogonal_matrix_def norm_eq orthogonal_transformation)
  14.623        apply (simp only: matrix_works[OF lf, symmetric])
  14.624        apply (subst dot_matrix_vector_mul)
  14.625 -      apply (simp add: dot_matrix_product matrix_mul_lid)
  14.626 +      apply (simp add: dot_matrix_product linear_def scalar_mult_eq_scaleR)
  14.627        done
  14.628    }
  14.629    ultimately show ?thesis
  14.630 -    by blast
  14.631 +    by (auto simp: linear_def scalar_mult_eq_scaleR)
  14.632  qed
  14.633  
  14.634  lemma det_orthogonal_matrix:
  14.635 @@ -1159,7 +1219,7 @@
  14.636    then have "det (Q ** transpose Q) = det (mat 1:: 'a^'n^'n)"
  14.637      by simp
  14.638    then have "det Q * det Q = 1"
  14.639 -    by (simp add: det_mul det_I det_transpose)
  14.640 +    by (simp add: det_mul)
  14.641    then show ?thesis unfolding th .
  14.642  qed
  14.643  
  14.644 @@ -1266,9 +1326,9 @@
  14.645  proof -
  14.646    obtain S where "a \<in> S" "pairwise orthogonal S" and noS: "\<And>x. x \<in> S \<Longrightarrow> norm x = 1"
  14.647     and "independent S" "card S = CARD('n)" "span S = UNIV"
  14.648 -    using vector_in_orthonormal_basis assms by force
  14.649 -  with independent_imp_finite obtain f0 where "bij_betw f0 (UNIV::'n set) S"
  14.650 -    by (metis finite_class.finite_UNIV finite_same_card_bij)
  14.651 +    using vector_in_orthonormal_basis assms by (force simp: )
  14.652 +  then obtain f0 where "bij_betw f0 (UNIV::'n set) S"
  14.653 +    by (metis finite_class.finite_UNIV finite_same_card_bij finiteI_independent)
  14.654    then obtain f where f: "bij_betw f (UNIV::'n set) S" and a: "a = f k"
  14.655      using bij_swap_iff [of k "inv f0 a" f0]
  14.656      by (metis UNIV_I \<open>a \<in> S\<close> bij_betw_inv_into_right bij_betw_swap_iff swap_apply1)
  14.657 @@ -1299,7 +1359,8 @@
  14.658    show thesis
  14.659    proof
  14.660      show "orthogonal_transformation ?f"
  14.661 -      by (simp add: AB orthogonal_matrix_mul matrix_vector_mul_linear orthogonal_transformation_matrix)
  14.662 +      by (subst orthogonal_transformation_matrix)
  14.663 +        (auto simp: AB orthogonal_matrix_mul)
  14.664    next
  14.665      show "?f a = b"
  14.666        using \<open>orthogonal_matrix A\<close> unfolding orthogonal_matrix_def
  14.667 @@ -1321,10 +1382,10 @@
  14.668      by (auto intro: orthogonal_transformation_exists_1 [of "a /\<^sub>R norm a" "b /\<^sub>R norm b"])
  14.669    show ?thesis
  14.670    proof
  14.671 -    have "linear f"
  14.672 +    interpret linear f
  14.673        using f by (simp add: orthogonal_transformation_linear)
  14.674 -    then have "f a /\<^sub>R norm a = f (a /\<^sub>R norm a)"
  14.675 -      by (simp add: linear_cmul [of f])
  14.676 +    have "f a /\<^sub>R norm a = f (a /\<^sub>R norm a)"
  14.677 +      by (simp add: scale)
  14.678      also have "\<dots> = b /\<^sub>R norm a"
  14.679        by (simp add: eq assms [symmetric])
  14.680      finally show "f a = b"
  14.681 @@ -1453,7 +1514,7 @@
  14.682    by (simp add: eval_nat_numeral atLeastAtMostSuc_conv mult.commute)
  14.683  
  14.684  lemma det_1: "det (A::'a::comm_ring_1^1^1) = A$1$1"
  14.685 -  by (simp add: det_def of_nat_Suc sign_id)
  14.686 +  by (simp add: det_def sign_id)
  14.687  
  14.688  lemma det_2: "det (A::'a::comm_ring_1^2^2) = A$1$1 * A$2$2 - A$1$2 * A$2$1"
  14.689  proof -
  14.690 @@ -1563,9 +1624,14 @@
  14.691      by (metis eq_id_iff matrix_id orthogonal_transformation_id that)
  14.692  next
  14.693    case False
  14.694 -  with that show thesis
  14.695 -    by (auto simp: eq linear_cmul orthogonal_transformation_def
  14.696 -             intro: rotation_exists_1 [of "a /\<^sub>R norm a" "b /\<^sub>R norm b", OF 2])
  14.697 +  then obtain f where f: "orthogonal_transformation f" "det (matrix f) = 1"
  14.698 +    and f': "f (a /\<^sub>R norm a) = b /\<^sub>R norm b"
  14.699 +    using rotation_exists_1 [of "a /\<^sub>R norm a" "b /\<^sub>R norm b", OF 2] by auto
  14.700 +  then interpret linear f by (simp add: orthogonal_transformation)
  14.701 +  have "f a = b"
  14.702 +    using f' False
  14.703 +    by (simp add: eq scale)
  14.704 +  with f show thesis ..
  14.705  qed
  14.706  
  14.707  lemma rotation_rightward_line:
    15.1 --- a/src/HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy	Wed Apr 18 21:12:50 2018 +0100
    15.2 +++ b/src/HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy	Wed May 02 13:49:38 2018 +0200
    15.3 @@ -1226,7 +1226,7 @@
    15.4    have "negligible (span S)"
    15.5      using \<open>a \<noteq> 0\<close> a negligible_hyperplane by (blast intro: negligible_subset)
    15.6    then show ?thesis
    15.7 -    using span_inc by (blast intro: negligible_subset)
    15.8 +    using span_base by (blast intro: negligible_subset)
    15.9  qed
   15.10  
   15.11  proposition negligible_convex_frontier:
   15.12 @@ -1240,7 +1240,7 @@
   15.13                 and spanB: "S \<subseteq> span B" and cardB: "card B = dim S"
   15.14        by (metis basis_exists)
   15.15      consider "dim S < DIM('N)" | "dim S = DIM('N)"
   15.16 -      using dim_subset_UNIV le_eq_less_or_eq by blast
   15.17 +      using dim_subset_UNIV le_eq_less_or_eq by auto
   15.18      then show ?thesis
   15.19      proof cases
   15.20        case 1
   15.21 @@ -2848,8 +2848,12 @@
   15.22              show "negligible (frontier (g ` K \<inter> g ` L))"
   15.23                by (simp add: negligible_convex_frontier convex_Int conv convex_linear_image that)
   15.24            next
   15.25 -            show "negligible (interior (g ` K \<inter> g ` L))"
   15.26 -              by (metis (mono_tags, lifting) True finite.emptyI image_Int image_empty interior_Int interior_injective_linear_image intint negligible_finite pairwiseD that)
   15.27 +            have "\<forall>p N. pairwise p N = (\<forall>Na. (Na::'n set) \<in> N \<longrightarrow> (\<forall>Nb. Nb \<in> N \<and> Na \<noteq> Nb \<longrightarrow> p Na Nb))"
   15.28 +              by (metis pairwise_def)
   15.29 +            then have "interior K \<inter> interior L = {}"
   15.30 +              using intint that(2) that(3) that(4) by presburger
   15.31 +            then show "negligible (interior (g ` K \<inter> g ` L))"
   15.32 +              by (metis True empty_imp_negligible image_Int image_empty interior_Int interior_injective_linear_image that(1))
   15.33            qed
   15.34            moreover have "g ` K \<inter> g ` L \<subseteq> frontier (g ` K \<inter> g ` L) \<union> interior (g ` K \<inter> g ` L)"
   15.35              apply (auto simp: frontier_def)
   15.36 @@ -3176,7 +3180,7 @@
   15.37    assumes "f absolutely_integrable_on S"
   15.38    shows "(norm o f) absolutely_integrable_on S"
   15.39    using assms by (simp add: absolutely_integrable_on_def o_def)
   15.40 -    
   15.41 +
   15.42  lemma absolutely_integrable_abs:
   15.43    fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
   15.44    assumes "f absolutely_integrable_on S"
    16.1 --- a/src/HOL/Analysis/Euclidean_Space.thy	Wed Apr 18 21:12:50 2018 +0100
    16.2 +++ b/src/HOL/Analysis/Euclidean_Space.thy	Wed May 02 13:49:38 2018 +0200
    16.3 @@ -152,6 +152,53 @@
    16.4      using False by (auto simp: inner_sum_left)
    16.5  qed
    16.6  
    16.7 +lemma norm_le_componentwise:
    16.8 +   "(\<And>b. b \<in> Basis \<Longrightarrow> abs(inner x b) \<le> abs(inner y b)) \<Longrightarrow> norm x \<le> norm y"
    16.9 +  by (auto simp: norm_le euclidean_inner [of x x] euclidean_inner [of y y] abs_le_square_iff power2_eq_square intro!: sum_mono)
   16.10 +
   16.11 +lemma Basis_le_norm: "b \<in> Basis \<Longrightarrow> \<bar>inner x b\<bar> \<le> norm x"
   16.12 +  by (rule order_trans [OF Cauchy_Schwarz_ineq2]) simp
   16.13 +
   16.14 +lemma norm_bound_Basis_le: "b \<in> Basis \<Longrightarrow> norm x \<le> e \<Longrightarrow> \<bar>inner x b\<bar> \<le> e"
   16.15 +  by (metis Basis_le_norm order_trans)
   16.16 +
   16.17 +lemma norm_bound_Basis_lt: "b \<in> Basis \<Longrightarrow> norm x < e \<Longrightarrow> \<bar>inner x b\<bar> < e"
   16.18 +  by (metis Basis_le_norm le_less_trans)
   16.19 +
   16.20 +lemma norm_le_l1: "norm x \<le> (\<Sum>b\<in>Basis. \<bar>inner x b\<bar>)"
   16.21 +  apply (subst euclidean_representation[of x, symmetric])
   16.22 +  apply (rule order_trans[OF norm_sum])
   16.23 +  apply (auto intro!: sum_mono)
   16.24 +  done
   16.25 +
   16.26 +lemma sum_norm_allsubsets_bound:
   16.27 +  fixes f :: "'a \<Rightarrow> 'n::euclidean_space"
   16.28 +  assumes fP: "finite P"
   16.29 +    and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (sum f Q) \<le> e"
   16.30 +  shows "(\<Sum>x\<in>P. norm (f x)) \<le> 2 * real DIM('n) * e"
   16.31 +proof -
   16.32 +  have "(\<Sum>x\<in>P. norm (f x)) \<le> (\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>inner (f x) b\<bar>)"
   16.33 +    by (rule sum_mono) (rule norm_le_l1)
   16.34 +  also have "(\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>inner (f x) b\<bar>) = (\<Sum>b\<in>Basis. \<Sum>x\<in>P. \<bar>inner (f x) b\<bar>)"
   16.35 +    by (rule sum.swap)
   16.36 +  also have "\<dots> \<le> of_nat (card (Basis :: 'n set)) * (2 * e)"
   16.37 +  proof (rule sum_bounded_above)
   16.38 +    fix i :: 'n
   16.39 +    assume i: "i \<in> Basis"
   16.40 +    have "norm (\<Sum>x\<in>P. \<bar>inner (f x) i\<bar>) \<le>
   16.41 +      norm (inner (\<Sum>x\<in>P \<inter> - {x. inner (f x) i < 0}. f x) i) + norm (inner (\<Sum>x\<in>P \<inter> {x. inner (f x) i < 0}. f x) i)"
   16.42 +      by (simp add: abs_real_def sum.If_cases[OF fP] sum_negf norm_triangle_ineq4 inner_sum_left
   16.43 +        del: real_norm_def)
   16.44 +    also have "\<dots> \<le> e + e"
   16.45 +      unfolding real_norm_def
   16.46 +      by (intro add_mono norm_bound_Basis_le i fPs) auto
   16.47 +    finally show "(\<Sum>x\<in>P. \<bar>inner (f x) i\<bar>) \<le> 2*e" by simp
   16.48 +  qed
   16.49 +  also have "\<dots> = 2 * real DIM('n) * e" by simp
   16.50 +  finally show ?thesis .
   16.51 +qed
   16.52 +
   16.53 +
   16.54  subsection%unimportant \<open>Subclass relationships\<close>
   16.55  
   16.56  instance euclidean_space \<subseteq> perfect_space
   16.57 @@ -250,4 +297,56 @@
   16.58  
   16.59  end
   16.60  
   16.61 +
   16.62 +subsection \<open>Locale instances\<close>
   16.63 +
   16.64 +lemma finite_dimensional_vector_space_euclidean:
   16.65 +  "finite_dimensional_vector_space ( *\<^sub>R) Basis"
   16.66 +proof unfold_locales
   16.67 +  show "finite (Basis::'a set)" by (metis finite_Basis)
   16.68 +  show "real_vector.independent (Basis::'a set)"
   16.69 +    unfolding dependent_def dependent_raw_def[symmetric]
   16.70 +    apply (subst span_finite)
   16.71 +    apply simp
   16.72 +    apply clarify
   16.73 +    apply (drule_tac f="inner a" in arg_cong)
   16.74 +    apply (simp add: inner_Basis inner_sum_right eq_commute)
   16.75 +    done
   16.76 +  show "module.span ( *\<^sub>R) Basis = UNIV"
   16.77 +    unfolding span_finite [OF finite_Basis] span_raw_def[symmetric]
   16.78 +    by (auto intro!: euclidean_representation[symmetric])
   16.79 +qed
   16.80 +
   16.81 +interpretation eucl?: finite_dimensional_vector_space "scaleR :: real => 'a => 'a::euclidean_space" "Basis"
   16.82 +  rewrites "module.dependent ( *\<^sub>R) = dependent"
   16.83 +    and "module.representation ( *\<^sub>R) = representation"
   16.84 +    and "module.subspace ( *\<^sub>R) = subspace"
   16.85 +    and "module.span ( *\<^sub>R) = span"
   16.86 +    and "vector_space.extend_basis ( *\<^sub>R) = extend_basis"
   16.87 +    and "vector_space.dim ( *\<^sub>R) = dim"
   16.88 +    and "Vector_Spaces.linear ( *\<^sub>R) ( *\<^sub>R) = linear"
   16.89 +    and "Vector_Spaces.linear ( * ) ( *\<^sub>R) = linear"
   16.90 +    and "finite_dimensional_vector_space.dimension Basis = DIM('a)"
   16.91 +    and "dimension = DIM('a)"
   16.92 +  by (auto simp add: dependent_raw_def representation_raw_def
   16.93 +      subspace_raw_def span_raw_def extend_basis_raw_def dim_raw_def linear_def
   16.94 +      real_scaleR_def[abs_def]
   16.95 +      finite_dimensional_vector_space.dimension_def
   16.96 +      intro!: finite_dimensional_vector_space.dimension_def
   16.97 +      finite_dimensional_vector_space_euclidean)
   16.98 +
   16.99 +interpretation eucl?: finite_dimensional_vector_space_prod scaleR scaleR Basis Basis
  16.100 +  rewrites "Basis_pair = Basis"
  16.101 +    and "module_prod.scale ( *\<^sub>R) ( *\<^sub>R) = (scaleR::_\<Rightarrow>_\<Rightarrow>('a \<times> 'b))"
  16.102 +proof -
  16.103 +  show "finite_dimensional_vector_space_prod ( *\<^sub>R) ( *\<^sub>R) Basis Basis"
  16.104 +    by unfold_locales
  16.105 +  interpret finite_dimensional_vector_space_prod "( *\<^sub>R)" "( *\<^sub>R)" "Basis::'a set" "Basis::'b set"
  16.106 +    by fact
  16.107 +  show "Basis_pair = Basis"
  16.108 +    unfolding Basis_pair_def Basis_prod_def by auto
  16.109 +  show "module_prod.scale ( *\<^sub>R) ( *\<^sub>R) = scaleR"
  16.110 +    by (fact module_prod_scale_eq_scaleR)
  16.111 +qed
  16.112 +
  16.113  end
    17.1 --- a/src/HOL/Analysis/Finite_Cartesian_Product.thy	Wed Apr 18 21:12:50 2018 +0100
    17.2 +++ b/src/HOL/Analysis/Finite_Cartesian_Product.thy	Wed May 02 13:49:38 2018 +0200
    17.3 @@ -10,7 +10,6 @@
    17.4    L2_Norm
    17.5    "HOL-Library.Numeral_Type"
    17.6    "HOL-Library.Countable_Set"
    17.7 -  "HOL-Library.FuncSet"
    17.8  begin
    17.9  
   17.10  subsection \<open>Finite Cartesian products, with indexing and lambdas\<close>
   17.11 @@ -230,6 +229,80 @@
   17.12    by standard (simp_all add: vec_eq_iff)
   17.13  
   17.14  
   17.15 +subsection\<open>Basic componentwise operations on vectors\<close>
   17.16 +
   17.17 +instantiation vec :: (times, finite) times
   17.18 +begin
   17.19 +
   17.20 +definition "( * ) \<equiv> (\<lambda> x y.  (\<chi> i. (x$i) * (y$i)))"
   17.21 +instance ..
   17.22 +
   17.23 +end
   17.24 +
   17.25 +instantiation vec :: (one, finite) one
   17.26 +begin
   17.27 +
   17.28 +definition "1 \<equiv> (\<chi> i. 1)"
   17.29 +instance ..
   17.30 +
   17.31 +end
   17.32 +
   17.33 +instantiation vec :: (ord, finite) ord
   17.34 +begin
   17.35 +
   17.36 +definition "x \<le> y \<longleftrightarrow> (\<forall>i. x$i \<le> y$i)"
   17.37 +definition "x < (y::'a^'b) \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
   17.38 +instance ..
   17.39 +
   17.40 +end
   17.41 +
   17.42 +text\<open>The ordering on one-dimensional vectors is linear.\<close>
   17.43 +
   17.44 +class cart_one =
   17.45 +  assumes UNIV_one: "card (UNIV :: 'a set) = Suc 0"
   17.46 +begin
   17.47 +
   17.48 +subclass finite
   17.49 +proof
   17.50 +  from UNIV_one show "finite (UNIV :: 'a set)"
   17.51 +    by (auto intro!: card_ge_0_finite)
   17.52 +qed
   17.53 +
   17.54 +end
   17.55 +
   17.56 +instance vec:: (order, finite) order
   17.57 +  by standard (auto simp: less_eq_vec_def less_vec_def vec_eq_iff
   17.58 +      intro: order.trans order.antisym order.strict_implies_order)
   17.59 +
   17.60 +instance vec :: (linorder, cart_one) linorder
   17.61 +proof
   17.62 +  obtain a :: 'b where all: "\<And>P. (\<forall>i. P i) \<longleftrightarrow> P a"
   17.63 +  proof -
   17.64 +    have "card (UNIV :: 'b set) = Suc 0" by (rule UNIV_one)
   17.65 +    then obtain b :: 'b where "UNIV = {b}" by (auto iff: card_Suc_eq)
   17.66 +    then have "\<And>P. (\<forall>i\<in>UNIV. P i) \<longleftrightarrow> P b" by auto
   17.67 +    then show thesis by (auto intro: that)
   17.68 +  qed
   17.69 +  fix x y :: "'a^'b::cart_one"
   17.70 +  note [simp] = less_eq_vec_def less_vec_def all vec_eq_iff field_simps
   17.71 +  show "x \<le> y \<or> y \<le> x" by auto
   17.72 +qed
   17.73 +
   17.74 +text\<open>Constant Vectors\<close>
   17.75 +
   17.76 +definition "vec x = (\<chi> i. x)"
   17.77 +
   17.78 +text\<open>Also the scalar-vector multiplication.\<close>
   17.79 +
   17.80 +definition vector_scalar_mult:: "'a::times \<Rightarrow> 'a ^ 'n \<Rightarrow> 'a ^ 'n" (infixl "*s" 70)
   17.81 +  where "c *s x = (\<chi> i. c * (x$i))"
   17.82 +
   17.83 +text \<open>scalar product\<close>
   17.84 +
   17.85 +definition scalar_product :: "'a :: semiring_1 ^ 'n \<Rightarrow> 'a ^ 'n \<Rightarrow> 'a" where
   17.86 +  "scalar_product v w = (\<Sum> i \<in> UNIV. v $ i * w $ i)"
   17.87 +
   17.88 +
   17.89  subsection \<open>Real vector space\<close>
   17.90  
   17.91  instantiation vec :: (real_vector, finite) real_vector
   17.92 @@ -543,6 +616,29 @@
   17.93  unfolding norm_vec_def
   17.94  by (rule member_le_L2_set) simp_all
   17.95  
   17.96 +lemma norm_le_componentwise_cart:
   17.97 +  fixes x :: "'a::real_normed_vector^'n"
   17.98 +  assumes "\<And>i. norm(x$i) \<le> norm(y$i)"
   17.99 +  shows "norm x \<le> norm y"
  17.100 +  unfolding norm_vec_def
  17.101 +  by (rule L2_set_mono) (auto simp: assms)
  17.102 +
  17.103 +lemma norm_eq_0_imp: "norm x = 0 ==> x = (0::real ^'n)" by (metis norm_eq_zero)
  17.104 +
  17.105 +lemma component_le_norm_cart: "\<bar>x$i\<bar> \<le> norm x"
  17.106 +  apply (simp add: norm_vec_def)
  17.107 +  apply (rule member_le_L2_set, simp_all)
  17.108 +  done
  17.109 +
  17.110 +lemma norm_bound_component_le_cart: "norm x \<le> e ==> \<bar>x$i\<bar> \<le> e"
  17.111 +  by (metis component_le_norm_cart order_trans)
  17.112 +
  17.113 +lemma norm_bound_component_lt_cart: "norm x < e ==> \<bar>x$i\<bar> < e"
  17.114 +  by (metis component_le_norm_cart le_less_trans)
  17.115 +
  17.116 +lemma norm_le_l1_cart: "norm x \<le> sum(\<lambda>i. \<bar>x$i\<bar>) UNIV"
  17.117 +  by (simp add: norm_vec_def L2_set_le_sum)
  17.118 +
  17.119  lemma bounded_linear_vec_nth: "bounded_linear (\<lambda>x. x $ i)"
  17.120  apply standard
  17.121  apply (rule vector_add_component)
  17.122 @@ -649,6 +745,16 @@
  17.123  
  17.124  end
  17.125  
  17.126 +lemma norm_axis_1 [simp]: "norm (axis m (1::real)) = 1"
  17.127 +  by (simp add: inner_axis' norm_eq_1)
  17.128 +
  17.129 +lemma sum_norm_allsubsets_bound_cart:
  17.130 +  fixes f:: "'a \<Rightarrow> real ^'n"
  17.131 +  assumes fP: "finite P" and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (sum f Q) \<le> e"
  17.132 +  shows "sum (\<lambda>x. norm (f x)) P \<le> 2 * real CARD('n) *  e"
  17.133 +  using sum_norm_allsubsets_bound[OF assms]
  17.134 +  by simp
  17.135 +
  17.136  lemma cart_eq_inner_axis: "a $ i = inner a (axis i 1)"
  17.137    by (simp add: inner_axis)
  17.138  
  17.139 @@ -684,4 +790,414 @@
  17.140    shows "(axis_index (axis u 1 :: real^'n)) = (u::'n)"
  17.141    by (simp add: axis_eq_axis axis_index_def)
  17.142  
  17.143 +subsection \<open>A naive proof procedure to lift really trivial arithmetic stuff from the basis of the vector space\<close>
  17.144 +
  17.145 +lemma sum_cong_aux:
  17.146 +  "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> sum f A = sum g A"
  17.147 +  by (auto intro: sum.cong)
  17.148 +
  17.149 +hide_fact (open) sum_cong_aux
  17.150 +
  17.151 +method_setup vector = \<open>
  17.152 +let
  17.153 +  val ss1 =
  17.154 +    simpset_of (put_simpset HOL_basic_ss @{context}
  17.155 +      addsimps [@{thm sum.distrib} RS sym,
  17.156 +      @{thm sum_subtractf} RS sym, @{thm sum_distrib_left},
  17.157 +      @{thm sum_distrib_right}, @{thm sum_negf} RS sym])
  17.158 +  val ss2 =
  17.159 +    simpset_of (@{context} addsimps
  17.160 +             [@{thm plus_vec_def}, @{thm times_vec_def},
  17.161 +              @{thm minus_vec_def}, @{thm uminus_vec_def},
  17.162 +              @{thm one_vec_def}, @{thm zero_vec_def}, @{thm vec_def},
  17.163 +              @{thm scaleR_vec_def},
  17.164 +              @{thm vec_lambda_beta}, @{thm vector_scalar_mult_def}])
  17.165 +  fun vector_arith_tac ctxt ths =
  17.166 +    simp_tac (put_simpset ss1 ctxt)
  17.167 +    THEN' (fn i => resolve_tac ctxt @{thms Finite_Cartesian_Product.sum_cong_aux} i
  17.168 +         ORELSE resolve_tac ctxt @{thms sum.neutral} i
  17.169 +         ORELSE simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm vec_eq_iff}]) i)
  17.170 +    (* THEN' TRY o clarify_tac HOL_cs  THEN' (TRY o rtac @{thm iffI}) *)
  17.171 +    THEN' asm_full_simp_tac (put_simpset ss2 ctxt addsimps ths)
  17.172 +in
  17.173 +  Attrib.thms >> (fn ths => fn ctxt => SIMPLE_METHOD' (vector_arith_tac ctxt ths))
  17.174  end
  17.175 +\<close> "lift trivial vector statements to real arith statements"
  17.176 +
  17.177 +lemma vec_0[simp]: "vec 0 = 0" by vector
  17.178 +lemma vec_1[simp]: "vec 1 = 1" by vector
  17.179 +
  17.180 +lemma vec_inj[simp]: "vec x = vec y \<longleftrightarrow> x = y" by vector
  17.181 +
  17.182 +lemma vec_in_image_vec: "vec x \<in> (vec ` S) \<longleftrightarrow> x \<in> S" by auto
  17.183 +
  17.184 +lemma vec_add: "vec(x + y) = vec x + vec y"  by vector
  17.185 +lemma vec_sub: "vec(x - y) = vec x - vec y" by vector
  17.186 +lemma vec_cmul: "vec(c * x) = c *s vec x " by vector
  17.187 +lemma vec_neg: "vec(- x) = - vec x " by vector
  17.188 +
  17.189 +lemma vec_scaleR: "vec(c * x) = c *\<^sub>R vec x"
  17.190 +  by vector
  17.191 +
  17.192 +lemma vec_sum:
  17.193 +  assumes "finite S"
  17.194 +  shows "vec(sum f S) = sum (vec \<circ> f) S"
  17.195 +  using assms
  17.196 +proof induct
  17.197 +  case empty
  17.198 +  then show ?case by simp
  17.199 +next
  17.200 +  case insert
  17.201 +  then show ?case by (auto simp add: vec_add)
  17.202 +qed
  17.203 +
  17.204 +text\<open>Obvious "component-pushing".\<close>
  17.205 +
  17.206 +lemma vec_component [simp]: "vec x $ i = x"
  17.207 +  by vector
  17.208 +
  17.209 +lemma vector_mult_component [simp]: "(x * y)$i = x$i * y$i"
  17.210 +  by vector
  17.211 +
  17.212 +lemma vector_smult_component [simp]: "(c *s y)$i = c * (y$i)"
  17.213 +  by vector
  17.214 +
  17.215 +lemma cond_component: "(if b then x else y)$i = (if b then x$i else y$i)" by vector
  17.216 +
  17.217 +lemmas vector_component =
  17.218 +  vec_component vector_add_component vector_mult_component
  17.219 +  vector_smult_component vector_minus_component vector_uminus_component
  17.220 +  vector_scaleR_component cond_component
  17.221 +
  17.222 +
  17.223 +subsection \<open>Some frequently useful arithmetic lemmas over vectors\<close>
  17.224 +
  17.225 +instance vec :: (semigroup_mult, finite) semigroup_mult
  17.226 +  by standard (vector mult.assoc)
  17.227 +
  17.228 +instance vec :: (monoid_mult, finite) monoid_mult
  17.229 +  by standard vector+
  17.230 +
  17.231 +instance vec :: (ab_semigroup_mult, finite) ab_semigroup_mult
  17.232 +  by standard (vector mult.commute)
  17.233 +
  17.234 +instance vec :: (comm_monoid_mult, finite) comm_monoid_mult
  17.235 +  by standard vector
  17.236 +
  17.237 +instance vec :: (semiring, finite) semiring
  17.238 +  by standard (vector field_simps)+
  17.239 +
  17.240 +instance vec :: (semiring_0, finite) semiring_0
  17.241 +  by standard (vector field_simps)+
  17.242 +instance vec :: (semiring_1, finite) semiring_1
  17.243 +  by standard vector
  17.244 +instance vec :: (comm_semiring, finite) comm_semiring
  17.245 +  by standard (vector field_simps)+
  17.246 +
  17.247 +instance vec :: (comm_semiring_0, finite) comm_semiring_0 ..
  17.248 +instance vec :: (semiring_0_cancel, finite) semiring_0_cancel ..
  17.249 +instance vec :: (comm_semiring_0_cancel, finite) comm_semiring_0_cancel ..
  17.250 +instance vec :: (ring, finite) ring ..
  17.251 +instance vec :: (semiring_1_cancel, finite) semiring_1_cancel ..
  17.252 +instance vec :: (comm_semiring_1, finite) comm_semiring_1 ..
  17.253 +
  17.254 +instance vec :: (ring_1, finite) ring_1 ..
  17.255 +
  17.256 +instance vec :: (real_algebra, finite) real_algebra
  17.257 +  by standard (simp_all add: vec_eq_iff)
  17.258 +
  17.259 +instance vec :: (real_algebra_1, finite) real_algebra_1 ..
  17.260 +
  17.261 +lemma of_nat_index: "(of_nat n :: 'a::semiring_1 ^'n)$i = of_nat n"
  17.262 +proof (induct n)
  17.263 +  case 0
  17.264 +  then show ?case by vector
  17.265 +next
  17.266 +  case Suc
  17.267 +  then show ?case by vector
  17.268 +qed
  17.269 +
  17.270 +lemma one_index [simp]: "(1 :: 'a :: one ^ 'n) $ i = 1"
  17.271 +  by vector
  17.272 +
  17.273 +lemma neg_one_index [simp]: "(- 1 :: 'a :: {one, uminus} ^ 'n) $ i = - 1"
  17.274 +  by vector
  17.275 +
  17.276 +instance vec :: (semiring_char_0, finite) semiring_char_0
  17.277 +proof
  17.278 +  fix m n :: nat
  17.279 +  show "inj (of_nat :: nat \<Rightarrow> 'a ^ 'b)"
  17.280 +    by (auto intro!: injI simp add: vec_eq_iff of_nat_index)
  17.281 +qed
  17.282 +
  17.283 +instance vec :: (numeral, finite) numeral ..
  17.284 +instance vec :: (semiring_numeral, finite) semiring_numeral ..
  17.285 +
  17.286 +lemma numeral_index [simp]: "numeral w $ i = numeral w"
  17.287 +  by (induct w) (simp_all only: numeral.simps vector_add_component one_index)
  17.288 +
  17.289 +lemma neg_numeral_index [simp]: "- numeral w $ i = - numeral w"
  17.290 +  by (simp only: vector_uminus_component numeral_index)
  17.291 +
  17.292 +instance vec :: (comm_ring_1, finite) comm_ring_1 ..
  17.293 +instance vec :: (ring_char_0, finite) ring_char_0 ..
  17.294 +
  17.295 +lemma vector_smult_assoc: "a *s (b *s x) = ((a::'a::semigroup_mult) * b) *s x"
  17.296 +  by (vector mult.assoc)
  17.297 +lemma vector_sadd_rdistrib: "((a::'a::semiring) + b) *s x = a *s x + b *s x"
  17.298 +  by (vector field_simps)
  17.299 +lemma vector_add_ldistrib: "(c::'a::semiring) *s (x + y) = c *s x + c *s y"
  17.300 +  by (vector field_simps)
  17.301 +lemma vector_smult_lzero[simp]: "(0::'a::mult_zero) *s x = 0" by vector
  17.302 +lemma vector_smult_lid[simp]: "(1::'a::monoid_mult) *s x = x" by vector
  17.303 +lemma vector_ssub_ldistrib: "(c::'a::ring) *s (x - y) = c *s x - c *s y"
  17.304 +  by (vector field_simps)
  17.305 +lemma vector_smult_rneg: "(c::'a::ring) *s -x = -(c *s x)" by vector
  17.306 +lemma vector_smult_lneg: "- (c::'a::ring) *s x = -(c *s x)" by vector
  17.307 +lemma vector_sneg_minus1: "-x = (-1::'a::ring_1) *s x" by vector
  17.308 +lemma vector_smult_rzero[simp]: "c *s 0 = (0::'a::mult_zero ^ 'n)" by vector
  17.309 +lemma vector_sub_rdistrib: "((a::'a::ring) - b) *s x = a *s x - b *s x"
  17.310 +  by (vector field_simps)
  17.311 +
  17.312 +lemma vec_eq[simp]: "(vec m = vec n) \<longleftrightarrow> (m = n)"
  17.313 +  by (simp add: vec_eq_iff)
  17.314 +
  17.315 +lemma Vector_Spaces_linear_vec [simp]: "Vector_Spaces.linear ( * ) vector_scalar_mult vec"
  17.316 +  by unfold_locales (vector algebra_simps)+
  17.317 +
  17.318 +lemma vector_mul_eq_0[simp]: "(a *s x = 0) \<longleftrightarrow> a = (0::'a::idom) \<or> x = 0"
  17.319 +  by vector
  17.320 +
  17.321 +lemma vector_mul_lcancel[simp]: "a *s x = a *s y \<longleftrightarrow> a = (0::'a::field) \<or> x = y"
  17.322 +  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_ssub_ldistrib)
  17.323 +
  17.324 +lemma vector_mul_rcancel[simp]: "a *s x = b *s x \<longleftrightarrow> (a::'a::field) = b \<or> x = 0"
  17.325 +  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_sub_rdistrib)
  17.326 +
  17.327 +lemma vector_mul_lcancel_imp: "a \<noteq> (0::'a::field) ==>  a *s x = a *s y ==> (x = y)"
  17.328 +  by (metis vector_mul_lcancel)
  17.329 +
  17.330 +lemma vector_mul_rcancel_imp: "x \<noteq> 0 \<Longrightarrow> (a::'a::field) *s x = b *s x ==> a = b"
  17.331 +  by (metis vector_mul_rcancel)
  17.332 +
  17.333 +lemma scalar_mult_eq_scaleR [abs_def]: "c *s x = c *\<^sub>R x"
  17.334 +  unfolding scaleR_vec_def vector_scalar_mult_def by simp
  17.335 +
  17.336 +lemma dist_mul[simp]: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y"
  17.337 +  unfolding dist_norm scalar_mult_eq_scaleR
  17.338 +  unfolding scaleR_right_diff_distrib[symmetric] by simp
  17.339 +
  17.340 +lemma sum_component [simp]:
  17.341 +  fixes f:: " 'a \<Rightarrow> ('b::comm_monoid_add) ^'n"
  17.342 +  shows "(sum f S)$i = sum (\<lambda>x. (f x)$i) S"
  17.343 +proof (cases "finite S")
  17.344 +  case True
  17.345 +  then show ?thesis by induct simp_all
  17.346 +next
  17.347 +  case False
  17.348 +  then show ?thesis by simp
  17.349 +qed
  17.350 +
  17.351 +lemma sum_eq: "sum f S = (\<chi> i. sum (\<lambda>x. (f x)$i ) S)"
  17.352 +  by (simp add: vec_eq_iff)
  17.353 +
  17.354 +lemma sum_cmul:
  17.355 +  fixes f:: "'c \<Rightarrow> ('a::semiring_1)^'n"
  17.356 +  shows "sum (\<lambda>x. c *s f x) S = c *s sum f S"
  17.357 +  by (simp add: vec_eq_iff sum_distrib_left)
  17.358 +
  17.359 +lemma linear_vec [simp]: "linear vec"
  17.360 +  using Vector_Spaces_linear_vec
  17.361 +  apply (auto )
  17.362 +  by unfold_locales (vector algebra_simps)+
  17.363 +
  17.364 +subsection \<open>Matrix operations\<close>
  17.365 +
  17.366 +text\<open>Matrix notation. NB: an MxN matrix is of type @{typ "'a^'n^'m"}, not @{typ "'a^'m^'n"}\<close>
  17.367 +
  17.368 +definition map_matrix::"('a \<Rightarrow> 'b) \<Rightarrow> (('a, 'i::finite)vec, 'j::finite) vec \<Rightarrow> (('b, 'i)vec, 'j) vec" where
  17.369 +  "map_matrix f x = (\<chi> i j. f (x $ i $ j))"
  17.370 +
  17.371 +lemma nth_map_matrix[simp]: "map_matrix f x $ i $ j = f (x $ i $ j)"
  17.372 +  by (simp add: map_matrix_def)
  17.373 +
  17.374 +definition matrix_matrix_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'p^'n \<Rightarrow> 'a ^ 'p ^'m"
  17.375 +    (infixl "**" 70)
  17.376 +  where "m ** m' == (\<chi> i j. sum (\<lambda>k. ((m$i)$k) * ((m'$k)$j)) (UNIV :: 'n set)) ::'a ^ 'p ^'m"
  17.377 +
  17.378 +definition matrix_vector_mult :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n \<Rightarrow> 'a ^ 'm"
  17.379 +    (infixl "*v" 70)
  17.380 +  where "m *v x \<equiv> (\<chi> i. sum (\<lambda>j. ((m$i)$j) * (x$j)) (UNIV ::'n set)) :: 'a^'m"
  17.381 +
  17.382 +definition vector_matrix_mult :: "'a ^ 'm \<Rightarrow> ('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n "
  17.383 +    (infixl "v*" 70)
  17.384 +  where "v v* m == (\<chi> j. sum (\<lambda>i. ((m$i)$j) * (v$i)) (UNIV :: 'm set)) :: 'a^'n"
  17.385 +
  17.386 +definition "(mat::'a::zero => 'a ^'n^'n) k = (\<chi> i j. if i = j then k else 0)"
  17.387 +definition transpose where
  17.388 +  "(transpose::'a^'n^'m \<Rightarrow> 'a^'m^'n) A = (\<chi> i j. ((A$j)$i))"
  17.389 +definition "(row::'m => 'a ^'n^'m \<Rightarrow> 'a ^'n) i A = (\<chi> j. ((A$i)$j))"
  17.390 +definition "(column::'n =>'a^'n^'m =>'a^'m) j A = (\<chi> i. ((A$i)$j))"
  17.391 +definition "rows(A::'a^'n^'m) = { row i A | i. i \<in> (UNIV :: 'm set)}"
  17.392 +definition "columns(A::'a^'n^'m) = { column i A | i. i \<in> (UNIV :: 'n set)}"
  17.393 +
  17.394 +lemma mat_0[simp]: "mat 0 = 0" by (vector mat_def)
  17.395 +lemma matrix_add_ldistrib: "(A ** (B + C)) = (A ** B) + (A ** C)"
  17.396 +  by (vector matrix_matrix_mult_def sum.distrib[symmetric] field_simps)
  17.397 +
  17.398 +lemma matrix_mul_lid [simp]:
  17.399 +  fixes A :: "'a::semiring_1 ^ 'm ^ 'n"
  17.400 +  shows "mat 1 ** A = A"
  17.401 +  apply (simp add: matrix_matrix_mult_def mat_def)
  17.402 +  apply vector
  17.403 +  apply (auto simp only: if_distrib if_distribR sum.delta'[OF finite]
  17.404 +    mult_1_left mult_zero_left if_True UNIV_I)
  17.405 +  done
  17.406 +
  17.407 +lemma matrix_mul_rid [simp]:
  17.408 +  fixes A :: "'a::semiring_1 ^ 'm ^ 'n"
  17.409 +  shows "A ** mat 1 = A"
  17.410 +  apply (simp add: matrix_matrix_mult_def mat_def)
  17.411 +  apply vector
  17.412 +  apply (auto simp only: if_distrib if_distribR sum.delta[OF finite]
  17.413 +    mult_1_right mult_zero_right if_True UNIV_I cong: if_cong)
  17.414 +  done
  17.415 +
  17.416 +lemma matrix_mul_assoc: "A ** (B ** C) = (A ** B) ** C"
  17.417 +  apply (vector matrix_matrix_mult_def sum_distrib_left sum_distrib_right mult.assoc)
  17.418 +  apply (subst sum.swap)
  17.419 +  apply simp
  17.420 +  done
  17.421 +
  17.422 +lemma matrix_vector_mul_assoc: "A *v (B *v x) = (A ** B) *v x"
  17.423 +  apply (vector matrix_matrix_mult_def matrix_vector_mult_def
  17.424 +    sum_distrib_left sum_distrib_right mult.assoc)
  17.425 +  apply (subst sum.swap)
  17.426 +  apply simp
  17.427 +  done
  17.428 +
  17.429 +lemma matrix_vector_mul_lid [simp]: "mat 1 *v x = (x::'a::semiring_1 ^ 'n)"
  17.430 +  apply (vector matrix_vector_mult_def mat_def)
  17.431 +  apply (simp add: if_distrib if_distribR sum.delta' cong del: if_weak_cong)
  17.432 +  done
  17.433 +
  17.434 +lemma matrix_transpose_mul:
  17.435 +    "transpose(A ** B) = transpose B ** transpose (A::'a::comm_semiring_1^_^_)"
  17.436 +  by (simp add: matrix_matrix_mult_def transpose_def vec_eq_iff mult.commute)
  17.437 +
  17.438 +lemma matrix_eq:
  17.439 +  fixes A B :: "'a::semiring_1 ^ 'n ^ 'm"
  17.440 +  shows "A = B \<longleftrightarrow>  (\<forall>x. A *v x = B *v x)" (is "?lhs \<longleftrightarrow> ?rhs")
  17.441 +  apply auto
  17.442 +  apply (subst vec_eq_iff)
  17.443 +  apply clarify
  17.444 +  apply (clarsimp simp add: matrix_vector_mult_def if_distrib if_distribR vec_eq_iff cong del: if_weak_cong)
  17.445 +  apply (erule_tac x="axis ia 1" in allE)
  17.446 +  apply (erule_tac x="i" in allE)
  17.447 +  apply (auto simp add: if_distrib if_distribR axis_def
  17.448 +    sum.delta[OF finite] cong del: if_weak_cong)
  17.449 +  done
  17.450 +
  17.451 +lemma matrix_vector_mul_component: "((A::real^_^_) *v x)$k = inner (A$k) x"
  17.452 +  by (simp add: matrix_vector_mult_def inner_vec_def)
  17.453 +
  17.454 +lemma dot_lmul_matrix: "inner ((x::real ^_) v* A) y = inner x (A *v y)"
  17.455 +  apply (simp add: inner_vec_def matrix_vector_mult_def vector_matrix_mult_def sum_distrib_right sum_distrib_left ac_simps)
  17.456 +  apply (subst sum.swap)
  17.457 +  apply simp
  17.458 +  done
  17.459 +
  17.460 +lemma transpose_mat [simp]: "transpose (mat n) = mat n"
  17.461 +  by (vector transpose_def mat_def)
  17.462 +
  17.463 +lemma transpose_transpose [simp]: "transpose(transpose A) = A"
  17.464 +  by (vector transpose_def)
  17.465 +
  17.466 +lemma row_transpose [simp]: "row i (transpose A) = column i A"
  17.467 +  by (simp add: row_def column_def transpose_def vec_eq_iff)
  17.468 +
  17.469 +lemma column_transpose [simp]: "column i (transpose A) = row i A"
  17.470 +  by (simp add: row_def column_def transpose_def vec_eq_iff)
  17.471 +
  17.472 +lemma rows_transpose [simp]: "rows(transpose A) = columns A"
  17.473 +  by (auto simp add: rows_def columns_def intro: set_eqI)
  17.474 +
  17.475 +lemma columns_transpose [simp]: "columns(transpose A) = rows A"
  17.476 +  by (metis transpose_transpose rows_transpose)
  17.477 +
  17.478 +lemma matrix_mult_sum:
  17.479 +  "(A::'a::comm_semiring_1^'n^'m) *v x = sum (\<lambda>i. (x$i) *s column i A) (UNIV:: 'n set)"
  17.480 +  by (simp add: matrix_vector_mult_def vec_eq_iff column_def mult.commute)
  17.481 +
  17.482 +lemma vector_componentwise:
  17.483 +  "(x::'a::ring_1^'n) = (\<chi> j. \<Sum>i\<in>UNIV. (x$i) * (axis i 1 :: 'a^'n) $ j)"
  17.484 +  by (simp add: axis_def if_distrib sum.If_cases vec_eq_iff)
  17.485 +
  17.486 +lemma basis_expansion: "sum (\<lambda>i. (x$i) *s axis i 1) UNIV = (x::('a::ring_1) ^'n)"
  17.487 +  by (auto simp add: axis_def vec_eq_iff if_distrib sum.If_cases cong del: if_weak_cong)
  17.488 +
  17.489 +
  17.490 +text\<open>Correspondence between matrices and linear operators.\<close>
  17.491 +
  17.492 +definition matrix :: "('a::{plus,times, one, zero}^'m \<Rightarrow> 'a ^ 'n) \<Rightarrow> 'a^'m^'n"
  17.493 +  where "matrix f = (\<chi> i j. (f(axis j 1))$i)"
  17.494 +
  17.495 +lemma matrix_id_mat_1: "matrix id = mat 1"
  17.496 +  by (simp add: mat_def matrix_def axis_def)
  17.497 +
  17.498 +lemma matrix_scaleR: "(matrix (( *\<^sub>R) r)) = mat r"
  17.499 +  by (simp add: mat_def matrix_def axis_def if_distrib cong: if_cong)
  17.500 +
  17.501 +lemma matrix_vector_mul_linear[intro, simp]: "linear (\<lambda>x. A *v (x::real ^ _))"
  17.502 +  by (simp add: linear_iff matrix_vector_mult_def vec_eq_iff
  17.503 +      field_simps sum_distrib_left sum.distrib)
  17.504 +
  17.505 +lemma matrix_vector_mult_add_distrib [algebra_simps]:
  17.506 +  "A *v (x + y) = A *v x + A *v y"
  17.507 +  by (vector matrix_vector_mult_def sum.distrib distrib_left)
  17.508 +
  17.509 +lemma matrix_vector_mult_diff_distrib [algebra_simps]:
  17.510 +  fixes A :: "'a::ring_1^'n^'m"
  17.511 +  shows "A *v (x - y) = A *v x - A *v y"
  17.512 +  by (vector matrix_vector_mult_def sum_subtractf right_diff_distrib)
  17.513 +
  17.514 +lemma matrix_vector_mult_scaleR[algebra_simps]:
  17.515 +  fixes A :: "real^'n^'m"
  17.516 +  shows "A *v (c *\<^sub>R x) = c *\<^sub>R (A *v x)"
  17.517 +  using linear_iff matrix_vector_mul_linear by blast
  17.518 +
  17.519 +lemma matrix_vector_mult_0_right [simp]: "A *v 0 = 0"
  17.520 +  by (simp add: matrix_vector_mult_def vec_eq_iff)
  17.521 +
  17.522 +lemma matrix_vector_mult_0 [simp]: "0 *v w = 0"
  17.523 +  by (simp add: matrix_vector_mult_def vec_eq_iff)
  17.524 +
  17.525 +lemma matrix_vector_mult_add_rdistrib [algebra_simps]:
  17.526 +  "(A + B) *v x = (A *v x) + (B *v x)"
  17.527 +  by (vector matrix_vector_mult_def sum.distrib distrib_right)
  17.528 +
  17.529 +lemma matrix_vector_mult_diff_rdistrib [algebra_simps]:
  17.530 +  fixes A :: "'a :: ring_1^'n^'m"
  17.531 +  shows "(A - B) *v x = (A *v x) - (B *v x)"
  17.532 +  by (vector matrix_vector_mult_def sum_subtractf left_diff_distrib)
  17.533 +
  17.534 +lemma matrix_vector_column:
  17.535 +  "(A::'a::comm_semiring_1^'n^_) *v x = sum (\<lambda>i. (x$i) *s ((transpose A)$i)) (UNIV:: 'n set)"
  17.536 +  by (simp add: matrix_vector_mult_def transpose_def vec_eq_iff mult.commute)
  17.537 +
  17.538 +subsection\<open>Inverse matrices  (not necessarily square)\<close>
  17.539 +
  17.540 +definition
  17.541 +  "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
  17.542 +
  17.543 +definition
  17.544 +  "matrix_inv(A:: 'a::semiring_1^'n^'m) =
  17.545 +    (SOME A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
  17.546 +
  17.547 +lemma inj_matrix_vector_mult:
  17.548 +  fixes A::"'a::field^'n^'m"
  17.549 +  assumes "invertible A"
  17.550 +  shows "inj (( *v) A)"
  17.551 +  by (metis assms inj_on_inverseI invertible_def matrix_vector_mul_assoc matrix_vector_mul_lid)
  17.552 +
  17.553 +end
    18.1 --- a/src/HOL/Analysis/Further_Topology.thy	Wed Apr 18 21:12:50 2018 +0100
    18.2 +++ b/src/HOL/Analysis/Further_Topology.thy	Wed May 02 13:49:38 2018 +0200
    18.3 @@ -68,7 +68,7 @@
    18.4      by (simp add: subspace_orthogonal_to_vectors T'_def)
    18.5    have dim_eq: "dim T' + dim T = DIM('a)"
    18.6      using dim_subspace_orthogonal_to_vectors [of T UNIV] \<open>subspace T\<close>
    18.7 -    by (simp add: dim_UNIV T'_def)
    18.8 +    by (simp add: T'_def)
    18.9    have "\<exists>v1 v2. v1 \<in> span T \<and> (\<forall>w \<in> span T. orthogonal v2 w) \<and> x = v1 + v2" for x
   18.10      by (force intro: orthogonal_subspace_decomp_exists [of T x])
   18.11    then obtain p1 p2 where p1span: "p1 x \<in> span T"
   18.12 @@ -76,25 +76,35 @@
   18.13                        and eq: "p1 x + p2 x = x" for x
   18.14      by metis
   18.15    then have p1: "\<And>z. p1 z \<in> T" and ortho: "\<And>w. w \<in> T \<Longrightarrow> orthogonal (p2 x) w" for x
   18.16 -    using span_eq \<open>subspace T\<close> by blast+
   18.17 +    using span_eq_iff \<open>subspace T\<close> by blast+
   18.18    then have p2: "\<And>z. p2 z \<in> T'"
   18.19      by (simp add: T'_def orthogonal_commute)
   18.20    have p12_eq: "\<And>x y. \<lbrakk>x \<in> T; y \<in> T'\<rbrakk> \<Longrightarrow> p1(x + y) = x \<and> p2(x + y) = y"
   18.21    proof (rule orthogonal_subspace_decomp_unique [OF eq p1span, where T=T'])
   18.22      show "\<And>x y. \<lbrakk>x \<in> T; y \<in> T'\<rbrakk> \<Longrightarrow> p2 (x + y) \<in> span T'"
   18.23 -      using span_eq p2 \<open>subspace T'\<close> by blast
   18.24 +      using span_eq_iff p2 \<open>subspace T'\<close> by blast
   18.25      show "\<And>a b. \<lbrakk>a \<in> T; b \<in> T'\<rbrakk> \<Longrightarrow> orthogonal a b"
   18.26        using T'_def by blast
   18.27 -  qed (auto simp: span_superset)
   18.28 +  qed (auto simp: span_base)
   18.29    then have "\<And>c x. p1 (c *\<^sub>R x) = c *\<^sub>R p1 x \<and> p2 (c *\<^sub>R x) = c *\<^sub>R p2 x"
   18.30 -    by (metis eq \<open>subspace T\<close> \<open>subspace T'\<close> p1 p2 scaleR_add_right subspace_mul)
   18.31 +  proof -
   18.32 +    fix c :: real and x :: 'a
   18.33 +    have f1: "c *\<^sub>R x = c *\<^sub>R p1 x + c *\<^sub>R p2 x"
   18.34 +      by (metis eq pth_6)
   18.35 +    have f2: "c *\<^sub>R p2 x \<in> T'"
   18.36 +      by (simp add: \<open>subspace T'\<close> p2 subspace_scale)
   18.37 +    have "c *\<^sub>R p1 x \<in> T"
   18.38 +      by (metis (full_types) assms(2) p1span span_eq_iff subspace_scale)
   18.39 +    then show "p1 (c *\<^sub>R x) = c *\<^sub>R p1 x \<and> p2 (c *\<^sub>R x) = c *\<^sub>R p2 x"
   18.40 +      using f2 f1 p12_eq by presburger
   18.41 +  qed
   18.42    moreover have lin_add: "\<And>x y. p1 (x + y) = p1 x + p1 y \<and> p2 (x + y) = p2 x + p2 y"
   18.43    proof (rule orthogonal_subspace_decomp_unique [OF _ p1span, where T=T'])
   18.44      show "\<And>x y. p1 (x + y) + p2 (x + y) = p1 x + p1 y + (p2 x + p2 y)"
   18.45        by (simp add: add.assoc add.left_commute eq)
   18.46      show  "\<And>a b. \<lbrakk>a \<in> T; b \<in> T'\<rbrakk> \<Longrightarrow> orthogonal a b"
   18.47        using T'_def by blast
   18.48 -  qed (auto simp: p1span p2 span_superset subspace_add)
   18.49 +  qed (auto simp: p1span p2 span_base span_add)
   18.50    ultimately have "linear p1" "linear p2"
   18.51      by unfold_locales auto
   18.52    have "(\<lambda>z. g (p1 z)) differentiable_on {x + y |x y. x \<in> S - {0} \<and> y \<in> T'}"
   18.53 @@ -263,7 +273,7 @@
   18.54    show ?thesis
   18.55    proof (rule that [OF \<open>subspace T\<close>])
   18.56      show "T \<subseteq> U"
   18.57 -      using span_eq \<open>subspace U\<close> \<open>T \<subseteq> span U\<close> by blast
   18.58 +      using span_eq_iff \<open>subspace U\<close> \<open>T \<subseteq> span U\<close> by blast
   18.59      show "aff_dim T = aff_dim S"
   18.60        using dimT \<open>subspace T\<close> affS aff_dim_subspace by fastforce
   18.61      show "rel_frontier S homeomorphic sphere 0 1 \<inter> T"
   18.62 @@ -314,7 +324,7 @@
   18.63        where "subspace T'" and affT': "aff_dim T' = aff_dim T"
   18.64          and homT: "rel_frontier T homeomorphic sphere 0 1 \<inter> T'"
   18.65        apply (rule spheremap_lemma3 [OF \<open>bounded T\<close> \<open>convex T\<close> subspace_UNIV, where 'b='a])
   18.66 -       apply (simp add: dim_UNIV aff_dim_le_DIM)
   18.67 +       apply (simp add: aff_dim_le_DIM)
   18.68        using \<open>T \<noteq> {}\<close> by blast
   18.69      with homeomorphic_imp_homotopy_eqv
   18.70      have relT: "sphere 0 1 \<inter> T'  homotopy_eqv rel_frontier T"
   18.71 @@ -2003,7 +2013,7 @@
   18.72    have "U \<subseteq> S"
   18.73      using ope openin_imp_subset by blast
   18.74    have "(UNIV::'b set) homeomorphic S"
   18.75 -    by (simp add: \<open>subspace S\<close> dimS dim_UNIV homeomorphic_subspaces)
   18.76 +    by (simp add: \<open>subspace S\<close> dimS homeomorphic_subspaces)
   18.77    then obtain h k where homhk: "homeomorphism (UNIV::'b set) S h k"
   18.78      using homeomorphic_def by blast
   18.79    have homkh: "homeomorphism S (k ` S) k h"
   18.80 @@ -2090,7 +2100,7 @@
   18.81  proof -
   18.82    obtain V' where "subspace V'" "V' \<subseteq> U" "dim V' = dim V"
   18.83      using choose_subspace_of_subspace [OF VU]
   18.84 -    by (metis span_eq \<open>subspace U\<close>)
   18.85 +    by (metis span_eq_iff \<open>subspace U\<close>)
   18.86    then have "V homeomorphic V'"
   18.87      by (simp add: \<open>subspace V\<close> homeomorphic_subspaces)
   18.88    then obtain h k where homhk: "homeomorphism V V' h k"
   18.89 @@ -2136,7 +2146,7 @@
   18.90    proof -
   18.91      obtain T where "subspace T" "T \<subseteq> U" "dim T = dim V"
   18.92        using choose_subspace_of_subspace [of "dim V" U]
   18.93 -      by (metis span_eq \<open>subspace U\<close> \<open>dim V < dim U\<close> linear not_le)
   18.94 +      by (metis \<open>dim V < dim U\<close> assms(2) order.strict_implies_order span_eq_iff)
   18.95      then have "V homeomorphic T"
   18.96        by (simp add: \<open>subspace V\<close> homeomorphic_subspaces)
   18.97      then obtain h k where homhk: "homeomorphism V T h k"
    19.1 --- a/src/HOL/Analysis/Henstock_Kurzweil_Integration.thy	Wed Apr 18 21:12:50 2018 +0100
    19.2 +++ b/src/HOL/Analysis/Henstock_Kurzweil_Integration.thy	Wed May 02 13:49:38 2018 +0200
    19.3 @@ -2866,7 +2866,7 @@
    19.4    then have "?sum b = f b"
    19.5      using Suc_pred'[OF \<open>p > 0\<close>]
    19.6      by (simp add: diff_eq_eq Dg_def power_0_left le_Suc_eq if_distrib
    19.7 -        cond_application_beta sum.If_cases f0)
    19.8 +        if_distribR sum.If_cases f0)
    19.9    also
   19.10    have "{..<p} = (\<lambda>x. p - x - 1) ` {..<p}"
   19.11    proof safe
    20.1 --- a/src/HOL/Analysis/Homeomorphism.thy	Wed Apr 18 21:12:50 2018 +0100
    20.2 +++ b/src/HOL/Analysis/Homeomorphism.thy	Wed May 02 13:49:38 2018 +0200
    20.3 @@ -941,7 +941,7 @@
    20.4      apply (rule choose_subspace_of_subspace [of "dim ((+) (- a) ` S)" "{x::'n. i \<bullet> x = 0}"])
    20.5       apply (simp add: dim_hyperplane [OF \<open>i \<noteq> 0\<close>])
    20.6       apply (metis DIM_positive Suc_pred dd not_le not_less_eq_eq)
    20.7 -    apply (metis span_eq subspace_hyperplane)
    20.8 +    apply (metis span_eq_iff subspace_hyperplane)
    20.9      done
   20.10    have "subspace (span ((+) (- a) ` S))"
   20.11      using subspace_span by blast
   20.12 @@ -956,7 +956,7 @@
   20.13    have hcont: "continuous_on A h" and kcont: "continuous_on B k" for A B
   20.14      using \<open>linear h\<close> \<open>linear k\<close> linear_continuous_on linear_conv_bounded_linear by blast+
   20.15    have ihhhh[simp]: "\<And>x. x \<in> S \<Longrightarrow> i \<bullet> h (x - a) = 0"
   20.16 -    using Tsub [THEN subsetD] heq span_inc by fastforce
   20.17 +    using Tsub [THEN subsetD] heq span_superset by fastforce
   20.18    have "sphere 0 1 - {i} homeomorphic {x. i \<bullet> x = 0}"
   20.19      apply (rule homeomorphic_punctured_sphere_affine)
   20.20      using i
    21.1 --- a/src/HOL/Analysis/Inner_Product.thy	Wed Apr 18 21:12:50 2018 +0100
    21.2 +++ b/src/HOL/Analysis/Inner_Product.thy	Wed May 02 13:49:38 2018 +0200
    21.3 @@ -161,6 +161,44 @@
    21.4  
    21.5  end
    21.6  
    21.7 +lemma square_bound_lemma:
    21.8 +  fixes x :: real
    21.9 +  shows "x < (1 + x) * (1 + x)"
   21.10 +proof -
   21.11 +  have "(x + 1/2)\<^sup>2 + 3/4 > 0"
   21.12 +    using zero_le_power2[of "x+1/2"] by arith
   21.13 +  then show ?thesis
   21.14 +    by (simp add: field_simps power2_eq_square)
   21.15 +qed
   21.16 +
   21.17 +lemma square_continuous:
   21.18 +  fixes e :: real
   21.19 +  shows "e > 0 \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. \<bar>y - x\<bar> < d \<longrightarrow> \<bar>y * y - x * x\<bar> < e)"
   21.20 +  using isCont_power[OF continuous_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2]
   21.21 +  by (force simp add: power2_eq_square)
   21.22 +
   21.23 +lemma norm_eq_0_dot: "norm x = 0 \<longleftrightarrow> inner x x = (0::real)"
   21.24 +  by simp (* TODO: delete *)
   21.25 +
   21.26 +lemma norm_triangle_sub:
   21.27 +  fixes x y :: "'a::real_normed_vector"
   21.28 +  shows "norm x \<le> norm y + norm (x - y)"
   21.29 +  using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps)
   21.30 +
   21.31 +lemma norm_le: "norm x \<le> norm y \<longleftrightarrow> inner x x \<le> inner y y"
   21.32 +  by (simp add: norm_eq_sqrt_inner)
   21.33 +
   21.34 +lemma norm_lt: "norm x < norm y \<longleftrightarrow> inner x x < inner y y"
   21.35 +  by (simp add: norm_eq_sqrt_inner)
   21.36 +
   21.37 +lemma norm_eq: "norm x = norm y \<longleftrightarrow> inner x x = inner y y"
   21.38 +  apply (subst order_eq_iff)
   21.39 +  apply (auto simp: norm_le)
   21.40 +  done
   21.41 +
   21.42 +lemma norm_eq_1: "norm x = 1 \<longleftrightarrow> inner x x = 1"
   21.43 +  by (simp add: norm_eq_sqrt_inner)
   21.44 +
   21.45  lemma inner_divide_left:
   21.46    fixes a :: "'a :: {real_inner,real_div_algebra}"
   21.47    shows "inner (a / of_real m) b = (inner a b) / m"
    22.1 --- a/src/HOL/Analysis/Linear_Algebra.thy	Wed Apr 18 21:12:50 2018 +0100
    22.2 +++ b/src/HOL/Analysis/Linear_Algebra.thy	Wed May 02 13:49:38 2018 +0200
    22.3 @@ -23,8 +23,8 @@
    22.4    show "f (a + b) = f a + f b" by (rule f.add)
    22.5    show "f (a - b) = f a - f b" by (rule f.diff)
    22.6    show "f 0 = 0" by (rule f.zero)
    22.7 -  show "f (- a) = - f a" by (rule f.minus)
    22.8 -  show "f (s *\<^sub>R v) = s *\<^sub>R (f v)" by (rule f.scaleR)
    22.9 +  show "f (- a) = - f a" by (rule f.neg)
   22.10 +  show "f (s *\<^sub>R v) = s *\<^sub>R (f v)" by (rule f.scale)
   22.11  qed
   22.12  
   22.13  lemma bounded_linearI:
   22.14 @@ -34,1312 +34,6 @@
   22.15    shows "bounded_linear f"
   22.16    using assms by (rule bounded_linear_intro) (* FIXME: duplicate *)
   22.17  
   22.18 -subsection \<open>A generic notion of "hull" (convex, affine, conic hull and closure).\<close>
   22.19 -
   22.20 -definition%important hull :: "('a set \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "hull" 75)
   22.21 -  where "S hull s = \<Inter>{t. S t \<and> s \<subseteq> t}"
   22.22 -
   22.23 -lemma hull_same: "S s \<Longrightarrow> S hull s = s"
   22.24 -  unfolding hull_def by auto
   22.25 -
   22.26 -lemma hull_in: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> S (S hull s)"
   22.27 -  unfolding hull_def Ball_def by auto
   22.28 -
   22.29 -lemma hull_eq: "(\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)) \<Longrightarrow> (S hull s) = s \<longleftrightarrow> S s"
   22.30 -  using hull_same[of S s] hull_in[of S s] by metis
   22.31 -
   22.32 -lemma hull_hull [simp]: "S hull (S hull s) = S hull s"
   22.33 -  unfolding hull_def by blast
   22.34 -
   22.35 -lemma hull_subset[intro]: "s \<subseteq> (S hull s)"
   22.36 -  unfolding hull_def by blast
   22.37 -
   22.38 -lemma hull_mono: "s \<subseteq> t \<Longrightarrow> (S hull s) \<subseteq> (S hull t)"
   22.39 -  unfolding hull_def by blast
   22.40 -
   22.41 -lemma hull_antimono: "\<forall>x. S x \<longrightarrow> T x \<Longrightarrow> (T hull s) \<subseteq> (S hull s)"
   22.42 -  unfolding hull_def by blast
   22.43 -
   22.44 -lemma hull_minimal: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (S hull s) \<subseteq> t"
   22.45 -  unfolding hull_def by blast
   22.46 -
   22.47 -lemma subset_hull: "S t \<Longrightarrow> S hull s \<subseteq> t \<longleftrightarrow> s \<subseteq> t"
   22.48 -  unfolding hull_def by blast
   22.49 -
   22.50 -lemma hull_UNIV [simp]: "S hull UNIV = UNIV"
   22.51 -  unfolding hull_def by auto
   22.52 -
   22.53 -lemma hull_unique: "s \<subseteq> t \<Longrightarrow> S t \<Longrightarrow> (\<And>t'. s \<subseteq> t' \<Longrightarrow> S t' \<Longrightarrow> t \<subseteq> t') \<Longrightarrow> (S hull s = t)"
   22.54 -  unfolding hull_def by auto
   22.55 -
   22.56 -lemma hull_induct: "(\<And>x. x\<in> S \<Longrightarrow> P x) \<Longrightarrow> Q {x. P x} \<Longrightarrow> \<forall>x\<in> Q hull S. P x"
   22.57 -  using hull_minimal[of S "{x. P x}" Q]
   22.58 -  by (auto simp add: subset_eq)
   22.59 -
   22.60 -lemma hull_inc: "x \<in> S \<Longrightarrow> x \<in> P hull S"
   22.61 -  by (metis hull_subset subset_eq)
   22.62 -
   22.63 -lemma hull_Un_subset: "(S hull s) \<union> (S hull t) \<subseteq> (S hull (s \<union> t))"
   22.64 -  unfolding Un_subset_iff by (metis hull_mono Un_upper1 Un_upper2)
   22.65 -
   22.66 -lemma hull_Un:
   22.67 -  assumes T: "\<And>T. Ball T S \<Longrightarrow> S (\<Inter>T)"
   22.68 -  shows "S hull (s \<union> t) = S hull (S hull s \<union> S hull t)"
   22.69 -  apply (rule equalityI)
   22.70 -  apply (meson hull_mono hull_subset sup.mono)
   22.71 -  by (metis hull_Un_subset hull_hull hull_mono)
   22.72 -
   22.73 -lemma hull_Un_left: "P hull (S \<union> T) = P hull (P hull S \<union> T)"
   22.74 -  apply (rule equalityI)
   22.75 -   apply (simp add: Un_commute hull_mono hull_subset sup.coboundedI2)
   22.76 -  by (metis Un_subset_iff hull_hull hull_mono hull_subset)
   22.77 -
   22.78 -lemma hull_Un_right: "P hull (S \<union> T) = P hull (S \<union> P hull T)"
   22.79 -  by (metis hull_Un_left sup.commute)
   22.80 -
   22.81 -lemma hull_insert:
   22.82 -   "P hull (insert a S) = P hull (insert a (P hull S))"
   22.83 -  by (metis hull_Un_right insert_is_Un)
   22.84 -
   22.85 -lemma hull_redundant_eq: "a \<in> (S hull s) \<longleftrightarrow> S hull (insert a s) = S hull s"
   22.86 -  unfolding hull_def by blast
   22.87 -
   22.88 -lemma hull_redundant: "a \<in> (S hull s) \<Longrightarrow> S hull (insert a s) = S hull s"
   22.89 -  by (metis hull_redundant_eq)
   22.90 -
   22.91 -subsection \<open>Linear functions.\<close>
   22.92 -
   22.93 -lemma%important linear_iff:
   22.94 -  "linear f \<longleftrightarrow> (\<forall>x y. f (x + y) = f x + f y) \<and> (\<forall>c x. f (c *\<^sub>R x) = c *\<^sub>R f x)"
   22.95 -  (is "linear f \<longleftrightarrow> ?rhs")
   22.96 -proof%unimportant
   22.97 -  assume "linear f"
   22.98 -  then interpret f: linear f .
   22.99 -  show "?rhs" by (simp add: f.add f.scaleR)
  22.100 -next
  22.101 -  assume "?rhs"
  22.102 -  then show "linear f" by unfold_locales simp_all
  22.103 -qed
  22.104 -
  22.105 -lemma linear_compose_cmul: "linear f \<Longrightarrow> linear (\<lambda>x. c *\<^sub>R f x)"
  22.106 -  by (simp add: linear_iff algebra_simps)
  22.107 -
  22.108 -lemma linear_compose_scaleR: "linear f \<Longrightarrow> linear (\<lambda>x. f x *\<^sub>R c)"
  22.109 -  by (simp add: linear_iff scaleR_add_left)
  22.110 -
  22.111 -lemma linear_compose_neg: "linear f \<Longrightarrow> linear (\<lambda>x. - f x)"
  22.112 -  by (simp add: linear_iff)
  22.113 -
  22.114 -lemma linear_compose_add: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x + g x)"
  22.115 -  by (simp add: linear_iff algebra_simps)
  22.116 -
  22.117 -lemma linear_compose_sub: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (\<lambda>x. f x - g x)"
  22.118 -  by (simp add: linear_iff algebra_simps)
  22.119 -
  22.120 -lemma linear_compose: "linear f \<Longrightarrow> linear g \<Longrightarrow> linear (g \<circ> f)"
  22.121 -  by (simp add: linear_iff)
  22.122 -
  22.123 -lemma linear_id: "linear id"
  22.124 -  by (simp add: linear_iff id_def)
  22.125 -
  22.126 -lemma linear_zero: "linear (\<lambda>x. 0)"
  22.127 -  by (simp add: linear_iff)
  22.128 -
  22.129 -lemma linear_uminus: "linear uminus"
  22.130 -by (simp add: linear_iff)
  22.131 -
  22.132 -lemma linear_compose_sum:
  22.133 -  assumes lS: "\<forall>a \<in> S. linear (f a)"
  22.134 -  shows "linear (\<lambda>x. sum (\<lambda>a. f a x) S)"
  22.135 -proof (cases "finite S")
  22.136 -  case True
  22.137 -  then show ?thesis
  22.138 -    using lS by induct (simp_all add: linear_zero linear_compose_add)
  22.139 -next
  22.140 -  case False
  22.141 -  then show ?thesis
  22.142 -    by (simp add: linear_zero)
  22.143 -qed
  22.144 -
  22.145 -lemma linear_0: "linear f \<Longrightarrow> f 0 = 0"
  22.146 -  unfolding linear_iff
  22.147 -  apply clarsimp
  22.148 -  apply (erule allE[where x="0::'a"])
  22.149 -  apply simp
  22.150 -  done
  22.151 -
  22.152 -lemma linear_cmul: "linear f \<Longrightarrow> f (c *\<^sub>R x) = c *\<^sub>R f x"
  22.153 -  by (rule linear.scaleR)
  22.154 -
  22.155 -lemma linear_neg: "linear f \<Longrightarrow> f (- x) = - f x"
  22.156 -  using linear_cmul [where c="-1"] by simp
  22.157 -
  22.158 -lemma linear_add: "linear f \<Longrightarrow> f (x + y) = f x + f y"
  22.159 -  by (metis linear_iff)
  22.160 -
  22.161 -lemma linear_diff: "linear f \<Longrightarrow> f (x - y) = f x - f y"
  22.162 -  using linear_add [of f x "- y"] by (simp add: linear_neg)
  22.163 -
  22.164 -lemma linear_sum:
  22.165 -  assumes f: "linear f"
  22.166 -  shows "f (sum g S) = sum (f \<circ> g) S"
  22.167 -proof (cases "finite S")
  22.168 -  case True
  22.169 -  then show ?thesis
  22.170 -    by induct (simp_all add: linear_0 [OF f] linear_add [OF f])
  22.171 -next
  22.172 -  case False
  22.173 -  then show ?thesis
  22.174 -    by (simp add: linear_0 [OF f])
  22.175 -qed
  22.176 -
  22.177 -lemma linear_sum_mul:
  22.178 -  assumes lin: "linear f"
  22.179 -  shows "f (sum (\<lambda>i. c i *\<^sub>R v i) S) = sum (\<lambda>i. c i *\<^sub>R f (v i)) S"
  22.180 -  using linear_sum[OF lin, of "\<lambda>i. c i *\<^sub>R v i" , unfolded o_def] linear_cmul[OF lin]
  22.181 -  by simp
  22.182 -
  22.183 -lemma linear_injective_0:
  22.184 -  assumes lin: "linear f"
  22.185 -  shows "inj f \<longleftrightarrow> (\<forall>x. f x = 0 \<longrightarrow> x = 0)"
  22.186 -proof -
  22.187 -  have "inj f \<longleftrightarrow> (\<forall> x y. f x = f y \<longrightarrow> x = y)"
  22.188 -    by (simp add: inj_on_def)
  22.189 -  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f x - f y = 0 \<longrightarrow> x - y = 0)"
  22.190 -    by simp
  22.191 -  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f (x - y) = 0 \<longrightarrow> x - y = 0)"
  22.192 -    by (simp add: linear_diff[OF lin])
  22.193 -  also have "\<dots> \<longleftrightarrow> (\<forall> x. f x = 0 \<longrightarrow> x = 0)"
  22.194 -    by auto
  22.195 -  finally show ?thesis .
  22.196 -qed
  22.197 -
  22.198 -lemma linear_scaleR  [simp]: "linear (\<lambda>x. scaleR c x)"
  22.199 -  by (simp add: linear_iff scaleR_add_right)
  22.200 -
  22.201 -lemma linear_scaleR_left [simp]: "linear (\<lambda>r. scaleR r x)"
  22.202 -  by (simp add: linear_iff scaleR_add_left)
  22.203 -
  22.204 -lemma injective_scaleR: "c \<noteq> 0 \<Longrightarrow> inj (\<lambda>x::'a::real_vector. scaleR c x)"
  22.205 -  by (simp add: inj_on_def)
  22.206 -
  22.207 -lemma linear_add_cmul:
  22.208 -  assumes "linear f"
  22.209 -  shows "f (a *\<^sub>R x + b *\<^sub>R y) = a *\<^sub>R f x +  b *\<^sub>R f y"
  22.210 -  using linear_add[of f] linear_cmul[of f] assms by simp
  22.211 -
  22.212 -subsection \<open>Subspaces of vector spaces\<close>
  22.213 -
  22.214 -definition%important (in real_vector) subspace :: "'a set \<Rightarrow> bool"
  22.215 -  where "subspace S \<longleftrightarrow> 0 \<in> S \<and> (\<forall>x \<in> S. \<forall>y \<in> S. x + y \<in> S) \<and> (\<forall>c. \<forall>x \<in> S. c *\<^sub>R x \<in> S)"
  22.216 -
  22.217 -definition%important (in real_vector) "span S = (subspace hull S)"
  22.218 -definition%important (in real_vector) "dependent S \<longleftrightarrow> (\<exists>a \<in> S. a \<in> span (S - {a}))"
  22.219 -abbreviation (in real_vector) "independent s \<equiv> \<not> dependent s"
  22.220 -
  22.221 -text \<open>Closure properties of subspaces.\<close>
  22.222 -
  22.223 -lemma subspace_UNIV[simp]: "subspace UNIV"
  22.224 -  by (simp add: subspace_def)
  22.225 -
  22.226 -lemma (in real_vector) subspace_0: "subspace S \<Longrightarrow> 0 \<in> S"
  22.227 -  by (metis subspace_def)
  22.228 -
  22.229 -lemma (in real_vector) subspace_add: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x + y \<in> S"
  22.230 -  by (metis subspace_def)
  22.231 -
  22.232 -lemma (in real_vector) subspace_mul: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> c *\<^sub>R x \<in> S"
  22.233 -  by (metis subspace_def)
  22.234 -
  22.235 -lemma subspace_neg: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> - x \<in> S"
  22.236 -  by (metis scaleR_minus1_left subspace_mul)
  22.237 -
  22.238 -lemma subspace_diff: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x - y \<in> S"
  22.239 -  using subspace_add [of S x "- y"] by (simp add: subspace_neg)
  22.240 -
  22.241 -lemma (in real_vector) subspace_sum:
  22.242 -  assumes sA: "subspace A"
  22.243 -    and f: "\<And>x. x \<in> B \<Longrightarrow> f x \<in> A"
  22.244 -  shows "sum f B \<in> A"
  22.245 -proof (cases "finite B")
  22.246 -  case True
  22.247 -  then show ?thesis
  22.248 -    using f by induct (simp_all add: subspace_0 [OF sA] subspace_add [OF sA])
  22.249 -qed (simp add: subspace_0 [OF sA])
  22.250 -
  22.251 -lemma subspace_trivial [iff]: "subspace {0}"
  22.252 -  by (simp add: subspace_def)
  22.253 -
  22.254 -lemma (in real_vector) subspace_inter: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<inter> B)"
  22.255 -  by (simp add: subspace_def)
  22.256 -
  22.257 -lemma subspace_Times: "subspace A \<Longrightarrow> subspace B \<Longrightarrow> subspace (A \<times> B)"
  22.258 -  unfolding subspace_def zero_prod_def by simp
  22.259 -
  22.260 -lemma subspace_sums: "\<lbrakk>subspace S; subspace T\<rbrakk> \<Longrightarrow> subspace {x + y|x y. x \<in> S \<and> y \<in> T}"
  22.261 -apply (simp add: subspace_def)
  22.262 -apply (intro conjI impI allI)
  22.263 -  using add.right_neutral apply blast
  22.264 - apply clarify
  22.265 - apply (metis add.assoc add.left_commute)
  22.266 -using scaleR_add_right by blast
  22.267 -
  22.268 -subsection%unimportant \<open>Properties of span\<close>
  22.269 -
  22.270 -lemma (in real_vector) span_mono: "A \<subseteq> B \<Longrightarrow> span A \<subseteq> span B"
  22.271 -  by (metis span_def hull_mono)
  22.272 -
  22.273 -lemma (in real_vector) subspace_span [iff]: "subspace (span S)"
  22.274 -  unfolding span_def
  22.275 -  apply (rule hull_in)
  22.276 -  apply (simp only: subspace_def Inter_iff Int_iff subset_eq)
  22.277 -  apply auto
  22.278 -  done
  22.279 -
  22.280 -lemma (in real_vector) span_clauses:
  22.281 -  "a \<in> S \<Longrightarrow> a \<in> span S"
  22.282 -  "0 \<in> span S"
  22.283 -  "x\<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S"
  22.284 -  "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S"
  22.285 -  by (metis span_def hull_subset subset_eq) (metis subspace_span subspace_def)+
  22.286 -
  22.287 -lemma span_unique:
  22.288 -  "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> (\<And>T'. S \<subseteq> T' \<Longrightarrow> subspace T' \<Longrightarrow> T \<subseteq> T') \<Longrightarrow> span S = T"
  22.289 -  unfolding span_def by (rule hull_unique)
  22.290 -
  22.291 -lemma span_minimal: "S \<subseteq> T \<Longrightarrow> subspace T \<Longrightarrow> span S \<subseteq> T"
  22.292 -  unfolding span_def by (rule hull_minimal)
  22.293 -
  22.294 -lemma span_UNIV [simp]: "span UNIV = UNIV"
  22.295 -  by (intro span_unique) auto
  22.296 -
  22.297 -lemma (in real_vector) span_induct:
  22.298 -  assumes x: "x \<in> span S"
  22.299 -    and P: "subspace (Collect P)"
  22.300 -    and SP: "\<And>x. x \<in> S \<Longrightarrow> P x"
  22.301 -  shows "P x"
  22.302 -proof -
  22.303 -  from SP have SP': "S \<subseteq> Collect P"
  22.304 -    by (simp add: subset_eq)
  22.305 -  from x hull_minimal[where S=subspace, OF SP' P, unfolded span_def[symmetric]]
  22.306 -  show ?thesis
  22.307 -    using subset_eq by force
  22.308 -qed
  22.309 -
  22.310 -lemma span_empty[simp]: "span {} = {0}"
  22.311 -  apply (simp add: span_def)
  22.312 -  apply (rule hull_unique)
  22.313 -  apply (auto simp add: subspace_def)
  22.314 -  done
  22.315 -
  22.316 -lemma (in real_vector) independent_empty [iff]: "independent {}"
  22.317 -  by (simp add: dependent_def)
  22.318 -
  22.319 -lemma dependent_single[simp]: "dependent {x} \<longleftrightarrow> x = 0"
  22.320 -  unfolding dependent_def by auto
  22.321 -
  22.322 -lemma (in real_vector) independent_mono: "independent A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> independent B"
  22.323 -  apply (clarsimp simp add: dependent_def span_mono)
  22.324 -  apply (subgoal_tac "span (B - {a}) \<le> span (A - {a})")
  22.325 -  apply force
  22.326 -  apply (rule span_mono)
  22.327 -  apply auto
  22.328 -  done
  22.329 -
  22.330 -lemma (in real_vector) span_subspace: "A \<subseteq> B \<Longrightarrow> B \<le> span A \<Longrightarrow>  subspace B \<Longrightarrow> span A = B"
  22.331 -  by (metis order_antisym span_def hull_minimal)
  22.332 -
  22.333 -lemma (in real_vector) span_induct':
  22.334 -  "\<forall>x \<in> S. P x \<Longrightarrow> subspace {x. P x} \<Longrightarrow> \<forall>x \<in> span S. P x"
  22.335 -  unfolding span_def by (rule hull_induct) auto
  22.336 -
  22.337 -inductive_set (in real_vector) span_induct_alt_help for S :: "'a set"
  22.338 -where
  22.339 -  span_induct_alt_help_0: "0 \<in> span_induct_alt_help S"
  22.340 -| span_induct_alt_help_S:
  22.341 -    "x \<in> S \<Longrightarrow> z \<in> span_induct_alt_help S \<Longrightarrow>
  22.342 -      (c *\<^sub>R x + z) \<in> span_induct_alt_help S"
  22.343 -
  22.344 -lemma span_induct_alt':
  22.345 -  assumes h0: "h 0"
  22.346 -    and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)"
  22.347 -  shows "\<forall>x \<in> span S. h x"
  22.348 -proof -
  22.349 -  {
  22.350 -    fix x :: 'a
  22.351 -    assume x: "x \<in> span_induct_alt_help S"
  22.352 -    have "h x"
  22.353 -      apply (rule span_induct_alt_help.induct[OF x])
  22.354 -      apply (rule h0)
  22.355 -      apply (rule hS)
  22.356 -      apply assumption
  22.357 -      apply assumption
  22.358 -      done
  22.359 -  }
  22.360 -  note th0 = this
  22.361 -  {
  22.362 -    fix x
  22.363 -    assume x: "x \<in> span S"
  22.364 -    have "x \<in> span_induct_alt_help S"
  22.365 -    proof (rule span_induct[where x=x and S=S])
  22.366 -      show "x \<in> span S" by (rule x)
  22.367 -    next
  22.368 -      fix x
  22.369 -      assume xS: "x \<in> S"
  22.370 -      from span_induct_alt_help_S[OF xS span_induct_alt_help_0, of 1]
  22.371 -      show "x \<in> span_induct_alt_help S"
  22.372 -        by simp
  22.373 -    next
  22.374 -      have "0 \<in> span_induct_alt_help S" by (rule span_induct_alt_help_0)
  22.375 -      moreover
  22.376 -      {
  22.377 -        fix x y
  22.378 -        assume h: "x \<in> span_induct_alt_help S" "y \<in> span_induct_alt_help S"
  22.379 -        from h have "(x + y) \<in> span_induct_alt_help S"
  22.380 -          apply (induct rule: span_induct_alt_help.induct)
  22.381 -          apply simp
  22.382 -          unfolding add.assoc
  22.383 -          apply (rule span_induct_alt_help_S)
  22.384 -          apply assumption
  22.385 -          apply simp
  22.386 -          done
  22.387 -      }
  22.388 -      moreover
  22.389 -      {
  22.390 -        fix c x
  22.391 -        assume xt: "x \<in> span_induct_alt_help S"
  22.392 -        then have "(c *\<^sub>R x) \<in> span_induct_alt_help S"
  22.393 -          apply (induct rule: span_induct_alt_help.induct)
  22.394 -          apply (simp add: span_induct_alt_help_0)
  22.395 -          apply (simp add: scaleR_right_distrib)
  22.396 -          apply (rule span_induct_alt_help_S)
  22.397 -          apply assumption
  22.398 -          apply simp
  22.399 -          done }
  22.400 -      ultimately show "subspace {a. a \<in> span_induct_alt_help S}"
  22.401 -        unfolding subspace_def Ball_def by blast
  22.402 -    qed
  22.403 -  }
  22.404 -  with th0 show ?thesis by blast
  22.405 -qed
  22.406 -
  22.407 -lemma span_induct_alt:
  22.408 -  assumes h0: "h 0"
  22.409 -    and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c *\<^sub>R x + y)"
  22.410 -    and x: "x \<in> span S"
  22.411 -  shows "h x"
  22.412 -  using span_induct_alt'[of h S] h0 hS x by blast
  22.413 -
  22.414 -text \<open>Individual closure properties.\<close>
  22.415 -
  22.416 -lemma span_span: "span (span A) = span A"
  22.417 -  unfolding span_def hull_hull ..
  22.418 -
  22.419 -lemma (in real_vector) span_superset: "x \<in> S \<Longrightarrow> x \<in> span S"
  22.420 -  by (metis span_clauses(1))
  22.421 -
  22.422 -lemma (in real_vector) span_0 [simp]: "0 \<in> span S"
  22.423 -  by (metis subspace_span subspace_0)
  22.424 -
  22.425 -lemma span_inc: "S \<subseteq> span S"
  22.426 -  by (metis subset_eq span_superset)
  22.427 -
  22.428 -lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S"
  22.429 -  using span_inc[unfolded subset_eq] using span_mono[of T "span S"] span_mono[of S "span T"]
  22.430 -  by (auto simp add: span_span)
  22.431 -
  22.432 -lemma (in real_vector) dependent_0:
  22.433 -  assumes "0 \<in> A"
  22.434 -  shows "dependent A"
  22.435 -  unfolding dependent_def
  22.436 -  using assms span_0
  22.437 -  by blast
  22.438 -
  22.439 -lemma (in real_vector) span_add: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x + y \<in> span S"
  22.440 -  by (metis subspace_add subspace_span)
  22.441 -
  22.442 -lemma (in real_vector) span_mul: "x \<in> span S \<Longrightarrow> c *\<^sub>R x \<in> span S"
  22.443 -  by (metis subspace_span subspace_mul)
  22.444 -
  22.445 -lemma span_neg: "x \<in> span S \<Longrightarrow> - x \<in> span S"
  22.446 -  by (metis subspace_neg subspace_span)
  22.447 -
  22.448 -lemma span_diff: "x \<in> span S \<Longrightarrow> y \<in> span S \<Longrightarrow> x - y \<in> span S"
  22.449 -  by (metis subspace_span subspace_diff)
  22.450 -
  22.451 -lemma (in real_vector) span_sum: "(\<And>x. x \<in> A \<Longrightarrow> f x \<in> span S) \<Longrightarrow> sum f A \<in> span S"
  22.452 -  by (rule subspace_sum [OF subspace_span])
  22.453 -
  22.454 -lemma span_add_eq: "x \<in> span S \<Longrightarrow> x + y \<in> span S \<longleftrightarrow> y \<in> span S"
  22.455 -  by (metis add_minus_cancel scaleR_minus1_left subspace_def subspace_span)
  22.456 -
  22.457 -text \<open>The key breakdown property.\<close>
  22.458 -
  22.459 -lemma span_singleton: "span {x} = range (\<lambda>k. k *\<^sub>R x)"
  22.460 -proof (rule span_unique)
  22.461 -  show "{x} \<subseteq> range (\<lambda>k. k *\<^sub>R x)"
  22.462 -    by (fast intro: scaleR_one [symmetric])
  22.463 -  show "subspace (range (\<lambda>k. k *\<^sub>R x))"
  22.464 -    unfolding subspace_def
  22.465 -    by (auto intro: scaleR_add_left [symmetric])
  22.466 -next
  22.467 -  fix T
  22.468 -  assume "{x} \<subseteq> T" and "subspace T"
  22.469 -  then show "range (\<lambda>k. k *\<^sub>R x) \<subseteq> T"
  22.470 -    unfolding subspace_def by auto
  22.471 -qed
  22.472 -
  22.473 -text \<open>Mapping under linear image.\<close>
  22.474 -
  22.475 -lemma subspace_linear_image:
  22.476 -  assumes lf: "linear f"
  22.477 -    and sS: "subspace S"
  22.478 -  shows "subspace (f ` S)"
  22.479 -  using lf sS linear_0[OF lf]
  22.480 -  unfolding linear_iff subspace_def
  22.481 -  apply (auto simp add: image_iff)
  22.482 -  apply (rule_tac x="x + y" in bexI)
  22.483 -  apply auto
  22.484 -  apply (rule_tac x="c *\<^sub>R x" in bexI)
  22.485 -  apply auto
  22.486 -  done
  22.487 -
  22.488 -lemma subspace_linear_vimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace (f -` S)"
  22.489 -  by (auto simp add: subspace_def linear_iff linear_0[of f])
  22.490 -
  22.491 -lemma subspace_linear_preimage: "linear f \<Longrightarrow> subspace S \<Longrightarrow> subspace {x. f x \<in> S}"
  22.492 -  by (auto simp add: subspace_def linear_iff linear_0[of f])
  22.493 -
  22.494 -lemma span_linear_image:
  22.495 -  assumes lf: "linear f"
  22.496 -  shows "span (f ` S) = f ` span S"
  22.497 -proof (rule span_unique)
  22.498 -  show "f ` S \<subseteq> f ` span S"
  22.499 -    by (intro image_mono span_inc)
  22.500 -  show "subspace (f ` span S)"
  22.501 -    using lf subspace_span by (rule subspace_linear_image)
  22.502 -next
  22.503 -  fix T
  22.504 -  assume "f ` S \<subseteq> T" and "subspace T"
  22.505 -  then show "f ` span S \<subseteq> T"
  22.506 -    unfolding image_subset_iff_subset_vimage
  22.507 -    by (intro span_minimal subspace_linear_vimage lf)
  22.508 -qed
  22.509 -
  22.510 -lemma spans_image:
  22.511 -  assumes lf: "linear f"
  22.512 -    and VB: "V \<subseteq> span B"
  22.513 -  shows "f ` V \<subseteq> span (f ` B)"
  22.514 -  unfolding span_linear_image[OF lf] by (metis VB image_mono)
  22.515 -
  22.516 -lemma span_Un: "span (A \<union> B) = (\<lambda>(a, b). a + b) ` (span A \<times> span B)"
  22.517 -proof (rule span_unique)
  22.518 -  show "A \<union> B \<subseteq> (\<lambda>(a, b). a + b) ` (span A \<times> span B)"
  22.519 -    by safe (force intro: span_clauses)+
  22.520 -next
  22.521 -  have "linear (\<lambda>(a, b). a + b)"
  22.522 -    by (simp add: linear_iff scaleR_add_right)
  22.523 -  moreover have "subspace (span A \<times> span B)"
  22.524 -    by (intro subspace_Times subspace_span)
  22.525 -  ultimately show "subspace ((\<lambda>(a, b). a + b) ` (span A \<times> span B))"
  22.526 -    by (rule subspace_linear_image)
  22.527 -next
  22.528 -  fix T
  22.529 -  assume "A \<union> B \<subseteq> T" and "subspace T"
  22.530 -  then show "(\<lambda>(a, b). a + b) ` (span A \<times> span B) \<subseteq> T"
  22.531 -    by (auto intro!: subspace_add elim: span_induct)
  22.532 -qed
  22.533 -
  22.534 -lemma span_insert: "span (insert a S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
  22.535 -proof -
  22.536 -  have "span ({a} \<union> S) = {x. \<exists>k. (x - k *\<^sub>R a) \<in> span S}"
  22.537 -    unfolding span_Un span_singleton
  22.538 -    apply safe
  22.539 -    apply (rule_tac x=k in exI, simp)
  22.540 -    apply (erule rev_image_eqI [OF SigmaI [OF rangeI]])
  22.541 -    apply auto
  22.542 -    done
  22.543 -  then show ?thesis by simp
  22.544 -qed
  22.545 -
  22.546 -lemma span_breakdown:
  22.547 -  assumes bS: "b \<in> S"
  22.548 -    and aS: "a \<in> span S"
  22.549 -  shows "\<exists>k. a - k *\<^sub>R b \<in> span (S - {b})"
  22.550 -  using assms span_insert [of b "S - {b}"]
  22.551 -  by (simp add: insert_absorb)
  22.552 -
  22.553 -lemma span_breakdown_eq: "x \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. x - k *\<^sub>R a \<in> span S)"
  22.554 -  by (simp add: span_insert)
  22.555 -
  22.556 -text \<open>Hence some "reversal" results.\<close>
  22.557 -
  22.558 -lemma in_span_insert:
  22.559 -  assumes a: "a \<in> span (insert b S)"
  22.560 -    and na: "a \<notin> span S"
  22.561 -  shows "b \<in> span (insert a S)"
  22.562 -proof -
  22.563 -  from a obtain k where k: "a - k *\<^sub>R b \<in> span S"
  22.564 -    unfolding span_insert by fast
  22.565 -  show ?thesis
  22.566 -  proof (cases "k = 0")
  22.567 -    case True
  22.568 -    with k have "a \<in> span S" by simp
  22.569 -    with na show ?thesis by simp
  22.570 -  next
  22.571 -    case False
  22.572 -    from k have "(- inverse k) *\<^sub>R (a - k *\<^sub>R b) \<in> span S"
  22.573 -      by (rule span_mul)
  22.574 -    then have "b - inverse k *\<^sub>R a \<in> span S"
  22.575 -      using \<open>k \<noteq> 0\<close> by (simp add: scaleR_diff_right)
  22.576 -    then show ?thesis
  22.577 -      unfolding span_insert by fast
  22.578 -  qed
  22.579 -qed
  22.580 -
  22.581 -lemma in_span_delete:
  22.582 -  assumes a: "a \<in> span S"
  22.583 -    and na: "a \<notin> span (S - {b})"
  22.584 -  shows "b \<in> span (insert a (S - {b}))"
  22.585 -  apply (rule in_span_insert)
  22.586 -  apply (rule set_rev_mp)
  22.587 -  apply (rule a)
  22.588 -  apply (rule span_mono)
  22.589 -  apply blast
  22.590 -  apply (rule na)
  22.591 -  done
  22.592 -
  22.593 -text \<open>Transitivity property.\<close>
  22.594 -
  22.595 -lemma span_redundant: "x \<in> span S \<Longrightarrow> span (insert x S) = span S"
  22.596 -  unfolding span_def by (rule hull_redundant)
  22.597 -
  22.598 -lemma span_trans:
  22.599 -  assumes x: "x \<in> span S"
  22.600 -    and y: "y \<in> span (insert x S)"
  22.601 -  shows "y \<in> span S"
  22.602 -  using assms by (simp only: span_redundant)
  22.603 -
  22.604 -lemma span_insert_0[simp]: "span (insert 0 S) = span S"
  22.605 -  by (simp only: span_redundant span_0)
  22.606 -
  22.607 -text \<open>An explicit expansion is sometimes needed.\<close>
  22.608 -
  22.609 -lemma span_explicit:
  22.610 -  "span P = {y. \<exists>S u. finite S \<and> S \<subseteq> P \<and> sum (\<lambda>v. u v *\<^sub>R v) S = y}"
  22.611 -  (is "_ = ?E" is "_ = {y. ?h y}" is "_ = {y. \<exists>S u. ?Q S u y}")
  22.612 -proof -
  22.613 -  {
  22.614 -    fix x
  22.615 -    assume "?h x"
  22.616 -    then obtain S u where "finite S" and "S \<subseteq> P" and "sum (\<lambda>v. u v *\<^sub>R v) S = x"
  22.617 -      by blast
  22.618 -    then have "x \<in> span P"
  22.619 -      by (auto intro: span_sum span_mul span_superset)
  22.620 -  }
  22.621 -  moreover
  22.622 -  have "\<forall>x \<in> span P. ?h x"
  22.623 -  proof (rule span_induct_alt')
  22.624 -    show "?h 0"
  22.625 -      by (rule exI[where x="{}"], simp)
  22.626 -  next
  22.627 -    fix c x y
  22.628 -    assume x: "x \<in> P"
  22.629 -    assume hy: "?h y"
  22.630 -    from hy obtain S u where fS: "finite S" and SP: "S\<subseteq>P"
  22.631 -      and u: "sum (\<lambda>v. u v *\<^sub>R v) S = y" by blast
  22.632 -    let ?S = "insert x S"
  22.633 -    let ?u = "\<lambda>y. if y = x then (if x \<in> S then u y + c else c) else u y"
  22.634 -    from fS SP x have th0: "finite (insert x S)" "insert x S \<subseteq> P"
  22.635 -      by blast+
  22.636 -    have "?Q ?S ?u (c*\<^sub>R x + y)"
  22.637 -    proof cases
  22.638 -      assume xS: "x \<in> S"
  22.639 -      have "sum (\<lambda>v. ?u v *\<^sub>R v) ?S = (\<Sum>v\<in>S - {x}. u v *\<^sub>R v) + (u x + c) *\<^sub>R x"
  22.640 -        using xS by (simp add: sum.remove [OF fS xS] insert_absorb)
  22.641 -      also have "\<dots> = (\<Sum>v\<in>S. u v *\<^sub>R v) + c *\<^sub>R x"
  22.642 -        by (simp add: sum.remove [OF fS xS] algebra_simps)
  22.643 -      also have "\<dots> = c*\<^sub>R x + y"
  22.644 -        by (simp add: add.commute u)
  22.645 -      finally have "sum (\<lambda>v. ?u v *\<^sub>R v) ?S = c*\<^sub>R x + y" .
  22.646 -      then show ?thesis using th0 by blast
  22.647 -    next
  22.648 -      assume xS: "x \<notin> S"
  22.649 -      have th00: "(\<Sum>v\<in>S. (if v = x then c else u v) *\<^sub>R v) = y"
  22.650 -        unfolding u[symmetric]
  22.651 -        apply (rule sum.cong)
  22.652 -        using xS
  22.653 -        apply auto
  22.654 -        done
  22.655 -      show ?thesis using fS xS th0
  22.656 -        by (simp add: th00 add.commute cong del: if_weak_cong)
  22.657 -    qed
  22.658 -    then show "?h (c*\<^sub>R x + y)"
  22.659 -      by fast
  22.660 -  qed
  22.661 -  ultimately show ?thesis by blast
  22.662 -qed
  22.663 -
  22.664 -lemma dependent_explicit:
  22.665 -  "dependent P \<longleftrightarrow> (\<exists>S u. finite S \<and> S \<subseteq> P \<and> (\<exists>v\<in>S. u v \<noteq> 0 \<and> sum (\<lambda>v. u v *\<^sub>R v) S = 0))"
  22.666 -  (is "?lhs = ?rhs")
  22.667 -proof -
  22.668 -  {
  22.669 -    assume dP: "dependent P"
  22.670 -    then obtain a S u where aP: "a \<in> P" and fS: "finite S"
  22.671 -      and SP: "S \<subseteq> P - {a}" and ua: "sum (\<lambda>v. u v *\<^sub>R v) S = a"
  22.672 -      unfolding dependent_def span_explicit by blast
  22.673 -    let ?S = "insert a S"
  22.674 -    let ?u = "\<lambda>y. if y = a then - 1 else u y"
  22.675 -    let ?v = a
  22.676 -    from aP SP have aS: "a \<notin> S"
  22.677 -      by blast
  22.678 -    from fS SP aP have th0: "finite ?S" "?S \<subseteq> P" "?v \<in> ?S" "?u ?v \<noteq> 0"
  22.679 -      by auto
  22.680 -    have s0: "sum (\<lambda>v. ?u v *\<^sub>R v) ?S = 0"
  22.681 -      using fS aS
  22.682 -      apply simp
  22.683 -      apply (subst (2) ua[symmetric])
  22.684 -      apply (rule sum.cong)
  22.685 -      apply auto
  22.686 -      done
  22.687 -    with th0 have ?rhs by fast
  22.688 -  }
  22.689 -  moreover
  22.690 -  {
  22.691 -    fix S u v
  22.692 -    assume fS: "finite S"
  22.693 -      and SP: "S \<subseteq> P"
  22.694 -      and vS: "v \<in> S"
  22.695 -      and uv: "u v \<noteq> 0"
  22.696 -      and u: "sum (\<lambda>v. u v *\<^sub>R v) S = 0"
  22.697 -    let ?a = v
  22.698 -    let ?S = "S - {v}"
  22.699 -    let ?u = "\<lambda>i. (- u i) / u v"
  22.700 -    have th0: "?a \<in> P" "finite ?S" "?S \<subseteq> P"
  22.701 -      using fS SP vS by auto
  22.702 -    have "sum (\<lambda>v. ?u v *\<^sub>R v) ?S =
  22.703 -      sum (\<lambda>v. (- (inverse (u ?a))) *\<^sub>R (u v *\<^sub>R v)) S - ?u v *\<^sub>R v"
  22.704 -      using fS vS uv by (simp add: sum_diff1 field_simps)
  22.705 -    also have "\<dots> = ?a"
  22.706 -      unfolding scaleR_right.sum [symmetric] u using uv by simp
  22.707 -    finally have "sum (\<lambda>v. ?u v *\<^sub>R v) ?S = ?a" .
  22.708 -    with th0 have ?lhs
  22.709 -      unfolding dependent_def span_explicit
  22.710 -      apply -
  22.711 -      apply (rule bexI[where x= "?a"])
  22.712 -      apply (simp_all del: scaleR_minus_left)
  22.713 -      apply (rule exI[where x= "?S"])
  22.714 -      apply (auto simp del: scaleR_minus_left)
  22.715 -      done
  22.716 -  }
  22.717 -  ultimately show ?thesis by blast
  22.718 -qed
  22.719 -
  22.720 -lemma dependent_finite:
  22.721 -  assumes "finite S"
  22.722 -    shows "dependent S \<longleftrightarrow> (\<exists>u. (\<exists>v \<in> S. u v \<noteq> 0) \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = 0)"
  22.723 -           (is "?lhs = ?rhs")
  22.724 -proof
  22.725 -  assume ?lhs
  22.726 -  then obtain T u v
  22.727 -         where "finite T" "T \<subseteq> S" "v\<in>T" "u v \<noteq> 0" "(\<Sum>v\<in>T. u v *\<^sub>R v) = 0"
  22.728 -    by (force simp: dependent_explicit)
  22.729 -  with assms show ?rhs
  22.730 -    apply (rule_tac x="\<lambda>v. if v \<in> T then u v else 0" in exI)
  22.731 -    apply (auto simp: sum.mono_neutral_right)
  22.732 -    done
  22.733 -next
  22.734 -  assume ?rhs  with assms show ?lhs
  22.735 -    by (fastforce simp add: dependent_explicit)
  22.736 -qed
  22.737 -
  22.738 -lemma span_alt:
  22.739 -  "span B = {(\<Sum>x | f x \<noteq> 0. f x *\<^sub>R x) | f. {x. f x \<noteq> 0} \<subseteq> B \<and> finite {x. f x \<noteq> 0}}"
  22.740 -  unfolding span_explicit
  22.741 -  apply safe
  22.742 -  subgoal for x S u
  22.743 -    by (intro exI[of _ "\<lambda>x. if x \<in> S then u x else 0"])
  22.744 -        (auto intro!: sum.mono_neutral_cong_right)
  22.745 -  apply auto
  22.746 -  done
  22.747 -
  22.748 -lemma dependent_alt:
  22.749 -  "dependent B \<longleftrightarrow>
  22.750 -    (\<exists>X. finite {x. X x \<noteq> 0} \<and> {x. X x \<noteq> 0} \<subseteq> B \<and> (\<Sum>x|X x \<noteq> 0. X x *\<^sub>R x) = 0 \<and> (\<exists>x. X x \<noteq> 0))"
  22.751 -  unfolding dependent_explicit
  22.752 -  apply safe
  22.753 -  subgoal for S u v
  22.754 -    apply (intro exI[of _ "\<lambda>x. if x \<in> S then u x else 0"])
  22.755 -    apply (subst sum.mono_neutral_cong_left[where T=S])
  22.756 -    apply (auto intro!: sum.mono_neutral_cong_right cong: rev_conj_cong)
  22.757 -    done
  22.758 -  apply auto
  22.759 -  done
  22.760 -
  22.761 -lemma independent_alt:
  22.762 -  "independent B \<longleftrightarrow>
  22.763 -    (\<forall>X. finite {x. X x \<noteq> 0} \<longrightarrow> {x. X x \<noteq> 0} \<subseteq> B \<longrightarrow> (\<Sum>x|X x \<noteq> 0. X x *\<^sub>R x) = 0 \<longrightarrow> (\<forall>x. X x = 0))"
  22.764 -  unfolding dependent_alt by auto
  22.765 -
  22.766 -lemma independentD_alt:
  22.767 -  "independent B \<Longrightarrow> finite {x. X x \<noteq> 0} \<Longrightarrow> {x. X x \<noteq> 0} \<subseteq> B \<Longrightarrow> (\<Sum>x|X x \<noteq> 0. X x *\<^sub>R x) = 0 \<Longrightarrow> X x = 0"
  22.768 -  unfolding independent_alt by blast
  22.769 -
  22.770 -lemma independentD_unique:
  22.771 -  assumes B: "independent B"
  22.772 -    and X: "finite {x. X x \<noteq> 0}" "{x. X x \<noteq> 0} \<subseteq> B"
  22.773 -    and Y: "finite {x. Y x \<noteq> 0}" "{x. Y x \<noteq> 0} \<subseteq> B"
  22.774 -    and "(\<Sum>x | X x \<noteq> 0. X x *\<^sub>R x) = (\<Sum>x| Y x \<noteq> 0. Y x *\<^sub>R x)"
  22.775 -  shows "X = Y"
  22.776 -proof -
  22.777 -  have "X x - Y x = 0" for x
  22.778 -    using B
  22.779 -  proof (rule independentD_alt)
  22.780 -    have "{x. X x - Y x \<noteq> 0} \<subseteq> {x. X x \<noteq> 0} \<union> {x. Y x \<noteq> 0}"
  22.781 -      by auto
  22.782 -    then show "finite {x. X x - Y x \<noteq> 0}" "{x. X x - Y x \<noteq> 0} \<subseteq> B"
  22.783 -      using X Y by (auto dest: finite_subset)
  22.784 -    then have "(\<Sum>x | X x - Y x \<noteq> 0. (X x - Y x) *\<^sub>R x) = (\<Sum>v\<in>{S. X S \<noteq> 0} \<union> {S. Y S \<noteq> 0}. (X v - Y v) *\<^sub>R v)"
  22.785 -      using X Y by (intro sum.mono_neutral_cong_left) auto
  22.786 -    also have "\<dots> = (\<Sum>v\<in>{S. X S \<noteq> 0} \<union> {S. Y S \<noteq> 0}. X v *\<^sub>R v) - (\<Sum>v\<in>{S. X S \<noteq> 0} \<union> {S. Y S \<noteq> 0}. Y v *\<^sub>R v)"
  22.787 -      by (simp add: scaleR_diff_left sum_subtractf assms)
  22.788 -    also have "(\<Sum>v\<in>{S. X S \<noteq> 0} \<union> {S. Y S \<noteq> 0}. X v *\<^sub>R v) = (\<Sum>v\<in>{S. X S \<noteq> 0}. X v *\<^sub>R v)"
  22.789 -      using X Y by (intro sum.mono_neutral_cong_right) auto
  22.790 -    also have "(\<Sum>v\<in>{S. X S \<noteq> 0} \<union> {S. Y S \<noteq> 0}. Y v *\<^sub>R v) = (\<Sum>v\<in>{S. Y S \<noteq> 0}. Y v *\<^sub>R v)"
  22.791 -      using X Y by (intro sum.mono_neutral_cong_right) auto
  22.792 -    finally show "(\<Sum>x | X x - Y x \<noteq> 0. (X x - Y x) *\<^sub>R x) = 0"
  22.793 -      using assms by simp
  22.794 -  qed
  22.795 -  then show ?thesis
  22.796 -    by auto
  22.797 -qed
  22.798 -
  22.799 -text \<open>This is useful for building a basis step-by-step.\<close>
  22.800 -
  22.801 -lemma independent_insert:
  22.802 -  "independent (insert a S) \<longleftrightarrow>
  22.803 -    (if a \<in> S then independent S else independent S \<and> a \<notin> span S)"
  22.804 -  (is "?lhs \<longleftrightarrow> ?rhs")
  22.805 -proof (cases "a \<in> S")
  22.806 -  case True
  22.807 -  then show ?thesis
  22.808 -    using insert_absorb[OF True] by simp
  22.809 -next
  22.810 -  case False
  22.811 -  show ?thesis
  22.812 -  proof
  22.813 -    assume i: ?lhs
  22.814 -    then show ?rhs
  22.815 -      using False
  22.816 -      apply simp
  22.817 -      apply (rule conjI)
  22.818 -      apply (rule independent_mono)
  22.819 -      apply assumption
  22.820 -      apply blast
  22.821 -      apply (simp add: dependent_def)
  22.822 -      done
  22.823 -  next
  22.824 -    assume i: ?rhs
  22.825 -    show ?lhs
  22.826 -      using i False
  22.827 -      apply (auto simp add: dependent_def)
  22.828 -      by (metis in_span_insert insert_Diff_if insert_Diff_single insert_absorb)
  22.829 -  qed
  22.830 -qed
  22.831 -
  22.832 -lemma independent_Union_directed:
  22.833 -  assumes directed: "\<And>c d. c \<in> C \<Longrightarrow> d \<in> C \<Longrightarrow> c \<subseteq> d \<or> d \<subseteq> c"
  22.834 -  assumes indep: "\<And>c. c \<in> C \<Longrightarrow> independent c"
  22.835 -  shows "independent (\<Union>C)"
  22.836 -proof
  22.837 -  assume "dependent (\<Union>C)"
  22.838 -  then obtain u v S where S: "finite S" "S \<subseteq> \<Union>C" "v \<in> S" "u v \<noteq> 0" "(\<Sum>v\<in>S. u v *\<^sub>R v) = 0"
  22.839 -    by (auto simp: dependent_explicit)
  22.840 -
  22.841 -  have "S \<noteq> {}"
  22.842 -    using \<open>v \<in> S\<close> by auto
  22.843 -  have "\<exists>c\<in>C. S \<subseteq> c"
  22.844 -    using \<open>finite S\<close> \<open>S \<noteq> {}\<close> \<open>S \<subseteq> \<Union>C\<close>
  22.845 -  proof (induction rule: finite_ne_induct)
  22.846 -    case (insert i I)
  22.847 -    then obtain c d where cd: "c \<in> C" "d \<in> C" and iI: "I \<subseteq> c" "i \<in> d"
  22.848 -      by blast
  22.849 -    from directed[OF cd] cd have "c \<union> d \<in> C"
  22.850 -      by (auto simp: sup.absorb1 sup.absorb2)
  22.851 -    with iI show ?case
  22.852 -      by (intro bexI[of _ "c \<union> d"]) auto
  22.853 -  qed auto
  22.854 -  then obtain c where "c \<in> C" "S \<subseteq> c"
  22.855 -    by auto
  22.856 -  have "dependent c"
  22.857 -    unfolding dependent_explicit
  22.858 -    by (intro exI[of _ S] exI[of _ u] bexI[of _ v] conjI) fact+
  22.859 -  with indep[OF \<open>c \<in> C\<close>] show False
  22.860 -    by auto
  22.861 -qed
  22.862 -
  22.863 -text \<open>Hence we can create a maximal independent subset.\<close>
  22.864 -
  22.865 -lemma maximal_independent_subset_extend:
  22.866 -  assumes "S \<subseteq> V" "independent S"
  22.867 -  shows "\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
  22.868 -proof -
  22.869 -  let ?C = "{B. S \<subseteq> B \<and> independent B \<and> B \<subseteq> V}"
  22.870 -  have "\<exists>M\<in>?C. \<forall>X\<in>?C. M \<subseteq> X \<longrightarrow> X = M"
  22.871 -  proof (rule subset_Zorn)
  22.872 -    fix C :: "'a set set" assume "subset.chain ?C C"
  22.873 -    then have C: "\<And>c. c \<in> C \<Longrightarrow> c \<subseteq> V" "\<And>c. c \<in> C \<Longrightarrow> S \<subseteq> c" "\<And>c. c \<in> C \<Longrightarrow> independent c"
  22.874 -      "\<And>c d. c \<in> C \<Longrightarrow> d \<in> C \<Longrightarrow> c \<subseteq> d \<or> d \<subseteq> c"
  22.875 -      unfolding subset.chain_def by blast+
  22.876 -
  22.877 -    show "\<exists>U\<in>?C. \<forall>X\<in>C. X \<subseteq> U"
  22.878 -    proof cases
  22.879 -      assume "C = {}" with assms show ?thesis
  22.880 -        by (auto intro!: exI[of _ S])
  22.881 -    next
  22.882 -      assume "C \<noteq> {}"
  22.883 -      with C(2) have "S \<subseteq> \<Union>C"
  22.884 -        by auto
  22.885 -      moreover have "independent (\<Union>C)"
  22.886 -        by (intro independent_Union_directed C)
  22.887 -      moreover have "\<Union>C \<subseteq> V"
  22.888 -        using C by auto
  22.889 -      ultimately show ?thesis
  22.890 -        by auto
  22.891 -    qed
  22.892 -  qed
  22.893 -  then obtain B where B: "independent B" "B \<subseteq> V" "S \<subseteq> B"
  22.894 -    and max: "\<And>S. independent S \<Longrightarrow> S \<subseteq> V \<Longrightarrow> B \<subseteq> S \<Longrightarrow> S = B"
  22.895 -    by auto
  22.896 -  moreover
  22.897 -  { assume "\<not> V \<subseteq> span B"
  22.898 -    then obtain v where "v \<in> V" "v \<notin> span B"
  22.899 -      by auto
  22.900 -    with B have "independent (insert v B)"
  22.901 -      unfolding independent_insert by auto
  22.902 -    from max[OF this] \<open>v \<in> V\<close> \<open>B \<subseteq> V\<close>
  22.903 -    have "v \<in> B"
  22.904 -      by auto
  22.905 -    with \<open>v \<notin> span B\<close> have False
  22.906 -      by (auto intro: span_superset) }
  22.907 -  ultimately show ?thesis
  22.908 -    by (auto intro!: exI[of _ B])
  22.909 -qed
  22.910 -
  22.911 -
  22.912 -lemma maximal_independent_subset:
  22.913 -  "\<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
  22.914 -  by (metis maximal_independent_subset_extend[of "{}"] empty_subsetI independent_empty)
  22.915 -
  22.916 -lemma span_finite:
  22.917 -  assumes fS: "finite S"
  22.918 -  shows "span S = {y. \<exists>u. sum (\<lambda>v. u v *\<^sub>R v) S = y}"
  22.919 -  (is "_ = ?rhs")
  22.920 -proof -
  22.921 -  {
  22.922 -    fix y
  22.923 -    assume y: "y \<in> span S"
  22.924 -    from y obtain S' u where fS': "finite S'"
  22.925 -      and SS': "S' \<subseteq> S"
  22.926 -      and u: "sum (\<lambda>v. u v *\<^sub>R v) S' = y"
  22.927 -      unfolding span_explicit by blast
  22.928 -    let ?u = "\<lambda>x. if x \<in> S' then u x else 0"
  22.929 -    have "sum (\<lambda>v. ?u v *\<^sub>R v) S = sum (\<lambda>v. u v *\<^sub>R v) S'"
  22.930 -      using SS' fS by (auto intro!: sum.mono_neutral_cong_right)
  22.931 -    then have "sum (\<lambda>v. ?u v *\<^sub>R v) S = y" by (metis u)
  22.932 -    then have "y \<in> ?rhs" by auto
  22.933 -  }
  22.934 -  moreover
  22.935 -  {
  22.936 -    fix y u
  22.937 -    assume u: "sum (\<lambda>v. u v *\<^sub>R v) S = y"
  22.938 -    then have "y \<in> span S" using fS unfolding span_explicit by auto
  22.939 -  }
  22.940 -  ultimately show ?thesis by blast
  22.941 -qed
  22.942 -
  22.943 -lemma linear_independent_extend_subspace:
  22.944 -  assumes "independent B"
  22.945 -  shows "\<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x) \<and> range g = span (f`B)"
  22.946 -proof -
  22.947 -  from maximal_independent_subset_extend[OF _ \<open>independent B\<close>, of UNIV]
  22.948 -  obtain B' where "B \<subseteq> B'" "independent B'" "span B' = UNIV"
  22.949 -    by (auto simp: top_unique)
  22.950 -  have "\<forall>y. \<exists>X. {x. X x \<noteq> 0} \<subseteq> B' \<and> finite {x. X x \<noteq> 0} \<and> y = (\<Sum>x|X x \<noteq> 0. X x *\<^sub>R x)"
  22.951 -    using \<open>span B' = UNIV\<close> unfolding span_alt by auto
  22.952 -  then obtain X where X: "\<And>y. {x. X y x \<noteq> 0} \<subseteq> B'" "\<And>y. finite {x. X y x \<noteq> 0}"
  22.953 -    "\<And>y. y = (\<Sum>x|X y x \<noteq> 0. X y x *\<^sub>R x)"
  22.954 -    unfolding choice_iff by auto
  22.955 -
  22.956 -  have X_add: "X (x + y) = (\<lambda>z. X x z + X y z)" for x y
  22.957 -    using \<open>independent B'\<close>
  22.958 -  proof (rule independentD_unique)
  22.959 -    have "(\<Sum>z | X x z + X y z \<noteq> 0. (X x z + X y z) *\<^sub>R z)
  22.960 -      = (\<Sum>z\<in>{z. X x z \<noteq> 0} \<union> {z. X y z \<noteq> 0}. (X x z + X y z) *\<^sub>R z)"
  22.961 -      by (intro sum.mono_neutral_cong_left) (auto intro: X)
  22.962 -    also have "\<dots> = (\<Sum>z\<in>{z. X x z \<noteq> 0}. X x z *\<^sub>R z) + (\<Sum>z\<in>{z. X y z \<noteq> 0}. X y z *\<^sub>R z)"
  22.963 -      by (auto simp add: scaleR_add_left sum.distrib
  22.964 -               intro!: arg_cong2[where f="(+)"]  sum.mono_neutral_cong_right X)
  22.965 -    also have "\<dots> = x + y"
  22.966 -      by (simp add: X(3)[symmetric])
  22.967 -    also have "\<dots> = (\<Sum>z | X (x + y) z \<noteq> 0. X (x + y) z *\<^sub>R z)"
  22.968 -      by (rule X(3))
  22.969 -    finally show "(\<Sum>z | X (x + y) z \<noteq> 0. X (x + y) z *\<^sub>R z) = (\<Sum>z | X x z + X y z \<noteq> 0. (X x z + X y z) *\<^sub>R z)"
  22.970 -      ..
  22.971 -    have "{z. X x z + X y z \<noteq> 0} \<subseteq> {z. X x z \<noteq> 0} \<union> {z. X y z \<noteq> 0}"
  22.972 -      by auto
  22.973 -    then show "finite {z. X x z + X y z \<noteq> 0}" "{xa. X x xa + X y xa \<noteq> 0} \<subseteq> B'"
  22.974 -        "finite {xa. X (x + y) xa \<noteq> 0}" "{xa. X (x + y) xa \<noteq> 0} \<subseteq> B'"
  22.975 -      using X(1) by (auto dest: finite_subset intro: X)
  22.976 -  qed
  22.977 -
  22.978 -  have X_cmult: "X (c *\<^sub>R x) = (\<lambda>z. c * X x z)" for x c
  22.979 -    using \<open>independent B'\<close>
  22.980 -  proof (rule independentD_unique)
  22.981 -    show "finite {z. X (c *\<^sub>R x) z \<noteq> 0}" "{z. X (c *\<^sub>R x) z \<noteq> 0} \<subseteq> B'"
  22.982 -      "finite {z. c * X x z \<noteq> 0}" "{z. c * X x z \<noteq> 0} \<subseteq> B' "
  22.983 -      using X(1,2) by auto
  22.984 -    show "(\<Sum>z | X (c *\<^sub>R x) z \<noteq> 0. X (c *\<^sub>R x) z *\<^sub>R z) = (\<Sum>z | c * X x z \<noteq> 0. (c * X x z) *\<^sub>R z)"
  22.985 -      unfolding scaleR_scaleR[symmetric] scaleR_sum_right[symmetric]
  22.986 -      by (cases "c = 0") (auto simp: X(3)[symmetric])
  22.987 -  qed
  22.988 -
  22.989 -  have X_B': "x \<in> B' \<Longrightarrow> X x = (\<lambda>z. if z = x then 1 else 0)" for x
  22.990 -    using \<open>independent B'\<close>
  22.991 -    by (rule independentD_unique[OF _ X(2) X(1)]) (auto intro: X simp: X(3)[symmetric])
  22.992 -
  22.993 -  define f' where "f' y = (if y \<in> B then f y else 0)" for y
  22.994 -  define g where "g y = (\<Sum>x|X y x \<noteq> 0. X y x *\<^sub>R f' x)" for y
  22.995 -
  22.996 -  have g_f': "x \<in> B' \<Longrightarrow> g x = f' x" for x
  22.997 -    by (auto simp: g_def X_B')
  22.998 -
  22.999 -  have "linear g"
 22.1000 -  proof
 22.1001 -    fix x y
 22.1002 -    have *: "(\<Sum>z | X x z + X y z \<noteq> 0. (X x z + X y z) *\<^sub>R f' z)
 22.1003 -      = (\<Sum>z\<in>{z. X x z \<noteq> 0} \<union> {z. X y z \<noteq> 0}. (X x z + X y z) *\<^sub>R f' z)"
 22.1004 -      by (intro sum.mono_neutral_cong_left) (auto intro: X)
 22.1005 -    show "g (x + y) = g x + g y"
 22.1006 -      unfolding g_def X_add *
 22.1007 -      by (auto simp add: scaleR_add_left sum.distrib
 22.1008 -               intro!: arg_cong2[where f="(+)"]  sum.mono_neutral_cong_right X)
 22.1009 -  next
 22.1010 -    show "g (r *\<^sub>R x) = r *\<^sub>R g x" for r x
 22.1011 -      by (auto simp add: g_def X_cmult scaleR_sum_right intro!: sum.mono_neutral_cong_left X)
 22.1012 -  qed
 22.1013 -  moreover have "\<forall>x\<in>B. g x = f x"
 22.1014 -    using \<open>B \<subseteq> B'\<close> by (auto simp: g_f' f'_def)
 22.1015 -  moreover have "range g = span (f`B)"
 22.1016 -    unfolding \<open>span B' = UNIV\<close>[symmetric] span_linear_image[OF \<open>linear g\<close>, symmetric]
 22.1017 -  proof (rule span_subspace)
 22.1018 -    have "g ` B' \<subseteq> f`B \<union> {0}"
 22.1019 -      by (auto simp: g_f' f'_def)
 22.1020 -    also have "\<dots> \<subseteq> span (f`B)"
 22.1021 -      by (auto intro: span_superset span_0)
 22.1022 -    finally show "g ` B' \<subseteq> span (f`B)"
 22.1023 -      by auto
 22.1024 -    have "x \<in> B \<Longrightarrow> f x = g x" for x
 22.1025 -      using \<open>B \<subseteq> B'\<close> by (auto simp add: g_f' f'_def)
 22.1026 -    then show "span (f ` B) \<subseteq> span (g ` B')"
 22.1027 -      using \<open>B \<subseteq> B'\<close> by (intro span_mono) auto
 22.1028 -  qed (rule subspace_span)
 22.1029 -  ultimately show ?thesis
 22.1030 -    by auto
 22.1031 -qed
 22.1032 -
 22.1033 -lemma linear_independent_extend:
 22.1034 -  "independent B \<Longrightarrow> \<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)"
 22.1035 -  using linear_independent_extend_subspace[of B f] by auto
 22.1036 -
 22.1037 -text \<open>Linear functions are equal on a subspace if they are on a spanning set.\<close>
 22.1038 -
 22.1039 -lemma subspace_kernel:
 22.1040 -  assumes lf: "linear f"
 22.1041 -  shows "subspace {x. f x = 0}"
 22.1042 -  apply (simp add: subspace_def)
 22.1043 -  apply (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf])
 22.1044 -  done
 22.1045 -
 22.1046 -lemma linear_eq_0_span:
 22.1047 -  assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0"
 22.1048 -  shows "\<forall>x \<in> span B. f x = 0"
 22.1049 -  using f0 subspace_kernel[OF lf]
 22.1050 -  by (rule span_induct')
 22.1051 -
 22.1052 -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"
 22.1053 -  using linear_eq_0_span[of f B] by auto
 22.1054 -
 22.1055 -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"
 22.1056 -  using linear_eq_0_span[of "\<lambda>x. f x - g x" B] by (auto simp: linear_compose_sub)
 22.1057 -
 22.1058 -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"
 22.1059 -  using linear_eq_span[of f g B] by auto
 22.1060 -
 22.1061 -text \<open>The degenerate case of the Exchange Lemma.\<close>
 22.1062 -
 22.1063 -lemma spanning_subset_independent:
 22.1064 -  assumes BA: "B \<subseteq> A"
 22.1065 -    and iA: "independent A"
 22.1066 -    and AsB: "A \<subseteq> span B"
 22.1067 -  shows "A = B"
 22.1068 -proof
 22.1069 -  show "B \<subseteq> A" by (rule BA)
 22.1070 -
 22.1071 -  from span_mono[OF BA] span_mono[OF AsB]
 22.1072 -  have sAB: "span A = span B" unfolding span_span by blast
 22.1073 -
 22.1074 -  {
 22.1075 -    fix x
 22.1076 -    assume x: "x \<in> A"
 22.1077 -    from iA have th0: "x \<notin> span (A - {x})"
 22.1078 -      unfolding dependent_def using x by blast
 22.1079 -    from x have xsA: "x \<in> span A"
 22.1080 -      by (blast intro: span_superset)
 22.1081 -    have "A - {x} \<subseteq> A" by blast
 22.1082 -    then have th1: "span (A - {x}) \<subseteq> span A"
 22.1083 -      by (metis span_mono)
 22.1084 -    {
 22.1085 -      assume xB: "x \<notin> B"
 22.1086 -      from xB BA have "B \<subseteq> A - {x}"
 22.1087 -        by blast
 22.1088 -      then have "span B \<subseteq> span (A - {x})"
 22.1089 -        by (metis span_mono)
 22.1090 -      with th1 th0 sAB have "x \<notin> span A"
 22.1091 -        by blast
 22.1092 -      with x have False
 22.1093 -        by (metis span_superset)
 22.1094 -    }
 22.1095 -    then have "x \<in> B" by blast
 22.1096 -  }
 22.1097 -  then show "A \<subseteq> B" by blast
 22.1098 -qed
 22.1099 -
 22.1100 -text \<open>Relation between bases and injectivity/surjectivity of map.\<close>
 22.1101 -
 22.1102 -lemma spanning_surjective_image:
 22.1103 -  assumes us: "UNIV \<subseteq> span S"
 22.1104 -    and lf: "linear f"
 22.1105 -    and sf: "surj f"
 22.1106 -  shows "UNIV \<subseteq> span (f ` S)"
 22.1107 -proof -
 22.1108 -  have "UNIV \<subseteq> f ` UNIV"
 22.1109 -    using sf by (auto simp add: surj_def)
 22.1110 -  also have " \<dots> \<subseteq> span (f ` S)"
 22.1111 -    using spans_image[OF lf us] .
 22.1112 -  finally show ?thesis .
 22.1113 -qed
 22.1114 -
 22.1115 -lemma independent_inj_on_image:
 22.1116 -  assumes iS: "independent S"
 22.1117 -    and lf: "linear f"
 22.1118 -    and fi: "inj_on f (span S)"
 22.1119 -  shows "independent (f ` S)"
 22.1120 -proof -
 22.1121 -  {
 22.1122 -    fix a
 22.1123 -    assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})"
 22.1124 -    have eq: "f ` S - {f a} = f ` (S - {a})"
 22.1125 -      using fi \<open>a\<in>S\<close> by (auto simp add: inj_on_def span_superset)
 22.1126 -    from a have "f a \<in> f ` span (S - {a})"
 22.1127 -      unfolding eq span_linear_image[OF lf, of "S - {a}"] by blast
 22.1128 -    then have "a \<in> span (S - {a})"
 22.1129 -      by (rule inj_on_image_mem_iff_alt[OF fi, rotated])
 22.1130 -         (insert span_mono[of "S - {a}" S], auto intro: span_superset \<open>a\<in>S\<close>)
 22.1131 -    with a(1) iS have False
 22.1132 -      by (simp add: dependent_def)
 22.1133 -  }
 22.1134 -  then show ?thesis
 22.1135 -    unfolding dependent_def by blast
 22.1136 -qed
 22.1137 -
 22.1138 -lemma independent_injective_image:
 22.1139 -  "independent S \<Longrightarrow> linear f \<Longrightarrow> inj f \<Longrightarrow> independent (f ` S)"
 22.1140 -  using independent_inj_on_image[of S f] by (auto simp: subset_inj_on)
 22.1141 -
 22.1142 -text \<open>Detailed theorems about left and right invertibility in general case.\<close>
 22.1143 -
 22.1144 -lemma linear_inj_on_left_inverse:
 22.1145 -  assumes lf: "linear f" and fi: "inj_on f (span S)"
 22.1146 -  shows "\<exists>g. range g \<subseteq> span S \<and> linear g \<and> (\<forall>x\<in>span S. g (f x) = x)"
 22.1147 -proof -
 22.1148 -  obtain B where "independent B" "B \<subseteq> S" "S \<subseteq> span B"
 22.1149 -    using maximal_independent_subset[of S] by auto
 22.1150 -  then have "span S = span B"
 22.1151 -    unfolding span_eq by (auto simp: span_superset)
 22.1152 -  with linear_independent_extend_subspace[OF independent_inj_on_image, OF \<open>independent B\<close> lf] fi
 22.1153 -  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)"
 22.1154 -    by fastforce
 22.1155 -  have fB: "inj_on f B"
 22.1156 -    using fi by (auto simp: \<open>span S = span B\<close> intro: subset_inj_on span_superset)
 22.1157 -
 22.1158 -  have "\<forall>x\<in>span B. g (f x) = x"
 22.1159 -  proof (intro linear_eq_span)
 22.1160 -    show "linear (\<lambda>x. x)" "linear (\<lambda>x. g (f x))"
 22.1161 -      using linear_id linear_compose[OF \<open>linear f\<close> \<open>linear g\<close>] by (auto simp: id_def comp_def)
 22.1162 -    show "\<forall>x \<in> B. g (f x) = x"
 22.1163 -      using g fi \<open>span S = span B\<close> by (auto simp: fB)
 22.1164 -  qed
 22.1165 -  moreover
 22.1166 -  have "inv_into B f ` f ` B \<subseteq> B"
 22.1167 -    by (auto simp: fB)
 22.1168 -  then have "range g \<subseteq> span S"
 22.1169 -    unfolding g \<open>span S = span B\<close> by (intro span_mono)
 22.1170 -  ultimately show ?thesis
 22.1171 -    using \<open>span S = span B\<close> \<open>linear g\<close> by auto
 22.1172 -qed
 22.1173 -
 22.1174 -lemma linear_injective_left_inverse: "linear f \<Longrightarrow> inj f \<Longrightarrow> \<exists>g. linear g \<and> g \<circ> f = id"
 22.1175 -  using linear_inj_on_left_inverse[of f UNIV] by (auto simp: fun_eq_iff span_UNIV)
 22.1176 -
 22.1177 -lemma linear_surj_right_inverse:
 22.1178 -  assumes lf: "linear f" and sf: "span T \<subseteq> f`span S"
 22.1179 -  shows "\<exists>g. range g \<subseteq> span S \<and> linear g \<and> (\<forall>x\<in>span T. f (g x) = x)"
 22.1180 -proof -
 22.1181 -  obtain B where "independent B" "B \<subseteq> T" "T \<subseteq> span B"
 22.1182 -    using maximal_independent_subset[of T] by auto
 22.1183 -  then have "span T = span B"
 22.1184 -    unfolding span_eq by (auto simp: span_superset)
 22.1185 -
 22.1186 -  from linear_independent_extend_subspace[OF \<open>independent B\<close>, of "inv_into (span S) f"]
 22.1187 -  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)"
 22.1188 -    by auto
 22.1189 -  moreover have "x \<in> B \<Longrightarrow> f (inv_into (span S) f x) = x" for x
 22.1190 -    using \<open>B \<subseteq> T\<close> \<open>span T \<subseteq> f`span S\<close> by (intro f_inv_into_f) (auto intro: span_superset)
 22.1191 -  ultimately have "\<forall>x\<in>B. f (g x) = x"
 22.1192 -    by auto
 22.1193 -  then have "\<forall>x\<in>span B. f (g x) = x"
 22.1194 -    using linear_id linear_compose[OF \<open>linear g\<close> \<open>linear f\<close>]
 22.1195 -    by (intro linear_eq_span) (auto simp: id_def comp_def)
 22.1196 -  moreover have "inv_into (span S) f ` B \<subseteq> span S"
 22.1197 -    using \<open>B \<subseteq> T\<close> \<open>span T \<subseteq> f`span S\<close> by (auto intro: inv_into_into span_superset)
 22.1198 -  then have "range g \<subseteq> span S"
 22.1199 -    unfolding g by (intro span_minimal subspace_span) auto
 22.1200 -  ultimately show ?thesis
 22.1201 -    using \<open>linear g\<close> \<open>span T = span B\<close> by auto
 22.1202 -qed
 22.1203 -
 22.1204 -lemma linear_surjective_right_inverse: "linear f \<Longrightarrow> surj f \<Longrightarrow> \<exists>g. linear g \<and> f \<circ> g = id"
 22.1205 -  using linear_surj_right_inverse[of f UNIV UNIV]
 22.1206 -  by (auto simp: span_UNIV fun_eq_iff)
 22.1207 -
 22.1208 -text \<open>The general case of the Exchange Lemma, the key to what follows.\<close>
 22.1209 -
 22.1210 -lemma exchange_lemma:
 22.1211 -  assumes f:"finite t"
 22.1212 -    and i: "independent s"
 22.1213 -    and sp: "s \<subseteq> span t"
 22.1214 -  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'"
 22.1215 -  using f i sp
 22.1216 -proof (induct "card (t - s)" arbitrary: s t rule: less_induct)
 22.1217 -  case less
 22.1218 -  note ft = \<open>finite t\<close> and s = \<open>independent s\<close> and sp = \<open>s \<subseteq> span t\<close>
 22.1219 -  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'"
 22.1220 -  let ?ths = "\<exists>t'. ?P t'"
 22.1221 -  {
 22.1222 -    assume "s \<subseteq> t"
 22.1223 -    then have ?ths
 22.1224 -      by (metis ft Un_commute sp sup_ge1)
 22.1225 -  }
 22.1226 -  moreover
 22.1227 -  {
 22.1228 -    assume st: "t \<subseteq> s"
 22.1229 -    from spanning_subset_independent[OF st s sp] st ft span_mono[OF st]
 22.1230 -    have ?ths
 22.1231 -      by (metis Un_absorb sp)
 22.1232 -  }
 22.1233 -  moreover
 22.1234 -  {
 22.1235 -    assume st: "\<not> s \<subseteq> t" "\<not> t \<subseteq> s"
 22.1236 -    from st(2) obtain b where b: "b \<in> t" "b \<notin> s"
 22.1237 -      by blast
 22.1238 -    from b have "t - {b} - s \<subset> t - s"
 22.1239 -      by blast
 22.1240 -    then have cardlt: "card (t - {b} - s) < card (t - s)"
 22.1241 -      using ft by (auto intro: psubset_card_mono)
 22.1242 -    from b ft have ct0: "card t \<noteq> 0"
 22.1243 -      by auto
 22.1244 -    have ?ths
 22.1245 -    proof cases
 22.1246 -      assume stb: "s \<subseteq> span (t - {b})"
 22.1247 -      from ft have ftb: "finite (t - {b})"
 22.1248 -        by auto
 22.1249 -      from less(1)[OF cardlt ftb s stb]
 22.1250 -      obtain u where u: "card u = card (t - {b})" "s \<subseteq> u" "u \<subseteq> s \<union> (t - {b})" "s \<subseteq> span u"
 22.1251 -        and fu: "finite u" by blast
 22.1252 -      let ?w = "insert b u"
 22.1253 -      have th0: "s \<subseteq> insert b u"
 22.1254 -        using u by blast
 22.1255 -      from u(3) b have "u \<subseteq> s \<union> t"
 22.1256 -        by blast
 22.1257 -      then have th1: "insert b u \<subseteq> s \<union> t"
 22.1258 -        using u b by blast
 22.1259 -      have bu: "b \<notin> u"
 22.1260 -        using b u by blast
 22.1261 -      from u(1) ft b have "card u = (card t - 1)"
 22.1262 -        by auto
 22.1263 -      then have th2: "card (insert b u) = card t"
 22.1264 -        using card_insert_disjoint[OF fu bu] ct0 by auto
 22.1265 -      from u(4) have "s \<subseteq> span u" .
 22.1266 -      also have "\<dots> \<subseteq> span (insert b u)"
 22.1267 -        by (rule span_mono) blast
 22.1268 -      finally have th3: "s \<subseteq> span (insert b u)" .
 22.1269 -      from th0 th1 th2 th3 fu have th: "?P ?w"
 22.1270 -        by blast
 22.1271 -      from th show ?thesis by blast
 22.1272 -    next
 22.1273 -      assume stb: "\<not> s \<subseteq> span (t - {b})"
 22.1274 -      from stb obtain a where a: "a \<in> s" "a \<notin> span (t - {b})"
 22.1275 -        by blast
 22.1276 -      have ab: "a \<noteq> b"
 22.1277 -        using a b by blast
 22.1278 -      have at: "a \<notin> t"
 22.1279 -        using a ab span_superset[of a "t- {b}"] by auto
 22.1280 -      have mlt: "card ((insert a (t - {b})) - s) < card (t - s)"
 22.1281 -        using cardlt ft a b by auto
 22.1282 -      have ft': "finite (insert a (t - {b}))"
 22.1283 -        using ft by auto
 22.1284 -      {
 22.1285 -        fix x
 22.1286 -        assume xs: "x \<in> s"
 22.1287 -        have t: "t \<subseteq> insert b (insert a (t - {b}))"
 22.1288 -          using b by auto
 22.1289 -        from b(1) have "b \<in> span t"
 22.1290 -          by (simp add: span_superset)
 22.1291 -        have bs: "b \<in> span (insert a (t - {b}))"
 22.1292 -          apply (rule in_span_delete)
 22.1293 -          using a sp unfolding subset_eq
 22.1294 -          apply auto
 22.1295 -          done
 22.1296 -        from xs sp have "x \<in> span t"
 22.1297 -          by blast
 22.1298 -        with span_mono[OF t] have x: "x \<in> span (insert b (insert a (t - {b})))" ..
 22.1299 -        from span_trans[OF bs x] have "x \<in> span (insert a (t - {b}))" .
 22.1300 -      }
 22.1301 -      then have sp': "s \<subseteq> span (insert a (t - {b}))"
 22.1302 -        by blast
 22.1303 -      from less(1)[OF mlt ft' s sp'] obtain u where u:
 22.1304 -        "card u = card (insert a (t - {b}))"
 22.1305 -        "finite u" "s \<subseteq> u" "u \<subseteq> s \<union> insert a (t - {b})"
 22.1306 -        "s \<subseteq> span u" by blast
 22.1307 -      from u a b ft at ct0 have "?P u"
 22.1308 -        by auto
 22.1309 -      then show ?thesis by blast
 22.1310 -    qed
 22.1311 -  }
 22.1312 -  ultimately show ?ths by blast
 22.1313 -qed
 22.1314 -
 22.1315 -text \<open>This implies corresponding size bounds.\<close>
 22.1316 -
 22.1317 -lemma independent_span_bound:
 22.1318 -  assumes f: "finite t"
 22.1319 -    and i: "independent s"
 22.1320 -    and sp: "s \<subseteq> span t"
 22.1321 -  shows "finite s \<and> card s \<le> card t"
 22.1322 -  by (metis exchange_lemma[OF f i sp] finite_subset card_mono)
 22.1323 -
 22.1324  lemma finite_Atleast_Atmost_nat[simp]: "finite {f x |x. x\<in> (UNIV::'a::finite set)}"
 22.1325  proof -
 22.1326    have eq: "{f x |x. x\<in> UNIV} = f ` UNIV"
 22.1327 @@ -1353,51 +47,8 @@
 22.1328  
 22.1329  subsection%unimportant \<open>More interesting properties of the norm.\<close>
 22.1330  
 22.1331 -lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)"
 22.1332 -  by auto
 22.1333 -
 22.1334  notation inner (infix "\<bullet>" 70)
 22.1335  
 22.1336 -lemma square_bound_lemma:
 22.1337 -  fixes x :: real
 22.1338 -  shows "x < (1 + x) * (1 + x)"
 22.1339 -proof -
 22.1340 -  have "(x + 1/2)\<^sup>2 + 3/4 > 0"
 22.1341 -    using zero_le_power2[of "x+1/2"] by arith
 22.1342 -  then show ?thesis
 22.1343 -    by (simp add: field_simps power2_eq_square)
 22.1344 -qed
 22.1345 -
 22.1346 -lemma square_continuous:
 22.1347 -  fixes e :: real
 22.1348 -  shows "e > 0 \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. \<bar>y - x\<bar> < d \<longrightarrow> \<bar>y * y - x * x\<bar> < e)"
 22.1349 -  using isCont_power[OF continuous_ident, of x, unfolded isCont_def LIM_eq, rule_format, of e 2]
 22.1350 -  by (force simp add: power2_eq_square)
 22.1351 -
 22.1352 -
 22.1353 -lemma norm_eq_0_dot: "norm x = 0 \<longleftrightarrow> x \<bullet> x = (0::real)"
 22.1354 -  by simp (* TODO: delete *)
 22.1355 -
 22.1356 -lemma norm_triangle_sub:
 22.1357 -  fixes x y :: "'a::real_normed_vector"
 22.1358 -  shows "norm x \<le> norm y + norm (x - y)"
 22.1359 -  using norm_triangle_ineq[of "y" "x - y"] by (simp add: field_simps)
 22.1360 -
 22.1361 -lemma norm_le: "norm x \<le> norm y \<longleftrightarrow> x \<bullet> x \<le> y \<bullet> y"
 22.1362 -  by (simp add: norm_eq_sqrt_inner)
 22.1363 -
 22.1364 -lemma norm_lt: "norm x < norm y \<longleftrightarrow> x \<bullet> x < y \<bullet> y"
 22.1365 -  by (simp add: norm_eq_sqrt_inner)
 22.1366 -
 22.1367 -lemma norm_eq: "norm x = norm y \<longleftrightarrow> x \<bullet> x = y \<bullet> y"
 22.1368 -  apply (subst order_eq_iff)
 22.1369 -  apply (auto simp: norm_le)
 22.1370 -  done
 22.1371 -
 22.1372 -lemma norm_eq_1: "norm x = 1 \<longleftrightarrow> x \<bullet> x = 1"
 22.1373 -  by (simp add: norm_eq_sqrt_inner)
 22.1374 -
 22.1375 -
 22.1376  text\<open>Equality of vectors in terms of @{term "(\<bullet>)"} products.\<close>
 22.1377  
 22.1378  lemma linear_componentwise:
 22.1379 @@ -1405,11 +56,11 @@
 22.1380    assumes lf: "linear f"
 22.1381    shows "(f x) \<bullet> j = (\<Sum>i\<in>Basis. (x\<bullet>i) * (f i\<bullet>j))" (is "?lhs = ?rhs")
 22.1382  proof -
 22.1383 +  interpret linear f by fact
 22.1384    have "?rhs = (\<Sum>i\<in>Basis. (x\<bullet>i) *\<^sub>R (f i))\<bullet>j"
 22.1385      by (simp add: inner_sum_left)
 22.1386    then show ?thesis
 22.1387 -    unfolding linear_sum_mul[OF lf, symmetric]
 22.1388 -    unfolding euclidean_representation ..
 22.1389 +    by (simp add: euclidean_representation sum[symmetric] scale[symmetric])
 22.1390  qed
 22.1391  
 22.1392  lemma vector_eq: "x = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y \<and> y \<bullet> y = x \<bullet> x"
 22.1393 @@ -1607,22 +258,15 @@
 22.1394    using bilinear_radd [of h _ x "- y"] by (simp add: bilinear_rneg)
 22.1395  
 22.1396  lemma bilinear_sum:
 22.1397 -  assumes bh: "bilinear h"
 22.1398 -    and fS: "finite S"
 22.1399 -    and fT: "finite T"
 22.1400 +  assumes "bilinear h"
 22.1401    shows "h (sum f S) (sum g T) = sum (\<lambda>(i,j). h (f i) (g j)) (S \<times> T) "
 22.1402  proof -
 22.1403 +  interpret l: linear "\<lambda>x. h x y" for y using assms by (simp add: bilinear_def)
 22.1404 +  interpret r: linear "\<lambda>y. h x y" for x using assms by (simp add: bilinear_def)
 22.1405    have "h (sum f S) (sum g T) = sum (\<lambda>x. h (f x) (sum g T)) S"
 22.1406 -    apply (rule linear_sum[unfolded o_def])
 22.1407 -    using bh fS
 22.1408 -    apply (auto simp add: bilinear_def)
 22.1409 -    done
 22.1410 +    by (simp add: l.sum)
 22.1411    also have "\<dots> = sum (\<lambda>x. sum (\<lambda>y. h (f x) (g y)) T) S"
 22.1412 -    apply (rule sum.cong, simp)
 22.1413 -    apply (rule linear_sum[unfolded o_def])
 22.1414 -    using bh fT
 22.1415 -    apply (auto simp add: bilinear_def)
 22.1416 -    done
 22.1417 +    by (rule sum.cong) (simp_all add: r.sum)
 22.1418    finally show ?thesis
 22.1419      unfolding sum.cartesian_product .
 22.1420  qed
 22.1421 @@ -1663,6 +307,7 @@
 22.1422    assumes lf: "linear f"
 22.1423    shows "x \<bullet> adjoint f y = f x \<bullet> y"
 22.1424  proof -
 22.1425 +  interpret linear f by fact
 22.1426    have "\<forall>y. \<exists>w. \<forall>x. f x \<bullet> y = x \<bullet> w"
 22.1427    proof (intro allI exI)
 22.1428      fix y :: "'m" and x
 22.1429 @@ -1670,8 +315,7 @@
 22.1430      have "f x \<bullet> y = f (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R i) \<bullet> y"
 22.1431        by (simp add: euclidean_representation)
 22.1432      also have "\<dots> = (\<Sum>i\<in>Basis. (x \<bullet> i) *\<^sub>R f i) \<bullet> y"
 22.1433 -      unfolding linear_sum[OF lf]
 22.1434 -      by (simp add: linear_cmul[OF lf])
 22.1435 +      by (simp add: sum scale)
 22.1436      finally show "f x \<bullet> y = x \<bullet> ?w"
 22.1437        by (simp add: inner_sum_left inner_sum_right mult.commute)
 22.1438    qed
 22.1439 @@ -1847,63 +491,14 @@
 22.1440  subsection%unimportant \<open>Euclidean Spaces as Typeclass\<close>
 22.1441  
 22.1442  lemma independent_Basis: "independent Basis"
 22.1443 -  unfolding dependent_def
 22.1444 -  apply (subst span_finite)
 22.1445 -  apply simp
 22.1446 -  apply clarify
 22.1447 -  apply (drule_tac f="inner a" in arg_cong)
 22.1448 -  apply (simp add: inner_Basis inner_sum_right eq_commute)
 22.1449 -  done
 22.1450 +  by (rule independent_Basis)
 22.1451  
 22.1452  lemma span_Basis [simp]: "span Basis = UNIV"
 22.1453 -  unfolding span_finite [OF finite_Basis]
 22.1454 -  by (fast intro: euclidean_representation)
 22.1455 +  by (rule span_Basis)
 22.1456  
 22.1457  lemma in_span_Basis: "x \<in> span Basis"
 22.1458    unfolding span_Basis ..
 22.1459  
 22.1460 -lemma Basis_le_norm: "b \<in> Basis \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> norm x"
 22.1461 -  by (rule order_trans [OF Cauchy_Schwarz_ineq2]) simp
 22.1462 -
 22.1463 -lemma norm_bound_Basis_le: "b \<in> Basis \<Longrightarrow> norm x \<le> e \<Longrightarrow> \<bar>x \<bullet> b\<bar> \<le> e"
 22.1464 -  by (metis Basis_le_norm order_trans)
 22.1465 -
 22.1466 -lemma norm_bound_Basis_lt: "b \<in> Basis \<Longrightarrow> norm x < e \<Longrightarrow> \<bar>x \<bullet> b\<bar> < e"
 22.1467 -  by (metis Basis_le_norm le_less_trans)
 22.1468 -
 22.1469 -lemma norm_le_l1: "norm x \<le> (\<Sum>b\<in>Basis. \<bar>x \<bullet> b\<bar>)"
 22.1470 -  apply (subst euclidean_representation[of x, symmetric])
 22.1471 -  apply (rule order_trans[OF norm_sum])
 22.1472 -  apply (auto intro!: sum_mono)
 22.1473 -  done
 22.1474 -
 22.1475 -lemma sum_norm_allsubsets_bound:
 22.1476 -  fixes f :: "'a \<Rightarrow> 'n::euclidean_space"
 22.1477 -  assumes fP: "finite P"
 22.1478 -    and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (sum f Q) \<le> e"
 22.1479 -  shows "(\<Sum>x\<in>P. norm (f x)) \<le> 2 * real DIM('n) * e"
 22.1480 -proof -
 22.1481 -  have "(\<Sum>x\<in>P. norm (f x)) \<le> (\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>)"
 22.1482 -    by (rule sum_mono) (rule norm_le_l1)
 22.1483 -  also have "(\<Sum>x\<in>P. \<Sum>b\<in>Basis. \<bar>f x \<bullet> b\<bar>) = (\<Sum>b\<in>Basis. \<Sum>x\<in>P. \<bar>f x \<bullet> b\<bar>)"
 22.1484 -    by (rule sum.swap)
 22.1485 -  also have "\<dots> \<le> of_nat (card (Basis :: 'n set)) * (2 * e)"
 22.1486 -  proof (rule sum_bounded_above)
 22.1487 -    fix i :: 'n
 22.1488 -    assume i: "i \<in> Basis"
 22.1489 -    have "norm (\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le>
 22.1490 -      norm ((\<Sum>x\<in>P \<inter> - {x. f x \<bullet> i < 0}. f x) \<bullet> i) + norm ((\<Sum>x\<in>P \<inter> {x. f x \<bullet> i < 0}. f x) \<bullet> i)"
 22.1491 -      by (simp add: abs_real_def sum.If_cases[OF fP] sum_negf norm_triangle_ineq4 inner_sum_left
 22.1492 -        del: real_norm_def)
 22.1493 -    also have "\<dots> \<le> e + e"
 22.1494 -      unfolding real_norm_def
 22.1495 -      by (intro add_mono norm_bound_Basis_le i fPs) auto
 22.1496 -    finally show "(\<Sum>x\<in>P. \<bar>f x \<bullet> i\<bar>) \<le> 2*e" by simp
 22.1497 -  qed
 22.1498 -  also have "\<dots> = 2 * real DIM('n) * e" by simp
 22.1499 -  finally show ?thesis .
 22.1500 -qed
 22.1501 -
 22.1502  
 22.1503  subsection%unimportant \<open>Linearity and Bilinearity continued\<close>
 22.1504  
 22.1505 @@ -1912,6 +507,7 @@
 22.1506    assumes lf: "linear f"
 22.1507    shows "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x"
 22.1508  proof
 22.1509 +  interpret linear f by fact
 22.1510    let ?B = "\<Sum>b\<in>Basis. norm (f b)"
 22.1511    show "\<forall>x. norm (f x) \<le> ?B * norm x"
 22.1512    proof
 22.1513 @@ -1920,7 +516,7 @@
 22.1514      have "norm (f x) = norm (f (\<Sum>b\<in>Basis. (x \<bullet> b) *\<^sub>R b))"
 22.1515        unfolding euclidean_representation ..
 22.1516      also have "\<dots> = norm (sum ?g Basis)"
 22.1517 -      by (simp add: linear_sum [OF lf] linear_cmul [OF lf])
 22.1518 +      by (simp add: sum scale)
 22.1519      finally have th0: "norm (f x) = norm (sum ?g Basis)" .
 22.1520      have th: "norm (?g i) \<le> norm (f i) * norm x" if "i \<in> Basis" for i
 22.1521      proof -
 22.1522 @@ -1997,15 +593,15 @@
 22.1523    fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::euclidean_space"
 22.1524    assumes "linear f" "inj f"
 22.1525    obtains B where "B > 0" "\<And>x. B * norm x \<le> norm(f x)"
 22.1526 -  using linear_injective_left_inverse [OF assms] linear_invertible_bounded_below_pos assms by blast
 22.1527 +  using linear_injective_left_inverse [OF assms]
 22.1528 +    linear_invertible_bounded_below_pos assms by blast
 22.1529  
 22.1530  lemma bounded_linearI':
 22.1531    fixes f ::"'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
 22.1532    assumes "\<And>x y. f (x + y) = f x + f y"
 22.1533      and "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x"
 22.1534    shows "bounded_linear f"
 22.1535 -  unfolding linear_conv_bounded_linear[symmetric]
 22.1536 -  by (rule linearI[OF assms])
 22.1537 +  using assms linearI linear_conv_bounded_linear by blast
 22.1538  
 22.1539  lemma bilinear_bounded:
 22.1540    fixes h :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space \<Rightarrow> 'k::real_normed_vector"
 22.1541 @@ -2020,7 +616,7 @@
 22.1542      apply rule
 22.1543      done
 22.1544    also have "\<dots> = norm (sum (\<lambda> (i,j). h ((x \<bullet> i) *\<^sub>R i) ((y \<bullet> j) *\<^sub>R j)) (Basis \<times> Basis))"
 22.1545 -    unfolding bilinear_sum[OF bh finite_Basis finite_Basis] ..
 22.1546 +    unfolding bilinear_sum[OF bh] ..
 22.1547    finally have th: "norm (h x y) = \<dots>" .
 22.1548    show "norm (h x y) \<le> (\<Sum>i\<in>Basis. \<Sum>j\<in>Basis. norm (h i j)) * norm x * norm y"
 22.1549      apply (auto simp add: sum_distrib_right th sum.cartesian_product)
 22.1550 @@ -2084,14 +680,14 @@
 22.1551      by (simp only: ac_simps)
 22.1552  qed
 22.1553  
 22.1554 -lemma bounded_linear_imp_has_derivative:
 22.1555 -     "bounded_linear f \<Longrightarrow> (f has_derivative f) net"
 22.1556 -  by (simp add: has_derivative_def bounded_linear.linear linear_diff)
 22.1557 +lemma bounded_linear_imp_has_derivative: "bounded_linear f \<Longrightarrow> (f has_derivative f) net"
 22.1558 +  by (auto simp add: has_derivative_def linear_diff linear_linear linear_def
 22.1559 +      dest: bounded_linear.linear)
 22.1560  
 22.1561  lemma linear_imp_has_derivative:
 22.1562    fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
 22.1563    shows "linear f \<Longrightarrow> (f has_derivative f) net"
 22.1564 -by (simp add: has_derivative_def linear_conv_bounded_linear linear_diff)
 22.1565 +  by (simp add: bounded_linear_imp_has_derivative linear_conv_bounded_linear)
 22.1566  
 22.1567  lemma bounded_linear_imp_differentiable: "bounded_linear f \<Longrightarrow> f differentiable net"
 22.1568    using bounded_linear_imp_has_derivative differentiable_def by blast
 22.1569 @@ -2099,7 +695,7 @@
 22.1570  lemma linear_imp_differentiable:
 22.1571    fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
 22.1572    shows "linear f \<Longrightarrow> f differentiable net"
 22.1573 -by (metis linear_imp_has_derivative differentiable_def)
 22.1574 +  by (metis linear_imp_has_derivative differentiable_def)
 22.1575  
 22.1576  
 22.1577  subsection%unimportant \<open>We continue.\<close>
 22.1578 @@ -2107,221 +703,21 @@
 22.1579  lemma independent_bound:
 22.1580    fixes S :: "'a::euclidean_space set"
 22.1581    shows "independent S \<Longrightarrow> finite S \<and> card S \<le> DIM('a)"
 22.1582 -  using independent_span_bound[OF finite_Basis, of S] by auto
 22.1583 +  by (metis dim_subset_UNIV finiteI_independent dim_span_eq_card_independent)
 22.1584 +
 22.1585 +lemmas independent_imp_finite = finiteI_independent
 22.1586  
 22.1587  corollary
 22.1588    fixes S :: "'a::euclidean_space set"
 22.1589    assumes "independent S"
 22.1590 -  shows independent_imp_finite: "finite S" and independent_card_le:"card S \<le> DIM('a)"
 22.1591 -using assms independent_bound by auto
 22.1592 -
 22.1593 -lemma independent_explicit:
 22.1594 -  fixes B :: "'a::euclidean_space set"
 22.1595 -  shows "independent B \<longleftrightarrow>
 22.1596 -         finite B \<and> (\<forall>c. (\<Sum>v\<in>B. c v *\<^sub>R v) = 0 \<longrightarrow> (\<forall>v \<in> B. c v = 0))"
 22.1597 -apply (cases "finite B")
 22.1598 - apply (force simp: dependent_finite)
 22.1599 -using independent_bound
 22.1600 -apply auto
 22.1601 -done
 22.1602 +  shows independent_card_le:"card S \<le> DIM('a)"
 22.1603 +  using assms independent_bound by auto
 22.1604  
 22.1605  lemma dependent_biggerset:
 22.1606    fixes S :: "'a::euclidean_space set"
 22.1607    shows "(finite S \<Longrightarrow> card S > DIM('a)) \<Longrightarrow> dependent S"
 22.1608    by (metis independent_bound not_less)
 22.1609  
 22.1610 -text \<open>Notion of dimension.\<close>
 22.1611 -
 22.1612 -definition "dim V = (SOME n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> card B = n)"
 22.1613 -
 22.1614 -lemma basis_exists:
 22.1615 -  "\<exists>B. (B :: ('a::euclidean_space) set) \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = dim V)"
 22.1616 -  unfolding dim_def some_eq_ex[of "\<lambda>n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (card B = n)"]
 22.1617 -  using maximal_independent_subset[of V] independent_bound
 22.1618 -  by auto
 22.1619 -
 22.1620 -corollary dim_le_card:
 22.1621 -  fixes s :: "'a::euclidean_space set"
 22.1622 -  shows "finite s \<Longrightarrow> dim s \<le> card s"
 22.1623 -by (metis basis_exists card_mono)
 22.1624 -
 22.1625 -text \<open>Consequences of independence or spanning for cardinality.\<close>
 22.1626 -
 22.1627 -lemma independent_card_le_dim:
 22.1628 -  fixes B :: "'a::euclidean_space set"
 22.1629 -  assumes "B \<subseteq> V"
 22.1630 -    and "independent B"
 22.1631 -  shows "card B \<le> dim V"
 22.1632 -proof -
 22.1633 -  from basis_exists[of V] \<open>B \<subseteq> V\<close>
 22.1634 -  obtain B' where "independent B'"
 22.1635 -    and "B \<subseteq> span B'"
 22.1636 -    and "card B' = dim V"
 22.1637 -    by blast
 22.1638 -  with independent_span_bound[OF _ \<open>independent B\<close> \<open>B \<subseteq> span B'\<close>] independent_bound[of B']
 22.1639 -  show ?thesis by auto
 22.1640 -qed
 22.1641 -
 22.1642 -lemma span_card_ge_dim:
 22.1643 -  fixes B :: "'a::euclidean_space set"
 22.1644 -  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> finite B \<Longrightarrow> dim V \<le> card B"
 22.1645 -  by (metis basis_exists[of V] independent_span_bound subset_trans)
 22.1646 -
 22.1647 -lemma basis_card_eq_dim:
 22.1648 -  fixes V :: "'a::euclidean_space set"
 22.1649 -  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B = dim V"
 22.1650 -  by (metis order_eq_iff independent_card_le_dim span_card_ge_dim independent_bound)
 22.1651 -
 22.1652 -lemma dim_unique:
 22.1653 -  fixes B :: "'a::euclidean_space set"
 22.1654 -  shows "B \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> card B = n \<Longrightarrow> dim V = n"
 22.1655 -  by (metis basis_card_eq_dim)
 22.1656 -
 22.1657 -text \<open>More lemmas about dimension.\<close>
 22.1658 -
 22.1659 -lemma dim_UNIV [simp]: "dim (UNIV :: 'a::euclidean_space set) = DIM('a)"
 22.1660 -  using independent_Basis
 22.1661 -  by (intro dim_unique[of Basis]) auto
 22.1662 -
 22.1663 -lemma dim_subset:
 22.1664 -  fixes S :: "'a::euclidean_space set"
 22.1665 -  shows "S \<subseteq> T \<Longrightarrow> dim S \<le> dim T"
 22.1666 -  using basis_exists[of T] basis_exists[of S]
 22.1667 -  by (metis independent_card_le_dim subset_trans)
 22.1668 -
 22.1669 -lemma dim_subset_UNIV:
 22.1670 -  fixes S :: "'a::euclidean_space set"
 22.1671 -  shows "dim S \<le> DIM('a)"
 22.1672 -  by (metis dim_subset subset_UNIV dim_UNIV)
 22.1673 -
 22.1674 -text \<open>Converses to those.\<close>
 22.1675 -
 22.1676 -lemma card_ge_dim_independent:
 22.1677 -  fixes B :: "'a::euclidean_space set"
 22.1678 -  assumes BV: "B \<subseteq> V"
 22.1679 -    and iB: "independent B"
 22.1680 -    and dVB: "dim V \<le> card B"
 22.1681 -  shows "V \<subseteq> span B"
 22.1682 -proof
 22.1683 -  fix a
 22.1684 -  assume aV: "a \<in> V"
 22.1685 -  {
 22.1686 -    assume aB: "a \<notin> span B"
 22.1687 -    then have iaB: "independent (insert a B)"
 22.1688 -      using iB aV BV by (simp add: independent_insert)
 22.1689 -    from aV BV have th0: "insert a B \<subseteq> V"
 22.1690 -      by blast
 22.1691 -    from aB have "a \<notin>B"
 22.1692 -      by (auto simp add: span_superset)
 22.1693 -    with independent_card_le_dim[OF th0 iaB] dVB independent_bound[OF iB]
 22.1694 -    have False by auto
 22.1695 -  }
 22.1696 -  then show "a \<in> span B" by blast
 22.1697 -qed
 22.1698 -
 22.1699 -lemma card_le_dim_spanning:
 22.1700 -  assumes BV: "(B:: ('a::euclidean_space) set) \<subseteq> V"
 22.1701 -    and VB: "V \<subseteq> span B"
 22.1702 -    and fB: "finite B"
 22.1703 -    and dVB: "dim V \<ge> card B"
 22.1704 -  shows "independent B"
 22.1705 -proof -
 22.1706 -  {
 22.1707 -    fix a
 22.1708 -    assume a: "a \<in> B" "a \<in> span (B - {a})"
 22.1709 -    from a fB have c0: "card B \<noteq> 0"
 22.1710 -      by auto
 22.1711 -    from a fB have cb: "card (B - {a}) = card B - 1"
 22.1712 -      by auto
 22.1713 -    from BV a have th0: "B - {a} \<subseteq> V"
 22.1714 -      by blast
 22.1715 -    {
 22.1716 -      fix x
 22.1717 -      assume x: "x \<in> V"
 22.1718 -      from a have eq: "insert a (B - {a}) = B"
 22.1719 -        by blast
 22.1720 -      from x VB have x': "x \<in> span B"
 22.1721 -        by blast
 22.1722 -      from span_trans[OF a(2), unfolded eq, OF x']
 22.1723 -      have "x \<in> span (B - {a})" .
 22.1724 -    }
 22.1725 -    then have th1: "V \<subseteq> span (B - {a})"
 22.1726 -      by blast
 22.1727 -    have th2: "finite (B - {a})"
 22.1728 -      using fB by auto
 22.1729 -    from span_card_ge_dim[OF th0 th1 th2]
 22.1730 -    have c: "dim V \<le> card (B - {a})" .
 22.1731 -    from c c0 dVB cb have False by simp
 22.1732 -  }
 22.1733 -  then show ?thesis
 22.1734 -    unfolding dependent_def by blast
 22.1735 -qed
 22.1736 -
 22.1737 -lemma card_eq_dim:
 22.1738 -  fixes B :: "'a::euclidean_space set"
 22.1739 -  shows "B \<subseteq> V \<Longrightarrow> card B = dim V \<Longrightarrow> finite B \<Longrightarrow> independent B \<longleftrightarrow> V \<subseteq> span B"
 22.1740 -  by (metis order_eq_iff card_le_dim_spanning card_ge_dim_independent)
 22.1741 -
 22.1742 -text \<open>More general size bound lemmas.\<close>
 22.1743 -
 22.1744 -lemma independent_bound_general:
 22.1745 -  fixes S :: "'a::euclidean_space set"
 22.1746 -  shows "independent S \<Longrightarrow> finite S \<and> card S \<le> dim S"
 22.1747 -  by (metis independent_card_le_dim independent_bound subset_refl)
 22.1748 -
 22.1749 -lemma dependent_biggerset_general:
 22.1750 -  fixes S :: "'a::euclidean_space set"
 22.1751 -  shows "(finite S \<Longrightarrow> card S > dim S) \<Longrightarrow> dependent S"
 22.1752 -  using independent_bound_general[of S] by (metis linorder_not_le)
 22.1753 -
 22.1754 -lemma dim_span [simp]:
 22.1755 -  fixes S :: "'a::euclidean_space set"
 22.1756 -  shows "dim (span S) = dim S"
 22.1757 -proof -
 22.1758 -  have th0: "dim S \<le> dim (span S)"
 22.1759 -    by (auto simp add: subset_eq intro: dim_subset span_superset)
 22.1760 -  from basis_exists[of S]
 22.1761 -  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S"
 22.1762 -    by blast
 22.1763 -  from B have fB: "finite B" "card B = dim S"
 22.1764 -    using independent_bound by blast+
 22.1765 -  have bSS: "B \<subseteq> span S"
 22.1766 -    using B(1) by (metis subset_eq span_inc)
 22.1767 -  have sssB: "span S \<subseteq> span B"
 22.1768 -    using span_mono[OF B(3)] by (simp add: span_span)
 22.1769 -  from span_card_ge_dim[OF bSS sssB fB(1)] th0 show ?thesis
 22.1770 -    using fB(2) by arith
 22.1771 -qed
 22.1772 -
 22.1773 -lemma subset_le_dim:
 22.1774 -  fixes S :: "'a::euclidean_space set"
 22.1775 -  shows "S \<subseteq> span T \<Longrightarrow> dim S \<le> dim T"
 22.1776 -  by (metis dim_span dim_subset)
 22.1777 -
 22.1778 -lemma span_eq_dim:
 22.1779 -  fixes S :: "'a::euclidean_space set"
 22.1780 -  shows "span S = span T \<Longrightarrow> dim S = dim T"
 22.1781 -  by (metis dim_span)
 22.1782 -
 22.1783 -lemma dim_image_le:
 22.1784 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
 22.1785 -  assumes lf: "linear f"
 22.1786 -  shows "dim (f ` S) \<le> dim (S)"
 22.1787 -proof -
 22.1788 -  from basis_exists[of S] obtain B where
 22.1789 -    B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" by blast
 22.1790 -  from B have fB: "finite B" "card B = dim S"
 22.1791 -    using independent_bound by blast+
 22.1792 -  have "dim (f ` S) \<le> card (f ` B)"
 22.1793 -    apply (rule span_card_ge_dim)
 22.1794 -    using lf B fB
 22.1795 -    apply (auto simp add: span_linear_image spans_image subset_image_iff)
 22.1796 -    done
 22.1797 -  also have "\<dots> \<le> dim S"
 22.1798 -    using card_image_le[OF fB(1)] fB by simp
 22.1799 -  finally show ?thesis .
 22.1800 -qed
 22.1801 -
 22.1802  text \<open>Picking an orthogonal replacement for a spanning set.\<close>
 22.1803  
 22.1804  lemma vector_sub_project_orthogonal:
 22.1805 @@ -2367,10 +763,10 @@
 22.1806      have "x - k *\<^sub>R (a - (\<Sum>x\<in>C. (x \<bullet> a / (x \<bullet> x)) *\<^sub>R x)) \<in> span C \<longleftrightarrow> x - k *\<^sub>R a \<in> span C"
 22.1807        apply (simp only: scaleR_right_diff_distrib th0)
 22.1808        apply (rule span_add_eq)
 22.1809 -      apply (rule span_mul)
 22.1810 +      apply (rule span_scale)
 22.1811        apply (rule span_sum)
 22.1812 -      apply (rule span_mul)
 22.1813 -      apply (rule span_superset)
 22.1814 +      apply (rule span_scale)
 22.1815 +      apply (rule span_base)
 22.1816        apply assumption
 22.1817        done
 22.1818    }
 22.1819 @@ -2402,7 +798,8 @@
 22.1820  
 22.1821  lemma orthogonal_basis_exists:
 22.1822    fixes V :: "('a::euclidean_space) set"
 22.1823 -  shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and> (card B = dim V) \<and> pairwise orthogonal B"
 22.1824 +  shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and>
 22.1825 +  (card B = dim V) \<and> pairwise orthogonal B"
 22.1826  proof -
 22.1827    from basis_exists[of V] obtain B where
 22.1828      B: "B \<subseteq> V" "independent B" "V \<subseteq> span B" "card B = dim V"
 22.1829 @@ -2413,7 +810,7 @@
 22.1830      C: "finite C" "card C \<le> card B" "span C = span B" "pairwise orthogonal C"
 22.1831      by blast
 22.1832    from C B have CSV: "C \<subseteq> span V"
 22.1833 -    by (metis span_inc span_mono subset_trans)
 22.1834 +    by (metis span_superset span_mono subset_trans)
 22.1835    from span_mono[OF B(3)] C have SVC: "span V \<subseteq> span C"
 22.1836      by (simp add: span_span)
 22.1837    from card_le_dim_spanning[OF CSV SVC C(1)] C(2,3) fB
 22.1838 @@ -2423,7 +820,7 @@
 22.1839      by simp
 22.1840    moreover have "dim V \<le> card C"
 22.1841      using span_card_ge_dim[OF CSV SVC C(1)]
 22.1842 -    by (simp add: dim_span)
 22.1843 +    by simp
 22.1844    ultimately have CdV: "card C = dim V"
 22.1845      using C(1) by simp
 22.1846    from C B CSV CdV iC show ?thesis
 22.1847 @@ -2440,7 +837,8 @@
 22.1848    from sU obtain a where a: "a \<notin> span S"
 22.1849      by blast
 22.1850    from orthogonal_basis_exists obtain B where
 22.1851 -    B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B" "card B = dim S" "pairwise orthogonal B"
 22.1852 +    B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B"
 22.1853 +    "card B = dim S" "pairwise orthogonal B"
 22.1854      by blast
 22.1855    from B have fB: "finite B" "card B = dim S"
 22.1856      using independent_bound by auto
 22.1857 @@ -2451,8 +849,8 @@
 22.1858    have "sum (\<lambda>b. (a \<bullet> b / (b \<bullet> b)) *\<^sub>R b) B \<in> span S"
 22.1859      unfolding sSB
 22.1860      apply (rule span_sum)
 22.1861 -    apply (rule span_mul)
 22.1862 -    apply (rule span_superset)
 22.1863 +    apply (rule span_scale)
 22.1864 +    apply (rule span_base)
 22.1865      apply assumption
 22.1866      done
 22.1867    with a have a0:"?a  \<noteq> 0"
 22.1868 @@ -2504,7 +902,7 @@
 22.1869      then have "dim (span S) = dim (UNIV :: ('a) set)"
 22.1870        by simp
 22.1871      then have "dim S = DIM('a)"
 22.1872 -      by (simp add: dim_span dim_UNIV)
 22.1873 +      by (metis Euclidean_Space.dim_UNIV dim_span)
 22.1874      with d have False by arith
 22.1875    }
 22.1876    then have th: "span S \<noteq> UNIV"
 22.1877 @@ -2512,132 +910,15 @@
 22.1878    from span_not_univ_subset_hyperplane[OF th] show ?thesis .
 22.1879  qed
 22.1880  
 22.1881 -text \<open>We can extend a linear basis-basis injection to the whole set.\<close>
 22.1882 -
 22.1883 -lemma linear_indep_image_lemma:
 22.1884 -  assumes lf: "linear f"
 22.1885 -    and fB: "finite B"
 22.1886 -    and ifB: "independent (f ` B)"
 22.1887 -    and fi: "inj_on f B"
 22.1888 -    and xsB: "x \<in> span B"
 22.1889 -    and fx: "f x = 0"
 22.1890 -  shows "x = 0"
 22.1891 -  using fB ifB fi xsB fx
 22.1892 -proof (induct arbitrary: x rule: finite_induct[OF fB])
 22.1893 -  case 1
 22.1894 -  then show ?case by auto
 22.1895 -next
 22.1896 -  case (2 a b x)
 22.1897 -  have fb: "finite b" using "2.prems" by simp
 22.1898 -  have th0: "f ` b \<subseteq> f ` (insert a b)"
 22.1899 -    apply (rule image_mono)
 22.1900 -    apply blast
 22.1901 -    done
 22.1902 -  from independent_mono[ OF "2.prems"(2) th0]
 22.1903 -  have ifb: "independent (f ` b)"  .
 22.1904 -  have fib: "inj_on f b"
 22.1905 -    apply (rule subset_inj_on [OF "2.prems"(3)])
 22.1906 -    apply blast
 22.1907 -    done
 22.1908 -  from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)]
 22.1909 -  obtain k where k: "x - k*\<^sub>R a \<in> span (b - {a})"
 22.1910 -    by blast
 22.1911 -  have "f (x - k*\<^sub>R a) \<in> span (f ` b)"
 22.1912 -    unfolding span_linear_image[OF lf]
 22.1913 -    apply (rule imageI)
 22.1914 -    using k span_mono[of "b - {a}" b]
 22.1915 -    apply blast
 22.1916 -    done
 22.1917 -  then have "f x - k*\<^sub>R f a \<in> span (f ` b)"
 22.1918 -    by (simp add: linear_diff[OF lf] linear_cmul[OF lf])
 22.1919 -  then have th: "-k *\<^sub>R f a \<in> span (f ` b)"
 22.1920 -    using "2.prems"(5) by simp
 22.1921 -  have xsb: "x \<in> span b"
 22.1922 -  proof (cases "k = 0")
 22.1923 -    case True
 22.1924 -    with k have "x \<in> span (b - {a})" by simp
 22.1925 -    then show ?thesis using span_mono[of "b - {a}" b]
 22.1926 -      by blast
 22.1927 -  next
 22.1928 -    case False
 22.1929 -    with span_mul[OF th, of "- 1/ k"]
 22.1930 -    have th1: "f a \<in> span (f ` b)"
 22.1931 -      by auto
 22.1932 -    from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric]
 22.1933 -    have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
 22.1934 -    from "2.prems"(2) [unfolded dependent_def bex_simps(8), rule_format, of "f a"]
 22.1935 -    have "f a \<notin> span (f ` b)" using tha
 22.1936 -      using "2.hyps"(2)
 22.1937 -      "2.prems"(3) by auto
 22.1938 -    with th1 have False by blast
 22.1939 -    then show ?thesis by blast
 22.1940 -  qed
 22.1941 -  from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)] show "x = 0" .
 22.1942 -qed
 22.1943 -
 22.1944 -text \<open>Can construct an isomorphism between spaces of same dimension.\<close>
 22.1945 -
 22.1946 -lemma subspace_isomorphism:
 22.1947 -  fixes S :: "'a::euclidean_space set"
 22.1948 -    and T :: "'b::euclidean_space set"
 22.1949 -  assumes s: "subspace S"
 22.1950 -    and t: "subspace T"
 22.1951 -    and d: "dim S = dim T"
 22.1952 -  shows "\<exists>f. linear f \<and> f ` S = T \<and> inj_on f S"
 22.1953 -proof -
 22.1954 -  from basis_exists[of S] independent_bound
 22.1955 -  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "card B = dim S" and fB: "finite B"
 22.1956 -    by blast
 22.1957 -  from basis_exists[of T] independent_bound
 22.1958 -  obtain C where C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "card C = dim T" and fC: "finite C"
 22.1959 -    by blast
 22.1960 -  from B(4) C(4) card_le_inj[of B C] d
 22.1961 -  obtain f where f: "f ` B \<subseteq> C" "inj_on f B" using \<open>finite B\<close> \<open>finite C\<close>
 22.1962 -    by auto
 22.1963 -  from linear_independent_extend[OF B(2)]
 22.1964 -  obtain g where g: "linear g" "\<forall>x\<in> B. g x = f x"
 22.1965 -    by blast
 22.1966 -  from inj_on_iff_eq_card[OF fB, of f] f(2) have "card (f ` B) = card B"
 22.1967 -    by simp
 22.1968 -  with B(4) C(4) have ceq: "card (f ` B) = card C"
 22.1969 -    using d by simp
 22.1970 -  have "g ` B = f ` B"
 22.1971 -    using g(2) by (auto simp add: image_iff)
 22.1972 -  also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
 22.1973 -  finally have gBC: "g ` B = C" .
 22.1974 -  have gi: "inj_on g B"
 22.1975 -    using f(2) g(2) by (auto simp add: inj_on_def)
 22.1976 -  note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
 22.1977 -  {
 22.1978 -    fix x y
 22.1979 -    assume x: "x \<in> S" and y: "y \<in> S" and gxy: "g x = g y"
 22.1980 -    from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B"
 22.1981 -      by blast+
 22.1982 -    from gxy have th0: "g (x - y) = 0"
 22.1983 -      by (simp add: linear_diff[OF g(1)])
 22.1984 -    have th1: "x - y \<in> span B"
 22.1985 -      using x' y' by (metis span_diff)
 22.1986 -    have "x = y"
 22.1987 -      using g0[OF th1 th0] by simp
 22.1988 -  }
 22.1989 -  then have giS: "inj_on g S"
 22.1990 -    unfolding inj_on_def by blast
 22.1991 -  from span_subspace[OF B(1,3) s] have "g ` S = span (g ` B)"
 22.1992 -    by (simp add: span_linear_image[OF g(1)])
 22.1993 -  also have "\<dots> = span C" unfolding gBC ..
 22.1994 -  also have "\<dots> = T" using span_subspace[OF C(1,3) t] .
 22.1995 -  finally have gS: "g ` S = T" .
 22.1996 -  from g(1) gS giS show ?thesis
 22.1997 -    by blast
 22.1998 -qed
 22.1999 -
 22.2000  lemma linear_eq_stdbasis:
 22.2001    fixes f :: "'a::euclidean_space \<Rightarrow> _"
 22.2002    assumes lf: "linear f"
 22.2003      and lg: "linear g"
 22.2004 -    and fg: "\<forall>b\<in>Basis. f b = g b"
 22.2005 +    and fg: "\<And>b. b \<in> Basis \<Longrightarrow> f b = g b"
 22.2006    shows "f = g"
 22.2007 -  using linear_eq[OF lf lg, of _ Basis] fg by auto
 22.2008 +  using linear_eq_on_span[OF lf lg, of Basis] fg
 22.2009 +  by auto
 22.2010 +
 22.2011  
 22.2012  text \<open>Similar results for bilinear functions.\<close>
 22.2013  
 22.2014 @@ -2652,7 +933,8 @@
 22.2015    let ?P = "{x. \<forall>y\<in> span C. f x y = g x y}"
 22.2016    from bf bg have sp: "subspace ?P"
 22.2017      unfolding bilinear_def linear_iff subspace_def bf bg
 22.2018 -    by (auto simp add: span_0 bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def
 22.2019 +    by (auto simp add: span_zero bilinear_lzero[OF bf] bilinear_lzero[OF bg]
 22.2020 +        span_add Ball_def
 22.2021        intro: bilinear_ladd[OF bf])
 22.2022  
 22.2023    have "\<forall>x \<in> span B. \<forall>y\<in> span C. f x y = g x y"
 22.2024 @@ -2662,7 +944,8 @@
 22.2025      apply (simp add: fg)
 22.2026      apply (auto simp add: subspace_def)
 22.2027      using bf bg unfolding bilinear_def linear_iff
 22.2028 -    apply (auto simp add: span_0 bilinear_rzero[OF bf] bilinear_rzero[OF bg] span_add Ball_def
 22.2029 +      apply (auto simp add: span_zero bilinear_rzero[OF bf] bilinear_rzero[OF bg]
 22.2030 +        span_add Ball_def
 22.2031        intro: bilinear_ladd[OF bf])
 22.2032      done
 22.2033    then show ?thesis
 22.2034 @@ -2677,234 +960,6 @@
 22.2035    shows "f = g"
 22.2036    using bilinear_eq[OF bf bg equalityD2[OF span_Basis] equalityD2[OF span_Basis] fg] by blast
 22.2037  
 22.2038 -text \<open>An injective map @{typ "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"} is also surjective.\<close>
 22.2039 -
 22.2040 -lemma linear_injective_imp_surjective:
 22.2041 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2042 -  assumes lf: "linear f"
 22.2043 -    and fi: "inj f"
 22.2044 -  shows "surj f"
 22.2045 -proof -
 22.2046 -  let ?U = "UNIV :: 'a set"
 22.2047 -  from basis_exists[of ?U] obtain B
 22.2048 -    where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" "card B = dim ?U"
 22.2049 -    by blast
 22.2050 -  from B(4) have d: "dim ?U = card B"
 22.2051 -    by simp
 22.2052 -  have th: "?U \<subseteq> span (f ` B)"
 22.2053 -    apply (rule card_ge_dim_independent)
 22.2054 -    apply blast
 22.2055 -    apply (rule independent_injective_image[OF B(2) lf fi])
 22.2056 -    apply (rule order_eq_refl)
 22.2057 -    apply (rule sym)
 22.2058 -    unfolding d
 22.2059 -    apply (rule card_image)
 22.2060 -    apply (rule subset_inj_on[OF fi])
 22.2061 -    apply blast
 22.2062 -    done
 22.2063 -  from th show ?thesis
 22.2064 -    unfolding span_linear_image[OF lf] surj_def
 22.2065 -    using B(3) by blast
 22.2066 -qed
 22.2067 -
 22.2068 -text \<open>And vice versa.\<close>
 22.2069 -
 22.2070 -lemma surjective_iff_injective_gen:
 22.2071 -  assumes fS: "finite S"
 22.2072 -    and fT: "finite T"
 22.2073 -    and c: "card S = card T"
 22.2074 -    and ST: "f ` S \<subseteq> T"
 22.2075 -  shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S"
 22.2076 -  (is "?lhs \<longleftrightarrow> ?rhs")
 22.2077 -proof
 22.2078 -  assume h: "?lhs"
 22.2079 -  {
 22.2080 -    fix x y
 22.2081 -    assume x: "x \<in> S"
 22.2082 -    assume y: "y \<in> S"
 22.2083 -    assume f: "f x = f y"
 22.2084 -    from x fS have S0: "card S \<noteq> 0"
 22.2085 -      by auto
 22.2086 -    have "x = y"
 22.2087 -    proof (rule ccontr)
 22.2088 -      assume xy: "\<not> ?thesis"
 22.2089 -      have th: "card S \<le> card (f ` (S - {y}))"
 22.2090 -        unfolding c
 22.2091 -        apply (rule card_mono)
 22.2092 -        apply (rule finite_imageI)
 22.2093 -        using fS apply simp
 22.2094 -        using h xy x y f unfolding subset_eq image_iff
 22.2095 -        apply auto
 22.2096 -        apply (case_tac "xa = f x")
 22.2097 -        apply (rule bexI[where x=x])
 22.2098 -        apply auto
 22.2099 -        done
 22.2100 -      also have " \<dots> \<le> card (S - {y})"
 22.2101 -        apply (rule card_image_le)
 22.2102 -        using fS by simp
 22.2103 -      also have "\<dots> \<le> card S - 1" using y fS by simp
 22.2104 -      finally show False using S0 by arith
 22.2105 -    qed
 22.2106 -  }
 22.2107 -  then show ?rhs
 22.2108 -    unfolding inj_on_def by blast
 22.2109 -next
 22.2110 -  assume h: ?rhs
 22.2111 -  have "f ` S = T"
 22.2112 -    apply (rule card_subset_eq[OF fT ST])
 22.2113 -    unfolding card_image[OF h]
 22.2114 -    apply (rule c)
 22.2115 -    done
 22.2116 -  then show ?lhs by blast
 22.2117 -qed
 22.2118 -
 22.2119 -lemma linear_surjective_imp_injective:
 22.2120 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2121 -  assumes lf: "linear f"
 22.2122 -    and sf: "surj f"
 22.2123 -  shows "inj f"
 22.2124 -proof -
 22.2125 -  let ?U = "UNIV :: 'a set"
 22.2126 -  from basis_exists[of ?U] obtain B
 22.2127 -    where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" and d: "card B = dim ?U"
 22.2128 -    by blast
 22.2129 -  {
 22.2130 -    fix x
 22.2131 -    assume x: "x \<in> span B"
 22.2132 -    assume fx: "f x = 0"
 22.2133 -    from B(2) have fB: "finite B"
 22.2134 -      using independent_bound by auto
 22.2135 -    have fBi: "independent (f ` B)"
 22.2136 -      apply (rule card_le_dim_spanning[of "f ` B" ?U])
 22.2137 -      apply blast
 22.2138 -      using sf B(3)
 22.2139 -      unfolding span_linear_image[OF lf] surj_def subset_eq image_iff
 22.2140 -      apply blast
 22.2141 -      using fB apply blast
 22.2142 -      unfolding d[symmetric]
 22.2143 -      apply (rule card_image_le)
 22.2144 -      apply (rule fB)
 22.2145 -      done
 22.2146 -    have th0: "dim ?U \<le> card (f ` B)"
 22.2147 -      apply (rule span_card_ge_dim)
 22.2148 -      apply blast
 22.2149 -      unfolding span_linear_image[OF lf]
 22.2150 -      apply (rule subset_trans[where B = "f ` UNIV"])
 22.2151 -      using sf unfolding surj_def
 22.2152 -      apply blast
 22.2153 -      apply (rule image_mono)
 22.2154 -      apply (rule B(3))
 22.2155 -      apply (metis finite_imageI fB)
 22.2156 -      done
 22.2157 -    moreover have "card (f ` B) \<le> card B"
 22.2158 -      by (rule card_image_le, rule fB)
 22.2159 -    ultimately have th1: "card B = card (f ` B)"
 22.2160 -      unfolding d by arith
 22.2161 -    have fiB: "inj_on f B"
 22.2162 -      unfolding surjective_iff_injective_gen[OF fB finite_imageI[OF fB] th1 subset_refl, symmetric]
 22.2163 -      by blast
 22.2164 -    from linear_indep_image_lemma[OF lf fB fBi fiB x] fx
 22.2165 -    have "x = 0" by blast
 22.2166 -  }
 22.2167 -  then show ?thesis
 22.2168 -    unfolding linear_injective_0[OF lf]
 22.2169 -    using B(3)
 22.2170 -    by blast
 22.2171 -qed
 22.2172 -
 22.2173 -text \<open>Hence either is enough for isomorphism.\<close>
 22.2174 -
 22.2175 -lemma left_right_inverse_eq:
 22.2176 -  assumes fg: "f \<circ> g = id"
 22.2177 -    and gh: "g \<circ> h = id"
 22.2178 -  shows "f = h"
 22.2179 -proof -
 22.2180 -  have "f = f \<circ> (g \<circ> h)"
 22.2181 -    unfolding gh by simp
 22.2182 -  also have "\<dots> = (f \<circ> g) \<circ> h"
 22.2183 -    by (simp add: o_assoc)
 22.2184 -  finally show "f = h"
 22.2185 -    unfolding fg by simp
 22.2186 -qed
 22.2187 -
 22.2188 -lemma isomorphism_expand:
 22.2189 -  "f \<circ> g = id \<and> g \<circ> f = id \<longleftrightarrow> (\<forall>x. f (g x) = x) \<and> (\<forall>x. g (f x) = x)"
 22.2190 -  by (simp add: fun_eq_iff o_def id_def)
 22.2191 -
 22.2192 -lemma linear_injective_isomorphism:
 22.2193 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2194 -  assumes lf: "linear f"
 22.2195 -    and fi: "inj f"
 22.2196 -  shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)"
 22.2197 -  unfolding isomorphism_expand[symmetric]
 22.2198 -  using linear_surjective_right_inverse[OF lf linear_injective_imp_surjective[OF lf fi]]
 22.2199 -    linear_injective_left_inverse[OF lf fi]
 22.2200 -  by (metis left_right_inverse_eq)
 22.2201 -
 22.2202 -lemma linear_surjective_isomorphism:
 22.2203 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2204 -  assumes lf: "linear f"
 22.2205 -    and sf: "surj f"
 22.2206 -  shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)"
 22.2207 -  unfolding isomorphism_expand[symmetric]
 22.2208 -  using linear_surjective_right_inverse[OF lf sf]
 22.2209 -    linear_injective_left_inverse[OF lf linear_surjective_imp_injective[OF lf sf]]
 22.2210 -  by (metis left_right_inverse_eq)
 22.2211 -
 22.2212 -text \<open>Left and right inverses are the same for
 22.2213 -  @{typ "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"}.\<close>
 22.2214 -
 22.2215 -lemma linear_inverse_left:
 22.2216 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2217 -  assumes lf: "linear f"
 22.2218 -    and lf': "linear f'"
 22.2219 -  shows "f \<circ> f' = id \<longleftrightarrow> f' \<circ> f = id"
 22.2220 -proof -
 22.2221 -  {
 22.2222 -    fix f f':: "'a \<Rightarrow> 'a"
 22.2223 -    assume lf: "linear f" "linear f'"
 22.2224 -    assume f: "f \<circ> f' = id"
 22.2225 -    from f have sf: "surj f"
 22.2226 -      apply (auto simp add: o_def id_def surj_def)
 22.2227 -      apply metis
 22.2228 -      done
 22.2229 -    from linear_surjective_isomorphism[OF lf(1) sf] lf f
 22.2230 -    have "f' \<circ> f = id"
 22.2231 -      unfolding fun_eq_iff o_def id_def by metis
 22.2232 -  }
 22.2233 -  then show ?thesis
 22.2234 -    using lf lf' by metis
 22.2235 -qed
 22.2236 -
 22.2237 -text \<open>Moreover, a one-sided inverse is automatically linear.\<close>
 22.2238 -
 22.2239 -lemma left_inverse_linear:
 22.2240 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2241 -  assumes lf: "linear f"
 22.2242 -    and gf: "g \<circ> f = id"
 22.2243 -  shows "linear g"
 22.2244 -proof -
 22.2245 -  from gf have fi: "inj f"
 22.2246 -    apply (auto simp add: inj_on_def o_def id_def fun_eq_iff)
 22.2247 -    apply metis
 22.2248 -    done
 22.2249 -  from linear_injective_isomorphism[OF lf fi]
 22.2250 -  obtain h :: "'a \<Rightarrow> 'a" where h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x"
 22.2251 -    by blast
 22.2252 -  have "h = g"
 22.2253 -    apply (rule ext) using gf h(2,3)
 22.2254 -    apply (simp add: o_def id_def fun_eq_iff)
 22.2255 -    apply metis
 22.2256 -    done
 22.2257 -  with h(1) show ?thesis by blast
 22.2258 -qed
 22.2259 -
 22.2260 -lemma inj_linear_imp_inv_linear:
 22.2261 -  fixes f :: "'a::euclidean_space \<Rightarrow> 'a::euclidean_space"
 22.2262 -  assumes "linear f" "inj f" shows "linear (inv f)"
 22.2263 -using assms inj_iff left_inverse_linear by blast
 22.2264 -
 22.2265 -
 22.2266  subsection \<open>Infinity norm\<close>
 22.2267  
 22.2268  definition%important "infnorm (x::'a::euclidean_space) = Sup {\<bar>x \<bullet> b\<bar> |b. b \<in> Basis}"
 22.2269 @@ -3181,7 +1236,7 @@
 22.2270    qed
 22.2271    then show ?thesis
 22.2272      apply (clarsimp simp: collinear_def)
 22.2273 -    by (metis real_vector.scale_zero_right vector_fraction_eq_iff)
 22.2274 +    by (metis scaleR_zero_right vector_fraction_eq_iff)
 22.2275  qed
 22.2276  
 22.2277  lemma collinear_subset: "\<lbrakk>collinear T; S \<subseteq> T\<rbrakk> \<Longrightarrow> collinear S"
    23.1 --- a/src/HOL/Analysis/Path_Connected.thy	Wed Apr 18 21:12:50 2018 +0100
    23.2 +++ b/src/HOL/Analysis/Path_Connected.thy	Wed May 02 13:49:38 2018 +0200
    23.3 @@ -6354,21 +6354,18 @@
    23.4      by (meson subsetD image_eqI inj_on_def)
    23.5    obtain f where "linear f" and ffb: "\<And>x. x \<in> B \<Longrightarrow> f x = fb x"
    23.6      using linear_independent_extend \<open>independent B\<close> by fastforce
    23.7 -  have "f ` S \<subseteq> T"
    23.8 -    by (metis ffb \<open>fb ` B \<subseteq> C\<close> \<open>linear f\<close> \<open>span B = S\<close> \<open>span C = T\<close> image_cong span_linear_image span_mono)
    23.9 +  have "span (f ` B) \<subseteq> span C"
   23.10 +    by (metis \<open>fb ` B \<subseteq> C\<close> ffb image_cong span_mono)
   23.11 +  then have "f ` S \<subseteq> T"
   23.12 +    unfolding \<open>span B = S\<close> \<open>span C = T\<close> span_linear_image[OF \<open>linear f\<close>] .
   23.13    have [simp]: "\<And>x. x \<in> B \<Longrightarrow> norm (fb x) = norm x"
   23.14      using B1 C1 \<open>fb ` B \<subseteq> C\<close> by auto
   23.15    have "norm (f x) = norm x" if "x \<in> S" for x
   23.16    proof -
   23.17 +    interpret linear f by fact
   23.18      obtain a where x: "x = (\<Sum>v \<in> B. a v *\<^sub>R v)"
   23.19        using \<open>finite B\<close> \<open>span B = S\<close> \<open>x \<in> S\<close> span_finite by fastforce
   23.20 -    have "f x = (\<Sum>v \<in> B. f (a v *\<^sub>R v))"
   23.21 -      using linear_sum [OF \<open>linear f\<close>] x by auto
   23.22 -    also have "... = (\<Sum>v \<in> B. a v *\<^sub>R f v)"
   23.23 -      using \<open>linear f\<close> by (simp add: linear_sum linear.scaleR)
   23.24 -    also have "... = (\<Sum>v \<in> B. a v *\<^sub>R fb v)"
   23.25 -      by (simp add: ffb cong: sum.cong)
   23.26 -    finally have "norm (f x)^2 = norm (\<Sum>v\<in>B. a v *\<^sub>R fb v)^2" by simp
   23.27 +    have "norm (f x)^2 = norm (\<Sum>v\<in>B. a v *\<^sub>R fb v)^2" by (simp add: sum scale ffb x)
   23.28      also have "... = (\<Sum>v\<in>B. norm ((a v *\<^sub>R fb v))^2)"
   23.29        apply (rule norm_sum_Pythagorean [OF \<open>finite B\<close>])
   23.30        apply (rule pairwise_ortho_scaleR [OF pairwise_orth_fb])
   23.31 @@ -6410,6 +6407,7 @@
   23.32      by (meson subsetD image_eqI inj_on_def)
   23.33    obtain f where "linear f" and ffb: "\<And>x. x \<in> B \<Longrightarrow> f x = fb x"
   23.34      using linear_independent_extend \<open>independent B\<close> by fastforce
   23.35 +  interpret f: linear f by fact
   23.36    define gb where "gb \<equiv> inv_into B fb"
   23.37    then have pairwise_orth_gb: "pairwise (\<lambda>v j. orthogonal (gb v) (gb j)) C"
   23.38      using Borth
   23.39 @@ -6417,8 +6415,12 @@
   23.40      by (metis \<open>bij_betw fb B C\<close> bij_betw_imp_surj_on bij_betw_inv_into_right inv_into_into)
   23.41    obtain g where "linear g" and ggb: "\<And>x. x \<in> C \<Longrightarrow> g x = gb x"
   23.42      using linear_independent_extend \<open>independent C\<close> by fastforce
   23.43 -  have "f ` S \<subseteq> T"
   23.44 -    by (metis \<open>bij_betw fb B C\<close> bij_betw_imp_surj_on eq_iff ffb  \<open>linear f\<close> \<open>span B = S\<close> \<open>span C = T\<close> image_cong span_linear_image)
   23.45 +  interpret g: linear g by fact
   23.46 +  have "span (f ` B) \<subseteq> span C"
   23.47 +    by (metis \<open>bij_betw fb B C\<close> bij_betw_imp_surj_on eq_iff ffb image_cong)
   23.48 +  then have "f ` S \<subseteq> T"
   23.49 +    unfolding \<open>span B = S\<close> \<open>span C = T\<close>
   23.50 +      span_linear_image[OF \<open>linear f\<close>] .
   23.51    have [simp]: "\<And>x. x \<in> B \<Longrightarrow> norm (fb x) = norm x"
   23.52      using B1 C1 \<open>bij_betw fb B C\<close> bij_betw_imp_surj_on by fastforce
   23.53    have f [simp]: "norm (f x) = norm x" "g (f x) = x" if "x \<in> S" for x
   23.54 @@ -6428,7 +6430,7 @@
   23.55      have "f x = (\<Sum>v \<in> B. f (a v *\<^sub>R v))"
   23.56        using linear_sum [OF \<open>linear f\<close>] x by auto
   23.57      also have "... = (\<Sum>v \<in> B. a v *\<^sub>R f v)"
   23.58 -      using \<open>linear f\<close> by (simp add: linear_sum linear.scaleR)
   23.59 +      by (simp add: f.sum f.scale)
   23.60      also have "... = (\<Sum>v \<in> B. a v *\<^sub>R fb v)"
   23.61        by (simp add: ffb cong: sum.cong)
   23.62      finally have *: "f x = (\<Sum>v\<in>B. a v *\<^sub>R fb v)" .
   23.63 @@ -6443,9 +6445,9 @@
   23.64        by (simp add: norm_eq_sqrt_inner)
   23.65      have "g (f x) = g (\<Sum>v\<in>B. a v *\<^sub>R fb v)" by (simp add: *)
   23.66      also have "... = (\<Sum>v\<in>B. g (a v *\<^sub>R fb v))"
   23.67 -      using \<open>linear g\<close> by (simp add: linear_sum linear.scaleR)
   23.68 +      by (simp add: g.sum g.scale)
   23.69      also have "... = (\<Sum>v\<in>B. a v *\<^sub>R g (fb v))"
   23.70 -      by (simp add: \<open>linear g\<close> linear.scaleR)
   23.71 +      by (simp add: g.scale)
   23.72      also have "... = (\<Sum>v\<in>B. a v *\<^sub>R v)"
   23.73        apply (rule sum.cong [OF refl])
   23.74        using \<open>bij_betw fb B C\<close> gb_def bij_betwE bij_betw_inv_into_left gb_def ggb by fastforce
   23.75 @@ -6460,16 +6462,16 @@
   23.76      obtain a where x: "x = (\<Sum>v \<in> C. a v *\<^sub>R v)"
   23.77        using \<open>finite C\<close> \<open>span C = T\<close> \<open>x \<in> T\<close> span_finite by fastforce
   23.78      have "g x = (\<Sum>v \<in> C. g (a v *\<^sub>R v))"
   23.79 -      using linear_sum [OF \<open>linear g\<close>] x by auto
   23.80 +      by (simp add: x g.sum)
   23.81      also have "... = (\<Sum>v \<in> C. a v *\<^sub>R g v)"
   23.82 -      using \<open>linear g\<close> by (simp add: linear_sum linear.scaleR)
   23.83 +      by (simp add: g.scale)
   23.84      also have "... = (\<Sum>v \<in> C. a v *\<^sub>R gb v)"
   23.85        by (simp add: ggb cong: sum.cong)
   23.86      finally have "f (g x) = f (\<Sum>v\<in>C. a v *\<^sub>R gb v)" by simp
   23.87      also have "... = (\<Sum>v\<in>C. f (a v *\<^sub>R gb v))"
   23.88 -      using \<open>linear f\<close> by (simp add: linear_sum linear.scaleR)
   23.89 +      by (simp add: f.scale f.sum)
   23.90      also have "... = (\<Sum>v\<in>C. a v *\<^sub>R f (gb v))"
   23.91 -      by (simp add: \<open>linear f\<close> linear.scaleR)
   23.92 +      by (simp add: f.scale f.sum)
   23.93      also have "... = (\<Sum>v\<in>C. a v *\<^sub>R v)"
   23.94        using \<open>bij_betw fb B C\<close>
   23.95        by (simp add: bij_betw_def gb_def bij_betw_inv_into_right ffb inv_into_into)
   23.96 @@ -6478,7 +6480,8 @@
   23.97      finally show "f (g x) = x" .
   23.98    qed
   23.99    have gim: "g ` T = S"
  23.100 -    by (metis (no_types, lifting) \<open>f ` S \<subseteq> T\<close> \<open>linear g\<close> \<open>span B = S\<close> \<open>span C = T\<close> d dim_eq_span dim_image_le f(2) image_subset_iff span_linear_image span_span subsetI)
  23.101 +    by (metis (full_types) S T \<open>f ` S \<subseteq> T\<close> d dim_eq_span dim_image_le f(2) g.linear_axioms
  23.102 +        image_iff linear_subspace_image span_eq_iff subset_iff)
  23.103    have fim: "f ` S = T"
  23.104      using \<open>g ` T = S\<close> image_iff by fastforce
  23.105    have [simp]: "norm (g x) = norm x" if "x \<in> T" for x
  23.106 @@ -6504,8 +6507,8 @@
  23.107    obtains f::"'M::euclidean_space \<Rightarrow>'N::euclidean_space" and g
  23.108    where "linear f" "linear g"
  23.109                      "\<And>x. norm(f x) = norm x" "\<And>y. norm(g y) = norm y"
  23.110 -                    "\<And>x. g(f x) = x" "\<And>y. f(g y) = y"
  23.111 -  using assms by (auto simp: dim_UNIV intro: isometries_subspaces [of "UNIV::'M set" "UNIV::'N set"])
  23.112 +                    "\<And>x. g (f x) = x" "\<And>y. f(g y) = y"
  23.113 +  using assms by (auto simp: intro: isometries_subspaces [of "UNIV::'M set" "UNIV::'N set"])
  23.114  
  23.115  lemma homeomorphic_subspaces:
  23.116    fixes S :: "'a::euclidean_space set"
  23.117 @@ -7079,7 +7082,7 @@
  23.118      shows "uncountable (ball a r)"
  23.119  proof -
  23.120    have "uncountable (open_segment a (a + r *\<^sub>R (SOME i. i \<in> Basis)))"
  23.121 -    by (metis Basis_zero SOME_Basis add_cancel_right_right assms less_le real_vector.scale_eq_0_iff uncountable_open_segment)
  23.122 +    by (metis Basis_zero SOME_Basis add_cancel_right_right assms less_le scale_eq_0_iff uncountable_open_segment)
  23.123    moreover have "open_segment a (a + r *\<^sub>R (SOME i. i \<in> Basis)) \<subseteq> ball a r"
  23.124      using assms by (auto simp: in_segment algebra_simps dist_norm SOME_Basis)
  23.125    ultimately show ?thesis
    24.1 --- a/src/HOL/Analysis/Polytope.thy	Wed Apr 18 21:12:50 2018 +0100
    24.2 +++ b/src/HOL/Analysis/Polytope.thy	Wed May 02 13:49:38 2018 +0200
    24.3 @@ -197,8 +197,7 @@
    24.4        by (simp add: algebra_simps d_def) (simp add: divide_simps)
    24.5      have [simp]: "((e - e * e / (e + norm (b - c))) / norm (b - c)) = (e / (e + norm (b - c)))"
    24.6        using False nbc
    24.7 -      apply (simp add: algebra_simps divide_simps)
    24.8 -      by (metis mult_eq_0_iff norm_eq_zero norm_imp_pos_and_ge norm_pths(2) real_scaleR_def scaleR_left.add zero_less_norm_iff)
    24.9 +      by (simp add: divide_simps) (simp add: algebra_simps)
   24.10      have "b \<in> open_segment d c"
   24.11        apply (simp add: open_segment_image_interval)
   24.12        apply (simp add: d_def algebra_simps image_def)
   24.13 @@ -2673,7 +2672,8 @@
   24.14  lemma polyhedron_negations:
   24.15    fixes S :: "'a :: euclidean_space set"
   24.16    shows   "polyhedron S \<Longrightarrow> polyhedron(image uminus S)"
   24.17 -by (auto simp: polyhedron_linear_image_eq linear_uminus bij_uminus)
   24.18 +  by (subst polyhedron_linear_image_eq)
   24.19 +    (auto simp: bij_uminus intro!: linear_uminus)
   24.20  
   24.21  subsection\<open>Relation between polytopes and polyhedra\<close>
   24.22  
    25.1 --- a/src/HOL/Analysis/Product_Vector.thy	Wed Apr 18 21:12:50 2018 +0100
    25.2 +++ b/src/HOL/Analysis/Product_Vector.thy	Wed May 02 13:49:38 2018 +0200
    25.3 @@ -10,6 +10,52 @@
    25.4    "HOL-Library.Product_Plus"
    25.5  begin
    25.6  
    25.7 +lemma Times_eq_image_sum:
    25.8 +  fixes S :: "'a :: comm_monoid_add set" and T :: "'b :: comm_monoid_add set"
    25.9 +  shows "S \<times> T = {u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T}"
   25.10 +  by force
   25.11 +
   25.12 +
   25.13 +subsection \<open>Product is a module\<close>
   25.14 +
   25.15 +locale module_prod = module_pair begin
   25.16 +
   25.17 +definition scale :: "'a \<Rightarrow> 'b \<times> 'c \<Rightarrow> 'b \<times> 'c"
   25.18 +  where "scale a v = (s1 a (fst v), s2 a (snd v))"
   25.19 +
   25.20 +lemma scale_prod: "scale x (a, b) = (s1 x a, s2 x b)"
   25.21 +  by (auto simp: scale_def)
   25.22 +
   25.23 +sublocale p: module scale
   25.24 +proof qed (simp_all add: scale_def
   25.25 +  m1.scale_left_distrib m1.scale_right_distrib m2.scale_left_distrib m2.scale_right_distrib)
   25.26 +
   25.27 +lemma subspace_Times: "m1.subspace A \<Longrightarrow> m2.subspace B \<Longrightarrow> p.subspace (A \<times> B)"
   25.28 +  unfolding m1.subspace_def m2.subspace_def p.subspace_def
   25.29 +  by (auto simp: zero_prod_def scale_def)
   25.30 +
   25.31 +lemma module_hom_fst: "module_hom scale s1 fst"
   25.32 +  by unfold_locales (auto simp: scale_def)
   25.33 +
   25.34 +lemma module_hom_snd: "module_hom scale s2 snd"
   25.35 +  by unfold_locales (auto simp: scale_def)
   25.36 +
   25.37 +end
   25.38 +
   25.39 +locale vector_space_prod = vector_space_pair begin
   25.40 +
   25.41 +sublocale module_prod s1 s2
   25.42 +  rewrites "module_hom = Vector_Spaces.linear"
   25.43 +  by unfold_locales (fact module_hom_eq_linear)
   25.44 +
   25.45 +sublocale p: vector_space scale by unfold_locales (auto simp: algebra_simps)
   25.46 +
   25.47 +lemmas linear_fst = module_hom_fst
   25.48 +  and linear_snd = module_hom_snd
   25.49 +
   25.50 +end
   25.51 +
   25.52 +
   25.53  subsection \<open>Product is a real vector space\<close>
   25.54  
   25.55  instantiation%important prod :: (real_vector, real_vector) real_vector
   25.56 @@ -42,6 +88,27 @@
   25.57  
   25.58  end
   25.59  
   25.60 +lemma module_prod_scale_eq_scaleR: "module_prod.scale ( *\<^sub>R) ( *\<^sub>R) = scaleR"
   25.61 +  apply (rule ext) apply (rule ext)
   25.62 +  apply (subst module_prod.scale_def)
   25.63 +  subgoal by unfold_locales
   25.64 +  by (simp add: scaleR_prod_def)
   25.65 +
   25.66 +interpretation real_vector?: vector_space_prod "scaleR::_\<Rightarrow>_\<Rightarrow>'a::real_vector" "scaleR::_\<Rightarrow>_\<Rightarrow>'b::real_vector"
   25.67 +  rewrites "scale = (( *\<^sub>R)::_\<Rightarrow>_\<Rightarrow>('a \<times> 'b))"
   25.68 +    and "module.dependent ( *\<^sub>R) = dependent"
   25.69 +    and "module.representation ( *\<^sub>R) = representation"
   25.70 +    and "module.subspace ( *\<^sub>R) = subspace"
   25.71 +    and "module.span ( *\<^sub>R) = span"
   25.72 +    and "vector_space.extend_basis ( *\<^sub>R) = extend_basis"
   25.73 +    and "vector_space.dim ( *\<^sub>R) = dim"
   25.74 +    and "Vector_Spaces.linear ( *\<^sub>R) ( *\<^sub>R) = linear"
   25.75 +  subgoal by unfold_locales
   25.76 +  subgoal by (fact module_prod_scale_eq_scaleR)
   25.77 +  unfolding dependent_raw_def representation_raw_def subspace_raw_def span_raw_def
   25.78 +    extend_basis_raw_def dim_raw_def linear_def
   25.79 +  by (rule refl)+
   25.80 +
   25.81  subsection \<open>Product is a metric space\<close>
   25.82  
   25.83  (* TODO: Product of uniform spaces and compatibility with metric_spaces! *)
   25.84 @@ -270,7 +337,7 @@
   25.85    show "(f (x + y), g (x + y)) = (f x, g x) + (f y, g y)"
   25.86      by (simp add: f.add g.add)
   25.87    show "(f (r *\<^sub>R x), g (r *\<^sub>R x)) = r *\<^sub>R (f x, g x)"
   25.88 -    by (simp add: f.scaleR g.scaleR)
   25.89 +    by (simp add: f.scale g.scale)
   25.90    obtain Kf where "0 < Kf" and norm_f: "\<And>x. norm (f x) \<le> norm x * Kf"
   25.91      using f.pos_bounded by fast
   25.92    obtain Kg where "0 < Kg" and norm_g: "\<And>x. norm (g x) \<le> norm x * Kg"
   25.93 @@ -389,4 +456,112 @@
   25.94    unfolding norm_Pair
   25.95    by (metis norm_ge_zero sqrt_sum_squares_le_sum)
   25.96  
   25.97 +lemma (in vector_space_prod) span_Times_sing1: "p.span ({0} \<times> B) = {0} \<times> vs2.span B"
   25.98 +  apply (rule p.span_unique)
   25.99 +  subgoal by (auto intro!: vs1.span_base vs2.span_base)
  25.100 +  subgoal using vs1.subspace_single_0 vs2.subspace_span by (rule subspace_Times)
  25.101 +  subgoal for T
  25.102 +  proof safe
  25.103 +    fix b
  25.104 +    assume subset_T: "{0} \<times> B \<subseteq> T" and subspace: "p.subspace T" and b_span: "b \<in> vs2.span B"
  25.105 +    then obtain t r where b: "b = (\<Sum>a\<in>t. r a *b a)" and t: "finite t" "t \<subseteq> B"
  25.106 +      by (auto simp: vs2.span_explicit)
  25.107 +    have "(0, b) = (\<Sum>b\<in>t. scale (r b) (0, b))"
  25.108 +      unfolding b scale_prod sum_prod
  25.109 +      by simp
  25.110 +    also have "\<dots> \<in> T"
  25.111 +      using \<open>t \<subseteq> B\<close> subset_T
  25.112 +      by (auto intro!: p.subspace_sum p.subspace_scale subspace)
  25.113 +    finally show "(0, b) \<in> T" .
  25.114 +  qed
  25.115 +  done
  25.116 +
  25.117 +lemma (in vector_space_prod) span_Times_sing2: "p.span (A \<times> {0}) = vs1.span A \<times> {0}"
  25.118 +  apply (rule p.span_unique)
  25.119 +  subgoal by (auto intro!: vs1.span_base vs2.span_base)
  25.120 +  subgoal using vs1.subspace_span vs2.subspace_single_0 by (rule subspace_Times)
  25.121 +  subgoal for T
  25.122 +  proof safe
  25.123 +    fix a
  25.124 +    assume subset_T: "A \<times> {0} \<subseteq> T" and subspace: "p.subspace T" and a_span: "a \<in> vs1.span A"
  25.125 +    then obtain t r where a: "a = (\<Sum>a\<in>t. r a *a a)" and t: "finite t" "t \<subseteq> A"
  25.126 +      by (auto simp: vs1.span_explicit)
  25.127 +    have "(a, 0) = (\<Sum>a\<in>t. scale (r a) (a, 0))"
  25.128 +      unfolding a scale_prod sum_prod
  25.129 +      by simp
  25.130 +    also have "\<dots> \<in> T"
  25.131 +      using \<open>t \<subseteq> A\<close> subset_T
  25.132 +      by (auto intro!: p.subspace_sum p.subspace_scale subspace)
  25.133 +    finally show "(a, 0) \<in> T" .
  25.134 +  qed
  25.135 +  done
  25.136 +
  25.137 +lemma (in finite_dimensional_vector_space) zero_not_in_Basis[simp]: "0 \<notin> Basis"
  25.138 +  using dependent_zero local.independent_Basis by blast
  25.139 +
  25.140 +locale finite_dimensional_vector_space_prod = vector_space_prod + finite_dimensional_vector_space_pair begin
  25.141 +
  25.142 +definition "Basis_pair = B1 \<times> {0} \<union> {0} \<times> B2"
  25.143 +
  25.144 +sublocale p: finite_dimensional_vector_space scale Basis_pair
  25.145 +proof unfold_locales
  25.146 +  show "finite Basis_pair"
  25.147 +    by (auto intro!: finite_cartesian_product vs1.finite_Basis vs2.finite_Basis simp: Basis_pair_def)
  25.148 +  show "p.independent Basis_pair"
  25.149 +    unfolding p.dependent_def Basis_pair_def
  25.150 +  proof safe
  25.151 +    fix a
  25.152 +    assume a: "a \<in> B1"
  25.153 +    assume "(a, 0) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)})"
  25.154 +    also have "B1 \<times> {0} \<union> {0} \<times> B2 - {(a, 0)} = (B1 - {a}) \<times> {0} \<union> {0} \<times> B2"
  25.155 +      by auto
  25.156 +    finally show False
  25.157 +      using a vs1.dependent_def vs1.independent_Basis
  25.158 +      by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
  25.159 +  next
  25.160 +    fix b
  25.161 +    assume b: "b \<in> B2"
  25.162 +    assume "(0, b) \<in> p.span (B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)})"
  25.163 +    also have "(B1 \<times> {0} \<union> {0} \<times> B2 - {(0, b)}) = B1 \<times> {0} \<union> {0} \<times> (B2 - {b})"
  25.164 +      by auto
  25.165 +    finally show False
  25.166 +      using b vs2.dependent_def vs2.independent_Basis
  25.167 +      by (auto simp: p.span_Un span_Times_sing1 span_Times_sing2)
  25.168 +  qed
  25.169 +  show "p.span Basis_pair = UNIV"
  25.170 +    by (auto simp: p.span_Un span_Times_sing2 span_Times_sing1 vs1.span_Basis vs2.span_Basis
  25.171 +        Basis_pair_def)
  25.172 +qed
  25.173 +
  25.174 +lemma dim_Times:
  25.175 +  assumes "vs1.subspace S" "vs2.subspace T"
  25.176 +  shows "p.dim(S \<times> T) = vs1.dim S + vs2.dim T"
  25.177 +proof -
  25.178 +  interpret p1: Vector_Spaces.linear s1 scale "(\<lambda>x. (x, 0))"
  25.179 +    by unfold_locales (auto simp: scale_def)
  25.180 +  interpret pair1: finite_dimensional_vector_space_pair "( *a)" B1 scale Basis_pair
  25.181 +    by unfold_locales
  25.182 +  interpret p2: Vector_Spaces.linear s2 scale "(\<lambda>x. (0, x))"
  25.183 +    by unfold_locales (auto simp: scale_def)
  25.184 +  interpret pair2: finite_dimensional_vector_space_pair "( *b)" B2 scale Basis_pair
  25.185 +    by unfold_locales
  25.186 +  have ss: "p.subspace ((\<lambda>x. (x, 0)) ` S)" "p.subspace (Pair 0 ` T)"
  25.187 +    by (rule p1.subspace_image p2.subspace_image assms)+
  25.188 +  have "p.dim(S \<times> T) = p.dim({u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T})"
  25.189 +    by (simp add: Times_eq_image_sum)
  25.190 +  moreover have "p.dim ((\<lambda>x. (x, 0::'c)) ` S) = vs1.dim S" "p.dim (Pair (0::'b) ` T) = vs2.dim T"
  25.191 +     by (simp_all add: inj_on_def p1.linear_axioms pair1.dim_image_eq p2.linear_axioms pair2.dim_image_eq)
  25.192 +  moreover have "p.dim ((\<lambda>x. (x, 0)) ` S \<inter> Pair 0 ` T) = 0"
  25.193 +    by (subst p.dim_eq_0) auto
  25.194 +  ultimately show ?thesis
  25.195 +    using p.dim_sums_Int [OF ss] by linarith
  25.196 +qed
  25.197 +
  25.198 +lemma dimension_pair: "p.dimension = vs1.dimension + vs2.dimension"
  25.199 +  using dim_Times[OF vs1.subspace_UNIV vs2.subspace_UNIV]
  25.200 +  by (auto simp: p.dim_UNIV vs1.dim_UNIV vs2.dim_UNIV
  25.201 +      p.dimension_def vs1.dimension_def vs2.dimension_def)
  25.202 +
  25.203  end
  25.204 +
  25.205 +end
    26.1 --- a/src/HOL/Analysis/Sigma_Algebra.thy	Wed Apr 18 21:12:50 2018 +0100
    26.2 +++ b/src/HOL/Analysis/Sigma_Algebra.thy	Wed May 02 13:49:38 2018 +0200
    26.3 @@ -11,7 +11,6 @@
    26.4  imports
    26.5    Complex_Main
    26.6    "HOL-Library.Countable_Set"
    26.7 -  "HOL-Library.FuncSet"
    26.8    "HOL-Library.Indicator_Function"
    26.9    "HOL-Library.Extended_Nonnegative_Real"
   26.10    "HOL-Library.Disjoint_Sets"
    27.1 --- a/src/HOL/Analysis/Starlike.thy	Wed Apr 18 21:12:50 2018 +0100
    27.2 +++ b/src/HOL/Analysis/Starlike.thy	Wed May 02 13:49:38 2018 +0200
    27.3 @@ -10,7 +10,6 @@
    27.4  
    27.5  theory Starlike
    27.6    imports Convex_Euclidean_Space
    27.7 -
    27.8  begin
    27.9  
   27.10  subsection \<open>Midpoint\<close>
   27.11 @@ -108,8 +107,12 @@
   27.12    using less_eq_real_def by (auto simp: segment algebra_simps)
   27.13  
   27.14  lemma closed_segment_linear_image:
   27.15 -    "linear f \<Longrightarrow> closed_segment (f a) (f b) = f ` (closed_segment a b)"
   27.16 -  by (force simp add: in_segment linear_add_cmul)
   27.17 +  "closed_segment (f a) (f b) = f ` (closed_segment a b)" if "linear f"
   27.18 +proof -
   27.19 +  interpret linear f by fact
   27.20 +  show ?thesis
   27.21 +    by (force simp add: in_segment add scale)
   27.22 +qed
   27.23  
   27.24  lemma open_segment_linear_image:
   27.25      "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> open_segment (f a) (f b) = f ` (open_segment a b)"
   27.26 @@ -1680,9 +1683,9 @@
   27.27          fix x :: "'a::euclidean_space"
   27.28          assume "x \<in> d"
   27.29          then have "x \<in> span d"
   27.30 -          using span_superset[of _ "d"] by auto
   27.31 +          using span_base[of _ "d"] by auto
   27.32          then have "x /\<^sub>R (2 * real (card d)) \<in> span d"
   27.33 -          using span_mul[of x "d" "(inverse (real (card d)) / 2)"] by auto
   27.34 +          using span_scale[of x "d" "(inverse (real (card d)) / 2)"] by auto
   27.35        }
   27.36        then show "\<And>x. x\<in>d \<Longrightarrow> x /\<^sub>R (2 * real (card d)) \<in> span d"
   27.37          by auto
   27.38 @@ -1705,22 +1708,26 @@
   27.39    then show ?thesis using rel_interior_sing by auto
   27.40  next
   27.41    case False
   27.42 -  obtain B where B: "independent B \<and> B \<le> S \<and> S \<le> span B \<and> card B = dim S"
   27.43 +  obtain B where B: "independent B \<and> B \<le> S \<and> S \<le> span B \<and>
   27.44 +  card B = dim S"
   27.45      using basis_exists[of S] by auto
   27.46    then have "B \<noteq> {}"
   27.47      using B assms \<open>S \<noteq> {0}\<close> span_empty by auto
   27.48    have "insert 0 B \<le> span B"
   27.49 -    using subspace_span[of B] subspace_0[of "span B"] span_inc by auto
   27.50 +    using subspace_span[of B] subspace_0[of "span B"]
   27.51 +      span_superset by auto
   27.52    then have "span (insert 0 B) \<le> span B"
   27.53      using span_span[of B] span_mono[of "insert 0 B" "span B"] by blast
   27.54    then have "convex hull insert 0 B \<le> span B"
   27.55      using convex_hull_subset_span[of "insert 0 B"] by auto
   27.56    then have "span (convex hull insert 0 B) \<le> span B"
   27.57 -    using span_span[of B] span_mono[of "convex hull insert 0 B" "span B"] by blast
   27.58 +    using span_span[of B]
   27.59 +      span_mono[of "convex hull insert 0 B" "span B"] by blast
   27.60    then have *: "span (convex hull insert 0 B) = span B"
   27.61      using span_mono[of B "convex hull insert 0 B"] hull_subset[of "insert 0 B"] by auto
   27.62    then have "span (convex hull insert 0 B) = span S"
   27.63 -    using B span_mono[of B S] span_mono[of S "span B"] span_span[of B] by auto
   27.64 +    using B span_mono[of B S] span_mono[of S "span B"]
   27.65 +      span_span[of B] by auto
   27.66    moreover have "0 \<in> affine hull (convex hull insert 0 B)"
   27.67      using hull_subset[of "convex hull insert 0 B"] hull_subset[of "insert 0 B"] by auto
   27.68    ultimately have **: "affine hull (convex hull insert 0 B) = affine hull S"
   27.69 @@ -1787,8 +1794,8 @@
   27.70    obtains a where "a \<in> interior (convex hull (insert 0 S))"
   27.71  proof -
   27.72    have "affine hull (insert 0 S) = UNIV"
   27.73 -    apply (simp add: hull_inc affine_hull_span_0)
   27.74 -    using assms dim_eq_full indep_card_eq_dim_span by fastforce
   27.75 +    by (simp add: hull_inc affine_hull_span_0 dim_eq_full[symmetric]
   27.76 +         assms(1) assms(3) dim_eq_card_independent)
   27.77    moreover have "rel_interior (convex hull insert 0 S) \<noteq> {}"
   27.78      using rel_interior_eq_empty [of "convex hull (insert 0 S)"] by auto
   27.79    ultimately have "interior (convex hull insert 0 S) \<noteq> {}"
   27.80 @@ -2815,6 +2822,7 @@
   27.81      using assms rel_interior_empty rel_interior_eq_empty by auto
   27.82  next
   27.83    case False
   27.84 +  interpret linear f by fact
   27.85    have *: "f ` (rel_interior S) \<subseteq> f ` S"
   27.86      unfolding image_mono using rel_interior_subset by auto
   27.87    have "f ` S \<subseteq> f ` (closure S)"
   27.88 @@ -2847,15 +2855,15 @@
   27.89        then obtain e where e: "e > 1" "(1 - e) *\<^sub>R x1 + e *\<^sub>R z1 \<in> S"
   27.90          using convex_rel_interior_iff[of S z1] \<open>convex S\<close> x1 z1 by auto
   27.91        moreover have "f ((1 - e) *\<^sub>R x1 + e *\<^sub>R z1) = (1 - e) *\<^sub>R x + e *\<^sub>R z"
   27.92 -        using x1 z1 \<open>linear f\<close> by (simp add: linear_add_cmul)
   27.93 +        using x1 z1 by (simp add: linear_add linear_scale \<open>linear f\<close>)
   27.94        ultimately have "(1 - e) *\<^sub>R x + e *\<^sub>R z \<in> f ` S"
   27.95          using imageI[of "(1 - e) *\<^sub>R x1 + e *\<^sub>R z1" S f] by auto
   27.96        then have "\<exists>e. e > 1 \<and> (1 - e) *\<^sub>R x + e *\<^sub>R z \<in> f ` S"
   27.97          using e by auto
   27.98      }
   27.99      then have "z \<in> rel_interior (f ` S)"
  27.100 -      using convex_rel_interior_iff[of "f ` S" z] \<open>convex S\<close>
  27.101 -        \<open>linear f\<close> \<open>S \<noteq> {}\<close> convex_linear_image[of f S]  linear_conv_bounded_linear[of f]
  27.102 +      using convex_rel_interior_iff[of "f ` S" z] \<open>convex S\<close> \<open>linear f\<close>
  27.103 +        \<open>S \<noteq> {}\<close> convex_linear_image[of f S]  linear_conv_bounded_linear[of f]
  27.104        by auto
  27.105    }
  27.106    ultimately show ?thesis by auto
  27.107 @@ -2868,6 +2876,7 @@
  27.108      and "f -` (rel_interior S) \<noteq> {}"
  27.109    shows "rel_interior (f -` S) = f -` (rel_interior S)"
  27.110  proof -
  27.111 +  interpret linear f by fact
  27.112    have "S \<noteq> {}"
  27.113      using assms rel_interior_empty by auto
  27.114    have nonemp: "f -` S \<noteq> {}"
  27.115 @@ -2877,7 +2886,7 @@
  27.116    have conv: "convex (f -` S)"
  27.117      using convex_linear_vimage assms by auto
  27.118    then have "convex (S \<inter> range f)"
  27.119 -    by (metis assms(1) assms(2) convex_Int subspace_UNIV subspace_imp_convex subspace_linear_image)
  27.120 +    by (simp add: assms(2) convex_Int convex_linear_image linear_axioms)
  27.121    {
  27.122      fix z
  27.123      assume "z \<in> f -` (rel_interior S)"
  27.124 @@ -2917,7 +2926,7 @@
  27.125          convex_rel_interior_iff[of "S \<inter> (range f)" "f z"]
  27.126        by auto
  27.127      moreover have "affine (range f)"
  27.128 -      by (metis assms(1) subspace_UNIV subspace_imp_affine subspace_linear_image)
  27.129 +      by (simp add: linear_axioms linear_subspace_image subspace_imp_affine)
  27.130      ultimately have "f z \<in> rel_interior S"
  27.131        using convex_affine_rel_interior_Int[of S "range f"] assms by auto
  27.132      then have "z \<in> f -` (rel_interior S)"
  27.133 @@ -3888,9 +3897,7 @@
  27.134    apply (induct s rule: finite_induct)
  27.135    apply (simp_all add:  affine_dependent_iff_dependent affine_hull_insert_span_gen interior_translation)
  27.136    apply (rule empty_interior_lowdim)
  27.137 -  apply (simp add: affine_dependent_iff_dependent affine_hull_insert_span_gen)
  27.138 -  apply (metis Suc_le_lessD not_less order_trans card_image_le finite_imageI dim_le_card)
  27.139 -  done
  27.140 +  by (auto simp: Suc_le_lessD card_image_le dual_order.trans intro!: dim_le_card'[THEN le_less_trans])
  27.141  
  27.142  lemma empty_interior_convex_hull:
  27.143    fixes s :: "'a::euclidean_space set"
  27.144 @@ -5641,7 +5648,7 @@
  27.145        by (simp add: algebra_simps)
  27.146      have "inverse k *\<^sub>R k *\<^sub>R (x-a) \<in> span ((\<lambda>x. x - a) ` (S \<inter> T))"
  27.147        apply (rule span_mul)
  27.148 -      apply (rule span_superset)
  27.149 +      apply (rule span_base)
  27.150        apply (rule image_eqI [where x = "a + k *\<^sub>R (x - a)"])
  27.151        apply (auto simp: S T)
  27.152        done
  27.153 @@ -5799,7 +5806,7 @@
  27.154        by (auto simp: sum.remove [of _ k] inner_commute assms that)
  27.155      finally have "x = (\<Sum>b\<in>Basis - {k}. (x \<bullet> b) *\<^sub>R b)" .
  27.156      then show ?thesis
  27.157 -      by (simp add: Linear_Algebra.span_finite) metis
  27.158 +      by (simp add: span_finite)
  27.159    qed
  27.160    show ?thesis
  27.161      apply (rule span_subspace [symmetric])
  27.162 @@ -5811,11 +5818,11 @@
  27.163  lemma dim_special_hyperplane:
  27.164    fixes k :: "'n::euclidean_space"
  27.165    shows "k \<in> Basis \<Longrightarrow> dim {x. k \<bullet> x = 0} = DIM('n) - 1"
  27.166 -apply (simp add: special_hyperplane_span)
  27.167 -apply (rule Linear_Algebra.dim_unique [OF subset_refl])
  27.168 -apply (auto simp: Diff_subset independent_substdbasis)
  27.169 -apply (metis member_remove remove_def span_clauses(1))
  27.170 -done
  27.171 +  apply (simp add: special_hyperplane_span)
  27.172 +  apply (rule dim_unique [OF order_refl])
  27.173 +    apply (auto simp: Diff_subset independent_substdbasis)
  27.174 +  apply (metis member_remove remove_def span_clauses(1))
  27.175 +  done
  27.176  
  27.177  proposition dim_hyperplane:
  27.178    fixes a :: "'a::euclidean_space"
  27.179 @@ -5831,7 +5838,7 @@
  27.180                and ortho: "pairwise orthogonal B"
  27.181      using orthogonal_basis_exists by metis
  27.182    with assms have "a \<notin> span B"
  27.183 -    by (metis (mono_tags, lifting) span_eq inner_eq_zero_iff mem_Collect_eq span0 span_subspace)
  27.184 +    by (metis (mono_tags, lifting) span_eq inner_eq_zero_iff mem_Collect_eq span0)
  27.185    then have ind: "independent (insert a B)"
  27.186      by (simp add: \<open>independent B\<close> independent_insert)
  27.187    have "finite B"
  27.188 @@ -5843,13 +5850,15 @@
  27.189        using assms
  27.190        by (auto simp: algebra_simps)
  27.191      show "y \<in> span (insert a B)"
  27.192 -      by (metis (mono_tags, lifting) z Bsub Convex_Euclidean_Space.span_eq
  27.193 +      by (metis (mono_tags, lifting) z Bsub span_eq_iff
  27.194           add_diff_cancel_left' mem_Collect_eq span0 span_breakdown_eq span_subspace subspB)
  27.195    qed
  27.196    then have dima: "DIM('a) = dim(insert a B)"
  27.197 -    by (metis antisym dim_UNIV dim_subset_UNIV subset_le_dim)
  27.198 +    by (metis independent_Basis span_Basis dim_eq_card top.extremum_uniqueI)
  27.199    then show ?thesis
  27.200 -    by (metis (mono_tags, lifting) Bsub Diff_insert_absorb \<open>a \<notin> span B\<close> ind card0 card_Diff_singleton dim_span indep_card_eq_dim_span insertI1 subsetCE subspB)
  27.201 +    by (metis (mono_tags, lifting) Bsub Diff_insert_absorb \<open>a \<notin> span B\<close> ind card0
  27.202 +        card_Diff_singleton dim_span indep_card_eq_dim_span insertI1 subsetCE
  27.203 +        subspB)
  27.204  qed
  27.205  
  27.206  lemma lowdim_eq_hyperplane:
  27.207 @@ -5857,13 +5866,15 @@
  27.208    assumes "dim S = DIM('a) - 1"
  27.209    obtains a where "a \<noteq> 0" and "span S = {x. a \<bullet> x = 0}"
  27.210  proof -
  27.211 -  have [simp]: "dim S < DIM('a)"
  27.212 -    by (simp add: DIM_positive assms)
  27.213 +  have dimS: "dim S < DIM('a)"
  27.214 +    by (simp add: assms)
  27.215    then obtain b where b: "b \<noteq> 0" "span S \<subseteq> {a. b \<bullet> a = 0}"
  27.216      using lowdim_subset_hyperplane [of S] by fastforce
  27.217    show ?thesis
  27.218 -    using b that real_vector_class.subspace_span [of S]
  27.219 -    by (simp add: assms dim_hyperplane subspace_dim_equal subspace_hyperplane)
  27.220 +    apply (rule that[OF b(1)])
  27.221 +    apply (rule subspace_dim_equal)
  27.222 +    by (auto simp: assms b dim_hyperplane dim_span subspace_hyperplane
  27.223 +        subspace_span)
  27.224  qed
  27.225  
  27.226  lemma dim_eq_hyperplane:
  27.227 @@ -5927,47 +5938,6 @@
  27.228  
  27.229  subsection%unimportant\<open>Some stepping theorems\<close>
  27.230  
  27.231 -lemma dim_empty [simp]: "dim ({} :: 'a::euclidean_space set) = 0"
  27.232 -  by (force intro!: dim_unique)
  27.233 -
  27.234 -lemma dim_insert:
  27.235 -  fixes x :: "'a::euclidean_space"
  27.236 -  shows "dim (insert x S) = (if x \<in> span S then dim S else dim S + 1)"
  27.237 -proof -
  27.238 -  show ?thesis
  27.239 -  proof (cases "x \<in> span S")
  27.240 -    case True then show ?thesis
  27.241 -      by (metis dim_span span_redundant)
  27.242 -  next
  27.243 -    case False
  27.244 -    obtain B where B: "B \<subseteq> span S" "independent B" "span S \<subseteq> span B" "card B = dim (span S)"
  27.245 -      using basis_exists [of "span S"] by blast
  27.246 -    have 1: "insert x B \<subseteq> span (insert x S)"
  27.247 -      by (meson \<open>B \<subseteq> span S\<close> dual_order.trans insertI1 insert_subsetI span_mono span_superset subset_insertI)
  27.248 -    have 2: "span (insert x S) \<subseteq> span (insert x B)"
  27.249 -      by (metis \<open>B \<subseteq> span S\<close> \<open>span S \<subseteq> span B\<close> span_breakdown_eq span_subspace subsetI subspace_span)
  27.250 -    have 3: "independent (insert x B)"
  27.251 -      by (metis B independent_insert span_subspace subspace_span False)
  27.252 -    have "dim (span (insert x S)) = Suc (dim S)"
  27.253 -      apply (rule dim_unique [OF 1 2 3])
  27.254 -      by (metis B False card_insert_disjoint dim_span independent_imp_finite subsetCE)
  27.255 -    then show ?thesis
  27.256 -      by (simp add: False)
  27.257 -  qed
  27.258 -qed
  27.259 -
  27.260 -lemma dim_singleton [simp]:
  27.261 -  fixes x :: "'a::euclidean_space"
  27.262 -  shows "dim{x} = (if x = 0 then 0 else 1)"
  27.263 -by (simp add: dim_insert)
  27.264 -
  27.265 -lemma dim_eq_0 [simp]:
  27.266 -  fixes S :: "'a::euclidean_space set"
  27.267 -  shows "dim S = 0 \<longleftrightarrow> S \<subseteq> {0}"
  27.268 -apply safe
  27.269 -apply (metis DIM_positive DIM_real card_ge_dim_independent contra_subsetD dim_empty dim_insert dim_singleton empty_subsetI independent_empty less_not_refl zero_le)
  27.270 -by (metis dim_singleton dim_subset le_0_eq)
  27.271 -                  
  27.272  lemma aff_dim_insert:
  27.273    fixes a :: "'a::euclidean_space"
  27.274    shows "aff_dim (insert a S) = (if a \<in> affine hull S then aff_dim S else aff_dim S + 1)"
  27.275 @@ -5981,9 +5951,7 @@
  27.276    show ?thesis using S
  27.277      apply (simp add: hull_redundant cong: aff_dim_affine_hull2)
  27.278      apply (simp add: affine_hull_insert_span_gen hull_inc)
  27.279 -    apply (simp add: insert_commute [of a] hull_inc aff_dim_eq_dim [of x] dim_insert)
  27.280 -    apply (metis (no_types, lifting) add_minus_cancel image_iff uminus_add_conv_diff)
  27.281 -    done
  27.282 +    by (force simp add:span_zero insert_commute [of a] hull_inc aff_dim_eq_dim [of x] dim_insert)
  27.283  qed
  27.284  
  27.285  lemma affine_dependent_choose:
  27.286 @@ -6147,7 +6115,7 @@
  27.287      then have "norm (a /\<^sub>R (norm a)) = 1"
  27.288        by simp
  27.289      moreover have "a /\<^sub>R (norm a) \<in> span S"
  27.290 -      by (simp add: \<open>a \<in> S\<close> span_mul span_superset)
  27.291 +      by (simp add: \<open>a \<in> S\<close> span_scale span_base)
  27.292      ultimately have ass: "a /\<^sub>R (norm a) \<in> span S \<inter> sphere 0 1"
  27.293        by simp
  27.294      show ?thesis
  27.295 @@ -6171,7 +6139,7 @@
  27.296        moreover have "norm (a /\<^sub>R (norm a)) = 1"
  27.297          using \<open>a \<noteq> 0\<close> by simp
  27.298        moreover have "a /\<^sub>R (norm a) \<in> span S"
  27.299 -        by (simp add: \<open>a \<in> S\<close> span_mul span_superset)
  27.300 +        by (simp add: \<open>a \<in> S\<close> span_scale span_base)
  27.301        ultimately have ass: "a /\<^sub>R (norm a) \<in> span S \<inter> sphere 0 1"
  27.302          by simp
  27.303        have aa: "a /\<^sub>R (norm a) \<in> (\<Inter>c\<in>C. {x. 0 \<le> c \<bullet> x})"
  27.304 @@ -6636,41 +6604,6 @@
  27.305    qed
  27.306  qed
  27.307  
  27.308 -subsection%unimportant\<open>Misc results about span\<close>
  27.309 -
  27.310 -lemma eq_span_insert_eq:
  27.311 -  assumes "(x - y) \<in> span S"
  27.312 -    shows "span(insert x S) = span(insert y S)"
  27.313 -proof -
  27.314 -  have *: "span(insert x S) \<subseteq> span(insert y S)" if "(x - y) \<in> span S" for x y
  27.315 -  proof -
  27.316 -    have 1: "(r *\<^sub>R x - r *\<^sub>R y) \<in> span S" for r
  27.317 -      by (metis real_vector.scale_right_diff_distrib span_mul that)
  27.318 -    have 2: "(z - k *\<^sub>R y) - k *\<^sub>R (x - y) = z - k *\<^sub>R x" for  z k
  27.319 -      by (simp add: real_vector.scale_right_diff_distrib)
  27.320 -  show ?thesis
  27.321 -    apply (clarsimp simp add: span_breakdown_eq)
  27.322 -    by (metis 1 2 diff_add_cancel real_vector.scale_right_diff_distrib span_add_eq)
  27.323 -  qed
  27.324 -  show ?thesis
  27.325 -    apply (intro subset_antisym * assms)
  27.326 -    using assms subspace_neg subspace_span minus_diff_eq by force
  27.327 -qed
  27.328 -
  27.329 -lemma dim_psubset:
  27.330 -    fixes S :: "'a :: euclidean_space set"
  27.331 -    shows "span S \<subset> span T \<Longrightarrow> dim S < dim T"
  27.332 -by (metis (no_types, hide_lams) dim_span less_le not_le subspace_dim_equal subspace_span)
  27.333 -
  27.334 -
  27.335 -lemma basis_subspace_exists:
  27.336 -  fixes S :: "'a::euclidean_space set"
  27.337 -  shows
  27.338 -   "subspace S
  27.339 -        \<Longrightarrow> \<exists>b. finite b \<and> b \<subseteq> S \<and>
  27.340 -                independent b \<and> span b = S \<and> card b = dim S"
  27.341 -by (metis span_subspace basis_exists independent_imp_finite)
  27.342 -
  27.343  lemma affine_hyperplane_sums_eq_UNIV_0:
  27.344    fixes S :: "'a :: euclidean_space set"
  27.345    assumes "affine S"
  27.346 @@ -6687,7 +6620,7 @@
  27.347      using \<open>a \<bullet> w \<noteq> 0\<close> span_induct subspace_hyperplane by auto
  27.348    moreover have "w \<in> span {x + y |x y. x \<in> S \<and> a \<bullet> y = 0}"
  27.349      using \<open>w \<in> S\<close>
  27.350 -    by (metis (mono_tags, lifting) inner_zero_right mem_Collect_eq pth_d span_superset)
  27.351 +    by (metis (mono_tags, lifting) inner_zero_right mem_Collect_eq pth_d span_base)
  27.352    ultimately have span2: "span {y. a \<bullet> y = 0} \<noteq> span {x + y |x y. x \<in> S \<and> a \<bullet> y = 0}"
  27.353      by blast
  27.354    have "a \<noteq> 0" using assms inner_zero_left by blast
  27.355 @@ -6704,7 +6637,7 @@
  27.356      using DIM_lt apply simp
  27.357      done
  27.358    ultimately show ?thesis
  27.359 -    by (simp add: subs) (metis (lifting) span_eq subs)
  27.360 +    by (simp add: subs) (metis (lifting) span_eq_iff subs)
  27.361  qed
  27.362  
  27.363  proposition affine_hyperplane_sums_eq_UNIV:
  27.364 @@ -6751,108 +6684,6 @@
  27.365    finally show ?thesis .
  27.366  qed
  27.367  
  27.368 -proposition dim_sums_Int:
  27.369 -    fixes S :: "'a :: euclidean_space set"
  27.370 -  assumes "subspace S" "subspace T"
  27.371 -  shows "dim {x + y |x y. x \<in> S \<and> y \<in> T} + dim(S \<inter> T) = dim S + dim T"
  27.372 -proof -
  27.373 -  obtain B where B: "B \<subseteq> S \<inter> T" "S \<inter> T \<subseteq> span B"
  27.374 -             and indB: "independent B"
  27.375 -             and cardB: "card B = dim (S \<inter> T)"
  27.376 -    using basis_exists by blast
  27.377 -  then obtain C D where "B \<subseteq> C" "C \<subseteq> S" "independent C" "S \<subseteq> span C"
  27.378 -                    and "B \<subseteq> D" "D \<subseteq> T" "independent D" "T \<subseteq> span D"
  27.379 -    using maximal_independent_subset_extend
  27.380 -    by (metis Int_subset_iff \<open>B \<subseteq> S \<inter> T\<close> indB)
  27.381 -  then have "finite B" "finite C" "finite D"
  27.382 -    by (simp_all add: independent_imp_finite indB independent_bound)
  27.383 -  have Beq: "B = C \<inter> D"
  27.384 -    apply (rule sym)
  27.385 -    apply (rule spanning_subset_independent)
  27.386 -    using \<open>B \<subseteq> C\<close> \<open>B \<subseteq> D\<close> apply blast
  27.387 -    apply (meson \<open>independent C\<close> independent_mono inf.cobounded1)
  27.388 -    using B \<open>C \<subseteq> S\<close> \<open>D \<subseteq> T\<close> apply auto
  27.389 -    done
  27.390 -  then have Deq: "D = B \<union> (D - C)"
  27.391 -    by blast
  27.392 -  have CUD: "C \<union> D \<subseteq> {x + y |x y. x \<in> S \<and> y \<in> T}"
  27.393 -    apply safe
  27.394 -    apply (metis add.right_neutral subsetCE \<open>C \<subseteq> S\<close> \<open>subspace T\<close> set_eq_subset span_0 span_minimal)
  27.395 -    apply (metis add.left_neutral subsetCE \<open>D \<subseteq> T\<close> \<open>subspace S\<close> set_eq_subset span_0 span_minimal)
  27.396 -    done
  27.397 -  have "a v = 0" if 0: "(\<Sum>v\<in>C. a v *\<^sub>R v) + (\<Sum>v\<in>D - C. a v *\<^sub>R v) = 0"
  27.398 -                 and v: "v \<in> C \<union> (D-C)" for a v
  27.399 -  proof -
  27.400 -    have eq: "(\<Sum>v\<in>D - C. a v *\<^sub>R v) = - (\<Sum>v\<in>C. a v *\<^sub>R v)"
  27.401 -      using that add_eq_0_iff by blast
  27.402 -    have "(\<Sum>v\<in>D - C. a v *\<^sub>R v) \<in> S"
  27.403 -      apply (subst eq)
  27.404 -      apply (rule subspace_neg [OF \<open>subspace S\<close>])
  27.405 -      apply (rule subspace_sum [OF \<open>subspace S\<close>])
  27.406 -      by (meson subsetCE subspace_mul \<open>C \<subseteq> S\<close> \<open>subspace S\<close>)
  27.407 -    moreover have "(\<Sum>v\<in>D - C. a v *\<^sub>R v) \<in> T"
  27.408 -      apply (rule subspace_sum [OF \<open>subspace T\<close>])
  27.409 -      by (meson DiffD1 \<open>D \<subseteq> T\<close> \<open>subspace T\<close> subset_eq subspace_def)
  27.410 -    ultimately have "(\<Sum>v \<in> D-C. a v *\<^sub>R v) \<in> span B"
  27.411 -      using B by blast
  27.412 -    then obtain e where e: "(\<Sum>v\<in>B. e v *\<^sub>R v) = (\<Sum>v \<in> D-C. a v *\<^sub>R v)"
  27.413 -      using span_finite [OF \<open>finite B\<close>] by blast
  27.414 -    have "\<And>c v. \<lbrakk>(\<Sum>v\<in>C. c v *\<^sub>R v) = 0; v \<in> C\<rbrakk> \<Longrightarrow> c v = 0"
  27.415 -      using independent_explicit \<open>independent C\<close> by blast
  27.416 -    define cc where "cc x = (if x \<in> B then a x + e x else a x)" for x
  27.417 -    have [simp]: "C \<inter> B = B" "D \<inter> B = B" "C \<inter> - B = C-D" "B \<inter> (D - C) = {}"
  27.418 -      using \<open>B \<subseteq> C\<close> \<open>B \<subseteq> D\<close> Beq by blast+
  27.419 -    have f2: "(\<Sum>v\<in>C \<inter> D. e v *\<^sub>R v) = (\<Sum>v\<in>D - C. a v *\<^sub>R v)"
  27.420 -      using Beq e by presburger
  27.421 -    have f3: "(\<Sum>v\<in>C \<union> D. a v *\<^sub>R v) = (\<Sum>v\<in>C - D. a v *\<^sub>R v) + (\<Sum>v\<in>D - C. a v *\<^sub>R v) + (\<Sum>v\<in>C \<inter> D. a v *\<^sub>R v)"
  27.422 -      using \<open>finite C\<close> \<open>finite D\<close> sum.union_diff2 by blast
  27.423 -    have f4: "(\<Sum>v\<in>C \<union> (D - C). a v *\<^sub>R v) = (\<Sum>v\<in>C. a v *\<^sub>R v) + (\<Sum>v\<in>D - C. a v *\<^sub>R v)"
  27.424 -      by (meson Diff_disjoint \<open>finite C\<close> \<open>finite D\<close> finite_Diff sum.union_disjoint)
  27.425 -    have "(\<Sum>v\<in>C. cc v *\<^sub>R v) = 0"
  27.426 -      using 0 f2 f3 f4
  27.427 -      apply (simp add: cc_def Beq if_smult \<open>finite C\<close> sum.If_cases algebra_simps sum.distrib)
  27.428 -      apply (simp add: add.commute add.left_commute diff_eq)
  27.429 -      done
  27.430 -    then have "\<And>v. v \<in> C \<Longrightarrow> cc v = 0"
  27.431 -      using independent_explicit \<open>independent C\<close> by blast
  27.432 -    then have C0: "\<And>v. v \<in> C - B \<Longrightarrow> a v = 0"
  27.433 -      by (simp add: cc_def Beq) meson
  27.434 -    then have [simp]: "(\<Sum>x\<in>C - B. a x *\<^sub>R x) = 0"
  27.435 -      by simp
  27.436 -    have "(\<Sum>x\<in>C. a x *\<^sub>R x) = (\<Sum>x\<in>B. a x *\<^sub>R x)"
  27.437 -    proof -
  27.438 -      have "C - D = C - B"
  27.439 -        using Beq by blast
  27.440 -      then show ?thesis
  27.441 -        using Beq \<open>(\<Sum>x\<in>C - B. a x *\<^sub>R x) = 0\<close> f3 f4 by auto
  27.442 -    qed
  27.443 -    with 0 have Dcc0: "(\<Sum>v\<in>D. a v *\<^sub>R v) = 0"
  27.444 -      apply (subst Deq)
  27.445 -      by (simp add: \<open>finite B\<close> \<open>finite D\<close> sum_Un)
  27.446 -    then have D0: "\<And>v. v \<in> D \<Longrightarrow> a v = 0"
  27.447 -      using independent_explicit \<open>independent D\<close> by blast
  27.448 -    show ?thesis
  27.449 -      using v C0 D0 Beq by blast
  27.450 -  qed
  27.451 -  then have "independent (C \<union> (D - C))"
  27.452 -    by (simp add: independent_explicit \<open>finite C\<close> \<open>finite D\<close> sum_Un del: Un_Diff_cancel)
  27.453 -  then have indCUD: "independent (C \<union> D)" by simp
  27.454 -  have "dim (S \<inter> T) = card B"
  27.455 -    by (rule dim_unique [OF B indB refl])
  27.456 -  moreover have "dim S = card C"
  27.457 -    by (metis \<open>C \<subseteq> S\<close> \<open>independent C\<close> \<open>S \<subseteq> span C\<close> basis_card_eq_dim)
  27.458 -  moreover have "dim T = card D"
  27.459 -    by (metis \<open>D \<subseteq> T\<close> \<open>independent D\<close> \<open>T \<subseteq> span D\<close> basis_card_eq_dim)
  27.460 -  moreover have "dim {x + y |x y. x \<in> S \<and> y \<in> T} = card(C \<union> D)"
  27.461 -    apply (rule dim_unique [OF CUD _ indCUD refl], clarify)
  27.462 -    apply (meson \<open>S \<subseteq> span C\<close> \<open>T \<subseteq> span D\<close> span_add span_inc span_minimal subsetCE subspace_span sup.bounded_iff)
  27.463 -    done
  27.464 -  ultimately show ?thesis
  27.465 -    using \<open>B = C \<inter> D\<close> [symmetric]
  27.466 -    by (simp add:  \<open>independent C\<close> \<open>independent D\<close> card_Un_Int independent_finite)
  27.467 -qed
  27.468 -
  27.469 -
  27.470  lemma aff_dim_sums_Int_0:
  27.471    assumes "affine S"
  27.472        and "affine T"
  27.473 @@ -6921,62 +6752,8 @@
  27.474  by (metis (no_types) aff_dim_affine_hull aff_dim_le_DIM aff_dim_UNIV affine_hull_UNIV less_le)
  27.475  
  27.476  
  27.477 -lemma dim_Times:
  27.478 -  fixes S :: "'a :: euclidean_space set" and T :: "'a set"
  27.479 -  assumes "subspace S" "subspace T"
  27.480 -  shows "dim(S \<times> T) = dim S + dim T"
  27.481 -proof -
  27.482 -  have ss: "subspace ((\<lambda>x. (x, 0)) ` S)" "subspace (Pair 0 ` T)"
  27.483 -    by (rule subspace_linear_image, unfold_locales, auto simp: assms)+
  27.484 -  have "dim(S \<times> T) = dim({u + v |u v. u \<in> (\<lambda>x. (x, 0)) ` S \<and> v \<in> Pair 0 ` T})"
  27.485 -    by (simp add: Times_eq_image_sum)
  27.486 -  moreover have "dim ((\<lambda>x. (x, 0::'a)) ` S) = dim S" "dim (Pair (0::'a) ` T) = dim T"
  27.487 -    by (auto simp: additive.intro linear.intro linear_axioms.intro inj_on_def intro: dim_image_eq)
  27.488 -  moreover have "dim ((\<lambda>x. (x, 0)) ` S \<inter> Pair 0 ` T) = 0"
  27.489 -    by (subst dim_eq_0) (force simp: zero_prod_def)
  27.490 -  ultimately show ?thesis
  27.491 -    using dim_sums_Int [OF ss] by linarith
  27.492 -qed
  27.493 -
  27.494  subsection\<open> Orthogonal bases, Gram-Schmidt process, and related theorems\<close>
  27.495  
  27.496 -lemma span_delete_0 [simp]: "span(S - {0}) = span S"
  27.497 -proof
  27.498 -  show "span (S - {0}) \<subseteq> span S"
  27.499 -    by (blast intro!: span_mono)
  27.500 -next
  27.501 -  have "span S \<subseteq> span(insert 0 (S - {0}))"
  27.502 -    by (blast intro!: span_mono)
  27.503 -  also have "... \<subseteq> span(S - {0})"
  27.504 -    using span_insert_0 by blast
  27.505 -  finally show "span S \<subseteq> span (S - {0})" .
  27.506 -qed
  27.507 -
  27.508 -lemma span_image_scale:
  27.509 -  assumes "finite S" and nz: "\<And>x. x \<in> S \<Longrightarrow> c x \<noteq> 0"
  27.510 -    shows "span ((\<lambda>x. c x *\<^sub>R x) ` S) = span S"
  27.511 -using assms
  27.512 -proof (induction S arbitrary: c)
  27.513 -  case (empty c) show ?case by simp
  27.514 -next
  27.515 -  case (insert x F c)
  27.516 -  show ?case
  27.517 -  proof (intro set_eqI iffI)
  27.518 -    fix y
  27.519 -      assume "y \<in> span ((\<lambda>x. c x *\<^sub>R x) ` insert x F)"
  27.520 -      then show "y \<in> span (insert x F)"
  27.521 -        using insert by (force simp: span_breakdown_eq)
  27.522 -  next
  27.523 -    fix y
  27.524 -      assume "y \<in> span (insert x F)"
  27.525 -      then show "y \<in> span ((\<lambda>x. c x *\<^sub>R x) ` insert x F)"
  27.526 -        using insert
  27.527 -        apply (clarsimp simp: span_breakdown_eq)
  27.528 -        apply (rule_tac x="k / c x" in exI)
  27.529 -        by simp
  27.530 -  qed
  27.531 -qed
  27.532 -
  27.533  lemma pairwise_orthogonal_independent:
  27.534    assumes "pairwise orthogonal S" and "0 \<notin> S"
  27.535      shows "independent S"
  27.536 @@ -7022,9 +6799,8 @@
  27.537  lemma orthogonal_to_span:
  27.538    assumes a: "a \<in> span S" and x: "\<And>y. y \<in> S \<Longrightarrow> orthogonal x y"
  27.539      shows "orthogonal x a"
  27.540 -apply (rule span_induct [OF a subspace_orthogonal_to_vector])
  27.541 -apply (simp add: x)
  27.542 -done
  27.543 +  by (metis a orthogonal_clauses(1,2,4)
  27.544 +      span_induct_alt x)
  27.545  
  27.546  proposition%important Gram_Schmidt_step:
  27.547    fixes S :: "'a::euclidean_space set"
  27.548 @@ -7064,19 +6840,20 @@
  27.549    define a' where "a' = a - (\<Sum>b\<in>S. (b \<bullet> a / (b \<bullet> b)) *\<^sub>R b)"
  27.550    obtain U where orthU: "pairwise orthogonal (S \<union> insert a' U)"
  27.551               and spanU: "span (insert a' S \<union> U) = span (insert a' S \<union> T)"
  27.552 -    apply (rule exE [OF insert.IH [of "insert a' S"]])
  27.553 -    apply (auto simp: Gram_Schmidt_step a'_def insert.prems orthogonal_commute pairwise_orthogonal_insert span_clauses)
  27.554 -    done
  27.555 +    by (rule exE [OF insert.IH [of "insert a' S"]])
  27.556 +      (auto simp: Gram_Schmidt_step a'_def insert.prems orthogonal_commute
  27.557 +        pairwise_orthogonal_insert span_clauses)
  27.558    have orthS: "\<And>x. x \<in> S \<Longrightarrow> a' \<bullet> x = 0"
  27.559      apply (simp add: a'_def)
  27.560      using Gram_Schmidt_step [OF \<open>pairwise orthogonal S\<close>]
  27.561 -    apply (force simp: orthogonal_def inner_commute span_inc [THEN subsetD])
  27.562 +    apply (force simp: orthogonal_def inner_commute span_superset [THEN subsetD])
  27.563      done
  27.564    have "span (S \<union> insert a' U) = span (insert a' (S \<union> T))"
  27.565      using spanU by simp
  27.566    also have "... = span (insert a (S \<union> T))"
  27.567      apply (rule eq_span_insert_eq)
  27.568 -    apply (simp add: a'_def span_neg span_sum span_clauses(1) span_mul)
  27.569 +    apply (simp add: a'_def span_neg span_sum span_clauses(1)
  27.570 +        span_scale)
  27.571      done
  27.572    also have "... = span (S \<union> insert a T)"
  27.573      by simp
  27.574 @@ -7097,17 +6874,15 @@
  27.575    with orthogonal_extension_aux [of B S]
  27.576    obtain U where "pairwise orthogonal (S \<union> U)" "span (S \<union> U) = span (S \<union> B)"
  27.577      using assms pairwise_orthogonal_imp_finite by auto
  27.578 -  show ?thesis
  27.579 -    apply (rule_tac U=U in that)
  27.580 -     apply (simp add: \<open>pairwise orthogonal (S \<union> U)\<close>)
  27.581 -    by (metis \<open>span (S \<union> U) = span (S \<union> B)\<close> \<open>span B = span T\<close> span_Un)
  27.582 +  with \<open>span B = span T\<close> show ?thesis
  27.583 +    by (rule_tac U=U in that) (auto simp: span_Un)
  27.584  qed
  27.585  
  27.586  corollary orthogonal_extension_strong:
  27.587    fixes S :: "'a::euclidean_space set"
  27.588    assumes S: "pairwise orthogonal S"
  27.589    obtains U where "U \<inter> (insert 0 S) = {}" "pairwise orthogonal (S \<union> U)"
  27.590 -                   "span (S \<union> U) = span (S \<union> T)"
  27.591 +                  "span (S \<union> U) = span (S \<union> T)"
  27.592  proof -
  27.593    obtain U where "pairwise orthogonal (S \<union> U)" "span (S \<union> U) = span (S \<union> T)"
  27.594      using orthogonal_extension assms by blast
  27.595 @@ -7115,8 +6890,8 @@
  27.596      apply (rule_tac U = "U - (insert 0 S)" in that)
  27.597        apply blast
  27.598       apply (force simp: pairwise_def)
  27.599 -    apply (metis (no_types, lifting) Un_Diff_cancel span_insert_0 span_Un)
  27.600 -  done
  27.601 +    apply (metis Un_Diff_cancel Un_insert_left span_redundant span_zero)
  27.602 +    done
  27.603  qed
  27.604  
  27.605  subsection\<open>Decomposing a vector into parts in orthogonal subspaces\<close>
  27.606 @@ -7132,7 +6907,7 @@
  27.607      using basis_exists by blast
  27.608    with orthogonal_extension [of "{}" B]
  27.609    show ?thesis
  27.610 -    by (metis Un_empty_left assms pairwise_empty span_inc span_subspace that)
  27.611 +    by (metis Un_empty_left assms pairwise_empty span_superset span_subspace that)
  27.612  qed
  27.613  
  27.614  lemma orthogonal_basis_subspace:
  27.615 @@ -7161,7 +6936,7 @@
  27.616               and "independent B" "card B = dim S" "span B = S"
  27.617      by (blast intro: orthogonal_basis_subspace [OF assms])
  27.618    have 1: "(\<lambda>x. x /\<^sub>R norm x) ` B \<subseteq> S"
  27.619 -    using \<open>span B = S\<close> span_clauses(1) span_mul by fastforce
  27.620 +    using \<open>span B = S\<close> span_clauses(1) span_scale by fastforce
  27.621    have 2: "pairwise orthogonal ((\<lambda>x. x /\<^sub>R norm x) ` B)"
  27.622      using orth by (force simp: pairwise_def orthogonal_clauses)
  27.623    have 3: "\<And>x. x \<in> (\<lambda>x. x /\<^sub>R norm x) ` B \<Longrightarrow> norm x = 1"
  27.624 @@ -7194,7 +6969,8 @@
  27.625    obtain B where "B \<subseteq> span S" and orthB: "pairwise orthogonal B"
  27.626               and "\<And>x. x \<in> B \<Longrightarrow> norm x = 1"
  27.627               and "independent B" "card B = dim S" "span B = span S"
  27.628 -    by (rule orthonormal_basis_subspace [of "span S"]) auto
  27.629 +    by (rule orthonormal_basis_subspace [of "span S", OF subspace_span])
  27.630 +      (auto simp: dim_span)
  27.631    with assms obtain u where spanBT: "span B \<subseteq> span T" and "u \<notin> span B" "u \<in> span T"
  27.632      by auto
  27.633    obtain C where orthBC: "pairwise orthogonal (B \<union> C)" and spanBC: "span (B \<union> C) = span (B \<union> {u})"
  27.634 @@ -7203,18 +6979,21 @@
  27.635    proof (cases "C \<subseteq> insert 0 B")
  27.636      case True
  27.637      then have "C \<subseteq> span B"
  27.638 -      using Linear_Algebra.span_eq
  27.639 +      using span_eq
  27.640        by (metis span_insert_0 subset_trans)
  27.641      moreover have "u \<in> span (B \<union> C)"
  27.642 -      using \<open>span (B \<union> C) = span (B \<union> {u})\<close> span_inc by force
  27.643 +      using \<open>span (B \<union> C) = span (B \<union> {u})\<close> span_superset by force
  27.644      ultimately show ?thesis
  27.645 -      by (metis \<open>u \<notin> span B\<close> span_Un span_span sup.orderE)
  27.646 +      using True \<open>u \<notin> span B\<close>
  27.647 +      by (metis Un_insert_left span_insert_0 sup.orderE)
  27.648    next
  27.649      case False
  27.650      then obtain x where "x \<in> C" "x \<noteq> 0" "x \<notin> B"
  27.651        by blast
  27.652      then have "x \<in> span T"
  27.653 -      by (metis (no_types, lifting) Un_insert_right Un_upper2 \<open>u \<in> span T\<close> spanBT spanBC \<open>u \<in> span T\<close> insert_subset span_inc span_mono span_span subsetCE subset_trans sup_bot.comm_neutral)
  27.654 +      by (metis (no_types, lifting) Un_insert_right Un_upper2 \<open>u \<in> span T\<close> spanBT spanBC
  27.655 +          \<open>u \<in> span T\<close> insert_subset span_superset span_mono
  27.656 +          span_span subsetCE subset_trans sup_bot.comm_neutral)
  27.657      moreover have "orthogonal x y" if "y \<in> span B" for y
  27.658        using that
  27.659      proof (rule span_induct)
  27.660 @@ -7234,8 +7013,10 @@
  27.661    obtains x where "x \<noteq> 0" "\<And>y. y \<in> span S \<Longrightarrow> orthogonal x y"
  27.662  proof -
  27.663  have "span S \<subset> UNIV"
  27.664 -  by (metis assms dim_eq_full less_irrefl top.not_eq_extremum)
  27.665 -  with orthogonal_to_subspace_exists_gen [of S UNIV] that show ?thesis by auto
  27.666 +  by (metis (mono_tags) UNIV_I assms inner_eq_zero_iff less_le lowdim_subset_hyperplane
  27.667 +      mem_Collect_eq top.extremum_strict top.not_eq_extremum)
  27.668 +  with orthogonal_to_subspace_exists_gen [of S UNIV] that show ?thesis
  27.669 +    by (auto simp: span_UNIV)
  27.670  qed
  27.671  
  27.672  corollary orthogonal_to_vector_exists:
  27.673 @@ -7253,14 +7034,16 @@
  27.674    fixes S :: "'a :: euclidean_space set"
  27.675    obtains y z where "y \<in> span S" "\<And>w. w \<in> span S \<Longrightarrow> orthogonal z w" "x = y + z"
  27.676  proof%unimportant -
  27.677 -  obtain T where "0 \<notin> T" "T \<subseteq> span S" "pairwise orthogonal T" "independent T" "card T = dim (span S)" "span T = span S"
  27.678 +  obtain T where "0 \<notin> T" "T \<subseteq> span S" "pairwise orthogonal T" "independent T"
  27.679 +    "card T = dim (span S)" "span T = span S"
  27.680      using orthogonal_basis_subspace subspace_span by blast
  27.681    let ?a = "\<Sum>b\<in>T. (b \<bullet> x / (b \<bullet> b)) *\<^sub>R b"
  27.682    have orth: "orthogonal (x - ?a) w" if "w \<in> span S" for w
  27.683 -    by (simp add: Gram_Schmidt_step \<open>pairwise orthogonal T\<close> \<open>span T = span S\<close> orthogonal_commute that)
  27.684 +    by (simp add: Gram_Schmidt_step \<open>pairwise orthogonal T\<close> \<open>span T = span S\<close>
  27.685 +        orthogonal_commute that)
  27.686    show ?thesis
  27.687      apply (rule_tac y = "?a" and z = "x - ?a" in that)
  27.688 -      apply (meson \<open>T \<subseteq> span S\<close> span_mul span_sum subsetCE)
  27.689 +      apply (meson \<open>T \<subseteq> span S\<close> span_scale span_sum subsetCE)
  27.690       apply (fact orth, simp)
  27.691      done
  27.692  qed
  27.693 @@ -7284,7 +7067,8 @@
  27.694  lemma vector_in_orthogonal_spanningset:
  27.695    fixes a :: "'a::euclidean_space"
  27.696    obtains S where "a \<in> S" "pairwise orthogonal S" "span S = UNIV"
  27.697 -  by (metis UNIV_I Un_iff empty_iff insert_subset orthogonal_extension pairwise_def pairwise_orthogonal_insert span_UNIV subsetI subset_antisym)
  27.698 +  by (metis UNIV_I Un_iff empty_iff insert_subset orthogonal_extension pairwise_def
  27.699 +      pairwise_orthogonal_insert span_UNIV subsetI subset_antisym)
  27.700  
  27.701  lemma vector_in_orthogonal_basis:
  27.702    fixes a :: "'a::euclidean_space"
  27.703 @@ -7304,7 +7088,7 @@
  27.704        using \<open>independent (S - {0})\<close> independent_finite by blast
  27.705      show "card (S - {0}) = DIM('a)"
  27.706        using span_delete_0 [of S] S
  27.707 -      by (simp add: \<open>independent (S - {0})\<close> indep_card_eq_dim_span)
  27.708 +      by (simp add: \<open>independent (S - {0})\<close> indep_card_eq_dim_span dim_UNIV)
  27.709    qed (use S \<open>a \<noteq> 0\<close> in auto)
  27.710  qed
  27.711  
  27.712 @@ -7337,7 +7121,9 @@
  27.713      then show "card ?S = DIM('a)"
  27.714        by (simp add: card_image S)
  27.715      show "span ?S = UNIV"
  27.716 -      by (metis (no_types) \<open>0 \<notin> S\<close> \<open>finite S\<close> \<open>span S = UNIV\<close> field_class.field_inverse_zero inverse_inverse_eq less_irrefl span_image_scale zero_less_norm_iff)
  27.717 +      by (metis (no_types) \<open>0 \<notin> S\<close> \<open>finite S\<close> \<open>span S = UNIV\<close>
  27.718 +          field_class.field_inverse_zero inverse_inverse_eq less_irrefl span_image_scale
  27.719 +          zero_less_norm_iff)
  27.720    qed
  27.721  qed
  27.722  
  27.723 @@ -7354,17 +7140,17 @@
  27.724    then have 0: "\<And>x y. \<lbrakk>x \<in> span A; y \<in> span B\<rbrakk> \<Longrightarrow> x \<bullet> y = 0"
  27.725      by simp
  27.726    have "dim(A \<union> B) = dim (span (A \<union> B))"
  27.727 -    by simp
  27.728 -  also have "... = dim ((\<lambda>(a, b). a + b) ` (span A \<times> span B))"
  27.729 -    by (simp add: span_Un)
  27.730 -  also have "... = dim {x + y |x y. x \<in> span A \<and> y \<in> span B}"
  27.731 +    by (simp add: dim_span)
  27.732 +  also have "span (A \<union> B) = ((\<lambda>(a, b). a + b) ` (span A \<times> span B))"
  27.733 +    by (auto simp add: span_Un image_def)
  27.734 +  also have "dim \<dots> = dim {x + y |x y. x \<in> span A \<and> y \<in> span B}"
  27.735      by (auto intro!: arg_cong [where f=dim])
  27.736    also have "... = dim {x + y |x y. x \<in> span A \<and> y \<in> span B} + dim(span A \<inter> span B)"
  27.737      by (auto simp: dest: 0)
  27.738    also have "... = dim (span A) + dim (span B)"
  27.739 -    by (rule dim_sums_Int) auto
  27.740 +    by (rule dim_sums_Int) (auto simp: subspace_span)
  27.741    also have "... = dim A + dim B"
  27.742 -    by simp
  27.743 +    by (simp add: dim_span)
  27.744    finally show ?thesis .
  27.745  qed
  27.746  
  27.747 @@ -7384,22 +7170,24 @@
  27.748        obtain y z where "x = y + z" "y \<in> span A" and orth: "\<And>w. w \<in> span A \<Longrightarrow> orthogonal z w"
  27.749          using orthogonal_subspace_decomp_exists [of A x] that by auto
  27.750        have "y \<in> span B"
  27.751 -        by (metis span_eq \<open>y \<in> span A\<close> assms subset_iff)
  27.752 +        using \<open>y \<in> span A\<close> assms(3) span_mono by blast
  27.753        then have "z \<in> {a \<in> B. \<forall>x. x \<in> A \<longrightarrow> orthogonal x a}"
  27.754 -        by simp (metis (no_types) span_eq \<open>x = y + z\<close> \<open>subspace A\<close> \<open>subspace B\<close> orth orthogonal_commute span_add_eq that)
  27.755 +        apply simp
  27.756 +        using \<open>x = y + z\<close> assms(1) assms(2) orth orthogonal_commute span_add_eq
  27.757 +          span_eq_iff that by blast
  27.758        then have z: "z \<in> span {y \<in> B. \<forall>x\<in>A. orthogonal x y}"
  27.759 -        by (meson span_inc subset_iff)
  27.760 +        by (meson span_superset subset_iff)
  27.761        then show ?thesis
  27.762 -        apply (simp add: span_Un image_def)
  27.763 -        apply (rule bexI [OF _ z])
  27.764 -        apply (simp add: \<open>x = y + z\<close> \<open>y \<in> span A\<close>)
  27.765 -        done
  27.766 +        apply (auto simp: span_Un image_def  \<open>x = y + z\<close> \<open>y \<in> span A\<close>)
  27.767 +        using \<open>y \<in> span A\<close> add.commute by blast
  27.768      qed
  27.769      show "span B \<subseteq> span ({y \<in> B. \<forall>x\<in>A. orthogonal x y} \<union> A)"
  27.770 -      by (rule span_minimal) (auto intro: * span_minimal elim: )
  27.771 +      by (rule span_minimal)
  27.772 +        (auto intro: * span_minimal simp: subspace_span)
  27.773    qed
  27.774    then show ?thesis
  27.775 -    by (metis (no_types, lifting) dim_orthogonal_sum dim_span mem_Collect_eq orthogonal_commute orthogonal_def)
  27.776 +    by (metis (no_types, lifting) dim_orthogonal_sum dim_span mem_Collect_eq
  27.777 +        orthogonal_commute orthogonal_def)
  27.778  qed
  27.779  
  27.780  lemma aff_dim_openin:
  27.781 @@ -7444,9 +7232,9 @@
  27.782        then show "(\<lambda>x. e *\<^sub>R x) ` B \<subseteq> (\<lambda>x. x - a) ` S"
  27.783          using e' by blast
  27.784        show "independent ((\<lambda>x. e *\<^sub>R x) ` B)"
  27.785 -        using \<open>independent B\<close>
  27.786 -        apply (rule independent_injective_image, simp)
  27.787 -        by (metis \<open>0 < e\<close> injective_scaleR less_irrefl)
  27.788 +        using linear_scale_self \<open>independent B\<close>
  27.789 +        apply (rule linear_independent_injective_image)
  27.790 +        using \<open>0 < e\<close> inj_on_def by fastforce
  27.791      qed
  27.792      also have "... = aff_dim S"
  27.793        using \<open>a \<in> S\<close> aff_dim_eq_dim hull_inc by force
  27.794 @@ -7466,7 +7254,8 @@
  27.795      using aff_dim_openin
  27.796      by (metis aff_dim_subspace \<open>subspace T\<close> \<open>S \<noteq> {}\<close> ope subspace_affine)
  27.797    also have "... \<le> dim S"
  27.798 -    by (metis aff_dim_subset aff_dim_subspace dim_span span_inc subspace_span)
  27.799 +    by (metis aff_dim_subset aff_dim_subspace dim_span span_superset
  27.800 +        subspace_span)
  27.801    finally show "dim T \<le> dim S" by simp
  27.802  qed
  27.803  
  27.804 @@ -7502,13 +7291,13 @@
  27.805                using \<open>0 < e\<close> by (simp add: dist_norm)
  27.806            next
  27.807              have "?y \<in> S"
  27.808 -              by (metis span_eq \<open>a \<in> span S\<close> \<open>x \<in> S\<close> \<open>subspace S\<close> subspace_add subspace_mul)
  27.809 +              by (metis \<open>a \<in> span S\<close> \<open>x \<in> S\<close> assms(2) span_eq_iff subspace_add subspace_scale)
  27.810              moreover have "?y \<notin> U"
  27.811              proof -
  27.812                have "e/2 / norm a \<noteq> 0"
  27.813                  using \<open>0 < e\<close> \<open>a \<noteq> 0\<close> by auto
  27.814                then show ?thesis
  27.815 -                by (metis True \<open>a \<noteq> 0\<close> a orthogonal_scaleR orthogonal_self real_vector.scale_eq_0_iff span_add_eq span_clauses(1))
  27.816 +                by (metis True \<open>a \<noteq> 0\<close> a orthogonal_scaleR orthogonal_self scale_eq_0_iff span_add_eq span_clauses(1))
  27.817              qed
  27.818              ultimately show "?y \<in> S - U" by blast
  27.819            qed
  27.820 @@ -7628,7 +7417,7 @@
  27.821    then have ba'': "\<And>w. w \<in> S \<Longrightarrow> a'' \<bullet> w = b - a' \<bullet> z"
  27.822      by (simp add: inner_diff_left z)
  27.823    have "\<And>w. w \<in> (+) (- z) ` S \<Longrightarrow> (w + a') \<in> (+) (- z) ` S"