src/HOL/Multivariate_Analysis/L2_Norm.thy
author wenzelm
Sun Nov 02 17:09:04 2014 +0100 (2014-11-02)
changeset 58877 262572d90bc6
parent 56536 aefb4a8da31f
child 60420 884f54e01427
permissions -rw-r--r--
modernized header;
wenzelm@41959
     1
(*  Title:      HOL/Multivariate_Analysis/L2_Norm.thy
huffman@36333
     2
    Author:     Brian Huffman, Portland State University
huffman@36333
     3
*)
huffman@36333
     4
wenzelm@58877
     5
section {* Square root of sum of squares *}
huffman@36333
     6
huffman@36333
     7
theory L2_Norm
huffman@36333
     8
imports NthRoot
huffman@36333
     9
begin
huffman@36333
    10
huffman@36333
    11
definition
wenzelm@53015
    12
  "setL2 f A = sqrt (\<Sum>i\<in>A. (f i)\<^sup>2)"
huffman@36333
    13
huffman@36333
    14
lemma setL2_cong:
huffman@36333
    15
  "\<lbrakk>A = B; \<And>x. x \<in> B \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> setL2 f A = setL2 g B"
huffman@36333
    16
  unfolding setL2_def by simp
huffman@36333
    17
huffman@36333
    18
lemma strong_setL2_cong:
huffman@36333
    19
  "\<lbrakk>A = B; \<And>x. x \<in> B =simp=> f x = g x\<rbrakk> \<Longrightarrow> setL2 f A = setL2 g B"
huffman@36333
    20
  unfolding setL2_def simp_implies_def by simp
huffman@36333
    21
huffman@36333
    22
lemma setL2_infinite [simp]: "\<not> finite A \<Longrightarrow> setL2 f A = 0"
huffman@36333
    23
  unfolding setL2_def by simp
huffman@36333
    24
huffman@36333
    25
lemma setL2_empty [simp]: "setL2 f {} = 0"
huffman@36333
    26
  unfolding setL2_def by simp
huffman@36333
    27
huffman@36333
    28
lemma setL2_insert [simp]:
huffman@36333
    29
  "\<lbrakk>finite F; a \<notin> F\<rbrakk> \<Longrightarrow>
wenzelm@53015
    30
    setL2 f (insert a F) = sqrt ((f a)\<^sup>2 + (setL2 f F)\<^sup>2)"
huffman@36333
    31
  unfolding setL2_def by (simp add: setsum_nonneg)
huffman@36333
    32
huffman@36333
    33
lemma setL2_nonneg [simp]: "0 \<le> setL2 f A"
huffman@36333
    34
  unfolding setL2_def by (simp add: setsum_nonneg)
huffman@36333
    35
huffman@36333
    36
lemma setL2_0': "\<forall>a\<in>A. f a = 0 \<Longrightarrow> setL2 f A = 0"
huffman@36333
    37
  unfolding setL2_def by simp
huffman@36333
    38
huffman@36333
    39
lemma setL2_constant: "setL2 (\<lambda>x. y) A = sqrt (of_nat (card A)) * \<bar>y\<bar>"
huffman@36333
    40
  unfolding setL2_def by (simp add: real_sqrt_mult)
huffman@36333
    41
huffman@36333
    42
lemma setL2_mono:
huffman@36333
    43
  assumes "\<And>i. i \<in> K \<Longrightarrow> f i \<le> g i"
huffman@36333
    44
  assumes "\<And>i. i \<in> K \<Longrightarrow> 0 \<le> f i"
huffman@36333
    45
  shows "setL2 f K \<le> setL2 g K"
huffman@36333
    46
  unfolding setL2_def
wenzelm@41891
    47
  by (simp add: setsum_nonneg setsum_mono power_mono assms)
huffman@36333
    48
huffman@36333
    49
lemma setL2_strict_mono:
huffman@36333
    50
  assumes "finite K" and "K \<noteq> {}"
huffman@36333
    51
  assumes "\<And>i. i \<in> K \<Longrightarrow> f i < g i"
huffman@36333
    52
  assumes "\<And>i. i \<in> K \<Longrightarrow> 0 \<le> f i"
huffman@36333
    53
  shows "setL2 f K < setL2 g K"
huffman@36333
    54
  unfolding setL2_def
huffman@36333
    55
  by (simp add: setsum_strict_mono power_strict_mono assms)
huffman@36333
    56
huffman@36333
    57
lemma setL2_right_distrib:
huffman@36333
    58
  "0 \<le> r \<Longrightarrow> r * setL2 f A = setL2 (\<lambda>x. r * f x) A"
huffman@36333
    59
  unfolding setL2_def
huffman@36333
    60
  apply (simp add: power_mult_distrib)
huffman@36333
    61
  apply (simp add: setsum_right_distrib [symmetric])
huffman@36333
    62
  apply (simp add: real_sqrt_mult setsum_nonneg)
huffman@36333
    63
  done
huffman@36333
    64
huffman@36333
    65
lemma setL2_left_distrib:
huffman@36333
    66
  "0 \<le> r \<Longrightarrow> setL2 f A * r = setL2 (\<lambda>x. f x * r) A"
huffman@36333
    67
  unfolding setL2_def
huffman@36333
    68
  apply (simp add: power_mult_distrib)
huffman@36333
    69
  apply (simp add: setsum_left_distrib [symmetric])
huffman@36333
    70
  apply (simp add: real_sqrt_mult setsum_nonneg)
huffman@36333
    71
  done
huffman@36333
    72
huffman@36333
    73
lemma setsum_nonneg_eq_0_iff:
huffman@36333
    74
  fixes f :: "'a \<Rightarrow> 'b::ordered_ab_group_add"
huffman@36333
    75
  shows "\<lbrakk>finite A; \<forall>x\<in>A. 0 \<le> f x\<rbrakk> \<Longrightarrow> setsum f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
huffman@36333
    76
  apply (induct set: finite, simp)
huffman@36333
    77
  apply (simp add: add_nonneg_eq_0_iff setsum_nonneg)
huffman@36333
    78
  done
huffman@36333
    79
huffman@36333
    80
lemma setL2_eq_0_iff: "finite A \<Longrightarrow> setL2 f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
huffman@36333
    81
  unfolding setL2_def
huffman@36333
    82
  by (simp add: setsum_nonneg setsum_nonneg_eq_0_iff)
huffman@36333
    83
huffman@36333
    84
lemma setL2_triangle_ineq:
huffman@36333
    85
  shows "setL2 (\<lambda>i. f i + g i) A \<le> setL2 f A + setL2 g A"
huffman@36333
    86
proof (cases "finite A")
huffman@36333
    87
  case False
huffman@36333
    88
  thus ?thesis by simp
huffman@36333
    89
next
huffman@36333
    90
  case True
huffman@36333
    91
  thus ?thesis
huffman@36333
    92
  proof (induct set: finite)
huffman@36333
    93
    case empty
huffman@36333
    94
    show ?case by simp
huffman@36333
    95
  next
huffman@36333
    96
    case (insert x F)
wenzelm@53015
    97
    hence "sqrt ((f x + g x)\<^sup>2 + (setL2 (\<lambda>i. f i + g i) F)\<^sup>2) \<le>
wenzelm@53015
    98
           sqrt ((f x + g x)\<^sup>2 + (setL2 f F + setL2 g F)\<^sup>2)"
huffman@36333
    99
      by (intro real_sqrt_le_mono add_left_mono power_mono insert
huffman@36333
   100
                setL2_nonneg add_increasing zero_le_power2)
huffman@36333
   101
    also have
wenzelm@53015
   102
      "\<dots> \<le> sqrt ((f x)\<^sup>2 + (setL2 f F)\<^sup>2) + sqrt ((g x)\<^sup>2 + (setL2 g F)\<^sup>2)"
huffman@36333
   103
      by (rule real_sqrt_sum_squares_triangle_ineq)
huffman@36333
   104
    finally show ?case
huffman@36333
   105
      using insert by simp
huffman@36333
   106
  qed
huffman@36333
   107
qed
huffman@36333
   108
huffman@36333
   109
lemma sqrt_sum_squares_le_sum:
wenzelm@53015
   110
  "\<lbrakk>0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> sqrt (x\<^sup>2 + y\<^sup>2) \<le> x + y"
huffman@36333
   111
  apply (rule power2_le_imp_le)
nipkow@56536
   112
  apply (simp add: power2_sum)
huffman@44142
   113
  apply simp
huffman@36333
   114
  done
huffman@36333
   115
huffman@36333
   116
lemma setL2_le_setsum [rule_format]:
huffman@36333
   117
  "(\<forall>i\<in>A. 0 \<le> f i) \<longrightarrow> setL2 f A \<le> setsum f A"
huffman@36333
   118
  apply (cases "finite A")
huffman@36333
   119
  apply (induct set: finite)
huffman@36333
   120
  apply simp
huffman@36333
   121
  apply clarsimp
huffman@36333
   122
  apply (erule order_trans [OF sqrt_sum_squares_le_sum])
huffman@36333
   123
  apply simp
huffman@36333
   124
  apply simp
huffman@36333
   125
  apply simp
huffman@36333
   126
  done
huffman@36333
   127
wenzelm@53015
   128
lemma sqrt_sum_squares_le_sum_abs: "sqrt (x\<^sup>2 + y\<^sup>2) \<le> \<bar>x\<bar> + \<bar>y\<bar>"
huffman@36333
   129
  apply (rule power2_le_imp_le)
nipkow@56536
   130
  apply (simp add: power2_sum)
huffman@44142
   131
  apply simp
huffman@36333
   132
  done
huffman@36333
   133
huffman@36333
   134
lemma setL2_le_setsum_abs: "setL2 f A \<le> (\<Sum>i\<in>A. \<bar>f i\<bar>)"
huffman@36333
   135
  apply (cases "finite A")
huffman@36333
   136
  apply (induct set: finite)
huffman@36333
   137
  apply simp
huffman@36333
   138
  apply simp
huffman@36333
   139
  apply (rule order_trans [OF sqrt_sum_squares_le_sum_abs])
huffman@36333
   140
  apply simp
huffman@36333
   141
  apply simp
huffman@36333
   142
  done
huffman@36333
   143
huffman@36333
   144
lemma setL2_mult_ineq_lemma:
huffman@36333
   145
  fixes a b c d :: real
wenzelm@53015
   146
  shows "2 * (a * c) * (b * d) \<le> a\<^sup>2 * d\<^sup>2 + b\<^sup>2 * c\<^sup>2"
huffman@36333
   147
proof -
wenzelm@53015
   148
  have "0 \<le> (a * d - b * c)\<^sup>2" by simp
wenzelm@53015
   149
  also have "\<dots> = a\<^sup>2 * d\<^sup>2 + b\<^sup>2 * c\<^sup>2 - 2 * (a * d) * (b * c)"
huffman@36333
   150
    by (simp only: power2_diff power_mult_distrib)
wenzelm@53015
   151
  also have "\<dots> = a\<^sup>2 * d\<^sup>2 + b\<^sup>2 * c\<^sup>2 - 2 * (a * c) * (b * d)"
huffman@36333
   152
    by simp
wenzelm@53015
   153
  finally show "2 * (a * c) * (b * d) \<le> a\<^sup>2 * d\<^sup>2 + b\<^sup>2 * c\<^sup>2"
huffman@36333
   154
    by simp
huffman@36333
   155
qed
huffman@36333
   156
huffman@36333
   157
lemma setL2_mult_ineq: "(\<Sum>i\<in>A. \<bar>f i\<bar> * \<bar>g i\<bar>) \<le> setL2 f A * setL2 g A"
huffman@36333
   158
  apply (cases "finite A")
huffman@36333
   159
  apply (induct set: finite)
huffman@36333
   160
  apply simp
huffman@36333
   161
  apply (rule power2_le_imp_le, simp)
huffman@36333
   162
  apply (rule order_trans)
huffman@36333
   163
  apply (rule power_mono)
huffman@36333
   164
  apply (erule add_left_mono)
nipkow@56536
   165
  apply (simp add: setsum_nonneg)
huffman@36333
   166
  apply (simp add: power2_sum)
huffman@36333
   167
  apply (simp add: power_mult_distrib)
webertj@49962
   168
  apply (simp add: distrib_left distrib_right)
huffman@36333
   169
  apply (rule ord_le_eq_trans)
huffman@36333
   170
  apply (rule setL2_mult_ineq_lemma)
nipkow@56536
   171
  apply simp_all
huffman@36333
   172
  done
huffman@36333
   173
huffman@36333
   174
lemma member_le_setL2: "\<lbrakk>finite A; i \<in> A\<rbrakk> \<Longrightarrow> f i \<le> setL2 f A"
huffman@36333
   175
  apply (rule_tac s="insert i (A - {i})" and t="A" in subst)
huffman@36333
   176
  apply fast
huffman@36333
   177
  apply (subst setL2_insert)
huffman@36333
   178
  apply simp
huffman@36333
   179
  apply simp
huffman@36333
   180
  apply simp
huffman@36333
   181
  done
huffman@36333
   182
huffman@36333
   183
end