src/HOL/Library/Euclidean_Space.thy
author huffman
Sat, 21 Feb 2009 10:58:25 -0800
changeset 30040 e2cd1acda1ab
parent 30039 7208c88df507
child 30041 9becd197a40e
permissions -rw-r--r--
real_normed_vector instance
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     1
(* Title:      Library/Euclidean_Space
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     2
   ID:         $Id: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     3
   Author:     Amine Chaieb, University of Cambridge
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     4
*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     5
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     6
header {* (Real) Vectors in Euclidean space, and elementary linear algebra.*}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     7
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     8
theory Euclidean_Space
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
     9
  imports "~~/src/HOL/Decision_Procs/Dense_Linear_Order" Complex_Main 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    10
  Finite_Cartesian_Product Glbs Infinite_Set Numeral_Type
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    11
  uses ("normarith.ML")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    12
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    13
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    14
text{* Some common special cases.*}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    15
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    16
lemma forall_1: "(\<forall>(i::'a::{order,one}). 1 <= i \<and> i <= 1 --> P i) \<longleftrightarrow> P 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    17
  by (metis order_eq_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    18
lemma forall_dimindex_1: "(\<forall>i \<in> {1..dimindex(UNIV:: 1 set)}. P i) \<longleftrightarrow> P 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    19
  by (simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    20
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    21
lemma forall_2: "(\<forall>(i::nat). 1 <= i \<and> i <= 2 --> P i) \<longleftrightarrow> P 1 \<and> P 2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    22
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    23
  have "\<And>i::nat. 1 <= i \<and> i <= 2 \<longleftrightarrow> i = 1 \<or> i = 2" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    24
  thus ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    25
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    26
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    27
lemma forall_3: "(\<forall>(i::nat). 1 <= i \<and> i <= 3 --> P i) \<longleftrightarrow> P 1 \<and> P 2 \<and> P 3"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    28
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    29
  have "\<And>i::nat. 1 <= i \<and> i <= 3 \<longleftrightarrow> i = 1 \<or> i = 2 \<or> i = 3" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    30
  thus ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    31
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    32
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    33
lemma setsum_singleton[simp]: "setsum f {x} = f x" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    34
lemma setsum_1: "setsum f {(1::'a::{order,one})..1} = f 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    35
  by (simp add: atLeastAtMost_singleton)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    36
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    37
lemma setsum_2: "setsum f {1::nat..2} = f 1 + f 2" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    38
  by (simp add: nat_number  atLeastAtMostSuc_conv add_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    39
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    40
lemma setsum_3: "setsum f {1::nat..3} = f 1 + f 2 + f 3" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    41
  by (simp add: nat_number  atLeastAtMostSuc_conv add_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    42
29906
80369da39838 section -> subsection
huffman
parents: 29905
diff changeset
    43
subsection{* Basic componentwise operations on vectors. *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    44
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    45
instantiation "^" :: (plus,type) plus
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    46
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    47
definition  vector_add_def : "op + \<equiv> (\<lambda> x y.  (\<chi> i. (x$i) + (y$i)))" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    48
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    49
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    50
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    51
instantiation "^" :: (times,type) times
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    52
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    53
  definition vector_mult_def : "op * \<equiv> (\<lambda> x y.  (\<chi> i. (x$i) * (y$i)))" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    54
  instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    55
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    56
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    57
instantiation "^" :: (minus,type) minus begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    58
  definition vector_minus_def : "op - \<equiv> (\<lambda> x y.  (\<chi> i. (x$i) - (y$i)))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    59
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    60
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    61
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    62
instantiation "^" :: (uminus,type) uminus begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    63
  definition vector_uminus_def : "uminus \<equiv> (\<lambda> x.  (\<chi> i. - (x$i)))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    64
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    65
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    66
instantiation "^" :: (zero,type) zero begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    67
  definition vector_zero_def : "0 \<equiv> (\<chi> i. 0)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    68
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    69
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    70
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    71
instantiation "^" :: (one,type) one begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    72
  definition vector_one_def : "1 \<equiv> (\<chi> i. 1)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    73
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    74
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    75
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    76
instantiation "^" :: (ord,type) ord
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    77
 begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    78
definition vector_less_eq_def:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    79
  "less_eq (x :: 'a ^'b) y = (ALL i : {1 .. dimindex (UNIV :: 'b set)}.
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    80
  x$i <= y$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    81
definition vector_less_def: "less (x :: 'a ^'b) y = (ALL i : {1 ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    82
  dimindex (UNIV :: 'b set)}. x$i < y$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    83
 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    84
instance by (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    85
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    86
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    87
instantiation "^" :: (scaleR, type) scaleR
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    88
begin
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    89
definition vector_scaleR_def: "scaleR = (\<lambda> r x.  (\<chi> i. scaleR r (x$i)))" 
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    90
instance ..
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    91
end
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    92
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
    93
text{* Also the scalar-vector multiplication. *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    94
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    95
definition vector_scalar_mult:: "'a::times \<Rightarrow> 'a ^'n \<Rightarrow> 'a ^ 'n" (infixr "*s" 75)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    96
  where "c *s x = (\<chi> i. c * (x$i))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    97
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    98
text{* Constant Vectors *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    99
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   100
definition "vec x = (\<chi> i. x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   101
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   102
text{* Dot products. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   103
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   104
definition dot :: "'a::{comm_monoid_add, times} ^ 'n \<Rightarrow> 'a ^ 'n \<Rightarrow> 'a" (infix "\<bullet>" 70) where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   105
  "x \<bullet> y = setsum (\<lambda>i. x$i * y$i) {1 .. dimindex (UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   106
lemma dot_1[simp]: "(x::'a::{comm_monoid_add, times}^1) \<bullet> y = (x$1) * (y$1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   107
  by (simp add: dot_def dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   108
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   109
lemma dot_2[simp]: "(x::'a::{comm_monoid_add, times}^2) \<bullet> y = (x$1) * (y$1) + (x$2) * (y$2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   110
  by (simp add: dot_def dimindex_def nat_number)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   111
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   112
lemma dot_3[simp]: "(x::'a::{comm_monoid_add, times}^3) \<bullet> y = (x$1) * (y$1) + (x$2) * (y$2) + (x$3) * (y$3)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   113
  by (simp add: dot_def dimindex_def nat_number)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   114
29906
80369da39838 section -> subsection
huffman
parents: 29905
diff changeset
   115
subsection {* A naive proof procedure to lift really trivial arithmetic stuff from the basis of the vector space. *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   116
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   117
lemmas Cart_lambda_beta' = Cart_lambda_beta[rule_format]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   118
method_setup vector = {*
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   119
let
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   120
  val ss1 = HOL_basic_ss addsimps [@{thm dot_def}, @{thm setsum_addf} RS sym, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   121
  @{thm setsum_subtractf} RS sym, @{thm setsum_right_distrib}, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   122
  @{thm setsum_left_distrib}, @{thm setsum_negf} RS sym]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   123
  val ss2 = @{simpset} addsimps 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   124
             [@{thm vector_add_def}, @{thm vector_mult_def},  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   125
              @{thm vector_minus_def}, @{thm vector_uminus_def}, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   126
              @{thm vector_one_def}, @{thm vector_zero_def}, @{thm vec_def}, 
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   127
              @{thm vector_scaleR_def},
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   128
              @{thm Cart_lambda_beta'}, @{thm vector_scalar_mult_def}]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   129
 fun vector_arith_tac ths = 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   130
   simp_tac ss1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   131
   THEN' (fn i => rtac @{thm setsum_cong2} i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   132
         ORELSE rtac @{thm setsum_0'} i 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   133
         ORELSE simp_tac (HOL_basic_ss addsimps [@{thm "Cart_eq"}]) i)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   134
   (* THEN' TRY o clarify_tac HOL_cs  THEN' (TRY o rtac @{thm iffI}) *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   135
   THEN' asm_full_simp_tac (ss2 addsimps ths)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   136
 in
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   137
  Method.thms_args (Method.SIMPLE_METHOD' o vector_arith_tac)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   138
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   139
*} "Lifts trivial vector statements to real arith statements"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   140
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   141
lemma vec_0[simp]: "vec 0 = 0" by (vector vector_zero_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   142
lemma vec_1[simp]: "vec 1 = 1" by (vector vector_one_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   143
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   144
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   145
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   146
text{* Obvious "component-pushing". *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   147
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   148
lemma vec_component: " i \<in> {1 .. dimindex (UNIV :: 'n set)} \<Longrightarrow> (vec x :: 'a ^ 'n)$i = x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   149
  by (vector vec_def) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   150
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   151
lemma vector_add_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   152
  fixes x y :: "'a::{plus} ^ 'n"  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   153
  shows "(x + y)$i = x$i + y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   154
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   155
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   156
lemma vector_minus_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   157
  fixes x y :: "'a::{minus} ^ 'n"  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   158
  shows "(x - y)$i = x$i - y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   159
  using i  by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   160
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   161
lemma vector_mult_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   162
  fixes x y :: "'a::{times} ^ 'n"  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   163
  shows "(x * y)$i = x$i * y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   164
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   165
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   166
lemma vector_smult_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   167
  fixes y :: "'a::{times} ^ 'n"  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   168
  shows "(c *s y)$i = c * (y$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   169
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   170
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   171
lemma vector_uminus_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   172
  fixes x :: "'a::{uminus} ^ 'n"  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   173
  shows "(- x)$i = - (x$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   174
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   175
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   176
lemma vector_scaleR_component:
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   177
  fixes x :: "'a::scaleR ^ 'n"
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   178
  assumes i: "i \<in> {1 .. dimindex(UNIV :: 'n set)}"
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   179
  shows "(scaleR r x)$i = scaleR r (x$i)"
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   180
  using i by vector
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   181
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   182
lemma cond_component: "(if b then x else y)$i = (if b then x$i else y$i)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   183
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   184
lemmas vector_component =
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   185
  vec_component vector_add_component vector_mult_component
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   186
  vector_smult_component vector_minus_component vector_uminus_component
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   187
  vector_scaleR_component cond_component
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   188
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   189
subsection {* Some frequently useful arithmetic lemmas over vectors. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   190
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   191
instance "^" :: (semigroup_add,type) semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   192
  apply (intro_classes) by (vector add_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   193
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   194
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   195
instance "^" :: (monoid_add,type) monoid_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   196
  apply (intro_classes) by vector+ 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   197
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   198
instance "^" :: (group_add,type) group_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   199
  apply (intro_classes) by (vector algebra_simps)+ 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   200
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   201
instance "^" :: (ab_semigroup_add,type) ab_semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   202
  apply (intro_classes) by (vector add_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   203
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   204
instance "^" :: (comm_monoid_add,type) comm_monoid_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   205
  apply (intro_classes) by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   206
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   207
instance "^" :: (ab_group_add,type) ab_group_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   208
  apply (intro_classes) by vector+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   209
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   210
instance "^" :: (cancel_semigroup_add,type) cancel_semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   211
  apply (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   212
  by (vector Cart_eq)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   213
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   214
instance "^" :: (cancel_ab_semigroup_add,type) cancel_ab_semigroup_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   215
  apply (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   216
  by (vector Cart_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   217
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   218
instance "^" :: (real_vector, type) real_vector
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   219
  by default (vector scaleR_left_distrib scaleR_right_distrib)+
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   220
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   221
instance "^" :: (semigroup_mult,type) semigroup_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   222
  apply (intro_classes) by (vector mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   223
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   224
instance "^" :: (monoid_mult,type) monoid_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   225
  apply (intro_classes) by vector+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   226
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   227
instance "^" :: (ab_semigroup_mult,type) ab_semigroup_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   228
  apply (intro_classes) by (vector mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   229
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   230
instance "^" :: (ab_semigroup_idem_mult,type) ab_semigroup_idem_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   231
  apply (intro_classes) by (vector mult_idem)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   232
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   233
instance "^" :: (comm_monoid_mult,type) comm_monoid_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   234
  apply (intro_classes) by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   235
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   236
fun vector_power :: "('a::{one,times} ^'n) \<Rightarrow> nat \<Rightarrow> 'a^'n" where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   237
  "vector_power x 0 = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   238
  | "vector_power x (Suc n) = x * vector_power x n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   239
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   240
instantiation "^" :: (recpower,type) recpower 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   241
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   242
  definition vec_power_def: "op ^ \<equiv> vector_power"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   243
  instance 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   244
  apply (intro_classes) by (simp_all add: vec_power_def) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   245
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   246
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   247
instance "^" :: (semiring,type) semiring
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   248
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   249
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   250
instance "^" :: (semiring_0,type) semiring_0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   251
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   252
instance "^" :: (semiring_1,type) semiring_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   253
  apply (intro_classes) apply vector using dimindex_ge_1 by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   254
instance "^" :: (comm_semiring,type) comm_semiring
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   255
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   256
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   257
instance "^" :: (comm_semiring_0,type) comm_semiring_0 by (intro_classes) 
29905
26ee9656872a add instance for cancel_comm_monoid_add
huffman
parents: 29881
diff changeset
   258
instance "^" :: (cancel_comm_monoid_add, type) cancel_comm_monoid_add ..
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   259
instance "^" :: (semiring_0_cancel,type) semiring_0_cancel by (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   260
instance "^" :: (comm_semiring_0_cancel,type) comm_semiring_0_cancel by (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   261
instance "^" :: (ring,type) ring by (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   262
instance "^" :: (semiring_1_cancel,type) semiring_1_cancel by (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   263
instance "^" :: (comm_semiring_1,type) comm_semiring_1 by (intro_classes)
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   264
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   265
instance "^" :: (ring_1,type) ring_1 ..
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   266
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   267
instance "^" :: (real_algebra,type) real_algebra
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   268
  apply intro_classes
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   269
  apply (simp_all add: vector_scaleR_def ring_simps)
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   270
  apply vector
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   271
  apply vector
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   272
  done
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   273
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   274
instance "^" :: (real_algebra_1,type) real_algebra_1 ..
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   275
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   276
lemma of_nat_index: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   277
  "i\<in>{1 .. dimindex (UNIV :: 'n set)} \<Longrightarrow> (of_nat n :: 'a::semiring_1 ^'n)$i = of_nat n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   278
  apply (induct n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   279
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   280
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   281
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   282
lemma zero_index[simp]: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   283
  "i\<in>{1 .. dimindex (UNIV :: 'n set)} \<Longrightarrow> (0 :: 'a::zero ^'n)$i = 0" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   284
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   285
lemma one_index[simp]: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   286
  "i\<in>{1 .. dimindex (UNIV :: 'n set)} \<Longrightarrow> (1 :: 'a::one ^'n)$i = 1" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   287
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   288
lemma one_plus_of_nat_neq_0: "(1::'a::semiring_char_0) + of_nat n \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   289
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   290
  have "(1::'a) + of_nat n = 0 \<longleftrightarrow> of_nat 1 + of_nat n = (of_nat 0 :: 'a)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   291
  also have "\<dots> \<longleftrightarrow> 1 + n = 0" by (simp only: of_nat_add[symmetric] of_nat_eq_iff) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   292
  finally show ?thesis by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   293
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   294
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   295
instance "^" :: (semiring_char_0,type) semiring_char_0 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   296
proof (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   297
  fix m n ::nat
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   298
  show "(of_nat m :: 'a^'b) = of_nat n \<longleftrightarrow> m = n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   299
  proof(induct m arbitrary: n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   300
    case 0 thus ?case apply vector 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   301
      apply (induct n,auto simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   302
      using dimindex_ge_1 apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   303
      apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   304
      by (auto simp add: of_nat_index one_plus_of_nat_neq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   305
  next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   306
    case (Suc n m)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   307
    thus ?case  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   308
      apply (induct m, auto simp add: ring_simps of_nat_index zero_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   309
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   310
      apply (simp add: one_plus_of_nat_neq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   311
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   312
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   313
      apply (simp only: of_nat.simps(2)[where ?'a = 'a, symmetric] of_nat_eq_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   314
      using  dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   315
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   316
      apply (simp only: of_nat.simps(2)[where ?'a = 'a, symmetric] of_nat_eq_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   317
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   318
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   319
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   320
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   321
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   322
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   323
instance "^" :: (comm_ring_1,type) comm_ring_1 by intro_classes
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
   324
instance "^" :: (ring_char_0,type) ring_char_0 by intro_classes
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   325
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   326
lemma vector_smult_assoc: "a *s (b *s x) = ((a::'a::semigroup_mult) * b) *s x"  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   327
  by (vector mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   328
lemma vector_sadd_rdistrib: "((a::'a::semiring) + b) *s x = a *s x + b *s x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   329
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   330
lemma vector_add_ldistrib: "(c::'a::semiring) *s (x + y) = c *s x + c *s y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   331
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   332
lemma vector_smult_lzero[simp]: "(0::'a::mult_zero) *s x = 0" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   333
lemma vector_smult_lid[simp]: "(1::'a::monoid_mult) *s x = x" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   334
lemma vector_ssub_ldistrib: "(c::'a::ring) *s (x - y) = c *s x - c *s y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   335
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   336
lemma vector_smult_rneg: "(c::'a::ring) *s -x = -(c *s x)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   337
lemma vector_smult_lneg: "- (c::'a::ring) *s x = -(c *s x)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   338
lemma vector_sneg_minus1: "-x = (- (1::'a::ring_1)) *s x" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   339
lemma vector_smult_rzero[simp]: "c *s 0 = (0::'a::mult_zero ^ 'n)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   340
lemma vector_sub_rdistrib: "((a::'a::ring) - b) *s x = a *s x - b *s x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   341
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   342
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   343
lemma vec_eq[simp]: "(vec m = vec n) \<longleftrightarrow> (m = n)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   344
  apply (auto simp add: vec_def Cart_eq vec_component Cart_lambda_beta )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   345
  using dimindex_ge_1 apply auto done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   346
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   347
subsection {* Square root of sum of squares *}
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   348
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   349
definition
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   350
  "setL2 f A = sqrt (\<Sum>i\<in>A. (f i)\<twosuperior>)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   351
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   352
lemma setL2_cong:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   353
  "\<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> setL2 f A = setL2 g B"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   354
  unfolding setL2_def by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   355
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   356
lemma strong_setL2_cong:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   357
  "\<lbrakk>A = B; \<And>x. x \<in> B =simp=> f x = g x\<rbrakk> \<Longrightarrow> setL2 f A = setL2 g B"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   358
  unfolding setL2_def simp_implies_def by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   359
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   360
lemma setL2_infinite [simp]: "\<not> finite A \<Longrightarrow> setL2 f A = 0"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   361
  unfolding setL2_def by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   362
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   363
lemma setL2_empty [simp]: "setL2 f {} = 0"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   364
  unfolding setL2_def by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   365
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   366
lemma setL2_insert [simp]:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   367
  "\<lbrakk>finite F; a \<notin> F\<rbrakk> \<Longrightarrow>
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   368
    setL2 f (insert a F) = sqrt ((f a)\<twosuperior> + (setL2 f F)\<twosuperior>)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   369
  unfolding setL2_def by (simp add: setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   370
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   371
lemma setL2_nonneg [simp]: "0 \<le> setL2 f A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   372
  unfolding setL2_def by (simp add: setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   373
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   374
lemma setL2_0': "\<forall>a\<in>A. f a = 0 \<Longrightarrow> setL2 f A = 0"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   375
  unfolding setL2_def by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   376
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   377
lemma setL2_mono:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   378
  assumes "\<And>i. i \<in> K \<Longrightarrow> f i \<le> g i"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   379
  assumes "\<And>i. i \<in> K \<Longrightarrow> 0 \<le> f i"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   380
  shows "setL2 f K \<le> setL2 g K"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   381
  unfolding setL2_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   382
  by (simp add: setsum_nonneg setsum_mono power_mono prems)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   383
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   384
lemma setL2_right_distrib:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   385
  "0 \<le> r \<Longrightarrow> r * setL2 f A = setL2 (\<lambda>x. r * f x) A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   386
  unfolding setL2_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   387
  apply (simp add: power_mult_distrib)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   388
  apply (simp add: setsum_right_distrib [symmetric])
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   389
  apply (simp add: real_sqrt_mult setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   390
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   391
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   392
lemma setL2_left_distrib:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   393
  "0 \<le> r \<Longrightarrow> setL2 f A * r = setL2 (\<lambda>x. f x * r) A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   394
  unfolding setL2_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   395
  apply (simp add: power_mult_distrib)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   396
  apply (simp add: setsum_left_distrib [symmetric])
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   397
  apply (simp add: real_sqrt_mult setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   398
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   399
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   400
lemma setsum_nonneg_eq_0_iff:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   401
  fixes f :: "'a \<Rightarrow> 'b::pordered_ab_group_add"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   402
  shows "\<lbrakk>finite A; \<forall>x\<in>A. 0 \<le> f x\<rbrakk> \<Longrightarrow> setsum f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   403
  apply (induct set: finite, simp)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   404
  apply (simp add: add_nonneg_eq_0_iff setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   405
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   406
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   407
lemma setL2_eq_0_iff: "finite A \<Longrightarrow> setL2 f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   408
  unfolding setL2_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   409
  by (simp add: setsum_nonneg setsum_nonneg_eq_0_iff)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   410
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   411
lemma setL2_triangle_ineq:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   412
  shows "setL2 (\<lambda>i. f i + g i) A \<le> setL2 f A + setL2 g A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   413
proof (cases "finite A")
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   414
  case False
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   415
  thus ?thesis by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   416
next
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   417
  case True
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   418
  thus ?thesis
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   419
  proof (induct set: finite)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   420
    case empty
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   421
    show ?case by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   422
  next
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   423
    case (insert x F)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   424
    hence "sqrt ((f x + g x)\<twosuperior> + (setL2 (\<lambda>i. f i + g i) F)\<twosuperior>) \<le>
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   425
           sqrt ((f x + g x)\<twosuperior> + (setL2 f F + setL2 g F)\<twosuperior>)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   426
      by (intro real_sqrt_le_mono add_left_mono power_mono insert
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   427
                setL2_nonneg add_increasing zero_le_power2)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   428
    also have
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   429
      "\<dots> \<le> sqrt ((f x)\<twosuperior> + (setL2 f F)\<twosuperior>) + sqrt ((g x)\<twosuperior> + (setL2 g F)\<twosuperior>)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   430
      by (rule real_sqrt_sum_squares_triangle_ineq)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   431
    finally show ?case
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   432
      using insert by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   433
  qed
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   434
qed
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   435
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   436
lemma sqrt_sum_squares_le_sum:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   437
  "\<lbrakk>0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt (x\<twosuperior> + y\<twosuperior>) \<le> x + y"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   438
  apply (rule power2_le_imp_le)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   439
  apply (simp add: power2_sum)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   440
  apply (simp add: mult_nonneg_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   441
  apply (simp add: add_nonneg_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   442
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   443
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   444
lemma setL2_le_setsum [rule_format]:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   445
  "(\<forall>i\<in>A. 0 \<le> f i) \<longrightarrow> setL2 f A \<le> setsum f A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   446
  apply (cases "finite A")
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   447
  apply (induct set: finite)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   448
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   449
  apply clarsimp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   450
  apply (erule order_trans [OF sqrt_sum_squares_le_sum])
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   451
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   452
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   453
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   454
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   455
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   456
lemma sqrt_sum_squares_le_sum_abs: "sqrt (x\<twosuperior> + y\<twosuperior>) \<le> \<bar>x\<bar> + \<bar>y\<bar>"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   457
  apply (rule power2_le_imp_le)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   458
  apply (simp add: power2_sum)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   459
  apply (simp add: mult_nonneg_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   460
  apply (simp add: add_nonneg_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   461
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   462
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   463
lemma setL2_le_setsum_abs: "setL2 f A \<le> (\<Sum>i\<in>A. \<bar>f i\<bar>)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   464
  apply (cases "finite A")
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   465
  apply (induct set: finite)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   466
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   467
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   468
  apply (rule order_trans [OF sqrt_sum_squares_le_sum_abs])
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   469
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   470
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   471
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   472
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   473
lemma setL2_mult_ineq_lemma:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   474
  fixes a b c d :: real
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   475
  shows "2 * (a * c) * (b * d) \<le> a\<twosuperior> * d\<twosuperior> + b\<twosuperior> * c\<twosuperior>"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   476
proof -
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   477
  have "0 \<le> (a * d - b * c)\<twosuperior>" by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   478
  also have "\<dots> = a\<twosuperior> * d\<twosuperior> + b\<twosuperior> * c\<twosuperior> - 2 * (a * d) * (b * c)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   479
    by (simp only: power2_diff power_mult_distrib)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   480
  also have "\<dots> = a\<twosuperior> * d\<twosuperior> + b\<twosuperior> * c\<twosuperior> - 2 * (a * c) * (b * d)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   481
    by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   482
  finally show "2 * (a * c) * (b * d) \<le> a\<twosuperior> * d\<twosuperior> + b\<twosuperior> * c\<twosuperior>"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   483
    by simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   484
qed
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   485
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   486
lemma setL2_mult_ineq: "(\<Sum>i\<in>A. \<bar>f i\<bar> * \<bar>g i\<bar>) \<le> setL2 f A * setL2 g A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   487
  apply (cases "finite A")
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   488
  apply (induct set: finite)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   489
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   490
  apply (rule power2_le_imp_le, simp)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   491
  apply (rule order_trans)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   492
  apply (rule power_mono)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   493
  apply (erule add_left_mono)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   494
  apply (simp add: add_nonneg_nonneg mult_nonneg_nonneg setsum_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   495
  apply (simp add: power2_sum)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   496
  apply (simp add: power_mult_distrib)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   497
  apply (simp add: right_distrib left_distrib)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   498
  apply (rule ord_le_eq_trans)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   499
  apply (rule setL2_mult_ineq_lemma)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   500
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   501
  apply (intro mult_nonneg_nonneg setL2_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   502
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   503
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   504
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   505
lemma member_le_setL2: "\<lbrakk>finite A; i \<in> A\<rbrakk> \<Longrightarrow> f i \<le> setL2 f A"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   506
  apply (rule_tac s="insert i (A - {i})" and t="A" in subst)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   507
  apply fast
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   508
  apply (subst setL2_insert)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   509
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   510
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   511
  apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   512
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   513
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   514
subsection {* Norms *}
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   515
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   516
instantiation "^" :: (real_normed_vector, type) real_normed_vector
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   517
begin
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   518
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   519
definition vector_norm_def:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   520
  "norm (x::'a^'b) = setL2 (\<lambda>i. norm (x$i)) {1 .. dimindex (UNIV:: 'b set)}"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   521
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   522
definition vector_sgn_def:
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   523
  "sgn (x::'a^'b) = scaleR (inverse (norm x)) x"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   524
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   525
instance proof
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   526
  fix a :: real and x y :: "'a ^ 'b"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   527
  show "0 \<le> norm x"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   528
    unfolding vector_norm_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   529
    by (rule setL2_nonneg)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   530
  show "norm x = 0 \<longleftrightarrow> x = 0"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   531
    unfolding vector_norm_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   532
    by (simp add: setL2_eq_0_iff Cart_eq)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   533
  show "norm (x + y) \<le> norm x + norm y"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   534
    unfolding vector_norm_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   535
    apply (rule order_trans [OF _ setL2_triangle_ineq])
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   536
    apply (rule setL2_mono)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   537
    apply (simp add: vector_component norm_triangle_ineq)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   538
    apply simp
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   539
    done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   540
  show "norm (scaleR a x) = \<bar>a\<bar> * norm x"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   541
    unfolding vector_norm_def
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   542
    by (simp add: vector_component norm_scaleR setL2_right_distrib
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   543
             cong: strong_setL2_cong)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   544
  show "sgn x = scaleR (inverse (norm x)) x"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   545
    by (rule vector_sgn_def)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   546
qed
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   547
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   548
end
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   549
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   550
subsection{* Properties of the dot product.  *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   551
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   552
lemma dot_sym: "(x::'a:: {comm_monoid_add, ab_semigroup_mult} ^ 'n) \<bullet> y = y \<bullet> x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   553
  by (vector mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   554
lemma dot_ladd: "((x::'a::ring ^ 'n) + y) \<bullet> z = (x \<bullet> z) + (y \<bullet> z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   555
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   556
lemma dot_radd: "x \<bullet> (y + (z::'a::ring ^ 'n)) = (x \<bullet> y) + (x \<bullet> z)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   557
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   558
lemma dot_lsub: "((x::'a::ring ^ 'n) - y) \<bullet> z = (x \<bullet> z) - (y \<bullet> z)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   559
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   560
lemma dot_rsub: "(x::'a::ring ^ 'n) \<bullet> (y - z) = (x \<bullet> y) - (x \<bullet> z)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   561
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   562
lemma dot_lmult: "(c *s x) \<bullet> y = (c::'a::ring) * (x \<bullet> y)" by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   563
lemma dot_rmult: "x \<bullet> (c *s y) = (c::'a::comm_ring) * (x \<bullet> y)" by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   564
lemma dot_lneg: "(-x) \<bullet> (y::'a::ring ^ 'n) = -(x \<bullet> y)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   565
lemma dot_rneg: "(x::'a::ring ^ 'n) \<bullet> (-y) = -(x \<bullet> y)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   566
lemma dot_lzero[simp]: "0 \<bullet> x = (0::'a::{comm_monoid_add, mult_zero})" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   567
lemma dot_rzero[simp]: "x \<bullet> 0 = (0::'a::{comm_monoid_add, mult_zero})" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   568
lemma dot_pos_le[simp]: "(0::'a\<Colon>ordered_ring_strict) <= x \<bullet> x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   569
  by (simp add: dot_def setsum_nonneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   570
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   571
lemma setsum_squares_eq_0_iff: assumes fS: "finite F" and fp: "\<forall>x \<in> F. f x \<ge> (0 ::'a::pordered_ab_group_add)" shows "setsum f F = 0 \<longleftrightarrow> (ALL x:F. f x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   572
using fS fp setsum_nonneg[OF fp]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   573
proof (induct set: finite)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   574
  case empty thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   575
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   576
  case (insert x F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   577
  from insert.prems have Fx: "f x \<ge> 0" and Fp: "\<forall> a \<in> F. f a \<ge> 0" by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   578
  from insert.hyps Fp setsum_nonneg[OF Fp]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   579
  have h: "setsum f F = 0 \<longleftrightarrow> (\<forall>a \<in>F. f a = 0)" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   580
  from sum_nonneg_eq_zero_iff[OF Fx  setsum_nonneg[OF Fp]] insert.hyps(1,2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   581
  show ?case by (simp add: h)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   582
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   583
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   584
lemma dot_eq_0: "x \<bullet> x = 0 \<longleftrightarrow> (x::'a::{ordered_ring_strict,ring_no_zero_divisors} ^ 'n) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   585
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   586
  {assume f: "finite (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   587
    let ?S = "{Suc 0 .. card (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   588
    have fS: "finite ?S" using f by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   589
    have fp: "\<forall> i\<in> ?S. x$i * x$i>= 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   590
    have ?thesis by (vector dimindex_def f setsum_squares_eq_0_iff[OF fS fp])}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   591
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   592
  {assume "\<not> finite (UNIV :: 'n set)" then have ?thesis by (vector dimindex_def)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   593
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   594
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   595
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   596
lemma dot_pos_lt: "(0 < x \<bullet> x) \<longleftrightarrow> (x::'a::{ordered_ring_strict,ring_no_zero_divisors} ^ 'n) \<noteq> 0" using dot_eq_0[of x] dot_pos_le[of x] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   597
  by (auto simp add: le_less) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   598
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   599
subsection{* The collapse of the general concepts to dimension one. *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   600
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   601
lemma vector_one: "(x::'a ^1) = (\<chi> i. (x$1))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   602
  by (vector dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   603
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   604
lemma forall_one: "(\<forall>(x::'a ^1). P x) \<longleftrightarrow> (\<forall>x. P(\<chi> i. x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   605
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   606
  apply (erule_tac x= "x$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   607
  apply (simp only: vector_one[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   608
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   609
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   610
lemma norm_vector_1: "norm (x :: _^1) = norm (x$1)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   611
  by (simp add: vector_norm_def dimindex_def)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   612
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   613
lemma norm_real: "norm(x::real ^ 1) = abs(x$1)" 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   614
  by (simp add: norm_vector_1)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   615
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   616
text{* Metric *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   617
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   618
text {* FIXME: generalize to arbitrary @{text real_normed_vector} types *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   619
definition dist:: "real ^ 'n \<Rightarrow> real ^ 'n \<Rightarrow> real" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   620
  "dist x y = norm (x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   621
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   622
lemma dist_real: "dist(x::real ^ 1) y = abs((x$1) - (y$1))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   623
  using dimindex_ge_1[of "UNIV :: 1 set"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   624
  by (auto simp add: norm_real dist_def vector_component Cart_lambda_beta[where ?'a = "1"] )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   625
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   626
subsection {* A connectedness or intermediate value lemma with several applications. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   627
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   628
lemma connected_real_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   629
  fixes f :: "real \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   630
  assumes ab: "a \<le> b" and fa: "f a \<in> e1" and fb: "f b \<in> e2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   631
  and dst: "\<And>e x. a <= x \<Longrightarrow> x <= b \<Longrightarrow> 0 < e ==> \<exists>d > 0. \<forall>y. abs(y - x) < d \<longrightarrow> dist(f y) (f x) < e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   632
  and e1: "\<forall>y \<in> e1. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   633
  and e2: "\<forall>y \<in> e2. \<exists>e > 0. \<forall>y'. dist y' y < e \<longrightarrow> y' \<in> e2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   634
  and e12: "~(\<exists>x \<ge> a. x <= b \<and> f x \<in> e1 \<and> f x \<in> e2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   635
  shows "\<exists>x \<ge> a. x <= b \<and> f x \<notin> e1 \<and> f x \<notin> e2" (is "\<exists> x. ?P x")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   636
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   637
  let ?S = "{c. \<forall>x \<ge> a. x <= c \<longrightarrow> f x \<in> e1}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   638
  have Se: " \<exists>x. x \<in> ?S" apply (rule exI[where x=a]) by (auto simp add: fa) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   639
  have Sub: "\<exists>y. isUb UNIV ?S y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   640
    apply (rule exI[where x= b])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   641
    using ab fb e12 by (auto simp add: isUb_def setle_def)  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   642
  from reals_complete[OF Se Sub] obtain l where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   643
    l: "isLub UNIV ?S l"by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   644
  have alb: "a \<le> l" "l \<le> b" using l ab fa fb e12
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   645
    apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   646
    by (metis linorder_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   647
  have ale1: "\<forall>z \<ge> a. z < l \<longrightarrow> f z \<in> e1" using l
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   648
    apply (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   649
    by (metis linorder_linear not_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   650
    have th1: "\<And>z x e d :: real. z <= x + e \<Longrightarrow> e < d ==> z < x \<or> abs(z - x) < d" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   651
    have th2: "\<And>e x:: real. 0 < e ==> ~(x + e <= x)" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   652
    have th3: "\<And>d::real. d > 0 \<Longrightarrow> \<exists>e > 0. e < d" by dlo
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   653
    {assume le2: "f l \<in> e2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   654
      from le2 fa fb e12 alb have la: "l \<noteq> a" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   655
      hence lap: "l - a > 0" using alb by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   656
      from e2[rule_format, OF le2] obtain e where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   657
	e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e2" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   658
      from dst[OF alb e(1)] obtain d where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   659
	d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   660
      have "\<exists>d'. d' < d \<and> d' >0 \<and> l - d' > a" using lap d(1) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   661
	apply ferrack by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   662
      then obtain d' where d': "d' > 0" "d' < d" "l - d' > a" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   663
      from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e2" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   664
      from th0[rule_format, of "l - d'"] d' have "f (l - d') \<in> e2" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   665
      moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   666
      have "f (l - d') \<in> e1" using ale1[rule_format, of "l -d'"] d' by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   667
      ultimately have False using e12 alb d' by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   668
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   669
    {assume le1: "f l \<in> e1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   670
    from le1 fa fb e12 alb have lb: "l \<noteq> b" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   671
      hence blp: "b - l > 0" using alb by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   672
      from e1[rule_format, OF le1] obtain e where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   673
	e: "e > 0" "\<forall>y. dist y (f l) < e \<longrightarrow> y \<in> e1" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   674
      from dst[OF alb e(1)] obtain d where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   675
	d: "d > 0" "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> dist (f y) (f l) < e" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   676
      have "\<exists>d'. d' < d \<and> d' >0" using d(1) by dlo 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   677
      then obtain d' where d': "d' > 0" "d' < d" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   678
      from d e have th0: "\<forall>y. \<bar>y - l\<bar> < d \<longrightarrow> f y \<in> e1" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   679
      hence "\<forall>y. l \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" using d' by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   680
      with ale1 have "\<forall>y. a \<le> y \<and> y \<le> l + d' \<longrightarrow> f y \<in> e1" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   681
      with l d' have False 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   682
	by (auto simp add: isLub_def isUb_def setle_def setge_def leastP_def) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   683
    ultimately show ?thesis using alb by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   684
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   685
29881
58f3c48dbbb7 fix document generation
huffman
parents: 29844
diff changeset
   686
text{* One immediately useful corollary is the existence of square roots! --- Should help to get rid of all the development of square-root for reals as a special case @{typ "real^1"} *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   687
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   688
lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   689
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   690
  have "(x + 1/2)^2 + 3/4 > 0" using zero_le_power2[of "x+1/2"] by arith 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   691
  thus ?thesis by (simp add: ring_simps power2_eq_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   692
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   693
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   694
lemma square_continuous: "0 < (e::real) ==> \<exists>d. 0 < d \<and> (\<forall>y. abs(y - x) < d \<longrightarrow> abs(y * y - x * x) < e)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   695
  using isCont_power[OF isCont_ident, of 2, unfolded isCont_def LIM_def, rule_format, of e x] apply (auto simp add: power2_eq_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   696
  apply (rule_tac x="s" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   697
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   698
  apply (erule_tac x=y in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   699
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   700
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   701
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   702
lemma real_le_lsqrt: "0 <= x \<Longrightarrow> 0 <= y \<Longrightarrow> x <= y^2 ==> sqrt x <= y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   703
  using real_sqrt_le_iff[of x "y^2"] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   704
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   705
lemma real_le_rsqrt: "x^2 \<le> y \<Longrightarrow> x \<le> sqrt y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   706
  using real_sqrt_le_mono[of "x^2" y] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   707
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   708
lemma real_less_rsqrt: "x^2 < y \<Longrightarrow> x < sqrt y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   709
  using real_sqrt_less_mono[of "x^2" y] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   710
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   711
lemma sqrt_even_pow2: assumes n: "even n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   712
  shows "sqrt(2 ^ n) = 2 ^ (n div 2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   713
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   714
  from n obtain m where m: "n = 2*m" unfolding even_nat_equiv_def2 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   715
    by (auto simp add: nat_number) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   716
  from m  have "sqrt(2 ^ n) = sqrt ((2 ^ m) ^ 2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   717
    by (simp only: power_mult[symmetric] mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   718
  then show ?thesis  using m by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   719
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   720
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   721
lemma real_div_sqrt: "0 <= x ==> x / sqrt(x) = sqrt(x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   722
  apply (cases "x = 0", simp_all)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   723
  using sqrt_divide_self_eq[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   724
  apply (simp add: inverse_eq_divide real_sqrt_ge_0_iff field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   725
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   726
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   727
text{* Hence derive more interesting properties of the norm. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   728
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   729
lemma norm_0: "norm (0::real ^ 'n) = 0"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   730
  by (rule norm_zero)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   731
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   732
lemma norm_pos_le: "0 <= norm (x::real^'n)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   733
  by (rule norm_ge_zero)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   734
lemma norm_neg: " norm(-x) = norm (x:: real ^ 'n)" 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   735
  by (rule norm_minus_cancel)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   736
lemma norm_sub: "norm(x - y) = norm(y - (x::real ^ 'n))" 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   737
  by (rule norm_minus_commute)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   738
lemma norm_mul: "norm(a *s x) = abs(a) * norm x"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   739
  by (simp add: vector_norm_def vector_component setL2_right_distrib
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   740
           abs_mult cong: strong_setL2_cong)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   741
lemma norm_eq_0_dot: "(norm x = 0) \<longleftrightarrow> (x \<bullet> x = (0::real))"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   742
  by (simp add: vector_norm_def dot_def setL2_def power2_eq_square)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   743
lemma norm_eq_0: "norm x = 0 \<longleftrightarrow> x = (0::real ^ 'n)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   744
  by (rule norm_eq_zero)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   745
lemma norm_pos_lt: "0 < norm x \<longleftrightarrow> x \<noteq> (0::real ^ 'n)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   746
  by (rule zero_less_norm_iff)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   747
lemma real_vector_norm_def: "norm x = sqrt (x \<bullet> x)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   748
  by (simp add: vector_norm_def setL2_def dot_def power2_eq_square)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   749
lemma norm_pow_2: "norm x ^ 2 = x \<bullet> x"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   750
  by (simp add: real_vector_norm_def)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   751
lemma norm_eq_0_imp: "norm x = 0 ==> x = (0::real ^'n)" by (metis norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   752
lemma norm_le_0: "norm x <= 0 \<longleftrightarrow> x = (0::real ^'n)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   753
  by (rule norm_le_zero_iff)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   754
lemma vector_mul_eq_0: "(a *s x = 0) \<longleftrightarrow> a = (0::'a::idom) \<or> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   755
  by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   756
lemma vector_mul_lcancel: "a *s x = a *s y \<longleftrightarrow> a = (0::real) \<or> x = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   757
  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_ssub_ldistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   758
lemma vector_mul_rcancel: "a *s x = b *s x \<longleftrightarrow> (a::real) = b \<or> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   759
  by (metis eq_iff_diff_eq_0 vector_mul_eq_0 vector_sub_rdistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   760
lemma vector_mul_lcancel_imp: "a \<noteq> (0::real) ==>  a *s x = a *s y ==> (x = y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   761
  by (metis vector_mul_lcancel)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   762
lemma vector_mul_rcancel_imp: "x \<noteq> 0 \<Longrightarrow> (a::real) *s x = b *s x ==> a = b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   763
  by (metis vector_mul_rcancel)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   764
lemma norm_cauchy_schwarz: "x \<bullet> y <= norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   765
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   766
  {assume "norm x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   767
    hence ?thesis by (simp add: norm_eq_0 dot_lzero dot_rzero norm_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   768
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   769
  {assume "norm y = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   770
    hence ?thesis by (simp add: norm_eq_0 dot_lzero dot_rzero norm_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   771
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   772
  {assume h: "norm x \<noteq> 0" "norm y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   773
    let ?z = "norm y *s x - norm x *s y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   774
    from h have p: "norm x * norm y > 0" by (metis norm_pos_le le_less zero_compare_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   775
    from dot_pos_le[of ?z]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   776
    have "(norm x * norm y) * (x \<bullet> y) \<le> norm x ^2 * norm y ^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   777
      apply (simp add: dot_rsub dot_lsub dot_lmult dot_rmult ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   778
      by (simp add: norm_pow_2[symmetric] power2_eq_square dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   779
    hence "x\<bullet>y \<le> (norm x ^2 * norm y ^2) / (norm x * norm y)" using p
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   780
      by (simp add: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   781
    hence ?thesis using h by (simp add: power2_eq_square)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   782
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   783
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   784
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   785
lemma norm_abs: "abs (norm x) = norm (x::real ^'n)"
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   786
  by (rule abs_norm_cancel) (* already declared [simp] *)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   787
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   788
lemma norm_cauchy_schwarz_abs: "\<bar>x \<bullet> y\<bar> \<le> norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   789
  using norm_cauchy_schwarz[of x y] norm_cauchy_schwarz[of x "-y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   790
  by (simp add: real_abs_def dot_rneg norm_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   791
lemma norm_triangle: "norm(x + y) <= norm x + norm (y::real ^'n)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   792
  by (rule norm_triangle_ineq)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   793
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   794
lemma norm_triangle_sub: "norm (x::real ^'n) <= norm(y) + norm(x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   795
  using norm_triangle[of "y" "x - y"] by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   796
lemma norm_triangle_le: "norm(x::real ^'n) + norm y <= e ==> norm(x + y) <= e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   797
  by (metis order_trans norm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   798
lemma norm_triangle_lt: "norm(x::real ^'n) + norm(y) < e ==> norm(x + y) < e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   799
  by (metis basic_trans_rules(21) norm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   800
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   801
lemma setsum_delta: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   802
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   803
  shows "setsum (\<lambda>k. if k=a then b k else 0) S = (if a \<in> S then b a else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   804
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   805
  let ?f = "(\<lambda>k. if k=a then b k else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   806
  {assume a: "a \<notin> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   807
    hence "\<forall> k\<in> S. ?f k = 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   808
    hence ?thesis  using a by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   809
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   810
  {assume a: "a \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   811
    let ?A = "S - {a}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   812
    let ?B = "{a}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   813
    have eq: "S = ?A \<union> ?B" using a by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   814
    have dj: "?A \<inter> ?B = {}" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   815
    from fS have fAB: "finite ?A" "finite ?B" by auto  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   816
    have "setsum ?f S = setsum ?f ?A + setsum ?f ?B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   817
      using setsum_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   818
      by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   819
    then have ?thesis  using a by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   820
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   821
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   822
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   823
lemma component_le_norm: "i \<in> {1 .. dimindex(UNIV :: 'n set)} ==> \<bar>x$i\<bar> <= norm (x::real ^ 'n)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   824
  apply (simp add: vector_norm_def)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   825
  apply (rule member_le_setL2, simp_all)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   826
  done
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   827
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   828
lemma norm_bound_component_le: "norm(x::real ^ 'n) <= e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   829
                ==> \<forall>i \<in> {1 .. dimindex(UNIV:: 'n set)}. \<bar>x$i\<bar> <= e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   830
  by (metis component_le_norm order_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   831
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   832
lemma norm_bound_component_lt: "norm(x::real ^ 'n) < e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   833
                ==> \<forall>i \<in> {1 .. dimindex(UNIV:: 'n set)}. \<bar>x$i\<bar> < e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   834
  by (metis component_le_norm basic_trans_rules(21))
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   835
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   836
lemma norm_le_l1: "norm (x:: real ^'n) <= setsum(\<lambda>i. \<bar>x$i\<bar>) {1..dimindex(UNIV::'n set)}"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   837
  by (simp add: vector_norm_def setL2_le_setsum)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   838
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   839
lemma real_abs_norm: "\<bar> norm x\<bar> = norm (x :: real ^'n)" 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   840
  by (rule abs_norm_cancel)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   841
lemma real_abs_sub_norm: "\<bar>norm(x::real ^'n) - norm y\<bar> <= norm(x - y)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   842
  by (rule norm_triangle_ineq3)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   843
lemma norm_le: "norm(x::real ^ 'n) <= norm(y) \<longleftrightarrow> x \<bullet> x <= y \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   844
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   845
lemma norm_lt: "norm(x::real ^'n) < norm(y) \<longleftrightarrow> x \<bullet> x < y \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   846
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   847
lemma norm_eq: "norm (x::real ^'n) = norm y \<longleftrightarrow> x \<bullet> x = y \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   848
  by (simp add: order_eq_iff norm_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   849
lemma norm_eq_1: "norm(x::real ^ 'n) = 1 \<longleftrightarrow> x \<bullet> x = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   850
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   851
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   852
text{* Squaring equations and inequalities involving norms.  *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   853
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   854
lemma dot_square_norm: "x \<bullet> x = norm(x)^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   855
  by (simp add: real_vector_norm_def  dot_pos_le )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   856
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   857
lemma norm_eq_square: "norm(x) = a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x = a^2"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   858
  by (auto simp add: real_vector_norm_def)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   859
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   860
lemma real_abs_le_square_iff: "\<bar>x\<bar> \<le> \<bar>y\<bar> \<longleftrightarrow> (x::real)^2 \<le> y^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   861
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   862
  have "x^2 \<le> y^2 \<longleftrightarrow> (x -y) * (y + x) \<le> 0" by (simp add: ring_simps power2_eq_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   863
  also have "\<dots> \<longleftrightarrow> \<bar>x\<bar> \<le> \<bar>y\<bar>" apply (simp add: zero_compare_simps real_abs_def not_less) by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   864
finally show ?thesis ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   865
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   866
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   867
lemma norm_le_square: "norm(x) <= a \<longleftrightarrow> 0 <= a \<and> x \<bullet> x <= a^2"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   868
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   869
  using norm_pos_le[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   870
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   871
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   872
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   873
lemma norm_ge_square: "norm(x) >= a \<longleftrightarrow> a <= 0 \<or> x \<bullet> x >= a ^ 2" 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
   874
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   875
  using norm_pos_le[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   876
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   877
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   878
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   879
lemma norm_lt_square: "norm(x) < a \<longleftrightarrow> 0 < a \<and> x \<bullet> x < a^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   880
  by (metis not_le norm_ge_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   881
lemma norm_gt_square: "norm(x) > a \<longleftrightarrow> a < 0 \<or> x \<bullet> x > a^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   882
  by (metis norm_le_square not_less)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   883
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   884
text{* Dot product in terms of the norm rather than conversely. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   885
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   886
lemma dot_norm: "x \<bullet> y = (norm(x + y) ^2 - norm x ^ 2 - norm y ^ 2) / 2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   887
  by (simp add: norm_pow_2 dot_ladd dot_radd dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   888
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   889
lemma dot_norm_neg: "x \<bullet> y = ((norm x ^ 2 + norm y ^ 2) - norm(x - y) ^ 2) / 2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   890
  by (simp add: norm_pow_2 dot_ladd dot_radd dot_lsub dot_rsub dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   891
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   892
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   893
text{* Equality of vectors in terms of @{term "op \<bullet>"} products.    *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   894
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   895
lemma vector_eq: "(x:: real ^ 'n) = y \<longleftrightarrow> x \<bullet> x = x \<bullet> y\<and> y \<bullet> y = x \<bullet> x" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   896
proof
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   897
  assume "?lhs" then show ?rhs by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   898
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   899
  assume ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   900
  then have "x \<bullet> x - x \<bullet> y = 0 \<and> x \<bullet> y - y\<bullet> y = 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   901
  hence "x \<bullet> (x - y) = 0 \<and> y \<bullet> (x - y) = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   902
    by (simp add: dot_rsub dot_lsub dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   903
  then have "(x - y) \<bullet> (x - y) = 0" by (simp add: ring_simps dot_lsub dot_rsub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   904
  then show "x = y" by (simp add: dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   905
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   906
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   907
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   908
subsection{* General linear decision procedure for normed spaces. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   909
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   910
lemma norm_cmul_rule_thm: "b >= norm(x) ==> \<bar>c\<bar> * b >= norm(c *s x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   911
  apply (clarsimp simp add: norm_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   912
  apply (rule mult_mono1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   913
  apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   914
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   915
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   916
lemma norm_add_rule_thm: "b1 >= norm(x1 :: real ^'n) \<Longrightarrow> b2 >= norm(x2) ==> b1 + b2 >= norm(x1 + x2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   917
  apply (rule norm_triangle_le) by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   918
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   919
lemma ge_iff_diff_ge_0: "(a::'a::ordered_ring) \<ge> b == a - b \<ge> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   920
  by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   921
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   922
lemma pth_1: "(x::real^'n) == 1 *s x" by (simp only: vector_smult_lid)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   923
lemma pth_2: "x - (y::real^'n) == x + -y" by (atomize (full)) simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   924
lemma pth_3: "(-x::real^'n) == -1 *s x" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   925
lemma pth_4: "0 *s (x::real^'n) == 0" "c *s 0 = (0::real ^ 'n)" by vector+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   926
lemma pth_5: "c *s (d *s x) == (c * d) *s (x::real ^ 'n)" by (atomize (full)) vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   927
lemma pth_6: "(c::real) *s (x + y) == c *s x + c *s y" by (atomize (full)) (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   928
lemma pth_7: "0 + x == (x::real^'n)" "x + 0 == x" by simp_all 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   929
lemma pth_8: "(c::real) *s x + d *s x == (c + d) *s x" by (atomize (full)) (vector ring_simps) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   930
lemma pth_9: "((c::real) *s x + z) + d *s x == (c + d) *s x + z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   931
  "c *s x + (d *s x + z) == (c + d) *s x + z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   932
  "(c *s x + w) + (d *s x + z) == (c + d) *s x + (w + z)" by ((atomize (full)), vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   933
lemma pth_a: "(0::real) *s x + y == y" by (atomize (full)) vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   934
lemma pth_b: "(c::real) *s x + d *s y == c *s x + d *s y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   935
  "(c *s x + z) + d *s y == c *s x + (z + d *s y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   936
  "c *s x + (d *s y + z) == c *s x + (d *s y + z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   937
  "(c *s x + w) + (d *s y + z) == c *s x + (w + (d *s y + z))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   938
  by ((atomize (full)), vector)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   939
lemma pth_c: "(c::real) *s x + d *s y == d *s y + c *s x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   940
  "(c *s x + z) + d *s y == d *s y + (c *s x + z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   941
  "c *s x + (d *s y + z) == d *s y + (c *s x + z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   942
  "(c *s x + w) + (d *s y + z) == d *s y + ((c *s x + w) + z)" by ((atomize (full)), vector)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   943
lemma pth_d: "x + (0::real ^'n) == x" by (atomize (full)) vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   944
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   945
lemma norm_imp_pos_and_ge: "norm (x::real ^ 'n) == n \<Longrightarrow> norm x \<ge> 0 \<and> n \<ge> norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   946
  by (atomize) (auto simp add: norm_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   947
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   948
lemma real_eq_0_iff_le_ge_0: "(x::real) = 0 == x \<ge> 0 \<and> -x \<ge> 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   949
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   950
lemma norm_pths: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   951
  "(x::real ^'n) = y \<longleftrightarrow> norm (x - y) \<le> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   952
  "x \<noteq> y \<longleftrightarrow> \<not> (norm (x - y) \<le> 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   953
  using norm_pos_le[of "x - y"] by (auto simp add: norm_0 norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   954
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   955
use "normarith.ML"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   956
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   957
method_setup norm = {* Method.ctxt_args (Method.SIMPLE_METHOD' o NormArith.norm_arith_tac)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   958
*} "Proves simple linear statements about vector norms"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   959
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   960
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   961
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   962
text{* Hence more metric properties. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   963
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   964
lemma dist_refl: "dist x x = 0" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   965
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   966
lemma dist_sym: "dist x y = dist y x"by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   967
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   968
lemma dist_pos_le: "0 <= dist x y" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   969
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   970
lemma dist_triangle: "dist x z <= dist x y + dist y z" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   971
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   972
lemma dist_triangle_alt: "dist y z <= dist x y + dist x z" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   973
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   974
lemma dist_eq_0: "dist x y = 0 \<longleftrightarrow> x = y" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   975
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   976
lemma dist_pos_lt: "x \<noteq> y ==> 0 < dist x y" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   977
lemma dist_nz:  "x \<noteq> y \<longleftrightarrow> 0 < dist x y" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   978
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   979
lemma dist_triangle_le: "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   980
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   981
lemma dist_triangle_lt: "dist x z + dist y z < e ==> dist x y < e" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   982
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   983
lemma dist_triangle_half_l: "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 ==> dist x1 x2 < e" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   984
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   985
lemma dist_triangle_half_r: "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 ==> dist x1 x2 < e" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   986
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   987
lemma dist_triangle_add: "dist (x + y) (x' + y') <= dist x x' + dist y y'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   988
  by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   989
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   990
lemma dist_mul: "dist (c *s x) (c *s y) = \<bar>c\<bar> * dist x y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   991
  unfolding dist_def vector_ssub_ldistrib[symmetric] norm_mul .. 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   992
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   993
lemma dist_triangle_add_half: " dist x x' < e / 2 \<Longrightarrow> dist y y' < e / 2 ==> dist(x + y) (x' + y') < e" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   994
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   995
lemma dist_le_0: "dist x y <= 0 \<longleftrightarrow> x = y" by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   996
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   997
instantiation "^" :: (monoid_add,type) monoid_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   998
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   999
  instance by (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1000
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1001
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1002
lemma setsum_eq: "setsum f S = (\<chi> i. setsum (\<lambda>x. (f x)$i ) S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1003
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1004
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1005
  apply (cases "finite S")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1006
  apply (rule finite_induct[of S])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1007
  apply (auto simp add: vector_component zero_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1008
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1009
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1010
lemma setsum_clauses: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1011
  shows "setsum f {} = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1012
  and "finite S \<Longrightarrow> setsum f (insert x S) =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1013
                 (if x \<in> S then setsum f S else f x + setsum f S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1014
  by (auto simp add: insert_absorb)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1015
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1016
lemma setsum_cmul: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1017
  fixes f:: "'c \<Rightarrow> ('a::semiring_1)^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1018
  shows "setsum (\<lambda>x. c *s f x) S = c *s setsum f S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1019
  by (simp add: setsum_eq Cart_eq Cart_lambda_beta vector_component setsum_right_distrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1020
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1021
lemma setsum_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1022
  fixes f:: " 'a \<Rightarrow> ('b::semiring_1) ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1023
  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1024
  shows "(setsum f S)$i = setsum (\<lambda>x. (f x)$i) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1025
  using i by (simp add: setsum_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1026
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1027
  (* This needs finiteness assumption due to the definition of fold!!! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1028
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1029
lemma setsum_superset:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1030
  assumes fb: "finite B" and ab: "A \<subseteq> B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1031
  and f0: "\<forall>x \<in> B - A. f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1032
  shows "setsum f B = setsum f A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1033
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1034
  from ab fb have fa: "finite A" by (metis finite_subset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1035
  from fb have fba: "finite (B - A)" by (metis finite_Diff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1036
  have d: "A \<inter> (B - A) = {}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1037
  from ab have b: "B = A \<union> (B - A)" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1038
  from setsum_Un_disjoint[OF fa fba d, of f] b
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1039
    setsum_0'[OF f0]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1040
  show "setsum f B = setsum f A" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1041
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1042
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1043
lemma setsum_restrict_set:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1044
  assumes fA: "finite A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1045
  shows "setsum f (A \<inter> B) = setsum (\<lambda>x. if x \<in> B then f x else 0) A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1046
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1047
  from fA have fab: "finite (A \<inter> B)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1048
  have aba: "A \<inter> B \<subseteq> A" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1049
  let ?g = "\<lambda>x. if x \<in> A\<inter>B then f x else 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1050
  from setsum_superset[OF fA aba, of ?g]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1051
  show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1052
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1053
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1054
lemma setsum_cases:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1055
  assumes fA: "finite A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1056
  shows "setsum (\<lambda>x. if x \<in> B then f x else g x) A =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1057
         setsum f (A \<inter> B) + setsum g (A \<inter> - B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1058
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1059
  have a: "A = A \<inter> B \<union> A \<inter> -B" "(A \<inter> B) \<inter> (A \<inter> -B) = {}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1060
    by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1061
  from fA 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1062
  have f: "finite (A \<inter> B)" "finite (A \<inter> -B)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1063
  let ?g = "\<lambda>x. if x \<in> B then f x else g x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1064
  from setsum_Un_disjoint[OF f a(2), of ?g] a(1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1065
  show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1066
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1067
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1068
lemma setsum_norm: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1069
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1070
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1071
  shows "norm (setsum f S) <= setsum (\<lambda>x. norm(f x)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1072
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1073
  case 1 thus ?case by (simp add: norm_zero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1074
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1075
  case (2 x S)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1076
  from "2.hyps" have "norm (setsum f (insert x S)) \<le> norm (f x) + norm (setsum f S)" by (simp add: norm_triangle_ineq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1077
  also have "\<dots> \<le> norm (f x) + setsum (\<lambda>x. norm(f x)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1078
    using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1079
  finally  show ?case  using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1080
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1081
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1082
lemma real_setsum_norm: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1083
  fixes f :: "'a \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1084
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1085
  shows "norm (setsum f S) <= setsum (\<lambda>x. norm(f x)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1086
proof(induct rule: finite_induct[OF fS])
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  1087
  case 1 thus ?case by simp
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1088
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1089
  case (2 x S)
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  1090
  from "2.hyps" have "norm (setsum f (insert x S)) \<le> norm (f x) + norm (setsum f S)" by (simp add: norm_triangle_ineq)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1091
  also have "\<dots> \<le> norm (f x) + setsum (\<lambda>x. norm(f x)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1092
    using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1093
  finally  show ?case  using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1094
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1095
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1096
lemma setsum_norm_le: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1097
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1098
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1099
  and fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1100
  shows "norm (setsum f S) \<le> setsum g S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1101
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1102
  from fg have "setsum (\<lambda>x. norm(f x)) S <= setsum g S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1103
    by - (rule setsum_mono, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1104
  then show ?thesis using setsum_norm[OF fS, of f] fg
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1105
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1106
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1107
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1108
lemma real_setsum_norm_le: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1109
  fixes f :: "'a \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1110
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1111
  and fg: "\<forall>x \<in> S. norm (f x) \<le> g x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1112
  shows "norm (setsum f S) \<le> setsum g S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1113
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1114
  from fg have "setsum (\<lambda>x. norm(f x)) S <= setsum g S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1115
    by - (rule setsum_mono, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1116
  then show ?thesis using real_setsum_norm[OF fS, of f] fg
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1117
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1118
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1119
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1120
lemma setsum_norm_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1121
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1122
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1123
  and K: "\<forall>x \<in> S. norm (f x) \<le> K"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1124
  shows "norm (setsum f S) \<le> of_nat (card S) * K"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1125
  using setsum_norm_le[OF fS K] setsum_constant[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1126
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1127
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1128
lemma real_setsum_norm_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1129
  fixes f :: "'a \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1130
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1131
  and K: "\<forall>x \<in> S. norm (f x) \<le> K"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1132
  shows "norm (setsum f S) \<le> of_nat (card S) * K"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1133
  using real_setsum_norm_le[OF fS K] setsum_constant[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1134
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1135
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1136
lemma setsum_vmul:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1137
  fixes f :: "'a \<Rightarrow> 'b::{real_normed_vector,semiring, mult_zero}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1138
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1139
  shows "setsum f S *s v = setsum (\<lambda>x. f x *s v) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1140
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1141
  case 1 then show ?case by (simp add: vector_smult_lzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1142
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1143
  case (2 x F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1144
  from "2.hyps" have "setsum f (insert x F) *s v = (f x + setsum f F) *s v" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1145
    by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1146
  also have "\<dots> = f x *s v + setsum f F *s v" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1147
    by (simp add: vector_sadd_rdistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1148
  also have "\<dots> = setsum (\<lambda>x. f x *s v) (insert x F)" using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1149
  finally show ?case .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1150
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1151
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1152
(* FIXME : Problem thm setsum_vmul[of _ "f:: 'a \<Rightarrow> real ^'n"]  ---
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1153
 Get rid of *s and use real_vector instead! Also prove that ^ creates a real_vector !! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1154
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1155
lemma setsum_add_split: assumes mn: "(m::nat) \<le> n + 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1156
  shows "setsum f {m..n + p} = setsum f {m..n} + setsum f {n + 1..n + p}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1157
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1158
  let ?A = "{m .. n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1159
  let ?B = "{n + 1 .. n + p}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1160
  have eq: "{m .. n+p} = ?A \<union> ?B" using mn by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1161
  have d: "?A \<inter> ?B = {}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1162
  from setsum_Un_disjoint[of "?A" "?B" f] eq d show ?thesis by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1163
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1164
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1165
lemma setsum_reindex_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1166
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1167
  and nz: "\<And> x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x \<noteq> y \<Longrightarrow> f x = f y \<Longrightarrow> h (f x) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1168
  shows "setsum h (f ` S) = setsum (h o f) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1169
using nz
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1170
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1171
  case 1 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1172
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1173
  case (2 x F) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1174
  {assume fxF: "f x \<in> f ` F" hence "\<exists>y \<in> F . f y = f x" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1175
    then obtain y where y: "y \<in> F" "f x = f y" by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1176
    from "2.hyps" y have xy: "x \<noteq> y" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1177
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1178
    from "2.prems"[of x y] "2.hyps" xy y have h0: "h (f x) = 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1179
    have "setsum h (f ` insert x F) = setsum h (f ` F)" using fxF by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1180
    also have "\<dots> = setsum (h o f) (insert x F)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1181
      using "2.hyps" "2.prems" h0  by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1182
    finally have ?case .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1183
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1184
  {assume fxF: "f x \<notin> f ` F"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1185
    have "setsum h (f ` insert x F) = h (f x) + setsum h (f ` F)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1186
      using fxF "2.hyps" by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1187
    also have "\<dots> = setsum (h o f) (insert x F)"  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1188
      using "2.hyps" "2.prems" fxF
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1189
      apply auto apply metis done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1190
    finally have ?case .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1191
  ultimately show ?case by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1192
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1193
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1194
lemma setsum_Un_nonzero:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1195
  assumes fS: "finite S" and fF: "finite F"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1196
  and f: "\<forall> x\<in> S \<inter> F . f x = (0::'a::ab_group_add)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1197
  shows "setsum f (S \<union> F) = setsum f S + setsum f F"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1198
  using setsum_Un[OF fS fF, of f] setsum_0'[OF f] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1199
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1200
lemma setsum_natinterval_left:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1201
  assumes mn: "(m::nat) <= n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1202
  shows "setsum f {m..n} = f m + setsum f {m + 1..n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1203
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1204
  from mn have "{m .. n} = insert m {m+1 .. n}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1205
  then show ?thesis by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1206
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1207
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1208
lemma setsum_natinterval_difff: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1209
  fixes f:: "nat \<Rightarrow> ('a::ab_group_add)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1210
  shows  "setsum (\<lambda>k. f k - f(k + 1)) {(m::nat) .. n} =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1211
          (if m <= n then f m - f(n + 1) else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1212
by (induct n, auto simp add: ring_simps not_le le_Suc_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1213
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1214
lemmas setsum_restrict_set' = setsum_restrict_set[unfolded Int_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1215
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1216
lemma setsum_setsum_restrict:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1217
  "finite S \<Longrightarrow> finite T \<Longrightarrow> setsum (\<lambda>x. setsum (\<lambda>y. f x y) {y. y\<in> T \<and> R x y}) S = setsum (\<lambda>y. setsum (\<lambda>x. f x y) {x. x \<in> S \<and> R x y}) T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1218
  apply (simp add: setsum_restrict_set'[unfolded mem_def] mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1219
  by (rule setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1220
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1221
lemma setsum_image_gen: assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1222
  shows "setsum g S = setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1223
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1224
  {fix x assume "x \<in> S" then have "{y. y\<in> f`S \<and> f x = y} = {f x}" by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1225
  note th0 = this
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1226
  have "setsum g S = setsum (\<lambda>x. setsum (\<lambda>y. g x) {y. y\<in> f`S \<and> f x = y}) S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1227
    apply (rule setsum_cong2) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1228
    by (simp add: th0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1229
  also have "\<dots> = setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1230
    apply (rule setsum_setsum_restrict[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1231
    by (rule finite_imageI[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1232
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1233
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1234
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1235
    (* FIXME: Here too need stupid finiteness assumption on T!!! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1236
lemma setsum_group:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1237
  assumes fS: "finite S" and fT: "finite T" and fST: "f ` S \<subseteq> T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1238
  shows "setsum (\<lambda>y. setsum g {x. x\<in> S \<and> f x = y}) T = setsum g S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1239
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1240
apply (subst setsum_image_gen[OF fS, of g f])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1241
apply (rule setsum_superset[OF fT fST])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1242
by (auto intro: setsum_0')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1243
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1244
(* FIXME: Change the name to fold_image\<dots> *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1245
lemma (in comm_monoid_mult) fold_1': "finite S \<Longrightarrow> (\<forall>x\<in>S. f x = 1) \<Longrightarrow> fold_image op * f 1 S = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1246
  apply (induct set: finite)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1247
  apply simp by (auto simp add: fold_image_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1248
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1249
lemma (in comm_monoid_mult) fold_union_nonzero:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1250
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1251
  and I0: "\<forall>x \<in> S\<inter>T. f x = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1252
  shows "fold_image (op *) f 1 (S \<union> T) = fold_image (op *) f 1 S * fold_image (op *) f 1 T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1253
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1254
  have "fold_image op * f 1 (S \<inter> T) = 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1255
    apply (rule fold_1')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1256
    using fS fT I0 by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1257
  with fold_image_Un_Int[OF fS fT] show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1258
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1259
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1260
lemma setsum_union_nonzero:  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1261
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1262
  and I0: "\<forall>x \<in> S\<inter>T. f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1263
  shows "setsum f (S \<union> T) = setsum f S  + setsum f T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1264
  using fS fT
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1265
  apply (simp add: setsum_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1266
  apply (rule comm_monoid_add.fold_union_nonzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1267
  using I0 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1268
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1269
lemma setprod_union_nonzero:  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1270
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1271
  and I0: "\<forall>x \<in> S\<inter>T. f x = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1272
  shows "setprod f (S \<union> T) = setprod f S  * setprod f T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1273
  using fS fT
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1274
  apply (simp add: setprod_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1275
  apply (rule fold_union_nonzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1276
  using I0 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1277
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1278
lemma setsum_unions_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1279
  assumes fS: "finite S" and fSS: "\<forall>T \<in> S. finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1280
  and f0: "\<And>T1 T2 x. T1\<in>S \<Longrightarrow> T2\<in>S \<Longrightarrow> T1 \<noteq> T2 \<Longrightarrow> x \<in> T1 \<Longrightarrow> x \<in> T2 \<Longrightarrow> f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1281
  shows "setsum f (\<Union>S) = setsum (\<lambda>T. setsum f T) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1282
  using fSS f0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1283
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1284
  case 1 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1285
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1286
  case (2 T F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1287
  then have fTF: "finite T" "\<forall>T\<in>F. finite T" "finite F" and TF: "T \<notin> F" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1288
    and H: "setsum f (\<Union> F) = setsum (setsum f) F" by (auto simp add: finite_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1289
  from fTF have fUF: "finite (\<Union>F)" by (auto intro: finite_Union)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1290
  from "2.prems" TF fTF
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1291
  show ?case 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1292
    by (auto simp add: H[symmetric] intro: setsum_union_nonzero[OF fTF(1) fUF, of f])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1293
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1294
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1295
  (* FIXME : Copied from Pocklington --- should be moved to Finite_Set!!!!!!!! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1296
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1297
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1298
lemma (in comm_monoid_mult) fold_related: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1299
  assumes Re: "R e e" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1300
  and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1301
  and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1302
  shows "R (fold_image (op *) h e S) (fold_image (op *) g e S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1303
  using fS by (rule finite_subset_induct) (insert assms, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1304
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1305
  (* FIXME: I think we can get rid of the finite assumption!! *)	
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1306
lemma (in comm_monoid_mult) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1307
  fold_eq_general:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1308
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1309
  and h: "\<forall>y\<in>S'. \<exists>!x. x\<in> S \<and> h(x) = y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1310
  and f12:  "\<forall>x\<in>S. h x \<in> S' \<and> f2(h x) = f1 x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1311
  shows "fold_image (op *) f1 e S = fold_image (op *) f2 e S'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1312
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1313
  from h f12 have hS: "h ` S = S'" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1314
  {fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1315
    from f12 h H  have "x = y" by auto }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1316
  hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1317
  from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1318
  from hS have "fold_image (op *) f2 e S' = fold_image (op *) f2 e (h ` S)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1319
  also have "\<dots> = fold_image (op *) (f2 o h) e S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1320
    using fold_image_reindex[OF fS hinj, of f2 e] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1321
  also have "\<dots> = fold_image (op *) f1 e S " using th fold_image_cong[OF fS, of "f2 o h" f1 e]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1322
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1323
  finally show ?thesis ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1324
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1325
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1326
lemma (in comm_monoid_mult) fold_eq_general_inverses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1327
  assumes fS: "finite S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1328
  and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1329
  and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x  \<and> g (h x) = f x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1330
  shows "fold_image (op *) f e S = fold_image (op *) g e T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1331
  using fold_eq_general[OF fS, of T h g f e] kh hk by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1332
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1333
lemma setsum_eq_general_reverses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1334
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1335
  and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1336
  and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x  \<and> g (h x) = f x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1337
  shows "setsum f S = setsum g T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1338
  apply (simp add: setsum_def fS fT)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1339
  apply (rule comm_monoid_add.fold_eq_general_inverses[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1340
  apply (erule kh)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1341
  apply (erule hk)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1342
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1343
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1344
lemma vsum_norm_allsubsets_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1345
  fixes f:: "'a \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1346
  assumes fP: "finite P" and fPs: "\<And>Q. Q \<subseteq> P \<Longrightarrow> norm (setsum f Q) \<le> e" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1347
  shows "setsum (\<lambda>x. norm (f x)) P \<le> 2 * real (dimindex(UNIV :: 'n set)) *  e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1348
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1349
  let ?d = "real (dimindex (UNIV ::'n set))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1350
  let ?nf = "\<lambda>x. norm (f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1351
  let ?U = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1352
  have th0: "setsum (\<lambda>x. setsum (\<lambda>i. \<bar>f x $ i\<bar>) ?U) P = setsum (\<lambda>i. setsum (\<lambda>x. \<bar>f x $ i\<bar>) P) ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1353
    by (rule setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1354
  have th1: "2 * ?d * e = of_nat (card ?U) * (2 * e)" by (simp add: real_of_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1355
  have "setsum ?nf P \<le> setsum (\<lambda>x. setsum (\<lambda>i. \<bar>f x $ i\<bar>) ?U) P"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1356
    apply (rule setsum_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1357
    by (rule norm_le_l1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1358
  also have "\<dots> \<le> 2 * ?d * e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1359
    unfolding th0 th1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1360
  proof(rule setsum_bounded)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1361
    fix i assume i: "i \<in> ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1362
    let ?Pp = "{x. x\<in> P \<and> f x $ i \<ge> 0}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1363
    let ?Pn = "{x. x \<in> P \<and> f x $ i < 0}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1364
    have thp: "P = ?Pp \<union> ?Pn" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1365
    have thp0: "?Pp \<inter> ?Pn ={}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1366
    have PpP: "?Pp \<subseteq> P" and PnP: "?Pn \<subseteq> P" by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1367
    have Ppe:"setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pp \<le> e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1368
      using i component_le_norm[OF i, of "setsum (\<lambda>x. f x) ?Pp"]  fPs[OF PpP]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1369
      by (auto simp add: setsum_component intro: abs_le_D1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1370
    have Pne: "setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pn \<le> e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1371
      using i component_le_norm[OF i, of "setsum (\<lambda>x. - f x) ?Pn"]  fPs[OF PnP]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1372
      by (auto simp add: setsum_negf norm_neg setsum_component vector_component intro: abs_le_D1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1373
    have "setsum (\<lambda>x. \<bar>f x $ i\<bar>) P = setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pp + setsum (\<lambda>x. \<bar>f x $ i\<bar>) ?Pn" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1374
      apply (subst thp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1375
      apply (rule setsum_Un_nonzero) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1376
      using fP thp0 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1377
    also have "\<dots> \<le> 2*e" using Pne Ppe by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1378
    finally show "setsum (\<lambda>x. \<bar>f x $ i\<bar>) P \<le> 2*e" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1379
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1380
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1381
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1382
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1383
lemma dot_lsum: "finite S \<Longrightarrow> setsum f S \<bullet> (y::'a::{comm_ring}^'n) = setsum (\<lambda>x. f x \<bullet> y) S "
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1384
  by (induct rule: finite_induct, auto simp add: dot_lzero dot_ladd)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1385
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1386
lemma dot_rsum: "finite S \<Longrightarrow> (y::'a::{comm_ring}^'n) \<bullet> setsum f S = setsum (\<lambda>x. y \<bullet> f x) S "
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1387
  by (induct rule: finite_induct, auto simp add: dot_rzero dot_radd)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1388
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1389
subsection{* Basis vectors in coordinate directions. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1390
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1391
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1392
definition "basis k = (\<chi> i. if i = k then 1 else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1393
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1394
lemma delta_mult_idempotent: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1395
  "(if k=a then 1 else (0::'a::semiring_1)) * (if k=a then 1 else 0) = (if k=a then 1 else 0)" by (cases "k=a", auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1396
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1397
lemma norm_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1398
  assumes k: "k \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1399
  shows "norm (basis k :: real ^'n) = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1400
  using k 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1401
  apply (simp add: basis_def real_vector_norm_def dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1402
  apply (vector delta_mult_idempotent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1403
  using setsum_delta[of "{1 .. dimindex (UNIV :: 'n set)}" "k" "\<lambda>k. 1::real"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1404
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1405
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1406
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1407
lemma norm_basis_1: "norm(basis 1 :: real ^'n) = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1408
  apply (simp add: basis_def real_vector_norm_def dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1409
  apply (vector delta_mult_idempotent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1410
  using setsum_delta[of "{1 .. dimindex (UNIV :: 'n set)}" "1" "\<lambda>k. 1::real"] dimindex_nonzero[of "UNIV :: 'n set"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1411
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1412
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1413
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1414
lemma vector_choose_size: "0 <= c ==> \<exists>(x::real^'n). norm x = c"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1415
  apply (rule exI[where x="c *s basis 1"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1416
  by (simp only: norm_mul norm_basis_1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1417
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1418
lemma vector_choose_dist: assumes e: "0 <= e" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1419
  shows "\<exists>(y::real^'n). dist x y = e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1420
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1421
  from vector_choose_size[OF e] obtain c:: "real ^'n"  where "norm c = e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1422
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1423
  then have "dist x (x - c) = e" by (simp add: dist_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1424
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1425
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1426
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1427
lemma basis_inj: "inj_on (basis :: nat \<Rightarrow> real ^'n) {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1428
  by (auto simp add: inj_on_def basis_def Cart_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1429
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1430
lemma basis_component: "i \<in> {1 .. dimindex(UNIV:: 'n set)} ==> (basis k ::('a::semiring_1)^'n)$i = (if k=i then 1 else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1431
  by (simp add: basis_def Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1432
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1433
lemma cond_value_iff: "f (if b then x else y) = (if b then f x else f y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1434
  by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1435
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1436
lemma basis_expansion:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1437
  "setsum (\<lambda>i. (x$i) *s basis i) {1 .. dimindex (UNIV :: 'n set)} = (x::('a::ring_1) ^'n)" (is "?lhs = ?rhs" is "setsum ?f ?S = _")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1438
  by (auto simp add: Cart_eq basis_component[where ?'n = "'n"] setsum_component vector_component cond_value_iff setsum_delta[of "?S", where ?'b = "'a", simplified] cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1439
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1440
lemma basis_expansion_unique: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1441
  "setsum (\<lambda>i. f i *s basis i) {1 .. dimindex (UNIV :: 'n set)} = (x::('a::comm_ring_1) ^'n) \<longleftrightarrow> (\<forall>i\<in>{1 .. dimindex(UNIV:: 'n set)}. f i = x$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1442
  by (simp add: Cart_eq setsum_component vector_component basis_component setsum_delta cond_value_iff cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1443
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1444
lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1445
  by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1446
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1447
lemma dot_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1448
  assumes i: "i \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1449
  shows "basis i \<bullet> x = x$i" "x \<bullet> (basis i :: 'a^'n) = (x$i :: 'a::semiring_1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1450
  using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1451
  by (auto simp add: dot_def basis_def Cart_lambda_beta cond_application_beta  cond_value_iff setsum_delta cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1452
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1453
lemma basis_eq_0: "basis i = (0::'a::semiring_1^'n) \<longleftrightarrow> i \<notin> {1..dimindex(UNIV ::'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1454
  by (auto simp add: Cart_eq basis_component zero_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1455
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1456
lemma basis_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1457
  assumes k: "k \<in> {1 .. dimindex(UNIV ::'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1458
  shows "basis k \<noteq> (0:: 'a::semiring_1 ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1459
  using k by (simp add: basis_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1460
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1461
lemma vector_eq_ldot: "(\<forall>x. x \<bullet> y = x \<bullet> z) \<longleftrightarrow> y = (z::'a::semiring_1^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1462
  apply (auto simp add: Cart_eq dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1463
  apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1464
  apply (simp add: dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1465
  apply (subgoal_tac "y = z")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1466
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1467
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1468
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1469
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1470
lemma vector_eq_rdot: "(\<forall>z. x \<bullet> z = y \<bullet> z) \<longleftrightarrow> x = (y::'a::semiring_1^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1471
  apply (auto simp add: Cart_eq dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1472
  apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1473
  apply (simp add: dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1474
  apply (subgoal_tac "x = y")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1475
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1476
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1477
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1478
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1479
subsection{* Orthogonality. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1480
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1481
definition "orthogonal x y \<longleftrightarrow> (x \<bullet> y = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1482
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1483
lemma orthogonal_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1484
  assumes i:"i \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1485
  shows "orthogonal (basis i :: 'a^'n) x \<longleftrightarrow> x$i = (0::'a::ring_1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1486
  using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1487
  by (auto simp add: orthogonal_def dot_def basis_def Cart_lambda_beta cond_value_iff cond_application_beta setsum_delta cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1488
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1489
lemma orthogonal_basis_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1490
  assumes i:"i \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1491
  and j: "j \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1492
  shows "orthogonal (basis i :: 'a::ring_1^'n) (basis j) \<longleftrightarrow> i \<noteq> j" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1493
  unfolding orthogonal_basis[OF i] basis_component[OF i] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1494
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1495
  (* FIXME : Maybe some of these require less than comm_ring, but not all*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1496
lemma orthogonal_clauses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1497
  "orthogonal a (0::'a::comm_ring ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1498
  "orthogonal a x ==> orthogonal a (c *s x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1499
  "orthogonal a x ==> orthogonal a (-x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1500
  "orthogonal a x \<Longrightarrow> orthogonal a y ==> orthogonal a (x + y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1501
  "orthogonal a x \<Longrightarrow> orthogonal a y ==> orthogonal a (x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1502
  "orthogonal 0 a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1503
  "orthogonal x a ==> orthogonal (c *s x) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1504
  "orthogonal x a ==> orthogonal (-x) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1505
  "orthogonal x a \<Longrightarrow> orthogonal y a ==> orthogonal (x + y) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1506
  "orthogonal x a \<Longrightarrow> orthogonal y a ==> orthogonal (x - y) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1507
  unfolding orthogonal_def dot_rneg dot_rmult dot_radd dot_rsub
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1508
  dot_lzero dot_rzero dot_lneg dot_lmult dot_ladd dot_lsub
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1509
  by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1510
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1511
lemma orthogonal_commute: "orthogonal (x::'a::{ab_semigroup_mult,comm_monoid_add} ^'n)y \<longleftrightarrow> orthogonal y x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1512
  by (simp add: orthogonal_def dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1513
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1514
subsection{* Explicit vector construction from lists. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1515
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1516
lemma Cart_lambda_beta_1[simp]: "(Cart_lambda g)$1 = g 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1517
  apply (rule Cart_lambda_beta[rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1518
  using dimindex_ge_1 apply auto done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1519
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1520
lemma Cart_lambda_beta_1'[simp]: "(Cart_lambda g)$(Suc 0) = g 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1521
  by (simp only: One_nat_def[symmetric] Cart_lambda_beta_1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1522
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1523
definition "vector l = (\<chi> i. if i <= length l then l ! (i - 1) else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1524
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1525
lemma vector_1: "(vector[x]) $1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1526
  using dimindex_ge_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1527
  by (auto simp add: vector_def Cart_lambda_beta[rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1528
lemma dimindex_2[simp]: "2 \<in> {1 .. dimindex (UNIV :: 2 set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1529
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1530
lemma dimindex_2'[simp]: "2 \<in> {Suc 0 .. dimindex (UNIV :: 2 set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1531
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1532
lemma dimindex_3[simp]: "2 \<in> {1 .. dimindex (UNIV :: 3 set)}" "3 \<in> {1 .. dimindex (UNIV :: 3 set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1533
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1534
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1535
lemma dimindex_3'[simp]: "2 \<in> {Suc 0 .. dimindex (UNIV :: 3 set)}" "3 \<in> {Suc 0 .. dimindex (UNIV :: 3 set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1536
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1537
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1538
lemma vector_2:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1539
 "(vector[x,y]) $1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1540
 "(vector[x,y] :: 'a^2)$2 = (y::'a::zero)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1541
  apply (simp add: vector_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1542
  using Cart_lambda_beta[rule_format, OF dimindex_2, of "\<lambda>i. if i \<le> length [x,y] then [x,y] ! (i - 1) else (0::'a)"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1543
  apply (simp only: vector_def )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1544
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1545
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1546
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1547
lemma vector_3:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1548
 "(vector [x,y,z] ::('a::zero)^3)$1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1549
 "(vector [x,y,z] ::('a::zero)^3)$2 = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1550
 "(vector [x,y,z] ::('a::zero)^3)$3 = z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1551
apply (simp_all add: vector_def Cart_lambda_beta dimindex_3)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1552
  using Cart_lambda_beta[rule_format, OF dimindex_3(1), of "\<lambda>i. if i \<le> length [x,y,z] then [x,y,z] ! (i - 1) else (0::'a)"]   using Cart_lambda_beta[rule_format, OF dimindex_3(2), of "\<lambda>i. if i \<le> length [x,y,z] then [x,y,z] ! (i - 1) else (0::'a)"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1553
  by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1554
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1555
lemma forall_vector_1: "(\<forall>v::'a::zero^1. P v) \<longleftrightarrow> (\<forall>x. P(vector[x]))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1556
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1557
  apply (erule_tac x="v$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1558
  apply (subgoal_tac "vector [v$1] = v")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1559
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1560
  by (vector vector_def dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1561
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1562
lemma forall_vector_2: "(\<forall>v::'a::zero^2. P v) \<longleftrightarrow> (\<forall>x y. P(vector[x, y]))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1563
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1564
  apply (erule_tac x="v$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1565
  apply (erule_tac x="v$2" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1566
  apply (subgoal_tac "vector [v$1, v$2] = v")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1567
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1568
  apply (vector vector_def dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1569
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1570
  apply (subgoal_tac "i = 1 \<or> i =2", auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1571
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1572
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1573
lemma forall_vector_3: "(\<forall>v::'a::zero^3. P v) \<longleftrightarrow> (\<forall>x y z. P(vector[x, y, z]))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1574
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1575
  apply (erule_tac x="v$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1576
  apply (erule_tac x="v$2" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1577
  apply (erule_tac x="v$3" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1578
  apply (subgoal_tac "vector [v$1, v$2, v$3] = v")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1579
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1580
  apply (vector vector_def dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1581
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1582
  apply (subgoal_tac "i = 1 \<or> i =2 \<or> i = 3", auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1583
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1584
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1585
subsection{* Linear functions. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1586
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1587
definition "linear f \<longleftrightarrow> (\<forall>x y. f(x + y) = f x + f y) \<and> (\<forall>c x. f(c *s x) = c *s f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1588
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1589
lemma linear_compose_cmul: "linear f ==> linear (\<lambda>x. (c::'a::comm_semiring) *s f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1590
  by (vector linear_def Cart_eq Cart_lambda_beta[rule_format] ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1591
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1592
lemma linear_compose_neg: "linear (f :: 'a ^'n \<Rightarrow> 'a::comm_ring ^'m) ==> linear (\<lambda>x. -(f(x)))" by (vector linear_def Cart_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1593
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1594
lemma linear_compose_add: "linear (f :: 'a ^'n \<Rightarrow> 'a::semiring_1 ^'m) \<Longrightarrow> linear g ==> linear (\<lambda>x. f(x) + g(x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1595
  by (vector linear_def Cart_eq ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1596
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1597
lemma linear_compose_sub: "linear (f :: 'a ^'n \<Rightarrow> 'a::ring_1 ^'m) \<Longrightarrow> linear g ==> linear (\<lambda>x. f x - g x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1598
  by (vector linear_def Cart_eq ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1599
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1600
lemma linear_compose: "linear f \<Longrightarrow> linear g ==> linear (g o f)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1601
  by (simp add: linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1602
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1603
lemma linear_id: "linear id" by (simp add: linear_def id_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1604
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1605
lemma linear_zero: "linear (\<lambda>x. 0::'a::semiring_1 ^ 'n)" by (simp add: linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1606
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1607
lemma linear_compose_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1608
  assumes fS: "finite S" and lS: "\<forall>a \<in> S. linear (f a :: 'a::semiring_1 ^ 'n \<Rightarrow> 'a ^ 'm)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1609
  shows "linear(\<lambda>x. setsum (\<lambda>a. f a x :: 'a::semiring_1 ^'m) S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1610
  using lS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1611
  apply (induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1612
  by (auto simp add: linear_zero intro: linear_compose_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1613
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1614
lemma linear_vmul_component:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1615
  fixes f:: "'a::semiring_1^'m \<Rightarrow> 'a^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1616
  assumes lf: "linear f" and k: "k \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1617
  shows "linear (\<lambda>x. f x $ k *s v)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1618
  using lf k
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1619
  apply (auto simp add: linear_def )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1620
  by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1621
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1622
lemma linear_0: "linear f ==> f 0 = (0::'a::semiring_1 ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1623
  unfolding linear_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1624
  apply clarsimp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1625
  apply (erule allE[where x="0::'a"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1626
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1627
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1628
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1629
lemma linear_cmul: "linear f ==> f(c*s x) = c *s f x" by (simp add: linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1630
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1631
lemma linear_neg: "linear (f :: 'a::ring_1 ^'n \<Rightarrow> _) ==> f (-x) = - f x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1632
  unfolding vector_sneg_minus1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1633
  using linear_cmul[of f] by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1634
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1635
lemma linear_add: "linear f ==> f(x + y) = f x + f y" by (metis linear_def) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1636
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1637
lemma linear_sub: "linear (f::'a::ring_1 ^'n \<Rightarrow> _) ==> f(x - y) = f x - f y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1638
  by (simp add: diff_def linear_add linear_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1639
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1640
lemma linear_setsum: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1641
  fixes f:: "'a::semiring_1^'n \<Rightarrow> _"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1642
  assumes lf: "linear f" and fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1643
  shows "f (setsum g S) = setsum (f o g) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1644
proof (induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1645
  case 1 thus ?case by (simp add: linear_0[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1646
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1647
  case (2 x F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1648
  have "f (setsum g (insert x F)) = f (g x + setsum g F)" using "2.hyps"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1649
    by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1650
  also have "\<dots> = f (g x) + f (setsum g F)" using linear_add[OF lf] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1651
  also have "\<dots> = setsum (f o g) (insert x F)" using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1652
  finally show ?case .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1653
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1654
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1655
lemma linear_setsum_mul:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1656
  fixes f:: "'a ^'n \<Rightarrow> 'a::semiring_1^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1657
  assumes lf: "linear f" and fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1658
  shows "f (setsum (\<lambda>i. c i *s v i) S) = setsum (\<lambda>i. c i *s f (v i)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1659
  using linear_setsum[OF lf fS, of "\<lambda>i. c i *s v i" , unfolded o_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1660
  linear_cmul[OF lf] by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1661
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1662
lemma linear_injective_0:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1663
  assumes lf: "linear (f:: 'a::ring_1 ^ 'n \<Rightarrow> _)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1664
  shows "inj f \<longleftrightarrow> (\<forall>x. f x = 0 \<longrightarrow> x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1665
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1666
  have "inj f \<longleftrightarrow> (\<forall> x y. f x = f y \<longrightarrow> x = y)" by (simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1667
  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f x - f y = 0 \<longrightarrow> x - y = 0)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1668
  also have "\<dots> \<longleftrightarrow> (\<forall> x y. f (x - y) = 0 \<longrightarrow> x - y = 0)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1669
    by (simp add: linear_sub[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1670
  also have "\<dots> \<longleftrightarrow> (\<forall> x. f x = 0 \<longrightarrow> x = 0)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1671
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1672
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1673
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1674
lemma linear_bounded:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1675
  fixes f:: "real ^'m \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1676
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1677
  shows "\<exists>B. \<forall>x. norm (f x) \<le> B * norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1678
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1679
  let ?S = "{1..dimindex(UNIV:: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1680
  let ?B = "setsum (\<lambda>i. norm(f(basis i))) ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1681
  have fS: "finite ?S" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1682
  {fix x:: "real ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1683
    let ?g = "(\<lambda>i::nat. (x$i) *s (basis i) :: real ^ 'm)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1684
    have "norm (f x) = norm (f (setsum (\<lambda>i. (x$i) *s (basis i)) ?S))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1685
      by (simp only:  basis_expansion)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1686
    also have "\<dots> = norm (setsum (\<lambda>i. (x$i) *s f (basis i))?S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1687
      using linear_setsum[OF lf fS, of ?g, unfolded o_def] linear_cmul[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1688
      by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1689
    finally have th0: "norm (f x) = norm (setsum (\<lambda>i. (x$i) *s f (basis i))?S)" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1690
    {fix i assume i: "i \<in> ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1691
      from component_le_norm[OF i, of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1692
      have "norm ((x$i) *s f (basis i :: real ^'m)) \<le> norm (f (basis i)) * norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1693
      unfolding norm_mul
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1694
      apply (simp only: mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1695
      apply (rule mult_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1696
      by (auto simp add: ring_simps norm_pos_le) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1697
    then have th: "\<forall>i\<in> ?S. norm ((x$i) *s f (basis i :: real ^'m)) \<le> norm (f (basis i)) * norm x" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1698
    from real_setsum_norm_le[OF fS, of "\<lambda>i. (x$i) *s (f (basis i))", OF th]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1699
    have "norm (f x) \<le> ?B * norm x" unfolding th0 setsum_left_distrib by metis}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1700
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1701
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1702
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1703
lemma linear_bounded_pos:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1704
  fixes f:: "real ^'n \<Rightarrow> real ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1705
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1706
  shows "\<exists>B > 0. \<forall>x. norm (f x) \<le> B * norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1707
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1708
  from linear_bounded[OF lf] obtain B where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1709
    B: "\<forall>x. norm (f x) \<le> B * norm x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1710
  let ?K = "\<bar>B\<bar> + 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1711
  have Kp: "?K > 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1712
    {assume C: "B < 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1713
      have "norm (1::real ^ 'n) > 0" by (simp add: norm_pos_lt)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1714
      with C have "B * norm (1:: real ^ 'n) < 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1715
	by (simp add: zero_compare_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1716
      with B[rule_format, of 1] norm_pos_le[of "f 1"] have False by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1717
    }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1718
    then have Bp: "B \<ge> 0" by ferrack
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1719
    {fix x::"real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1720
      have "norm (f x) \<le> ?K *  norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1721
      using B[rule_format, of x] norm_pos_le[of x] norm_pos_le[of "f x"] Bp
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  1722
      apply (auto simp add: ring_simps split add: abs_split)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  1723
      apply (erule order_trans, simp)
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  1724
      done
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1725
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1726
  then show ?thesis using Kp by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1727
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1728
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1729
subsection{* Bilinear functions. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1730
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1731
definition "bilinear f \<longleftrightarrow> (\<forall>x. linear(\<lambda>y. f x y)) \<and> (\<forall>y. linear(\<lambda>x. f x y))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1732
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1733
lemma bilinear_ladd: "bilinear h ==> h (x + y) z = (h x z) + (h y z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1734
  by (simp add: bilinear_def linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1735
lemma bilinear_radd: "bilinear h ==> h x (y + z) = (h x y) + (h x z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1736
  by (simp add: bilinear_def linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1737
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1738
lemma bilinear_lmul: "bilinear h ==> h (c *s x) y = c *s (h x y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1739
  by (simp add: bilinear_def linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1740
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1741
lemma bilinear_rmul: "bilinear h ==> h x (c *s y) = c *s (h x y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1742
  by (simp add: bilinear_def linear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1743
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1744
lemma bilinear_lneg: "bilinear h ==> h (- (x:: 'a::ring_1 ^ 'n)) y = -(h x y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1745
  by (simp only: vector_sneg_minus1 bilinear_lmul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1746
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1747
lemma bilinear_rneg: "bilinear h ==> h x (- (y:: 'a::ring_1 ^ 'n)) = - h x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1748
  by (simp only: vector_sneg_minus1 bilinear_rmul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1749
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1750
lemma  (in ab_group_add) eq_add_iff: "x = x + y \<longleftrightarrow> y = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1751
  using add_imp_eq[of x y 0] by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1752
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1753
lemma bilinear_lzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1754
  fixes h :: "'a::ring^'n \<Rightarrow> _" assumes bh: "bilinear h" shows "h 0 x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1755
  using bilinear_ladd[OF bh, of 0 0 x] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1756
    by (simp add: eq_add_iff ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1757
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1758
lemma bilinear_rzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1759
  fixes h :: "'a::ring^'n \<Rightarrow> _" assumes bh: "bilinear h" shows "h x 0 = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1760
  using bilinear_radd[OF bh, of x 0 0 ] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1761
    by (simp add: eq_add_iff ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1762
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1763
lemma bilinear_lsub: "bilinear h ==> h (x - (y:: 'a::ring_1 ^ 'n)) z = h x z - h y z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1764
  by (simp  add: diff_def bilinear_ladd bilinear_lneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1765
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1766
lemma bilinear_rsub: "bilinear h ==> h z (x - (y:: 'a::ring_1 ^ 'n)) = h z x - h z y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1767
  by (simp  add: diff_def bilinear_radd bilinear_rneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1768
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1769
lemma bilinear_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1770
  fixes h:: "'a ^'n \<Rightarrow> 'a::semiring_1^'m \<Rightarrow> 'a ^ 'k"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1771
  assumes bh: "bilinear h" and fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1772
  shows "h (setsum f S) (setsum g T) = setsum (\<lambda>(i,j). h (f i) (g j)) (S \<times> T) "
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1773
proof- 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1774
  have "h (setsum f S) (setsum g T) = setsum (\<lambda>x. h (f x) (setsum g T)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1775
    apply (rule linear_setsum[unfolded o_def])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1776
    using bh fS by (auto simp add: bilinear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1777
  also have "\<dots> = setsum (\<lambda>x. setsum (\<lambda>y. h (f x) (g y)) T) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1778
    apply (rule setsum_cong, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1779
    apply (rule linear_setsum[unfolded o_def])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1780
    using bh fT by (auto simp add: bilinear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1781
  finally show ?thesis unfolding setsum_cartesian_product .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1782
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1783
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1784
lemma bilinear_bounded:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1785
  fixes h:: "real ^'m \<Rightarrow> real^'n \<Rightarrow> real ^ 'k"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1786
  assumes bh: "bilinear h"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1787
  shows "\<exists>B. \<forall>x y. norm (h x y) \<le> B * norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1788
proof- 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1789
  let ?M = "{1 .. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1790
  let ?N = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1791
  let ?B = "setsum (\<lambda>(i,j). norm (h (basis i) (basis j))) (?M \<times> ?N)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1792
  have fM: "finite ?M" and fN: "finite ?N" by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1793
  {fix x:: "real ^ 'm" and  y :: "real^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1794
    have "norm (h x y) = norm (h (setsum (\<lambda>i. (x$i) *s basis i) ?M) (setsum (\<lambda>i. (y$i) *s basis i) ?N))" unfolding basis_expansion ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1795
    also have "\<dots> = norm (setsum (\<lambda> (i,j). h ((x$i) *s basis i) ((y$j) *s basis j)) (?M \<times> ?N))"  unfolding bilinear_setsum[OF bh fM fN] ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1796
    finally have th: "norm (h x y) = \<dots>" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1797
    have "norm (h x y) \<le> ?B * norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1798
      apply (simp add: setsum_left_distrib th)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1799
      apply (rule real_setsum_norm_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1800
      using fN fM
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1801
      apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1802
      apply (auto simp add: bilinear_rmul[OF bh] bilinear_lmul[OF bh] norm_mul ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1803
      apply (rule mult_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1804
      apply (auto simp add: norm_pos_le zero_le_mult_iff component_le_norm)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1805
      apply (rule mult_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1806
      apply (auto simp add: norm_pos_le zero_le_mult_iff component_le_norm)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1807
      done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1808
  then show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1809
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1810
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1811
lemma bilinear_bounded_pos:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1812
  fixes h:: "real ^'m \<Rightarrow> real^'n \<Rightarrow> real ^ 'k"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1813
  assumes bh: "bilinear h"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1814
  shows "\<exists>B > 0. \<forall>x y. norm (h x y) \<le> B * norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1815
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1816
  from bilinear_bounded[OF bh] obtain B where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1817
    B: "\<forall>x y. norm (h x y) \<le> B * norm x * norm y" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1818
  let ?K = "\<bar>B\<bar> + 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1819
  have Kp: "?K > 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1820
  have KB: "B < ?K" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1821
  {fix x::"real ^'m" and y :: "real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1822
    from KB Kp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1823
    have "B * norm x * norm y \<le> ?K * norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1824
      apply - 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1825
      apply (rule mult_right_mono, rule mult_right_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1826
      by (auto simp add: norm_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1827
    then have "norm (h x y) \<le> ?K * norm x * norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1828
      using B[rule_format, of x y] by simp} 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1829
  with Kp show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1830
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1831
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1832
subsection{* Adjoints. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1833
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1834
definition "adjoint f = (SOME f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1835
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1836
lemma choice_iff: "(\<forall>x. \<exists>y. P x y) \<longleftrightarrow> (\<exists>f. \<forall>x. P x (f x))" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1837
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1838
lemma adjoint_works_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1839
  fixes f:: "'a::ring_1 ^'n \<Rightarrow> 'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1840
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1841
  shows "\<forall>x y. f x \<bullet> y = x \<bullet> adjoint f y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1842
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1843
  let ?N = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1844
  let ?M = "{1 .. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1845
  have fN: "finite ?N" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1846
  have fM: "finite ?M" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1847
  {fix y:: "'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1848
    let ?w = "(\<chi> i. (f (basis i) \<bullet> y)) :: 'a ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1849
    {fix x
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1850
      have "f x \<bullet> y = f (setsum (\<lambda>i. (x$i) *s basis i) ?N) \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1851
	by (simp only: basis_expansion)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1852
      also have "\<dots> = (setsum (\<lambda>i. (x$i) *s f (basis i)) ?N) \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1853
	unfolding linear_setsum[OF lf fN] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1854
	by (simp add: linear_cmul[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1855
      finally have "f x \<bullet> y = x \<bullet> ?w"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1856
	apply (simp only: )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1857
	apply (simp add: dot_def setsum_component Cart_lambda_beta setsum_left_distrib setsum_right_distrib vector_component setsum_commute[of _ ?M ?N] ring_simps del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1858
	done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1859
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1860
  then show ?thesis unfolding adjoint_def 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1861
    some_eq_ex[of "\<lambda>f'. \<forall>x y. f x \<bullet> y = x \<bullet> f' y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1862
    using choice_iff[of "\<lambda>a b. \<forall>x. f x \<bullet> a = x \<bullet> b "]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1863
    by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1864
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1865
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1866
lemma adjoint_works:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1867
  fixes f:: "'a::ring_1 ^'n \<Rightarrow> 'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1868
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1869
  shows "x \<bullet> adjoint f y = f x \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1870
  using adjoint_works_lemma[OF lf] by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1871
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1872
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1873
lemma adjoint_linear:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1874
  fixes f :: "'a::comm_ring_1 ^'n \<Rightarrow> 'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1875
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1876
  shows "linear (adjoint f)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1877
  by (simp add: linear_def vector_eq_ldot[symmetric] dot_radd dot_rmult adjoint_works[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1878
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1879
lemma adjoint_clauses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1880
  fixes f:: "'a::comm_ring_1 ^'n \<Rightarrow> 'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1881
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1882
  shows "x \<bullet> adjoint f y = f x \<bullet> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1883
  and "adjoint f y \<bullet> x = y \<bullet> f x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1884
  by (simp_all add: adjoint_works[OF lf] dot_sym )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1885
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1886
lemma adjoint_adjoint:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1887
  fixes f:: "'a::comm_ring_1 ^ 'n \<Rightarrow> _"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1888
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1889
  shows "adjoint (adjoint f) = f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1890
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1891
  by (simp add: vector_eq_ldot[symmetric] adjoint_clauses[OF adjoint_linear[OF lf]] adjoint_clauses[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1892
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1893
lemma adjoint_unique:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1894
  fixes f:: "'a::comm_ring_1 ^ 'n \<Rightarrow> 'a ^ 'm"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1895
  assumes lf: "linear f" and u: "\<forall>x y. f' x \<bullet> y = x \<bullet> f y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1896
  shows "f' = adjoint f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1897
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1898
  using u
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1899
  by (simp add: vector_eq_rdot[symmetric] adjoint_clauses[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1900
29881
58f3c48dbbb7 fix document generation
huffman
parents: 29844
diff changeset
  1901
text{* Matrix notation. NB: an MxN matrix is of type @{typ "'a^'n^'m"}, not @{typ "'a^'m^'n"} *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1902
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1903
consts generic_mult :: "'a \<Rightarrow> 'b \<Rightarrow> 'c" (infixr "\<star>" 75)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1904
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1905
defs (overloaded) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1906
matrix_matrix_mult_def: "(m:: ('a::semiring_1) ^'n^'m) \<star> (m' :: 'a ^'p^'n) \<equiv> (\<chi> i j. setsum (\<lambda>k. ((m$i)$k) * ((m'$k)$j)) {1 .. dimindex (UNIV :: 'n set)}) ::'a ^ 'p ^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1907
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1908
abbreviation 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1909
  matrix_matrix_mult' :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'p^'n \<Rightarrow> 'a ^ 'p ^'m"  (infixl "**" 70)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1910
  where "m ** m' == m\<star> m'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1911
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1912
defs (overloaded) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1913
  matrix_vector_mult_def: "(m::('a::semiring_1) ^'n^'m) \<star> (x::'a ^'n) \<equiv> (\<chi> i. setsum (\<lambda>j. ((m$i)$j) * (x$j)) {1..dimindex(UNIV ::'n set)}) :: 'a^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1914
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1915
abbreviation 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1916
  matrix_vector_mult' :: "('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n \<Rightarrow> 'a ^ 'm"  (infixl "*v" 70)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1917
  where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1918
  "m *v v == m \<star> v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1919
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1920
defs (overloaded) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1921
  vector_matrix_mult_def: "(x::'a^'m) \<star> (m::('a::semiring_1) ^'n^'m) \<equiv> (\<chi> j. setsum (\<lambda>i. ((m$i)$j) * (x$i)) {1..dimindex(UNIV :: 'm set)}) :: 'a^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1922
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1923
abbreviation 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1924
  vactor_matrix_mult' :: "'a ^ 'm \<Rightarrow> ('a::semiring_1) ^'n^'m \<Rightarrow> 'a ^'n "  (infixl "v*" 70)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1925
  where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1926
  "v v* m == v \<star> m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1927
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1928
definition "(mat::'a::zero => 'a ^'n^'m) k = (\<chi> i j. if i = j then k else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1929
definition "(transp::'a^'n^'m \<Rightarrow> 'a^'m^'n) A = (\<chi> i j. ((A$j)$i))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1930
definition "(row::nat => 'a ^'n^'m \<Rightarrow> 'a ^'n) i A = (\<chi> j. ((A$i)$j))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1931
definition "(column::nat =>'a^'n^'m =>'a^'m) j A = (\<chi> i. ((A$i)$j))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1932
definition "rows(A::'a^'n^'m) = { row i A | i. i \<in> {1 .. dimindex(UNIV :: 'm set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1933
definition "columns(A::'a^'n^'m) = { column i A | i. i \<in> {1 .. dimindex(UNIV :: 'n set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1934
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1935
lemma mat_0[simp]: "mat 0 = 0" by (vector mat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1936
lemma matrix_add_ldistrib: "(A ** (B + C)) = (A \<star> B) + (A \<star> C)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1937
  by (vector matrix_matrix_mult_def setsum_addf[symmetric] ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1938
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1939
lemma setsum_delta': 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1940
  assumes fS: "finite S" shows 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1941
  "setsum (\<lambda>k. if a = k then b k else 0) S = 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1942
     (if a\<in> S then b a else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1943
  using setsum_delta[OF fS, of a b, symmetric] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1944
  by (auto intro: setsum_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1945
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1946
lemma matrix_mul_lid: "mat 1 ** A = A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1947
  apply (simp add: matrix_matrix_mult_def mat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1948
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1949
  by (auto simp only: cond_value_iff cond_application_beta setsum_delta'[OF finite_atLeastAtMost]  mult_1_left mult_zero_left if_True)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1950
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1951
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1952
lemma matrix_mul_rid: "A ** mat 1 = A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1953
  apply (simp add: matrix_matrix_mult_def mat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1954
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1955
  by (auto simp only: cond_value_iff cond_application_beta setsum_delta[OF finite_atLeastAtMost]  mult_1_right mult_zero_right if_True cong: if_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1956
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1957
lemma matrix_mul_assoc: "A ** (B ** C) = (A ** B) ** C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1958
  apply (vector matrix_matrix_mult_def setsum_right_distrib setsum_left_distrib mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1959
  apply (subst setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1960
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1961
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1962
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1963
lemma matrix_vector_mul_assoc: "A *v (B *v x) = (A ** B) *v x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1964
  apply (vector matrix_matrix_mult_def matrix_vector_mult_def setsum_right_distrib setsum_left_distrib mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1965
  apply (subst setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1966
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1967
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1968
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1969
lemma matrix_vector_mul_lid: "mat 1 *v x = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1970
  apply (vector matrix_vector_mult_def mat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1971
  by (simp add: cond_value_iff cond_application_beta 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1972
    setsum_delta' cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1973
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1974
lemma matrix_transp_mul: "transp(A ** B) = transp B ** transp (A::'a::comm_semiring_1^'m^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1975
  by (simp add: matrix_matrix_mult_def transp_def Cart_eq Cart_lambda_beta mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1976
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1977
lemma matrix_eq: "A = B \<longleftrightarrow>  (\<forall>x. A *v x = B *v x)" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1978
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1979
  apply (subst Cart_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1980
  apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1981
  apply (clarsimp simp add: matrix_vector_mult_def basis_def cond_value_iff cond_application_beta Cart_eq Cart_lambda_beta cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1982
  apply (erule_tac x="basis ia" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1983
  apply (erule_tac x="i" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1984
  by (auto simp add: basis_def cond_value_iff cond_application_beta Cart_lambda_beta setsum_delta[OF finite_atLeastAtMost] cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1985
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1986
lemma matrix_vector_mul_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1987
  assumes k: "k \<in> {1.. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1988
  shows "((A::'a::semiring_1^'n'^'m) *v x)$k = (A$k) \<bullet> x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1989
  using k
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1990
  by (simp add: matrix_vector_mult_def Cart_lambda_beta dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1991
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1992
lemma dot_lmul_matrix: "((x::'a::comm_semiring_1 ^'n) v* A) \<bullet> y = x \<bullet> (A *v y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1993
  apply (simp add: dot_def matrix_vector_mult_def vector_matrix_mult_def setsum_left_distrib setsum_right_distrib Cart_lambda_beta mult_ac)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1994
  apply (subst setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1995
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1996
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1997
lemma transp_mat: "transp (mat n) = mat n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1998
  by (vector transp_def mat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1999
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2000
lemma transp_transp: "transp(transp A) = A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2001
  by (vector transp_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2002
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2003
lemma row_transp: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2004
  fixes A:: "'a::semiring_1^'n^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2005
  assumes i: "i \<in> {1.. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2006
  shows "row i (transp A) = column i A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2007
  using i 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2008
  by (simp add: row_def column_def transp_def Cart_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2009
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2010
lemma column_transp:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2011
  fixes A:: "'a::semiring_1^'n^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2012
  assumes i: "i \<in> {1.. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2013
  shows "column i (transp A) = row i A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2014
  using i 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2015
  by (simp add: row_def column_def transp_def Cart_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2016
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2017
lemma rows_transp: "rows(transp (A::'a::semiring_1^'n^'m)) = columns A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2018
apply (auto simp add: rows_def columns_def row_transp intro: set_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2019
apply (rule_tac x=i in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2020
apply (auto simp add: row_transp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2021
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2022
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2023
lemma columns_transp: "columns(transp (A::'a::semiring_1^'n^'m)) = rows A" by (metis transp_transp rows_transp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2024
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2025
text{* Two sometimes fruitful ways of looking at matrix-vector multiplication. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2026
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2027
lemma matrix_mult_dot: "A *v x = (\<chi> i. A$i \<bullet> x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2028
  by (simp add: matrix_vector_mult_def dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2029
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2030
lemma matrix_mult_vsum: "(A::'a::comm_semiring_1^'n^'m) *v x = setsum (\<lambda>i. (x$i) *s column i A) {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2031
  by (simp add: matrix_vector_mult_def Cart_eq setsum_component Cart_lambda_beta vector_component column_def mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2032
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2033
lemma vector_componentwise:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2034
  "(x::'a::ring_1^'n) = (\<chi> j. setsum (\<lambda>i. (x$i) * (basis i :: 'a^'n)$j) {1..dimindex(UNIV :: 'n set)})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2035
  apply (subst basis_expansion[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2036
  by (vector Cart_eq Cart_lambda_beta setsum_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2037
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2038
lemma linear_componentwise:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2039
  fixes f:: "'a::ring_1 ^ 'm \<Rightarrow> 'a ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2040
  assumes lf: "linear f" and j: "j \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2041
  shows "(f x)$j = setsum (\<lambda>i. (x$i) * (f (basis i)$j)) {1 .. dimindex (UNIV :: 'm set)}" (is "?lhs = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2042
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2043
  let ?M = "{1 .. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2044
  let ?N = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2045
  have fM: "finite ?M" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2046
  have "?rhs = (setsum (\<lambda>i.(x$i) *s f (basis i) ) ?M)$j"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2047
    unfolding vector_smult_component[OF j, symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2048
    unfolding setsum_component[OF j, of "(\<lambda>i.(x$i) *s f (basis i :: 'a^'m))" ?M]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2049
    ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2050
  then show ?thesis unfolding linear_setsum_mul[OF lf fM, symmetric] basis_expansion ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2051
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2052
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2053
text{* Inverse matrices  (not necessarily square) *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2054
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2055
definition "invertible(A::'a::semiring_1^'n^'m) \<longleftrightarrow> (\<exists>A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2056
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2057
definition "matrix_inv(A:: 'a::semiring_1^'n^'m) =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2058
        (SOME A'::'a^'m^'n. A ** A' = mat 1 \<and> A' ** A = mat 1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2059
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2060
text{* Correspondence between matrices and linear operators. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2061
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2062
definition matrix:: "('a::{plus,times, one, zero}^'m \<Rightarrow> 'a ^ 'n) \<Rightarrow> 'a^'m^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2063
where "matrix f = (\<chi> i j. (f(basis j))$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2064
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2065
lemma matrix_vector_mul_linear: "linear(\<lambda>x. A *v (x::'a::comm_semiring_1 ^ 'n))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2066
  by (simp add: linear_def matrix_vector_mult_def Cart_eq Cart_lambda_beta vector_component ring_simps setsum_right_distrib setsum_addf)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2067
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2068
lemma matrix_works: assumes lf: "linear f" shows "matrix f *v x = f (x::'a::comm_ring_1 ^ 'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2069
apply (simp add: matrix_def matrix_vector_mult_def Cart_eq Cart_lambda_beta mult_commute del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2070
apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2071
apply (rule linear_componentwise[OF lf, symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2072
apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2073
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2074
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2075
lemma matrix_vector_mul: "linear f ==> f = (\<lambda>x. matrix f *v (x::'a::comm_ring_1 ^ 'n))" by (simp add: ext matrix_works)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2076
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2077
lemma matrix_of_matrix_vector_mul: "matrix(\<lambda>x. A *v (x :: 'a:: comm_ring_1 ^ 'n)) = A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2078
  by (simp add: matrix_eq matrix_vector_mul_linear matrix_works)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2079
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2080
lemma matrix_compose: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2081
  assumes lf: "linear (f::'a::comm_ring_1^'n \<Rightarrow> _)" and lg: "linear g" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2082
  shows "matrix (g o f) = matrix g ** matrix f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2083
  using lf lg linear_compose[OF lf lg] matrix_works[OF linear_compose[OF lf lg]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2084
  by (simp  add: matrix_eq matrix_works matrix_vector_mul_assoc[symmetric] o_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2085
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2086
lemma matrix_vector_column:"(A::'a::comm_semiring_1^'n^'m) *v x = setsum (\<lambda>i. (x$i) *s ((transp A)$i)) {1..dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2087
  by (simp add: matrix_vector_mult_def transp_def Cart_eq Cart_lambda_beta setsum_component vector_component mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2088
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2089
lemma adjoint_matrix: "adjoint(\<lambda>x. (A::'a::comm_ring_1^'n^'m) *v x) = (\<lambda>x. transp A *v x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2090
  apply (rule adjoint_unique[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2091
  apply (rule matrix_vector_mul_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2092
  apply (simp add: transp_def dot_def Cart_lambda_beta matrix_vector_mult_def setsum_left_distrib setsum_right_distrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2093
  apply (subst setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2094
  apply (auto simp add: mult_ac)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2095
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2096
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2097
lemma matrix_adjoint: assumes lf: "linear (f :: 'a::comm_ring_1^'n \<Rightarrow> 'a ^ 'm)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2098
  shows "matrix(adjoint f) = transp(matrix f)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2099
  apply (subst matrix_vector_mul[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2100
  unfolding adjoint_matrix matrix_of_matrix_vector_mul ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2101
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2102
subsection{* Interlude: Some properties of real sets *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2103
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2104
lemma seq_mono_lemma: assumes "\<forall>(n::nat) \<ge> m. (d n :: real) < e n" and "\<forall>n \<ge> m. e n <= e m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2105
  shows "\<forall>n \<ge> m. d n < e m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2106
  using prems apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2107
  apply (erule_tac x="n" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2108
  apply (erule_tac x="n" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2109
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2110
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2111
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2112
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2113
lemma real_convex_bound_lt: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2114
  assumes xa: "(x::real) < a" and ya: "y < a" and u: "0 <= u" and v: "0 <= v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2115
  and uv: "u + v = 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2116
  shows "u * x + v * y < a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2117
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2118
  have uv': "u = 0 \<longrightarrow> v \<noteq> 0" using u v uv by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2119
  have "a = a * (u + v)" unfolding uv  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2120
  hence th: "u * a + v * a = a" by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2121
  from xa u have "u \<noteq> 0 \<Longrightarrow> u*x < u*a" by (simp add: mult_compare_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2122
  from ya v have "v \<noteq> 0 \<Longrightarrow> v * y < v * a" by (simp add: mult_compare_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2123
  from xa ya u v have "u * x + v * y < u * a + v * a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2124
    apply (cases "u = 0", simp_all add: uv')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2125
    apply(rule mult_strict_left_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2126
    using uv' apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2127
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2128
    apply (rule add_less_le_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2129
    apply(rule mult_strict_left_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2130
    apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2131
    apply (rule mult_left_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2132
    apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2133
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2134
  thus ?thesis unfolding th .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2135
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2136
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2137
lemma real_convex_bound_le: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2138
  assumes xa: "(x::real) \<le> a" and ya: "y \<le> a" and u: "0 <= u" and v: "0 <= v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2139
  and uv: "u + v = 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2140
  shows "u * x + v * y \<le> a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2141
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2142
  from xa ya u v have "u * x + v * y \<le> u * a + v * a" by (simp add: add_mono mult_left_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2143
  also have "\<dots> \<le> (u + v) * a" by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2144
  finally show ?thesis unfolding uv by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2145
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2146
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2147
lemma infinite_enumerate: assumes fS: "infinite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2148
  shows "\<exists>r. subseq r \<and> (\<forall>n. r n \<in> S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2149
unfolding subseq_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2150
using enumerate_in_set[OF fS] enumerate_mono[of _ _ S] fS by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2151
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2152
lemma approachable_lt_le: "(\<exists>(d::real)>0. \<forall>x. f x < d \<longrightarrow> P x) \<longleftrightarrow> (\<exists>d>0. \<forall>x. f x \<le> d \<longrightarrow> P x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2153
apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2154
apply (rule_tac x="d/2" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2155
apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2156
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2157
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2158
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2159
lemma triangle_lemma: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2160
  assumes x: "0 <= (x::real)" and y:"0 <= y" and z: "0 <= z" and xy: "x^2 <= y^2 + z^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2161
  shows "x <= y + z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2162
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2163
  have "y^2 + z^2 \<le> y^2 + 2*y*z + z^2" using z y  by (simp add: zero_compare_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2164
  with xy have th: "x ^2 \<le> (y+z)^2" by (simp add: power2_eq_square ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2165
  from y z have yz: "y + z \<ge> 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2166
  from power2_le_imp_le[OF th yz] show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2167
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2168
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2169
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2170
lemma lambda_skolem: "(\<forall>i \<in> {1 .. dimindex(UNIV :: 'n set)}. \<exists>x. P i x) \<longleftrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2171
   (\<exists>x::'a ^ 'n. \<forall>i \<in> {1 .. dimindex(UNIV:: 'n set)}. P i (x$i))" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2172
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2173
  let ?S = "{1 .. dimindex(UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2174
  {assume H: "?rhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2175
    then have ?lhs by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2176
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2177
  {assume H: "?lhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2178
    then obtain f where f:"\<forall>i\<in> ?S. P i (f i)" unfolding Ball_def choice_iff by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2179
    let ?x = "(\<chi> i. (f i)) :: 'a ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2180
    {fix i assume i: "i \<in> ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2181
      with f i have "P i (f i)" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2182
      then have "P i (?x$i)" using Cart_lambda_beta[of f, rule_format, OF i] by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2183
    }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2184
    hence "\<forall>i \<in> ?S. P i (?x$i)" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2185
    hence ?rhs by metis }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2186
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2187
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2188
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2189
(* Supremum and infimum of real sets *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2190
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2191
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2192
definition rsup:: "real set \<Rightarrow> real" where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2193
  "rsup S = (SOME a. isLub UNIV S a)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2194
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2195
lemma rsup_alt: "rsup S = (SOME a. (\<forall>x \<in> S. x \<le> a) \<and> (\<forall>b. (\<forall>x \<in> S. x \<le> b) \<longrightarrow> a \<le> b))"  by (auto simp  add: isLub_def rsup_def leastP_def isUb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2196
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2197
lemma rsup: assumes Se: "S \<noteq> {}" and b: "\<exists>b. S *<= b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2198
  shows "isLub UNIV S (rsup S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2199
using Se b
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2200
unfolding rsup_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2201
apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2202
apply (rule someI_ex)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2203
apply (rule reals_complete)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2204
by (auto simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2205
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2206
lemma rsup_le: assumes Se: "S \<noteq> {}" and Sb: "S *<= b" shows "rsup S \<le> b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2207
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2208
  from Sb have bu: "isUb UNIV S b" by (simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2209
  from rsup[OF Se] Sb have "isLub UNIV S (rsup S)"  by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2210
  then show ?thesis using bu by (auto simp add: isLub_def leastP_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2211
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2212
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2213
lemma rsup_finite_Max: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2214
  shows "rsup S = Max S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2215
using fS Se
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2216
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2217
  let ?m = "Max S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2218
  from Max_ge[OF fS] have Sm: "\<forall> x\<in> S. x \<le> ?m" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2219
  with rsup[OF Se] have lub: "isLub UNIV S (rsup S)" by (metis setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2220
  from Max_in[OF fS Se] lub have mrS: "?m \<le> rsup S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2221
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2222
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2223
  have "rsup S \<le> ?m" using Sm lub
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2224
    by (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2225
  ultimately  show ?thesis by arith 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2226
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2227
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2228
lemma rsup_finite_in: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2229
  shows "rsup S \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2230
  using rsup_finite_Max[OF fS Se] Max_in[OF fS Se] by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2231
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2232
lemma rsup_finite_Ub: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2233
  shows "isUb S S (rsup S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2234
  using rsup_finite_Max[OF fS Se] rsup_finite_in[OF fS Se] Max_ge[OF fS]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2235
  unfolding isUb_def setle_def by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2236
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2237
lemma rsup_finite_ge_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2238
  shows "a \<le> rsup S \<longleftrightarrow> (\<exists> x \<in> S. a \<le> x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2239
using rsup_finite_Ub[OF fS Se] by (auto simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2240
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2241
lemma rsup_finite_le_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2242
  shows "a \<ge> rsup S \<longleftrightarrow> (\<forall> x \<in> S. a \<ge> x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2243
using rsup_finite_Ub[OF fS Se] by (auto simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2244
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2245
lemma rsup_finite_gt_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2246
  shows "a < rsup S \<longleftrightarrow> (\<exists> x \<in> S. a < x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2247
using rsup_finite_Ub[OF fS Se] by (auto simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2248
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2249
lemma rsup_finite_lt_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2250
  shows "a > rsup S \<longleftrightarrow> (\<forall> x \<in> S. a > x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2251
using rsup_finite_Ub[OF fS Se] by (auto simp add: isUb_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2252
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2253
lemma rsup_unique: assumes b: "S *<= b" and S: "\<forall>b' < b. \<exists>x \<in> S. b' < x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2254
  shows "rsup S = b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2255
using b S  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2256
unfolding setle_def rsup_alt
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2257
apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2258
apply (rule some_equality)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2259
apply (metis  linorder_not_le order_eq_iff[symmetric])+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2260
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2261
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2262
lemma rsup_le_subset: "S\<noteq>{} \<Longrightarrow> S \<subseteq> T \<Longrightarrow> (\<exists>b. T *<= b) \<Longrightarrow> rsup S \<le> rsup T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2263
  apply (rule rsup_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2264
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2265
  using rsup[of T] by (auto simp add: isLub_def leastP_def setge_def setle_def isUb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2266
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2267
lemma isUb_def': "isUb R S = (\<lambda>x. S *<= x \<and> x \<in> R)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2268
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2269
  by (metis isUb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2270
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2271
lemma UNIV_trivial: "UNIV x" using UNIV_I[of x] by (metis mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2272
lemma rsup_bounds: assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2273
  shows "a \<le> rsup S \<and> rsup S \<le> b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2274
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2275
  from rsup[OF Se] u have lub: "isLub UNIV S (rsup S)" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2276
  hence b: "rsup S \<le> b" using u by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2277
  from Se obtain y where y: "y \<in> S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2278
  from lub l have "a \<le> rsup S" apply (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2279
    apply (erule ballE[where x=y])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2280
    apply (erule ballE[where x=y])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2281
    apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2282
    using y apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2283
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2284
  with b show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2285
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2286
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2287
lemma rsup_abs_le: "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>rsup S\<bar> \<le> a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2288
  unfolding abs_le_interval_iff  using rsup_bounds[of S "-a" a]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2289
  by (auto simp add: setge_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2290
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2291
lemma rsup_asclose: assumes S:"S \<noteq> {}" and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" shows "\<bar>rsup S - l\<bar> \<le> e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2292
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2293
  have th: "\<And>(x::real) l e. \<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2294
  show ?thesis using S b rsup_bounds[of S "l - e" "l+e"] unfolding th 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2295
    by  (auto simp add: setge_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2296
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2297
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2298
definition rinf:: "real set \<Rightarrow> real" where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2299
  "rinf S = (SOME a. isGlb UNIV S a)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2300
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2301
lemma rinf_alt: "rinf S = (SOME a. (\<forall>x \<in> S. x \<ge> a) \<and> (\<forall>b. (\<forall>x \<in> S. x \<ge> b) \<longrightarrow> a \<ge> b))"  by (auto simp  add: isGlb_def rinf_def greatestP_def isLb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2302
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2303
lemma reals_complete_Glb: assumes Se: "\<exists>x. x \<in> S" and lb: "\<exists> y. isLb UNIV S y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2304
  shows "\<exists>(t::real). isGlb UNIV S t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2305
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2306
  let ?M = "uminus ` S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2307
  from lb have th: "\<exists>y. isUb UNIV ?M y" apply (auto simp add: isUb_def isLb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2308
    by (rule_tac x="-y" in exI, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2309
  from Se have Me: "\<exists>x. x \<in> ?M" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2310
  from reals_complete[OF Me th] obtain t where t: "isLub UNIV ?M t" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2311
  have "isGlb UNIV S (- t)" using t
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2312
    apply (auto simp add: isLub_def isGlb_def leastP_def greatestP_def setle_def setge_def isUb_def isLb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2313
    apply (erule_tac x="-y" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2314
    apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2315
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2316
  then show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2317
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2318
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2319
lemma rinf: assumes Se: "S \<noteq> {}" and b: "\<exists>b. b <=* S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2320
  shows "isGlb UNIV S (rinf S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2321
using Se b
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2322
unfolding rinf_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2323
apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2324
apply (rule someI_ex)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2325
apply (rule reals_complete_Glb)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2326
apply (auto simp add: isLb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2327
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2328
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2329
lemma rinf_ge: assumes Se: "S \<noteq> {}" and Sb: "b <=* S" shows "rinf S \<ge> b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2330
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2331
  from Sb have bu: "isLb UNIV S b" by (simp add: isLb_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2332
  from rinf[OF Se] Sb have "isGlb UNIV S (rinf S)"  by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2333
  then show ?thesis using bu by (auto simp add: isGlb_def greatestP_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2334
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2335
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2336
lemma rinf_finite_Min: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2337
  shows "rinf S = Min S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2338
using fS Se
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2339
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2340
  let ?m = "Min S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2341
  from Min_le[OF fS] have Sm: "\<forall> x\<in> S. x \<ge> ?m" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2342
  with rinf[OF Se] have glb: "isGlb UNIV S (rinf S)" by (metis setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2343
  from Min_in[OF fS Se] glb have mrS: "?m \<ge> rinf S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2344
    by (auto simp add: isGlb_def greatestP_def setle_def setge_def isLb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2345
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2346
  have "rinf S \<ge> ?m" using Sm glb
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2347
    by (auto simp add: isGlb_def greatestP_def isLb_def setle_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2348
  ultimately  show ?thesis by arith 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2349
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2350
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2351
lemma rinf_finite_in: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2352
  shows "rinf S \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2353
  using rinf_finite_Min[OF fS Se] Min_in[OF fS Se] by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2354
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2355
lemma rinf_finite_Lb: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2356
  shows "isLb S S (rinf S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2357
  using rinf_finite_Min[OF fS Se] rinf_finite_in[OF fS Se] Min_le[OF fS]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2358
  unfolding isLb_def setge_def by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2359
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2360
lemma rinf_finite_ge_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2361
  shows "a \<le> rinf S \<longleftrightarrow> (\<forall> x \<in> S. a \<le> x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2362
using rinf_finite_Lb[OF fS Se] by (auto simp add: isLb_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2363
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2364
lemma rinf_finite_le_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2365
  shows "a \<ge> rinf S \<longleftrightarrow> (\<exists> x \<in> S. a \<ge> x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2366
using rinf_finite_Lb[OF fS Se] by (auto simp add: isLb_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2367
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2368
lemma rinf_finite_gt_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2369
  shows "a < rinf S \<longleftrightarrow> (\<forall> x \<in> S. a < x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2370
using rinf_finite_Lb[OF fS Se] by (auto simp add: isLb_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2371
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2372
lemma rinf_finite_lt_iff: assumes fS: "finite S" and Se: "S \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2373
  shows "a > rinf S \<longleftrightarrow> (\<exists> x \<in> S. a > x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2374
using rinf_finite_Lb[OF fS Se] by (auto simp add: isLb_def setge_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2375
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2376
lemma rinf_unique: assumes b: "b <=* S" and S: "\<forall>b' > b. \<exists>x \<in> S. b' > x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2377
  shows "rinf S = b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2378
using b S  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2379
unfolding setge_def rinf_alt
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2380
apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2381
apply (rule some_equality)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2382
apply (metis  linorder_not_le order_eq_iff[symmetric])+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2383
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2384
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2385
lemma rinf_ge_subset: "S\<noteq>{} \<Longrightarrow> S \<subseteq> T \<Longrightarrow> (\<exists>b. b <=* T) \<Longrightarrow> rinf S >= rinf T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2386
  apply (rule rinf_ge)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2387
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2388
  using rinf[of T] by (auto simp add: isGlb_def greatestP_def setge_def setle_def isLb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2389
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2390
lemma isLb_def': "isLb R S = (\<lambda>x. x <=* S \<and> x \<in> R)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2391
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2392
  by (metis isLb_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2393
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2394
lemma rinf_bounds: assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2395
  shows "a \<le> rinf S \<and> rinf S \<le> b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2396
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2397
  from rinf[OF Se] l have lub: "isGlb UNIV S (rinf S)" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2398
  hence b: "a \<le> rinf S" using l by (auto simp add: isGlb_def greatestP_def setle_def setge_def isLb_def')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2399
  from Se obtain y where y: "y \<in> S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2400
  from lub u have "b \<ge> rinf S" apply (auto simp add: isGlb_def greatestP_def setle_def setge_def isLb_def')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2401
    apply (erule ballE[where x=y])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2402
    apply (erule ballE[where x=y])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2403
    apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2404
    using y apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2405
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2406
  with b show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2407
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2408
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2409
lemma rinf_abs_ge: "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>rinf S\<bar> \<le> a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2410
  unfolding abs_le_interval_iff  using rinf_bounds[of S "-a" a]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2411
  by (auto simp add: setge_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2412
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2413
lemma rinf_asclose: assumes S:"S \<noteq> {}" and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" shows "\<bar>rinf S - l\<bar> \<le> e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2414
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2415
  have th: "\<And>(x::real) l e. \<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2416
  show ?thesis using S b rinf_bounds[of S "l - e" "l+e"] unfolding th 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2417
    by  (auto simp add: setge_def setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2418
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2419
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2420
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2421
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2422
subsection{* Operator norm. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2423
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2424
definition "onorm f = rsup {norm (f x)| x. norm x = 1}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2425
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2426
lemma norm_bound_generalize:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2427
  fixes f:: "real ^'n \<Rightarrow> real^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2428
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2429
  shows "(\<forall>x. norm x = 1 \<longrightarrow> norm (f x) \<le> b) \<longleftrightarrow> (\<forall>x. norm (f x) \<le> b * norm x)" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2430
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2431
  {assume H: ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2432
    {fix x :: "real^'n" assume x: "norm x = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2433
      from H[rule_format, of x] x have "norm (f x) \<le> b" by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2434
    then have ?lhs by blast }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2435
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2436
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2437
  {assume H: ?lhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2438
    from H[rule_format, of "basis 1"] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2439
    have bp: "b \<ge> 0" using norm_pos_le[of "f (basis 1)"] dimindex_ge_1[of "UNIV:: 'n set"]
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  2440
      by (auto simp add: norm_basis elim: order_trans [OF norm_ge_zero])
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2441
    {fix x :: "real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2442
      {assume "x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2443
	then have "norm (f x) \<le> b * norm x" by (simp add: linear_0[OF lf] norm_0 bp)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2444
      moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2445
      {assume x0: "x \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2446
	hence n0: "norm x \<noteq> 0" by (metis norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2447
	let ?c = "1/ norm x"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  2448
	have "norm (?c*s x) = 1" using x0 by (simp add: n0 norm_mul)
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2449
	with H have "norm (f(?c*s x)) \<le> b" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2450
	hence "?c * norm (f x) \<le> b" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2451
	  by (simp add: linear_cmul[OF lf] norm_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2452
	hence "norm (f x) \<le> b * norm x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2453
	  using n0 norm_pos_le[of x] by (auto simp add: field_simps)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2454
      ultimately have "norm (f x) \<le> b * norm x" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2455
    then have ?rhs by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2456
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2457
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2458
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2459
lemma onorm:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2460
  fixes f:: "real ^'n \<Rightarrow> real ^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2461
  assumes lf: "linear f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2462
  shows "norm (f x) <= onorm f * norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2463
  and "\<forall>x. norm (f x) <= b * norm x \<Longrightarrow> onorm f <= b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2464
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2465
  {
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2466
    let ?S = "{norm (f x) |x. norm x = 1}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2467
    have Se: "?S \<noteq> {}" using  norm_basis_1 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2468
    from linear_bounded[OF lf] have b: "\<exists> b. ?S *<= b" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2469
      unfolding norm_bound_generalize[OF lf, symmetric] by (auto simp add: setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2470
    {from rsup[OF Se b, unfolded onorm_def[symmetric]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2471
      show "norm (f x) <= onorm f * norm x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2472
	apply - 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2473
	apply (rule spec[where x = x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2474
	unfolding norm_bound_generalize[OF lf, symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2475
	by (auto simp add: isLub_def isUb_def leastP_def setge_def setle_def)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2476
    {
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2477
      show "\<forall>x. norm (f x) <= b * norm x \<Longrightarrow> onorm f <= b"  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2478
	using rsup[OF Se b, unfolded onorm_def[symmetric]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2479
	unfolding norm_bound_generalize[OF lf, symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2480
	by (auto simp add: isLub_def isUb_def leastP_def setge_def setle_def)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2481
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2482
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2483
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2484
lemma onorm_pos_le: assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" shows "0 <= onorm f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2485
  using order_trans[OF norm_pos_le onorm(1)[OF lf, of "basis 1"], unfolded norm_basis_1] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2486
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2487
lemma onorm_eq_0: assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2488
  shows "onorm f = 0 \<longleftrightarrow> (\<forall>x. f x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2489
  using onorm[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2490
  apply (auto simp add: norm_0 onorm_pos_le norm_le_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2491
  apply atomize
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2492
  apply (erule allE[where x="0::real"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2493
  using onorm_pos_le[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2494
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2495
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2496
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2497
lemma onorm_const: "onorm(\<lambda>x::real^'n. (y::real ^ 'm)) = norm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2498
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2499
  let ?f = "\<lambda>x::real^'n. (y::real ^ 'm)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2500
  have th: "{norm (?f x)| x. norm x = 1} = {norm y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2501
    by(auto intro: vector_choose_size set_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2502
  show ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2503
    unfolding onorm_def th
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2504
    apply (rule rsup_unique) by (simp_all  add: setle_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2505
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2506
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2507
lemma onorm_pos_lt: assumes lf: "linear (f::real ^ 'n \<Rightarrow> real ^'m)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2508
  shows "0 < onorm f \<longleftrightarrow> ~(\<forall>x. f x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2509
  unfolding onorm_eq_0[OF lf, symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2510
  using onorm_pos_le[OF lf] by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2511
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2512
lemma onorm_compose:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2513
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" and lg: "linear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2514
  shows "onorm (f o g) <= onorm f * onorm g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2515
  apply (rule onorm(2)[OF linear_compose[OF lg lf], rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2516
  unfolding o_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2517
  apply (subst mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2518
  apply (rule order_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2519
  apply (rule onorm(1)[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2520
  apply (rule mult_mono1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2521
  apply (rule onorm(1)[OF lg])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2522
  apply (rule onorm_pos_le[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2523
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2524
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2525
lemma onorm_neg_lemma: assumes lf: "linear (f::real ^'n \<Rightarrow> real^'m)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2526
  shows "onorm (\<lambda>x. - f x) \<le> onorm f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2527
  using onorm[OF linear_compose_neg[OF lf]] onorm[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2528
  unfolding norm_neg by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2529
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2530
lemma onorm_neg: assumes lf: "linear (f::real ^'n \<Rightarrow> real^'m)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2531
  shows "onorm (\<lambda>x. - f x) = onorm f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2532
  using onorm_neg_lemma[OF lf] onorm_neg_lemma[OF linear_compose_neg[OF lf]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2533
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2534
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2535
lemma onorm_triangle:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2536
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" and lg: "linear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2537
  shows "onorm (\<lambda>x. f x + g x) <= onorm f + onorm g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2538
  apply(rule onorm(2)[OF linear_compose_add[OF lf lg], rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2539
  apply (rule order_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2540
  apply (rule norm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2541
  apply (simp add: distrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2542
  apply (rule add_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2543
  apply (rule onorm(1)[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2544
  apply (rule onorm(1)[OF lg])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2545
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2546
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2547
lemma onorm_triangle_le: "linear (f::real ^'n \<Rightarrow> real ^'m) \<Longrightarrow> linear g \<Longrightarrow> onorm(f) + onorm(g) <= e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2548
  \<Longrightarrow> onorm(\<lambda>x. f x + g x) <= e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2549
  apply (rule order_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2550
  apply (rule onorm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2551
  apply assumption+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2552
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2553
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2554
lemma onorm_triangle_lt: "linear (f::real ^'n \<Rightarrow> real ^'m) \<Longrightarrow> linear g \<Longrightarrow> onorm(f) + onorm(g) < e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2555
  ==> onorm(\<lambda>x. f x + g x) < e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2556
  apply (rule order_le_less_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2557
  apply (rule onorm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2558
  by assumption+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2559
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2560
(* "lift" from 'a to 'a^1 and "drop" from 'a^1 to 'a -- FIXME: potential use of transfer *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2561
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2562
definition vec1:: "'a \<Rightarrow> 'a ^ 1" where "vec1 x = (\<chi> i. x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2563
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2564
definition dest_vec1:: "'a ^1 \<Rightarrow> 'a" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2565
  where "dest_vec1 x = (x$1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2566
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2567
lemma vec1_component[simp]: "(vec1 x)$1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2568
  by (simp add: vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2569
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2570
lemma vec1_dest_vec1[simp]: "vec1(dest_vec1 x) = x" "dest_vec1(vec1 y) = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2571
  by (simp_all add: vec1_def dest_vec1_def Cart_eq Cart_lambda_beta dimindex_def del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2572
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2573
lemma forall_vec1: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (vec1 x))" by (metis vec1_dest_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2574
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2575
lemma exists_vec1: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. P(vec1 x))" by (metis vec1_dest_vec1) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2576
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2577
lemma forall_dest_vec1: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P(dest_vec1 x))"  by (metis vec1_dest_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2578
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2579
lemma exists_dest_vec1: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. P(dest_vec1 x))"by (metis vec1_dest_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2580
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2581
lemma vec1_eq[simp]:  "vec1 x = vec1 y \<longleftrightarrow> x = y" by (metis vec1_dest_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2582
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2583
lemma dest_vec1_eq[simp]: "dest_vec1 x = dest_vec1 y \<longleftrightarrow> x = y" by (metis vec1_dest_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2584
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2585
lemma vec1_in_image_vec1: "vec1 x \<in> (vec1 ` S) \<longleftrightarrow> x \<in> S" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2586
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2587
lemma vec1_vec: "vec1 x = vec x" by (vector vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2588
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2589
lemma vec1_add: "vec1(x + y) = vec1 x + vec1 y" by (vector vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2590
lemma vec1_sub: "vec1(x - y) = vec1 x - vec1 y" by (vector vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2591
lemma vec1_cmul: "vec1(c* x) = c *s vec1 x " by (vector vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2592
lemma vec1_neg: "vec1(- x) = - vec1 x " by (vector vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2593
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2594
lemma vec1_setsum: assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2595
  shows "vec1(setsum f S) = setsum (vec1 o f) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2596
  apply (induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2597
  apply (simp add: vec1_vec)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2598
  apply (auto simp add: vec1_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2599
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2600
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2601
lemma dest_vec1_lambda: "dest_vec1(\<chi> i. x i) = x 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2602
  by (simp add: dest_vec1_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2603
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2604
lemma dest_vec1_vec: "dest_vec1(vec x) = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2605
  by (simp add: vec1_vec[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2606
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2607
lemma dest_vec1_add: "dest_vec1(x + y) = dest_vec1 x + dest_vec1 y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2608
 by (metis vec1_dest_vec1 vec1_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2609
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2610
lemma dest_vec1_sub: "dest_vec1(x - y) = dest_vec1 x - dest_vec1 y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2611
 by (metis vec1_dest_vec1 vec1_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2612
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2613
lemma dest_vec1_cmul: "dest_vec1(c*sx) = c * dest_vec1 x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2614
 by (metis vec1_dest_vec1 vec1_cmul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2615
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2616
lemma dest_vec1_neg: "dest_vec1(- x) = - dest_vec1 x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2617
 by (metis vec1_dest_vec1 vec1_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2618
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2619
lemma dest_vec1_0[simp]: "dest_vec1 0 = 0" by (metis vec_0 dest_vec1_vec)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2620
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2621
lemma dest_vec1_sum: assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2622
  shows "dest_vec1(setsum f S) = setsum (dest_vec1 o f) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2623
  apply (induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2624
  apply (simp add: dest_vec1_vec)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2625
  apply (auto simp add: dest_vec1_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2626
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2627
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2628
lemma norm_vec1: "norm(vec1 x) = abs(x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2629
  by (simp add: vec1_def norm_real)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2630
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2631
lemma dist_vec1: "dist(vec1 x) (vec1 y) = abs(x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2632
  by (simp only: dist_real vec1_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2633
lemma abs_dest_vec1: "norm x = \<bar>dest_vec1 x\<bar>"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2634
  by (metis vec1_dest_vec1 norm_vec1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2635
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2636
lemma linear_vmul_dest_vec1: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2637
  fixes f:: "'a::semiring_1^'n \<Rightarrow> 'a^1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2638
  shows "linear f \<Longrightarrow> linear (\<lambda>x. dest_vec1(f x) *s v)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2639
  unfolding dest_vec1_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2640
  apply (rule linear_vmul_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2641
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2642
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2643
lemma linear_from_scalars:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2644
  assumes lf: "linear (f::'a::comm_ring_1 ^1 \<Rightarrow> 'a^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2645
  shows "f = (\<lambda>x. dest_vec1 x *s column 1 (matrix f))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2646
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2647
  apply (subst matrix_works[OF lf, symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2648
  apply (auto simp add: Cart_eq matrix_vector_mult_def dest_vec1_def column_def Cart_lambda_beta vector_component dimindex_def mult_commute del: One_nat_def )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2649
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2650
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2651
lemma linear_to_scalars: assumes lf: "linear (f::'a::comm_ring_1 ^'n \<Rightarrow> 'a^1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2652
  shows "f = (\<lambda>x. vec1(row 1 (matrix f) \<bullet> x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2653
  apply (rule ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2654
  apply (subst matrix_works[OF lf, symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2655
  apply (auto simp add: Cart_eq matrix_vector_mult_def vec1_def row_def Cart_lambda_beta vector_component dimindex_def dot_def mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2656
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2657
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2658
lemma dest_vec1_eq_0: "dest_vec1 x = 0 \<longleftrightarrow> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2659
  by (simp add: dest_vec1_eq[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2660
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2661
lemma setsum_scalars: assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2662
  shows "setsum f S = vec1 (setsum (dest_vec1 o f) S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2663
  unfolding vec1_setsum[OF fS] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2664
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2665
lemma dest_vec1_wlog_le: "(\<And>(x::'a::linorder ^ 1) y. P x y \<longleftrightarrow> P y x)  \<Longrightarrow> (\<And>x y. dest_vec1 x <= dest_vec1 y ==> P x y) \<Longrightarrow> P x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2666
  apply (cases "dest_vec1 x \<le> dest_vec1 y")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2667
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2668
  apply (subgoal_tac "dest_vec1 y \<le> dest_vec1 x")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2669
  apply (auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2670
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2671
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2672
text{* Pasting vectors. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2673
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2674
lemma linear_fstcart: "linear fstcart"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2675
  by (auto simp add: linear_def fstcart_def Cart_eq Cart_lambda_beta vector_component dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2676
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2677
lemma linear_sndcart: "linear sndcart"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2678
  by (auto simp add: linear_def sndcart_def Cart_eq Cart_lambda_beta vector_component dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2679
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2680
lemma fstcart_vec[simp]: "fstcart(vec x) = vec x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2681
  by (vector fstcart_def vec_def dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2682
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2683
lemma fstcart_add[simp]:"fstcart(x + y) = fstcart (x::'a::{plus,times}^('b,'c) finite_sum) + fstcart y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2684
  using linear_fstcart[unfolded linear_def] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2685
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2686
lemma fstcart_cmul[simp]:"fstcart(c*s x) = c*s fstcart (x::'a::{plus,times}^('b,'c) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2687
  using linear_fstcart[unfolded linear_def] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2688
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2689
lemma fstcart_neg[simp]:"fstcart(- x) = - fstcart (x::'a::ring_1^('b,'c) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2690
unfolding vector_sneg_minus1 fstcart_cmul ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2691
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2692
lemma fstcart_sub[simp]:"fstcart(x - y) = fstcart (x::'a::ring_1^('b,'c) finite_sum) - fstcart y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2693
  unfolding diff_def fstcart_add fstcart_neg  ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2694
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2695
lemma fstcart_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2696
  fixes f:: "'d \<Rightarrow> 'a::semiring_1^_"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2697
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2698
  shows "fstcart (setsum f S) = setsum (\<lambda>i. fstcart (f i)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2699
  by (induct rule: finite_induct[OF fS], simp_all add: vec_0[symmetric] del: vec_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2700
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2701
lemma sndcart_vec[simp]: "sndcart(vec x) = vec x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2702
  by (vector sndcart_def vec_def dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2703
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2704
lemma sndcart_add[simp]:"sndcart(x + y) = sndcart (x::'a::{plus,times}^('b,'c) finite_sum) + sndcart y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2705
  using linear_sndcart[unfolded linear_def] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2706
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2707
lemma sndcart_cmul[simp]:"sndcart(c*s x) = c*s sndcart (x::'a::{plus,times}^('b,'c) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2708
  using linear_sndcart[unfolded linear_def] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2709
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2710
lemma sndcart_neg[simp]:"sndcart(- x) = - sndcart (x::'a::ring_1^('b,'c) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2711
unfolding vector_sneg_minus1 sndcart_cmul ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2712
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2713
lemma sndcart_sub[simp]:"sndcart(x - y) = sndcart (x::'a::ring_1^('b,'c) finite_sum) - sndcart y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2714
  unfolding diff_def sndcart_add sndcart_neg  ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2715
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2716
lemma sndcart_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2717
  fixes f:: "'d \<Rightarrow> 'a::semiring_1^_"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2718
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2719
  shows "sndcart (setsum f S) = setsum (\<lambda>i. sndcart (f i)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2720
  by (induct rule: finite_induct[OF fS], simp_all add: vec_0[symmetric] del: vec_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2721
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2722
lemma pastecart_vec[simp]: "pastecart (vec x) (vec x) = vec x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2723
  by (simp add: pastecart_eq fstcart_vec sndcart_vec fstcart_pastecart sndcart_pastecart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2724
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2725
lemma pastecart_add[simp]:"pastecart (x1::'a::{plus,times}^_) y1 + pastecart x2 y2 = pastecart (x1 + x2) (y1 + y2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2726
  by (simp add: pastecart_eq fstcart_add sndcart_add fstcart_pastecart sndcart_pastecart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2727
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2728
lemma pastecart_cmul[simp]: "pastecart (c *s (x1::'a::{plus,times}^_)) (c *s y1) = c *s pastecart x1 y1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2729
  by (simp add: pastecart_eq fstcart_pastecart sndcart_pastecart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2730
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2731
lemma pastecart_neg[simp]: "pastecart (- (x::'a::ring_1^_)) (- y) = - pastecart x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2732
  unfolding vector_sneg_minus1 pastecart_cmul ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2733
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2734
lemma pastecart_sub: "pastecart (x1::'a::ring_1^_) y1 - pastecart x2 y2 = pastecart (x1 - x2) (y1 - y2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2735
  by (simp add: diff_def pastecart_neg[symmetric] del: pastecart_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2736
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2737
lemma pastecart_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2738
  fixes f:: "'d \<Rightarrow> 'a::semiring_1^_"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2739
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2740
  shows "pastecart (setsum f S) (setsum g S) = setsum (\<lambda>i. pastecart (f i) (g i)) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2741
  by (simp  add: pastecart_eq fstcart_setsum[OF fS] sndcart_setsum[OF fS] fstcart_pastecart sndcart_pastecart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2742
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2743
lemma norm_fstcart: "norm(fstcart x) <= norm (x::real ^('n,'m) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2744
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2745
  let ?n = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2746
  let ?m = "dimindex (UNIV :: 'm set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2747
  let ?N = "{1 .. ?n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2748
  let ?M = "{1 .. ?m}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2749
  let ?NM = "{1 .. dimindex (UNIV :: ('n,'m) finite_sum set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2750
  have th_0: "1 \<le> ?n +1" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2751
  have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2752
    by (simp add: pastecart_fst_snd)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2753
  have th1: "fstcart x \<bullet> fstcart x \<le> pastecart (fstcart x) (sndcart x) \<bullet> pastecart (fstcart x) (sndcart x)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2754
    by (simp add: dot_def setsum_add_split[OF th_0, of _ ?m] pastecart_def dimindex_finite_sum Cart_lambda_beta setsum_nonneg zero_le_square del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2755
  then show ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2756
    unfolding th0 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  2757
    unfolding real_vector_norm_def real_sqrt_le_iff id_def
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2758
    by (simp add: dot_def dimindex_finite_sum Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2759
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2760
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2761
lemma dist_fstcart: "dist(fstcart (x::real^_)) (fstcart y) <= dist x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2762
  by (metis dist_def fstcart_sub[symmetric] norm_fstcart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2763
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2764
lemma norm_sndcart: "norm(sndcart x) <= norm (x::real ^('n,'m) finite_sum)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2765
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2766
  let ?n = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2767
  let ?m = "dimindex (UNIV :: 'm set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2768
  let ?N = "{1 .. ?n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2769
  let ?M = "{1 .. ?m}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2770
  let ?nm = "dimindex (UNIV :: ('n,'m) finite_sum set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2771
  let ?NM = "{1 .. ?nm}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2772
  have thnm[simp]: "?nm = ?n + ?m" by (simp add: dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2773
  have th_0: "1 \<le> ?n +1" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2774
  have th0: "norm x = norm (pastecart (fstcart x) (sndcart x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2775
    by (simp add: pastecart_fst_snd)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2776
  let ?f = "\<lambda>n. n - ?n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2777
  let ?S = "{?n+1 .. ?nm}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2778
  have finj:"inj_on ?f ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2779
    using dimindex_nonzero[of "UNIV :: 'n set"] dimindex_nonzero[of "UNIV :: 'm set"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2780
    apply (simp add: Ball_def atLeastAtMost_iff inj_on_def dimindex_finite_sum del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2781
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2782
  have fS: "?f ` ?S = ?M" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2783
    apply (rule set_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2784
    apply (simp add: image_iff Bex_def) using dimindex_nonzero[of "UNIV :: 'n set"] dimindex_nonzero[of "UNIV :: 'm set"] by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2785
  have th1: "sndcart x \<bullet> sndcart x \<le> pastecart (fstcart x) (sndcart x) \<bullet> pastecart (fstcart x) (sndcart x)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2786
    by (simp add: dot_def setsum_add_split[OF th_0, of _ ?m] pastecart_def dimindex_finite_sum Cart_lambda_beta setsum_nonneg zero_le_square setsum_reindex[OF finj, unfolded fS] del: One_nat_def)    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2787
  then show ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2788
    unfolding th0 
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  2789
    unfolding real_vector_norm_def real_sqrt_le_iff id_def
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2790
    by (simp add: dot_def dimindex_finite_sum Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2791
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2792
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2793
lemma dist_sndcart: "dist(sndcart (x::real^_)) (sndcart y) <= dist x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2794
  by (metis dist_def sndcart_sub[symmetric] norm_sndcart)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2795
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2796
lemma dot_pastecart: "(pastecart (x1::'a::{times,comm_monoid_add}^'n) (x2::'a::{times,comm_monoid_add}^'m)) \<bullet> (pastecart y1 y2) =  x1 \<bullet> y1 + x2 \<bullet> y2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2797
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2798
  let ?n = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2799
  let ?m = "dimindex (UNIV :: 'm set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2800
  let ?N = "{1 .. ?n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2801
  let ?M = "{1 .. ?m}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2802
  let ?nm = "dimindex (UNIV :: ('n,'m) finite_sum set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2803
  let ?NM = "{1 .. ?nm}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2804
  have thnm: "?nm = ?n + ?m" by (simp add: dimindex_finite_sum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2805
  have th_0: "1 \<le> ?n +1" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2806
  have th_1: "\<And>i. i \<in> {?m + 1 .. ?nm} \<Longrightarrow> i - ?m \<in> ?N" apply (simp add: thnm) by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2807
  let ?f = "\<lambda>a b i. (a$i) * (b$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2808
  let ?g = "?f (pastecart x1 x2) (pastecart y1 y2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2809
  let ?S = "{?n +1 .. ?nm}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2810
  {fix i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2811
    assume i: "i \<in> ?N"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2812
    have "?g i = ?f x1 y1 i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2813
      using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2814
      apply (simp add: pastecart_def Cart_lambda_beta thnm) done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2815
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2816
  hence th2: "setsum ?g ?N = setsum (?f x1 y1) ?N"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2817
    apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2818
    apply (rule setsum_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2819
    apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2820
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2821
  {fix i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2822
    assume i: "i \<in> ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2823
    have "?g i = ?f x2 y2 (i - ?n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2824
      using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2825
      apply (simp add: pastecart_def Cart_lambda_beta thnm) done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2826
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2827
  hence th3: "setsum ?g ?S = setsum (\<lambda>i. ?f x2 y2 (i -?n)) ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2828
    apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2829
    apply (rule setsum_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2830
    apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2831
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2832
  let ?r = "\<lambda>n. n - ?n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2833
  have rinj: "inj_on ?r ?S" apply (simp add: inj_on_def Ball_def thnm) by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2834
  have rS: "?r ` ?S = ?M" apply (rule set_ext) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2835
    apply (simp add: thnm image_iff Bex_def) by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2836
  have "pastecart x1 x2 \<bullet> (pastecart y1 y2) = setsum ?g ?NM" by (simp add: dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2837
  also have "\<dots> = setsum ?g ?N + setsum ?g ?S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2838
    by (simp add: dot_def thnm setsum_add_split[OF th_0, of _ ?m] del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2839
  also have "\<dots> = setsum (?f x1 y1) ?N + setsum (?f x2 y2) ?M"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2840
    unfolding setsum_reindex[OF rinj, unfolded rS o_def] th2 th3 ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2841
  finally 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2842
  show ?thesis by (simp add: dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2843
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2844
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2845
lemma norm_pastecart: "norm(pastecart x y) <= norm(x :: real ^ _) + norm(y)"
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  2846
  unfolding real_vector_norm_def dot_pastecart real_sqrt_le_iff id_def
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2847
  apply (rule power2_le_imp_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2848
  apply (simp add: real_sqrt_pow2[OF add_nonneg_nonneg[OF dot_pos_le[of x] dot_pos_le[of y]]])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2849
  apply (auto simp add: power2_eq_square ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2850
  apply (simp add: power2_eq_square[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2851
  apply (rule mult_nonneg_nonneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2852
  apply (simp_all add: real_sqrt_pow2[OF dot_pos_le])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2853
  apply (rule add_nonneg_nonneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2854
  apply (simp_all add: real_sqrt_pow2[OF dot_pos_le])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2855
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2856
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2857
subsection {* A generic notion of "hull" (convex, affine, conic hull and closure). *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2858
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2859
definition hull :: "'a set set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "hull" 75) where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2860
  "S hull s = Inter {t. t \<in> S \<and> s \<subseteq> t}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2861
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2862
lemma hull_same: "s \<in> S \<Longrightarrow> S hull s = s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2863
  unfolding hull_def by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2864
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2865
lemma hull_in: "(\<And>T. T \<subseteq> S ==> Inter T \<in> S) ==> (S hull s) \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2866
unfolding hull_def subset_iff by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2867
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2868
lemma hull_eq: "(\<And>T. T \<subseteq> S ==> Inter T \<in> S) ==> (S hull s) = s \<longleftrightarrow> s \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2869
using hull_same[of s S] hull_in[of S s] by metis  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2870
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2871
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2872
lemma hull_hull: "S hull (S hull s) = S hull s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2873
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2874
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2875
lemma hull_subset: "s \<subseteq> (S hull s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2876
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2877
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2878
lemma hull_mono: " s \<subseteq> t ==> (S hull s) \<subseteq> (S hull t)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2879
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2880
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2881
lemma hull_antimono: "S \<subseteq> T ==> (T hull s) \<subseteq> (S hull s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2882
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2883
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2884
lemma hull_minimal: "s \<subseteq> t \<Longrightarrow> t \<in> S ==> (S hull s) \<subseteq> t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2885
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2886
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2887
lemma subset_hull: "t \<in> S ==> S hull s \<subseteq> t \<longleftrightarrow>  s \<subseteq> t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2888
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2889
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2890
lemma hull_unique: "s \<subseteq> t \<Longrightarrow> t \<in> S \<Longrightarrow> (\<And>t'. s \<subseteq> t' \<Longrightarrow> t' \<in> S ==> t \<subseteq> t')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2891
           ==> (S hull s = t)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2892
unfolding hull_def by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2893
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2894
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"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2895
  using hull_minimal[of S "{x. P x}" Q]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2896
  by (auto simp add: subset_eq Collect_def mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2897
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2898
lemma hull_inc: "x \<in> S \<Longrightarrow> x \<in> P hull S" by (metis hull_subset subset_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2899
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2900
lemma hull_union_subset: "(S hull s) \<union> (S hull t) \<subseteq> (S hull (s \<union> t))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2901
unfolding Un_subset_iff by (metis hull_mono Un_upper1 Un_upper2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2902
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2903
lemma hull_union: assumes T: "\<And>T. T \<subseteq> S ==> Inter T \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2904
  shows "S hull (s \<union> t) = S hull (S hull s \<union> S hull t)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2905
apply rule
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2906
apply (rule hull_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2907
unfolding Un_subset_iff
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2908
apply (metis hull_subset Un_upper1 Un_upper2 subset_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2909
apply (rule hull_minimal)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2910
apply (metis hull_union_subset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2911
apply (metis hull_in T)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2912
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2913
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2914
lemma hull_redundant_eq: "a \<in> (S hull s) \<longleftrightarrow> (S hull (insert a s) = S hull s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2915
  unfolding hull_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2916
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2917
lemma hull_redundant: "a \<in> (S hull s) ==> (S hull (insert a s) = S hull s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2918
by (metis hull_redundant_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2919
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2920
text{* Archimedian properties and useful consequences. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2921
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2922
lemma real_arch_simple: "\<exists>n. x <= real (n::nat)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2923
  using reals_Archimedean2[of x] apply auto by (rule_tac x="Suc n" in exI, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2924
lemmas real_arch_lt = reals_Archimedean2
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2925
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2926
lemmas real_arch = reals_Archimedean3
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2927
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2928
lemma real_arch_inv: "0 < e \<longleftrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2929
  using reals_Archimedean
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2930
  apply (auto simp add: field_simps inverse_positive_iff_positive)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2931
  apply (subgoal_tac "inverse (real n) > 0")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2932
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2933
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2934
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2935
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2936
lemma real_pow_lbound: "0 <= x ==> 1 + real n * x <= (1 + x) ^ n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2937
proof(induct n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2938
  case 0 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2939
next 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2940
  case (Suc n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2941
  hence h: "1 + real n * x \<le> (1 + x) ^ n" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2942
  from h have p: "1 \<le> (1 + x) ^ n" using Suc.prems by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2943
  from h have "1 + real n * x + x \<le> (1 + x) ^ n + x" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2944
  also have "\<dots> \<le> (1 + x) ^ Suc n" apply (subst diff_le_0_iff_le[symmetric]) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2945
    apply (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2946
    using mult_left_mono[OF p Suc.prems] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2947
  finally show ?case  by (simp add: real_of_nat_Suc ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2948
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2949
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2950
lemma real_arch_pow: assumes x: "1 < (x::real)" shows "\<exists>n. y < x^n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2951
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2952
  from x have x0: "x - 1 > 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2953
  from real_arch[OF x0, rule_format, of y] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2954
  obtain n::nat where n:"y < real n * (x - 1)" by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2955
  from x0 have x00: "x- 1 \<ge> 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2956
  from real_pow_lbound[OF x00, of n] n 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2957
  have "y < x^n" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2958
  then show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2959
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2960
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2961
lemma real_arch_pow2: "\<exists>n. (x::real) < 2^ n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2962
  using real_arch_pow[of 2 x] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2963
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2964
lemma real_arch_pow_inv: assumes y: "(y::real) > 0" and x1: "x < 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2965
  shows "\<exists>n. x^n < y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2966
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2967
  {assume x0: "x > 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2968
    from x0 x1 have ix: "1 < 1/x" by (simp add: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2969
    from real_arch_pow[OF ix, of "1/y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2970
    obtain n where n: "1/y < (1/x)^n" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2971
    then 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2972
    have ?thesis using y x0 by (auto simp add: field_simps power_divide) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2973
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2974
  {assume "\<not> x > 0" with y x1 have ?thesis apply auto by (rule exI[where x=1], auto)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2975
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2976
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2977
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2978
lemma forall_pos_mono: "(\<And>d e::real. d < e \<Longrightarrow> P d ==> P e) \<Longrightarrow> (\<And>n::nat. n \<noteq> 0 ==> P(inverse(real n))) \<Longrightarrow> (\<And>e. 0 < e ==> P e)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2979
  by (metis real_arch_inv)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2980
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2981
lemma forall_pos_mono_1: "(\<And>d e::real. d < e \<Longrightarrow> P d ==> P e) \<Longrightarrow> (\<And>n. P(inverse(real (Suc n)))) ==> 0 < e ==> P e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2982
  apply (rule forall_pos_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2983
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2984
  apply (atomize)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2985
  apply (erule_tac x="n - 1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2986
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2987
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2988
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2989
lemma real_archimedian_rdiv_eq_0: assumes x0: "x \<ge> 0" and c: "c \<ge> 0" and xc: "\<forall>(m::nat)>0. real m * x \<le> c"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2990
  shows "x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2991
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2992
  {assume "x \<noteq> 0" with x0 have xp: "x > 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2993
    from real_arch[OF xp, rule_format, of c] obtain n::nat where n: "c < real n * x"  by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2994
    with xc[rule_format, of n] have "n = 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2995
    with n c have False by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2996
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2997
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2998
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  2999
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3000
(* Relate max and min to sup and inf.                                        *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3001
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3002
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3003
lemma real_max_rsup: "max x y = rsup {x,y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3004
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3005
  have f: "finite {x, y}" "{x,y} \<noteq> {}"  by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3006
  from rsup_finite_le_iff[OF f, of "max x y"] have "rsup {x,y} \<le> max x y" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3007
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3008
  have "max x y \<le> rsup {x,y}" using rsup_finite_ge_iff[OF f, of "max x y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3009
    by (simp add: linorder_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3010
  ultimately show ?thesis by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3011
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3012
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3013
lemma real_min_rinf: "min x y = rinf {x,y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3014
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3015
  have f: "finite {x, y}" "{x,y} \<noteq> {}"  by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3016
  from rinf_finite_le_iff[OF f, of "min x y"] have "rinf {x,y} \<le> min x y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3017
    by (simp add: linorder_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3018
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3019
  have "min x y \<le> rinf {x,y}" using rinf_finite_ge_iff[OF f, of "min x y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3020
    by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3021
  ultimately show ?thesis by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3022
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3023
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3024
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3025
(* Geometric progression.                                                    *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3026
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3027
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3028
lemma sum_gp_basic: "((1::'a::{field, recpower}) - x) * setsum (\<lambda>i. x^i) {0 .. n} = (1 - x^(Suc n))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3029
  (is "?lhs = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3030
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3031
  {assume x1: "x = 1" hence ?thesis by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3032
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3033
  {assume x1: "x\<noteq>1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3034
    hence x1': "x - 1 \<noteq> 0" "1 - x \<noteq> 0" "x - 1 = - (1 - x)" "- (1 - x) \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3035
    from geometric_sum[OF x1, of "Suc n", unfolded x1']
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3036
    have "(- (1 - x)) * setsum (\<lambda>i. x^i) {0 .. n} = - (1 - x^(Suc n))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3037
      unfolding atLeastLessThanSuc_atLeastAtMost
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3038
      using x1' apply (auto simp only: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3039
      apply (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3040
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3041
    then have ?thesis by (simp add: ring_simps) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3042
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3043
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3044
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3045
lemma sum_gp_multiplied: assumes mn: "m <= n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3046
  shows "((1::'a::{field, recpower}) - x) * setsum (op ^ x) {m..n} = x^m - x^ Suc n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3047
  (is "?lhs = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3048
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3049
  let ?S = "{0..(n - m)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3050
  from mn have mn': "n - m \<ge> 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3051
  let ?f = "op + m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3052
  have i: "inj_on ?f ?S" unfolding inj_on_def by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3053
  have f: "?f ` ?S = {m..n}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3054
    using mn apply (auto simp add: image_iff Bex_def) by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3055
  have th: "op ^ x o op + m = (\<lambda>i. x^m * x^i)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3056
    by (rule ext, simp add: power_add power_mult)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3057
  from setsum_reindex[OF i, of "op ^ x", unfolded f th setsum_right_distrib[symmetric]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3058
  have "?lhs = x^m * ((1 - x) * setsum (op ^ x) {0..n - m})" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3059
  then show ?thesis unfolding sum_gp_basic using mn
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3060
    by (simp add: ring_simps power_add[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3061
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3062
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3063
lemma sum_gp: "setsum (op ^ (x::'a::{field, recpower})) {m .. n} = 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3064
   (if n < m then 0 else if x = 1 then of_nat ((n + 1) - m) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3065
                    else (x^ m - x^ (Suc n)) / (1 - x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3066
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3067
  {assume nm: "n < m" hence ?thesis by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3068
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3069
  {assume "\<not> n < m" hence nm: "m \<le> n" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3070
    {assume x: "x = 1"  hence ?thesis by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3071
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3072
    {assume x: "x \<noteq> 1" hence nz: "1 - x \<noteq> 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3073
      from sum_gp_multiplied[OF nm, of x] nz have ?thesis by (simp add: field_simps)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3074
    ultimately have ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3075
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3076
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3077
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3078
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3079
lemma sum_gp_offset: "setsum (op ^ (x::'a::{field,recpower})) {m .. m+n} = 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3080
  (if x = 1 then of_nat n + 1 else x^m * (1 - x^Suc n) / (1 - x))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3081
  unfolding sum_gp[of x m "m + n"] power_Suc
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3082
  by (simp add: ring_simps power_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3083
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3084
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3085
subsection{* A bit of linear algebra. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3086
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3087
definition "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 *s x \<in>S )"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3088
definition "span S = (subspace hull S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3089
definition "dependent S \<longleftrightarrow> (\<exists>a \<in> S. a \<in> span(S - {a}))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3090
abbreviation "independent s == ~(dependent s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3091
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3092
(* Closure properties of subspaces.                                          *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3093
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3094
lemma subspace_UNIV[simp]: "subspace(UNIV)" by (simp add: subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3095
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3096
lemma subspace_0: "subspace S ==> 0 \<in> S" by (metis subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3097
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3098
lemma subspace_add: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S ==> x + y \<in> S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3099
  by (metis subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3100
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3101
lemma subspace_mul: "subspace S \<Longrightarrow> x \<in> S \<Longrightarrow> c *s x \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3102
  by (metis subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3103
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3104
lemma subspace_neg: "subspace S \<Longrightarrow> (x::'a::ring_1^'n) \<in> S \<Longrightarrow> - x \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3105
  by (metis vector_sneg_minus1 subspace_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3106
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3107
lemma subspace_sub: "subspace S \<Longrightarrow> (x::'a::ring_1^'n) \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x - y \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3108
  by (metis diff_def subspace_add subspace_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3109
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3110
lemma subspace_setsum:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3111
  assumes sA: "subspace A" and fB: "finite B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3112
  and f: "\<forall>x\<in> B. f x \<in> A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3113
  shows "setsum f B \<in> A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3114
  using  fB f sA
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3115
  apply(induct rule: finite_induct[OF fB])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3116
  by (simp add: subspace_def sA, auto simp add: sA subspace_add) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3117
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3118
lemma subspace_linear_image: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3119
  assumes lf: "linear (f::'a::semiring_1^'n \<Rightarrow> _)" and sS: "subspace S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3120
  shows "subspace(f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3121
  using lf sS linear_0[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3122
  unfolding linear_def subspace_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3123
  apply (auto simp add: image_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3124
  apply (rule_tac x="x + y" in bexI, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3125
  apply (rule_tac x="c*s x" in bexI, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3126
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3127
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3128
lemma subspace_linear_preimage: "linear (f::'a::semiring_1^'n \<Rightarrow> _) ==> subspace S ==> subspace {x. f x \<in> S}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3129
  by (auto simp add: subspace_def linear_def linear_0[of f])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3130
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3131
lemma subspace_trivial: "subspace {0::'a::semiring_1 ^_}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3132
  by (simp add: subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3133
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3134
lemma subspace_inter: "subspace A \<Longrightarrow> subspace B ==> subspace (A \<inter> B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3135
  by (simp add: subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3136
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3137
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3138
lemma span_mono: "A \<subseteq> B ==> span A \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3139
  by (metis span_def hull_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3140
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3141
lemma subspace_span: "subspace(span S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3142
  unfolding span_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3143
  apply (rule hull_in[unfolded mem_def])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3144
  apply (simp only: subspace_def Inter_iff Int_iff subset_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3145
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3146
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3147
  apply (simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3148
  apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3149
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3150
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3151
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3152
  apply (clarsimp simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3153
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3154
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3155
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3156
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3157
  apply (erule_tac x="X" in ballE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3158
  apply (simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3159
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3160
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3161
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3162
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3163
lemma span_clauses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3164
  "a \<in> S ==> a \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3165
  "0 \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3166
  "x\<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3167
  "x \<in> span S \<Longrightarrow> c *s x \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3168
  by (metis span_def hull_subset subset_eq subspace_span subspace_def)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3169
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3170
lemma span_induct: assumes SP: "\<And>x. x \<in> S ==> P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3171
  and P: "subspace P" and x: "x \<in> span S" shows "P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3172
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3173
  from SP have SP': "S \<subseteq> P" by (simp add: mem_def subset_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3174
  from P have P': "P \<in> subspace" by (simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3175
  from x hull_minimal[OF SP' P', unfolded span_def[symmetric]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3176
  show "P x" by (metis mem_def subset_eq) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3177
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3178
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3179
lemma span_empty: "span {} = {(0::'a::semiring_0 ^ 'n)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3180
  apply (simp add: span_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3181
  apply (rule hull_unique)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3182
  apply (auto simp add: mem_def subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3183
  unfolding mem_def[of "0::'a^'n", symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3184
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3185
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3186
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3187
lemma independent_empty: "independent {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3188
  by (simp add: dependent_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3189
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3190
lemma independent_mono: "independent A \<Longrightarrow> B \<subseteq> A ==> independent B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3191
  apply (clarsimp simp add: dependent_def span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3192
  apply (subgoal_tac "span (B - {a}) \<le> span (A - {a})")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3193
  apply force
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3194
  apply (rule span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3195
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3196
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3197
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3198
lemma span_subspace: "A \<subseteq> B \<Longrightarrow> B \<le> span A \<Longrightarrow>  subspace B \<Longrightarrow> span A = B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3199
  by (metis order_antisym span_def hull_minimal mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3200
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3201
lemma span_induct': assumes SP: "\<forall>x \<in> S. P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3202
  and P: "subspace P" shows "\<forall>x \<in> span S. P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3203
  using span_induct SP P by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3204
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3205
inductive span_induct_alt_help for S:: "'a::semiring_1^'n \<Rightarrow> bool"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3206
  where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3207
  span_induct_alt_help_0: "span_induct_alt_help S 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3208
  | span_induct_alt_help_S: "x \<in> S \<Longrightarrow> span_induct_alt_help S z \<Longrightarrow> span_induct_alt_help S (c *s x + z)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3209
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3210
lemma span_induct_alt': 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3211
  assumes h0: "h (0::'a::semiring_1^'n)" and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c*s x + y)" shows "\<forall>x \<in> span S. h x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3212
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3213
  {fix x:: "'a^'n" assume x: "span_induct_alt_help S x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3214
    have "h x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3215
      apply (rule span_induct_alt_help.induct[OF x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3216
      apply (rule h0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3217
      apply (rule hS, assumption, assumption)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3218
      done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3219
  note th0 = this
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3220
  {fix x assume x: "x \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3221
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3222
    have "span_induct_alt_help S x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3223
      proof(rule span_induct[where x=x and S=S])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3224
	show "x \<in> span S" using x .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3225
      next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3226
	fix x assume xS : "x \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3227
	  from span_induct_alt_help_S[OF xS span_induct_alt_help_0, of 1]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3228
	  show "span_induct_alt_help S x" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3229
	next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3230
	have "span_induct_alt_help S 0" by (rule span_induct_alt_help_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3231
	moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3232
	{fix x y assume h: "span_induct_alt_help S x" "span_induct_alt_help S y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3233
	  from h 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3234
	  have "span_induct_alt_help S (x + y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3235
	    apply (induct rule: span_induct_alt_help.induct)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3236
	    apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3237
	    unfolding add_assoc
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3238
	    apply (rule span_induct_alt_help_S)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3239
	    apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3240
	    apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3241
	    done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3242
	moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3243
	{fix c x assume xt: "span_induct_alt_help S x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3244
	  then have "span_induct_alt_help S (c*s x)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3245
	    apply (induct rule: span_induct_alt_help.induct)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3246
	    apply (simp add: span_induct_alt_help_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3247
	    apply (simp add: vector_smult_assoc vector_add_ldistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3248
	    apply (rule span_induct_alt_help_S)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3249
	    apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3250
	    apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3251
	    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3252
	}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3253
	ultimately show "subspace (span_induct_alt_help S)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3254
	  unfolding subspace_def mem_def Ball_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3255
      qed}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3256
  with th0 show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3257
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3258
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3259
lemma span_induct_alt: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3260
  assumes h0: "h (0::'a::semiring_1^'n)" and hS: "\<And>c x y. x \<in> S \<Longrightarrow> h y \<Longrightarrow> h (c*s x + y)" and x: "x \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3261
  shows "h x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3262
using span_induct_alt'[of h S] h0 hS x by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3263
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3264
(* Individual closure properties. *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3265
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3266
lemma span_superset: "x \<in> S ==> x \<in> span S" by (metis span_clauses)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3267
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3268
lemma span_0: "0 \<in> span S" by (metis subspace_span subspace_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3269
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3270
lemma span_add: "x \<in> span S \<Longrightarrow> y \<in> span S ==> x + y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3271
  by (metis subspace_add subspace_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3272
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3273
lemma span_mul: "x \<in> span S ==> (c *s x) \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3274
  by (metis subspace_span subspace_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3275
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3276
lemma span_neg: "x \<in> span S ==> - (x::'a::ring_1^'n) \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3277
  by (metis subspace_neg subspace_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3278
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3279
lemma span_sub: "(x::'a::ring_1^'n) \<in> span S \<Longrightarrow> y \<in> span S ==> x - y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3280
  by (metis subspace_span subspace_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3281
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3282
lemma span_setsum: "finite A \<Longrightarrow> \<forall>x \<in> A. f x \<in> span S ==> setsum f A \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3283
  apply (rule subspace_setsum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3284
  by (metis subspace_span subspace_setsum)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3285
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3286
lemma span_add_eq: "(x::'a::ring_1^'n) \<in> span S \<Longrightarrow> x + y \<in> span S \<longleftrightarrow> y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3287
  apply (auto simp only: span_add span_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3288
  apply (subgoal_tac "(x + y) - x \<in> span S", simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3289
  by (simp only: span_add span_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3290
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3291
(* Mapping under linear image. *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3292
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3293
lemma span_linear_image: assumes lf: "linear (f::'a::semiring_1 ^ 'n => _)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3294
  shows "span (f ` S) = f ` (span S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3295
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3296
  {fix x
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3297
    assume x: "x \<in> span (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3298
    have "x \<in> f ` span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3299
      apply (rule span_induct[where x=x and S = "f ` S"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3300
      apply (clarsimp simp add: image_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3301
      apply (frule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3302
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3303
      apply (simp only: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3304
      apply (rule subspace_linear_image[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3305
      apply (rule subspace_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3306
      apply (rule x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3307
      done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3308
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3309
  {fix x assume x: "x \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3310
    have th0:"(\<lambda>a. f a \<in> span (f ` S)) = {x. f x \<in> span (f ` S)}" apply (rule set_ext) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3311
      unfolding mem_def Collect_def ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3312
    have "f x \<in> span (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3313
      apply (rule span_induct[where S=S])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3314
      apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3315
      apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3316
      apply (subst th0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3317
      apply (rule subspace_linear_preimage[OF lf subspace_span, of "f ` S"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3318
      apply (rule x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3319
      done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3320
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3321
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3322
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3323
(* The key breakdown property. *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3324
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3325
lemma span_breakdown:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3326
  assumes bS: "(b::'a::ring_1 ^ 'n) \<in> S" and aS: "a \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3327
  shows "\<exists>k. a - k*s b \<in> span (S - {b})" (is "?P a")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3328
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3329
  {fix x assume xS: "x \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3330
    {assume ab: "x = b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3331
      then have "?P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3332
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3333
	apply (rule exI[where x="1"], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3334
	by (rule span_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3335
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3336
    {assume ab: "x \<noteq> b" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3337
      then have "?P x"  using xS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3338
	apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3339
	apply (rule exI[where x=0])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3340
	apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3341
	by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3342
    ultimately have "?P x" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3343
  moreover have "subspace ?P" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3344
    unfolding subspace_def 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3345
    apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3346
    apply (simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3347
    apply (rule exI[where x=0])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3348
    using span_0[of "S - {b}"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3349
    apply (simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3350
    apply (clarsimp simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3351
    apply (rule_tac x="k + ka" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3352
    apply (subgoal_tac "x + y - (k + ka) *s b = (x - k*s b) + (y - ka *s b)")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3353
    apply (simp only: )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3354
    apply (rule span_add[unfolded mem_def])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3355
    apply assumption+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3356
    apply (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3357
    apply (clarsimp simp add: mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3358
    apply (rule_tac x= "c*k" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3359
    apply (subgoal_tac "c *s x - (c * k) *s b = c*s (x - k*s b)")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3360
    apply (simp only: )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3361
    apply (rule span_mul[unfolded mem_def])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3362
    apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3363
    by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3364
  ultimately show "?P a" using aS span_induct[where S=S and P= "?P"] by metis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3365
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3366
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3367
lemma span_breakdown_eq:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3368
  "(x::'a::ring_1^'n) \<in> span (insert a S) \<longleftrightarrow> (\<exists>k. (x - k *s a) \<in> span S)" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3369
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3370
  {assume x: "x \<in> span (insert a S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3371
    from x span_breakdown[of "a" "insert a S" "x"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3372
    have ?rhs apply clarsimp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3373
      apply (rule_tac x= "k" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3374
      apply (rule set_rev_mp[of _ "span (S - {a})" _])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3375
      apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3376
      apply (rule span_mono)      
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3377
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3378
      done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3379
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3380
  { fix k assume k: "x - k *s a \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3381
    have eq: "x = (x - k *s a) + k *s a" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3382
    have "(x - k *s a) + k *s a \<in> span (insert a S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3383
      apply (rule span_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3384
      apply (rule set_rev_mp[of _ "span S" _])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3385
      apply (rule k)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3386
      apply (rule span_mono)      
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3387
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3388
      apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3389
      apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3390
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3391
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3392
    then have ?lhs using eq by metis}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3393
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3394
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3395
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3396
(* Hence some "reversal" results.*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3397
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3398
lemma in_span_insert:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3399
  assumes a: "(a::'a::field^'n) \<in> span (insert b S)" and na: "a \<notin> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3400
  shows "b \<in> span (insert a S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3401
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3402
  from span_breakdown[of b "insert b S" a, OF insertI1 a]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3403
  obtain k where k: "a - k*s b \<in> span (S - {b})" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3404
  {assume k0: "k = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3405
    with k have "a \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3406
      apply (simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3407
      apply (rule set_rev_mp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3408
      apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3409
      apply (rule span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3410
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3411
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3412
    with na  have ?thesis by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3413
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3414
  {assume k0: "k \<noteq> 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3415
    have eq: "b = (1/k) *s a - ((1/k) *s a - b)" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3416
    from k0 have eq': "(1/k) *s (a - k*s b) = (1/k) *s a - b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3417
      by (vector field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3418
    from k have "(1/k) *s (a - k*s b) \<in> span (S - {b})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3419
      by (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3420
    hence th: "(1/k) *s a - b \<in> span (S - {b})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3421
      unfolding eq' .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3422
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3423
    from k
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3424
    have ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3425
      apply (subst eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3426
      apply (rule span_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3427
      apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3428
      apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3429
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3430
      apply (rule set_rev_mp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3431
      apply (rule th)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3432
      apply (rule span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3433
      using na by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3434
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3435
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3436
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3437
lemma in_span_delete: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3438
  assumes a: "(a::'a::field^'n) \<in> span S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3439
  and na: "a \<notin> span (S-{b})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3440
  shows "b \<in> span (insert a (S - {b}))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3441
  apply (rule in_span_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3442
  apply (rule set_rev_mp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3443
  apply (rule a)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3444
  apply (rule span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3445
  apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3446
  apply (rule na)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3447
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3448
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3449
(* Transitivity property. *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3450
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3451
lemma span_trans:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3452
  assumes x: "(x::'a::ring_1^'n) \<in> span S" and y: "y \<in> span (insert x S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3453
  shows "y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3454
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3455
  from span_breakdown[of x "insert x S" y, OF insertI1 y]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3456
  obtain k where k: "y -k*s x \<in> span (S - {x})" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3457
  have eq: "y = (y - k *s x) + k *s x" by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3458
  show ?thesis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3459
    apply (subst eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3460
    apply (rule span_add)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3461
    apply (rule set_rev_mp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3462
    apply (rule k)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3463
    apply (rule span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3464
    apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3465
    apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3466
    by (rule x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3467
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3468
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3469
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3470
(* An explicit expansion is sometimes needed.                                *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3471
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3472
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3473
lemma span_explicit:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3474
  "span P = {y::'a::semiring_1^'n. \<exists>S u. finite S \<and> S \<subseteq> P \<and> setsum (\<lambda>v. u v *s v) S = y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3475
  (is "_ = ?E" is "_ = {y. ?h y}" is "_ = {y. \<exists>S u. ?Q S u y}")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3476
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3477
  {fix x assume x: "x \<in> ?E"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3478
    then obtain S u where fS: "finite S" and SP: "S\<subseteq>P" and u: "setsum (\<lambda>v. u v *s v) S = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3479
      by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3480
    have "x \<in> span P"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3481
      unfolding u[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3482
      apply (rule span_setsum[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3483
      using span_mono[OF SP]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3484
      by (auto intro: span_superset span_mul)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3485
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3486
  have "\<forall>x \<in> span P. x \<in> ?E"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3487
    unfolding mem_def Collect_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3488
  proof(rule span_induct_alt')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3489
    show "?h 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3490
      apply (rule exI[where x="{}"]) by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3491
  next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3492
    fix c x y
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3493
    assume x: "x \<in> P" and hy: "?h y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3494
    from hy obtain S u where fS: "finite S" and SP: "S\<subseteq>P" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3495
      and u: "setsum (\<lambda>v. u v *s v) S = y" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3496
    let ?S = "insert x S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3497
    let ?u = "\<lambda>y. if y = x then (if x \<in> S then u y + c else c)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3498
                  else u y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3499
    from fS SP x have th0: "finite (insert x S)" "insert x S \<subseteq> P" by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3500
    {assume xS: "x \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3501
      have S1: "S = (S - {x}) \<union> {x}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3502
	and Sss:"finite (S - {x})" "finite {x}" "(S -{x}) \<inter> {x} = {}" using xS fS by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3503
      have "setsum (\<lambda>v. ?u v *s v) ?S =(\<Sum>v\<in>S - {x}. u v *s v) + (u x + c) *s x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3504
	using xS 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3505
	by (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3506
	  setsum_clauses(2)[OF fS] cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3507
      also have "\<dots> = (\<Sum>v\<in>S. u v *s v) + c *s x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3508
	apply (simp add: setsum_Un_disjoint[OF Sss, unfolded S1[symmetric]])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3509
	by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3510
      also have "\<dots> = c*s x + y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3511
	by (simp add: add_commute u)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3512
      finally have "setsum (\<lambda>v. ?u v *s v) ?S = c*s x + y" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3513
    then have "?Q ?S ?u (c*s x + y)" using th0 by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3514
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3515
  {assume xS: "x \<notin> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3516
    have th00: "(\<Sum>v\<in>S. (if v = x then c else u v) *s v) = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3517
      unfolding u[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3518
      apply (rule setsum_cong2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3519
      using xS by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3520
    have "?Q ?S ?u (c*s x + y)" using fS xS th0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3521
      by (simp add: th00 setsum_clauses add_commute cong del: if_weak_cong)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3522
  ultimately have "?Q ?S ?u (c*s x + y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3523
    by (cases "x \<in> S", simp, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3524
    then show "?h (c*s x + y)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3525
      apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3526
      apply (rule exI[where x="?S"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3527
      apply (rule exI[where x="?u"]) by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3528
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3529
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3530
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3531
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3532
lemma dependent_explicit:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3533
  "dependent P \<longleftrightarrow> (\<exists>S u. finite S \<and> S \<subseteq> P \<and> (\<exists>(v::'a::{idom,field}^'n) \<in>S. u v \<noteq> 0 \<and> setsum (\<lambda>v. u v *s v) S = 0))" (is "?lhs = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3534
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3535
  {assume dP: "dependent P"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3536
    then obtain a S u where aP: "a \<in> P" and fS: "finite S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3537
      and SP: "S \<subseteq> P - {a}" and ua: "setsum (\<lambda>v. u v *s v) S = a" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3538
      unfolding dependent_def span_explicit by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3539
    let ?S = "insert a S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3540
    let ?u = "\<lambda>y. if y = a then - 1 else u y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3541
    let ?v = a
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3542
    from aP SP have aS: "a \<notin> S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3543
    from fS SP aP have th0: "finite ?S" "?S \<subseteq> P" "?v \<in> ?S" "?u ?v \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3544
    have s0: "setsum (\<lambda>v. ?u v *s v) ?S = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3545
      using fS aS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3546
      apply (simp add: vector_smult_lneg vector_smult_lid setsum_clauses ring_simps )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3547
      apply (subst (2) ua[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3548
      apply (rule setsum_cong2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3549
      by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3550
    with th0 have ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3551
      apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3552
      apply (rule exI[where x= "?S"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3553
      apply (rule exI[where x= "?u"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3554
      by clarsimp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3555
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3556
  {fix S u v assume fS: "finite S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3557
      and SP: "S \<subseteq> P" and vS: "v \<in> S" and uv: "u v \<noteq> 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3558
    and u: "setsum (\<lambda>v. u v *s v) S = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3559
    let ?a = v 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3560
    let ?S = "S - {v}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3561
    let ?u = "\<lambda>i. (- u i) / u v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3562
    have th0: "?a \<in> P" "finite ?S" "?S \<subseteq> P"       using fS SP vS by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3563
    have "setsum (\<lambda>v. ?u v *s v) ?S = setsum (\<lambda>v. (- (inverse (u ?a))) *s (u v *s v)) S - ?u v *s v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3564
      using fS vS uv 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3565
      by (simp add: setsum_diff1 vector_smult_lneg divide_inverse 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3566
	vector_smult_assoc field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3567
    also have "\<dots> = ?a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3568
      unfolding setsum_cmul u
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3569
      using uv by (simp add: vector_smult_lneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3570
    finally  have "setsum (\<lambda>v. ?u v *s v) ?S = ?a" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3571
    with th0 have ?lhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3572
      unfolding dependent_def span_explicit
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3573
      apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3574
      apply (rule bexI[where x= "?a"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3575
      apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3576
      apply (rule exI[where x= "?S"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3577
      by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3578
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3579
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3580
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3581
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3582
lemma span_finite:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3583
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3584
  shows "span S = {(y::'a::semiring_1^'n). \<exists>u. setsum (\<lambda>v. u v *s v) S = y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3585
  (is "_ = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3586
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3587
  {fix y assume y: "y \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3588
    from y obtain S' u where fS': "finite S'" and SS': "S' \<subseteq> S" and 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3589
      u: "setsum (\<lambda>v. u v *s v) S' = y" unfolding span_explicit by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3590
    let ?u = "\<lambda>x. if x \<in> S' then u x else 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3591
    from setsum_restrict_set[OF fS, of "\<lambda>v. u v *s v" S', symmetric] SS'
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3592
    have "setsum (\<lambda>v. ?u v *s v) S = setsum (\<lambda>v. u v *s v) S'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3593
      unfolding cond_value_iff cond_application_beta
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3594
      apply (simp add: cond_value_iff cong del: if_weak_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3595
      apply (rule setsum_cong)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3596
      apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3597
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3598
    hence "setsum (\<lambda>v. ?u v *s v) S = y" by (metis u)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3599
    hence "y \<in> ?rhs" by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3600
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3601
  {fix y u assume u: "setsum (\<lambda>v. u v *s v) S = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3602
    then have "y \<in> span S" using fS unfolding span_explicit by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3603
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3604
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3605
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3606
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3607
(* Standard bases are a spanning set, and obviously finite.                  *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3608
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3609
lemma span_stdbasis:"span {basis i :: 'a::ring_1^'n | i. i \<in> {1 .. dimindex(UNIV :: 'n set)}} = UNIV"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3610
apply (rule set_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3611
apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3612
apply (subst basis_expansion[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3613
apply (rule span_setsum)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3614
apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3615
apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3616
apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3617
apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3618
apply (auto simp add: Collect_def mem_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3619
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3620
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3621
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3622
lemma has_size_stdbasis: "{basis i ::real ^'n | i. i \<in> {1 .. dimindex (UNIV :: 'n set)}} hassize (dimindex(UNIV :: 'n set))" (is "?S hassize ?n")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3623
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3624
  have eq: "?S = basis ` {1 .. ?n}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3625
  show ?thesis unfolding eq
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3626
    apply (rule hassize_image_inj[OF basis_inj])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3627
    by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3628
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3629
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3630
lemma finite_stdbasis: "finite {basis i ::real^'n |i. i\<in> {1 .. dimindex(UNIV:: 'n set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3631
  using has_size_stdbasis[unfolded hassize_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3632
  ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3633
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3634
lemma card_stdbasis: "card {basis i ::real^'n |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}} = dimindex(UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3635
  using has_size_stdbasis[unfolded hassize_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3636
  ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3637
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3638
lemma independent_stdbasis_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3639
  assumes x: "(x::'a::semiring_1 ^ 'n) \<in> span (basis ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3640
  and i: "i \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3641
  and iS: "i \<notin> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3642
  shows "(x$i) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3643
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3644
  let ?n = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3645
  let ?U = "{1 .. ?n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3646
  let ?B = "basis ` S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3647
  let ?P = "\<lambda>(x::'a^'n). \<forall>i\<in> ?U. i \<notin> S \<longrightarrow> x$i =0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3648
 {fix x::"'a^'n" assume xS: "x\<in> ?B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3649
   from xS have "?P x" by (auto simp add: basis_component)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3650
 moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3651
 have "subspace ?P" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3652
   by (auto simp add: subspace_def Collect_def mem_def zero_index vector_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3653
 ultimately show ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3654
   using x span_induct[of ?B ?P x] i iS by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3655
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3656
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3657
lemma independent_stdbasis: "independent {basis i ::real^'n |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3658
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3659
  let ?n = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3660
  let ?I = "{1 .. ?n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3661
  let ?b = "basis :: nat \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3662
  let ?B = "?b ` ?I"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3663
  have eq: "{?b i|i. i \<in> ?I} = ?B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3664
    by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3665
  {assume d: "dependent ?B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3666
    then obtain k where k: "k \<in> ?I" "?b k \<in> span (?B - {?b k})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3667
      unfolding dependent_def by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3668
    have eq1: "?B - {?b k} = ?B - ?b ` {k}"  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3669
    have eq2: "?B - {?b k} = ?b ` (?I - {k})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3670
      unfolding eq1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3671
      apply (rule inj_on_image_set_diff[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3672
      apply (rule basis_inj) using k(1) by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3673
    from k(2) have th0: "?b k \<in> span (?b ` (?I - {k}))" unfolding eq2 .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3674
    from independent_stdbasis_lemma[OF th0 k(1), simplified]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3675
    have False by (simp add: basis_component[OF k(1), of k])}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3676
  then show ?thesis unfolding eq dependent_def ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3677
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3678
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3679
(* This is useful for building a basis step-by-step.                         *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3680
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3681
lemma independent_insert:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3682
  "independent(insert (a::'a::field ^'n) S) \<longleftrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3683
      (if a \<in> S then independent S
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3684
                else independent S \<and> a \<notin> span S)" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3685
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3686
  {assume aS: "a \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3687
    hence ?thesis using insert_absorb[OF aS] by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3688
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3689
  {assume aS: "a \<notin> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3690
    {assume i: ?lhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3691
      then have ?rhs using aS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3692
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3693
	apply (rule conjI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3694
	apply (rule independent_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3695
	apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3696
	apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3697
	by (simp add: dependent_def)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3698
    moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3699
    {assume i: ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3700
      have ?lhs using i aS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3701
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3702
	apply (auto simp add: dependent_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3703
	apply (case_tac "aa = a", auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3704
	apply (subgoal_tac "insert a S - {aa} = insert a (S - {aa})")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3705
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3706
	apply (subgoal_tac "a \<in> span (insert aa (S - {aa}))")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3707
	apply (subgoal_tac "insert aa (S - {aa}) = S")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3708
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3709
	apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3710
	apply (rule in_span_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3711
	apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3712
	apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3713
	apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3714
	done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3715
    ultimately have ?thesis by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3716
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3717
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3718
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3719
(* The degenerate case of the Exchange Lemma.  *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3720
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3721
lemma mem_delete: "x \<in> (A - {a}) \<longleftrightarrow> x \<noteq> a \<and> x \<in> A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3722
  by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3723
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3724
lemma span_span: "span (span A) = span A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3725
  unfolding span_def hull_hull ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3726
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3727
lemma span_inc: "S \<subseteq> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3728
  by (metis subset_eq span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3729
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3730
lemma spanning_subset_independent:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3731
  assumes BA: "B \<subseteq> A" and iA: "independent (A::('a::field ^'n) set)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3732
  and AsB: "A \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3733
  shows "A = B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3734
proof
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3735
  from BA show "B \<subseteq> A" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3736
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3737
  from span_mono[OF BA] span_mono[OF AsB]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3738
  have sAB: "span A = span B" unfolding span_span by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3739
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3740
  {fix x assume x: "x \<in> A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3741
    from iA have th0: "x \<notin> span (A - {x})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3742
      unfolding dependent_def using x by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3743
    from x have xsA: "x \<in> span A" by (blast intro: span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3744
    have "A - {x} \<subseteq> A" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3745
    hence th1:"span (A - {x}) \<subseteq> span A" by (metis span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3746
    {assume xB: "x \<notin> B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3747
      from xB BA have "B \<subseteq> A -{x}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3748
      hence "span B \<subseteq> span (A - {x})" by (metis span_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3749
      with th1 th0 sAB have "x \<notin> span A" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3750
      with x have False by (metis span_superset)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3751
    then have "x \<in> B" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3752
  then show "A \<subseteq> B" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3753
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3754
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3755
(* The general case of the Exchange Lemma, the key to what follows.  *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3756
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3757
lemma exchange_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3758
  assumes f:"finite (t:: ('a::field^'n) set)" and i: "independent s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3759
  and sp:"s \<subseteq> span t" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3760
  shows "\<exists>t'. (t' hassize card t) \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3761
using f i sp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3762
proof(induct c\<equiv>"card(t - s)" arbitrary: s t rule: nat_less_induct)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3763
  fix n:: nat and s t :: "('a ^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3764
  assume H: " \<forall>m<n. \<forall>(x:: ('a ^'n) set) xa.
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3765
                finite xa \<longrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3766
                independent x \<longrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3767
                x \<subseteq> span xa \<longrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3768
                m = card (xa - x) \<longrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3769
                (\<exists>t'. (t' hassize card xa) \<and>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3770
                      x \<subseteq> t' \<and> t' \<subseteq> x \<union> xa \<and> x \<subseteq> span t')"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3771
    and ft: "finite t" and s: "independent s" and sp: "s \<subseteq> span t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3772
    and n: "n = card (t - s)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3773
  let ?P = "\<lambda>t'. (t' hassize card t) \<and> s \<subseteq> t' \<and> t' \<subseteq> s \<union> t \<and> s \<subseteq> span t'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3774
  let ?ths = "\<exists>t'. ?P t'" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3775
  {assume st: "s \<subseteq> t" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3776
    from st ft span_mono[OF st] have ?ths apply - apply (rule exI[where x=t]) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3777
      by (auto simp add: hassize_def intro: span_superset)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3778
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3779
  {assume st: "t \<subseteq> s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3780
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3781
    from spanning_subset_independent[OF st s sp] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3782
      st ft span_mono[OF st] have ?ths apply - apply (rule exI[where x=t]) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3783
      by (auto simp add: hassize_def intro: span_superset)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3784
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3785
  {assume st: "\<not> s \<subseteq> t" "\<not> t \<subseteq> s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3786
    from st(2) obtain b where b: "b \<in> t" "b \<notin> s" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3787
      from b have "t - {b} - s \<subset> t - s" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3788
      then have cardlt: "card (t - {b} - s) < n" using n ft
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3789
 	by (auto intro: psubset_card_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3790
      from b ft have ct0: "card t \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3791
    {assume stb: "s \<subseteq> span(t -{b})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3792
      from ft have ftb: "finite (t -{b})" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3793
      from H[rule_format, OF cardlt ftb s stb] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3794
      obtain u where u: "u hassize card (t-{b})" "s \<subseteq> u" "u \<subseteq> s \<union> (t - {b})" "s \<subseteq> span u" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3795
      let ?w = "insert b u"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3796
      have th0: "s \<subseteq> insert b u" using u by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3797
      from u(3) b have "u \<subseteq> s \<union> t" by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3798
      then have th1: "insert b u \<subseteq> s \<union> t" using u b by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3799
      have bu: "b \<notin> u" using b u by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3800
      from u(1) have fu: "finite u" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3801
      from u(1) ft b have "u hassize (card t - 1)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3802
      then 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3803
      have th2: "insert b u hassize card t" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3804
	using  card_insert_disjoint[OF fu bu] ct0 by (auto simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3805
      from u(4) have "s \<subseteq> span u" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3806
      also have "\<dots> \<subseteq> span (insert b u)" apply (rule span_mono) by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3807
      finally have th3: "s \<subseteq> span (insert b u)" .      from th0 th1 th2 th3 have th: "?P ?w"  by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3808
      from th have ?ths by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3809
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3810
    {assume stb: "\<not> s \<subseteq> span(t -{b})" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3811
      from stb obtain a where a: "a \<in> s" "a \<notin> span (t - {b})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3812
      have ab: "a \<noteq> b" using a b by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3813
      have at: "a \<notin> t" using a ab span_superset[of a "t- {b}"] by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3814
      have mlt: "card ((insert a (t - {b})) - s) < n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3815
	using cardlt ft n  a b by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3816
      have ft': "finite (insert a (t - {b}))" using ft by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3817
      {fix x assume xs: "x \<in> s"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3818
	have t: "t \<subseteq> (insert b (insert a (t -{b})))" using b by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3819
	from b(1) have "b \<in> span t" by (simp add: span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3820
	have bs: "b \<in> span (insert a (t - {b}))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3821
	  by (metis in_span_delete a sp mem_def subset_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3822
	from xs sp have "x \<in> span t" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3823
	with span_mono[OF t]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3824
	have x: "x \<in> span (insert b (insert a (t - {b})))" ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3825
	from span_trans[OF bs x] have "x \<in> span (insert a (t - {b}))"  .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3826
      then have sp': "s \<subseteq> span (insert a (t - {b}))" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3827
      
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3828
      from H[rule_format, OF mlt ft' s sp' refl] obtain u where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3829
	u: "u hassize card (insert a (t -{b}))" "s \<subseteq> u" "u \<subseteq> s \<union> insert a (t -{b})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3830
	"s \<subseteq> span u" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3831
      from u a b ft at ct0 have "?P u" by (auto simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3832
      then have ?ths by blast }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3833
    ultimately have ?ths by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3834
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3835
  ultimately 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3836
  show ?ths  by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3837
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3838
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3839
(* This implies corresponding size bounds.                                   *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3840
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3841
lemma independent_span_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3842
  assumes f: "finite t" and i: "independent (s::('a::field^'n) set)" and sp:"s \<subseteq> span t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3843
  shows "finite s \<and> card s \<le> card t"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3844
  by (metis exchange_lemma[OF f i sp] hassize_def finite_subset card_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3845
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3846
lemma finite_Atleast_Atmost[simp]: "finite {f x |x. x\<in> {(i::'a::finite_intvl_succ) .. j}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3847
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3848
  have eq: "{f x |x. x\<in> {i .. j}} = f ` {i .. j}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3849
  show ?thesis unfolding eq 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3850
    apply (rule finite_imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3851
    apply (rule finite_intvl)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3852
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3853
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3854
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3855
lemma finite_Atleast_Atmost_nat[simp]: "finite {f x |x. x\<in> {(i::nat) .. j}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3856
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3857
  have eq: "{f x |x. x\<in> {i .. j}} = f ` {i .. j}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3858
  show ?thesis unfolding eq 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3859
    apply (rule finite_imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3860
    apply (rule finite_atLeastAtMost)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3861
    done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3862
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3863
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3864
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3865
lemma independent_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3866
  fixes S:: "(real^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3867
  shows "independent S \<Longrightarrow> finite S \<and> card S <= dimindex(UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3868
  apply (subst card_stdbasis[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3869
  apply (rule independent_span_bound)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3870
  apply (rule finite_Atleast_Atmost_nat)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3871
  apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3872
  unfolding span_stdbasis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3873
  apply (rule subset_UNIV)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3874
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3875
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3876
lemma dependent_biggerset: "(finite (S::(real ^'n) set) ==> card S > dimindex(UNIV:: 'n set)) ==> dependent S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3877
  by (metis independent_bound not_less)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3878
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3879
(* Hence we can create a maximal independent subset.                         *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3880
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3881
lemma maximal_independent_subset_extend:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3882
  assumes sv: "(S::(real^'n) set) \<subseteq> V" and iS: "independent S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3883
  shows "\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3884
  using sv iS
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3885
proof(induct d\<equiv> "dimindex (UNIV :: 'n set) - card S" arbitrary: S rule: nat_less_induct)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3886
  fix n and S:: "(real^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3887
  assume H: "\<forall>m<n. \<forall>S \<subseteq> V. independent S \<longrightarrow> m = dimindex (UNIV::'n set) - card S \<longrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3888
              (\<exists>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3889
    and sv: "S \<subseteq> V" and i: "independent S" and n: "n = dimindex (UNIV :: 'n set) - card S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3890
  let ?P = "\<lambda>B. S \<subseteq> B \<and> B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3891
  let ?ths = "\<exists>x. ?P x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3892
  let ?d = "dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3893
  {assume "V \<subseteq> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3894
    then have ?ths  using sv i by blast }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3895
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3896
  {assume VS: "\<not> V \<subseteq> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3897
    from VS obtain a where a: "a \<in> V" "a \<notin> span S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3898
    from a have aS: "a \<notin> S" by (auto simp add: span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3899
    have th0: "insert a S \<subseteq> V" using a sv by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3900
    from independent_insert[of a S]  i a 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3901
    have th1: "independent (insert a S)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3902
    have mlt: "?d - card (insert a S) < n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3903
      using aS a n independent_bound[OF th1] dimindex_ge_1[of "UNIV :: 'n set"] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3904
      by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3905
      
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3906
    from H[rule_format, OF mlt th0 th1 refl] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3907
    obtain B where B: "insert a S \<subseteq> B" "B \<subseteq> V" "independent B" " V \<subseteq> span B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3908
      by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3909
    from B have "?P B" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3910
    then have ?ths by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3911
  ultimately show ?ths by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3912
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3913
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3914
lemma maximal_independent_subset:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3915
  "\<exists>(B:: (real ^'n) set). B\<subseteq> V \<and> independent B \<and> V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3916
  by (metis maximal_independent_subset_extend[of "{}:: (real ^'n) set"] empty_subsetI independent_empty)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3917
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3918
(* Notion of dimension.                                                      *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3919
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3920
definition "dim V = (SOME n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (B hassize n))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3921
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3922
lemma basis_exists:  "\<exists>B. (B :: (real ^'n) set) \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (B hassize dim V)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3923
unfolding dim_def some_eq_ex[of "\<lambda>n. \<exists>B. B \<subseteq> V \<and> independent B \<and> V \<subseteq> span B \<and> (B hassize n)"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3924
unfolding hassize_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3925
using maximal_independent_subset[of V] independent_bound
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3926
by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3927
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3928
(* Consequences of independence or spanning for cardinality.                 *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3929
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3930
lemma independent_card_le_dim: "(B::(real ^'n) set) \<subseteq> V \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B \<le> dim V"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3931
by (metis basis_exists[of V] independent_span_bound[where ?'a=real] hassize_def subset_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3932
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3933
lemma span_card_ge_dim:  "(B::(real ^'n) set) \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> finite B \<Longrightarrow> dim V \<le> card B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3934
  by (metis basis_exists[of V] independent_span_bound hassize_def subset_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3935
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3936
lemma basis_card_eq_dim:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3937
  "B \<subseteq> (V:: (real ^'n) set) \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> finite B \<and> card B = dim V"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3938
  by (metis order_eq_iff independent_card_le_dim span_card_ge_dim independent_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3939
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3940
lemma dim_unique: "(B::(real ^'n) set) \<subseteq> V \<Longrightarrow> V \<subseteq> span B \<Longrightarrow> independent B \<Longrightarrow> B hassize n \<Longrightarrow> dim V = n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3941
  by (metis basis_card_eq_dim hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3942
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3943
(* More lemmas about dimension.                                              *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3944
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3945
lemma dim_univ: "dim (UNIV :: (real^'n) set) = dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3946
  apply (rule dim_unique[of "{basis i |i. i\<in> {1 .. dimindex (UNIV :: 'n set)}}"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3947
  by (auto simp only: span_stdbasis has_size_stdbasis independent_stdbasis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3948
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3949
lemma dim_subset:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3950
  "(S:: (real ^'n) set) \<subseteq> T \<Longrightarrow> dim S \<le> dim T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3951
  using basis_exists[of T] basis_exists[of S]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3952
  by (metis independent_span_bound[where ?'a = real and ?'n = 'n] subset_eq hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3953
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3954
lemma dim_subset_univ: "dim (S:: (real^'n) set) \<le> dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3955
  by (metis dim_subset subset_UNIV dim_univ)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3956
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3957
(* Converses to those.                                                       *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3958
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3959
lemma card_ge_dim_independent:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3960
  assumes BV:"(B::(real ^'n) set) \<subseteq> V" and iB:"independent B" and dVB:"dim V \<le> card B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3961
  shows "V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3962
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3963
  {fix a assume aV: "a \<in> V"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3964
    {assume aB: "a \<notin> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3965
      then have iaB: "independent (insert a B)" using iB aV  BV by (simp add: independent_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3966
      from aV BV have th0: "insert a B \<subseteq> V" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3967
      from aB have "a \<notin>B" by (auto simp add: span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3968
      with independent_card_le_dim[OF th0 iaB] dVB  have False by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3969
    then have "a \<in> span B"  by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3970
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3971
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3972
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3973
lemma card_le_dim_spanning:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3974
  assumes BV: "(B:: (real ^'n) set) \<subseteq> V" and VB: "V \<subseteq> span B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3975
  and fB: "finite B" and dVB: "dim V \<ge> card B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3976
  shows "independent B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3977
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3978
  {fix a assume a: "a \<in> B" "a \<in> span (B -{a})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3979
    from a fB have c0: "card B \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3980
    from a fB have cb: "card (B -{a}) = card B - 1" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3981
    from BV a have th0: "B -{a} \<subseteq> V" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3982
    {fix x assume x: "x \<in> V"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3983
      from a have eq: "insert a (B -{a}) = B" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3984
      from x VB have x': "x \<in> span B" by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3985
      from span_trans[OF a(2), unfolded eq, OF x']
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3986
      have "x \<in> span (B -{a})" . }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3987
    then have th1: "V \<subseteq> span (B -{a})" by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3988
    have th2: "finite (B -{a})" using fB by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3989
    from span_card_ge_dim[OF th0 th1 th2]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3990
    have c: "dim V \<le> card (B -{a})" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3991
    from c c0 dVB cb have False by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3992
  then show ?thesis unfolding dependent_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3993
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3994
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3995
lemma card_eq_dim: "(B:: (real ^'n) set) \<subseteq> V \<Longrightarrow> B hassize dim V \<Longrightarrow> independent B \<longleftrightarrow> V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3996
  by (metis hassize_def order_eq_iff card_le_dim_spanning 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3997
    card_ge_dim_independent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3998
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  3999
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4000
(* More general size bound lemmas.                                           *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4001
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4002
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4003
lemma independent_bound_general:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4004
  "independent (S:: (real^'n) set) \<Longrightarrow> finite S \<and> card S \<le> dim S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4005
  by (metis independent_card_le_dim independent_bound subset_refl)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4006
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4007
lemma dependent_biggerset_general: "(finite (S:: (real^'n) set) \<Longrightarrow> card S > dim S) \<Longrightarrow> dependent S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4008
  using independent_bound_general[of S] by (metis linorder_not_le) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4009
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4010
lemma dim_span: "dim (span (S:: (real ^'n) set)) = dim S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4011
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4012
  have th0: "dim S \<le> dim (span S)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4013
    by (auto simp add: subset_eq intro: dim_subset span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4014
  from basis_exists[of S] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4015
  obtain B where B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "B hassize dim S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4016
  from B have fB: "finite B" "card B = dim S" unfolding hassize_def by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4017
  have bSS: "B \<subseteq> span S" using B(1) by (metis subset_eq span_inc) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4018
  have sssB: "span S \<subseteq> span B" using span_mono[OF B(3)] by (simp add: span_span) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4019
  from span_card_ge_dim[OF bSS sssB fB(1)] th0 show ?thesis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4020
    using fB(2)  by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4021
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4022
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4023
lemma subset_le_dim: "(S:: (real ^'n) set) \<subseteq> span T \<Longrightarrow> dim S \<le> dim T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4024
  by (metis dim_span dim_subset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4025
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4026
lemma span_eq_dim: "span (S:: (real ^'n) set) = span T ==> dim S = dim T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4027
  by (metis dim_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4028
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4029
lemma spans_image:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4030
  assumes lf: "linear (f::'a::semiring_1^'n \<Rightarrow> _)" and VB: "V \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4031
  shows "f ` V \<subseteq> span (f ` B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4032
  unfolding span_linear_image[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4033
  by (metis VB image_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4034
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4035
lemma dim_image_le: assumes lf: "linear f" shows "dim (f ` S) \<le> dim (S:: (real ^'n) set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4036
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4037
  from basis_exists[of S] obtain B where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4038
    B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "B hassize dim S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4039
  from B have fB: "finite B" "card B = dim S" unfolding hassize_def by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4040
  have "dim (f ` S) \<le> card (f ` B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4041
    apply (rule span_card_ge_dim)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4042
    using lf B fB by (auto simp add: span_linear_image spans_image subset_image_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4043
  also have "\<dots> \<le> dim S" using card_image_le[OF fB(1)] fB by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4044
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4045
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4046
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4047
(* Relation between bases and injectivity/surjectivity of map.               *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4048
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4049
lemma spanning_surjective_image:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4050
  assumes us: "UNIV \<subseteq> span (S:: ('a::semiring_1 ^'n) set)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4051
  and lf: "linear f" and sf: "surj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4052
  shows "UNIV \<subseteq> span (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4053
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4054
  have "UNIV \<subseteq> f ` UNIV" using sf by (auto simp add: surj_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4055
  also have " \<dots> \<subseteq> span (f ` S)" using spans_image[OF lf us] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4056
finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4057
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4058
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4059
lemma independent_injective_image:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4060
  assumes iS: "independent (S::('a::semiring_1^'n) set)" and lf: "linear f" and fi: "inj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4061
  shows "independent (f ` S)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4062
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4063
  {fix a assume a: "a \<in> S" "f a \<in> span (f ` S - {f a})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4064
    have eq: "f ` S - {f a} = f ` (S - {a})" using fi
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4065
      by (auto simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4066
    from a have "f a \<in> f ` span (S -{a})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4067
      unfolding eq span_linear_image[OF lf, of "S - {a}"]  by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4068
    hence "a \<in> span (S -{a})" using fi by (auto simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4069
    with a(1) iS  have False by (simp add: dependent_def) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4070
  then show ?thesis unfolding dependent_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4071
qed 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4072
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4073
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4074
(* Picking an orthogonal replacement for a spanning set.                     *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4075
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4076
    (* FIXME : Move to some general theory ?*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4077
definition "pairwise R S \<longleftrightarrow> (\<forall>x \<in> S. \<forall>y\<in> S. x\<noteq>y \<longrightarrow> R x y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4078
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4079
lemma vector_sub_project_orthogonal: "(b::'a::ordered_field^'n) \<bullet> (x - ((b \<bullet> x) / (b\<bullet>b)) *s b) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4080
  apply (cases "b = 0", simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4081
  apply (simp add: dot_rsub dot_rmult)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4082
  unfolding times_divide_eq_right[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4083
  by (simp add: field_simps dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4084
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4085
lemma basis_orthogonal:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4086
  fixes B :: "(real ^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4087
  assumes fB: "finite B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4088
  shows "\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4089
  (is " \<exists>C. ?P B C")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4090
proof(induct rule: finite_induct[OF fB])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4091
  case 1 thus ?case apply (rule exI[where x="{}"]) by (auto simp add: pairwise_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4092
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4093
  case (2 a B)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4094
  note fB = `finite B` and aB = `a \<notin> B` 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4095
  from `\<exists>C. finite C \<and> card C \<le> card B \<and> span C = span B \<and> pairwise orthogonal C` 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4096
  obtain C where C: "finite C" "card C \<le> card B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4097
    "span C = span B" "pairwise orthogonal C" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4098
  let ?a = "a - setsum (\<lambda>x. (x\<bullet>a / (x\<bullet>x)) *s x) C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4099
  let ?C = "insert ?a C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4100
  from C(1) have fC: "finite ?C" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4101
  from fB aB C(1,2) have cC: "card ?C \<le> card (insert a B)" by (simp add: card_insert_if)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4102
  {fix x k 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4103
    have th0: "\<And>(a::'b::comm_ring) b c. a - (b - c) = c + (a - b)" by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4104
    have "x - k *s (a - (\<Sum>x\<in>C. (x \<bullet> a / (x \<bullet> x)) *s x)) \<in> span C \<longleftrightarrow> x - k *s a \<in> span C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4105
      apply (simp only: vector_ssub_ldistrib th0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4106
      apply (rule span_add_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4107
      apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4108
      apply (rule span_setsum[OF C(1)])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4109
      apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4110
      apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4111
      by (rule span_superset)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4112
  then have SC: "span ?C = span (insert a B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4113
    unfolding expand_set_eq span_breakdown_eq C(3)[symmetric] by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4114
  thm pairwise_def 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4115
  {fix x y assume xC: "x \<in> ?C" and yC: "y \<in> ?C" and xy: "x \<noteq> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4116
    {assume xa: "x = ?a" and ya: "y = ?a" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4117
      have "orthogonal x y" using xa ya xy by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4118
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4119
    {assume xa: "x = ?a" and ya: "y \<noteq> ?a" "y \<in> C" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4120
      from ya have Cy: "C = insert y (C - {y})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4121
      have fth: "finite (C - {y})" using C by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4122
      have "orthogonal x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4123
	using xa ya
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4124
	unfolding orthogonal_def xa dot_lsub dot_rsub diff_eq_0_iff_eq
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4125
	apply simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4126
	apply (subst Cy)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4127
	using C(1) fth
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4128
	apply (simp only: setsum_clauses)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4129
	apply (auto simp add: dot_ladd dot_lmult dot_eq_0 dot_sym[of y a] dot_lsum[OF fth])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4130
	apply (rule setsum_0')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4131
	apply clarsimp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4132
	apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4133
	by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4134
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4135
    {assume xa: "x \<noteq> ?a" "x \<in> C" and ya: "y = ?a" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4136
      from xa have Cx: "C = insert x (C - {x})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4137
      have fth: "finite (C - {x})" using C by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4138
      have "orthogonal x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4139
	using xa ya
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4140
	unfolding orthogonal_def ya dot_rsub dot_lsub diff_eq_0_iff_eq
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4141
	apply simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4142
	apply (subst Cx)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4143
	using C(1) fth
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4144
	apply (simp only: setsum_clauses)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4145
	apply (subst dot_sym[of x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4146
	apply (auto simp add: dot_radd dot_rmult dot_eq_0 dot_sym[of x a] dot_rsum[OF fth])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4147
	apply (rule setsum_0')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4148
	apply clarsimp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4149
	apply (rule C(4)[unfolded pairwise_def orthogonal_def, rule_format])
29844
4ac95212efcc fixed proof -- removed unnecessary sorry
chaieb
parents: 29842
diff changeset
  4150
	by auto}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4151
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4152
    {assume xa: "x \<in> C" and ya: "y \<in> C" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4153
      have "orthogonal x y" using xa ya xy C(4) unfolding pairwise_def by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4154
    ultimately have "orthogonal x y" using xC yC by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4155
  then have CPO: "pairwise orthogonal ?C" unfolding pairwise_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4156
  from fC cC SC CPO have "?P (insert a B) ?C" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4157
  then show ?case by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4158
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4159
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4160
lemma orthogonal_basis_exists:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4161
  fixes V :: "(real ^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4162
  shows "\<exists>B. independent B \<and> B \<subseteq> span V \<and> V \<subseteq> span B \<and> (B hassize dim V) \<and> pairwise orthogonal B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4163
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4164
  from basis_exists[of V] obtain B where B: "B \<subseteq> V" "independent B" "V \<subseteq> span B" "B hassize dim V" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4165
  from B have fB: "finite B" "card B = dim V" by (simp_all add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4166
  from basis_orthogonal[OF fB(1)] obtain C where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4167
    C: "finite C" "card C \<le> card B" "span C = span B" "pairwise orthogonal C" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4168
  from C B 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4169
  have CSV: "C \<subseteq> span V" by (metis span_inc span_mono subset_trans) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4170
  from span_mono[OF B(3)]  C have SVC: "span V \<subseteq> span C" by (simp add: span_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4171
  from card_le_dim_spanning[OF CSV SVC C(1)] C(2,3) fB
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4172
  have iC: "independent C" by (simp add: dim_span) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4173
  from C fB have "card C \<le> dim V" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4174
  moreover have "dim V \<le> card C" using span_card_ge_dim[OF CSV SVC C(1)]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4175
    by (simp add: dim_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4176
  ultimately have CdV: "C hassize dim V" unfolding hassize_def using C(1) by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4177
  from C B CSV CdV iC show ?thesis by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4178
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4179
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4180
lemma span_eq: "span S = span T \<longleftrightarrow> S \<subseteq> span T \<and> T \<subseteq> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4181
  by (metis set_eq_subset span_mono span_span span_inc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4182
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4183
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4184
(* Low-dimensional subset is in a hyperplane (weak orthogonal complement).   *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4185
(* ------------------------------------------------------------------------- *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4186
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4187
lemma span_not_univ_orthogonal:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4188
  assumes sU: "span S \<noteq> UNIV"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4189
  shows "\<exists>(a:: real ^'n). a \<noteq>0 \<and> (\<forall>x \<in> span S. a \<bullet> x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4190
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4191
  from sU obtain a where a: "a \<notin> span S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4192
  from orthogonal_basis_exists obtain B where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4193
    B: "independent B" "B \<subseteq> span S" "S \<subseteq> span B" "B hassize dim S" "pairwise orthogonal B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4194
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4195
  from B have fB: "finite B" "card B = dim S" by (simp_all add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4196
  from span_mono[OF B(2)] span_mono[OF B(3)]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4197
  have sSB: "span S = span B" by (simp add: span_span)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4198
  let ?a = "a - setsum (\<lambda>b. (a\<bullet>b / (b\<bullet>b)) *s b) B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4199
  have "setsum (\<lambda>b. (a\<bullet>b / (b\<bullet>b)) *s b) B \<in> span S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4200
    unfolding sSB
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4201
    apply (rule span_setsum[OF fB(1)])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4202
    apply clarsimp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4203
    apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4204
    by (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4205
  with a have a0:"?a  \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4206
  have "\<forall>x\<in>span B. ?a \<bullet> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4207
  proof(rule span_induct')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4208
    show "subspace (\<lambda>x. ?a \<bullet> x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4209
      by (auto simp add: subspace_def mem_def dot_radd dot_rmult) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4210
  next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4211
    {fix x assume x: "x \<in> B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4212
      from x have B': "B = insert x (B - {x})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4213
      have fth: "finite (B - {x})" using fB by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4214
      have "?a \<bullet> x = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4215
	apply (subst B') using fB fth
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4216
	unfolding setsum_clauses(2)[OF fth]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4217
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4218
	apply (clarsimp simp add: dot_lsub dot_ladd dot_lmult dot_lsum dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4219
	apply (rule setsum_0', rule ballI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4220
	unfolding dot_sym
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4221
	by (auto simp add: x field_simps dot_eq_0 intro: B(5)[unfolded pairwise_def orthogonal_def, rule_format])}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4222
    then show "\<forall>x \<in> B. ?a \<bullet> x = 0" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4223
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4224
  with a0 show ?thesis unfolding sSB by (auto intro: exI[where x="?a"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4225
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4226
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4227
lemma span_not_univ_subset_hyperplane: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4228
  assumes SU: "span S \<noteq> (UNIV ::(real^'n) set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4229
  shows "\<exists> a. a \<noteq>0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4230
  using span_not_univ_orthogonal[OF SU] by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4231
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4232
lemma lowdim_subset_hyperplane:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4233
  assumes d: "dim S < dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4234
  shows "\<exists>(a::real ^'n). a  \<noteq> 0 \<and> span S \<subseteq> {x. a \<bullet> x = 0}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4235
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4236
  {assume "span S = UNIV"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4237
    hence "dim (span S) = dim (UNIV :: (real ^'n) set)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4238
    hence "dim S = dimindex (UNIV :: 'n set)" by (simp add: dim_span dim_univ)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4239
    with d have False by arith}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4240
  hence th: "span S \<noteq> UNIV" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4241
  from span_not_univ_subset_hyperplane[OF th] show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4242
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4243
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4244
(* We can extend a linear basis-basis injection to the whole set.            *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4245
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4246
lemma linear_indep_image_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4247
  assumes lf: "linear f" and fB: "finite B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4248
  and ifB: "independent (f ` B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4249
  and fi: "inj_on f B" and xsB: "x \<in> span B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4250
  and fx: "f (x::'a::field^'n) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4251
  shows "x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4252
  using fB ifB fi xsB fx
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4253
proof(induct arbitrary: x rule: finite_induct[OF fB])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4254
  case 1 thus ?case by (auto simp add:  span_empty)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4255
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4256
  case (2 a b x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4257
  have fb: "finite b" using "2.prems" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4258
  have th0: "f ` b \<subseteq> f ` (insert a b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4259
    apply (rule image_mono) by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4260
  from independent_mono[ OF "2.prems"(2) th0]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4261
  have ifb: "independent (f ` b)"  .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4262
  have fib: "inj_on f b" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4263
    apply (rule subset_inj_on [OF "2.prems"(3)]) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4264
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4265
  from span_breakdown[of a "insert a b", simplified, OF "2.prems"(4)]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4266
  obtain k where k: "x - k*s a \<in> span (b -{a})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4267
  have "f (x - k*s a) \<in> span (f ` b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4268
    unfolding span_linear_image[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4269
    apply (rule imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4270
    using k span_mono[of "b-{a}" b] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4271
  hence "f x - k*s f a \<in> span (f ` b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4272
    by (simp add: linear_sub[OF lf] linear_cmul[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4273
  hence th: "-k *s f a \<in> span (f ` b)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4274
    using "2.prems"(5) by (simp add: vector_smult_lneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4275
  {assume k0: "k = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4276
    from k0 k have "x \<in> span (b -{a})" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4277
    then have "x \<in> span b" using span_mono[of "b-{a}" b]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4278
      by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4279
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4280
  {assume k0: "k \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4281
    from span_mul[OF th, of "- 1/ k"] k0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4282
    have th1: "f a \<in> span (f ` b)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4283
      by (auto simp add: vector_smult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4284
    from inj_on_image_set_diff[OF "2.prems"(3), of "insert a b " "{a}", symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4285
    have tha: "f ` insert a b - f ` {a} = f ` (insert a b - {a})" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4286
    from "2.prems"(2)[unfolded dependent_def bex_simps(10), rule_format, of "f a"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4287
    have "f a \<notin> span (f ` b)" using tha
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4288
      using "2.hyps"(2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4289
      "2.prems"(3) by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4290
    with th1 have False by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4291
    then have "x \<in> span b" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4292
  ultimately have xsb: "x \<in> span b" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4293
  from "2.hyps"(3)[OF fb ifb fib xsb "2.prems"(5)]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4294
  show "x = 0" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4295
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4296
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4297
(* We can extend a linear mapping from basis.                                *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4298
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4299
lemma linear_independent_extend_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4300
  assumes fi: "finite B" and ib: "independent B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4301
  shows "\<exists>g. (\<forall>x\<in> span B. \<forall>y\<in> span B. g ((x::'a::field^'n) + y) = g x + g y) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4302
           \<and> (\<forall>x\<in> span B. \<forall>c. g (c*s x) = c *s g x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4303
           \<and> (\<forall>x\<in> B. g x = f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4304
using ib fi
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4305
proof(induct rule: finite_induct[OF fi])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4306
  case 1 thus ?case by (auto simp add: span_empty) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4307
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4308
  case (2 a b)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4309
  from "2.prems" "2.hyps" have ibf: "independent b" "finite b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4310
    by (simp_all add: independent_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4311
  from "2.hyps"(3)[OF ibf] obtain g where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4312
    g: "\<forall>x\<in>span b. \<forall>y\<in>span b. g (x + y) = g x + g y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4313
    "\<forall>x\<in>span b. \<forall>c. g (c *s x) = c *s g x" "\<forall>x\<in>b. g x = f x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4314
  let ?h = "\<lambda>z. SOME k. (z - k *s a) \<in> span b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4315
  {fix z assume z: "z \<in> span (insert a b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4316
    have th0: "z - ?h z *s a \<in> span b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4317
      apply (rule someI_ex)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4318
      unfolding span_breakdown_eq[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4319
      using z .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4320
    {fix k assume k: "z - k *s a \<in> span b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4321
      have eq: "z - ?h z *s a - (z - k*s a) = (k - ?h z) *s a" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4322
	by (simp add: ring_simps vector_sadd_rdistrib[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4323
      from span_sub[OF th0 k]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4324
      have khz: "(k - ?h z) *s a \<in> span b" by (simp add: eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4325
      {assume "k \<noteq> ?h z" hence k0: "k - ?h z \<noteq> 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4326
	from k0 span_mul[OF khz, of "1 /(k - ?h z)"] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4327
	have "a \<in> span b" by (simp add: vector_smult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4328
	with "2.prems"(1) "2.hyps"(2) have False
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4329
	  by (auto simp add: dependent_def)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4330
      then have "k = ?h z" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4331
    with th0 have "z - ?h z *s a \<in> span b \<and> (\<forall>k. z - k *s a \<in> span b \<longrightarrow> k = ?h z)" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4332
  note h = this
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4333
  let ?g = "\<lambda>z. ?h z *s f a + g (z - ?h z *s a)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4334
  {fix x y assume x: "x \<in> span (insert a b)" and y: "y \<in> span (insert a b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4335
    have tha: "\<And>(x::'a^'n) y a k l. (x + y) - (k + l) *s a = (x - k *s a) + (y - l *s a)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4336
      by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4337
    have addh: "?h (x + y) = ?h x + ?h y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4338
      apply (rule conjunct2[OF h, rule_format, symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4339
      apply (rule span_add[OF x y])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4340
      unfolding tha
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4341
      by (metis span_add x y conjunct1[OF h, rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4342
    have "?g (x + y) = ?g x + ?g y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4343
      unfolding addh tha
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4344
      g(1)[rule_format,OF conjunct1[OF h, OF x] conjunct1[OF h, OF y]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4345
      by (simp add: vector_sadd_rdistrib)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4346
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4347
  {fix x:: "'a^'n" and c:: 'a  assume x: "x \<in> span (insert a b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4348
    have tha: "\<And>(x::'a^'n) c k a. c *s x - (c * k) *s a = c *s (x - k *s a)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4349
      by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4350
    have hc: "?h (c *s x) = c * ?h x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4351
      apply (rule conjunct2[OF h, rule_format, symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4352
      apply (metis span_mul x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4353
      by (metis tha span_mul x conjunct1[OF h])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4354
    have "?g (c *s x) = c*s ?g x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4355
      unfolding hc tha g(2)[rule_format, OF conjunct1[OF h, OF x]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4356
      by (vector ring_simps)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4357
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4358
  {fix x assume x: "x \<in> (insert a b)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4359
    {assume xa: "x = a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4360
      have ha1: "1 = ?h a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4361
	apply (rule conjunct2[OF h, rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4362
	apply (metis span_superset insertI1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4363
	using conjunct1[OF h, OF span_superset, OF insertI1]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4364
	by (auto simp add: span_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4365
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4366
      from xa ha1[symmetric] have "?g x = f x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4367
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4368
	using g(2)[rule_format, OF span_0, of 0]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4369
	by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4370
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4371
    {assume xb: "x \<in> b"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4372
      have h0: "0 = ?h x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4373
	apply (rule conjunct2[OF h, rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4374
	apply (metis  span_superset insertI1 xb x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4375
	apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4376
	apply (metis span_superset xb)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4377
	done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4378
      have "?g x = f x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4379
	by (simp add: h0[symmetric] g(3)[rule_format, OF xb])}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4380
    ultimately have "?g x = f x" using x by blast }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4381
  ultimately show ?case apply - apply (rule exI[where x="?g"]) by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4382
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4383
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4384
lemma linear_independent_extend:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4385
  assumes iB: "independent (B:: (real ^'n) set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4386
  shows "\<exists>g. linear g \<and> (\<forall>x\<in>B. g x = f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4387
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4388
  from maximal_independent_subset_extend[of B "UNIV"] iB
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4389
  obtain C where C: "B \<subseteq> C" "independent C" "\<And>x. x \<in> span C" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4390
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4391
  from C(2) independent_bound[of C] linear_independent_extend_lemma[of C f]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4392
  obtain g where g: "(\<forall>x\<in> span C. \<forall>y\<in> span C. g (x + y) = g x + g y) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4393
           \<and> (\<forall>x\<in> span C. \<forall>c. g (c*s x) = c *s g x)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4394
           \<and> (\<forall>x\<in> C. g x = f x)" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4395
  from g show ?thesis unfolding linear_def using C 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4396
    apply clarsimp by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4397
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4398
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4399
(* Can construct an isomorphism between spaces of same dimension.            *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4400
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4401
lemma card_le_inj: assumes fA: "finite A" and fB: "finite B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4402
  and c: "card A \<le> card B" shows "(\<exists>f. f ` A \<subseteq> B \<and> inj_on f A)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4403
using fB c
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4404
proof(induct arbitrary: B rule: finite_induct[OF fA])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4405
  case 1 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4406
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4407
  case (2 x s t) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4408
  thus ?case
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4409
  proof(induct rule: finite_induct[OF "2.prems"(1)])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4410
    case 1    then show ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4411
  next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4412
    case (2 y t)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4413
    from "2.prems"(1,2,5) "2.hyps"(1,2) have cst:"card s \<le> card t" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4414
    from "2.prems"(3) [OF "2.hyps"(1) cst] obtain f where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4415
      f: "f ` s \<subseteq> t \<and> inj_on f s" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4416
    from f "2.prems"(2) "2.hyps"(2) show ?case
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4417
      apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4418
      apply (rule exI[where x = "\<lambda>z. if z = x then y else f z"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4419
      by (auto simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4420
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4421
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4422
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4423
lemma card_subset_eq: assumes fB: "finite B" and AB: "A \<subseteq> B" and 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4424
  c: "card A = card B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4425
  shows "A = B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4426
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4427
  from fB AB have fA: "finite A" by (auto intro: finite_subset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4428
  from fA fB have fBA: "finite (B - A)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4429
  have e: "A \<inter> (B - A) = {}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4430
  have eq: "A \<union> (B - A) = B" using AB by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4431
  from card_Un_disjoint[OF fA fBA e, unfolded eq c]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4432
  have "card (B - A) = 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4433
  hence "B - A = {}" unfolding card_eq_0_iff using fA fB by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4434
  with AB show "A = B" by blast  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4435
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4436
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4437
lemma subspace_isomorphism:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4438
  assumes s: "subspace (S:: (real ^'n) set)" and t: "subspace T" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4439
  and d: "dim S = dim T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4440
  shows "\<exists>f. linear f \<and> f ` S = T \<and> inj_on f S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4441
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4442
  from basis_exists[of S] obtain B where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4443
    B: "B \<subseteq> S" "independent B" "S \<subseteq> span B" "B hassize dim S" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4444
  from basis_exists[of T] obtain C where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4445
    C: "C \<subseteq> T" "independent C" "T \<subseteq> span C" "C hassize dim T" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4446
  from B(4) C(4) card_le_inj[of B C] d obtain f where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4447
    f: "f ` B \<subseteq> C" "inj_on f B" unfolding hassize_def by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4448
  from linear_independent_extend[OF B(2)] obtain g where
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4449
    g: "linear g" "\<forall>x\<in> B. g x = f x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4450
  from B(4) have fB: "finite B" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4451
  from C(4) have fC: "finite C" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4452
  from inj_on_iff_eq_card[OF fB, of f] f(2) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4453
  have "card (f ` B) = card B" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4454
  with B(4) C(4) have ceq: "card (f ` B) = card C" using d 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4455
    by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4456
  have "g ` B = f ` B" using g(2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4457
    by (auto simp add: image_iff)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4458
  also have "\<dots> = C" using card_subset_eq[OF fC f(1) ceq] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4459
  finally have gBC: "g ` B = C" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4460
  have gi: "inj_on g B" using f(2) g(2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4461
    by (auto simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4462
  note g0 = linear_indep_image_lemma[OF g(1) fB, unfolded gBC, OF C(2) gi]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4463
  {fix x y assume x: "x \<in> S" and y: "y \<in> S" and gxy:"g x = g y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4464
    from B(3) x y have x': "x \<in> span B" and y': "y \<in> span B" by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4465
    from gxy have th0: "g (x - y) = 0" by (simp add: linear_sub[OF g(1)])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4466
    have th1: "x - y \<in> span B" using x' y' by (metis span_sub) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4467
    have "x=y" using g0[OF th1 th0] by simp }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4468
  then have giS: "inj_on g S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4469
    unfolding inj_on_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4470
  from span_subspace[OF B(1,3) s]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4471
  have "g ` S = span (g ` B)" by (simp add: span_linear_image[OF g(1)])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4472
  also have "\<dots> = span C" unfolding gBC ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4473
  also have "\<dots> = T" using span_subspace[OF C(1,3) t] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4474
  finally have gS: "g ` S = T" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4475
  from g(1) gS giS show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4476
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4477
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4478
(* linear functions are equal on a subspace if they are on a spanning set.   *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4479
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4480
lemma subspace_kernel:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4481
  assumes lf: "linear (f::'a::semiring_1 ^'n \<Rightarrow> _)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4482
  shows "subspace {x. f x = 0}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4483
apply (simp add: subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4484
by (simp add: linear_add[OF lf] linear_cmul[OF lf] linear_0[OF lf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4485
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4486
lemma linear_eq_0_span:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4487
  assumes lf: "linear f" and f0: "\<forall>x\<in>B. f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4488
  shows "\<forall>x \<in> span B. f x = (0::'a::semiring_1 ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4489
proof
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4490
  fix x assume x: "x \<in> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4491
  let ?P = "\<lambda>x. f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4492
  from subspace_kernel[OF lf] have "subspace ?P" unfolding Collect_def .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4493
  with x f0 span_induct[of B "?P" x] show "f x = 0" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4494
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4495
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4496
lemma linear_eq_0:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4497
  assumes lf: "linear f" and SB: "S \<subseteq> span B" and f0: "\<forall>x\<in>B. f x = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4498
  shows "\<forall>x \<in> S. f x = (0::'a::semiring_1^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4499
  by (metis linear_eq_0_span[OF lf] subset_eq SB f0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4500
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4501
lemma linear_eq:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4502
  assumes lf: "linear (f::'a::ring_1^'n \<Rightarrow> _)" and lg: "linear g" and S: "S \<subseteq> span B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4503
  and fg: "\<forall> x\<in> B. f x = g x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4504
  shows "\<forall>x\<in> S. f x = g x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4505
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4506
  let ?h = "\<lambda>x. f x - g x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4507
  from fg have fg': "\<forall>x\<in> B. ?h x = 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4508
  from linear_eq_0[OF linear_compose_sub[OF lf lg] S fg']
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4509
  show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4510
qed    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4511
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4512
lemma linear_eq_stdbasis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4513
  assumes lf: "linear (f::'a::ring_1^'m \<Rightarrow> 'a^'n)" and lg: "linear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4514
  and fg: "\<forall>i \<in> {1 .. dimindex(UNIV :: 'm set)}. f (basis i) = g(basis i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4515
  shows "f = g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4516
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4517
  let ?U = "UNIV :: 'm set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4518
  let ?I = "{basis i:: 'a^'m|i. i \<in> {1 .. dimindex ?U}}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4519
  {fix x assume x: "x \<in> (UNIV :: ('a^'m) set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4520
    from equalityD2[OF span_stdbasis]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4521
    have IU: " (UNIV :: ('a^'m) set) \<subseteq> span ?I" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4522
    from linear_eq[OF lf lg IU] fg x
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4523
    have "f x = g x" unfolding Collect_def  Ball_def mem_def by metis}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4524
  then show ?thesis by (auto intro: ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4525
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4526
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4527
(* Similar results for bilinear functions.                                   *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4528
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4529
lemma bilinear_eq:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4530
  assumes bf: "bilinear (f:: 'a::ring^'m \<Rightarrow> 'a^'n \<Rightarrow> 'a^'p)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4531
  and bg: "bilinear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4532
  and SB: "S \<subseteq> span B" and TC: "T \<subseteq> span C"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4533
  and fg: "\<forall>x\<in> B. \<forall>y\<in> C. f x y = g x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4534
  shows "\<forall>x\<in>S. \<forall>y\<in>T. f x y = g x y "
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4535
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4536
  let ?P = "\<lambda>x. \<forall>y\<in> span C. f x y = g x y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4537
  from bf bg have sp: "subspace ?P" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4538
    unfolding bilinear_def linear_def subspace_def bf bg  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4539
    by(auto simp add: span_0 mem_def bilinear_lzero[OF bf] bilinear_lzero[OF bg] span_add Ball_def intro:  bilinear_ladd[OF bf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4540
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4541
  have "\<forall>x \<in> span B. \<forall>y\<in> span C. f x y = g x y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4542
    apply -
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4543
    apply (rule ballI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4544
    apply (rule span_induct[of B ?P]) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4545
    defer
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4546
    apply (rule sp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4547
    apply assumption
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4548
    apply (clarsimp simp add: Ball_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4549
    apply (rule_tac P="\<lambda>y. f xa y = g xa y" and S=C in span_induct)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4550
    using fg 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4551
    apply (auto simp add: subspace_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4552
    using bf bg unfolding bilinear_def linear_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4553
    by(auto simp add: span_0 mem_def bilinear_rzero[OF bf] bilinear_rzero[OF bg] span_add Ball_def intro:  bilinear_ladd[OF bf])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4554
  then show ?thesis using SB TC by (auto intro: ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4555
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4556
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4557
lemma bilinear_eq_stdbasis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4558
  assumes bf: "bilinear (f:: 'a::ring_1^'m \<Rightarrow> 'a^'n \<Rightarrow> 'a^'p)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4559
  and bg: "bilinear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4560
  and fg: "\<forall>i\<in> {1 .. dimindex (UNIV :: 'm set)}. \<forall>j\<in>  {1 .. dimindex (UNIV :: 'n set)}. f (basis i) (basis j) = g (basis i) (basis j)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4561
  shows "f = g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4562
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4563
  from fg have th: "\<forall>x \<in> {basis i| i. i\<in> {1 .. dimindex (UNIV :: 'm set)}}. \<forall>y\<in>  {basis j |j. j \<in> {1 .. dimindex (UNIV :: 'n set)}}. f x y = g x y" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4564
  from bilinear_eq[OF bf bg equalityD2[OF span_stdbasis] equalityD2[OF span_stdbasis] th] show ?thesis by (blast intro: ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4565
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4566
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4567
(* Detailed theorems about left and right invertibility in general case.     *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4568
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4569
lemma left_invertible_transp:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4570
  "(\<exists>(B::'a^'n^'m). B ** transp (A::'a^'n^'m) = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B::'a^'m^'n). A ** B = mat 1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4571
  by (metis matrix_transp_mul transp_mat transp_transp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4572
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4573
lemma right_invertible_transp:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4574
  "(\<exists>(B::'a^'n^'m). transp (A::'a^'n^'m) ** B = mat (1::'a::comm_semiring_1)) \<longleftrightarrow> (\<exists>(B::'a^'m^'n). B ** A = mat 1)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4575
  by (metis matrix_transp_mul transp_mat transp_transp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4576
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4577
lemma linear_injective_left_inverse:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4578
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'m)" and fi: "inj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4579
  shows "\<exists>g. linear g \<and> g o f = id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4580
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4581
  from linear_independent_extend[OF independent_injective_image, OF independent_stdbasis, OF lf fi]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4582
  obtain h:: "real ^'m \<Rightarrow> real ^'n" where h: "linear h" " \<forall>x \<in> f ` {basis i|i. i \<in> {1 .. dimindex (UNIV::'n set)}}. h x = inv f x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4583
  from h(2) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4584
  have th: "\<forall>i\<in>{1..dimindex (UNIV::'n set)}. (h \<circ> f) (basis i) = id (basis i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4585
    using inv_o_cancel[OF fi, unfolded stupid_ext[symmetric] id_def o_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4586
    apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4587
    apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4588
    by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4589
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4590
  from linear_eq_stdbasis[OF linear_compose[OF lf h(1)] linear_id th]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4591
  have "h o f = id" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4592
  then show ?thesis using h(1) by blast  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4593
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4594
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4595
lemma linear_surjective_right_inverse:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4596
  assumes lf: "linear (f:: real ^'m \<Rightarrow> real ^'n)" and sf: "surj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4597
  shows "\<exists>g. linear g \<and> f o g = id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4598
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4599
  from linear_independent_extend[OF independent_stdbasis]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4600
  obtain h:: "real ^'n \<Rightarrow> real ^'m" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4601
    h: "linear h" "\<forall> x\<in> {basis i| i. i\<in> {1 .. dimindex (UNIV :: 'n set)}}. h x = inv f x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4602
  from h(2) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4603
  have th: "\<forall>i\<in>{1..dimindex (UNIV::'n set)}. (f o h) (basis i) = id (basis i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4604
    using sf
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4605
    apply (auto simp add: surj_iff o_def stupid_ext[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4606
    apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4607
    by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4608
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4609
  from linear_eq_stdbasis[OF linear_compose[OF h(1) lf] linear_id th]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4610
  have "f o h = id" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4611
  then show ?thesis using h(1) by blast  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4612
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4613
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4614
lemma matrix_left_invertible_injective:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4615
"(\<exists>B. (B::real^'m^'n) ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x y. A *v x = A *v y \<longrightarrow> x = y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4616
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4617
  {fix B:: "real^'m^'n" and x y assume B: "B ** A = mat 1" and xy: "A *v x = A*v y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4618
    from xy have "B*v (A *v x) = B *v (A*v y)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4619
    hence "x = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4620
      unfolding matrix_vector_mul_assoc B matrix_vector_mul_lid .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4621
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4622
  {assume A: "\<forall>x y. A *v x = A *v y \<longrightarrow> x = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4623
    hence i: "inj (op *v A)" unfolding inj_on_def by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4624
    from linear_injective_left_inverse[OF matrix_vector_mul_linear i]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4625
    obtain g where g: "linear g" "g o op *v A = id" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4626
    have "matrix g ** A = mat 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4627
      unfolding matrix_eq matrix_vector_mul_lid matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4628
      using g(2) by (simp add: o_def id_def stupid_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4629
    then have "\<exists>B. (B::real ^'m^'n) ** A = mat 1" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4630
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4631
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4632
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4633
lemma matrix_left_invertible_ker:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4634
  "(\<exists>B. (B::real ^'m^'n) ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> (\<forall>x. A *v x = 0 \<longrightarrow> x = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4635
  unfolding matrix_left_invertible_injective
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4636
  using linear_injective_0[OF matrix_vector_mul_linear, of A]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4637
  by (simp add: inj_on_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4638
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4639
lemma matrix_right_invertible_surjective:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4640
"(\<exists>B. (A::real^'n^'m) ** (B::real^'m^'n) = mat 1) \<longleftrightarrow> surj (\<lambda>x. A *v x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4641
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4642
  {fix B :: "real ^'m^'n"  assume AB: "A ** B = mat 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4643
    {fix x :: "real ^ 'm" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4644
      have "A *v (B *v x) = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4645
	by (simp add: matrix_vector_mul_lid matrix_vector_mul_assoc AB)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4646
    hence "surj (op *v A)" unfolding surj_def by metis }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4647
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4648
  {assume sf: "surj (op *v A)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4649
    from linear_surjective_right_inverse[OF matrix_vector_mul_linear sf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4650
    obtain g:: "real ^'m \<Rightarrow> real ^'n" where g: "linear g" "op *v A o g = id" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4651
      by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4652
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4653
    have "A ** (matrix g) = mat 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4654
      unfolding matrix_eq  matrix_vector_mul_lid 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4655
	matrix_vector_mul_assoc[symmetric] matrix_works[OF g(1)] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4656
      using g(2) unfolding o_def stupid_ext[symmetric] id_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4657
      .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4658
    hence "\<exists>B. A ** (B::real^'m^'n) = mat 1" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4659
  }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4660
  ultimately show ?thesis unfolding surj_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4661
qed    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4662
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4663
lemma matrix_left_invertible_independent_columns:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4664
  fixes A :: "real^'n^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4665
  shows "(\<exists>(B::real ^'m^'n). B ** A = mat 1) \<longleftrightarrow> (\<forall>c. setsum (\<lambda>i. c i *s column i A) {1 .. dimindex(UNIV :: 'n set)} = 0 \<longrightarrow> (\<forall>i\<in> {1 .. dimindex (UNIV :: 'n set)}. c i = 0))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4666
   (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4667
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4668
  let ?U = "{1 .. dimindex(UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4669
  {assume k: "\<forall>x. A *v x = 0 \<longrightarrow> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4670
    {fix c i assume c: "setsum (\<lambda>i. c i *s column i A) ?U = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4671
      and i: "i \<in> ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4672
      let ?x = "\<chi> i. c i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4673
      have th0:"A *v ?x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4674
	using c
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4675
	unfolding matrix_mult_vsum Cart_eq
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4676
	by (auto simp add: vector_component zero_index setsum_component Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4677
      from k[rule_format, OF th0] i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4678
      have "c i = 0" by (vector Cart_eq)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4679
    hence ?rhs by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4680
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4681
  {assume H: ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4682
    {fix x assume x: "A *v x = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4683
      let ?c = "\<lambda>i. ((x$i ):: real)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4684
      from H[rule_format, of ?c, unfolded matrix_mult_vsum[symmetric], OF x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4685
      have "x = 0" by vector}}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4686
  ultimately show ?thesis unfolding matrix_left_invertible_ker by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4687
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4688
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4689
lemma matrix_right_invertible_independent_rows:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4690
  fixes A :: "real^'n^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4691
  shows "(\<exists>(B::real^'m^'n). A ** B = mat 1) \<longleftrightarrow> (\<forall>c. setsum (\<lambda>i. c i *s row i A) {1 .. dimindex(UNIV :: 'm set)} = 0 \<longrightarrow> (\<forall>i\<in> {1 .. dimindex (UNIV :: 'm set)}. c i = 0))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4692
  unfolding left_invertible_transp[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4693
    matrix_left_invertible_independent_columns
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4694
  by (simp add: column_transp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4695
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4696
lemma matrix_right_invertible_span_columns:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4697
  "(\<exists>(B::real ^'n^'m). (A::real ^'m^'n) ** B = mat 1) \<longleftrightarrow> span (columns A) = UNIV" (is "?lhs = ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4698
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4699
  let ?U = "{1 .. dimindex (UNIV :: 'm set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4700
  have fU: "finite ?U" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4701
  have lhseq: "?lhs \<longleftrightarrow> (\<forall>y. \<exists>(x::real^'m). setsum (\<lambda>i. (x$i) *s column i A) ?U = y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4702
    unfolding matrix_right_invertible_surjective matrix_mult_vsum surj_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4703
    apply (subst eq_commute) ..    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4704
  have rhseq: "?rhs \<longleftrightarrow> (\<forall>x. x \<in> span (columns A))" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4705
  {assume h: ?lhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4706
    {fix x:: "real ^'n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4707
	from h[unfolded lhseq, rule_format, of x] obtain y:: "real ^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4708
	  where y: "setsum (\<lambda>i. (y$i) *s column i A) ?U = x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4709
	have "x \<in> span (columns A)"  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4710
	  unfolding y[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4711
	  apply (rule span_setsum[OF fU])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4712
	  apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4713
	  apply (rule span_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4714
	  apply (rule span_superset)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4715
	  unfolding columns_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4716
	  by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4717
    then have ?rhs unfolding rhseq by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4718
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4719
  {assume h:?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4720
    let ?P = "\<lambda>(y::real ^'n). \<exists>(x::real^'m). setsum (\<lambda>i. (x$i) *s column i A) ?U = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4721
    {fix y have "?P y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4722
      proof(rule span_induct_alt[of ?P "columns A"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4723
	show "\<exists>x\<Colon>real ^ 'm. setsum (\<lambda>i. (x$i) *s column i A) ?U = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4724
	  apply (rule exI[where x=0])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4725
	  by (simp add: zero_index vector_smult_lzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4726
      next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4727
	fix c y1 y2 assume y1: "y1 \<in> columns A" and y2: "?P y2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4728
	from y1 obtain i where i: "i \<in> ?U" "y1 = column i A" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4729
	  unfolding columns_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4730
	from y2 obtain x:: "real ^'m" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4731
	  x: "setsum (\<lambda>i. (x$i) *s column i A) ?U = y2" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4732
	let ?x = "(\<chi> j. if j = i then c + (x$i) else (x$j))::real^'m"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4733
	show "?P (c*s y1 + y2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4734
	  proof(rule exI[where x= "?x"], vector, auto simp add: i x[symmetric]Cart_lambda_beta setsum_component cond_value_iff right_distrib cond_application_beta vector_component cong del: if_weak_cong, simp only: One_nat_def[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4735
	    fix j 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4736
	    have th: "\<forall>xa \<in> ?U. (if xa = i then (c + (x$i)) * ((column xa A)$j)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4737
           else (x$xa) * ((column xa A$j))) = (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))" using i(1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4738
	      by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4739
	    have "setsum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4740
           else (x$xa) * ((column xa A$j))) ?U = setsum (\<lambda>xa. (if xa = i then c * ((column i A)$j) else 0) + ((x$xa) * ((column xa A)$j))) ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4741
	      apply (rule setsum_cong[OF refl])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4742
	      using th by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4743
	    also have "\<dots> = setsum (\<lambda>xa. if xa = i then c * ((column i A)$j) else 0) ?U + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4744
	      by (simp add: setsum_addf)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4745
	    also have "\<dots> = c * ((column i A)$j) + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4746
	      unfolding setsum_delta[OF fU]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4747
	      using i(1) by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4748
	    finally show "setsum (\<lambda>xa. if xa = i then (c + (x$i)) * ((column xa A)$j)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4749
           else (x$xa) * ((column xa A$j))) ?U = c * ((column i A)$j) + setsum (\<lambda>xa. ((x$xa) * ((column xa A)$j))) ?U" .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4750
	  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4751
	next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4752
	  show "y \<in> span (columns A)" unfolding h by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4753
	qed}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4754
    then have ?lhs unfolding lhseq ..}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4755
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4756
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4757
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4758
lemma matrix_left_invertible_span_rows:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4759
  "(\<exists>(B::real^'m^'n). B ** (A::real^'n^'m) = mat 1) \<longleftrightarrow> span (rows A) = UNIV"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4760
  unfolding right_invertible_transp[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4761
  unfolding columns_transp[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4762
  unfolding matrix_right_invertible_span_columns
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4763
 ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4764
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4765
(* An injective map real^'n->real^'n is also surjective.                       *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4766
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4767
lemma linear_injective_imp_surjective:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4768
  assumes lf: "linear (f:: real ^'n \<Rightarrow> real ^'n)" and fi: "inj f" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4769
  shows "surj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4770
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4771
  let ?U = "UNIV :: (real ^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4772
  from basis_exists[of ?U] obtain B 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4773
    where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" "B hassize dim ?U" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4774
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4775
  from B(4) have d: "dim ?U = card B" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4776
  have th: "?U \<subseteq> span (f ` B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4777
    apply (rule card_ge_dim_independent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4778
    apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4779
    apply (rule independent_injective_image[OF B(2) lf fi])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4780
    apply (rule order_eq_refl)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4781
    apply (rule sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4782
    unfolding d
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4783
    apply (rule card_image)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4784
    apply (rule subset_inj_on[OF fi])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4785
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4786
  from th show ?thesis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4787
    unfolding span_linear_image[OF lf] surj_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4788
    using B(3) by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4789
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4790
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4791
(* And vice versa.                                                           *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4792
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4793
lemma surjective_iff_injective_gen: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4794
  assumes fS: "finite S" and fT: "finite T" and c: "card S = card T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4795
  and ST: "f ` S \<subseteq> T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4796
  shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4797
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4798
  {assume h: "?lhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4799
    {fix x y assume x: "x \<in> S" and y: "y \<in> S" and f: "f x = f y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4800
      from x fS have S0: "card S \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4801
      {assume xy: "x \<noteq> y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4802
	have th: "card S \<le> card (f ` (S - {y}))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4803
	  unfolding c
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4804
	  apply (rule card_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4805
	  apply (rule finite_imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4806
	  using fS apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4807
	  using h xy x y f unfolding subset_eq image_iff
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4808
	  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4809
	  apply (case_tac "xa = f x")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4810
	  apply (rule bexI[where x=x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4811
	  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4812
	  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4813
	also have " \<dots> \<le> card (S -{y})"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4814
	  apply (rule card_image_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4815
	  using fS by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4816
	also have "\<dots> \<le> card S - 1" using y fS by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4817
	finally have False  using S0 by arith }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4818
      then have "x = y" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4819
    then have ?rhs unfolding inj_on_def by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4820
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4821
  {assume h: ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4822
    have "f ` S = T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4823
      apply (rule card_subset_eq[OF fT ST])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4824
      unfolding card_image[OF h] using c .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4825
    then have ?lhs by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4826
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4827
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4828
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4829
lemma linear_surjective_imp_injective:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4830
  assumes lf: "linear (f::real ^'n => real ^'n)" and sf: "surj f" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4831
  shows "inj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4832
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4833
  let ?U = "UNIV :: (real ^'n) set"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4834
  from basis_exists[of ?U] obtain B 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4835
    where B: "B \<subseteq> ?U" "independent B" "?U \<subseteq> span B" "B hassize dim ?U" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4836
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4837
  {fix x assume x: "x \<in> span B" and fx: "f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4838
    from B(4) have fB: "finite B" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4839
    from B(4) have d: "dim ?U = card B" by (simp add: hassize_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4840
    have fBi: "independent (f ` B)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4841
      apply (rule card_le_dim_spanning[of "f ` B" ?U])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4842
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4843
      using sf B(3)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4844
      unfolding span_linear_image[OF lf] surj_def subset_eq image_iff
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4845
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4846
      using fB apply (blast intro: finite_imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4847
      unfolding d
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4848
      apply (rule card_image_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4849
      apply (rule fB)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4850
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4851
    have th0: "dim ?U \<le> card (f ` B)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4852
      apply (rule span_card_ge_dim)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4853
      apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4854
      unfolding span_linear_image[OF lf]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4855
      apply (rule subset_trans[where B = "f ` UNIV"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4856
      using sf unfolding surj_def apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4857
      apply (rule image_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4858
      apply (rule B(3))
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4859
      apply (metis finite_imageI fB)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4860
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4861
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4862
    moreover have "card (f ` B) \<le> card B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4863
      by (rule card_image_le, rule fB)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4864
    ultimately have th1: "card B = card (f ` B)" unfolding d by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4865
    have fiB: "inj_on f B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4866
      unfolding surjective_iff_injective_gen[OF fB finite_imageI[OF fB] th1 subset_refl, symmetric] by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4867
    from linear_indep_image_lemma[OF lf fB fBi fiB x] fx
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4868
    have "x = 0" by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4869
  note th = this
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4870
  from th show ?thesis unfolding linear_injective_0[OF lf] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4871
    using B(3) by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4872
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4873
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4874
(* Hence either is enough for isomorphism.                                   *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4875
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4876
lemma left_right_inverse_eq:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4877
  assumes fg: "f o g = id" and gh: "g o h = id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4878
  shows "f = h" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4879
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4880
  have "f = f o (g o h)" unfolding gh by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4881
  also have "\<dots> = (f o g) o h" by (simp add: o_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4882
  finally show "f = h" unfolding fg by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4883
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4884
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4885
lemma isomorphism_expand:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4886
  "f o g = id \<and> g o f = id \<longleftrightarrow> (\<forall>x. f(g x) = x) \<and> (\<forall>x. g(f x) = x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4887
  by (simp add: expand_fun_eq o_def id_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4888
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4889
lemma linear_injective_isomorphism:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4890
  assumes lf: "linear (f :: real^'n \<Rightarrow> real ^'n)" and fi: "inj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4891
  shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4892
unfolding isomorphism_expand[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4893
using linear_surjective_right_inverse[OF lf linear_injective_imp_surjective[OF lf fi]] linear_injective_left_inverse[OF lf fi]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4894
by (metis left_right_inverse_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4895
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4896
lemma linear_surjective_isomorphism:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4897
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and sf: "surj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4898
  shows "\<exists>f'. linear f' \<and> (\<forall>x. f' (f x) = x) \<and> (\<forall>x. f (f' x) = x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4899
unfolding isomorphism_expand[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4900
using linear_surjective_right_inverse[OF lf sf] linear_injective_left_inverse[OF lf linear_surjective_imp_injective[OF lf sf]]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4901
by (metis left_right_inverse_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4902
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4903
(* Left and right inverses are the same for R^N->R^N.                        *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4904
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4905
lemma linear_inverse_left:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4906
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and lf': "linear f'"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4907
  shows "f o f' = id \<longleftrightarrow> f' o f = id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4908
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4909
  {fix f f':: "real ^'n \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4910
    assume lf: "linear f" "linear f'" and f: "f o f' = id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4911
    from f have sf: "surj f"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4912
      
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4913
      apply (auto simp add: o_def stupid_ext[symmetric] id_def surj_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4914
      by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4915
    from linear_surjective_isomorphism[OF lf(1) sf] lf f
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4916
    have "f' o f = id" unfolding stupid_ext[symmetric] o_def id_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4917
      by metis}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4918
  then show ?thesis using lf lf' by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4919
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4920
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4921
(* Moreover, a one-sided inverse is automatically linear.                    *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4922
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4923
lemma left_inverse_linear:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4924
  assumes lf: "linear (f::real ^'n \<Rightarrow> real ^'n)" and gf: "g o f = id" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4925
  shows "linear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4926
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4927
  from gf have fi: "inj f" apply (auto simp add: inj_on_def o_def id_def stupid_ext[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4928
    by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4929
  from linear_injective_isomorphism[OF lf fi] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4930
  obtain h:: "real ^'n \<Rightarrow> real ^'n" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4931
    h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4932
  have "h = g" apply (rule ext) using gf h(2,3)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4933
    apply (simp add: o_def id_def stupid_ext[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4934
    by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4935
  with h(1) show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4936
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4937
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4938
lemma right_inverse_linear:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4939
  assumes lf: "linear (f:: real ^'n \<Rightarrow> real ^'n)" and gf: "f o g = id" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4940
  shows "linear g"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4941
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4942
  from gf have fi: "surj f" apply (auto simp add: surj_def o_def id_def stupid_ext[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4943
    by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4944
  from linear_surjective_isomorphism[OF lf fi] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4945
  obtain h:: "real ^'n \<Rightarrow> real ^'n" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4946
    h: "linear h" "\<forall>x. h (f x) = x" "\<forall>x. f (h x) = x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4947
  have "h = g" apply (rule ext) using gf h(2,3)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4948
    apply (simp add: o_def id_def stupid_ext[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4949
    by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4950
  with h(1) show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4951
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4952
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4953
(* The same result in terms of square matrices.                              *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4954
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4955
lemma matrix_left_right_inverse:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4956
  fixes A A' :: "real ^'n^'n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4957
  shows "A ** A' = mat 1 \<longleftrightarrow> A' ** A = mat 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4958
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4959
  {fix A A' :: "real ^'n^'n" assume AA': "A ** A' = mat 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4960
    have sA: "surj (op *v A)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4961
      unfolding surj_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4962
      apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4963
      apply (rule_tac x="(A' *v y)" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4964
      by (simp add: matrix_vector_mul_assoc AA' matrix_vector_mul_lid)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4965
    from linear_surjective_isomorphism[OF matrix_vector_mul_linear sA]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4966
    obtain f' :: "real ^'n \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4967
      where f': "linear f'" "\<forall>x. f' (A *v x) = x" "\<forall>x. A *v f' x = x" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4968
    have th: "matrix f' ** A = mat 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4969
      by (simp add: matrix_eq matrix_works[OF f'(1)] matrix_vector_mul_assoc[symmetric] matrix_vector_mul_lid f'(2)[rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4970
    hence "(matrix f' ** A) ** A' = mat 1 ** A'" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4971
    hence "matrix f' = A'" by (simp add: matrix_mul_assoc[symmetric] AA' matrix_mul_rid matrix_mul_lid)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4972
    hence "matrix f' ** A = A' ** A" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4973
    hence "A' ** A = mat 1" by (simp add: th)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4974
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4975
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4976
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4977
(* Considering an n-element vector as an n-by-1 or 1-by-n matrix.            *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4978
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4979
definition "rowvector v = (\<chi> i j. (v$j))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4980
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4981
definition "columnvector v = (\<chi> i j. (v$i))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4982
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4983
lemma transp_columnvector:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4984
 "transp(columnvector v) = rowvector v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4985
  by (simp add: transp_def rowvector_def columnvector_def Cart_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4986
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4987
lemma transp_rowvector: "transp(rowvector v) = columnvector v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4988
  by (simp add: transp_def columnvector_def rowvector_def Cart_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4989
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4990
lemma dot_rowvector_columnvector:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4991
  "columnvector (A *v v) = A ** columnvector v"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4992
  by (vector columnvector_def matrix_matrix_mult_def matrix_vector_mult_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4993
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4994
lemma dot_matrix_product: "(x::'a::semiring_1^'n) \<bullet> y = (((rowvector x ::'a^'n^1) ** (columnvector y :: 'a^1^'n))$1)$1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4995
  apply (vector matrix_matrix_mult_def rowvector_def columnvector_def dot_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4996
  by (simp add: Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4997
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4998
lemma dot_matrix_vector_mul:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  4999
  fixes A B :: "real ^'n ^'n" and x y :: "real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5000
  shows "(A *v x) \<bullet> (B *v y) =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5001
      (((rowvector x :: real^'n^1) ** ((transp A ** B) ** (columnvector y :: real ^1^'n)))$1)$1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5002
unfolding dot_matrix_product transp_columnvector[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5003
  dot_rowvector_columnvector matrix_transp_mul matrix_mul_assoc ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5004
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5005
(* Infinity norm.                                                            *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5006
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5007
definition "infnorm (x::real^'n) = rsup {abs(x$i) |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5008
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5009
lemma numseg_dimindex_nonempty: "\<exists>i. i \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5010
  using dimindex_ge_1 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5011
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5012
lemma infnorm_set_image:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5013
  "{abs(x$i) |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}} =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5014
  (\<lambda>i. abs(x$i)) ` {1 .. dimindex(UNIV :: 'n set)}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5015
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5016
lemma infnorm_set_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5017
  shows "finite {abs((x::'a::abs ^'n)$i) |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5018
  and "{abs(x$i) |i. i\<in> {1 .. dimindex(UNIV :: 'n set)}} \<noteq> {}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5019
  unfolding infnorm_set_image
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5020
  using dimindex_ge_1[of "UNIV :: 'n set"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5021
  by (auto intro: finite_imageI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5022
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5023
lemma infnorm_pos_le: "0 \<le> infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5024
  unfolding infnorm_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5025
  unfolding rsup_finite_ge_iff[ OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5026
  unfolding infnorm_set_image
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5027
  using dimindex_ge_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5028
  by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5029
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5030
lemma infnorm_triangle: "infnorm ((x::real^'n) + y) \<le> infnorm x + infnorm y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5031
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5032
  have th: "\<And>x y (z::real). x - y <= z \<longleftrightarrow> x - z <= y" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5033
  have th1: "\<And>S f. f ` S = { f i| i. i \<in> S}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5034
  have th2: "\<And>x (y::real). abs(x + y) - abs(x) <= abs(y)" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5035
  show ?thesis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5036
  unfolding infnorm_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5037
  unfolding rsup_finite_le_iff[ OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5038
  apply (subst diff_le_eq[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5039
  unfolding rsup_finite_ge_iff[ OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5040
  unfolding infnorm_set_image bex_simps 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5041
  apply (subst th)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5042
  unfolding th1 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5043
  unfolding rsup_finite_ge_iff[ OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5044
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5045
  unfolding infnorm_set_image ball_simps bex_simps 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5046
  apply (simp add: vector_add_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5047
  apply (metis numseg_dimindex_nonempty th2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5048
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5049
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5050
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5051
lemma infnorm_eq_0: "infnorm x = 0 \<longleftrightarrow> (x::real ^'n) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5052
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5053
  have "infnorm x <= 0 \<longleftrightarrow> x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5054
    unfolding infnorm_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5055
    unfolding rsup_finite_le_iff[OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5056
    unfolding infnorm_set_image ball_simps
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5057
    by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5058
  then show ?thesis using infnorm_pos_le[of x] by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5059
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5060
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5061
lemma infnorm_0: "infnorm 0 = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5062
  by (simp add: infnorm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5063
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5064
lemma infnorm_neg: "infnorm (- x) = infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5065
  unfolding infnorm_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5066
  apply (rule cong[of "rsup" "rsup"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5067
  apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5068
  apply (rule set_ext)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5069
  apply (auto simp add: vector_component abs_minus_cancel)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5070
  apply (rule_tac x="i" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5071
  apply (simp add: vector_component)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5072
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5073
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5074
lemma infnorm_sub: "infnorm (x - y) = infnorm (y - x)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5075
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5076
  have "y - x = - (x - y)" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5077
  then show ?thesis  by (metis infnorm_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5078
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5079
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5080
lemma real_abs_sub_infnorm: "\<bar> infnorm x - infnorm y\<bar> \<le> infnorm (x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5081
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5082
  have th: "\<And>(nx::real) n ny. nx <= n + ny \<Longrightarrow> ny <= n + nx ==> \<bar>nx - ny\<bar> <= n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5083
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5084
  from infnorm_triangle[of "x - y" " y"] infnorm_triangle[of "x - y" "-x"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5085
  have ths: "infnorm x \<le> infnorm (x - y) + infnorm y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5086
    "infnorm y \<le> infnorm (x - y) + infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5087
    by (simp_all add: ring_simps infnorm_neg diff_def[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5088
  from th[OF ths]  show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5089
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5090
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5091
lemma real_abs_infnorm: " \<bar>infnorm x\<bar> = infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5092
  using infnorm_pos_le[of x] by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5093
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5094
lemma component_le_infnorm: assumes i: "i \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5095
  shows "\<bar>x$i\<bar> \<le> infnorm (x::real^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5096
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5097
  let ?U = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5098
  let ?S = "{\<bar>x$i\<bar> |i. i\<in> ?U}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5099
  have fS: "finite ?S" unfolding image_Collect[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5100
    apply (rule finite_imageI) unfolding Collect_def mem_def by simp  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5101
  have S0: "?S \<noteq> {}" using numseg_dimindex_nonempty by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5102
  have th1: "\<And>S f. f ` S = { f i| i. i \<in> S}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5103
  from rsup_finite_in[OF fS S0] rsup_finite_Ub[OF fS S0] i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5104
  show ?thesis unfolding infnorm_def isUb_def setle_def 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5105
    unfolding infnorm_set_image ball_simps by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5106
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5107
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5108
lemma infnorm_mul_lemma: "infnorm(a *s x) <= \<bar>a\<bar> * infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5109
  apply (subst infnorm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5110
  unfolding rsup_finite_le_iff[OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5111
  unfolding infnorm_set_image ball_simps
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5112
  apply (simp add: abs_mult vector_component del: One_nat_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5113
  apply (rule ballI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5114
  apply (drule component_le_infnorm[of _ x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5115
  apply (rule mult_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5116
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5117
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5118
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5119
lemma infnorm_mul: "infnorm(a *s x) = abs a * infnorm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5120
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5121
  {assume a0: "a = 0" hence ?thesis by (simp add: infnorm_0) }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5122
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5123
  {assume a0: "a \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5124
    from a0 have th: "(1/a) *s (a *s x) = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5125
      by (simp add: vector_smult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5126
    from a0 have ap: "\<bar>a\<bar> > 0" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5127
    from infnorm_mul_lemma[of "1/a" "a *s x"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5128
    have "infnorm x \<le> 1/\<bar>a\<bar> * infnorm (a*s x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5129
      unfolding th by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5130
    with ap have "\<bar>a\<bar> * infnorm x \<le> \<bar>a\<bar> * (1/\<bar>a\<bar> * infnorm (a *s x))" by (simp add: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5131
    then have "\<bar>a\<bar> * infnorm x \<le> infnorm (a*s x)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5132
      using ap by (simp add: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5133
    with infnorm_mul_lemma[of a x] have ?thesis by arith }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5134
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5135
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5136
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5137
lemma infnorm_pos_lt: "infnorm x > 0 \<longleftrightarrow> x \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5138
  using infnorm_pos_le[of x] infnorm_eq_0[of x] by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5139
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5140
(* Prove that it differs only up to a bound from Euclidean norm.             *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5141
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5142
lemma infnorm_le_norm: "infnorm x \<le> norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5143
  unfolding infnorm_def rsup_finite_le_iff[OF infnorm_set_lemma] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5144
  unfolding infnorm_set_image  ball_simps
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5145
  by (metis component_le_norm)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5146
lemma card_enum: "card {1 .. n} = n" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5147
lemma norm_le_infnorm: "norm(x) <= sqrt(real (dimindex(UNIV ::'n set))) * infnorm(x::real ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5148
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5149
  let ?d = "dimindex(UNIV ::'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5150
  have d: "?d = card {1 .. ?d}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5151
  have "real ?d \<ge> 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5152
  hence d2: "(sqrt (real ?d))^2 = real ?d"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5153
    by (auto intro: real_sqrt_pow2)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5154
  have th: "sqrt (real ?d) * infnorm x \<ge> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5155
    by (simp add: dimindex_ge_1 zero_le_mult_iff real_sqrt_ge_0_iff infnorm_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5156
  have th1: "x\<bullet>x \<le> (sqrt (real ?d) * infnorm x)^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5157
    unfolding power_mult_distrib d2 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5158
    apply (subst d)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5159
    apply (subst power2_abs[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5160
    unfolding real_of_nat_def dot_def power2_eq_square[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5161
    apply (subst power2_abs[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5162
    apply (rule setsum_bounded)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5163
    apply (rule power_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5164
    unfolding abs_of_nonneg[OF infnorm_pos_le] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5165
    unfolding infnorm_def  rsup_finite_ge_iff[OF infnorm_set_lemma]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5166
    unfolding infnorm_set_image bex_simps
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5167
    apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5168
    by (rule abs_ge_zero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5169
  from real_le_lsqrt[OF dot_pos_le th th1]
30040
e2cd1acda1ab real_normed_vector instance
huffman
parents: 30039
diff changeset
  5170
  show ?thesis unfolding real_vector_norm_def id_def . 
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5171
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5172
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5173
(* Equality in Cauchy-Schwarz and triangle inequalities.                     *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5174
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5175
lemma norm_cauchy_schwarz_eq: "(x::real ^'n) \<bullet> y = norm x * norm y \<longleftrightarrow> norm x *s y = norm y *s x" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5176
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5177
  {assume h: "x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5178
    hence ?thesis by (simp add: norm_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5179
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5180
  {assume h: "y = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5181
    hence ?thesis by (simp add: norm_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5182
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5183
  {assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5184
    from dot_eq_0[of "norm y *s x - norm x *s y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5185
    have "?rhs \<longleftrightarrow> (norm y * (norm y * norm x * norm x - norm x * (x \<bullet> y)) - norm x * (norm y * (y \<bullet> x) - norm x * norm y * norm y) =  0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5186
      using x y
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5187
      unfolding dot_rsub dot_lsub dot_lmult dot_rmult
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5188
      unfolding norm_pow_2[symmetric] power2_eq_square diff_eq_0_iff_eq apply (simp add: dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5189
      apply (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5190
      apply metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5191
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5192
    also have "\<dots> \<longleftrightarrow> (2 * norm x * norm y * (norm x * norm y - x \<bullet> y) = 0)" using x y
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5193
      by (simp add: ring_simps dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5194
    also have "\<dots> \<longleftrightarrow> ?lhs" using x y
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5195
      apply (simp add: norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5196
      by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5197
    finally have ?thesis by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5198
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5199
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5200
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5201
lemma norm_cauchy_schwarz_abs_eq: "abs(x \<bullet> y) = norm x * norm y \<longleftrightarrow>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5202
                norm x *s y = norm y *s x \<or> norm(x) *s y = - norm y *s x" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5203
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5204
  have th: "\<And>(x::real) a. a \<ge> 0 \<Longrightarrow> abs x = a \<longleftrightarrow> x = a \<or> x = - a" by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5205
  have "?rhs \<longleftrightarrow> norm x *s y = norm y *s x \<or> norm (- x) *s y = norm y *s (- x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5206
    apply (simp add: norm_neg) by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5207
  also have "\<dots> \<longleftrightarrow>(x \<bullet> y = norm x * norm y \<or>
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5208
     (-x) \<bullet> y = norm x * norm y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5209
    unfolding norm_cauchy_schwarz_eq[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5210
    unfolding norm_neg
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5211
      norm_mul by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5212
  also have "\<dots> \<longleftrightarrow> ?lhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5213
    unfolding th[OF mult_nonneg_nonneg, OF norm_pos_le[of x] norm_pos_le[of y]] dot_lneg
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5214
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5215
  finally show ?thesis ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5216
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5217
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5218
lemma norm_triangle_eq: "norm(x + y) = norm x + norm y \<longleftrightarrow> norm x *s y = norm y *s x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5219
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5220
  {assume x: "x =0 \<or> y =0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5221
    hence ?thesis by (cases "x=0", simp_all add: norm_0)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5222
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5223
  {assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5224
    hence "norm x \<noteq> 0" "norm y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5225
      by (simp_all add: norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5226
    hence n: "norm x > 0" "norm y > 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5227
      using norm_pos_le[of x] norm_pos_le[of y]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5228
      by arith+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5229
    have th: "\<And>(a::real) b c. a + b + c \<noteq> 0 ==> (a = b + c \<longleftrightarrow> a^2 = (b + c)^2)" by algebra
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5230
    have "norm(x + y) = norm x + norm y \<longleftrightarrow> norm(x + y)^ 2 = (norm x + norm y) ^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5231
      apply (rule th) using n norm_pos_le[of "x + y"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5232
      by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5233
    also have "\<dots> \<longleftrightarrow> norm x *s y = norm y *s x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5234
      unfolding norm_cauchy_schwarz_eq[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5235
      unfolding norm_pow_2 dot_ladd dot_radd
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5236
      by (simp add: norm_pow_2[symmetric] power2_eq_square dot_sym ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5237
    finally have ?thesis .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5238
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5239
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5240
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5241
(* Collinearity.*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5242
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5243
definition "collinear S \<longleftrightarrow> (\<exists>u. \<forall>x \<in> S. \<forall> y \<in> S. \<exists>c. x - y = c *s u)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5244
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5245
lemma collinear_empty:  "collinear {}" by (simp add: collinear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5246
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5247
lemma collinear_sing: "collinear {(x::'a::ring_1^'n)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5248
  apply (simp add: collinear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5249
  apply (rule exI[where x=0])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5250
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5251
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5252
lemma collinear_2: "collinear {(x::'a::ring_1^'n),y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5253
  apply (simp add: collinear_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5254
  apply (rule exI[where x="x - y"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5255
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5256
  apply (rule exI[where x=0], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5257
  apply (rule exI[where x=1], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5258
  apply (rule exI[where x="- 1"], simp add: vector_sneg_minus1[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5259
  apply (rule exI[where x=0], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5260
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5261
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5262
lemma collinear_lemma: "collinear {(0::real^'n),x,y} \<longleftrightarrow> x = 0 \<or> y = 0 \<or> (\<exists>c. y = c *s x)" (is "?lhs \<longleftrightarrow> ?rhs")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5263
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5264
  {assume "x=0 \<or> y = 0" hence ?thesis 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5265
      by (cases "x = 0", simp_all add: collinear_2 insert_commute)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5266
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5267
  {assume x: "x \<noteq> 0" and y: "y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5268
    {assume h: "?lhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5269
      then obtain u where u: "\<forall> x\<in> {0,x,y}. \<forall>y\<in> {0,x,y}. \<exists>c. x - y = c *s u" unfolding collinear_def by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5270
      from u[rule_format, of x 0] u[rule_format, of y 0]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5271
      obtain cx and cy where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5272
	cx: "x = cx*s u" and cy: "y = cy*s u"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5273
	by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5274
      from cx x have cx0: "cx \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5275
      from cy y have cy0: "cy \<noteq> 0" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5276
      let ?d = "cy / cx"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5277
      from cx cy cx0 have "y = ?d *s x" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5278
	by (simp add: vector_smult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5279
      hence ?rhs using x y by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5280
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5281
    {assume h: "?rhs"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5282
      then obtain c where c: "y = c*s x" using x y by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5283
      have ?lhs unfolding collinear_def c
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5284
	apply (rule exI[where x=x])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5285
	apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5286
	apply (rule exI[where x=0], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5287
	apply (rule exI[where x="- 1"], simp only: vector_smult_lneg vector_smult_lid)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5288
	apply (rule exI[where x= "-c"], simp only: vector_smult_lneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5289
	apply (rule exI[where x=1], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5290
	apply (rule exI[where x=0], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5291
	apply (rule exI[where x="1 - c"], simp add: vector_smult_lneg vector_sub_rdistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5292
	apply (rule exI[where x="c - 1"], simp add: vector_smult_lneg vector_sub_rdistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5293
	apply (rule exI[where x=0], simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5294
	done}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5295
    ultimately have ?thesis by blast}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5296
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5297
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5298
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5299
lemma norm_cauchy_schwarz_equal: "abs(x \<bullet> y) = norm x * norm y \<longleftrightarrow> collinear {(0::real^'n),x,y}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5300
unfolding norm_cauchy_schwarz_abs_eq
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5301
apply (cases "x=0", simp_all add: collinear_2 norm_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5302
apply (cases "y=0", simp_all add: collinear_2 norm_0 insert_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5303
unfolding collinear_lemma
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5304
apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5305
apply (subgoal_tac "norm x \<noteq> 0")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5306
apply (subgoal_tac "norm y \<noteq> 0")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5307
apply (rule iffI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5308
apply (cases "norm x *s y = norm y *s x")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5309
apply (rule exI[where x="(1/norm x) * norm y"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5310
apply (drule sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5311
unfolding vector_smult_assoc[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5312
apply (simp add: vector_smult_assoc field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5313
apply (rule exI[where x="(1/norm x) * - norm y"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5314
apply clarify
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5315
apply (drule sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5316
unfolding vector_smult_assoc[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5317
apply (simp add: vector_smult_assoc field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5318
apply (erule exE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5319
apply (erule ssubst)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5320
unfolding vector_smult_assoc
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5321
unfolding norm_mul
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5322
apply (subgoal_tac "norm x * c = \<bar>c\<bar> * norm x \<or> norm x * c = - \<bar>c\<bar> * norm x")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5323
apply (case_tac "c <= 0", simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5324
apply (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5325
apply (case_tac "c <= 0", simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5326
apply (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5327
apply (simp add: norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5328
apply (simp add: norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5329
done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  5330
30039
7208c88df507 fix real_vector, real_algebra instances
huffman
parents: 29906
diff changeset
  5331
end