src/HOL/Deriv.thy
changeset 69593 3dda49e08b9d
parent 69216 1a52baa70aed
child 70346 408e15cbd2a6
equal deleted inserted replaced
69592:a80d8ec6c998 69593:3dda49e08b9d
    18   where "(f has_derivative f') F \<longleftrightarrow>
    18   where "(f has_derivative f') F \<longleftrightarrow>
    19     bounded_linear f' \<and>
    19     bounded_linear f' \<and>
    20     ((\<lambda>y. ((f y - f (Lim F (\<lambda>x. x))) - f' (y - Lim F (\<lambda>x. x))) /\<^sub>R norm (y - Lim F (\<lambda>x. x))) \<longlongrightarrow> 0) F"
    20     ((\<lambda>y. ((f y - f (Lim F (\<lambda>x. x))) - f' (y - Lim F (\<lambda>x. x))) /\<^sub>R norm (y - Lim F (\<lambda>x. x))) \<longlongrightarrow> 0) F"
    21 
    21 
    22 text \<open>
    22 text \<open>
    23   Usually the filter @{term F} is @{term "at x within s"}.  @{term "(f has_derivative D)
    23   Usually the filter \<^term>\<open>F\<close> is \<^term>\<open>at x within s\<close>.  \<^term>\<open>(f has_derivative D)
    24   (at x within s)"} means: @{term D} is the derivative of function @{term f} at point @{term x}
    24   (at x within s)\<close> means: \<^term>\<open>D\<close> is the derivative of function \<^term>\<open>f\<close> at point \<^term>\<open>x\<close>
    25   within the set @{term s}. Where @{term s} is used to express left or right sided derivatives. In
    25   within the set \<^term>\<open>s\<close>. Where \<^term>\<open>s\<close> is used to express left or right sided derivatives. In
    26   most cases @{term s} is either a variable or @{term UNIV}.
    26   most cases \<^term>\<open>s\<close> is either a variable or \<^term>\<open>UNIV\<close>.
    27 \<close>
    27 \<close>
    28 
    28 
    29 text \<open>These are the only cases we'll care about, probably.\<close>
    29 text \<open>These are the only cases we'll care about, probably.\<close>
    30 
    30 
    31 lemma has_derivative_within: "(f has_derivative f') (at x within s) \<longleftrightarrow>
    31 lemma has_derivative_within: "(f has_derivative f') (at x within s) \<longleftrightarrow>
    58     fun eq_rule thm = get_first (try (fn eq_thm => eq_thm OF [thm])) eq_thms
    58     fun eq_rule thm = get_first (try (fn eq_thm => eq_thm OF [thm])) eq_thms
    59   in
    59   in
    60     Global_Theory.add_thms_dynamic
    60     Global_Theory.add_thms_dynamic
    61       (\<^binding>\<open>derivative_eq_intros\<close>,
    61       (\<^binding>\<open>derivative_eq_intros\<close>,
    62         fn context =>
    62         fn context =>
    63           Named_Theorems.get (Context.proof_of context) @{named_theorems derivative_intros}
    63           Named_Theorems.get (Context.proof_of context) \<^named_theorems>\<open>derivative_intros\<close>
    64           |> map_filter eq_rule)
    64           |> map_filter eq_rule)
    65   end
    65   end
    66 \<close>
    66 \<close>
    67 
    67 
    68 text \<open>
    68 text \<open>
   508 
   508 
   509 
   509 
   510 subsection \<open>Uniqueness\<close>
   510 subsection \<open>Uniqueness\<close>
   511 
   511 
   512 text \<open>
   512 text \<open>
   513 This can not generally shown for @{const has_derivative}, as we need to approach the point from
   513 This can not generally shown for \<^const>\<open>has_derivative\<close>, as we need to approach the point from
   514 all directions. There is a proof in \<open>Analysis\<close> for \<open>euclidean_space\<close>.
   514 all directions. There is a proof in \<open>Analysis\<close> for \<open>euclidean_space\<close>.
   515 \<close>
   515 \<close>
   516 
   516 
   517 lemma has_derivative_at2: "(f has_derivative f') (at x) \<longleftrightarrow>
   517 lemma has_derivative_at2: "(f has_derivative f') (at x) \<longleftrightarrow>
   518     bounded_linear f' \<and> ((\<lambda>y. (1 / (norm(y - x))) *\<^sub>R (f y - (f x + f' (y - x)))) \<longlongrightarrow> 0) (at x)"
   518     bounded_linear f' \<and> ((\<lambda>y. (1 / (norm(y - x))) *\<^sub>R (f y - (f x + f' (y - x)))) \<longlongrightarrow> 0) (at x)"
  1105 qed
  1105 qed
  1106 
  1106 
  1107 
  1107 
  1108 subsection \<open>Local extrema\<close>
  1108 subsection \<open>Local extrema\<close>
  1109 
  1109 
  1110 text \<open>If @{term "0 < f' x"} then @{term x} is Locally Strictly Increasing At The Right.\<close>
  1110 text \<open>If \<^term>\<open>0 < f' x\<close> then \<^term>\<open>x\<close> is Locally Strictly Increasing At The Right.\<close>
  1111 
  1111 
  1112 lemma has_real_derivative_pos_inc_right:
  1112 lemma has_real_derivative_pos_inc_right:
  1113   fixes f :: "real \<Rightarrow> real"
  1113   fixes f :: "real \<Rightarrow> real"
  1114   assumes der: "(f has_real_derivative l) (at x within S)"
  1114   assumes der: "(f has_real_derivative l) (at x within S)"
  1115     and l: "0 < l"
  1115     and l: "0 < l"
  1271 lemma lemma_interval: "a < x \<Longrightarrow> x < b \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b)"
  1271 lemma lemma_interval: "a < x \<Longrightarrow> x < b \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b)"
  1272   for a b x :: real
  1272   for a b x :: real
  1273   by (force dest: lemma_interval_lt)
  1273   by (force dest: lemma_interval_lt)
  1274 
  1274 
  1275 text \<open>Rolle's Theorem.
  1275 text \<open>Rolle's Theorem.
  1276    If @{term f} is defined and continuous on the closed interval
  1276    If \<^term>\<open>f\<close> is defined and continuous on the closed interval
  1277    \<open>[a,b]\<close> and differentiable on the open interval \<open>(a,b)\<close>,
  1277    \<open>[a,b]\<close> and differentiable on the open interval \<open>(a,b)\<close>,
  1278    and @{term "f a = f b"},
  1278    and \<^term>\<open>f a = f b\<close>,
  1279    then there exists \<open>x0 \<in> (a,b)\<close> such that @{term "f' x0 = 0"}\<close>
  1279    then there exists \<open>x0 \<in> (a,b)\<close> such that \<^term>\<open>f' x0 = 0\<close>\<close>
  1280 theorem Rolle_deriv:
  1280 theorem Rolle_deriv:
  1281   fixes f :: "real \<Rightarrow> real"
  1281   fixes f :: "real \<Rightarrow> real"
  1282   assumes "a < b"
  1282   assumes "a < b"
  1283     and fab: "f a = f b"
  1283     and fab: "f a = f b"
  1284     and contf: "continuous_on {a..b} f"
  1284     and contf: "continuous_on {a..b} f"
  1299   consider "a < x" "x < b" | "x = a \<or> x = b"
  1299   consider "a < x" "x < b" | "x = a \<or> x = b"
  1300     using \<open>a \<le> x\<close> \<open>x \<le> b\<close> by arith
  1300     using \<open>a \<le> x\<close> \<open>x \<le> b\<close> by arith
  1301   then show ?thesis
  1301   then show ?thesis
  1302   proof cases
  1302   proof cases
  1303     case 1
  1303     case 1
  1304     \<comment> \<open>@{term f} attains its maximum within the interval\<close>
  1304     \<comment> \<open>\<^term>\<open>f\<close> attains its maximum within the interval\<close>
  1305     then obtain l where der: "DERIV f x :> l"
  1305     then obtain l where der: "DERIV f x :> l"
  1306       using derf differentiable_def real_differentiable_def by blast
  1306       using derf differentiable_def real_differentiable_def by blast
  1307     obtain d where d: "0 < d" and bound: "\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1307     obtain d where d: "0 < d" and bound: "\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1308       using lemma_interval [OF 1] by blast
  1308       using lemma_interval [OF 1] by blast
  1309     then have bound': "\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> f y \<le> f x"
  1309     then have bound': "\<forall>y. \<bar>x - y\<bar> < d \<longrightarrow> f y \<le> f x"
  1319     consider "a < x'" "x' < b" | "x' = a \<or> x' = b"
  1319     consider "a < x'" "x' < b" | "x' = a \<or> x' = b"
  1320       using \<open>a \<le> x'\<close> \<open>x' \<le> b\<close> by arith
  1320       using \<open>a \<le> x'\<close> \<open>x' \<le> b\<close> by arith
  1321     then show ?thesis
  1321     then show ?thesis
  1322     proof cases
  1322     proof cases
  1323       case 1
  1323       case 1
  1324         \<comment> \<open>@{term f} attains its minimum within the interval\<close>
  1324         \<comment> \<open>\<^term>\<open>f\<close> attains its minimum within the interval\<close>
  1325       then obtain l where der: "DERIV f x' :> l"
  1325       then obtain l where der: "DERIV f x' :> l"
  1326         using derf differentiable_def real_differentiable_def by blast 
  1326         using derf differentiable_def real_differentiable_def by blast 
  1327       from lemma_interval [OF 1]
  1327       from lemma_interval [OF 1]
  1328       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1328       obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'-y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1329         by blast
  1329         by blast
  1333         \<comment> \<open>the derivative at a local minimum is zero\<close>
  1333         \<comment> \<open>the derivative at a local minimum is zero\<close>
  1334       then show ?thesis using 1 der derf [of x'] 
  1334       then show ?thesis using 1 der derf [of x'] 
  1335         by (metis has_derivative_unique has_field_derivative_def mult_zero_left)
  1335         by (metis has_derivative_unique has_field_derivative_def mult_zero_left)
  1336     next
  1336     next
  1337       case 2
  1337       case 2
  1338         \<comment> \<open>@{term f} is constant throughout the interval\<close>
  1338         \<comment> \<open>\<^term>\<open>f\<close> is constant throughout the interval\<close>
  1339       then have fx': "f b = f x'" by (auto simp: fab)
  1339       then have fx': "f b = f x'" by (auto simp: fab)
  1340       from dense [OF \<open>a < b\<close>] obtain r where r: "a < r" "r < b" by blast
  1340       from dense [OF \<open>a < b\<close>] obtain r where r: "a < r" "r < b" by blast
  1341       obtain d where d: "0 < d" and bound: "\<forall>y. \<bar>r - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1341       obtain d where d: "0 < d" and bound: "\<forall>y. \<bar>r - y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b"
  1342         using lemma_interval [OF r] by blast
  1342         using lemma_interval [OF r] by blast
  1343       have eq_fb: "f z = f b" if "a \<le> z" and "z \<le> b" for z
  1343       have eq_fb: "f z = f b" if "a \<le> z" and "z \<le> b" for z