src/HOL/Hyperreal/FrechetDeriv.thy
author huffman
Tue Dec 12 00:02:54 2006 +0100 (2006-12-12)
changeset 21776 e65109e168f3
child 22720 296813d7d306
permissions -rw-r--r--
theory of Frechet derivatives
huffman@21776
     1
(*  Title       : FrechetDeriv.thy
huffman@21776
     2
    ID          : $Id$
huffman@21776
     3
    Author      : Brian Huffman
huffman@21776
     4
*)
huffman@21776
     5
huffman@21776
     6
header {* Frechet Derivative *}
huffman@21776
     7
huffman@21776
     8
theory FrechetDeriv
huffman@21776
     9
imports Lim
huffman@21776
    10
begin
huffman@21776
    11
huffman@21776
    12
definition
huffman@21776
    13
  fderiv ::
huffman@21776
    14
  "['a::real_normed_vector \<Rightarrow> 'b::real_normed_vector, 'a, 'a \<Rightarrow> 'b] \<Rightarrow> bool"
huffman@21776
    15
    -- {* Frechet derivative: D is derivative of function f at x *}
huffman@21776
    16
          ("(FDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60) where
huffman@21776
    17
  "FDERIV f x :> D = (bounded_linear D \<and>
huffman@21776
    18
    (\<lambda>h. norm (f (x + h) - f x - D h) / norm h) -- 0 --> 0)"
huffman@21776
    19
huffman@21776
    20
lemma FDERIV_I:
huffman@21776
    21
  "\<lbrakk>bounded_linear D; (\<lambda>h. norm (f (x + h) - f x - D h) / norm h) -- 0 --> 0\<rbrakk>
huffman@21776
    22
   \<Longrightarrow> FDERIV f x :> D"
huffman@21776
    23
by (simp add: fderiv_def)
huffman@21776
    24
huffman@21776
    25
lemma FDERIV_D:
huffman@21776
    26
  "FDERIV f x :> D \<Longrightarrow> (\<lambda>h. norm (f (x + h) - f x - D h) / norm h) -- 0 --> 0"
huffman@21776
    27
by (simp add: fderiv_def)
huffman@21776
    28
huffman@21776
    29
lemma FDERIV_bounded_linear: "FDERIV f x :> D \<Longrightarrow> bounded_linear D"
huffman@21776
    30
by (simp add: fderiv_def)
huffman@21776
    31
huffman@21776
    32
lemma bounded_linear_zero:
huffman@21776
    33
  "bounded_linear (\<lambda>x::'a::real_normed_vector. 0::'b::real_normed_vector)"
huffman@21776
    34
proof (unfold_locales)
huffman@21776
    35
  show "(0::'b) = 0 + 0" by simp
huffman@21776
    36
  fix r show "(0::'b) = scaleR r 0" by simp
huffman@21776
    37
  have "\<forall>x::'a. norm (0::'b) \<le> norm x * 0" by simp
huffman@21776
    38
  thus "\<exists>K. \<forall>x::'a. norm (0::'b) \<le> norm x * K" ..
huffman@21776
    39
qed
huffman@21776
    40
huffman@21776
    41
lemma FDERIV_const: "FDERIV (\<lambda>x. k) x :> (\<lambda>h. 0)"
huffman@21776
    42
by (simp add: fderiv_def bounded_linear_zero)
huffman@21776
    43
huffman@21776
    44
lemma bounded_linear_ident:
huffman@21776
    45
  "bounded_linear (\<lambda>x::'a::real_normed_vector. x)"
huffman@21776
    46
proof (unfold_locales)
huffman@21776
    47
  fix x y :: 'a show "x + y = x + y" by simp
huffman@21776
    48
  fix r and x :: 'a show "scaleR r x = scaleR r x" by simp
huffman@21776
    49
  have "\<forall>x::'a. norm x \<le> norm x * 1" by simp
huffman@21776
    50
  thus "\<exists>K. \<forall>x::'a. norm x \<le> norm x * K" ..
huffman@21776
    51
qed
huffman@21776
    52
huffman@21776
    53
lemma FDERIV_ident: "FDERIV (\<lambda>x. x) x :> (\<lambda>h. h)"
huffman@21776
    54
by (simp add: fderiv_def bounded_linear_ident)
huffman@21776
    55
huffman@21776
    56
subsection {* Addition *}
huffman@21776
    57
huffman@21776
    58
lemma add_diff_add:
huffman@21776
    59
  fixes a b c d :: "'a::ab_group_add"
huffman@21776
    60
  shows "(a + c) - (b + d) = (a - b) + (c - d)"
huffman@21776
    61
by simp
huffman@21776
    62
huffman@21776
    63
lemma bounded_linear_add:
huffman@21776
    64
  includes bounded_linear f
huffman@21776
    65
  includes bounded_linear g
huffman@21776
    66
  shows "bounded_linear (\<lambda>x. f x + g x)"
huffman@21776
    67
apply (unfold_locales)
huffman@21776
    68
apply (simp only: f.add g.add add_ac)
huffman@21776
    69
apply (simp only: f.scaleR g.scaleR scaleR_right_distrib)
huffman@21776
    70
apply (rule f.pos_boundedE, rename_tac Kf)
huffman@21776
    71
apply (rule g.pos_boundedE, rename_tac Kg)
huffman@21776
    72
apply (rule_tac x="Kf + Kg" in exI, safe)
huffman@21776
    73
apply (subst right_distrib)
huffman@21776
    74
apply (rule order_trans [OF norm_triangle_ineq])
huffman@21776
    75
apply (rule add_mono, erule spec, erule spec)
huffman@21776
    76
done
huffman@21776
    77
huffman@21776
    78
lemma norm_ratio_ineq:
huffman@21776
    79
  fixes x y :: "'a::real_normed_vector"
huffman@21776
    80
  fixes h :: "'b::real_normed_vector"
huffman@21776
    81
  shows "norm (x + y) / norm h \<le> norm x / norm h + norm y / norm h"
huffman@21776
    82
apply (rule ord_le_eq_trans)
huffman@21776
    83
apply (rule divide_right_mono)
huffman@21776
    84
apply (rule norm_triangle_ineq)
huffman@21776
    85
apply (rule norm_ge_zero)
huffman@21776
    86
apply (rule add_divide_distrib)
huffman@21776
    87
done
huffman@21776
    88
huffman@21776
    89
lemma FDERIV_add:
huffman@21776
    90
  assumes f: "FDERIV f x :> F"
huffman@21776
    91
  assumes g: "FDERIV g x :> G"
huffman@21776
    92
  shows "FDERIV (\<lambda>x. f x + g x) x :> (\<lambda>h. F h + G h)"
huffman@21776
    93
proof (rule FDERIV_I)
huffman@21776
    94
  show "bounded_linear (\<lambda>h. F h + G h)"
huffman@21776
    95
    apply (rule bounded_linear_add)
huffman@21776
    96
    apply (rule FDERIV_bounded_linear [OF f])
huffman@21776
    97
    apply (rule FDERIV_bounded_linear [OF g])
huffman@21776
    98
    done
huffman@21776
    99
next
huffman@21776
   100
  have f': "(\<lambda>h. norm (f (x + h) - f x - F h) / norm h) -- 0 --> 0"
huffman@21776
   101
    using f by (rule FDERIV_D)
huffman@21776
   102
  have g': "(\<lambda>h. norm (g (x + h) - g x - G h) / norm h) -- 0 --> 0"
huffman@21776
   103
    using g by (rule FDERIV_D)
huffman@21776
   104
  from f' g'
huffman@21776
   105
  have "(\<lambda>h. norm (f (x + h) - f x - F h) / norm h
huffman@21776
   106
           + norm (g (x + h) - g x - G h) / norm h) -- 0 --> 0"
huffman@21776
   107
    by (rule LIM_add_zero)
huffman@21776
   108
  thus "(\<lambda>h. norm (f (x + h) + g (x + h) - (f x + g x) - (F h + G h))
huffman@21776
   109
           / norm h) -- 0 --> 0"
huffman@21776
   110
    apply (rule real_LIM_sandwich_zero)
huffman@21776
   111
     apply (simp add: divide_nonneg_pos)
huffman@21776
   112
    apply (simp only: add_diff_add)
huffman@21776
   113
    apply (rule norm_ratio_ineq)
huffman@21776
   114
    done
huffman@21776
   115
qed
huffman@21776
   116
huffman@21776
   117
subsection {* Subtraction *}
huffman@21776
   118
huffman@21776
   119
lemma bounded_linear_minus:
huffman@21776
   120
  includes bounded_linear f
huffman@21776
   121
  shows "bounded_linear (\<lambda>x. - f x)"
huffman@21776
   122
apply (unfold_locales)
huffman@21776
   123
apply (simp add: f.add)
huffman@21776
   124
apply (simp add: f.scaleR)
huffman@21776
   125
apply (simp add: f.bounded)
huffman@21776
   126
done
huffman@21776
   127
huffman@21776
   128
lemma FDERIV_minus:
huffman@21776
   129
  "FDERIV f x :> F \<Longrightarrow> FDERIV (\<lambda>x. - f x) x :> (\<lambda>h. - F h)"
huffman@21776
   130
apply (rule FDERIV_I)
huffman@21776
   131
apply (rule bounded_linear_minus)
huffman@21776
   132
apply (erule FDERIV_bounded_linear)
huffman@21776
   133
apply (simp only: fderiv_def minus_diff_minus norm_minus_cancel)
huffman@21776
   134
done
huffman@21776
   135
huffman@21776
   136
lemma FDERIV_diff:
huffman@21776
   137
  "\<lbrakk>FDERIV f x :> F; FDERIV g x :> G\<rbrakk>
huffman@21776
   138
   \<Longrightarrow> FDERIV (\<lambda>x. f x - g x) x :> (\<lambda>h. F h - G h)"
huffman@21776
   139
by (simp only: diff_minus FDERIV_add FDERIV_minus)
huffman@21776
   140
huffman@21776
   141
subsection {* Continuity *}
huffman@21776
   142
huffman@21776
   143
lemma FDERIV_isCont:
huffman@21776
   144
  assumes f: "FDERIV f x :> F"
huffman@21776
   145
  shows "isCont f x"
huffman@21776
   146
proof -
huffman@21776
   147
  from f interpret F: bounded_linear ["F"] by (rule FDERIV_bounded_linear)
huffman@21776
   148
  have "(\<lambda>h. norm (f (x + h) - f x - F h) / norm h) -- 0 --> 0"
huffman@21776
   149
    by (rule FDERIV_D [OF f])
huffman@21776
   150
  hence "(\<lambda>h. norm (f (x + h) - f x - F h) / norm h * norm h) -- 0 --> 0"
huffman@21776
   151
    by (intro LIM_mult_zero LIM_norm_zero LIM_self)
huffman@21776
   152
  hence "(\<lambda>h. norm (f (x + h) - f x - F h)) -- 0 --> 0"
huffman@21776
   153
    by (simp cong: LIM_cong)
huffman@21776
   154
  hence "(\<lambda>h. f (x + h) - f x - F h) -- 0 --> 0"
huffman@21776
   155
    by (rule LIM_norm_zero_cancel)
huffman@21776
   156
  hence "(\<lambda>h. f (x + h) - f x - F h + F h) -- 0 --> 0"
huffman@21776
   157
    by (intro LIM_add_zero F.LIM_zero LIM_self)
huffman@21776
   158
  hence "(\<lambda>h. f (x + h) - f x) -- 0 --> 0"
huffman@21776
   159
    by simp
huffman@21776
   160
  thus "isCont f x"
huffman@21776
   161
    unfolding isCont_iff by (rule LIM_zero_cancel)
huffman@21776
   162
qed
huffman@21776
   163
huffman@21776
   164
subsection {* Composition *}
huffman@21776
   165
huffman@21776
   166
lemma real_divide_cancel_lemma:
huffman@21776
   167
  fixes a b c :: real
huffman@21776
   168
  shows "(b = 0 \<Longrightarrow> a = 0) \<Longrightarrow> (a / b) * (b / c) = a / c"
huffman@21776
   169
by simp
huffman@21776
   170
huffman@21776
   171
lemma bounded_linear_compose:
huffman@21776
   172
  includes bounded_linear f
huffman@21776
   173
  includes bounded_linear g
huffman@21776
   174
  shows "bounded_linear (\<lambda>x. f (g x))"
huffman@21776
   175
proof (unfold_locales)
huffman@21776
   176
  fix x y show "f (g (x + y)) = f (g x) + f (g y)"
huffman@21776
   177
    by (simp only: f.add g.add)
huffman@21776
   178
next
huffman@21776
   179
  fix r x show "f (g (scaleR r x)) = scaleR r (f (g x))"
huffman@21776
   180
    by (simp only: f.scaleR g.scaleR)
huffman@21776
   181
next
huffman@21776
   182
  from f.pos_bounded
huffman@21776
   183
  obtain Kf where f: "\<And>x. norm (f x) \<le> norm x * Kf" and Kf: "0 < Kf" by fast
huffman@21776
   184
  from g.pos_bounded
huffman@21776
   185
  obtain Kg where g: "\<And>x. norm (g x) \<le> norm x * Kg" by fast
huffman@21776
   186
  show "\<exists>K. \<forall>x. norm (f (g x)) \<le> norm x * K"
huffman@21776
   187
  proof (intro exI allI)
huffman@21776
   188
    fix x
huffman@21776
   189
    have "norm (f (g x)) \<le> norm (g x) * Kf"
huffman@21776
   190
      using f .
huffman@21776
   191
    also have "\<dots> \<le> (norm x * Kg) * Kf"
huffman@21776
   192
      using g Kf [THEN order_less_imp_le] by (rule mult_right_mono)
huffman@21776
   193
    also have "(norm x * Kg) * Kf = norm x * (Kg * Kf)"
huffman@21776
   194
      by (rule mult_assoc)
huffman@21776
   195
    finally show "norm (f (g x)) \<le> norm x * (Kg * Kf)" .
huffman@21776
   196
  qed
huffman@21776
   197
qed
huffman@21776
   198
huffman@21776
   199
lemma FDERIV_compose:
huffman@21776
   200
  fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
huffman@21776
   201
  fixes g :: "'b::real_normed_vector \<Rightarrow> 'c::real_normed_vector"
huffman@21776
   202
  assumes f: "FDERIV f x :> F"
huffman@21776
   203
  assumes g: "FDERIV g (f x) :> G"
huffman@21776
   204
  shows "FDERIV (\<lambda>x. g (f x)) x :> (\<lambda>h. G (F h))"
huffman@21776
   205
proof (rule FDERIV_I)
huffman@21776
   206
  from FDERIV_bounded_linear [OF g] FDERIV_bounded_linear [OF f]
huffman@21776
   207
  show "bounded_linear (\<lambda>h. G (F h))"
huffman@21776
   208
    by (rule bounded_linear_compose)
huffman@21776
   209
next
huffman@21776
   210
  let ?Rf = "\<lambda>h. f (x + h) - f x - F h"
huffman@21776
   211
  let ?Rg = "\<lambda>k. g (f x + k) - g (f x) - G k"
huffman@21776
   212
  let ?k = "\<lambda>h. f (x + h) - f x"
huffman@21776
   213
  let ?Nf = "\<lambda>h. norm (?Rf h) / norm h"
huffman@21776
   214
  let ?Ng = "\<lambda>h. norm (?Rg (?k h)) / norm (?k h)"
huffman@21776
   215
  from f interpret F: bounded_linear ["F"] by (rule FDERIV_bounded_linear)
huffman@21776
   216
  from g interpret G: bounded_linear ["G"] by (rule FDERIV_bounded_linear)
huffman@21776
   217
  from F.bounded obtain kF where kF: "\<And>x. norm (F x) \<le> norm x * kF" by fast
huffman@21776
   218
  from G.bounded obtain kG where kG: "\<And>x. norm (G x) \<le> norm x * kG" by fast
huffman@21776
   219
huffman@21776
   220
  let ?fun2 = "\<lambda>h. ?Nf h * kG + ?Ng h * (?Nf h + kF)"
huffman@21776
   221
huffman@21776
   222
  show "(\<lambda>h. norm (g (f (x + h)) - g (f x) - G (F h)) / norm h) -- 0 --> 0"
huffman@21776
   223
  proof (rule real_LIM_sandwich_zero)
huffman@21776
   224
    have Nf: "?Nf -- 0 --> 0"
huffman@21776
   225
      using FDERIV_D [OF f] .
huffman@21776
   226
huffman@21776
   227
    have Ng1: "isCont (\<lambda>k. norm (?Rg k) / norm k) 0"
huffman@21776
   228
      by (simp add: isCont_def FDERIV_D [OF g])
huffman@21776
   229
    have Ng2: "?k -- 0 --> 0"
huffman@21776
   230
      apply (rule LIM_zero)
huffman@21776
   231
      apply (fold isCont_iff)
huffman@21776
   232
      apply (rule FDERIV_isCont [OF f])
huffman@21776
   233
      done
huffman@21776
   234
    have Ng: "?Ng -- 0 --> 0"
huffman@21776
   235
      using isCont_LIM_compose [OF Ng1 Ng2] by simp
huffman@21776
   236
huffman@21776
   237
    have "(\<lambda>h. ?Nf h * kG + ?Ng h * (?Nf h + kF))
huffman@21776
   238
           -- 0 --> 0 * kG + 0 * (0 + kF)"
huffman@21776
   239
      by (intro LIM_add LIM_mult LIM_const Nf Ng)
huffman@21776
   240
    thus "(\<lambda>h. ?Nf h * kG + ?Ng h * (?Nf h + kF)) -- 0 --> 0"
huffman@21776
   241
      by simp
huffman@21776
   242
  next
huffman@21776
   243
    fix h::'a assume h: "h \<noteq> 0"
huffman@21776
   244
    thus "0 \<le> norm (g (f (x + h)) - g (f x) - G (F h)) / norm h"
huffman@21776
   245
      by (simp add: divide_nonneg_pos)
huffman@21776
   246
  next
huffman@21776
   247
    fix h::'a assume h: "h \<noteq> 0"
huffman@21776
   248
    have "g (f (x + h)) - g (f x) - G (F h) = G (?Rf h) + ?Rg (?k h)"
huffman@21776
   249
      by (simp add: G.diff)
huffman@21776
   250
    hence "norm (g (f (x + h)) - g (f x) - G (F h)) / norm h
huffman@21776
   251
           = norm (G (?Rf h) + ?Rg (?k h)) / norm h"
huffman@21776
   252
      by (rule arg_cong)
huffman@21776
   253
    also have "\<dots> \<le> norm (G (?Rf h)) / norm h + norm (?Rg (?k h)) / norm h"
huffman@21776
   254
      by (rule norm_ratio_ineq)
huffman@21776
   255
    also have "\<dots> \<le> ?Nf h * kG + ?Ng h * (?Nf h + kF)"
huffman@21776
   256
    proof (rule add_mono)
huffman@21776
   257
      show "norm (G (?Rf h)) / norm h \<le> ?Nf h * kG"
huffman@21776
   258
        apply (rule ord_le_eq_trans)
huffman@21776
   259
        apply (rule divide_right_mono [OF kG norm_ge_zero])
huffman@21776
   260
        apply simp
huffman@21776
   261
        done
huffman@21776
   262
    next
huffman@21776
   263
      have "norm (?Rg (?k h)) / norm h = ?Ng h * (norm (?k h) / norm h)"
huffman@21776
   264
        apply (rule real_divide_cancel_lemma [symmetric])
huffman@21776
   265
        apply (simp add: G.zero)
huffman@21776
   266
        done
huffman@21776
   267
      also have "\<dots> \<le> ?Ng h * (?Nf h + kF)"
huffman@21776
   268
      proof (rule mult_left_mono)
huffman@21776
   269
        have "norm (?k h) / norm h = norm (?Rf h + F h) / norm h"
huffman@21776
   270
          by simp
huffman@21776
   271
        also have "\<dots> \<le> ?Nf h + norm (F h) / norm h"
huffman@21776
   272
          by (rule norm_ratio_ineq)
huffman@21776
   273
        also have "\<dots> \<le> ?Nf h + kF"
huffman@21776
   274
          apply (rule add_left_mono)
huffman@21776
   275
          apply (subst pos_divide_le_eq, simp add: h)
huffman@21776
   276
          apply (subst mult_commute)
huffman@21776
   277
          apply (rule kF)
huffman@21776
   278
          done
huffman@21776
   279
        finally show "norm (?k h) / norm h \<le> ?Nf h + kF" .
huffman@21776
   280
      next
huffman@21776
   281
        show "0 \<le> ?Ng h"
huffman@21776
   282
        apply (case_tac "f (x + h) - f x = 0", simp)
huffman@21776
   283
        apply (rule divide_nonneg_pos [OF norm_ge_zero])
huffman@21776
   284
        apply simp
huffman@21776
   285
        done
huffman@21776
   286
      qed
huffman@21776
   287
      finally show "norm (?Rg (?k h)) / norm h \<le> ?Ng h * (?Nf h + kF)" .
huffman@21776
   288
    qed
huffman@21776
   289
    finally show "norm (g (f (x + h)) - g (f x) - G (F h)) / norm h
huffman@21776
   290
        \<le> ?Nf h * kG + ?Ng h * (?Nf h + kF)" .
huffman@21776
   291
  qed
huffman@21776
   292
qed
huffman@21776
   293
huffman@21776
   294
subsection {* Product Rule *}
huffman@21776
   295
huffman@21776
   296
lemma (in bounded_bilinear) FDERIV_lemma:
huffman@21776
   297
  "a' ** b' - a ** b - (a ** B + A ** b)
huffman@21776
   298
   = a ** (b' - b - B) + (a' - a - A) ** b' + A ** (b' - b)"
huffman@21776
   299
by (simp add: diff_left diff_right)
huffman@21776
   300
huffman@21776
   301
lemma (in bounded_bilinear) FDERIV:
huffman@21776
   302
  fixes x :: "'d::real_normed_vector"
huffman@21776
   303
  assumes f: "FDERIV f x :> F"
huffman@21776
   304
  assumes g: "FDERIV g x :> G"
huffman@21776
   305
  shows "FDERIV (\<lambda>x. f x ** g x) x :> (\<lambda>h. f x ** G h + F h ** g x)"
huffman@21776
   306
proof (rule FDERIV_I)
huffman@21776
   307
  show "bounded_linear (\<lambda>h. f x ** G h + F h ** g x)"
huffman@21776
   308
    apply (rule bounded_linear_add)
huffman@21776
   309
    apply (rule bounded_linear_compose [OF bounded_linear_right])
huffman@21776
   310
    apply (rule FDERIV_bounded_linear [OF g])
huffman@21776
   311
    apply (rule bounded_linear_compose [OF bounded_linear_left])
huffman@21776
   312
    apply (rule FDERIV_bounded_linear [OF f])
huffman@21776
   313
    done
huffman@21776
   314
next
huffman@21776
   315
  from bounded_linear.bounded [OF FDERIV_bounded_linear [OF f]]
huffman@21776
   316
  obtain KF where norm_F: "\<And>x. norm (F x) \<le> norm x * KF" by fast
huffman@21776
   317
huffman@21776
   318
  from pos_bounded obtain K where K: "0 < K" and norm_prod:
huffman@21776
   319
    "\<And>a b. norm (a ** b) \<le> norm a * norm b * K" by fast
huffman@21776
   320
huffman@21776
   321
  let ?Rf = "\<lambda>h. f (x + h) - f x - F h"
huffman@21776
   322
  let ?Rg = "\<lambda>h. g (x + h) - g x - G h"
huffman@21776
   323
huffman@21776
   324
  let ?fun1 = "\<lambda>h.
huffman@21776
   325
        norm (f x ** ?Rg h + ?Rf h ** g (x + h) + F h ** (g (x + h) - g x)) /
huffman@21776
   326
        norm h"
huffman@21776
   327
huffman@21776
   328
  let ?fun2 = "\<lambda>h.
huffman@21776
   329
        norm (f x) * (norm (?Rg h) / norm h) * K +
huffman@21776
   330
        norm (?Rf h) / norm h * norm (g (x + h)) * K +
huffman@21776
   331
        KF * norm (g (x + h) - g x) * K"
huffman@21776
   332
huffman@21776
   333
  have "?fun1 -- 0 --> 0"
huffman@21776
   334
  proof (rule real_LIM_sandwich_zero)
huffman@21776
   335
    from f g isCont_iff [THEN iffD1, OF FDERIV_isCont [OF g]]
huffman@21776
   336
    have "?fun2 -- 0 -->
huffman@21776
   337
          norm (f x) * 0 * K + 0 * norm (g x) * K + KF * norm (0::'b) * K"
huffman@21776
   338
      by (intro LIM_add LIM_mult LIM_const LIM_norm LIM_zero FDERIV_D)
huffman@21776
   339
    thus "?fun2 -- 0 --> 0"
huffman@21776
   340
      by simp
huffman@21776
   341
  next
huffman@21776
   342
    fix h::'d assume "h \<noteq> 0"
huffman@21776
   343
    thus "0 \<le> ?fun1 h"
huffman@21776
   344
      by (simp add: divide_nonneg_pos)
huffman@21776
   345
  next
huffman@21776
   346
    fix h::'d assume "h \<noteq> 0"
huffman@21776
   347
    have "?fun1 h \<le> (norm (f x) * norm (?Rg h) * K +
huffman@21776
   348
         norm (?Rf h) * norm (g (x + h)) * K +
huffman@21776
   349
         norm h * KF * norm (g (x + h) - g x) * K) / norm h"
huffman@21776
   350
      by (intro
huffman@21776
   351
        divide_right_mono mult_mono'
huffman@21776
   352
        order_trans [OF norm_triangle_ineq add_mono]
huffman@21776
   353
        order_trans [OF norm_prod mult_right_mono]
huffman@21776
   354
        mult_nonneg_nonneg order_refl norm_ge_zero norm_F
huffman@21776
   355
        K [THEN order_less_imp_le]
huffman@21776
   356
      )
huffman@21776
   357
    also have "\<dots> = ?fun2 h"
huffman@21776
   358
      by (simp add: add_divide_distrib)
huffman@21776
   359
    finally show "?fun1 h \<le> ?fun2 h" .
huffman@21776
   360
  qed
huffman@21776
   361
  thus "(\<lambda>h.
huffman@21776
   362
    norm (f (x + h) ** g (x + h) - f x ** g x - (f x ** G h + F h ** g x))
huffman@21776
   363
    / norm h) -- 0 --> 0"
huffman@21776
   364
    by (simp only: FDERIV_lemma)
huffman@21776
   365
qed
huffman@21776
   366
huffman@21776
   367
lemmas FDERIV_mult = bounded_bilinear_mult.FDERIV
huffman@21776
   368
huffman@21776
   369
lemmas FDERIV_scaleR = bounded_bilinear_scaleR.FDERIV
huffman@21776
   370
huffman@21776
   371
subsection {* Powers *}
huffman@21776
   372
huffman@21776
   373
lemma FDERIV_power_Suc:
huffman@21776
   374
  fixes x :: "'a::{real_normed_algebra,recpower,comm_ring_1}"
huffman@21776
   375
  shows "FDERIV (\<lambda>x. x ^ Suc n) x :> (\<lambda>h. (of_nat n + 1) * x ^ n * h)"
huffman@21776
   376
 apply (induct n)
huffman@21776
   377
  apply (simp add: power_Suc FDERIV_ident)
huffman@21776
   378
 apply (drule FDERIV_mult [OF FDERIV_ident])
huffman@21776
   379
 apply (simp only: of_nat_Suc left_distrib mult_left_one)
huffman@21776
   380
 apply (simp only: power_Suc right_distrib mult_ac)
huffman@21776
   381
done
huffman@21776
   382
huffman@21776
   383
lemma FDERIV_power:
huffman@21776
   384
  fixes x :: "'a::{real_normed_algebra,recpower,comm_ring_1}"
huffman@21776
   385
  shows "FDERIV (\<lambda>x. x ^ n) x :> (\<lambda>h. of_nat n * x ^ (n - 1) * h)"
huffman@21776
   386
by (cases n, simp add: FDERIV_const, simp add: FDERIV_power_Suc)
huffman@21776
   387
huffman@21776
   388
subsection {* Inverse *}
huffman@21776
   389
huffman@21776
   390
lemma inverse_diff_inverse:
huffman@21776
   391
  "\<lbrakk>(a::'a::division_ring) \<noteq> 0; b \<noteq> 0\<rbrakk>
huffman@21776
   392
   \<Longrightarrow> inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
huffman@21776
   393
by (simp add: right_diff_distrib left_diff_distrib mult_assoc)
huffman@21776
   394
huffman@21776
   395
lemmas bounded_linear_mult_const =
huffman@21776
   396
  bounded_bilinear_mult.bounded_linear_left [THEN bounded_linear_compose]
huffman@21776
   397
huffman@21776
   398
lemmas bounded_linear_const_mult =
huffman@21776
   399
  bounded_bilinear_mult.bounded_linear_right [THEN bounded_linear_compose]
huffman@21776
   400
huffman@21776
   401
lemma FDERIV_inverse:
huffman@21776
   402
  fixes x :: "'a::real_normed_div_algebra"
huffman@21776
   403
  assumes x: "x \<noteq> 0"
huffman@21776
   404
  shows "FDERIV inverse x :> (\<lambda>h. - (inverse x * h * inverse x))"
huffman@21776
   405
        (is "FDERIV ?inv _ :> _")
huffman@21776
   406
proof (rule FDERIV_I)
huffman@21776
   407
  show "bounded_linear (\<lambda>h. - (?inv x * h * ?inv x))"
huffman@21776
   408
    apply (rule bounded_linear_minus)
huffman@21776
   409
    apply (rule bounded_linear_mult_const)
huffman@21776
   410
    apply (rule bounded_linear_const_mult)
huffman@21776
   411
    apply (rule bounded_linear_ident)
huffman@21776
   412
    done
huffman@21776
   413
next
huffman@21776
   414
  show "(\<lambda>h. norm (?inv (x + h) - ?inv x - - (?inv x * h * ?inv x)) / norm h)
huffman@21776
   415
        -- 0 --> 0"
huffman@21776
   416
  proof (rule LIM_equal2)
huffman@21776
   417
    show "0 < norm x" using x by simp
huffman@21776
   418
  next
huffman@21776
   419
    fix h::'a
huffman@21776
   420
    assume 1: "h \<noteq> 0"
huffman@21776
   421
    assume "norm (h - 0) < norm x"
huffman@21776
   422
    hence "h \<noteq> -x" by clarsimp
huffman@21776
   423
    hence 2: "x + h \<noteq> 0"
huffman@21776
   424
      apply (rule contrapos_nn)
huffman@21776
   425
      apply (rule sym)
huffman@21776
   426
      apply (erule equals_zero_I)
huffman@21776
   427
      done
huffman@21776
   428
    show "norm (?inv (x + h) - ?inv x - - (?inv x * h * ?inv x)) / norm h
huffman@21776
   429
          = norm ((?inv (x + h) - ?inv x) * h * ?inv x) / norm h"
huffman@21776
   430
      apply (subst inverse_diff_inverse [OF 2 x])
huffman@21776
   431
      apply (subst minus_diff_minus)
huffman@21776
   432
      apply (subst norm_minus_cancel)
huffman@21776
   433
      apply (simp add: left_diff_distrib)
huffman@21776
   434
      done
huffman@21776
   435
  next
huffman@21776
   436
    show "(\<lambda>h. norm ((?inv (x + h) - ?inv x) * h * ?inv x) / norm h)
huffman@21776
   437
          -- 0 --> 0"
huffman@21776
   438
    proof (rule real_LIM_sandwich_zero)
huffman@21776
   439
      show "(\<lambda>h. norm (?inv (x + h) - ?inv x) * norm (?inv x))
huffman@21776
   440
            -- 0 --> 0"
huffman@21776
   441
        apply (rule LIM_mult_left_zero)
huffman@21776
   442
        apply (rule LIM_norm_zero)
huffman@21776
   443
        apply (rule LIM_zero)
huffman@21776
   444
        apply (rule LIM_offset_zero)
huffman@21776
   445
        apply (rule LIM_inverse)
huffman@21776
   446
        apply (rule LIM_self)
huffman@21776
   447
        apply (rule x)
huffman@21776
   448
        done
huffman@21776
   449
    next
huffman@21776
   450
      fix h::'a assume h: "h \<noteq> 0"
huffman@21776
   451
      show "0 \<le> norm ((?inv (x + h) - ?inv x) * h * ?inv x) / norm h"
huffman@21776
   452
        apply (rule divide_nonneg_pos)
huffman@21776
   453
        apply (rule norm_ge_zero)
huffman@21776
   454
        apply (simp add: h)
huffman@21776
   455
        done
huffman@21776
   456
    next
huffman@21776
   457
      fix h::'a assume h: "h \<noteq> 0"
huffman@21776
   458
      have "norm ((?inv (x + h) - ?inv x) * h * ?inv x) / norm h
huffman@21776
   459
            \<le> norm (?inv (x + h) - ?inv x) * norm h * norm (?inv x) / norm h"
huffman@21776
   460
        apply (rule divide_right_mono [OF _ norm_ge_zero])
huffman@21776
   461
        apply (rule order_trans [OF norm_mult_ineq])
huffman@21776
   462
        apply (rule mult_right_mono [OF _ norm_ge_zero])
huffman@21776
   463
        apply (rule norm_mult_ineq)
huffman@21776
   464
        done
huffman@21776
   465
      also have "\<dots> = norm (?inv (x + h) - ?inv x) * norm (?inv x)"
huffman@21776
   466
        by simp
huffman@21776
   467
      finally show "norm ((?inv (x + h) - ?inv x) * h * ?inv x) / norm h
huffman@21776
   468
            \<le> norm (?inv (x + h) - ?inv x) * norm (?inv x)" .   
huffman@21776
   469
    qed
huffman@21776
   470
  qed
huffman@21776
   471
qed
huffman@21776
   472
huffman@21776
   473
subsection {* Alternate definition *}
huffman@21776
   474
huffman@21776
   475
lemma field_fderiv_def:
huffman@21776
   476
  fixes x :: "'a::real_normed_field" shows
huffman@21776
   477
  "FDERIV f x :> (\<lambda>h. h * D) = (\<lambda>h. (f (x + h) - f x) / h) -- 0 --> D"
huffman@21776
   478
 apply (unfold fderiv_def)
huffman@21776
   479
 apply (simp add: bounded_bilinear_mult.bounded_linear_left)
huffman@21776
   480
 apply (simp cong: LIM_cong add: nonzero_norm_divide [symmetric])
huffman@21776
   481
 apply (subst diff_divide_distrib)
huffman@21776
   482
 apply (subst times_divide_eq_left [symmetric])
huffman@21776
   483
 apply (simp cong: LIM_cong add: divide_self)
huffman@21776
   484
 apply (simp add: LIM_norm_zero_iff LIM_zero_iff)
huffman@21776
   485
done
huffman@21776
   486
huffman@21776
   487
end