src/HOL/Nonstandard_Analysis/HDeriv.thy
author wenzelm
Sun, 18 Dec 2016 23:43:50 +0100
changeset 64604 2bf8cfc98c4d
parent 64435 c93b0e6131c3
child 67399 eab6ce8368fa
permissions -rw-r--r--
misc tuning and modernization;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62479
716336f19aa9 clarified session;
wenzelm
parents: 61982
diff changeset
     1
(*  Title:      HOL/Nonstandard_Analysis/HDeriv.thy
716336f19aa9 clarified session;
wenzelm
parents: 61982
diff changeset
     2
    Author:     Jacques D. Fleuriot
716336f19aa9 clarified session;
wenzelm
parents: 61982
diff changeset
     3
    Copyright:  1998  University of Cambridge
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
     4
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
     5
*)
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
     6
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
     7
section \<open>Differentiation (Nonstandard)\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
     8
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
     9
theory HDeriv
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    10
  imports HLim
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    11
begin
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    12
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    13
text \<open>Nonstandard Definitions.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    14
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    15
definition nsderiv :: "['a::real_normed_field \<Rightarrow> 'a, 'a, 'a] \<Rightarrow> bool"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    16
    ("(NSDERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    17
  where "NSDERIV f x :> D \<longleftrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    18
    (\<forall>h \<in> Infinitesimal - {0}. (( *f* f)(star_of x + h) - star_of (f x)) / h \<approx> star_of D)"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    19
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    20
definition NSdifferentiable :: "['a::real_normed_field \<Rightarrow> 'a, 'a] \<Rightarrow> bool"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    21
    (infixl "NSdifferentiable" 60)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    22
  where "f NSdifferentiable x \<longleftrightarrow> (\<exists>D. NSDERIV f x :> D)"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    23
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    24
definition increment :: "(real \<Rightarrow> real) \<Rightarrow> real \<Rightarrow> hypreal \<Rightarrow> hypreal"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    25
  where "increment f x h =
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    26
    (SOME inc. f NSdifferentiable x \<and> inc = ( *f* f) (hypreal_of_real x + h) - hypreal_of_real (f x))"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    27
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    28
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
    29
subsection \<open>Derivatives\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    30
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    31
lemma DERIV_NS_iff: "(DERIV f x :> D) \<longleftrightarrow> (\<lambda>h. (f (x + h) - f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    32
  by (simp add: DERIV_def LIM_NSLIM_iff)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    33
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    34
lemma NS_DERIV_D: "DERIV f x :> D \<Longrightarrow> (\<lambda>h. (f (x + h) - f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    35
  by (simp add: DERIV_def LIM_NSLIM_iff)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    36
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    37
lemma hnorm_of_hypreal: "\<And>r. hnorm (( *f* of_real) r::'a::real_normed_div_algebra star) = \<bar>r\<bar>"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    38
  by transfer (rule norm_of_real)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    39
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    40
lemma Infinitesimal_of_hypreal:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    41
  "x \<in> Infinitesimal \<Longrightarrow> (( *f* of_real) x::'a::real_normed_div_algebra star) \<in> Infinitesimal"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    42
  apply (rule InfinitesimalI2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    43
  apply (drule (1) InfinitesimalD2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    44
  apply (simp add: hnorm_of_hypreal)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    45
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    46
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    47
lemma of_hypreal_eq_0_iff: "\<And>x. (( *f* of_real) x = (0::'a::real_algebra_1 star)) = (x = 0)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    48
  by transfer (rule of_real_eq_0_iff)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    49
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    50
lemma NSDeriv_unique: "NSDERIV f x :> D \<Longrightarrow> NSDERIV f x :> E \<Longrightarrow> D = E"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    51
  apply (subgoal_tac "( *f* of_real) \<epsilon> \<in> Infinitesimal - {0::'a star}")
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    52
   apply (simp only: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    53
   apply (drule (1) bspec)+
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    54
   apply (drule (1) approx_trans3)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    55
   apply simp
64604
2bf8cfc98c4d misc tuning and modernization;
wenzelm
parents: 64435
diff changeset
    56
  apply (simp add: Infinitesimal_of_hypreal)
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    57
  apply (simp add: of_hypreal_eq_0_iff hypreal_epsilon_not_zero)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    58
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    59
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    60
text \<open>First \<open>NSDERIV\<close> in terms of \<open>NSLIM\<close>.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    61
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    62
text \<open>First equivalence.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    63
lemma NSDERIV_NSLIM_iff: "(NSDERIV f x :> D) \<longleftrightarrow> (\<lambda>h. (f (x + h) - f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    64
  apply (auto simp add: nsderiv_def NSLIM_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    65
   apply (drule_tac x = xa in bspec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    66
    apply (rule_tac [3] ccontr)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    67
    apply (drule_tac [3] x = h in spec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    68
    apply (auto simp add: mem_infmal_iff starfun_lambda_cancel)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    69
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    70
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    71
text \<open>Second equivalence.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    72
lemma NSDERIV_NSLIM_iff2: "(NSDERIV f x :> D) \<longleftrightarrow> (\<lambda>z. (f z - f x) / (z - x)) \<midarrow>x\<rightarrow>\<^sub>N\<^sub>S D"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
    73
  by (simp add: NSDERIV_NSLIM_iff DERIV_LIM_iff LIM_NSLIM_iff [symmetric])
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    74
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    75
text \<open>While we're at it!\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    76
lemma NSDERIV_iff2:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    77
  "(NSDERIV f x :> D) \<longleftrightarrow>
64604
2bf8cfc98c4d misc tuning and modernization;
wenzelm
parents: 64435
diff changeset
    78
    (\<forall>w. w \<noteq> star_of x \<and> w \<approx> star_of x \<longrightarrow> ( *f* (\<lambda>z. (f z - f x) / (z - x))) w \<approx> star_of D)"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    79
  by (simp add: NSDERIV_NSLIM_iff2 NSLIM_def)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    80
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    81
(* FIXME delete *)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    82
lemma hypreal_not_eq_minus_iff: "x \<noteq> a \<longleftrightarrow> x - a \<noteq> (0::'a::ab_group_add)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    83
  by auto
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    84
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    85
lemma NSDERIVD5:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    86
  "(NSDERIV f x :> D) \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    87
   (\<forall>u. u \<approx> hypreal_of_real x \<longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    88
     ( *f* (\<lambda>z. f z - f x)) u \<approx> hypreal_of_real D * (u - hypreal_of_real x))"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    89
  apply (auto simp add: NSDERIV_iff2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    90
  apply (case_tac "u = hypreal_of_real x", auto)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    91
  apply (drule_tac x = u in spec, auto)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    92
  apply (drule_tac c = "u - hypreal_of_real x" and b = "hypreal_of_real D" in approx_mult1)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    93
   apply (drule_tac [!] hypreal_not_eq_minus_iff [THEN iffD1])
64604
2bf8cfc98c4d misc tuning and modernization;
wenzelm
parents: 64435
diff changeset
    94
   apply (subgoal_tac [2] "( *f* (\<lambda>z. z - x)) u \<noteq> (0::hypreal) ")
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    95
    apply (auto simp: approx_minus_iff [THEN iffD1, THEN mem_infmal_iff [THEN iffD2]]
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    96
      Infinitesimal_subset_HFinite [THEN subsetD])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
    97
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    98
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
    99
lemma NSDERIVD4:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   100
  "(NSDERIV f x :> D) \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   101
    (\<forall>h \<in> Infinitesimal.
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   102
      ( *f* f)(hypreal_of_real x + h) - hypreal_of_real (f x) \<approx> hypreal_of_real D * h)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   103
  apply (auto simp add: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   104
  apply (case_tac "h = 0")
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   105
   apply auto
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   106
  apply (drule_tac x = h in bspec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   107
   apply (drule_tac [2] c = h in approx_mult1)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   108
    apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   109
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   110
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   111
lemma NSDERIVD3:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   112
  "(NSDERIV f x :> D) \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   113
    \<forall>h \<in> Infinitesimal - {0}.
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   114
      (( *f* f) (hypreal_of_real x + h) - hypreal_of_real (f x)) \<approx> hypreal_of_real D * h"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   115
  apply (auto simp add: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   116
  apply (rule ccontr, drule_tac x = h in bspec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   117
   apply (drule_tac [2] c = h in approx_mult1)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   118
    apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD] simp add: mult.assoc)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   119
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   120
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   121
text \<open>Differentiability implies continuity nice and simple "algebraic" proof.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   122
lemma NSDERIV_isNSCont: "NSDERIV f x :> D \<Longrightarrow> isNSCont f x"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   123
  apply (auto simp add: nsderiv_def isNSCont_NSLIM_iff NSLIM_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   124
  apply (drule approx_minus_iff [THEN iffD1])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   125
  apply (drule hypreal_not_eq_minus_iff [THEN iffD1])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   126
  apply (drule_tac x = "xa - star_of x" in bspec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   127
   prefer 2 apply (simp add: add.assoc [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   128
   apply (auto simp add: mem_infmal_iff [symmetric] add.commute)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   129
  apply (drule_tac c = "xa - star_of x" in approx_mult1)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   130
   apply (auto intro: Infinitesimal_subset_HFinite [THEN subsetD] simp add: mult.assoc)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   131
  apply (drule_tac x3=D in
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   132
      HFinite_star_of [THEN [2] Infinitesimal_HFinite_mult, THEN mem_infmal_iff [THEN iffD1]])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   133
  apply (auto simp add: mult.commute intro: approx_trans approx_minus_iff [THEN iffD2])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   134
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   135
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   136
text \<open>Differentiation rules for combinations of functions
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   137
  follow from clear, straightforard, algebraic manipulations.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   138
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   139
text \<open>Constant function.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   140
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   141
(* use simple constant nslimit theorem *)
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   142
lemma NSDERIV_const [simp]: "NSDERIV (\<lambda>x. k) x :> 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   143
  by (simp add: NSDERIV_NSLIM_iff)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   144
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   145
text \<open>Sum of functions- proved easily.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   146
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   147
lemma NSDERIV_add:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   148
  "NSDERIV f x :> Da \<Longrightarrow> NSDERIV g x :> Db \<Longrightarrow> NSDERIV (\<lambda>x. f x + g x) x :> Da + Db"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   149
  apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   150
  apply (auto simp add: add_divide_distrib diff_divide_distrib dest!: spec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   151
  apply (drule_tac b = "star_of Da" and d = "star_of Db" in approx_add)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   152
   apply (auto simp add: ac_simps algebra_simps)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   153
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   154
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   155
text \<open>Product of functions - Proof is trivial but tedious
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   156
  and long due to rearrangement of terms.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   157
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   158
lemma lemma_nsderiv1: "(a * b) - (c * d) = (b * (a - c)) + (c * (b - d))"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   159
  for a b c d :: "'a::comm_ring star"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   160
  by (simp add: right_diff_distrib ac_simps)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   161
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   162
lemma lemma_nsderiv2: "(x - y) / z = star_of D + yb \<Longrightarrow> z \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   163
  z \<in> Infinitesimal \<Longrightarrow> yb \<in> Infinitesimal \<Longrightarrow> x - y \<approx> 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   164
  for x y z :: "'a::real_normed_field star"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   165
  apply (simp add: nonzero_divide_eq_eq)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   166
  apply (auto intro!: Infinitesimal_HFinite_mult2 HFinite_add
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   167
      simp add: mult.assoc mem_infmal_iff [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   168
  apply (erule Infinitesimal_subset_HFinite [THEN subsetD])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   169
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   170
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   171
lemma NSDERIV_mult:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   172
  "NSDERIV f x :> Da \<Longrightarrow> NSDERIV g x :> Db \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   173
    NSDERIV (\<lambda>x. f x * g x) x :> (Da * g x) + (Db * f x)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   174
  apply (auto simp add: NSDERIV_NSLIM_iff NSLIM_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   175
  apply (auto dest!: spec simp add: starfun_lambda_cancel lemma_nsderiv1)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   176
  apply (simp (no_asm) add: add_divide_distrib diff_divide_distrib)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   177
  apply (drule bex_Infinitesimal_iff2 [THEN iffD2])+
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   178
  apply (auto simp add: times_divide_eq_right [symmetric]
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   179
      simp del: times_divide_eq_right times_divide_eq_left)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   180
  apply (drule_tac D = Db in lemma_nsderiv2, assumption+)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   181
  apply (drule_tac approx_minus_iff [THEN iffD2, THEN bex_Infinitesimal_iff2 [THEN iffD2]])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   182
  apply (auto intro!: approx_add_mono1 simp: distrib_right distrib_left mult.commute add.assoc)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   183
  apply (rule_tac b1 = "star_of Db * star_of (f x)" in add.commute [THEN subst])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   184
  apply (auto intro!: Infinitesimal_add_approx_self2 [THEN approx_sym]
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   185
      Infinitesimal_add Infinitesimal_mult Infinitesimal_star_of_mult Infinitesimal_star_of_mult2
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   186
      simp add: add.assoc [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   187
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   188
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   189
text \<open>Multiplying by a constant.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   190
lemma NSDERIV_cmult: "NSDERIV f x :> D \<Longrightarrow> NSDERIV (\<lambda>x. c * f x) x :> c * D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   191
  apply (simp only: times_divide_eq_right [symmetric] NSDERIV_NSLIM_iff
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   192
      minus_mult_right right_diff_distrib [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   193
  apply (erule NSLIM_const [THEN NSLIM_mult])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   194
  done
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   195
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   196
text \<open>Negation of function.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   197
lemma NSDERIV_minus: "NSDERIV f x :> D \<Longrightarrow> NSDERIV (\<lambda>x. - f x) x :> - D"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   198
proof (simp add: NSDERIV_NSLIM_iff)
61971
720fa884656e more symbols;
wenzelm
parents: 59867
diff changeset
   199
  assume "(\<lambda>h. (f (x + h) - f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S D"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   200
  then have deriv: "(\<lambda>h. - ((f(x+h) - f x) / h)) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S - D"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   201
    by (rule NSLIM_minus)
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   202
  have "\<forall>h. - ((f (x + h) - f x) / h) = (- f (x + h) + f x) / h"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   203
    by (simp add: minus_divide_left)
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   204
  with deriv have "(\<lambda>h. (- f (x + h) + f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S - D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   205
    by simp
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   206
  then show "(\<lambda>h. (f (x + h) - f x) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S D \<Longrightarrow> (\<lambda>h. (f x - f (x + h)) / h) \<midarrow>0\<rightarrow>\<^sub>N\<^sub>S - D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   207
    by simp
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   208
qed
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   209
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   210
text \<open>Subtraction.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   211
lemma NSDERIV_add_minus:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   212
  "NSDERIV f x :> Da \<Longrightarrow> NSDERIV g x :> Db \<Longrightarrow> NSDERIV (\<lambda>x. f x + - g x) x :> Da + - Db"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   213
  by (blast dest: NSDERIV_add NSDERIV_minus)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   214
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   215
lemma NSDERIV_diff:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   216
  "NSDERIV f x :> Da \<Longrightarrow> NSDERIV g x :> Db \<Longrightarrow> NSDERIV (\<lambda>x. f x - g x) x :> Da - Db"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   217
  using NSDERIV_add_minus [of f x Da g Db] by simp
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   218
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   219
text \<open>Similarly to the above, the chain rule admits an entirely
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   220
  straightforward derivation. Compare this with Harrison's
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   221
  HOL proof of the chain rule, which proved to be trickier and
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   222
  required an alternative characterisation of differentiability-
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   223
  the so-called Carathedory derivative. Our main problem is
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   224
  manipulation of terms.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   225
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   226
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   227
subsection \<open>Lemmas\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   228
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   229
lemma NSDERIV_zero:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   230
  "NSDERIV g x :> D \<Longrightarrow> ( *f* g) (star_of x + xa) = star_of (g x) \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   231
    xa \<in> Infinitesimal \<Longrightarrow> xa \<noteq> 0 \<Longrightarrow> D = 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   232
  apply (simp add: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   233
  apply (drule bspec)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   234
   apply auto
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   235
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   236
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   237
text \<open>Can be proved differently using \<open>NSLIM_isCont_iff\<close>.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   238
lemma NSDERIV_approx:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   239
  "NSDERIV f x :> D \<Longrightarrow> h \<in> Infinitesimal \<Longrightarrow> h \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   240
    ( *f* f) (star_of x + h) - star_of (f x) \<approx> 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   241
  apply (simp add: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   242
  apply (simp add: mem_infmal_iff [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   243
  apply (rule Infinitesimal_ratio)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   244
    apply (rule_tac [3] approx_star_of_HFinite, auto)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   245
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   246
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   247
text \<open>From one version of differentiability
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   248
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   249
        \<open>f x - f a\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   250
      \<open>-------------- \<approx> Db\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   251
          \<open>x - a\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   252
\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   253
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   254
lemma NSDERIVD1: "[| NSDERIV f (g x) :> Da;
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   255
         ( *f* g) (star_of(x) + xa) \<noteq> star_of (g x);
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   256
         ( *f* g) (star_of(x) + xa) \<approx> star_of (g x)
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   257
      |] ==> (( *f* f) (( *f* g) (star_of(x) + xa))
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   258
                   - star_of (f (g x)))
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   259
              / (( *f* g) (star_of(x) + xa) - star_of (g x))
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   260
             \<approx> star_of(Da)"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   261
  by (auto simp add: NSDERIV_NSLIM_iff2 NSLIM_def)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   262
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   263
text \<open>From other version of differentiability
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   264
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   265
      \<open>f (x + h) - f x\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   266
     \<open>------------------ \<approx> Db\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   267
             \<open>h\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   268
\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   269
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   270
lemma NSDERIVD2: "[| NSDERIV g x :> Db; xa \<in> Infinitesimal; xa \<noteq> 0 |]
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   271
      ==> (( *f* g) (star_of(x) + xa) - star_of(g x)) / xa
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   272
          \<approx> star_of(Db)"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   273
  by (auto simp add: NSDERIV_NSLIM_iff NSLIM_def mem_infmal_iff starfun_lambda_cancel)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   274
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   275
lemma lemma_chain: "z \<noteq> 0 \<Longrightarrow> x * y = (x * inverse z) * (z * y)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   276
  for x y z :: "'a::real_normed_field star"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   277
proof -
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   278
  assume z: "z \<noteq> 0"
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   279
  have "x * y = x * (inverse z * z) * y" by (simp add: z)
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   280
  then show ?thesis by (simp add: mult.assoc)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   281
qed
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   282
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   283
text \<open>This proof uses both definitions of differentiability.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   284
lemma NSDERIV_chain:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   285
  "NSDERIV f (g x) :> Da \<Longrightarrow> NSDERIV g x :> Db \<Longrightarrow> NSDERIV (f \<circ> g) x :> Da * Db"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   286
  apply (simp (no_asm_simp) add: NSDERIV_NSLIM_iff NSLIM_def mem_infmal_iff [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   287
  apply clarify
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   288
  apply (frule_tac f = g in NSDERIV_approx)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   289
    apply (auto simp add: starfun_lambda_cancel2 starfun_o [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   290
  apply (case_tac "( *f* g) (star_of (x) + xa) = star_of (g x) ")
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   291
   apply (drule_tac g = g in NSDERIV_zero)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   292
      apply (auto simp add: divide_inverse)
64604
2bf8cfc98c4d misc tuning and modernization;
wenzelm
parents: 64435
diff changeset
   293
  apply (rule_tac z1 = "( *f* g) (star_of (x) + xa) - star_of (g x) " and y1 = "inverse xa"
2bf8cfc98c4d misc tuning and modernization;
wenzelm
parents: 64435
diff changeset
   294
      in lemma_chain [THEN ssubst])
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   295
   apply (erule hypreal_not_eq_minus_iff [THEN iffD1])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   296
  apply (rule approx_mult_star_of)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   297
   apply (simp_all add: divide_inverse [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   298
   apply (blast intro: NSDERIVD1 approx_minus_iff [THEN iffD2])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   299
  apply (blast intro: NSDERIVD2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   300
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   301
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   302
text \<open>Differentiation of natural number powers.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   303
lemma NSDERIV_Id [simp]: "NSDERIV (\<lambda>x. x) x :> 1"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   304
  by (simp add: NSDERIV_NSLIM_iff NSLIM_def del: divide_self_if)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   305
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   306
lemma NSDERIV_cmult_Id [simp]: "NSDERIV (op * c) x :> c"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   307
  using NSDERIV_Id [THEN NSDERIV_cmult] by simp
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   308
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   309
lemma NSDERIV_inverse:
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   310
  fixes x :: "'a::real_normed_field"
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
   311
  assumes "x \<noteq> 0" \<comment> \<open>can't get rid of @{term "x \<noteq> 0"} because it isn't continuous at zero\<close>
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   312
  shows "NSDERIV (\<lambda>x. inverse x) x :> - (inverse x ^ Suc (Suc 0))"
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   313
proof -
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   314
  {
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   315
    fix h :: "'a star"
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   316
    assume h_Inf: "h \<in> Infinitesimal"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   317
    from this assms have not_0: "star_of x + h \<noteq> 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   318
      by (rule Infinitesimal_add_not_zero)
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   319
    assume "h \<noteq> 0"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   320
    from h_Inf have "h * star_of x \<in> Infinitesimal"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   321
      by (rule Infinitesimal_HFinite_mult) simp
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   322
    with assms have "inverse (- (h * star_of x) + - (star_of x * star_of x)) \<approx>
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   323
      inverse (- (star_of x * star_of x))"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   324
      apply -
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   325
      apply (rule inverse_add_Infinitesimal_approx2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   326
      apply (auto dest!: hypreal_of_real_HFinite_diff_Infinitesimal
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   327
        simp add: inverse_minus_eq [symmetric] HFinite_minus_iff)
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   328
      done
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
   329
    moreover from not_0 \<open>h \<noteq> 0\<close> assms
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   330
    have "inverse (- (h * star_of x) + - (star_of x * star_of x)) =
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   331
      (inverse (star_of x + h) - inverse (star_of x)) / h"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   332
      apply (simp add: division_ring_inverse_diff nonzero_inverse_mult_distrib [symmetric]
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   333
          nonzero_inverse_minus_eq [symmetric] ac_simps ring_distribs)
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   334
      apply (subst nonzero_inverse_minus_eq [symmetric])
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   335
      using distrib_right [symmetric, of h "star_of x" "star_of x"] apply simp
56217
dc429a5b13c4 Some rationalisation of basic lemmas
paulson <lp15@cam.ac.uk>
parents: 54230
diff changeset
   336
      apply (simp add: field_simps)
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   337
      done
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53755
diff changeset
   338
    ultimately have "(inverse (star_of x + h) - inverse (star_of x)) / h \<approx>
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   339
      - (inverse (star_of x) * inverse (star_of x))"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   340
      using assms by simp
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   341
  }
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   342
  then show ?thesis by (simp add: nsderiv_def)
53755
b8e62805566b tuned proofs
haftmann
parents: 51525
diff changeset
   343
qed
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   344
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   345
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
   346
subsubsection \<open>Equivalence of NS and Standard definitions\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   347
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   348
lemma divideR_eq_divide: "x /\<^sub>R y = x / y"
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   349
  by (simp add: divide_inverse mult.commute)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   350
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   351
text \<open>Now equivalence between \<open>NSDERIV\<close> and \<open>DERIV\<close>.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   352
lemma NSDERIV_DERIV_iff: "NSDERIV f x :> D \<longleftrightarrow> DERIV f x :> D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   353
  by (simp add: DERIV_def NSDERIV_NSLIM_iff LIM_NSLIM_iff)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   354
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   355
text \<open>NS version.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   356
lemma NSDERIV_pow: "NSDERIV (\<lambda>x. x ^ n) x :> real n * (x ^ (n - Suc 0))"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   357
  by (simp add: NSDERIV_DERIV_iff DERIV_pow)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   358
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   359
text \<open>Derivative of inverse.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   360
lemma NSDERIV_inverse_fun:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   361
  "NSDERIV f x :> d \<Longrightarrow> f x \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   362
    NSDERIV (\<lambda>x. inverse (f x)) x :> (- (d * inverse (f x ^ Suc (Suc 0))))"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   363
  for x :: "'a::{real_normed_field}"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   364
  by (simp add: NSDERIV_DERIV_iff DERIV_inverse_fun del: power_Suc)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   365
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   366
text \<open>Derivative of quotient.\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   367
lemma NSDERIV_quotient:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   368
  fixes x :: "'a::real_normed_field"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   369
  shows "NSDERIV f x :> d \<Longrightarrow> NSDERIV g x :> e \<Longrightarrow> g x \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   370
    NSDERIV (\<lambda>y. f y / g y) x :> (d * g x - (e * f x)) / (g x ^ Suc (Suc 0))"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   371
  by (simp add: NSDERIV_DERIV_iff DERIV_quotient del: power_Suc)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   372
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   373
lemma CARAT_NSDERIV:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   374
  "NSDERIV f x :> l \<Longrightarrow> \<exists>g. (\<forall>z. f z - f x = g z * (z - x)) \<and> isNSCont g x \<and> g x = l"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   375
  by (auto simp add: NSDERIV_DERIV_iff isNSCont_isCont_iff CARAT_DERIV mult.commute)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   376
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   377
lemma hypreal_eq_minus_iff3: "x = y + z \<longleftrightarrow> x + - z = y"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   378
  for x y z :: hypreal
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   379
  by auto
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   380
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   381
lemma CARAT_DERIVD:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   382
  assumes all: "\<forall>z. f z - f x = g z * (z - x)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   383
    and nsc: "isNSCont g x"
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   384
  shows "NSDERIV f x :> g x"
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   385
proof -
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   386
  from nsc have "\<forall>w. w \<noteq> star_of x \<and> w \<approx> star_of x \<longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   387
       ( *f* g) w * (w - star_of x) / (w - star_of x) \<approx> star_of (g x)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   388
    by (simp add: isNSCont_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   389
  with all show ?thesis
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   390
    by (simp add: NSDERIV_iff2 starfun_if_eq cong: if_cong)
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   391
qed
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   392
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   393
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
   394
subsubsection \<open>Differentiability predicate\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   395
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   396
lemma NSdifferentiableD: "f NSdifferentiable x \<Longrightarrow> \<exists>D. NSDERIV f x :> D"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   397
  by (simp add: NSdifferentiable_def)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   398
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   399
lemma NSdifferentiableI: "NSDERIV f x :> D \<Longrightarrow> f NSdifferentiable x"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   400
  by (force simp add: NSdifferentiable_def)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   401
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   402
61975
b4b11391c676 isabelle update_cartouches -c -t;
wenzelm
parents: 61971
diff changeset
   403
subsection \<open>(NS) Increment\<close>
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   404
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   405
lemma incrementI:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   406
  "f NSdifferentiable x \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   407
    increment f x h = ( *f* f) (hypreal_of_real x + h) - hypreal_of_real (f x)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   408
  by (simp add: increment_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   409
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   410
lemma incrementI2:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   411
  "NSDERIV f x :> D \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   412
    increment f x h = ( *f* f) (hypreal_of_real x + h) - hypreal_of_real (f x)"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   413
  by (erule NSdifferentiableI [THEN incrementI])
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   414
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   415
text \<open>The Increment theorem -- Keisler p. 65.\<close>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   416
lemma increment_thm:
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   417
  "NSDERIV f x :> D \<Longrightarrow> h \<in> Infinitesimal \<Longrightarrow> h \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   418
    \<exists>e \<in> Infinitesimal. increment f x h = hypreal_of_real D * h + e * h"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   419
  apply (frule_tac h = h in incrementI2, simp add: nsderiv_def)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   420
  apply (drule bspec, auto)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   421
  apply (drule bex_Infinitesimal_iff2 [THEN iffD2], clarify)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   422
  apply (frule_tac b1 = "hypreal_of_real D + y" in mult_right_cancel [THEN iffD2])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   423
   apply (erule_tac [2]
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   424
      V = "(( *f* f) (hypreal_of_real x + h) - hypreal_of_real (f x)) / h = hypreal_of_real (D) + y"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   425
      in thin_rl)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   426
   apply assumption
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   427
  apply (simp add: times_divide_eq_right [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   428
  apply (auto simp add: distrib_right)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   429
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   430
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   431
lemma increment_thm2:
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   432
  "NSDERIV f x :> D \<Longrightarrow> h \<approx> 0 \<Longrightarrow> h \<noteq> 0 \<Longrightarrow>
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   433
    \<exists>e \<in> Infinitesimal. increment f x h = hypreal_of_real D * h + e * h"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   434
  by (blast dest!: mem_infmal_iff [THEN iffD2] intro!: increment_thm)
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   435
64435
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   436
lemma increment_approx_zero: "NSDERIV f x :> D \<Longrightarrow> h \<approx> 0 \<Longrightarrow> h \<noteq> 0 \<Longrightarrow> increment f x h \<approx> 0"
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   437
  apply (drule increment_thm2)
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   438
    apply (auto intro!: Infinitesimal_HFinite_mult2 HFinite_add
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   439
      simp add: distrib_right [symmetric] mem_infmal_iff [symmetric])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   440
  apply (erule Infinitesimal_subset_HFinite [THEN subsetD])
c93b0e6131c3 misc tuning and modernization;
wenzelm
parents: 64240
diff changeset
   441
  done
27468
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   442
0783dd1dc13d move nonstandard analysis theories to NSA directory
huffman
parents:
diff changeset
   443
end