src/HOL/Deriv.thy
changeset 33654 abf780db30ea
parent 31902 862ae16a799d
child 33659 2d7ab9458518
equal deleted inserted replaced
33640:0d82107dc07a 33654:abf780db30ea
   270 *}
   270 *}
   271 
   271 
   272 lemma DERIV_cmult:
   272 lemma DERIV_cmult:
   273       "DERIV f x :> D ==> DERIV (%x. c * f x) x :> c*D"
   273       "DERIV f x :> D ==> DERIV (%x. c * f x) x :> c*D"
   274 by (drule DERIV_mult' [OF DERIV_const], simp)
   274 by (drule DERIV_mult' [OF DERIV_const], simp)
       
   275 
       
   276 lemma DERIV_cdivide: "DERIV f x :> D ==> DERIV (%x. f x / c) x :> D / c"
       
   277   apply (subgoal_tac "DERIV (%x. (1 / c) * f x) x :> (1 / c) * D", force)
       
   278   apply (erule DERIV_cmult)
       
   279   done
   275 
   280 
   276 text {* Standard version *}
   281 text {* Standard version *}
   277 lemma DERIV_chain: "[| DERIV f (g x) :> Da; DERIV g x :> Db |] ==> DERIV (f o g) x :> Da * Db"
   282 lemma DERIV_chain: "[| DERIV f (g x) :> Da; DERIV g x :> Db |] ==> DERIV (f o g) x :> Da * Db"
   278 by (drule (1) DERIV_chain', simp add: o_def real_scaleR_def mult_commute)
   283 by (drule (1) DERIV_chain', simp add: o_def real_scaleR_def mult_commute)
   279 
   284 
   700       ==> \<exists>M::real. \<forall>x::real. a \<le> x & x \<le> b --> f(x) \<le> M"
   705       ==> \<exists>M::real. \<forall>x::real. a \<le> x & x \<le> b --> f(x) \<le> M"
   701 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> (\<exists>M. \<forall>x. u \<le> x & x \<le> v --> f x \<le> M)" in lemma_BOLZANO2)
   706 apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b --> (\<exists>M. \<forall>x. u \<le> x & x \<le> v --> f x \<le> M)" in lemma_BOLZANO2)
   702 apply safe
   707 apply safe
   703 apply simp_all
   708 apply simp_all
   704 apply (rename_tac x xa ya M Ma)
   709 apply (rename_tac x xa ya M Ma)
   705 apply (cut_tac x = M and y = Ma in linorder_linear, safe)
   710 apply (metis linorder_not_less order_le_less real_le_trans)
   706 apply (rule_tac x = Ma in exI, clarify)
       
   707 apply (cut_tac x = xb and y = xa in linorder_linear, force)
       
   708 apply (rule_tac x = M in exI, clarify)
       
   709 apply (cut_tac x = xb and y = xa in linorder_linear, force)
       
   710 apply (case_tac "a \<le> x & x \<le> b")
   711 apply (case_tac "a \<le> x & x \<le> b")
   711 apply (rule_tac [2] x = 1 in exI)
   712  prefer 2
   712 prefer 2 apply force
   713  apply (rule_tac x = 1 in exI, force)
   713 apply (simp add: LIM_eq isCont_iff)
   714 apply (simp add: LIM_eq isCont_iff)
   714 apply (drule_tac x = x in spec, auto)
   715 apply (drule_tac x = x in spec, auto)
   715 apply (erule_tac V = "\<forall>M. \<exists>x. a \<le> x & x \<le> b & ~ f x \<le> M" in thin_rl)
   716 apply (erule_tac V = "\<forall>M. \<exists>x. a \<le> x & x \<le> b & ~ f x \<le> M" in thin_rl)
   716 apply (drule_tac x = 1 in spec, auto)
   717 apply (drule_tac x = 1 in spec, auto)
   717 apply (rule_tac x = s in exI, clarify)
   718 apply (rule_tac x = s in exI, clarify)
   813 
   814 
   814 subsection {* Local extrema *}
   815 subsection {* Local extrema *}
   815 
   816 
   816 text{*If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right*}
   817 text{*If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right*}
   817 
   818 
   818 lemma DERIV_left_inc:
   819 lemma DERIV_pos_inc_right:
   819   fixes f :: "real => real"
   820   fixes f :: "real => real"
   820   assumes der: "DERIV f x :> l"
   821   assumes der: "DERIV f x :> l"
   821       and l:   "0 < l"
   822       and l:   "0 < l"
   822   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x + h)"
   823   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x + h)"
   823 proof -
   824 proof -
   843   by (simp add: pos_less_divide_eq h)
   844   by (simp add: pos_less_divide_eq h)
   844     qed
   845     qed
   845   qed
   846   qed
   846 qed
   847 qed
   847 
   848 
   848 lemma DERIV_left_dec:
   849 lemma DERIV_neg_dec_left:
   849   fixes f :: "real => real"
   850   fixes f :: "real => real"
   850   assumes der: "DERIV f x :> l"
   851   assumes der: "DERIV f x :> l"
   851       and l:   "l < 0"
   852       and l:   "l < 0"
   852   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x-h)"
   853   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x-h)"
   853 proof -
   854 proof -
   873   by (simp add: pos_less_divide_eq h)
   874   by (simp add: pos_less_divide_eq h)
   874     qed
   875     qed
   875   qed
   876   qed
   876 qed
   877 qed
   877 
   878 
       
   879 
       
   880 lemma DERIV_pos_inc_left:
       
   881   fixes f :: "real => real"
       
   882   shows "DERIV f x :> l \<Longrightarrow> 0 < l \<Longrightarrow> \<exists>d > 0. \<forall>h > 0. h < d --> f(x - h) < f(x)"
       
   883   apply (rule DERIV_neg_dec_left [of "%x. - f x" x "-l", simplified])
       
   884   apply (auto simp add: DERIV_minus) 
       
   885   done
       
   886 
       
   887 lemma DERIV_neg_dec_right:
       
   888   fixes f :: "real => real"
       
   889   shows "DERIV f x :> l \<Longrightarrow> l < 0 \<Longrightarrow> \<exists>d > 0. \<forall>h > 0. h < d --> f(x) > f(x + h)"
       
   890   apply (rule DERIV_pos_inc_right [of "%x. - f x" x "-l", simplified])
       
   891   apply (auto simp add: DERIV_minus) 
       
   892   done
       
   893 
   878 lemma DERIV_local_max:
   894 lemma DERIV_local_max:
   879   fixes f :: "real => real"
   895   fixes f :: "real => real"
   880   assumes der: "DERIV f x :> l"
   896   assumes der: "DERIV f x :> l"
   881       and d:   "0 < d"
   897       and d:   "0 < d"
   882       and le:  "\<forall>y. \<bar>x-y\<bar> < d --> f(y) \<le> f(x)"
   898       and le:  "\<forall>y. \<bar>x-y\<bar> < d --> f(y) \<le> f(x)"
   883   shows "l = 0"
   899   shows "l = 0"
   884 proof (cases rule: linorder_cases [of l 0])
   900 proof (cases rule: linorder_cases [of l 0])
   885   case equal thus ?thesis .
   901   case equal thus ?thesis .
   886 next
   902 next
   887   case less
   903   case less
   888   from DERIV_left_dec [OF der less]
   904   from DERIV_neg_dec_left [OF der less]
   889   obtain d' where d': "0 < d'"
   905   obtain d' where d': "0 < d'"
   890              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x-h)" by blast
   906              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x-h)" by blast
   891   from real_lbound_gt_zero [OF d d']
   907   from real_lbound_gt_zero [OF d d']
   892   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
   908   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
   893   with lt le [THEN spec [where x="x-e"]]
   909   with lt le [THEN spec [where x="x-e"]]
   894   show ?thesis by (auto simp add: abs_if)
   910   show ?thesis by (auto simp add: abs_if)
   895 next
   911 next
   896   case greater
   912   case greater
   897   from DERIV_left_inc [OF der greater]
   913   from DERIV_pos_inc_right [OF der greater]
   898   obtain d' where d': "0 < d'"
   914   obtain d' where d': "0 < d'"
   899              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x + h)" by blast
   915              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x + h)" by blast
   900   from real_lbound_gt_zero [OF d d']
   916   from real_lbound_gt_zero [OF d d']
   901   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
   917   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
   902   with lt le [THEN spec [where x="x+e"]]
   918   with lt le [THEN spec [where x="x+e"]]
  1203   moreover have " (v ((b + a) / 2) - v a) / ((b + a) / 2 - a) = k"
  1219   moreover have " (v ((b + a) / 2) - v a) / ((b + a) / 2 - a) = k"
  1204     by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq)
  1220     by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq)
  1205   ultimately show ?thesis using neq by (force simp add: add_commute)
  1221   ultimately show ?thesis using neq by (force simp add: add_commute)
  1206 qed
  1222 qed
  1207 
  1223 
       
  1224 (* A function with positive derivative is increasing. 
       
  1225    A simple proof using the MVT, by Jeremy Avigad. And variants.
       
  1226 *)
       
  1227 
       
  1228 lemma DERIV_pos_imp_increasing:
       
  1229   fixes a::real and b::real and f::"real => real"
       
  1230   assumes "a < b" and "\<forall>x. a \<le> x & x \<le> b --> (EX y. DERIV f x :> y & y > 0)"
       
  1231   shows "f a < f b"
       
  1232 proof (rule ccontr)
       
  1233   assume "~ f a < f b"
       
  1234   from assms have "EX l z. a < z & z < b & DERIV f z :> l
       
  1235       & f b - f a = (b - a) * l"
       
  1236     by (metis MVT DERIV_isCont differentiableI real_less_def)
       
  1237   then obtain l z where "a < z" and "z < b" and "DERIV f z :> l"
       
  1238       and "f b - f a = (b - a) * l"
       
  1239     by auto
       
  1240   
       
  1241   from prems have "~(l > 0)"
       
  1242     by (metis assms(1) linorder_not_le mult_le_0_iff real_le_eq_diff)
       
  1243   with prems show False
       
  1244     by (metis DERIV_unique real_less_def)
       
  1245 qed
       
  1246 
       
  1247 
       
  1248 lemma DERIV_nonneg_imp_nonincreasing:
       
  1249   fixes a::real and b::real and f::"real => real"
       
  1250   assumes "a \<le> b" and
       
  1251     "\<forall>x. a \<le> x & x \<le> b --> (\<exists>y. DERIV f x :> y & y \<ge> 0)"
       
  1252   shows "f a \<le> f b"
       
  1253 proof (rule ccontr, cases "a = b")
       
  1254   assume "~ f a \<le> f b"
       
  1255   assume "a = b"
       
  1256   with prems show False by auto
       
  1257   next assume "~ f a \<le> f b"
       
  1258   assume "a ~= b"
       
  1259   with assms have "EX l z. a < z & z < b & DERIV f z :> l
       
  1260       & f b - f a = (b - a) * l"
       
  1261     apply (intro MVT)
       
  1262     apply auto
       
  1263     apply (metis DERIV_isCont)
       
  1264     apply (metis differentiableI real_less_def)
       
  1265     done
       
  1266   then obtain l z where "a < z" and "z < b" and "DERIV f z :> l"
       
  1267       and "f b - f a = (b - a) * l"
       
  1268     by auto
       
  1269   from prems have "~(l >= 0)"
       
  1270     by (metis diff_self le_eqI le_iff_diff_le_0 real_le_anti_sym real_le_linear
       
  1271               split_mult_pos_le)
       
  1272   with prems show False
       
  1273     by (metis DERIV_unique order_less_imp_le)
       
  1274 qed
       
  1275 
       
  1276 lemma DERIV_neg_imp_decreasing:
       
  1277   fixes a::real and b::real and f::"real => real"
       
  1278   assumes "a < b" and
       
  1279     "\<forall>x. a \<le> x & x \<le> b --> (\<exists>y. DERIV f x :> y & y < 0)"
       
  1280   shows "f a > f b"
       
  1281 proof -
       
  1282   have "(%x. -f x) a < (%x. -f x) b"
       
  1283     apply (rule DERIV_pos_imp_increasing [of a b "%x. -f x"])
       
  1284     apply (insert prems, auto)
       
  1285     apply (metis DERIV_minus neg_0_less_iff_less)
       
  1286     done
       
  1287   thus ?thesis
       
  1288     by simp
       
  1289 qed
       
  1290 
       
  1291 lemma DERIV_nonpos_imp_nonincreasing:
       
  1292   fixes a::real and b::real and f::"real => real"
       
  1293   assumes "a \<le> b" and
       
  1294     "\<forall>x. a \<le> x & x \<le> b --> (\<exists>y. DERIV f x :> y & y \<le> 0)"
       
  1295   shows "f a \<ge> f b"
       
  1296 proof -
       
  1297   have "(%x. -f x) a \<le> (%x. -f x) b"
       
  1298     apply (rule DERIV_nonneg_imp_nonincreasing [of a b "%x. -f x"])
       
  1299     apply (insert prems, auto)
       
  1300     apply (metis DERIV_minus neg_0_le_iff_le)
       
  1301     done
       
  1302   thus ?thesis
       
  1303     by simp
       
  1304 qed
  1208 
  1305 
  1209 subsection {* Continuous injective functions *}
  1306 subsection {* Continuous injective functions *}
  1210 
  1307 
  1211 text{*Dull lemma: an continuous injection on an interval must have a
  1308 text{*Dull lemma: an continuous injection on an interval must have a
  1212 strict maximum at an end point, not in the middle.*}
  1309 strict maximum at an end point, not in the middle.*}