src/HOL/Multivariate_Analysis/Finite_Cartesian_Product.thy
author wenzelm
Sun Nov 02 17:09:04 2014 +0100 (2014-11-02)
changeset 58877 262572d90bc6
parent 57512 cc97b347b301
child 59815 cce82e360c2f
permissions -rw-r--r--
modernized header;
     1 (*  Title:      HOL/Multivariate_Analysis/Finite_Cartesian_Product.thy
     2     Author:     Amine Chaieb, University of Cambridge
     3 *)
     4 
     5 section {* Definition of finite Cartesian product types. *}
     6 
     7 theory Finite_Cartesian_Product
     8 imports
     9   Euclidean_Space
    10   L2_Norm
    11   "~~/src/HOL/Library/Numeral_Type"
    12 begin
    13 
    14 subsection {* Finite Cartesian products, with indexing and lambdas. *}
    15 
    16 typedef ('a, 'b) vec = "UNIV :: (('b::finite) \<Rightarrow> 'a) set"
    17   morphisms vec_nth vec_lambda ..
    18 
    19 notation
    20   vec_nth (infixl "$" 90) and
    21   vec_lambda (binder "\<chi>" 10)
    22 
    23 (*
    24   Translate "'b ^ 'n" into "'b ^ ('n :: finite)". When 'n has already more than
    25   the finite type class write "vec 'b 'n"
    26 *)
    27 
    28 syntax "_finite_vec" :: "type \<Rightarrow> type \<Rightarrow> type" ("(_ ^/ _)" [15, 16] 15)
    29 
    30 parse_translation {*
    31   let
    32     fun vec t u = Syntax.const @{type_syntax vec} $ t $ u;
    33     fun finite_vec_tr [t, u] =
    34       (case Term_Position.strip_positions u of
    35         v as Free (x, _) =>
    36           if Lexicon.is_tid x then
    37             vec t (Syntax.const @{syntax_const "_ofsort"} $ v $
    38               Syntax.const @{class_syntax finite})
    39           else vec t u
    40       | _ => vec t u)
    41   in
    42     [(@{syntax_const "_finite_vec"}, K finite_vec_tr)]
    43   end
    44 *}
    45 
    46 lemma vec_eq_iff: "(x = y) \<longleftrightarrow> (\<forall>i. x$i = y$i)"
    47   by (simp add: vec_nth_inject [symmetric] fun_eq_iff)
    48 
    49 lemma vec_lambda_beta [simp]: "vec_lambda g $ i = g i"
    50   by (simp add: vec_lambda_inverse)
    51 
    52 lemma vec_lambda_unique: "(\<forall>i. f$i = g i) \<longleftrightarrow> vec_lambda g = f"
    53   by (auto simp add: vec_eq_iff)
    54 
    55 lemma vec_lambda_eta: "(\<chi> i. (g$i)) = g"
    56   by (simp add: vec_eq_iff)
    57 
    58 
    59 subsection {* Group operations and class instances *}
    60 
    61 instantiation vec :: (zero, finite) zero
    62 begin
    63   definition "0 \<equiv> (\<chi> i. 0)"
    64   instance ..
    65 end
    66 
    67 instantiation vec :: (plus, finite) plus
    68 begin
    69   definition "op + \<equiv> (\<lambda> x y. (\<chi> i. x$i + y$i))"
    70   instance ..
    71 end
    72 
    73 instantiation vec :: (minus, finite) minus
    74 begin
    75   definition "op - \<equiv> (\<lambda> x y. (\<chi> i. x$i - y$i))"
    76   instance ..
    77 end
    78 
    79 instantiation vec :: (uminus, finite) uminus
    80 begin
    81   definition "uminus \<equiv> (\<lambda> x. (\<chi> i. - (x$i)))"
    82   instance ..
    83 end
    84 
    85 lemma zero_index [simp]: "0 $ i = 0"
    86   unfolding zero_vec_def by simp
    87 
    88 lemma vector_add_component [simp]: "(x + y)$i = x$i + y$i"
    89   unfolding plus_vec_def by simp
    90 
    91 lemma vector_minus_component [simp]: "(x - y)$i = x$i - y$i"
    92   unfolding minus_vec_def by simp
    93 
    94 lemma vector_uminus_component [simp]: "(- x)$i = - (x$i)"
    95   unfolding uminus_vec_def by simp
    96 
    97 instance vec :: (semigroup_add, finite) semigroup_add
    98   by default (simp add: vec_eq_iff add.assoc)
    99 
   100 instance vec :: (ab_semigroup_add, finite) ab_semigroup_add
   101   by default (simp add: vec_eq_iff add.commute)
   102 
   103 instance vec :: (monoid_add, finite) monoid_add
   104   by default (simp_all add: vec_eq_iff)
   105 
   106 instance vec :: (comm_monoid_add, finite) comm_monoid_add
   107   by default (simp add: vec_eq_iff)
   108 
   109 instance vec :: (cancel_semigroup_add, finite) cancel_semigroup_add
   110   by default (simp_all add: vec_eq_iff)
   111 
   112 instance vec :: (cancel_ab_semigroup_add, finite) cancel_ab_semigroup_add
   113   by default (simp add: vec_eq_iff)
   114 
   115 instance vec :: (cancel_comm_monoid_add, finite) cancel_comm_monoid_add ..
   116 
   117 instance vec :: (group_add, finite) group_add
   118   by default (simp_all add: vec_eq_iff)
   119 
   120 instance vec :: (ab_group_add, finite) ab_group_add
   121   by default (simp_all add: vec_eq_iff)
   122 
   123 
   124 subsection {* Real vector space *}
   125 
   126 instantiation vec :: (real_vector, finite) real_vector
   127 begin
   128 
   129 definition "scaleR \<equiv> (\<lambda> r x. (\<chi> i. scaleR r (x$i)))"
   130 
   131 lemma vector_scaleR_component [simp]: "(scaleR r x)$i = scaleR r (x$i)"
   132   unfolding scaleR_vec_def by simp
   133 
   134 instance
   135   by default (simp_all add: vec_eq_iff scaleR_left_distrib scaleR_right_distrib)
   136 
   137 end
   138 
   139 
   140 subsection {* Topological space *}
   141 
   142 instantiation vec :: (topological_space, finite) topological_space
   143 begin
   144 
   145 definition
   146   "open (S :: ('a ^ 'b) set) \<longleftrightarrow>
   147     (\<forall>x\<in>S. \<exists>A. (\<forall>i. open (A i) \<and> x$i \<in> A i) \<and>
   148       (\<forall>y. (\<forall>i. y$i \<in> A i) \<longrightarrow> y \<in> S))"
   149 
   150 instance proof
   151   show "open (UNIV :: ('a ^ 'b) set)"
   152     unfolding open_vec_def by auto
   153 next
   154   fix S T :: "('a ^ 'b) set"
   155   assume "open S" "open T" thus "open (S \<inter> T)"
   156     unfolding open_vec_def
   157     apply clarify
   158     apply (drule (1) bspec)+
   159     apply (clarify, rename_tac Sa Ta)
   160     apply (rule_tac x="\<lambda>i. Sa i \<inter> Ta i" in exI)
   161     apply (simp add: open_Int)
   162     done
   163 next
   164   fix K :: "('a ^ 'b) set set"
   165   assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
   166     unfolding open_vec_def
   167     apply clarify
   168     apply (drule (1) bspec)
   169     apply (drule (1) bspec)
   170     apply clarify
   171     apply (rule_tac x=A in exI)
   172     apply fast
   173     done
   174 qed
   175 
   176 end
   177 
   178 lemma open_vector_box: "\<forall>i. open (S i) \<Longrightarrow> open {x. \<forall>i. x $ i \<in> S i}"
   179   unfolding open_vec_def by auto
   180 
   181 lemma open_vimage_vec_nth: "open S \<Longrightarrow> open ((\<lambda>x. x $ i) -` S)"
   182   unfolding open_vec_def
   183   apply clarify
   184   apply (rule_tac x="\<lambda>k. if k = i then S else UNIV" in exI, simp)
   185   done
   186 
   187 lemma closed_vimage_vec_nth: "closed S \<Longrightarrow> closed ((\<lambda>x. x $ i) -` S)"
   188   unfolding closed_open vimage_Compl [symmetric]
   189   by (rule open_vimage_vec_nth)
   190 
   191 lemma closed_vector_box: "\<forall>i. closed (S i) \<Longrightarrow> closed {x. \<forall>i. x $ i \<in> S i}"
   192 proof -
   193   have "{x. \<forall>i. x $ i \<in> S i} = (\<Inter>i. (\<lambda>x. x $ i) -` S i)" by auto
   194   thus "\<forall>i. closed (S i) \<Longrightarrow> closed {x. \<forall>i. x $ i \<in> S i}"
   195     by (simp add: closed_INT closed_vimage_vec_nth)
   196 qed
   197 
   198 lemma tendsto_vec_nth [tendsto_intros]:
   199   assumes "((\<lambda>x. f x) ---> a) net"
   200   shows "((\<lambda>x. f x $ i) ---> a $ i) net"
   201 proof (rule topological_tendstoI)
   202   fix S assume "open S" "a $ i \<in> S"
   203   then have "open ((\<lambda>y. y $ i) -` S)" "a \<in> ((\<lambda>y. y $ i) -` S)"
   204     by (simp_all add: open_vimage_vec_nth)
   205   with assms have "eventually (\<lambda>x. f x \<in> (\<lambda>y. y $ i) -` S) net"
   206     by (rule topological_tendstoD)
   207   then show "eventually (\<lambda>x. f x $ i \<in> S) net"
   208     by simp
   209 qed
   210 
   211 lemma isCont_vec_nth [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x $ i) a"
   212   unfolding isCont_def by (rule tendsto_vec_nth)
   213 
   214 lemma vec_tendstoI:
   215   assumes "\<And>i. ((\<lambda>x. f x $ i) ---> a $ i) net"
   216   shows "((\<lambda>x. f x) ---> a) net"
   217 proof (rule topological_tendstoI)
   218   fix S assume "open S" and "a \<in> S"
   219   then obtain A where A: "\<And>i. open (A i)" "\<And>i. a $ i \<in> A i"
   220     and S: "\<And>y. \<forall>i. y $ i \<in> A i \<Longrightarrow> y \<in> S"
   221     unfolding open_vec_def by metis
   222   have "\<And>i. eventually (\<lambda>x. f x $ i \<in> A i) net"
   223     using assms A by (rule topological_tendstoD)
   224   hence "eventually (\<lambda>x. \<forall>i. f x $ i \<in> A i) net"
   225     by (rule eventually_all_finite)
   226   thus "eventually (\<lambda>x. f x \<in> S) net"
   227     by (rule eventually_elim1, simp add: S)
   228 qed
   229 
   230 lemma tendsto_vec_lambda [tendsto_intros]:
   231   assumes "\<And>i. ((\<lambda>x. f x i) ---> a i) net"
   232   shows "((\<lambda>x. \<chi> i. f x i) ---> (\<chi> i. a i)) net"
   233   using assms by (simp add: vec_tendstoI)
   234 
   235 lemma open_image_vec_nth: assumes "open S" shows "open ((\<lambda>x. x $ i) ` S)"
   236 proof (rule openI)
   237   fix a assume "a \<in> (\<lambda>x. x $ i) ` S"
   238   then obtain z where "a = z $ i" and "z \<in> S" ..
   239   then obtain A where A: "\<forall>i. open (A i) \<and> z $ i \<in> A i"
   240     and S: "\<forall>y. (\<forall>i. y $ i \<in> A i) \<longrightarrow> y \<in> S"
   241     using `open S` unfolding open_vec_def by auto
   242   hence "A i \<subseteq> (\<lambda>x. x $ i) ` S"
   243     by (clarsimp, rule_tac x="\<chi> j. if j = i then x else z $ j" in image_eqI,
   244       simp_all)
   245   hence "open (A i) \<and> a \<in> A i \<and> A i \<subseteq> (\<lambda>x. x $ i) ` S"
   246     using A `a = z $ i` by simp
   247   then show "\<exists>T. open T \<and> a \<in> T \<and> T \<subseteq> (\<lambda>x. x $ i) ` S" by - (rule exI)
   248 qed
   249 
   250 instance vec :: (perfect_space, finite) perfect_space
   251 proof
   252   fix x :: "'a ^ 'b" show "\<not> open {x}"
   253   proof
   254     assume "open {x}"
   255     hence "\<forall>i. open ((\<lambda>x. x $ i) ` {x})" by (fast intro: open_image_vec_nth)   
   256     hence "\<forall>i. open {x $ i}" by simp
   257     thus "False" by (simp add: not_open_singleton)
   258   qed
   259 qed
   260 
   261 
   262 subsection {* Metric space *}
   263 
   264 instantiation vec :: (metric_space, finite) metric_space
   265 begin
   266 
   267 definition
   268   "dist x y = setL2 (\<lambda>i. dist (x$i) (y$i)) UNIV"
   269 
   270 lemma dist_vec_nth_le: "dist (x $ i) (y $ i) \<le> dist x y"
   271   unfolding dist_vec_def by (rule member_le_setL2) simp_all
   272 
   273 instance proof
   274   fix x y :: "'a ^ 'b"
   275   show "dist x y = 0 \<longleftrightarrow> x = y"
   276     unfolding dist_vec_def
   277     by (simp add: setL2_eq_0_iff vec_eq_iff)
   278 next
   279   fix x y z :: "'a ^ 'b"
   280   show "dist x y \<le> dist x z + dist y z"
   281     unfolding dist_vec_def
   282     apply (rule order_trans [OF _ setL2_triangle_ineq])
   283     apply (simp add: setL2_mono dist_triangle2)
   284     done
   285 next
   286   fix S :: "('a ^ 'b) set"
   287   show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
   288   proof
   289     assume "open S" show "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   290     proof
   291       fix x assume "x \<in> S"
   292       obtain A where A: "\<forall>i. open (A i)" "\<forall>i. x $ i \<in> A i"
   293         and S: "\<forall>y. (\<forall>i. y $ i \<in> A i) \<longrightarrow> y \<in> S"
   294         using `open S` and `x \<in> S` unfolding open_vec_def by metis
   295       have "\<forall>i\<in>UNIV. \<exists>r>0. \<forall>y. dist y (x $ i) < r \<longrightarrow> y \<in> A i"
   296         using A unfolding open_dist by simp
   297       hence "\<exists>r. \<forall>i\<in>UNIV. 0 < r i \<and> (\<forall>y. dist y (x $ i) < r i \<longrightarrow> y \<in> A i)"
   298         by (rule finite_set_choice [OF finite])
   299       then obtain r where r1: "\<forall>i. 0 < r i"
   300         and r2: "\<forall>i y. dist y (x $ i) < r i \<longrightarrow> y \<in> A i" by fast
   301       have "0 < Min (range r) \<and> (\<forall>y. dist y x < Min (range r) \<longrightarrow> y \<in> S)"
   302         by (simp add: r1 r2 S le_less_trans [OF dist_vec_nth_le])
   303       thus "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" ..
   304     qed
   305   next
   306     assume *: "\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S" show "open S"
   307     proof (unfold open_vec_def, rule)
   308       fix x assume "x \<in> S"
   309       then obtain e where "0 < e" and S: "\<forall>y. dist y x < e \<longrightarrow> y \<in> S"
   310         using * by fast
   311       def r \<equiv> "\<lambda>i::'b. e / sqrt (of_nat CARD('b))"
   312       from `0 < e` have r: "\<forall>i. 0 < r i"
   313         unfolding r_def by simp_all
   314       from `0 < e` have e: "e = setL2 r UNIV"
   315         unfolding r_def by (simp add: setL2_constant)
   316       def A \<equiv> "\<lambda>i. {y. dist (x $ i) y < r i}"
   317       have "\<forall>i. open (A i) \<and> x $ i \<in> A i"
   318         unfolding A_def by (simp add: open_ball r)
   319       moreover have "\<forall>y. (\<forall>i. y $ i \<in> A i) \<longrightarrow> y \<in> S"
   320         by (simp add: A_def S dist_vec_def e setL2_strict_mono dist_commute)
   321       ultimately show "\<exists>A. (\<forall>i. open (A i) \<and> x $ i \<in> A i) \<and>
   322         (\<forall>y. (\<forall>i. y $ i \<in> A i) \<longrightarrow> y \<in> S)" by metis
   323     qed
   324   qed
   325 qed
   326 
   327 end
   328 
   329 lemma Cauchy_vec_nth:
   330   "Cauchy (\<lambda>n. X n) \<Longrightarrow> Cauchy (\<lambda>n. X n $ i)"
   331   unfolding Cauchy_def by (fast intro: le_less_trans [OF dist_vec_nth_le])
   332 
   333 lemma vec_CauchyI:
   334   fixes X :: "nat \<Rightarrow> 'a::metric_space ^ 'n"
   335   assumes X: "\<And>i. Cauchy (\<lambda>n. X n $ i)"
   336   shows "Cauchy (\<lambda>n. X n)"
   337 proof (rule metric_CauchyI)
   338   fix r :: real assume "0 < r"
   339   hence "0 < r / of_nat CARD('n)" (is "0 < ?s") by simp
   340   def N \<equiv> "\<lambda>i. LEAST N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m $ i) (X n $ i) < ?s"
   341   def M \<equiv> "Max (range N)"
   342   have "\<And>i. \<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m $ i) (X n $ i) < ?s"
   343     using X `0 < ?s` by (rule metric_CauchyD)
   344   hence "\<And>i. \<forall>m\<ge>N i. \<forall>n\<ge>N i. dist (X m $ i) (X n $ i) < ?s"
   345     unfolding N_def by (rule LeastI_ex)
   346   hence M: "\<And>i. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m $ i) (X n $ i) < ?s"
   347     unfolding M_def by simp
   348   {
   349     fix m n :: nat
   350     assume "M \<le> m" "M \<le> n"
   351     have "dist (X m) (X n) = setL2 (\<lambda>i. dist (X m $ i) (X n $ i)) UNIV"
   352       unfolding dist_vec_def ..
   353     also have "\<dots> \<le> setsum (\<lambda>i. dist (X m $ i) (X n $ i)) UNIV"
   354       by (rule setL2_le_setsum [OF zero_le_dist])
   355     also have "\<dots> < setsum (\<lambda>i::'n. ?s) UNIV"
   356       by (rule setsum_strict_mono, simp_all add: M `M \<le> m` `M \<le> n`)
   357     also have "\<dots> = r"
   358       by simp
   359     finally have "dist (X m) (X n) < r" .
   360   }
   361   hence "\<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < r"
   362     by simp
   363   then show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < r" ..
   364 qed
   365 
   366 instance vec :: (complete_space, finite) complete_space
   367 proof
   368   fix X :: "nat \<Rightarrow> 'a ^ 'b" assume "Cauchy X"
   369   have "\<And>i. (\<lambda>n. X n $ i) ----> lim (\<lambda>n. X n $ i)"
   370     using Cauchy_vec_nth [OF `Cauchy X`]
   371     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
   372   hence "X ----> vec_lambda (\<lambda>i. lim (\<lambda>n. X n $ i))"
   373     by (simp add: vec_tendstoI)
   374   then show "convergent X"
   375     by (rule convergentI)
   376 qed
   377 
   378 
   379 subsection {* Normed vector space *}
   380 
   381 instantiation vec :: (real_normed_vector, finite) real_normed_vector
   382 begin
   383 
   384 definition "norm x = setL2 (\<lambda>i. norm (x$i)) UNIV"
   385 
   386 definition "sgn (x::'a^'b) = scaleR (inverse (norm x)) x"
   387 
   388 instance proof
   389   fix a :: real and x y :: "'a ^ 'b"
   390   show "norm x = 0 \<longleftrightarrow> x = 0"
   391     unfolding norm_vec_def
   392     by (simp add: setL2_eq_0_iff vec_eq_iff)
   393   show "norm (x + y) \<le> norm x + norm y"
   394     unfolding norm_vec_def
   395     apply (rule order_trans [OF _ setL2_triangle_ineq])
   396     apply (simp add: setL2_mono norm_triangle_ineq)
   397     done
   398   show "norm (scaleR a x) = \<bar>a\<bar> * norm x"
   399     unfolding norm_vec_def
   400     by (simp add: setL2_right_distrib)
   401   show "sgn x = scaleR (inverse (norm x)) x"
   402     by (rule sgn_vec_def)
   403   show "dist x y = norm (x - y)"
   404     unfolding dist_vec_def norm_vec_def
   405     by (simp add: dist_norm)
   406 qed
   407 
   408 end
   409 
   410 lemma norm_nth_le: "norm (x $ i) \<le> norm x"
   411 unfolding norm_vec_def
   412 by (rule member_le_setL2) simp_all
   413 
   414 lemma bounded_linear_vec_nth: "bounded_linear (\<lambda>x. x $ i)"
   415 apply default
   416 apply (rule vector_add_component)
   417 apply (rule vector_scaleR_component)
   418 apply (rule_tac x="1" in exI, simp add: norm_nth_le)
   419 done
   420 
   421 instance vec :: (banach, finite) banach ..
   422 
   423 
   424 subsection {* Inner product space *}
   425 
   426 instantiation vec :: (real_inner, finite) real_inner
   427 begin
   428 
   429 definition "inner x y = setsum (\<lambda>i. inner (x$i) (y$i)) UNIV"
   430 
   431 instance proof
   432   fix r :: real and x y z :: "'a ^ 'b"
   433   show "inner x y = inner y x"
   434     unfolding inner_vec_def
   435     by (simp add: inner_commute)
   436   show "inner (x + y) z = inner x z + inner y z"
   437     unfolding inner_vec_def
   438     by (simp add: inner_add_left setsum.distrib)
   439   show "inner (scaleR r x) y = r * inner x y"
   440     unfolding inner_vec_def
   441     by (simp add: setsum_right_distrib)
   442   show "0 \<le> inner x x"
   443     unfolding inner_vec_def
   444     by (simp add: setsum_nonneg)
   445   show "inner x x = 0 \<longleftrightarrow> x = 0"
   446     unfolding inner_vec_def
   447     by (simp add: vec_eq_iff setsum_nonneg_eq_0_iff)
   448   show "norm x = sqrt (inner x x)"
   449     unfolding inner_vec_def norm_vec_def setL2_def
   450     by (simp add: power2_norm_eq_inner)
   451 qed
   452 
   453 end
   454 
   455 
   456 subsection {* Euclidean space *}
   457 
   458 text {* Vectors pointing along a single axis. *}
   459 
   460 definition "axis k x = (\<chi> i. if i = k then x else 0)"
   461 
   462 lemma axis_nth [simp]: "axis i x $ i = x"
   463   unfolding axis_def by simp
   464 
   465 lemma axis_eq_axis: "axis i x = axis j y \<longleftrightarrow> x = y \<and> i = j \<or> x = 0 \<and> y = 0"
   466   unfolding axis_def vec_eq_iff by auto
   467 
   468 lemma inner_axis_axis:
   469   "inner (axis i x) (axis j y) = (if i = j then inner x y else 0)"
   470   unfolding inner_vec_def
   471   apply (cases "i = j")
   472   apply clarsimp
   473   apply (subst setsum.remove [of _ j], simp_all)
   474   apply (rule setsum.neutral, simp add: axis_def)
   475   apply (rule setsum.neutral, simp add: axis_def)
   476   done
   477 
   478 lemma setsum_single:
   479   assumes "finite A" and "k \<in> A" and "f k = y"
   480   assumes "\<And>i. i \<in> A \<Longrightarrow> i \<noteq> k \<Longrightarrow> f i = 0"
   481   shows "(\<Sum>i\<in>A. f i) = y"
   482   apply (subst setsum.remove [OF assms(1,2)])
   483   apply (simp add: setsum.neutral assms(3,4))
   484   done
   485 
   486 lemma inner_axis: "inner x (axis i y) = inner (x $ i) y"
   487   unfolding inner_vec_def
   488   apply (rule_tac k=i in setsum_single)
   489   apply simp_all
   490   apply (simp add: axis_def)
   491   done
   492 
   493 instantiation vec :: (euclidean_space, finite) euclidean_space
   494 begin
   495 
   496 definition "Basis = (\<Union>i. \<Union>u\<in>Basis. {axis i u})"
   497 
   498 instance proof
   499   show "(Basis :: ('a ^ 'b) set) \<noteq> {}"
   500     unfolding Basis_vec_def by simp
   501 next
   502   show "finite (Basis :: ('a ^ 'b) set)"
   503     unfolding Basis_vec_def by simp
   504 next
   505   fix u v :: "'a ^ 'b"
   506   assume "u \<in> Basis" and "v \<in> Basis"
   507   thus "inner u v = (if u = v then 1 else 0)"
   508     unfolding Basis_vec_def
   509     by (auto simp add: inner_axis_axis axis_eq_axis inner_Basis)
   510 next
   511   fix x :: "'a ^ 'b"
   512   show "(\<forall>u\<in>Basis. inner x u = 0) \<longleftrightarrow> x = 0"
   513     unfolding Basis_vec_def
   514     by (simp add: inner_axis euclidean_all_zero_iff vec_eq_iff)
   515 qed
   516 
   517 lemma DIM_cart[simp]: "DIM('a^'b) = CARD('b) * DIM('a)"
   518   apply (simp add: Basis_vec_def)
   519   apply (subst card_UN_disjoint)
   520      apply simp
   521     apply simp
   522    apply (auto simp: axis_eq_axis) [1]
   523   apply (subst card_UN_disjoint)
   524      apply (auto simp: axis_eq_axis)
   525   done
   526 
   527 end
   528 
   529 end