src/HOL/Multivariate_Analysis/Euclidean_Space.thy
changeset 38656 d5d342611edb
parent 38642 8fa437809c67
child 39198 f967a16dfcdd
equal deleted inserted replaced
38655:5001ed24e129 38656:d5d342611edb
  1931 subsection {* An ordering on euclidean spaces that will allow us to talk about intervals *}
  1931 subsection {* An ordering on euclidean spaces that will allow us to talk about intervals *}
  1932 
  1932 
  1933 class ordered_euclidean_space = ord + euclidean_space +
  1933 class ordered_euclidean_space = ord + euclidean_space +
  1934   assumes eucl_le: "x \<le> y \<longleftrightarrow> (\<forall>i < DIM('a). x $$ i \<le> y $$ i)"
  1934   assumes eucl_le: "x \<le> y \<longleftrightarrow> (\<forall>i < DIM('a). x $$ i \<le> y $$ i)"
  1935   and eucl_less: "x < y \<longleftrightarrow> (\<forall>i < DIM('a). x $$ i < y $$ i)"
  1935   and eucl_less: "x < y \<longleftrightarrow> (\<forall>i < DIM('a). x $$ i < y $$ i)"
       
  1936 
       
  1937 lemma eucl_less_not_refl[simp, intro!]: "\<not> x < (x::'a::ordered_euclidean_space)"
       
  1938   unfolding eucl_less[where 'a='a] by auto
       
  1939 
       
  1940 lemma euclidean_trans[trans]:
       
  1941   fixes x y z :: "'a::ordered_euclidean_space"
       
  1942   shows "x < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
       
  1943   and "x \<le> y \<Longrightarrow> y < z \<Longrightarrow> x < z"
       
  1944   and "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
       
  1945   by (force simp: eucl_less[where 'a='a] eucl_le[where 'a='a])+
  1936 
  1946 
  1937 subsection {* Linearity and Bilinearity continued *}
  1947 subsection {* Linearity and Bilinearity continued *}
  1938 
  1948 
  1939 lemma linear_bounded:
  1949 lemma linear_bounded:
  1940   fixes f:: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
  1950   fixes f:: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
  3386   by (rule dimension_eq) (auto simp: basis_complex_def)
  3396   by (rule dimension_eq) (auto simp: basis_complex_def)
  3387 
  3397 
  3388 instance complex :: euclidean_space
  3398 instance complex :: euclidean_space
  3389   proof qed (auto simp add: basis_complex_def inner_complex_def)
  3399   proof qed (auto simp add: basis_complex_def inner_complex_def)
  3390 
  3400 
       
  3401 section {* Products Spaces *}
       
  3402 
       
  3403 instantiation prod :: (real_basis, real_basis) real_basis
       
  3404 begin
       
  3405 
       
  3406 definition "basis i = (if i < DIM('a) then (basis i, 0) else (0, basis (i - DIM('a))))"
       
  3407 
       
  3408 instance
       
  3409 proof
       
  3410   let ?b = "basis :: nat \<Rightarrow> 'a \<times> 'b"
       
  3411   let ?b_a = "basis :: nat \<Rightarrow> 'a"
       
  3412   let ?b_b = "basis :: nat \<Rightarrow> 'b"
       
  3413 
       
  3414   note image_range =
       
  3415     image_add_atLeastLessThan[symmetric, of 0 "DIM('a)" "DIM('b)", simplified]
       
  3416 
       
  3417   have split_range:
       
  3418     "{..<DIM('b) + DIM('a)} = {..<DIM('a)} \<union> {DIM('a)..<DIM('b) + DIM('a)}"
       
  3419     by auto
       
  3420   have *: "?b ` {DIM('a)..<DIM('b) + DIM('a)} = {0} \<times> (?b_b ` {..<DIM('b)})"
       
  3421     "?b ` {..<DIM('a)} = (?b_a ` {..<DIM('a)}) \<times> {0}"
       
  3422     unfolding image_range image_image basis_prod_def_raw range_basis
       
  3423     by (auto simp: zero_prod_def basis_eq_0_iff)
       
  3424   hence b_split:
       
  3425     "?b ` {..<DIM('b) + DIM('a)} = (?b_a ` {..<DIM('a)}) \<times> {0} \<union> {0} \<times> (?b_b ` {..<DIM('b)})" (is "_ = ?prod")
       
  3426     by (subst split_range) (simp add: image_Un)
       
  3427 
       
  3428   have b_0: "?b ` {DIM('b) + DIM('a)..} = {0}" unfolding basis_prod_def_raw
       
  3429     by (auto simp: zero_prod_def image_iff basis_eq_0_iff elim!: ballE[of _ _ "DIM('a) + DIM('b)"])
       
  3430 
       
  3431   have split_UNIV:
       
  3432     "UNIV = {..<DIM('b) + DIM('a)} \<union> {DIM('b)+DIM('a)..}"
       
  3433     by auto
       
  3434 
       
  3435   have range_b: "range ?b = ?prod \<union> {0}"
       
  3436     by (subst split_UNIV) (simp add: image_Un b_split b_0)
       
  3437 
       
  3438   have prod: "\<And>f A B. setsum f (A \<times> B) = (\<Sum>a\<in>A. \<Sum>b\<in>B. f (a, b))"
       
  3439     by (simp add: setsum_cartesian_product)
       
  3440 
       
  3441   show "span (range ?b) = UNIV"
       
  3442     unfolding span_explicit range_b
       
  3443   proof safe
       
  3444     fix a::'a and b::'b
       
  3445     from in_span_basis[of a] in_span_basis[of b]
       
  3446     obtain Sa ua Sb ub where span:
       
  3447         "finite Sa" "Sa \<subseteq> basis ` {..<DIM('a)}" "a = (\<Sum>v\<in>Sa. ua v *\<^sub>R v)"
       
  3448         "finite Sb" "Sb \<subseteq> basis ` {..<DIM('b)}" "b = (\<Sum>v\<in>Sb. ub v *\<^sub>R v)"
       
  3449       unfolding span_explicit by auto
       
  3450 
       
  3451     let ?S = "((Sa - {0}) \<times> {0} \<union> {0} \<times> (Sb - {0}))"
       
  3452     have *:
       
  3453       "?S \<inter> {v. fst v = 0} \<inter> {v. snd v = 0} = {}"
       
  3454       "?S \<inter> - {v. fst v = 0} \<inter> {v. snd v = 0} = (Sa - {0}) \<times> {0}"
       
  3455       "?S \<inter> {v. fst v = 0} \<inter> - {v. snd v = 0} = {0} \<times> (Sb - {0})"
       
  3456       by (auto simp: zero_prod_def)
       
  3457     show "\<exists>S u. finite S \<and> S \<subseteq> ?prod \<union> {0} \<and> (\<Sum>v\<in>S. u v *\<^sub>R v) = (a, b)"
       
  3458       apply (rule exI[of _ ?S])
       
  3459       apply (rule exI[of _ "\<lambda>(v, w). (if w = 0 then ua v else 0) + (if v = 0 then ub w else 0)"])
       
  3460       using span
       
  3461       apply (simp add: prod_case_unfold setsum_addf if_distrib cond_application_beta setsum_cases prod *)
       
  3462       by (auto simp add: setsum_prod intro!: setsum_mono_zero_cong_left)
       
  3463   qed simp
       
  3464 
       
  3465   show "\<exists>d>0. ?b ` {d..} = {0} \<and> independent (?b ` {..<d}) \<and> inj_on ?b {..<d}"
       
  3466     apply (rule exI[of _ "DIM('b) + DIM('a)"]) unfolding b_0
       
  3467   proof (safe intro!: DIM_positive del: notI)
       
  3468     show inj_on: "inj_on ?b {..<DIM('b) + DIM('a)}" unfolding split_range
       
  3469       using inj_on_iff[OF basis_inj[where 'a='a]] inj_on_iff[OF basis_inj[where 'a='b]]
       
  3470       by (auto intro!: inj_onI simp: basis_prod_def basis_eq_0_iff)
       
  3471 
       
  3472     show "independent (?b ` {..<DIM('b) + DIM('a)})"
       
  3473       unfolding independent_eq_inj_on[OF inj_on]
       
  3474     proof safe
       
  3475       fix i u assume i_upper: "i < DIM('b) + DIM('a)" and
       
  3476           "(\<Sum>j\<in>{..<DIM('b) + DIM('a)} - {i}. u (?b j) *\<^sub>R ?b j) = ?b i" (is "?SUM = _")
       
  3477       let ?left = "{..<DIM('a)}" and ?right = "{DIM('a)..<DIM('b) + DIM('a)}"
       
  3478       show False
       
  3479       proof cases
       
  3480         assume "i < DIM('a)"
       
  3481         hence "(basis i, 0) = ?SUM" unfolding `?SUM = ?b i` unfolding basis_prod_def by auto
       
  3482         also have "\<dots> = (\<Sum>j\<in>?left - {i}. u (?b j) *\<^sub>R ?b j) +
       
  3483           (\<Sum>j\<in>?right. u (?b j) *\<^sub>R ?b j)"
       
  3484           using `i < DIM('a)` by (subst setsum_Un_disjoint[symmetric]) (auto intro!: setsum_cong)
       
  3485         also have "\<dots> =  (\<Sum>j\<in>?left - {i}. u (?b_a j, 0) *\<^sub>R (?b_a j, 0)) +
       
  3486           (\<Sum>j\<in>?right. u (0, ?b_b (j-DIM('a))) *\<^sub>R (0, ?b_b (j-DIM('a))))"
       
  3487           unfolding basis_prod_def by auto
       
  3488         finally have "basis i = (\<Sum>j\<in>?left - {i}. u (?b_a j, 0) *\<^sub>R ?b_a j)"
       
  3489           by (simp add: setsum_prod)
       
  3490         moreover
       
  3491         note independent_basis[where 'a='a, unfolded independent_eq_inj_on[OF basis_inj]]
       
  3492         note this[rule_format, of i "\<lambda>v. u (v, 0)"]
       
  3493         ultimately show False using `i < DIM('a)` by auto
       
  3494       next
       
  3495         let ?i = "i - DIM('a)"
       
  3496         assume not: "\<not> i < DIM('a)" hence "DIM('a) \<le> i" by auto
       
  3497         hence "?i < DIM('b)" using `i < DIM('b) + DIM('a)` by auto
       
  3498 
       
  3499         have inj_on: "inj_on (\<lambda>j. j - DIM('a)) {DIM('a)..<DIM('b) + DIM('a)}"
       
  3500           by (auto intro!: inj_onI)
       
  3501         with i_upper not have *: "{..<DIM('b)} - {?i} = (\<lambda>j. j-DIM('a))`(?right - {i})"
       
  3502           by (auto simp: inj_on_image_set_diff image_minus_const_atLeastLessThan_nat)
       
  3503 
       
  3504         have "(0, basis ?i) = ?SUM" unfolding `?SUM = ?b i`
       
  3505           unfolding basis_prod_def using not `?i < DIM('b)` by auto
       
  3506         also have "\<dots> = (\<Sum>j\<in>?left. u (?b j) *\<^sub>R ?b j) +
       
  3507           (\<Sum>j\<in>?right - {i}. u (?b j) *\<^sub>R ?b j)"
       
  3508           using not by (subst setsum_Un_disjoint[symmetric]) (auto intro!: setsum_cong)
       
  3509         also have "\<dots> =  (\<Sum>j\<in>?left. u (?b_a j, 0) *\<^sub>R (?b_a j, 0)) +
       
  3510           (\<Sum>j\<in>?right - {i}. u (0, ?b_b (j-DIM('a))) *\<^sub>R (0, ?b_b (j-DIM('a))))"
       
  3511           unfolding basis_prod_def by auto
       
  3512         finally have "basis ?i = (\<Sum>j\<in>{..<DIM('b)} - {?i}. u (0, ?b_b j) *\<^sub>R ?b_b j)"
       
  3513           unfolding *
       
  3514           by (subst setsum_reindex[OF inj_on[THEN subset_inj_on]])
       
  3515              (auto simp: setsum_prod)
       
  3516         moreover
       
  3517         note independent_basis[where 'a='b, unfolded independent_eq_inj_on[OF basis_inj]]
       
  3518         note this[rule_format, of ?i "\<lambda>v. u (0, v)"]
       
  3519         ultimately show False using `?i < DIM('b)` by auto
       
  3520       qed
       
  3521     qed
       
  3522   qed
       
  3523 qed
  3391 end
  3524 end
       
  3525 
       
  3526 lemma DIM_prod[simp]: "DIM('a \<times> 'b) = DIM('b::real_basis) + DIM('a::real_basis)"
       
  3527   by (rule dimension_eq) (auto simp: basis_prod_def zero_prod_def basis_eq_0_iff)
       
  3528 
       
  3529 instance prod :: (euclidean_space, euclidean_space) euclidean_space
       
  3530 proof (default, safe)
       
  3531   let ?b = "basis :: nat \<Rightarrow> 'a \<times> 'b"
       
  3532   fix i j assume "i < DIM('a \<times> 'b)" "j < DIM('a \<times> 'b)"
       
  3533   thus "?b i \<bullet> ?b j = (if i = j then 1 else 0)"
       
  3534     unfolding basis_prod_def by (auto simp: dot_basis)
       
  3535 qed
       
  3536 
       
  3537 instantiation prod :: (ordered_euclidean_space, ordered_euclidean_space) ordered_euclidean_space
       
  3538 begin
       
  3539 
       
  3540 definition "x \<le> (y::('a\<times>'b)) \<longleftrightarrow> (\<forall>i<DIM('a\<times>'b). x $$ i \<le> y $$ i)"
       
  3541 definition "x < (y::('a\<times>'b)) \<longleftrightarrow> (\<forall>i<DIM('a\<times>'b). x $$ i < y $$ i)"
       
  3542 
       
  3543 instance proof qed (auto simp: less_prod_def less_eq_prod_def)
       
  3544 end
       
  3545 
       
  3546 
       
  3547 end