src/HOL/Library/Euclidean_Space.thy
author huffman
Fri, 13 Feb 2009 14:41:54 -0800
changeset 29905 26ee9656872a
parent 29881 58f3c48dbbb7
child 29906 80369da39838
permissions -rw-r--r--
add instance for cancel_comm_monoid_add
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
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    43
section{* Basic componentwise operations on vectors. *}
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
29881
58f3c48dbbb7 fix document generation
huffman
parents: 29844
diff changeset
    87
text{* Also the scalar-vector multiplication. FIXME: We should unify this with the scalar multiplication in @{text real_vector} *}
29842
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    88
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    89
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
    90
  where "c *s x = (\<chi> i. c * (x$i))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    91
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    92
text{* Constant Vectors *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    93
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    94
definition "vec x = (\<chi> i. x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    95
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
    96
text{* Dot products. *}
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
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
    99
  "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
   100
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
   101
  by (simp add: dot_def dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   102
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   103
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
   104
  by (simp add: dot_def dimindex_def nat_number)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   105
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   106
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
   107
  by (simp add: dot_def dimindex_def nat_number)
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
section {* A naive proof procedure to lift really trivial arithmetic stuff from the basis of the vector space. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   110
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   111
lemmas Cart_lambda_beta' = Cart_lambda_beta[rule_format]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   112
method_setup vector = {*
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   113
let
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   114
  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
   115
  @{thm setsum_subtractf} RS sym, @{thm setsum_right_distrib}, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   116
  @{thm setsum_left_distrib}, @{thm setsum_negf} RS sym]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   117
  val ss2 = @{simpset} addsimps 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   118
             [@{thm vector_add_def}, @{thm vector_mult_def},  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   119
              @{thm vector_minus_def}, @{thm vector_uminus_def}, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   120
              @{thm vector_one_def}, @{thm vector_zero_def}, @{thm vec_def}, 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   121
              @{thm Cart_lambda_beta'}, @{thm vector_scalar_mult_def}]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   122
 fun vector_arith_tac ths = 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   123
   simp_tac ss1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   124
   THEN' (fn i => rtac @{thm setsum_cong2} i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   125
         ORELSE rtac @{thm setsum_0'} i 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   126
         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
   127
   (* 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
   128
   THEN' asm_full_simp_tac (ss2 addsimps ths)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   129
 in
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   130
  Method.thms_args (Method.SIMPLE_METHOD' o vector_arith_tac)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   131
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   132
*} "Lifts trivial vector statements to real arith statements"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   133
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   134
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
   135
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
   136
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   137
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   138
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   139
text{* Obvious "component-pushing". *}
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_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
   142
  by (vector vec_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
lemma vector_add_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   145
  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
   146
  shows "(x + y)$i = x$i + y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   147
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   148
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   149
lemma vector_minus_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   150
  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
   151
  shows "(x - y)$i = x$i - y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   152
  using i  by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   153
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   154
lemma vector_mult_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   155
  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
   156
  shows "(x * y)$i = x$i * y$i"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   157
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   158
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   159
lemma vector_smult_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   160
  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
   161
  shows "(c *s y)$i = c * (y$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   162
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   163
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   164
lemma vector_uminus_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   165
  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
   166
  shows "(- x)$i = - (x$i)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   167
  using i by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   168
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   169
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
   170
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   171
lemmas vector_component = vec_component vector_add_component vector_mult_component vector_smult_component vector_minus_component vector_uminus_component cond_component 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   172
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   173
subsection {* Some frequently useful arithmetic lemmas over vectors. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   174
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   175
instance "^" :: (semigroup_add,type) semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   176
  apply (intro_classes) by (vector add_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   177
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   178
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   179
instance "^" :: (monoid_add,type) monoid_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   180
  apply (intro_classes) by vector+ 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   181
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   182
instance "^" :: (group_add,type) group_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   183
  apply (intro_classes) by (vector algebra_simps)+ 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   184
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   185
instance "^" :: (ab_semigroup_add,type) ab_semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   186
  apply (intro_classes) by (vector add_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   187
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   188
instance "^" :: (comm_monoid_add,type) comm_monoid_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   189
  apply (intro_classes) by vector
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 "^" :: (ab_group_add,type) ab_group_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   192
  apply (intro_classes) by vector+
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
instance "^" :: (cancel_semigroup_add,type) cancel_semigroup_add 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   195
  apply (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   196
  by (vector Cart_eq)+
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 "^" :: (cancel_ab_semigroup_add,type) cancel_ab_semigroup_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   199
  apply (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   200
  by (vector Cart_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   201
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   202
instance "^" :: (semigroup_mult,type) semigroup_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   203
  apply (intro_classes) by (vector mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   204
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   205
instance "^" :: (monoid_mult,type) monoid_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   206
  apply (intro_classes) by vector+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   207
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   208
instance "^" :: (ab_semigroup_mult,type) ab_semigroup_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   209
  apply (intro_classes) by (vector mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   210
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   211
instance "^" :: (ab_semigroup_idem_mult,type) ab_semigroup_idem_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   212
  apply (intro_classes) by (vector mult_idem)
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 "^" :: (comm_monoid_mult,type) comm_monoid_mult 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   215
  apply (intro_classes) by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   216
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   217
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
   218
  "vector_power x 0 = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   219
  | "vector_power x (Suc n) = x * vector_power x n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   220
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   221
instantiation "^" :: (recpower,type) recpower 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   222
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   223
  definition vec_power_def: "op ^ \<equiv> vector_power"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   224
  instance 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   225
  apply (intro_classes) by (simp_all add: vec_power_def) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   226
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   227
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   228
instance "^" :: (semiring,type) semiring
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   229
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   230
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   231
instance "^" :: (semiring_0,type) semiring_0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   232
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   233
instance "^" :: (semiring_1,type) semiring_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   234
  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
   235
instance "^" :: (comm_semiring,type) comm_semiring
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   236
  apply (intro_classes) by (vector ring_simps)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   237
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   238
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
   239
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
   240
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
   241
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
   242
instance "^" :: (ring,type) ring by (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   243
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
   244
instance "^" :: (comm_semiring_1,type) comm_semiring_1 by (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   245
lemma of_nat_index: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   246
  "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
   247
  apply (induct n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   248
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   249
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   250
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   251
lemma zero_index[simp]: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   252
  "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
   253
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   254
lemma one_index[simp]: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   255
  "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
   256
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   257
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
   258
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   259
  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
   260
  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
   261
  finally show ?thesis by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   262
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   263
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   264
instance "^" :: (semiring_char_0,type) semiring_char_0 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   265
proof (intro_classes) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   266
  fix m n ::nat
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   267
  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
   268
  proof(induct m arbitrary: n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   269
    case 0 thus ?case apply vector 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   270
      apply (induct n,auto simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   271
      using dimindex_ge_1 apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   272
      apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   273
      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
   274
  next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   275
    case (Suc n m)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   276
    thus ?case  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   277
      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
   278
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   279
      apply (simp add: one_plus_of_nat_neq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   280
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   281
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   282
      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
   283
      using  dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   284
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   285
      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
   286
      using dimindex_ge_1 apply simp apply blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   287
      apply (simp add: vector_component one_index of_nat_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   288
      done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   289
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   290
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   291
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   292
instance "^" :: (comm_ring_1,type) comm_ring_1 by intro_classes
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   293
  (* FIXME!!! Why does the axclass package complain here !!*)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   294
(* instance "^" :: (ring_char_0,type) ring_char_0 by intro_classes *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   295
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   296
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
   297
  by (vector mult_assoc)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   298
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
   299
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   300
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
   301
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   302
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
   303
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
   304
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
   305
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   306
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
   307
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
   308
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
   309
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
   310
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
   311
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   312
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   313
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
   314
  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
   315
  using dimindex_ge_1 apply auto done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   316
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   317
subsection{* Properties of the dot product.  *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   318
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   319
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
   320
  by (vector mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   321
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
   322
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   323
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
   324
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   325
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
   326
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   327
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
   328
  by (vector ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   329
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
   330
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
   331
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
   332
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
   333
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
   334
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
   335
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
   336
  by (simp add: dot_def setsum_nonneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   337
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   338
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
   339
using fS fp setsum_nonneg[OF fp]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   340
proof (induct set: finite)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   341
  case empty thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   342
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   343
  case (insert x F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   344
  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
   345
  from insert.hyps Fp setsum_nonneg[OF Fp]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   346
  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
   347
  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
   348
  show ?case by (simp add: h)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   349
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   350
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   351
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
   352
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   353
  {assume f: "finite (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   354
    let ?S = "{Suc 0 .. card (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   355
    have fS: "finite ?S" using f by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   356
    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
   357
    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
   358
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   359
  {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
   360
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   361
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   362
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   363
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
   364
  by (auto simp add: le_less) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   365
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   366
subsection {* Introduce norms, but defer many properties till we get square roots. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   367
text{* FIXME : This is ugly *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   368
defs (overloaded) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   369
  real_of_real_def [code inline, simp]: "real == id"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   370
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   371
instantiation "^" :: ("{times, comm_monoid_add}", type) norm begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   372
definition  real_vector_norm_def: "norm \<equiv> (\<lambda>x. sqrt (real (x \<bullet> x)))" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   373
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   374
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   375
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   376
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   377
subsection{* The collapse of the general concepts to dimention one. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   378
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   379
lemma vector_one: "(x::'a ^1) = (\<chi> i. (x$1))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   380
  by (vector dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   381
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   382
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
   383
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   384
  apply (erule_tac x= "x$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   385
  apply (simp only: vector_one[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   386
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   387
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   388
lemma norm_real: "norm(x::real ^ 1) = abs(x$1)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   389
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   390
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   391
text{* Metric *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   392
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   393
definition dist:: "real ^ 'n \<Rightarrow> real ^ 'n \<Rightarrow> real" where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   394
  "dist x y = norm (x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   395
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   396
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
   397
  using dimindex_ge_1[of "UNIV :: 1 set"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   398
  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
   399
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   400
subsection {* A connectedness or intermediate value lemma with several applications. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   401
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   402
lemma connected_real_lemma:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   403
  fixes f :: "real \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   404
  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
   405
  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
   406
  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
   407
  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
   408
  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
   409
  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
   410
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   411
  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
   412
  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
   413
  have Sub: "\<exists>y. isUb UNIV ?S y" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   414
    apply (rule exI[where x= b])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   415
    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
   416
  from reals_complete[OF Se Sub] obtain l where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   417
    l: "isLub UNIV ?S l"by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   418
  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
   419
    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
   420
    by (metis linorder_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   421
  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
   422
    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
   423
    by (metis linorder_linear not_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   424
    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
   425
    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
   426
    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
   427
    {assume le2: "f l \<in> e2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   428
      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
   429
      hence lap: "l - a > 0" using alb by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   430
      from e2[rule_format, OF le2] obtain e where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   431
	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
   432
      from dst[OF alb e(1)] obtain d where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   433
	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
   434
      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
   435
	apply ferrack by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   436
      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
   437
      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
   438
      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
   439
      moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   440
      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
   441
      ultimately have False using e12 alb d' by auto}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   442
    moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   443
    {assume le1: "f l \<in> e1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   444
    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
   445
      hence blp: "b - l > 0" using alb by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   446
      from e1[rule_format, OF le1] obtain e where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   447
	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
   448
      from dst[OF alb e(1)] obtain d where 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   449
	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
   450
      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
   451
      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
   452
      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
   453
      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
   454
      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
   455
      with l d' have False 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   456
	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
   457
    ultimately show ?thesis using alb by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   458
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   459
29881
58f3c48dbbb7 fix document generation
huffman
parents: 29844
diff changeset
   460
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
   461
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   462
lemma square_bound_lemma: "(x::real) < (1 + x) * (1 + x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   463
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   464
  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
   465
  thus ?thesis by (simp add: ring_simps power2_eq_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   466
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   467
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   468
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
   469
  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
   470
  apply (rule_tac x="s" in exI)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   471
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   472
  apply (erule_tac x=y in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   473
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   474
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   475
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   476
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
   477
  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
   478
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   479
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
   480
  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
   481
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   482
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
   483
  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
   484
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   485
lemma sqrt_even_pow2: assumes n: "even n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   486
  shows "sqrt(2 ^ n) = 2 ^ (n div 2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   487
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   488
  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
   489
    by (auto simp add: nat_number) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   490
  from m  have "sqrt(2 ^ n) = sqrt ((2 ^ m) ^ 2)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   491
    by (simp only: power_mult[symmetric] mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   492
  then show ?thesis  using m by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   493
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   494
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   495
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
   496
  apply (cases "x = 0", simp_all)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   497
  using sqrt_divide_self_eq[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   498
  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
   499
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   500
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   501
text{* Hence derive more interesting properties of the norm. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   502
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   503
lemma norm_0: "norm (0::real ^ 'n) = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   504
  by (simp add: real_vector_norm_def dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   505
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   506
lemma norm_pos_le: "0 <= norm (x::real^'n)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   507
  by (simp add: real_vector_norm_def dot_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   508
lemma norm_neg: " norm(-x) = norm (x:: real ^ 'n)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   509
  by (simp add: real_vector_norm_def dot_lneg dot_rneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   510
lemma norm_sub: "norm(x - y) = norm(y - (x::real ^ 'n))" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   511
  by (metis norm_neg minus_diff_eq)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   512
lemma norm_mul: "norm(a *s x) = abs(a) * norm x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   513
  by (simp add: real_vector_norm_def dot_lmult dot_rmult mult_assoc[symmetric] real_sqrt_mult)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   514
lemma norm_eq_0_dot: "(norm x = 0) \<longleftrightarrow> (x \<bullet> x = (0::real))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   515
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   516
lemma norm_eq_0: "norm x = 0 \<longleftrightarrow> x = (0::real ^ 'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   517
  by (simp add: real_vector_norm_def dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   518
lemma norm_pos_lt: "0 < norm x \<longleftrightarrow> x \<noteq> (0::real ^ 'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   519
  by (metis less_le real_vector_norm_def norm_pos_le norm_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   520
lemma norm_pow_2: "norm x ^ 2 = x \<bullet> x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   521
  by (simp add: real_vector_norm_def dot_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   522
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
   523
lemma norm_le_0: "norm x <= 0 \<longleftrightarrow> x = (0::real ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   524
  by (metis norm_eq_0 norm_pos_le order_antisym) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   525
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
   526
  by vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   527
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
   528
  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
   529
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
   530
  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
   531
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
   532
  by (metis vector_mul_lcancel)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   533
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
   534
  by (metis vector_mul_rcancel)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   535
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
   536
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   537
  {assume "norm x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   538
    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
   539
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   540
  {assume "norm y = 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   541
    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
   542
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   543
  {assume h: "norm x \<noteq> 0" "norm y \<noteq> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   544
    let ?z = "norm y *s x - norm x *s y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   545
    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
   546
    from dot_pos_le[of ?z]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   547
    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
   548
      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
   549
      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
   550
    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
   551
      by (simp add: field_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   552
    hence ?thesis using h by (simp add: power2_eq_square)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   553
  ultimately show ?thesis by metis
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   554
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   555
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   556
lemma norm_abs[simp]: "abs (norm x) = norm (x::real ^'n)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   557
  using norm_pos_le[of x] by (simp add: real_abs_def linorder_linear)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   558
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   559
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
   560
  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
   561
  by (simp add: real_abs_def dot_rneg norm_neg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   562
lemma norm_triangle: "norm(x + y) <= norm x + norm (y::real ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   563
  unfolding real_vector_norm_def
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   564
  apply (rule real_le_lsqrt)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   565
  apply (auto simp add: dot_pos_le real_vector_norm_def[symmetric] norm_pos_le norm_pow_2[symmetric] intro: add_nonneg_nonneg)[1]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   566
  apply (auto simp add: dot_pos_le real_vector_norm_def[symmetric] norm_pos_le norm_pow_2[symmetric] intro: add_nonneg_nonneg)[1]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   567
  apply (simp add: dot_ladd dot_radd dot_sym )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   568
    by (simp add: norm_pow_2[symmetric] power2_eq_square ring_simps norm_cauchy_schwarz)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   569
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   570
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
   571
  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
   572
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
   573
  by (metis order_trans norm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   574
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
   575
  by (metis basic_trans_rules(21) norm_triangle)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   576
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   577
lemma setsum_delta: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   578
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   579
  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
   580
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   581
  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
   582
  {assume a: "a \<notin> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   583
    hence "\<forall> k\<in> S. ?f k = 0" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   584
    hence ?thesis  using a by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   585
  moreover 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   586
  {assume a: "a \<in> S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   587
    let ?A = "S - {a}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   588
    let ?B = "{a}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   589
    have eq: "S = ?A \<union> ?B" using a by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   590
    have dj: "?A \<inter> ?B = {}" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   591
    from fS have fAB: "finite ?A" "finite ?B" by auto  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   592
    have "setsum ?f S = setsum ?f ?A + setsum ?f ?B"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   593
      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
   594
      by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   595
    then have ?thesis  using a by simp}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   596
  ultimately show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   597
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   598
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   599
lemma component_le_norm: "i \<in> {1 .. dimindex(UNIV :: 'n set)} ==> \<bar>x$i\<bar> <= norm (x::real ^ 'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   600
proof(simp add: real_vector_norm_def, rule real_le_rsqrt, clarsimp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   601
  assume i: "Suc 0 \<le> i" "i \<le> dimindex (UNIV :: 'n set)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   602
  let ?S = "{1 .. dimindex(UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   603
  let ?f = "(\<lambda>k. if k = i then x$i ^2 else 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   604
  have fS: "finite ?S" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   605
  from i setsum_delta[OF fS, of i "\<lambda>k. x$i ^ 2"]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   606
  have th: "x$i^2 = setsum ?f ?S" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   607
  let ?g = "\<lambda>k. x$k * x$k"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   608
  {fix x assume x: "x \<in> ?S" have "?f x \<le> ?g x" by (simp add: power2_eq_square)}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   609
  with setsum_mono[of ?S ?f ?g] 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   610
  have "setsum ?f ?S \<le> setsum ?g ?S" by blast 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   611
  then show "x$i ^2 \<le> x \<bullet> (x:: real ^ 'n)" unfolding dot_def th[symmetric] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   612
qed    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   613
lemma norm_bound_component_le: "norm(x::real ^ 'n) <= e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   614
                ==> \<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
   615
  by (metis component_le_norm order_trans)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   616
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   617
lemma norm_bound_component_lt: "norm(x::real ^ 'n) < e
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   618
                ==> \<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
   619
  by (metis component_le_norm basic_trans_rules(21))
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   620
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   621
lemma norm_le_l1: "norm (x:: real ^'n) <= setsum(\<lambda>i. \<bar>x$i\<bar>) {1..dimindex(UNIV::'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   622
proof (simp add: real_vector_norm_def, rule real_le_lsqrt,simp add: dot_pos_le, simp add: setsum_mono, simp add: dot_def, induct "dimindex(UNIV::'n set)")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   623
  case 0 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   624
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   625
  case (Suc n)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   626
  have th: "2 * (\<bar>x$(Suc n)\<bar> * (\<Sum>i = Suc 0..n. \<bar>x$i\<bar>)) \<ge> 0" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   627
    apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   628
    apply (rule mult_nonneg_nonneg)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   629
    by (simp_all add: setsum_abs_ge_zero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   630
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   631
  from Suc
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   632
  show ?case using th by (simp add: power2_eq_square ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   633
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   634
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   635
lemma real_abs_norm: "\<bar> norm x\<bar> = norm (x :: real ^'n)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   636
  by (simp add: norm_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   637
lemma real_abs_sub_norm: "\<bar>norm(x::real ^'n) - norm y\<bar> <= norm(x - y)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   638
  apply (simp add: abs_le_iff ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   639
  by (metis norm_triangle_sub norm_sub)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   640
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
   641
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   642
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
   643
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   644
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
   645
  by (simp add: order_eq_iff norm_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   646
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
   647
  by (simp add: real_vector_norm_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   648
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   649
text{* Squaring equations and inequalities involving norms.  *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   650
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   651
lemma dot_square_norm: "x \<bullet> x = norm(x)^2"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   652
  by (simp add: real_vector_norm_def  dot_pos_le )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   653
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   654
lemma norm_eq_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
   655
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   656
  have th: "\<And>x y::real. x^2 = y^2 \<longleftrightarrow> x = y \<or> x = -y" by algebra
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   657
  show ?thesis using norm_pos_le[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   658
  apply (simp add: dot_square_norm th)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   659
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   660
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   661
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   662
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   663
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
   664
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   665
  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
   666
  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
   667
finally show ?thesis ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   668
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   669
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   670
lemma norm_le_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
   671
  using norm_pos_le[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   672
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   673
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   674
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   675
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   676
lemma norm_ge_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
   677
  using norm_pos_le[of x]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   678
  apply (simp add: dot_square_norm real_abs_le_square_iff[symmetric])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   679
  apply arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   680
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   681
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   682
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
   683
  by (metis not_le norm_ge_square)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   684
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
   685
  by (metis norm_le_square not_less)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   686
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   687
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
   688
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   689
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
   690
  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
   691
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   692
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
   693
  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
   694
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   695
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   696
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
   697
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   698
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
   699
proof
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   700
  assume "?lhs" then show ?rhs by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   701
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   702
  assume ?rhs
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   703
  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
   704
  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
   705
    by (simp add: dot_rsub dot_lsub dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   706
  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
   707
  then show "x = y" by (simp add: dot_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   708
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   709
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
subsection{* General linear decision procedure for normed spaces. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   712
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   713
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
   714
  apply (clarsimp simp add: norm_mul)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   715
  apply (rule mult_mono1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   716
  apply simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   717
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   718
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   719
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
   720
  apply (rule norm_triangle_le) by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   721
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   722
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
   723
  by (simp add: ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   724
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   725
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
   726
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
   727
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
   728
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
   729
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
   730
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
   731
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
   732
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
   733
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
   734
  "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
   735
  "(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
   736
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
   737
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
   738
  "(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
   739
  "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
   740
  "(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
   741
  by ((atomize (full)), vector)+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   742
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
   743
  "(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
   744
  "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
   745
  "(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
   746
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
   747
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   748
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
   749
  by (atomize) (auto simp add: norm_pos_le)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   750
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   751
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
   752
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   753
lemma norm_pths: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   754
  "(x::real ^'n) = y \<longleftrightarrow> norm (x - y) \<le> 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   755
  "x \<noteq> y \<longleftrightarrow> \<not> (norm (x - y) \<le> 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   756
  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
   757
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   758
use "normarith.ML"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   759
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   760
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
   761
*} "Proves simple linear statements about vector norms"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   762
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   763
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   764
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   765
text{* Hence more metric properties. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   766
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   767
lemma dist_refl: "dist x x = 0" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   768
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   769
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
   770
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   771
lemma dist_pos_le: "0 <= dist x y" by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   772
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   773
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
   774
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   775
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
   776
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   777
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
   778
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   779
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
   780
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
   781
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   782
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
   783
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   784
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
   785
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   786
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
   787
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   788
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
   789
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   790
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
   791
  by norm 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   792
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   793
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
   794
  unfolding dist_def vector_ssub_ldistrib[symmetric] norm_mul .. 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   795
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   796
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
   797
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   798
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
   799
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   800
instantiation "^" :: (monoid_add,type) monoid_add
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   801
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   802
  instance by (intro_classes)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   803
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   804
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   805
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
   806
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   807
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   808
  apply (cases "finite S")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   809
  apply (rule finite_induct[of S])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   810
  apply (auto simp add: vector_component zero_index)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   811
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   812
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   813
lemma setsum_clauses: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   814
  shows "setsum f {} = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   815
  and "finite S \<Longrightarrow> setsum f (insert x S) =
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   816
                 (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
   817
  by (auto simp add: insert_absorb)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   818
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   819
lemma setsum_cmul: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   820
  fixes f:: "'c \<Rightarrow> ('a::semiring_1)^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   821
  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
   822
  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
   823
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   824
lemma setsum_component: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   825
  fixes f:: " 'a \<Rightarrow> ('b::semiring_1) ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   826
  assumes i: "i \<in> {1 .. dimindex(UNIV:: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   827
  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
   828
  using i by (simp add: setsum_eq Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   829
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   830
  (* This needs finiteness assumption due to the definition of fold!!! *)
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 setsum_superset:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   833
  assumes fb: "finite B" and ab: "A \<subseteq> B" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   834
  and f0: "\<forall>x \<in> B - A. f x = 0"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   835
  shows "setsum f B = setsum f A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   836
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   837
  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
   838
  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
   839
  have d: "A \<inter> (B - A) = {}" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   840
  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
   841
  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
   842
    setsum_0'[OF f0]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   843
  show "setsum f B = setsum f A" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   844
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   845
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   846
lemma setsum_restrict_set:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   847
  assumes fA: "finite A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   848
  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
   849
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   850
  from fA have fab: "finite (A \<inter> B)" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   851
  have aba: "A \<inter> B \<subseteq> A" by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   852
  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
   853
  from setsum_superset[OF fA aba, of ?g]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   854
  show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   855
qed
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 setsum_cases:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   858
  assumes fA: "finite A"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   859
  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
   860
         setsum f (A \<inter> B) + setsum g (A \<inter> - B)"
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 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
   863
    by blast+
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   864
  from fA 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   865
  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
   866
  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
   867
  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
   868
  show ?thesis by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   869
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   870
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   871
lemma setsum_norm: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   872
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   873
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   874
  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
   875
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   876
  case 1 thus ?case by (simp add: norm_zero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   877
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   878
  case (2 x S)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   879
  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
   880
  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
   881
    using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   882
  finally  show ?case  using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   883
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   884
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   885
lemma real_setsum_norm: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   886
  fixes f :: "'a \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   887
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   888
  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
   889
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   890
  case 1 thus ?case by simp norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   891
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   892
  case (2 x S)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   893
  from "2.hyps" have "norm (setsum f (insert x S)) \<le> norm (f x) + norm (setsum f S)" apply (simp add: norm_triangle_ineq) by norm
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   894
  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
   895
    using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   896
  finally  show ?case  using "2.hyps" by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   897
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   898
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   899
lemma setsum_norm_le: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   900
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   901
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   902
  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
   903
  shows "norm (setsum f S) \<le> setsum g S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   904
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   905
  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
   906
    by - (rule setsum_mono, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   907
  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
   908
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   909
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   910
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   911
lemma real_setsum_norm_le: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   912
  fixes f :: "'a \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   913
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   914
  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
   915
  shows "norm (setsum f S) \<le> setsum g S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   916
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   917
  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
   918
    by - (rule setsum_mono, simp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   919
  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
   920
    by arith
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   921
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   922
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   923
lemma setsum_norm_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   924
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   925
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   926
  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
   927
  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
   928
  using setsum_norm_le[OF fS K] setsum_constant[symmetric]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   929
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   930
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   931
lemma real_setsum_norm_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   932
  fixes f :: "'a \<Rightarrow> real ^ 'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   933
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   934
  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
   935
  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
   936
  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
   937
  by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   938
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   939
instantiation "^" :: ("{scaleR, one, times}",type) scaleR
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   940
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   941
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   942
definition vector_scaleR_def: "(scaleR :: real \<Rightarrow> 'a ^'b \<Rightarrow> 'a ^'b) \<equiv> (\<lambda> c x . (scaleR c 1) *s x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   943
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   944
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   945
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   946
instantiation "^" :: ("ring_1",type) ring_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   947
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   948
instance by intro_classes
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   949
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   950
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   951
instantiation "^" :: (real_algebra_1,type) real_vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   952
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   953
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   954
instance
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   955
  apply intro_classes
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   956
  apply (simp_all  add: vector_scaleR_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   957
  apply (simp_all add: vector_sadd_rdistrib vector_add_ldistrib vector_smult_lid vector_smult_assoc scaleR_left_distrib mult_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   958
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   959
end
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
instantiation "^" :: (real_algebra_1,type) real_algebra
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   962
begin
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
instance
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   965
  apply intro_classes
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   966
  apply (simp_all add: vector_scaleR_def ring_simps)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   967
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   968
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   969
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   970
end
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
instantiation "^" :: (real_algebra_1,type) real_algebra_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   973
begin
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   974
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   975
instance ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   976
end
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   977
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   978
lemma setsum_vmul:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   979
  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
   980
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   981
  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
   982
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   983
  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
   984
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   985
  case (2 x F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   986
  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
   987
    by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   988
  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
   989
    by (simp add: vector_sadd_rdistrib)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   990
  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
   991
  finally show ?case .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   992
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   993
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   994
(* 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
   995
 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
   996
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
   997
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
   998
  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
   999
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1000
  let ?A = "{m .. n}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1001
  let ?B = "{n + 1 .. n + p}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1002
  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
  1003
  have d: "?A \<inter> ?B = {}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1004
  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
  1005
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1006
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1007
lemma setsum_reindex_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1008
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1009
  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
  1010
  shows "setsum h (f ` S) = setsum (h o f) S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1011
using nz
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1012
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1013
  case 1 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1014
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1015
  case (2 x F) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1016
  {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
  1017
    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
  1018
    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
  1019
    
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1020
    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
  1021
    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
  1022
    also have "\<dots> = setsum (h o f) (insert x F)" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1023
      using "2.hyps" "2.prems" h0  by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1024
    finally have ?case .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1025
  moreover
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1026
  {assume fxF: "f x \<notin> f ` F"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1027
    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
  1028
      using fxF "2.hyps" by simp 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1029
    also have "\<dots> = setsum (h o f) (insert x F)"  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1030
      using "2.hyps" "2.prems" fxF
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1031
      apply auto apply metis done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1032
    finally have ?case .}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1033
  ultimately show ?case by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1034
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1035
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1036
lemma setsum_Un_nonzero:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1037
  assumes fS: "finite S" and fF: "finite F"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1038
  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
  1039
  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
  1040
  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
  1041
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1042
lemma setsum_natinterval_left:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1043
  assumes mn: "(m::nat) <= n" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1044
  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
  1045
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1046
  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
  1047
  then show ?thesis by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1048
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1049
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1050
lemma setsum_natinterval_difff: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1051
  fixes f:: "nat \<Rightarrow> ('a::ab_group_add)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1052
  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
  1053
          (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
  1054
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
  1055
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1056
lemmas setsum_restrict_set' = setsum_restrict_set[unfolded Int_def]
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1057
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1058
lemma setsum_setsum_restrict:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1059
  "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
  1060
  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
  1061
  by (rule setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1062
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1063
lemma setsum_image_gen: assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1064
  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
  1065
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1066
  {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
  1067
  note th0 = this
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1068
  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
  1069
    apply (rule setsum_cong2) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1070
    by (simp add: th0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1071
  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
  1072
    apply (rule setsum_setsum_restrict[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1073
    by (rule finite_imageI[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1074
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1075
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1076
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1077
    (* FIXME: Here too need stupid finiteness assumption on T!!! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1078
lemma setsum_group:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1079
  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
  1080
  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
  1081
  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1082
apply (subst setsum_image_gen[OF fS, of g f])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1083
apply (rule setsum_superset[OF fT fST])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1084
by (auto intro: setsum_0')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1085
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1086
(* FIXME: Change the name to fold_image\<dots> *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1087
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
  1088
  apply (induct set: finite)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1089
  apply simp by (auto simp add: fold_image_insert)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1090
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1091
lemma (in comm_monoid_mult) fold_union_nonzero:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1092
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1093
  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
  1094
  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
  1095
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1096
  have "fold_image op * f 1 (S \<inter> T) = 1" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1097
    apply (rule fold_1')
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1098
    using fS fT I0 by auto 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1099
  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
  1100
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1101
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1102
lemma setsum_union_nonzero:  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1103
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1104
  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
  1105
  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
  1106
  using fS fT
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1107
  apply (simp add: setsum_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1108
  apply (rule comm_monoid_add.fold_union_nonzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1109
  using I0 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1110
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1111
lemma setprod_union_nonzero:  
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1112
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1113
  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
  1114
  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
  1115
  using fS fT
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1116
  apply (simp add: setprod_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1117
  apply (rule fold_union_nonzero)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1118
  using I0 by auto
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_unions_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1121
  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
  1122
  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
  1123
  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
  1124
  using fSS f0
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1125
proof(induct rule: finite_induct[OF fS])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1126
  case 1 thus ?case by simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1127
next
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1128
  case (2 T F)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1129
  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
  1130
    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
  1131
  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
  1132
  from "2.prems" TF fTF
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1133
  show ?case 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1134
    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
  1135
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1136
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1137
  (* FIXME : Copied from Pocklington --- should be moved to Finite_Set!!!!!!!! *)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1138
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1139
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1140
lemma (in comm_monoid_mult) fold_related: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1141
  assumes Re: "R e e" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1142
  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
  1143
  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
  1144
  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
  1145
  using fS by (rule finite_subset_induct) (insert assms, auto)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1146
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1147
  (* 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
  1148
lemma (in comm_monoid_mult) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1149
  fold_eq_general:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1150
  assumes fS: "finite S"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1151
  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
  1152
  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
  1153
  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
  1154
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1155
  from h f12 have hS: "h ` S = S'" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1156
  {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
  1157
    from f12 h H  have "x = y" by auto }
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1158
  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
  1159
  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
  1160
  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
  1161
  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
  1162
    using fold_image_reindex[OF fS hinj, of f2 e] .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1163
  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
  1164
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1165
  finally show ?thesis ..
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1166
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1167
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1168
lemma (in comm_monoid_mult) fold_eq_general_inverses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1169
  assumes fS: "finite S" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1170
  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
  1171
  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
  1172
  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
  1173
  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
  1174
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1175
lemma setsum_eq_general_reverses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1176
  assumes fS: "finite S" and fT: "finite T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1177
  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
  1178
  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
  1179
  shows "setsum f S = setsum g T"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1180
  apply (simp add: setsum_def fS fT)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1181
  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
  1182
  apply (erule kh)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1183
  apply (erule hk)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1184
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1185
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1186
lemma vsum_norm_allsubsets_bound:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1187
  fixes f:: "'a \<Rightarrow> real ^'n"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1188
  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
  1189
  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
  1190
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1191
  let ?d = "real (dimindex (UNIV ::'n set))"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1192
  let ?nf = "\<lambda>x. norm (f x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1193
  let ?U = "{1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1194
  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
  1195
    by (rule setsum_commute)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1196
  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
  1197
  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
  1198
    apply (rule setsum_mono)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1199
    by (rule norm_le_l1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1200
  also have "\<dots> \<le> 2 * ?d * e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1201
    unfolding th0 th1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1202
  proof(rule setsum_bounded)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1203
    fix i assume i: "i \<in> ?U"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1204
    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
  1205
    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
  1206
    have thp: "P = ?Pp \<union> ?Pn" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1207
    have thp0: "?Pp \<inter> ?Pn ={}" by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1208
    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
  1209
    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
  1210
      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
  1211
      by (auto simp add: setsum_component intro: abs_le_D1)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1212
    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
  1213
      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
  1214
      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
  1215
    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
  1216
      apply (subst thp)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1217
      apply (rule setsum_Un_nonzero) 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1218
      using fP thp0 by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1219
    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
  1220
    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
  1221
  qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1222
  finally show ?thesis .
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1223
qed
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1224
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1225
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
  1226
  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
  1227
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1228
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
  1229
  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
  1230
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1231
subsection{* Basis vectors in coordinate directions. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1232
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1233
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1234
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
  1235
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1236
lemma delta_mult_idempotent: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1237
  "(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
  1238
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1239
lemma norm_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1240
  assumes k: "k \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1241
  shows "norm (basis k :: real ^'n) = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1242
  using k 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1243
  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
  1244
  apply (vector delta_mult_idempotent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1245
  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
  1246
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1247
  done
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 norm_basis_1: "norm(basis 1 :: real ^'n) = 1"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1250
  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
  1251
  apply (vector delta_mult_idempotent)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1252
  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
  1253
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1254
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1255
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1256
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
  1257
  apply (rule exI[where x="c *s basis 1"])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1258
  by (simp only: norm_mul norm_basis_1)
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 vector_choose_dist: assumes e: "0 <= e" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1261
  shows "\<exists>(y::real^'n). dist x y = e"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1262
proof-
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1263
  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
  1264
    by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1265
  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
  1266
  then show ?thesis by blast
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1267
qed
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 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
  1270
  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
  1271
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1272
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
  1273
  by (simp add: basis_def Cart_lambda_beta)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1274
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1275
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
  1276
  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 basis_expansion:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1279
  "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
  1280
  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
  1281
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1282
lemma basis_expansion_unique: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1283
  "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
  1284
  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
  1285
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1286
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
  1287
  by auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1288
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1289
lemma dot_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1290
  assumes i: "i \<in> {1 .. dimindex (UNIV :: 'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1291
  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
  1292
  using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1293
  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
  1294
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1295
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
  1296
  by (auto simp add: Cart_eq basis_component zero_index)
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 basis_nonzero: 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1299
  assumes k: "k \<in> {1 .. dimindex(UNIV ::'n set)}"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1300
  shows "basis k \<noteq> (0:: 'a::semiring_1 ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1301
  using k by (simp add: basis_eq_0)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1302
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1303
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
  1304
  apply (auto simp add: Cart_eq dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1305
  apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1306
  apply (simp add: dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1307
  apply (subgoal_tac "y = z")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1308
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1309
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1310
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1311
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1312
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
  1313
  apply (auto simp add: Cart_eq dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1314
  apply (erule_tac x="basis i" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1315
  apply (simp add: dot_basis)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1316
  apply (subgoal_tac "x = y")
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1317
  apply simp
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1318
  apply vector
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1319
  done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1320
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1321
subsection{* Orthogonality. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1322
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1323
definition "orthogonal x y \<longleftrightarrow> (x \<bullet> y = 0)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1324
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1325
lemma orthogonal_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1326
  assumes i:"i \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1327
  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
  1328
  using i
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1329
  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
  1330
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1331
lemma orthogonal_basis_basis:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1332
  assumes i:"i \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1333
  and j: "j \<in> {1 .. dimindex(UNIV ::'n set)}" 
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1334
  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
  1335
  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
  1336
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1337
  (* 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
  1338
lemma orthogonal_clauses:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1339
  "orthogonal a (0::'a::comm_ring ^'n)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1340
  "orthogonal a x ==> orthogonal a (c *s x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1341
  "orthogonal a x ==> orthogonal a (-x)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1342
  "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
  1343
  "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
  1344
  "orthogonal 0 a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1345
  "orthogonal x a ==> orthogonal (c *s x) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1346
  "orthogonal x a ==> orthogonal (-x) a"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1347
  "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
  1348
  "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
  1349
  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
  1350
  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
  1351
  by simp_all
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1352
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1353
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
  1354
  by (simp add: orthogonal_def dot_sym)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1355
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1356
subsection{* Explicit vector construction from lists. *}
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1357
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1358
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
  1359
  apply (rule Cart_lambda_beta[rule_format])
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1360
  using dimindex_ge_1 apply auto done
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1361
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1362
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
  1363
  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
  1364
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1365
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
  1366
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1367
lemma vector_1: "(vector[x]) $1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1368
  using dimindex_ge_1
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1369
  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
  1370
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
  1371
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1372
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
  1373
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1374
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
  1375
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1376
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1377
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
  1378
  by (auto simp add: dimindex_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1379
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1380
lemma vector_2:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1381
 "(vector[x,y]) $1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1382
 "(vector[x,y] :: 'a^2)$2 = (y::'a::zero)"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1383
  apply (simp add: vector_def)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1384
  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
  1385
  apply (simp only: vector_def )
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1386
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1387
  done
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
lemma vector_3:
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1390
 "(vector [x,y,z] ::('a::zero)^3)$1 = x"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1391
 "(vector [x,y,z] ::('a::zero)^3)$2 = y"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1392
 "(vector [x,y,z] ::('a::zero)^3)$3 = z"
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1393
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
  1394
  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
  1395
  by simp_all
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 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
  1398
  apply auto
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset
  1399
  apply (erule_tac x="v$1" in allE)
4ac60c7d9b78 (Real) Vectors in Euclidean space, and elementary linear algebra.
chaieb
parents:
diff changeset