diff -r e49dc94eb624 -r e9ad90ce926c src/HOL/Deriv.thy --- a/src/HOL/Deriv.thy Tue May 10 14:04:44 2016 +0100 +++ b/src/HOL/Deriv.thy Tue May 10 15:48:37 2016 +0200 @@ -599,13 +599,19 @@ lemma differentiableI: "(f has_real_derivative D) (at x within s) \ f differentiable (at x within s)" by (force simp add: real_differentiable_def) -lemma DERIV_def: "DERIV f x :> D \ (\h. (f (x + h) - f x) / h) \0\ D" - apply (simp add: has_field_derivative_def has_derivative_at bounded_linear_mult_right LIM_zero_iff[symmetric, of _ D]) +lemma has_field_derivative_iff: + "(f has_field_derivative D) (at x within S) \ + ((\y. (f y - f x) / (y - x)) \ D) (at x within S)" + apply (simp add: has_field_derivative_def has_derivative_iff_norm bounded_linear_mult_right + LIM_zero_iff[symmetric, of _ D]) apply (subst (2) tendsto_norm_zero_iff[symmetric]) apply (rule filterlim_cong) apply (simp_all add: eventually_at_filter field_simps nonzero_norm_divide) done +lemma DERIV_def: "DERIV f x :> D \ (\h. (f (x + h) - f x) / h) \0\ D" + unfolding field_has_derivative_at has_field_derivative_def has_field_derivative_iff .. + lemma mult_commute_abs: "(\x. x * c) = op * (c::'a::ab_semigroup_mult)" by (simp add: fun_eq_iff mult.commute) @@ -645,14 +651,14 @@ by (auto simp: has_vector_derivative_def scaleR_diff_right) lemma has_vector_derivative_add_const: - "((\t. g t + z) has_vector_derivative f') (at x) = ((\t. g t) has_vector_derivative f') (at x)" + "((\t. g t + z) has_vector_derivative f') net = ((\t. g t) has_vector_derivative f') net" apply (intro iffI) apply (drule has_vector_derivative_diff [where g = "\t. z", OF _ has_vector_derivative_const], simp) apply (drule has_vector_derivative_add [OF _ has_vector_derivative_const], simp) done lemma has_vector_derivative_diff_const: - "((\t. g t - z) has_vector_derivative f') (at x) = ((\t. g t) has_vector_derivative f') (at x)" + "((\t. g t - z) has_vector_derivative f') net = ((\t. g t) has_vector_derivative f') net" using has_vector_derivative_add_const [where z = "-z"] by simp @@ -704,6 +710,11 @@ lemma DERIV_D: "DERIV f x :> D \ (\h. (f (x + h) - f x) / h) \0\ D" by (simp add: DERIV_def) +lemma has_field_derivativeD: + "(f has_field_derivative D) (at x within S) \ + ((\y. (f y - f x) / (y - x)) \ D) (at x within S)" + by (simp add: has_field_derivative_iff) + lemma DERIV_const [simp, derivative_intros]: "((\x. k) has_field_derivative 0) F" by (rule has_derivative_imp_has_field_derivative[OF has_derivative_const]) auto @@ -892,22 +903,27 @@ apply (simp add: add.commute) done -lemma DERIV_iff2: "(DERIV f x :> D) \ (\z. (f z - f x) / (z - x)) \x\ D" - by (simp add: DERIV_def DERIV_LIM_iff) +lemmas DERIV_iff2 = has_field_derivative_iff + +lemma has_field_derivative_cong_ev: + assumes "x = y" + and *: "eventually (\x. x \ s \ f x = g x) (nhds x)" + and "u = v" "s = t" "x \ s" + shows "(f has_field_derivative u) (at x within s) = (g has_field_derivative v) (at y within t)" + unfolding DERIV_iff2 +proof (rule filterlim_cong) + from assms have "f y = g y" by (auto simp: eventually_nhds) + with * show "\\<^sub>F xa in at x within s. (f xa - f x) / (xa - x) = (g xa - g y) / (xa - y)" + unfolding eventually_at_filter + by eventually_elim (auto simp: assms \f y = g y\) +qed (simp_all add: assms) lemma DERIV_cong_ev: "x = y \ eventually (\x. f x = g x) (nhds x) \ u = v \ DERIV f x :> u \ DERIV g y :> v" - unfolding DERIV_iff2 -proof (rule filterlim_cong) - assume *: "eventually (\x. f x = g x) (nhds x)" - moreover from * have "f x = g x" by (auto simp: eventually_nhds) - moreover assume "x = y" "u = v" - ultimately show "eventually (\xa. (f xa - f x) / (xa - x) = (g xa - g y) / (xa - y)) (at x)" - by (auto simp: eventually_at_filter elim: eventually_mono) -qed simp_all + by (rule has_field_derivative_cong_ev) simp_all lemma DERIV_shift: - "(DERIV f (x + z) :> y) \ (DERIV (\x. f (x + z)) x :> y)" + "(f has_field_derivative y) (at (x + z)) = ((\x. f (x + z)) has_field_derivative y) (at x)" by (simp add: DERIV_def field_simps) lemma DERIV_mirror: @@ -943,31 +959,64 @@ text\If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right\ +lemma has_real_derivative_pos_inc_right: + fixes f :: "real => real" + assumes der: "(f has_real_derivative l) (at x within S)" + and l: "0 < l" + shows "\d > 0. \h > 0. x + h \ S \ h < d \ f x < f (x + h)" + using assms +proof - + from der [THEN has_field_derivativeD, THEN tendstoD, OF l, unfolded eventually_at] + obtain s where s: "0 < s" + and all: "\xa. xa\S \ xa \ x \ dist xa x < s \ abs ((f xa - f x) / (xa - x) - l) < l" + by (auto simp: dist_real_def) + then show ?thesis + proof (intro exI conjI strip) + show "0 S" + with all [of "x + h"] show "f x < f (x+h)" + proof (simp add: abs_if dist_real_def pos_less_divide_eq split: if_split_asm) + assume "\ (f (x+h) - f x) / h < l" and h: "0 < h" + with l + have "0 < (f (x+h) - f x) / h" by arith + thus "f x < f (x+h)" + by (simp add: pos_less_divide_eq h) + qed + qed +qed + lemma DERIV_pos_inc_right: fixes f :: "real => real" assumes der: "DERIV f x :> l" and l: "0 < l" shows "\d > 0. \h > 0. h < d --> f(x) < f(x + h)" + using has_real_derivative_pos_inc_right[OF assms] + by auto + +lemma has_real_derivative_neg_dec_left: + fixes f :: "real => real" + assumes der: "(f has_real_derivative l) (at x within S)" + and "l < 0" + shows "\d > 0. \h > 0. x - h \ S \ h < d \ f x < f (x - h)" proof - - from l der [THEN DERIV_D, THEN LIM_D [where r = "l"]] - have "\s > 0. (\z. z \ 0 \ \z\ < s \ \(f(x+z) - f x) / z - l\ < l)" - by simp - then obtain s - where s: "0 < s" - and all: "!!z. z \ 0 \ \z\ < s \ \(f(x+z) - f x) / z - l\ < l" - by auto + from \l < 0\ have l: "- l > 0" by simp + from der [THEN has_field_derivativeD, THEN tendstoD, OF l, unfolded eventually_at] + obtain s where s: "0 < s" + and all: "\xa. xa\S \ xa \ x \ dist xa x < s \ abs ((f xa - f x) / (xa - x) - l) < - l" + by (auto simp: dist_real_def) thus ?thesis proof (intro exI conjI strip) show "0 S" + with all [of "x - h"] show "f x < f (x-h)" + proof (simp add: abs_if pos_less_divide_eq dist_real_def split add: if_split_asm) + assume " - ((f (x-h) - f x) / h) < l" and h: "0 < h" with l - have "0 < (f (x+h) - f x) / h" by arith - thus "f x < f (x+h)" - by (simp add: pos_less_divide_eq h) + have "0 < (f (x-h) - f x) / h" by arith + thus "f x < f (x-h)" + by (simp add: pos_less_divide_eq h) qed qed qed @@ -977,43 +1026,31 @@ assumes der: "DERIV f x :> l" and l: "l < 0" shows "\d > 0. \h > 0. h < d --> f(x) < f(x-h)" -proof - - from l der [THEN DERIV_D, THEN LIM_D [where r = "-l"]] - have "\s > 0. (\z. z \ 0 \ \z\ < s \ \(f(x+z) - f x) / z - l\ < -l)" - by simp - then obtain s - where s: "0 < s" - and all: "!!z. z \ 0 \ \z\ < s \ \(f(x+z) - f x) / z - l\ < -l" - by auto - thus ?thesis - proof (intro exI conjI strip) - show "0 real" + shows "(f has_real_derivative l) (at x within S) \ 0 < l \ \d>0. \h>0. x - h \ S \ h < d \ f (x - h) < f x" + by (rule has_real_derivative_neg_dec_left [of "%x. - f x" "-l" x S, simplified]) + (auto simp add: DERIV_minus) lemma DERIV_pos_inc_left: fixes f :: "real => real" shows "DERIV f x :> l \ 0 < l \ \d > 0. \h > 0. h < d --> f(x - h) < f(x)" - apply (rule DERIV_neg_dec_left [of "%x. - f x" "-l" x, simplified]) - apply (auto simp add: DERIV_minus) - done + using has_real_derivative_pos_inc_left + by blast + +lemma has_real_derivative_neg_dec_right: + fixes f :: "real => real" + shows "(f has_real_derivative l) (at x within S) \ l < 0 \ \d > 0. \h > 0. x + h \ S \ h < d \ f(x) > f(x + h)" + by (rule has_real_derivative_pos_inc_right [of "%x. - f x" "-l" x S, simplified]) + (auto simp add: DERIV_minus) lemma DERIV_neg_dec_right: fixes f :: "real => real" shows "DERIV f x :> l \ l < 0 \ \d > 0. \h > 0. h < d --> f(x) > f(x + h)" - apply (rule DERIV_pos_inc_right [of "%x. - f x" "-l" x, simplified]) - apply (auto simp add: DERIV_minus) - done + using has_real_derivative_neg_dec_right by blast lemma DERIV_local_max: fixes f :: "real => real"