author  hoelzl 
Tue, 21 Dec 2010 15:00:59 +0100  
changeset 41368  8afa26855137 
parent 37891  c26f9d06e82c 
child 41550  efa734d9b221 
permissions  rwrr 
21164  1 
(* Title : Deriv.thy 
2 
Author : Jacques D. Fleuriot 

3 
Copyright : 1998 University of Cambridge 

4 
Conversion to Isar and new proofs by Lawrence C Paulson, 2004 

5 
GMVT by Benjamin Porter, 2005 

6 
*) 

7 

8 
header{* Differentiation *} 

9 

10 
theory Deriv 

29987  11 
imports Lim 
21164  12 
begin 
13 

22984  14 
text{*Standard Definitions*} 
21164  15 

16 
definition 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

17 
deriv :: "['a::real_normed_field \<Rightarrow> 'a, 'a, 'a] \<Rightarrow> bool" 
21164  18 
{*Differentiation: D is derivative of function f at x*} 
21404
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
wenzelm
parents:
21239
diff
changeset

19 
("(DERIV (_)/ (_)/ :> (_))" [1000, 1000, 60] 60) where 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

20 
"DERIV f x :> D = ((%h. (f(x + h)  f x) / h)  0 > D)" 
21164  21 

22 
primrec 

34941  23 
Bolzano_bisect :: "(real \<times> real \<Rightarrow> bool) \<Rightarrow> real \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> real \<times> real" where 
24 
"Bolzano_bisect P a b 0 = (a, b)" 

25 
 "Bolzano_bisect P a b (Suc n) = 

26 
(let (x, y) = Bolzano_bisect P a b n 

27 
in if P (x, (x+y) / 2) then ((x+y)/2, y) 

28 
else (x, (x+y)/2))" 

21164  29 

30 

31 
subsection {* Derivatives *} 

32 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

33 
lemma DERIV_iff: "(DERIV f x :> D) = ((%h. (f(x + h)  f(x))/h)  0 > D)" 
21164  34 
by (simp add: deriv_def) 
35 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

36 
lemma DERIV_D: "DERIV f x :> D ==> (%h. (f(x + h)  f(x))/h)  0 > D" 
21164  37 
by (simp add: deriv_def) 
38 

39 
lemma DERIV_const [simp]: "DERIV (\<lambda>x. k) x :> 0" 

40 
by (simp add: deriv_def) 

41 

23069
cdfff0241c12
rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents:
23044
diff
changeset

42 
lemma DERIV_ident [simp]: "DERIV (\<lambda>x. x) x :> 1" 
23398  43 
by (simp add: deriv_def cong: LIM_cong) 
21164  44 

45 
lemma add_diff_add: 

46 
fixes a b c d :: "'a::ab_group_add" 

47 
shows "(a + c)  (b + d) = (a  b) + (c  d)" 

48 
by simp 

49 

50 
lemma DERIV_add: 

51 
"\<lbrakk>DERIV f x :> D; DERIV g x :> E\<rbrakk> \<Longrightarrow> DERIV (\<lambda>x. f x + g x) x :> D + E" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

52 
by (simp only: deriv_def add_diff_add add_divide_distrib LIM_add) 
21164  53 

54 
lemma DERIV_minus: 

55 
"DERIV f x :> D \<Longrightarrow> DERIV (\<lambda>x.  f x) x :>  D" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

56 
by (simp only: deriv_def minus_diff_minus divide_minus_left LIM_minus) 
21164  57 

58 
lemma DERIV_diff: 

59 
"\<lbrakk>DERIV f x :> D; DERIV g x :> E\<rbrakk> \<Longrightarrow> DERIV (\<lambda>x. f x  g x) x :> D  E" 

37887  60 
by (simp only: diff_minus DERIV_add DERIV_minus) 
21164  61 

62 
lemma DERIV_add_minus: 

63 
"\<lbrakk>DERIV f x :> D; DERIV g x :> E\<rbrakk> \<Longrightarrow> DERIV (\<lambda>x. f x +  g x) x :> D +  E" 

64 
by (simp only: DERIV_add DERIV_minus) 

65 

66 
lemma DERIV_isCont: "DERIV f x :> D \<Longrightarrow> isCont f x" 

67 
proof (unfold isCont_iff) 

68 
assume "DERIV f x :> D" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

69 
hence "(\<lambda>h. (f(x+h)  f(x)) / h)  0 > D" 
21164  70 
by (rule DERIV_D) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

71 
hence "(\<lambda>h. (f(x+h)  f(x)) / h * h)  0 > D * 0" 
23069
cdfff0241c12
rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents:
23044
diff
changeset

72 
by (intro LIM_mult LIM_ident) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

73 
hence "(\<lambda>h. (f(x+h)  f(x)) * (h / h))  0 > 0" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

74 
by simp 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

75 
hence "(\<lambda>h. f(x+h)  f(x))  0 > 0" 
23398  76 
by (simp cong: LIM_cong) 
21164  77 
thus "(\<lambda>h. f(x+h))  0 > f(x)" 
31338
d41a8ba25b67
generalize constants from Lim.thy to class metric_space
huffman
parents:
31336
diff
changeset

78 
by (simp add: LIM_def dist_norm) 
21164  79 
qed 
80 

81 
lemma DERIV_mult_lemma: 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

82 
fixes a b c d :: "'a::real_field" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

83 
shows "(a * b  c * d) / h = a * ((b  d) / h) + ((a  c) / h) * d" 
23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23441
diff
changeset

84 
by (simp add: diff_minus add_divide_distrib [symmetric] ring_distribs) 
21164  85 

86 
lemma DERIV_mult': 

87 
assumes f: "DERIV f x :> D" 

88 
assumes g: "DERIV g x :> E" 

89 
shows "DERIV (\<lambda>x. f x * g x) x :> f x * E + D * g x" 

90 
proof (unfold deriv_def) 

91 
from f have "isCont f x" 

92 
by (rule DERIV_isCont) 

93 
hence "(\<lambda>h. f(x+h))  0 > f x" 

94 
by (simp only: isCont_iff) 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

95 
hence "(\<lambda>h. f(x+h) * ((g(x+h)  g x) / h) + 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

96 
((f(x+h)  f x) / h) * g x) 
21164  97 
 0 > f x * E + D * g x" 
22613  98 
by (intro LIM_add LIM_mult LIM_const DERIV_D f g) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

99 
thus "(\<lambda>h. (f(x+h) * g(x+h)  f x * g x) / h) 
21164  100 
 0 > f x * E + D * g x" 
101 
by (simp only: DERIV_mult_lemma) 

102 
qed 

103 

104 
lemma DERIV_mult: 

105 
"[ DERIV f x :> Da; DERIV g x :> Db ] 

106 
==> DERIV (%x. f x * g x) x :> (Da * g(x)) + (Db * f(x))" 

107 
by (drule (1) DERIV_mult', simp only: mult_commute add_commute) 

108 

109 
lemma DERIV_unique: 

110 
"[ DERIV f x :> D; DERIV f x :> E ] ==> D = E" 

111 
apply (simp add: deriv_def) 

112 
apply (blast intro: LIM_unique) 

113 
done 

114 

115 
text{*Differentiation of finite sum*} 

116 

31880  117 
lemma DERIV_setsum: 
118 
assumes "finite S" 

119 
and "\<And> n. n \<in> S \<Longrightarrow> DERIV (%x. f x n) x :> (f' x n)" 

120 
shows "DERIV (%x. setsum (f x) S) x :> setsum (f' x) S" 

121 
using assms by induct (auto intro!: DERIV_add) 

122 

21164  123 
lemma DERIV_sumr [rule_format (no_asm)]: 
124 
"(\<forall>r. m \<le> r & r < (m + n) > DERIV (%x. f r x) x :> (f' r x)) 

125 
> DERIV (%x. \<Sum>n=m..<n::nat. f n x :: real) x :> (\<Sum>r=m..<n. f' r x)" 

31880  126 
by (auto intro: DERIV_setsum) 
21164  127 

128 
text{*Alternative definition for differentiability*} 

129 

130 
lemma DERIV_LIM_iff: 

31338
d41a8ba25b67
generalize constants from Lim.thy to class metric_space
huffman
parents:
31336
diff
changeset

131 
fixes f :: "'a::{real_normed_vector,inverse} \<Rightarrow> 'a" shows 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

132 
"((%h. (f(a + h)  f(a)) / h)  0 > D) = 
21164  133 
((%x. (f(x)f(a)) / (xa))  a > D)" 
134 
apply (rule iffI) 

135 
apply (drule_tac k=" a" in LIM_offset) 

136 
apply (simp add: diff_minus) 

137 
apply (drule_tac k="a" in LIM_offset) 

138 
apply (simp add: add_commute) 

139 
done 

140 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

141 
lemma DERIV_iff2: "(DERIV f x :> D) = ((%z. (f(z)  f(x)) / (zx))  x > D)" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

142 
by (simp add: deriv_def diff_minus [symmetric] DERIV_LIM_iff) 
21164  143 

144 
lemma inverse_diff_inverse: 

145 
"\<lbrakk>(a::'a::division_ring) \<noteq> 0; b \<noteq> 0\<rbrakk> 

146 
\<Longrightarrow> inverse a  inverse b =  (inverse a * (a  b) * inverse b)" 

29667  147 
by (simp add: algebra_simps) 
21164  148 

149 
lemma DERIV_inverse_lemma: 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

150 
"\<lbrakk>a \<noteq> 0; b \<noteq> (0::'a::real_normed_field)\<rbrakk> 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

151 
\<Longrightarrow> (inverse a  inverse b) / h 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

152 
=  (inverse a * ((a  b) / h) * inverse b)" 
21164  153 
by (simp add: inverse_diff_inverse) 
154 

155 
lemma DERIV_inverse': 

156 
assumes der: "DERIV f x :> D" 

157 
assumes neq: "f x \<noteq> 0" 

158 
shows "DERIV (\<lambda>x. inverse (f x)) x :>  (inverse (f x) * D * inverse (f x))" 

159 
(is "DERIV _ _ :> ?E") 

160 
proof (unfold DERIV_iff2) 

161 
from der have lim_f: "f  x > f x" 

162 
by (rule DERIV_isCont [unfolded isCont_def]) 

163 

164 
from neq have "0 < norm (f x)" by simp 

165 
with LIM_D [OF lim_f] obtain s 

166 
where s: "0 < s" 

167 
and less_fx: "\<And>z. \<lbrakk>z \<noteq> x; norm (z  x) < s\<rbrakk> 

168 
\<Longrightarrow> norm (f z  f x) < norm (f x)" 

169 
by fast 

170 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

171 
show "(\<lambda>z. (inverse (f z)  inverse (f x)) / (z  x))  x > ?E" 
21164  172 
proof (rule LIM_equal2 [OF s]) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

173 
fix z 
21164  174 
assume "z \<noteq> x" "norm (z  x) < s" 
175 
hence "norm (f z  f x) < norm (f x)" by (rule less_fx) 

176 
hence "f z \<noteq> 0" by auto 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

177 
thus "(inverse (f z)  inverse (f x)) / (z  x) = 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

178 
 (inverse (f z) * ((f z  f x) / (z  x)) * inverse (f x))" 
21164  179 
using neq by (rule DERIV_inverse_lemma) 
180 
next 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

181 
from der have "(\<lambda>z. (f z  f x) / (z  x))  x > D" 
21164  182 
by (unfold DERIV_iff2) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

183 
thus "(\<lambda>z.  (inverse (f z) * ((f z  f x) / (z  x)) * inverse (f x))) 
21164  184 
 x > ?E" 
22613  185 
by (intro LIM_mult LIM_inverse LIM_minus LIM_const lim_f neq) 
21164  186 
qed 
187 
qed 

188 

189 
lemma DERIV_divide: 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

190 
"\<lbrakk>DERIV f x :> D; DERIV g x :> E; g x \<noteq> 0\<rbrakk> 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

191 
\<Longrightarrow> DERIV (\<lambda>x. f x / g x) x :> (D * g x  f x * E) / (g x * g x)" 
21164  192 
apply (subgoal_tac "f x *  (inverse (g x) * E * inverse (g x)) + 
193 
D * inverse (g x) = (D * g x  f x * E) / (g x * g x)") 

194 
apply (erule subst) 

195 
apply (unfold divide_inverse) 

196 
apply (erule DERIV_mult') 

197 
apply (erule (1) DERIV_inverse') 

23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23441
diff
changeset

198 
apply (simp add: ring_distribs nonzero_inverse_mult_distrib) 
21164  199 
apply (simp add: mult_ac) 
200 
done 

201 

202 
lemma DERIV_power_Suc: 

31017  203 
fixes f :: "'a \<Rightarrow> 'a::{real_normed_field}" 
21164  204 
assumes f: "DERIV f x :> D" 
23431
25ca91279a9b
change simp rules for of_nat to work like int did previously (reorient of_nat_Suc, remove of_nat_mult [simp]); preserve original variable names in legacy int theorems
huffman
parents:
23413
diff
changeset

205 
shows "DERIV (\<lambda>x. f x ^ Suc n) x :> (1 + of_nat n) * (D * f x ^ n)" 
21164  206 
proof (induct n) 
207 
case 0 

30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

208 
show ?case by (simp add: f) 
21164  209 
case (Suc k) 
210 
from DERIV_mult' [OF f Suc] show ?case 

23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23441
diff
changeset

211 
apply (simp only: of_nat_Suc ring_distribs mult_1_left) 
29667  212 
apply (simp only: power_Suc algebra_simps) 
21164  213 
done 
214 
qed 

215 

216 
lemma DERIV_power: 

31017  217 
fixes f :: "'a \<Rightarrow> 'a::{real_normed_field}" 
21164  218 
assumes f: "DERIV f x :> D" 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

219 
shows "DERIV (\<lambda>x. f x ^ n) x :> of_nat n * (D * f x ^ (n  Suc 0))" 
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

220 
by (cases "n", simp, simp add: DERIV_power_Suc f del: power_Suc) 
21164  221 

29975  222 
text {* Caratheodory formulation of derivative at a point *} 
21164  223 

224 
lemma CARAT_DERIV: 

225 
"(DERIV f x :> l) = 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

226 
(\<exists>g. (\<forall>z. f z  f x = g z * (zx)) & isCont g x & g x = l)" 
21164  227 
(is "?lhs = ?rhs") 
228 
proof 

229 
assume der: "DERIV f x :> l" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

230 
show "\<exists>g. (\<forall>z. f z  f x = g z * (zx)) \<and> isCont g x \<and> g x = l" 
21164  231 
proof (intro exI conjI) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

232 
let ?g = "(%z. if z = x then l else (f z  f x) / (zx))" 
23413
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
nipkow
parents:
23412
diff
changeset

233 
show "\<forall>z. f z  f x = ?g z * (zx)" by simp 
21164  234 
show "isCont ?g x" using der 
235 
by (simp add: isCont_iff DERIV_iff diff_minus 

236 
cong: LIM_equal [rule_format]) 

237 
show "?g x = l" by simp 

238 
qed 

239 
next 

240 
assume "?rhs" 

241 
then obtain g where 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

242 
"(\<forall>z. f z  f x = g z * (zx))" and "isCont g x" and "g x = l" by blast 
21164  243 
thus "(DERIV f x :> l)" 
23413
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
nipkow
parents:
23412
diff
changeset

244 
by (auto simp add: isCont_iff DERIV_iff cong: LIM_cong) 
21164  245 
qed 
246 

247 
lemma DERIV_chain': 

248 
assumes f: "DERIV f x :> D" 

249 
assumes g: "DERIV g (f x) :> E" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

250 
shows "DERIV (\<lambda>x. g (f x)) x :> E * D" 
21164  251 
proof (unfold DERIV_iff2) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

252 
obtain d where d: "\<forall>y. g y  g (f x) = d y * (y  f x)" 
21164  253 
and cont_d: "isCont d (f x)" and dfx: "d (f x) = E" 
254 
using CARAT_DERIV [THEN iffD1, OF g] by fast 

255 
from f have "f  x > f x" 

256 
by (rule DERIV_isCont [unfolded isCont_def]) 

257 
with cont_d have "(\<lambda>z. d (f z))  x > d (f x)" 

21239  258 
by (rule isCont_LIM_compose) 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

259 
hence "(\<lambda>z. d (f z) * ((f z  f x) / (z  x))) 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

260 
 x > d (f x) * D" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

261 
by (rule LIM_mult [OF _ f [unfolded DERIV_iff2]]) 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

262 
thus "(\<lambda>z. (g (f z)  g (f x)) / (z  x))  x > E * D" 
35216  263 
by (simp add: d dfx) 
21164  264 
qed 
265 

31899  266 
text {* 
267 
Let's do the standard proof, though theorem 

268 
@{text "LIM_mult2"} follows from a NS proof 

269 
*} 

21164  270 

271 
lemma DERIV_cmult: 

272 
"DERIV f x :> D ==> DERIV (%x. c * f x) x :> c*D" 

273 
by (drule DERIV_mult' [OF DERIV_const], simp) 

274 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

275 
lemma DERIV_cdivide: "DERIV f x :> D ==> DERIV (%x. f x / c) x :> D / c" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

276 
apply (subgoal_tac "DERIV (%x. (1 / c) * f x) x :> (1 / c) * D", force) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

277 
apply (erule DERIV_cmult) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

278 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

279 

31899  280 
text {* Standard version *} 
21164  281 
lemma DERIV_chain: "[ DERIV f (g x) :> Da; DERIV g x :> Db ] ==> DERIV (f o g) x :> Da * Db" 
35216  282 
by (drule (1) DERIV_chain', simp add: o_def mult_commute) 
21164  283 

284 
lemma DERIV_chain2: "[ DERIV f (g x) :> Da; DERIV g x :> Db ] ==> DERIV (%x. f (g x)) x :> Da * Db" 

285 
by (auto dest: DERIV_chain simp add: o_def) 

286 

31899  287 
text {* Derivative of linear multiplication *} 
21164  288 
lemma DERIV_cmult_Id [simp]: "DERIV (op * c) x :> c" 
23069
cdfff0241c12
rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents:
23044
diff
changeset

289 
by (cut_tac c = c and x = x in DERIV_ident [THEN DERIV_cmult], simp) 
21164  290 

291 
lemma DERIV_pow: "DERIV (%x. x ^ n) x :> real n * (x ^ (n  Suc 0))" 

23069
cdfff0241c12
rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents:
23044
diff
changeset

292 
apply (cut_tac DERIV_power [OF DERIV_ident]) 
35216  293 
apply (simp add: real_of_nat_def) 
21164  294 
done 
295 

31899  296 
text {* Power of @{text "1"} *} 
21164  297 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

298 
lemma DERIV_inverse: 
31017  299 
fixes x :: "'a::{real_normed_field}" 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

300 
shows "x \<noteq> 0 ==> DERIV (%x. inverse(x)) x :> ((inverse x ^ Suc (Suc 0)))" 
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

301 
by (drule DERIV_inverse' [OF DERIV_ident]) simp 
21164  302 

31899  303 
text {* Derivative of inverse *} 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

304 
lemma DERIV_inverse_fun: 
31017  305 
fixes x :: "'a::{real_normed_field}" 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

306 
shows "[ DERIV f x :> d; f(x) \<noteq> 0 ] 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

307 
==> DERIV (%x. inverse(f x)) x :> ( (d * inverse(f(x) ^ Suc (Suc 0))))" 
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

308 
by (drule (1) DERIV_inverse') (simp add: mult_ac nonzero_inverse_mult_distrib) 
21164  309 

31899  310 
text {* Derivative of quotient *} 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

311 
lemma DERIV_quotient: 
31017  312 
fixes x :: "'a::{real_normed_field}" 
21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

313 
shows "[ DERIV f x :> d; DERIV g x :> e; g(x) \<noteq> 0 ] 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

314 
==> DERIV (%y. f(y) / (g y)) x :> (d*g(x)  (e*f(x))) / (g(x) ^ Suc (Suc 0))" 
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

315 
by (drule (2) DERIV_divide) (simp add: mult_commute) 
21164  316 

29975  317 
lemma lemma_DERIV_subst: "[ DERIV f x :> D; D = E ] ==> DERIV f x :> E" 
318 
by auto 

319 

31899  320 
text {* @{text "DERIV_intros"} *} 
321 
ML {* 

31902  322 
structure Deriv_Intros = Named_Thms 
31899  323 
( 
324 
val name = "DERIV_intros" 

325 
val description = "DERIV introduction rules" 

326 
) 

327 
*} 

31880  328 

31902  329 
setup Deriv_Intros.setup 
31880  330 

331 
lemma DERIV_cong: "\<lbrakk> DERIV f x :> X ; X = Y \<rbrakk> \<Longrightarrow> DERIV f x :> Y" 

332 
by simp 

333 

334 
declare 

335 
DERIV_const[THEN DERIV_cong, DERIV_intros] 

336 
DERIV_ident[THEN DERIV_cong, DERIV_intros] 

337 
DERIV_add[THEN DERIV_cong, DERIV_intros] 

338 
DERIV_minus[THEN DERIV_cong, DERIV_intros] 

339 
DERIV_mult[THEN DERIV_cong, DERIV_intros] 

340 
DERIV_diff[THEN DERIV_cong, DERIV_intros] 

341 
DERIV_inverse'[THEN DERIV_cong, DERIV_intros] 

342 
DERIV_divide[THEN DERIV_cong, DERIV_intros] 

343 
DERIV_power[where 'a=real, THEN DERIV_cong, 

344 
unfolded real_of_nat_def[symmetric], DERIV_intros] 

345 
DERIV_setsum[THEN DERIV_cong, DERIV_intros] 

22984  346 

31899  347 

22984  348 
subsection {* Differentiability predicate *} 
21164  349 

29169  350 
definition 
351 
differentiable :: "['a::real_normed_field \<Rightarrow> 'a, 'a] \<Rightarrow> bool" 

352 
(infixl "differentiable" 60) where 

353 
"f differentiable x = (\<exists>D. DERIV f x :> D)" 

354 

355 
lemma differentiableE [elim?]: 

356 
assumes "f differentiable x" 

357 
obtains df where "DERIV f x :> df" 

358 
using prems unfolding differentiable_def .. 

359 

21164  360 
lemma differentiableD: "f differentiable x ==> \<exists>D. DERIV f x :> D" 
361 
by (simp add: differentiable_def) 

362 

363 
lemma differentiableI: "DERIV f x :> D ==> f differentiable x" 

364 
by (force simp add: differentiable_def) 

365 

29169  366 
lemma differentiable_ident [simp]: "(\<lambda>x. x) differentiable x" 
367 
by (rule DERIV_ident [THEN differentiableI]) 

368 

369 
lemma differentiable_const [simp]: "(\<lambda>z. a) differentiable x" 

370 
by (rule DERIV_const [THEN differentiableI]) 

21164  371 

29169  372 
lemma differentiable_compose: 
373 
assumes f: "f differentiable (g x)" 

374 
assumes g: "g differentiable x" 

375 
shows "(\<lambda>x. f (g x)) differentiable x" 

376 
proof  

377 
from `f differentiable (g x)` obtain df where "DERIV f (g x) :> df" .. 

378 
moreover 

379 
from `g differentiable x` obtain dg where "DERIV g x :> dg" .. 

380 
ultimately 

381 
have "DERIV (\<lambda>x. f (g x)) x :> df * dg" by (rule DERIV_chain2) 

382 
thus ?thesis by (rule differentiableI) 

383 
qed 

384 

385 
lemma differentiable_sum [simp]: 

21164  386 
assumes "f differentiable x" 
387 
and "g differentiable x" 

388 
shows "(\<lambda>x. f x + g x) differentiable x" 

389 
proof  

29169  390 
from `f differentiable x` obtain df where "DERIV f x :> df" .. 
391 
moreover 

392 
from `g differentiable x` obtain dg where "DERIV g x :> dg" .. 

393 
ultimately 

394 
have "DERIV (\<lambda>x. f x + g x) x :> df + dg" by (rule DERIV_add) 

395 
thus ?thesis by (rule differentiableI) 

396 
qed 

397 

398 
lemma differentiable_minus [simp]: 

399 
assumes "f differentiable x" 

400 
shows "(\<lambda>x.  f x) differentiable x" 

401 
proof  

402 
from `f differentiable x` obtain df where "DERIV f x :> df" .. 

403 
hence "DERIV (\<lambda>x.  f x) x :>  df" by (rule DERIV_minus) 

404 
thus ?thesis by (rule differentiableI) 

21164  405 
qed 
406 

29169  407 
lemma differentiable_diff [simp]: 
21164  408 
assumes "f differentiable x" 
29169  409 
assumes "g differentiable x" 
21164  410 
shows "(\<lambda>x. f x  g x) differentiable x" 
29169  411 
unfolding diff_minus using prems by simp 
412 

413 
lemma differentiable_mult [simp]: 

414 
assumes "f differentiable x" 

415 
assumes "g differentiable x" 

416 
shows "(\<lambda>x. f x * g x) differentiable x" 

21164  417 
proof  
29169  418 
from `f differentiable x` obtain df where "DERIV f x :> df" .. 
21164  419 
moreover 
29169  420 
from `g differentiable x` obtain dg where "DERIV g x :> dg" .. 
421 
ultimately 

422 
have "DERIV (\<lambda>x. f x * g x) x :> df * g x + dg * f x" by (rule DERIV_mult) 

423 
thus ?thesis by (rule differentiableI) 

21164  424 
qed 
425 

29169  426 
lemma differentiable_inverse [simp]: 
427 
assumes "f differentiable x" and "f x \<noteq> 0" 

428 
shows "(\<lambda>x. inverse (f x)) differentiable x" 

21164  429 
proof  
29169  430 
from `f differentiable x` obtain df where "DERIV f x :> df" .. 
431 
hence "DERIV (\<lambda>x. inverse (f x)) x :>  (inverse (f x) * df * inverse (f x))" 

432 
using `f x \<noteq> 0` by (rule DERIV_inverse') 

433 
thus ?thesis by (rule differentiableI) 

21164  434 
qed 
435 

29169  436 
lemma differentiable_divide [simp]: 
437 
assumes "f differentiable x" 

438 
assumes "g differentiable x" and "g x \<noteq> 0" 

439 
shows "(\<lambda>x. f x / g x) differentiable x" 

440 
unfolding divide_inverse using prems by simp 

441 

442 
lemma differentiable_power [simp]: 

31017  443 
fixes f :: "'a::{real_normed_field} \<Rightarrow> 'a" 
29169  444 
assumes "f differentiable x" 
445 
shows "(\<lambda>x. f x ^ n) differentiable x" 

30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant typespecific versions of power_Suc
huffman
parents:
30242
diff
changeset

446 
by (induct n, simp, simp add: prems) 
29169  447 

22984  448 

21164  449 
subsection {* Nested Intervals and Bisection *} 
450 

451 
text{*Lemmas about nested intervals and proof by bisection (cf.Harrison). 

452 
All considerably tidied by lcp.*} 

453 

454 
lemma lemma_f_mono_add [rule_format (no_asm)]: "(\<forall>n. (f::nat=>real) n \<le> f (Suc n)) > f m \<le> f(m + no)" 

455 
apply (induct "no") 

456 
apply (auto intro: order_trans) 

457 
done 

458 

459 
lemma f_inc_g_dec_Beq_f: "[ \<forall>n. f(n) \<le> f(Suc n); 

460 
\<forall>n. g(Suc n) \<le> g(n); 

461 
\<forall>n. f(n) \<le> g(n) ] 

462 
==> Bseq (f :: nat \<Rightarrow> real)" 

463 
apply (rule_tac k = "f 0" and K = "g 0" in BseqI2, rule allI) 

464 
apply (induct_tac "n") 

465 
apply (auto intro: order_trans) 

466 
apply (rule_tac y = "g (Suc na)" in order_trans) 

467 
apply (induct_tac [2] "na") 

468 
apply (auto intro: order_trans) 

469 
done 

470 

471 
lemma f_inc_g_dec_Beq_g: "[ \<forall>n. f(n) \<le> f(Suc n); 

472 
\<forall>n. g(Suc n) \<le> g(n); 

473 
\<forall>n. f(n) \<le> g(n) ] 

474 
==> Bseq (g :: nat \<Rightarrow> real)" 

475 
apply (subst Bseq_minus_iff [symmetric]) 

476 
apply (rule_tac g = "%x.  (f x)" in f_inc_g_dec_Beq_f) 

477 
apply auto 

478 
done 

479 

480 
lemma f_inc_imp_le_lim: 

481 
fixes f :: "nat \<Rightarrow> real" 

482 
shows "\<lbrakk>\<forall>n. f n \<le> f (Suc n); convergent f\<rbrakk> \<Longrightarrow> f n \<le> lim f" 

483 
apply (rule linorder_not_less [THEN iffD1]) 

484 
apply (auto simp add: convergent_LIMSEQ_iff LIMSEQ_iff monoseq_Suc) 

36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

485 
apply (drule_tac x = "f n  lim f" in spec, clarsimp) 
21164  486 
apply (drule_tac P = "%na. no\<le>na > ?Q na" and x = "no + n" in spec, auto) 
487 
apply (subgoal_tac "lim f \<le> f (no + n) ") 

488 
apply (drule_tac no=no and m=n in lemma_f_mono_add) 

489 
apply (auto simp add: add_commute) 

490 
apply (induct_tac "no") 

491 
apply simp 

492 
apply (auto intro: order_trans simp add: diff_minus abs_if) 

493 
done 

494 

31404  495 
lemma lim_uminus: 
496 
fixes g :: "nat \<Rightarrow> 'a::real_normed_vector" 

497 
shows "convergent g ==> lim (%x.  g x) =  (lim g)" 

21164  498 
apply (rule LIMSEQ_minus [THEN limI]) 
499 
apply (simp add: convergent_LIMSEQ_iff) 

500 
done 

501 

502 
lemma g_dec_imp_lim_le: 

503 
fixes g :: "nat \<Rightarrow> real" 

504 
shows "\<lbrakk>\<forall>n. g (Suc n) \<le> g(n); convergent g\<rbrakk> \<Longrightarrow> lim g \<le> g n" 

505 
apply (subgoal_tac " (g n) \<le>  (lim g) ") 

506 
apply (cut_tac [2] f = "%x.  (g x)" in f_inc_imp_le_lim) 

507 
apply (auto simp add: lim_uminus convergent_minus_iff [symmetric]) 

508 
done 

509 

510 
lemma lemma_nest: "[ \<forall>n. f(n) \<le> f(Suc n); 

511 
\<forall>n. g(Suc n) \<le> g(n); 

512 
\<forall>n. f(n) \<le> g(n) ] 

513 
==> \<exists>l m :: real. l \<le> m & ((\<forall>n. f(n) \<le> l) & f > l) & 

514 
((\<forall>n. m \<le> g(n)) & g > m)" 

515 
apply (subgoal_tac "monoseq f & monoseq g") 

516 
prefer 2 apply (force simp add: LIMSEQ_iff monoseq_Suc) 

517 
apply (subgoal_tac "Bseq f & Bseq g") 

518 
prefer 2 apply (blast intro: f_inc_g_dec_Beq_f f_inc_g_dec_Beq_g) 

519 
apply (auto dest!: Bseq_monoseq_convergent simp add: convergent_LIMSEQ_iff) 

520 
apply (rule_tac x = "lim f" in exI) 

521 
apply (rule_tac x = "lim g" in exI) 

522 
apply (auto intro: LIMSEQ_le) 

523 
apply (auto simp add: f_inc_imp_le_lim g_dec_imp_lim_le convergent_LIMSEQ_iff) 

524 
done 

525 

526 
lemma lemma_nest_unique: "[ \<forall>n. f(n) \<le> f(Suc n); 

527 
\<forall>n. g(Suc n) \<le> g(n); 

528 
\<forall>n. f(n) \<le> g(n); 

529 
(%n. f(n)  g(n)) > 0 ] 

530 
==> \<exists>l::real. ((\<forall>n. f(n) \<le> l) & f > l) & 

531 
((\<forall>n. l \<le> g(n)) & g > l)" 

532 
apply (drule lemma_nest, auto) 

533 
apply (subgoal_tac "l = m") 

534 
apply (drule_tac [2] X = f in LIMSEQ_diff) 

535 
apply (auto intro: LIMSEQ_unique) 

536 
done 

537 

538 
text{*The universal quantifiers below are required for the declaration 

539 
of @{text Bolzano_nest_unique} below.*} 

540 

541 
lemma Bolzano_bisect_le: 

542 
"a \<le> b ==> \<forall>n. fst (Bolzano_bisect P a b n) \<le> snd (Bolzano_bisect P a b n)" 

543 
apply (rule allI) 

544 
apply (induct_tac "n") 

545 
apply (auto simp add: Let_def split_def) 

546 
done 

547 

548 
lemma Bolzano_bisect_fst_le_Suc: "a \<le> b ==> 

549 
\<forall>n. fst(Bolzano_bisect P a b n) \<le> fst (Bolzano_bisect P a b (Suc n))" 

550 
apply (rule allI) 

551 
apply (induct_tac "n") 

552 
apply (auto simp add: Bolzano_bisect_le Let_def split_def) 

553 
done 

554 

555 
lemma Bolzano_bisect_Suc_le_snd: "a \<le> b ==> 

556 
\<forall>n. snd(Bolzano_bisect P a b (Suc n)) \<le> snd (Bolzano_bisect P a b n)" 

557 
apply (rule allI) 

558 
apply (induct_tac "n") 

559 
apply (auto simp add: Bolzano_bisect_le Let_def split_def) 

560 
done 

561 

562 
lemma eq_divide_2_times_iff: "((x::real) = y / (2 * z)) = (2 * x = y/z)" 

563 
apply (auto) 

564 
apply (drule_tac f = "%u. (1/2) *u" in arg_cong) 

565 
apply (simp) 

566 
done 

567 

568 
lemma Bolzano_bisect_diff: 

569 
"a \<le> b ==> 

570 
snd(Bolzano_bisect P a b n)  fst(Bolzano_bisect P a b n) = 

571 
(ba) / (2 ^ n)" 

572 
apply (induct "n") 

573 
apply (auto simp add: eq_divide_2_times_iff add_divide_distrib Let_def split_def) 

574 
done 

575 

576 
lemmas Bolzano_nest_unique = 

577 
lemma_nest_unique 

578 
[OF Bolzano_bisect_fst_le_Suc Bolzano_bisect_Suc_le_snd Bolzano_bisect_le] 

579 

580 

581 
lemma not_P_Bolzano_bisect: 

582 
assumes P: "!!a b c. [ P(a,b); P(b,c); a \<le> b; b \<le> c] ==> P(a,c)" 

583 
and notP: "~ P(a,b)" 

584 
and le: "a \<le> b" 

585 
shows "~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))" 

586 
proof (induct n) 

23441  587 
case 0 show ?case using notP by simp 
21164  588 
next 
589 
case (Suc n) 

590 
thus ?case 

591 
by (auto simp del: surjective_pairing [symmetric] 

592 
simp add: Let_def split_def Bolzano_bisect_le [OF le] 

593 
P [of "fst (Bolzano_bisect P a b n)" _ "snd (Bolzano_bisect P a b n)"]) 

594 
qed 

595 

596 
(*Now we repackage P_prem as a formula*) 

597 
lemma not_P_Bolzano_bisect': 

598 
"[ \<forall>a b c. P(a,b) & P(b,c) & a \<le> b & b \<le> c > P(a,c); 

599 
~ P(a,b); a \<le> b ] ==> 

600 
\<forall>n. ~ P(fst(Bolzano_bisect P a b n), snd(Bolzano_bisect P a b n))" 

601 
by (blast elim!: not_P_Bolzano_bisect [THEN [2] rev_notE]) 

602 

603 

604 

605 
lemma lemma_BOLZANO: 

606 
"[ \<forall>a b c. P(a,b) & P(b,c) & a \<le> b & b \<le> c > P(a,c); 

607 
\<forall>x. \<exists>d::real. 0 < d & 

608 
(\<forall>a b. a \<le> x & x \<le> b & (ba) < d > P(a,b)); 

609 
a \<le> b ] 

610 
==> P(a,b)" 

611 
apply (rule Bolzano_nest_unique [where P1=P, THEN exE], assumption+) 

612 
apply (rule LIMSEQ_minus_cancel) 

613 
apply (simp (no_asm_simp) add: Bolzano_bisect_diff LIMSEQ_divide_realpow_zero) 

614 
apply (rule ccontr) 

615 
apply (drule not_P_Bolzano_bisect', assumption+) 

616 
apply (rename_tac "l") 

617 
apply (drule_tac x = l in spec, clarify) 

31336
e17f13cd1280
generalize constants in SEQ.thy to class metric_space
huffman
parents:
31017
diff
changeset

618 
apply (simp add: LIMSEQ_iff) 
21164  619 
apply (drule_tac P = "%r. 0<r > ?Q r" and x = "d/2" in spec) 
620 
apply (drule_tac P = "%r. 0<r > ?Q r" and x = "d/2" in spec) 

621 
apply (drule real_less_half_sum, auto) 

622 
apply (drule_tac x = "fst (Bolzano_bisect P a b (no + noa))" in spec) 

623 
apply (drule_tac x = "snd (Bolzano_bisect P a b (no + noa))" in spec) 

624 
apply safe 

625 
apply (simp_all (no_asm_simp)) 

626 
apply (rule_tac y = "abs (fst (Bolzano_bisect P a b (no + noa))  l) + abs (snd (Bolzano_bisect P a b (no + noa))  l)" in order_le_less_trans) 

627 
apply (simp (no_asm_simp) add: abs_if) 

628 
apply (rule real_sum_of_halves [THEN subst]) 

629 
apply (rule add_strict_mono) 

630 
apply (simp_all add: diff_minus [symmetric]) 

631 
done 

632 

633 

634 
lemma lemma_BOLZANO2: "((\<forall>a b c. (a \<le> b & b \<le> c & P(a,b) & P(b,c)) > P(a,c)) & 

635 
(\<forall>x. \<exists>d::real. 0 < d & 

636 
(\<forall>a b. a \<le> x & x \<le> b & (ba) < d > P(a,b)))) 

637 
> (\<forall>a b. a \<le> b > P(a,b))" 

638 
apply clarify 

639 
apply (blast intro: lemma_BOLZANO) 

640 
done 

641 

642 

643 
subsection {* Intermediate Value Theorem *} 

644 

645 
text {*Prove Contrapositive by Bisection*} 

646 

647 
lemma IVT: "[ f(a::real) \<le> (y::real); y \<le> f(b); 

648 
a \<le> b; 

649 
(\<forall>x. a \<le> x & x \<le> b > isCont f x) ] 

650 
==> \<exists>x. a \<le> x & x \<le> b & f(x) = y" 

651 
apply (rule contrapos_pp, assumption) 

652 
apply (cut_tac P = "% (u,v) . a \<le> u & u \<le> v & v \<le> b > ~ (f (u) \<le> y & y \<le> f (v))" in lemma_BOLZANO2) 

653 
apply safe 

654 
apply simp_all 

31338
d41a8ba25b67
generalize constants from Lim.thy to class metric_space
huffman
parents:
31336
diff
changeset

655 
apply (simp add: isCont_iff LIM_eq) 
21164  656 
apply (rule ccontr) 
657 
apply (subgoal_tac "a \<le> x & x \<le> b") 

658 
prefer 2 

659 
apply simp 

660 
apply (drule_tac P = "%d. 0<d > ?P d" and x = 1 in spec, arith) 

661 
apply (drule_tac x = x in spec)+ 

662 
apply simp 

663 
apply (drule_tac P = "%r. ?P r > (\<exists>s>0. ?Q r s) " and x = "\<bar>y  f x\<bar>" in spec) 

664 
apply safe 

665 
apply simp 

666 
apply (drule_tac x = s in spec, clarify) 

667 
apply (cut_tac x = "f x" and y = y in linorder_less_linear, safe) 

668 
apply (drule_tac x = "bax" in spec) 

669 
apply (simp_all add: abs_if) 

670 
apply (drule_tac x = "aax" in spec) 

671 
apply (case_tac "x \<le> aa", simp_all) 

672 
done 

673 

674 
lemma IVT2: "[ f(b::real) \<le> (y::real); y \<le> f(a); 

675 
a \<le> b; 

676 
(\<forall>x. a \<le> x & x \<le> b > isCont f x) 

677 
] ==> \<exists>x. a \<le> x & x \<le> b & f(x) = y" 

678 
apply (subgoal_tac " f a \<le> y & y \<le>  f b", clarify) 

679 
apply (drule IVT [where f = "%x.  f x"], assumption) 

680 
apply (auto intro: isCont_minus) 

681 
done 

682 

683 
(*HOL style here: objectlevel formulations*) 

684 
lemma IVT_objl: "(f(a::real) \<le> (y::real) & y \<le> f(b) & a \<le> b & 

685 
(\<forall>x. a \<le> x & x \<le> b > isCont f x)) 

686 
> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)" 

687 
apply (blast intro: IVT) 

688 
done 

689 

690 
lemma IVT2_objl: "(f(b::real) \<le> (y::real) & y \<le> f(a) & a \<le> b & 

691 
(\<forall>x. a \<le> x & x \<le> b > isCont f x)) 

692 
> (\<exists>x. a \<le> x & x \<le> b & f(x) = y)" 

693 
apply (blast intro: IVT2) 

694 
done 

695 

29975  696 

697 
subsection {* Boundedness of continuous functions *} 

698 

21164  699 
text{*By bisection, function continuous on closed interval is bounded above*} 
700 

701 
lemma isCont_bounded: 

702 
"[ a \<le> b; \<forall>x. a \<le> x & x \<le> b > isCont f x ] 

703 
==> \<exists>M::real. \<forall>x::real. a \<le> x & x \<le> b > f(x) \<le> M" 

704 
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) 

705 
apply safe 

706 
apply simp_all 

707 
apply (rename_tac x xa ya M Ma) 

36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

708 
apply (metis linorder_not_less order_le_less order_trans) 
21164  709 
apply (case_tac "a \<le> x & x \<le> b") 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

710 
prefer 2 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

711 
apply (rule_tac x = 1 in exI, force) 
31338
d41a8ba25b67
generalize constants from Lim.thy to class metric_space
huffman
parents:
31336
diff
changeset

712 
apply (simp add: LIM_eq isCont_iff) 
21164  713 
apply (drule_tac x = x in spec, auto) 
714 
apply (erule_tac V = "\<forall>M. \<exists>x. a \<le> x & x \<le> b & ~ f x \<le> M" in thin_rl) 

715 
apply (drule_tac x = 1 in spec, auto) 

716 
apply (rule_tac x = s in exI, clarify) 

717 
apply (rule_tac x = "\<bar>f x\<bar> + 1" in exI, clarify) 

718 
apply (drule_tac x = "xax" in spec) 

719 
apply (auto simp add: abs_ge_self) 

720 
done 

721 

722 
text{*Refine the above to existence of least upper bound*} 

723 

724 
lemma lemma_reals_complete: "((\<exists>x. x \<in> S) & (\<exists>y. isUb UNIV S (y::real))) > 

725 
(\<exists>t. isLub UNIV S t)" 

726 
by (blast intro: reals_complete) 

727 

728 
lemma isCont_has_Ub: "[ a \<le> b; \<forall>x. a \<le> x & x \<le> b > isCont f x ] 

729 
==> \<exists>M::real. (\<forall>x::real. a \<le> x & x \<le> b > f(x) \<le> M) & 

730 
(\<forall>N. N < M > (\<exists>x. a \<le> x & x \<le> b & N < f(x)))" 

731 
apply (cut_tac S = "Collect (%y. \<exists>x. a \<le> x & x \<le> b & y = f x)" 

732 
in lemma_reals_complete) 

733 
apply auto 

734 
apply (drule isCont_bounded, assumption) 

735 
apply (auto simp add: isUb_def leastP_def isLub_def setge_def setle_def) 

736 
apply (rule exI, auto) 

737 
apply (auto dest!: spec simp add: linorder_not_less) 

738 
done 

739 

740 
text{*Now show that it attains its upper bound*} 

741 

742 
lemma isCont_eq_Ub: 

743 
assumes le: "a \<le> b" 

744 
and con: "\<forall>x::real. a \<le> x & x \<le> b > isCont f x" 

745 
shows "\<exists>M::real. (\<forall>x. a \<le> x & x \<le> b > f(x) \<le> M) & 

746 
(\<exists>x. a \<le> x & x \<le> b & f(x) = M)" 

747 
proof  

748 
from isCont_has_Ub [OF le con] 

749 
obtain M where M1: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M" 

750 
and M2: "!!N. N<M ==> \<exists>x. a \<le> x \<and> x \<le> b \<and> N < f x" by blast 

751 
show ?thesis 

752 
proof (intro exI, intro conjI) 

753 
show " \<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> f x \<le> M" by (rule M1) 

754 
show "\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = M" 

755 
proof (rule ccontr) 

756 
assume "\<not> (\<exists>x. a \<le> x \<and> x \<le> b \<and> f x = M)" 

757 
with M1 have M3: "\<forall>x. a \<le> x & x \<le> b > f x < M" 

758 
by (fastsimp simp add: linorder_not_le [symmetric]) 

759 
hence "\<forall>x. a \<le> x & x \<le> b > isCont (%x. inverse (M  f x)) x" 

760 
by (auto simp add: isCont_inverse isCont_diff con) 

761 
from isCont_bounded [OF le this] 

762 
obtain k where k: "!!x. a \<le> x & x \<le> b > inverse (M  f x) \<le> k" by auto 

763 
have Minv: "!!x. a \<le> x & x \<le> b > 0 < inverse (M  f (x))" 

29667  764 
by (simp add: M3 algebra_simps) 
21164  765 
have "!!x. a \<le> x & x \<le> b > inverse (M  f x) < k+1" using k 
766 
by (auto intro: order_le_less_trans [of _ k]) 

767 
with Minv 

768 
have "!!x. a \<le> x & x \<le> b > inverse(k+1) < inverse(inverse(M  f x))" 

769 
by (intro strip less_imp_inverse_less, simp_all) 

770 
hence invlt: "!!x. a \<le> x & x \<le> b > inverse(k+1) < M  f x" 

771 
by simp 

772 
have "M  inverse (k+1) < M" using k [of a] Minv [of a] le 

773 
by (simp, arith) 

774 
from M2 [OF this] 

775 
obtain x where ax: "a \<le> x & x \<le> b & M  inverse(k+1) < f x" .. 

776 
thus False using invlt [of x] by force 

777 
qed 

778 
qed 

779 
qed 

780 

781 

782 
text{*Same theorem for lower bound*} 

783 

784 
lemma isCont_eq_Lb: "[ a \<le> b; \<forall>x. a \<le> x & x \<le> b > isCont f x ] 

785 
==> \<exists>M::real. (\<forall>x::real. a \<le> x & x \<le> b > M \<le> f(x)) & 

786 
(\<exists>x. a \<le> x & x \<le> b & f(x) = M)" 

787 
apply (subgoal_tac "\<forall>x. a \<le> x & x \<le> b > isCont (%x.  (f x)) x") 

788 
prefer 2 apply (blast intro: isCont_minus) 

789 
apply (drule_tac f = "(%x.  (f x))" in isCont_eq_Ub) 

790 
apply safe 

791 
apply auto 

792 
done 

793 

794 

795 
text{*Another version.*} 

796 

797 
lemma isCont_Lb_Ub: "[a \<le> b; \<forall>x. a \<le> x & x \<le> b > isCont f x ] 

798 
==> \<exists>L M::real. (\<forall>x::real. a \<le> x & x \<le> b > L \<le> f(x) & f(x) \<le> M) & 

799 
(\<forall>y. L \<le> y & y \<le> M > (\<exists>x. a \<le> x & x \<le> b & (f(x) = y)))" 

800 
apply (frule isCont_eq_Lb) 

801 
apply (frule_tac [2] isCont_eq_Ub) 

802 
apply (assumption+, safe) 

803 
apply (rule_tac x = "f x" in exI) 

804 
apply (rule_tac x = "f xa" in exI, simp, safe) 

805 
apply (cut_tac x = x and y = xa in linorder_linear, safe) 

806 
apply (cut_tac f = f and a = x and b = xa and y = y in IVT_objl) 

807 
apply (cut_tac [2] f = f and a = xa and b = x and y = y in IVT2_objl, safe) 

808 
apply (rule_tac [2] x = xb in exI) 

809 
apply (rule_tac [4] x = xb in exI, simp_all) 

810 
done 

811 

812 

29975  813 
subsection {* Local extrema *} 
814 

21164  815 
text{*If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right*} 
816 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

817 
lemma DERIV_pos_inc_right: 
21164  818 
fixes f :: "real => real" 
819 
assumes der: "DERIV f x :> l" 

820 
and l: "0 < l" 

821 
shows "\<exists>d > 0. \<forall>h > 0. h < d > f(x) < f(x + h)" 

822 
proof  

823 
from l der [THEN DERIV_D, THEN LIM_D [where r = "l"]] 

824 
have "\<exists>s > 0. (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z)  f x) / z  l\<bar> < l)" 

825 
by (simp add: diff_minus) 

826 
then obtain s 

827 
where s: "0 < s" 

828 
and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z)  f x) / z  l\<bar> < l" 

829 
by auto 

830 
thus ?thesis 

831 
proof (intro exI conjI strip) 

23441  832 
show "0<s" using s . 
21164  833 
fix h::real 
834 
assume "0 < h" "h < s" 

835 
with all [of h] show "f x < f (x+h)" 

836 
proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric] 

837 
split add: split_if_asm) 

838 
assume "~ (f (x+h)  f x) / h < l" and h: "0 < h" 

839 
with l 

840 
have "0 < (f (x+h)  f x) / h" by arith 

841 
thus "f x < f (x+h)" 

842 
by (simp add: pos_less_divide_eq h) 

843 
qed 

844 
qed 

845 
qed 

846 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

847 
lemma DERIV_neg_dec_left: 
21164  848 
fixes f :: "real => real" 
849 
assumes der: "DERIV f x :> l" 

850 
and l: "l < 0" 

851 
shows "\<exists>d > 0. \<forall>h > 0. h < d > f(x) < f(xh)" 

852 
proof  

853 
from l der [THEN DERIV_D, THEN LIM_D [where r = "l"]] 

854 
have "\<exists>s > 0. (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z)  f x) / z  l\<bar> < l)" 

855 
by (simp add: diff_minus) 

856 
then obtain s 

857 
where s: "0 < s" 

858 
and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z)  f x) / z  l\<bar> < l" 

859 
by auto 

860 
thus ?thesis 

861 
proof (intro exI conjI strip) 

23441  862 
show "0<s" using s . 
21164  863 
fix h::real 
864 
assume "0 < h" "h < s" 

865 
with all [of "h"] show "f x < f (xh)" 

866 
proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric] 

867 
split add: split_if_asm) 

868 
assume "  ((f (xh)  f x) / h) < l" and h: "0 < h" 

869 
with l 

870 
have "0 < (f (xh)  f x) / h" by arith 

871 
thus "f x < f (xh)" 

872 
by (simp add: pos_less_divide_eq h) 

873 
qed 

874 
qed 

875 
qed 

876 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

877 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

878 
lemma DERIV_pos_inc_left: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

879 
fixes f :: "real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

880 
shows "DERIV f x :> l \<Longrightarrow> 0 < l \<Longrightarrow> \<exists>d > 0. \<forall>h > 0. h < d > f(x  h) < f(x)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

881 
apply (rule DERIV_neg_dec_left [of "%x.  f x" x "l", simplified]) 
41368  882 
apply (auto simp add: DERIV_minus) 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

883 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

884 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

885 
lemma DERIV_neg_dec_right: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

886 
fixes f :: "real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

887 
shows "DERIV f x :> l \<Longrightarrow> l < 0 \<Longrightarrow> \<exists>d > 0. \<forall>h > 0. h < d > f(x) > f(x + h)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

888 
apply (rule DERIV_pos_inc_right [of "%x.  f x" x "l", simplified]) 
41368  889 
apply (auto simp add: DERIV_minus) 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

890 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

891 

21164  892 
lemma DERIV_local_max: 
893 
fixes f :: "real => real" 

894 
assumes der: "DERIV f x :> l" 

895 
and d: "0 < d" 

896 
and le: "\<forall>y. \<bar>xy\<bar> < d > f(y) \<le> f(x)" 

897 
shows "l = 0" 

898 
proof (cases rule: linorder_cases [of l 0]) 

23441  899 
case equal thus ?thesis . 
21164  900 
next 
901 
case less 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

902 
from DERIV_neg_dec_left [OF der less] 
21164  903 
obtain d' where d': "0 < d'" 
904 
and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (xh)" by blast 

905 
from real_lbound_gt_zero [OF d d'] 

906 
obtain e where "0 < e \<and> e < d \<and> e < d'" .. 

907 
with lt le [THEN spec [where x="xe"]] 

908 
show ?thesis by (auto simp add: abs_if) 

909 
next 

910 
case greater 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

911 
from DERIV_pos_inc_right [OF der greater] 
21164  912 
obtain d' where d': "0 < d'" 
913 
and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x + h)" by blast 

914 
from real_lbound_gt_zero [OF d d'] 

915 
obtain e where "0 < e \<and> e < d \<and> e < d'" .. 

916 
with lt le [THEN spec [where x="x+e"]] 

917 
show ?thesis by (auto simp add: abs_if) 

918 
qed 

919 

920 

921 
text{*Similar theorem for a local minimum*} 

922 
lemma DERIV_local_min: 

923 
fixes f :: "real => real" 

924 
shows "[ DERIV f x :> l; 0 < d; \<forall>y. \<bar>xy\<bar> < d > f(x) \<le> f(y) ] ==> l = 0" 

925 
by (drule DERIV_minus [THEN DERIV_local_max], auto) 

926 

927 

928 
text{*In particular, if a function is locally flat*} 

929 
lemma DERIV_local_const: 

930 
fixes f :: "real => real" 

931 
shows "[ DERIV f x :> l; 0 < d; \<forall>y. \<bar>xy\<bar> < d > f(x) = f(y) ] ==> l = 0" 

932 
by (auto dest!: DERIV_local_max) 

933 

29975  934 

935 
subsection {* Rolle's Theorem *} 

936 

21164  937 
text{*Lemma about introducing open ball in open interval*} 
938 
lemma lemma_interval_lt: 

939 
"[ a < x; x < b ] 

940 
==> \<exists>d::real. 0 < d & (\<forall>y. \<bar>xy\<bar> < d > a < y & y < b)" 

27668  941 

22998  942 
apply (simp add: abs_less_iff) 
21164  943 
apply (insert linorder_linear [of "xa" "bx"], safe) 
944 
apply (rule_tac x = "xa" in exI) 

945 
apply (rule_tac [2] x = "bx" in exI, auto) 

946 
done 

947 

948 
lemma lemma_interval: "[ a < x; x < b ] ==> 

949 
\<exists>d::real. 0 < d & (\<forall>y. \<bar>xy\<bar> < d > a \<le> y & y \<le> b)" 

950 
apply (drule lemma_interval_lt, auto) 

951 
apply (auto intro!: exI) 

952 
done 

953 

954 
text{*Rolle's Theorem. 

955 
If @{term f} is defined and continuous on the closed interval 

956 
@{text "[a,b]"} and differentiable on the open interval @{text "(a,b)"}, 

957 
and @{term "f(a) = f(b)"}, 

958 
then there exists @{text "x0 \<in> (a,b)"} such that @{term "f'(x0) = 0"}*} 

959 
theorem Rolle: 

960 
assumes lt: "a < b" 

961 
and eq: "f(a) = f(b)" 

962 
and con: "\<forall>x. a \<le> x & x \<le> b > isCont f x" 

963 
and dif [rule_format]: "\<forall>x. a < x & x < b > f differentiable x" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

964 
shows "\<exists>z::real. a < z & z < b & DERIV f z :> 0" 
21164  965 
proof  
966 
have le: "a \<le> b" using lt by simp 

967 
from isCont_eq_Ub [OF le con] 

968 
obtain x where x_max: "\<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> f z \<le> f x" 

969 
and alex: "a \<le> x" and xleb: "x \<le> b" 

970 
by blast 

971 
from isCont_eq_Lb [OF le con] 

972 
obtain x' where x'_min: "\<forall>z. a \<le> z \<and> z \<le> b \<longrightarrow> f x' \<le> f z" 

973 
and alex': "a \<le> x'" and x'leb: "x' \<le> b" 

974 
by blast 

975 
show ?thesis 

976 
proof cases 

977 
assume axb: "a < x & x < b" 

978 
{*@{term f} attains its maximum within the interval*} 

27668  979 
hence ax: "a<x" and xb: "x<b" by arith + 
21164  980 
from lemma_interval [OF ax xb] 
981 
obtain d where d: "0<d" and bound: "\<forall>y. \<bar>xy\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b" 

982 
by blast 

983 
hence bound': "\<forall>y. \<bar>xy\<bar> < d \<longrightarrow> f y \<le> f x" using x_max 

984 
by blast 

985 
from differentiableD [OF dif [OF axb]] 

986 
obtain l where der: "DERIV f x :> l" .. 

987 
have "l=0" by (rule DERIV_local_max [OF der d bound']) 

988 
{*the derivative at a local maximum is zero*} 

989 
thus ?thesis using ax xb der by auto 

990 
next 

991 
assume notaxb: "~ (a < x & x < b)" 

992 
hence xeqab: "x=a  x=b" using alex xleb by arith 

993 
hence fb_eq_fx: "f b = f x" by (auto simp add: eq) 

994 
show ?thesis 

995 
proof cases 

996 
assume ax'b: "a < x' & x' < b" 

997 
{*@{term f} attains its minimum within the interval*} 

27668  998 
hence ax': "a<x'" and x'b: "x'<b" by arith+ 
21164  999 
from lemma_interval [OF ax' x'b] 
1000 
obtain d where d: "0<d" and bound: "\<forall>y. \<bar>x'y\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b" 

1001 
by blast 

1002 
hence bound': "\<forall>y. \<bar>x'y\<bar> < d \<longrightarrow> f x' \<le> f y" using x'_min 

1003 
by blast 

1004 
from differentiableD [OF dif [OF ax'b]] 

1005 
obtain l where der: "DERIV f x' :> l" .. 

1006 
have "l=0" by (rule DERIV_local_min [OF der d bound']) 

1007 
{*the derivative at a local minimum is zero*} 

1008 
thus ?thesis using ax' x'b der by auto 

1009 
next 

1010 
assume notax'b: "~ (a < x' & x' < b)" 

1011 
{*@{term f} is constant througout the interval*} 

1012 
hence x'eqab: "x'=a  x'=b" using alex' x'leb by arith 

1013 
hence fb_eq_fx': "f b = f x'" by (auto simp add: eq) 

1014 
from dense [OF lt] 

1015 
obtain r where ar: "a < r" and rb: "r < b" by blast 

1016 
from lemma_interval [OF ar rb] 

1017 
obtain d where d: "0<d" and bound: "\<forall>y. \<bar>ry\<bar> < d \<longrightarrow> a \<le> y \<and> y \<le> b" 

1018 
by blast 

1019 
have eq_fb: "\<forall>z. a \<le> z > z \<le> b > f z = f b" 

1020 
proof (clarify) 

1021 
fix z::real 

1022 
assume az: "a \<le> z" and zb: "z \<le> b" 

1023 
show "f z = f b" 

1024 
proof (rule order_antisym) 

1025 
show "f z \<le> f b" by (simp add: fb_eq_fx x_max az zb) 

1026 
show "f b \<le> f z" by (simp add: fb_eq_fx' x'_min az zb) 

1027 
qed 

1028 
qed 

1029 
have bound': "\<forall>y. \<bar>ry\<bar> < d \<longrightarrow> f r = f y" 

1030 
proof (intro strip) 

1031 
fix y::real 

1032 
assume lt: "\<bar>ry\<bar> < d" 

1033 
hence "f y = f b" by (simp add: eq_fb bound) 

1034 
thus "f r = f y" by (simp add: eq_fb ar rb order_less_imp_le) 

1035 
qed 

1036 
from differentiableD [OF dif [OF conjI [OF ar rb]]] 

1037 
obtain l where der: "DERIV f r :> l" .. 

1038 
have "l=0" by (rule DERIV_local_const [OF der d bound']) 

1039 
{*the derivative of a constant function is zero*} 

1040 
thus ?thesis using ar rb der by auto 

1041 
qed 

1042 
qed 

1043 
qed 

1044 

1045 

1046 
subsection{*Mean Value Theorem*} 

1047 

1048 
lemma lemma_MVT: 

1049 
"f a  (f b  f a)/(ba) * a = f b  (f b  f a)/(ba) * (b::real)" 

1050 
proof cases 

1051 
assume "a=b" thus ?thesis by simp 

1052 
next 

1053 
assume "a\<noteq>b" 

1054 
hence ba: "ba \<noteq> 0" by arith 

1055 
show ?thesis 

1056 
by (rule real_mult_left_cancel [OF ba, THEN iffD1], 

1057 
simp add: right_diff_distrib, 

1058 
simp add: left_diff_distrib) 

1059 
qed 

1060 

1061 
theorem MVT: 

1062 
assumes lt: "a < b" 

1063 
and con: "\<forall>x. a \<le> x & x \<le> b > isCont f x" 

1064 
and dif [rule_format]: "\<forall>x. a < x & x < b > f differentiable x" 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

1065 
shows "\<exists>l z::real. a < z & z < b & DERIV f z :> l & 
21164  1066 
(f(b)  f(a) = (ba) * l)" 
1067 
proof  

1068 
let ?F = "%x. f x  ((f b  f a) / (ba)) * x" 

1069 
have contF: "\<forall>x. a \<le> x \<and> x \<le> b \<longrightarrow> isCont ?F x" using con 

23069
cdfff0241c12
rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents:
23044
diff
changeset

1070 
by (fast intro: isCont_diff isCont_const isCont_mult isCont_ident) 
21164  1071 
have difF: "\<forall>x. a < x \<and> x < b \<longrightarrow> ?F differentiable x" 
1072 
proof (clarify) 

1073 
fix x::real 

1074 
assume ax: "a < x" and xb: "x < b" 

1075 
from differentiableD [OF dif [OF conjI [OF ax xb]]] 

1076 
obtain l where der: "DERIV f x :> l" .. 

1077 
show "?F differentiable x" 

1078 
by (rule differentiableI [where D = "l  (f b  f a)/(ba)"], 

1079 
blast intro: DERIV_diff DERIV_cmult_Id der) 

1080 
qed 

1081 
from Rolle [where f = ?F, OF lt lemma_MVT contF difF] 

1082 
obtain z where az: "a < z" and zb: "z < b" and der: "DERIV ?F z :> 0" 

1083 
by blast 

1084 
have "DERIV (%x. ((f b  f a)/(ba)) * x) z :> (f b  f a)/(ba)" 

1085 
by (rule DERIV_cmult_Id) 

1086 
hence derF: "DERIV (\<lambda>x. ?F x + (f b  f a) / (b  a) * x) z 

1087 
:> 0 + (f b  f a) / (b  a)" 

1088 
by (rule DERIV_add [OF der]) 

1089 
show ?thesis 

1090 
proof (intro exI conjI) 

23441  1091 
show "a < z" using az . 
1092 
show "z < b" using zb . 

21164  1093 
show "f b  f a = (b  a) * ((f b  f a)/(ba))" by (simp) 
1094 
show "DERIV f z :> ((f b  f a)/(ba))" using derF by simp 

1095 
qed 

1096 
qed 

1097 

29803
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1098 
lemma MVT2: 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1099 
"[ a < b; \<forall>x. a \<le> x & x \<le> b > DERIV f x :> f'(x) ] 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1100 
==> \<exists>z::real. a < z & z < b & (f b  f a = (b  a) * f'(z))" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1101 
apply (drule MVT) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1102 
apply (blast intro: DERIV_isCont) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1103 
apply (force dest: order_less_imp_le simp add: differentiable_def) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1104 
apply (blast dest: DERIV_unique order_less_imp_le) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1105 
done 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1106 

21164  1107 

1108 
text{*A function is constant if its derivative is 0 over an interval.*} 

1109 

1110 
lemma DERIV_isconst_end: 

1111 
fixes f :: "real => real" 

1112 
shows "[ a < b; 

1113 
\<forall>x. a \<le> x & x \<le> b > isCont f x; 

1114 
\<forall>x. a < x & x < b > DERIV f x :> 0 ] 

1115 
==> f b = f a" 

1116 
apply (drule MVT, assumption) 

1117 
apply (blast intro: differentiableI) 

1118 
apply (auto dest!: DERIV_unique simp add: diff_eq_eq) 

1119 
done 

1120 

1121 
lemma DERIV_isconst1: 

1122 
fixes f :: "real => real" 

1123 
shows "[ a < b; 

1124 
\<forall>x. a \<le> x & x \<le> b > isCont f x; 

1125 
\<forall>x. a < x & x < b > DERIV f x :> 0 ] 

1126 
==> \<forall>x. a \<le> x & x \<le> b > f x = f a" 

1127 
apply safe 

1128 
apply (drule_tac x = a in order_le_imp_less_or_eq, safe) 

1129 
apply (drule_tac b = x in DERIV_isconst_end, auto) 

1130 
done 

1131 

1132 
lemma DERIV_isconst2: 

1133 
fixes f :: "real => real" 

1134 
shows "[ a < b; 

1135 
\<forall>x. a \<le> x & x \<le> b > isCont f x; 

1136 
\<forall>x. a < x & x < b > DERIV f x :> 0; 

1137 
a \<le> x; x \<le> b ] 

1138 
==> f x = f a" 

1139 
apply (blast dest: DERIV_isconst1) 

1140 
done 

1141 

29803
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1142 
lemma DERIV_isconst3: fixes a b x y :: real 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1143 
assumes "a < b" and "x \<in> {a <..< b}" and "y \<in> {a <..< b}" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1144 
assumes derivable: "\<And>x. x \<in> {a <..< b} \<Longrightarrow> DERIV f x :> 0" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1145 
shows "f x = f y" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1146 
proof (cases "x = y") 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1147 
case False 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1148 
let ?a = "min x y" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1149 
let ?b = "max x y" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1150 

c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1151 
have "\<forall>z. ?a \<le> z \<and> z \<le> ?b \<longrightarrow> DERIV f z :> 0" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1152 
proof (rule allI, rule impI) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1153 
fix z :: real assume "?a \<le> z \<and> z \<le> ?b" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1154 
hence "a < z" and "z < b" using `x \<in> {a <..< b}` and `y \<in> {a <..< b}` by auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1155 
hence "z \<in> {a<..<b}" by auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1156 
thus "DERIV f z :> 0" by (rule derivable) 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1157 
qed 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1158 
hence isCont: "\<forall>z. ?a \<le> z \<and> z \<le> ?b \<longrightarrow> isCont f z" 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1159 
and DERIV: "\<forall>z. ?a < z \<and> z < ?b \<longrightarrow> DERIV f z :> 0" using DERIV_isCont by auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1160 

c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1161 
have "?a < ?b" using `x \<noteq> y` by auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1162 
from DERIV_isconst2[OF this isCont DERIV, of x] and DERIV_isconst2[OF this isCont DERIV, of y] 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1163 
show ?thesis by auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1164 
qed auto 
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29667
diff
changeset

1165 

21164  1166 
lemma DERIV_isconst_all: 
1167 
fixes f :: "real => real" 

1168 
shows "\<forall>x. DERIV f x :> 0 ==> f(x) = f(y)" 

1169 
apply (rule linorder_cases [of x y]) 

1170 
apply (blast intro: sym DERIV_isCont DERIV_isconst_end)+ 

1171 
done 

1172 

1173 
lemma DERIV_const_ratio_const: 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

1174 
fixes f :: "real => real" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

1175 
shows "[a \<noteq> b; \<forall>x. DERIV f x :> k ] ==> (f(b)  f(a)) = (ba) * k" 
21164  1176 
apply (rule linorder_cases [of a b], auto) 
1177 
apply (drule_tac [!] f = f in MVT) 

1178 
apply (auto dest: DERIV_isCont DERIV_unique simp add: differentiable_def) 

23477
f4b83f03cac9
tuned and renamed group_eq_simps and ring_eq_simps
nipkow
parents:
23441
diff
changeset

1179 
apply (auto dest: DERIV_unique simp add: ring_distribs diff_minus) 
21164  1180 
done 
1181 

1182 
lemma DERIV_const_ratio_const2: 

21784
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

1183 
fixes f :: "real => real" 
e76faa6e65fd
changed (ns)deriv to take functions of type 'a::real_normed_field => 'a
huffman
parents:
21404
diff
changeset

1184 
shows "[a \<noteq> b; \<forall>x. DERIV f x :> k ] ==> (f(b)  f(a))/(ba) = k" 
21164  1185 
apply (rule_tac c1 = "ba" in real_mult_right_cancel [THEN iffD1]) 
1186 
apply (auto dest!: DERIV_const_ratio_const simp add: mult_assoc) 

1187 
done 

1188 

1189 
lemma real_average_minus_first [simp]: "((a + b) /2  a) = (ba)/(2::real)" 

1190 
by (simp) 

1191 

1192 
lemma real_average_minus_second [simp]: "((b + a)/2  a) = (ba)/(2::real)" 

1193 
by (simp) 

1194 

1195 
text{*Gallileo's "trick": average velocity = av. of end velocities*} 

1196 

1197 
lemma DERIV_const_average: 

1198 
fixes v :: "real => real" 

1199 
assumes neq: "a \<noteq> (b::real)" 

1200 
and der: "\<forall>x. DERIV v x :> k" 

1201 
shows "v ((a + b)/2) = (v a + v b)/2" 

1202 
proof (cases rule: linorder_cases [of a b]) 

1203 
case equal with neq show ?thesis by simp 

1204 
next 

1205 
case less 

1206 
have "(v b  v a) / (b  a) = k" 

1207 
by (rule DERIV_const_ratio_const2 [OF neq der]) 

1208 
hence "(ba) * ((v b  v a) / (ba)) = (ba) * k" by simp 

1209 
moreover have "(v ((a + b) / 2)  v a) / ((a + b) / 2  a) = k" 

1210 
by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq) 

1211 
ultimately show ?thesis using neq by force 

1212 
next 

1213 
case greater 

1214 
have "(v b  v a) / (b  a) = k" 

1215 
by (rule DERIV_const_ratio_const2 [OF neq der]) 

1216 
hence "(ba) * ((v b  v a) / (ba)) = (ba) * k" by simp 

1217 
moreover have " (v ((b + a) / 2)  v a) / ((b + a) / 2  a) = k" 

1218 
by (rule DERIV_const_ratio_const2 [OF _ der], simp add: neq) 

1219 
ultimately show ?thesis using neq by (force simp add: add_commute) 

1220 
qed 

1221 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1222 
(* A function with positive derivative is increasing. 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1223 
A simple proof using the MVT, by Jeremy Avigad. And variants. 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1224 
*) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1225 
lemma DERIV_pos_imp_increasing: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1226 
fixes a::real and b::real and f::"real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1227 
assumes "a < b" and "\<forall>x. a \<le> x & x \<le> b > (EX y. DERIV f x :> y & y > 0)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1228 
shows "f a < f b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1229 
proof (rule ccontr) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1230 
assume "~ f a < f b" 
33690  1231 
have "EX l z. a < z & z < b & DERIV f z :> l 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1232 
& f b  f a = (b  a) * l" 
33690  1233 
apply (rule MVT) 
1234 
using assms 

1235 
apply auto 

1236 
apply (metis DERIV_isCont) 

36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

1237 
apply (metis differentiableI less_le) 
33690  1238 
done 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1239 
then obtain l z where "a < z" and "z < b" and "DERIV f z :> l" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1240 
and "f b  f a = (b  a) * l" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1241 
by auto 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1242 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1243 
from prems have "~(l > 0)" 
36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

1244 
by (metis linorder_not_le mult_le_0_iff diff_le_0_iff_le) 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1245 
with prems show False 
36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

1246 
by (metis DERIV_unique less_le) 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1247 
qed 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1248 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1249 
lemma DERIV_nonneg_imp_nonincreasing: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1250 
fixes a::real and b::real and f::"real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1251 
assumes "a \<le> b" and 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1252 
"\<forall>x. a \<le> x & x \<le> b > (\<exists>y. DERIV f x :> y & y \<ge> 0)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1253 
shows "f a \<le> f b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1254 
proof (rule ccontr, cases "a = b") 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1255 
assume "~ f a \<le> f b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1256 
assume "a = b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1257 
with prems show False by auto 
37891  1258 
next 
1259 
assume A: "~ f a \<le> f b" 

1260 
assume B: "a ~= b" 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1261 
with assms have "EX l z. a < z & z < b & DERIV f z :> l 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1262 
& f b  f a = (b  a) * l" 
33690  1263 
apply  
1264 
apply (rule MVT) 

1265 
apply auto 

1266 
apply (metis DERIV_isCont) 

36777
be5461582d0f
avoid using realspecific versions of generic lemmas
huffman
parents:
35216
diff
changeset

1267 
apply (metis differentiableI less_le) 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1268 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1269 
then obtain l z where "a < z" and "z < b" and "DERIV f z :> l" 
37891  1270 
and C: "f b  f a = (b  a) * l" 
33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1271 
by auto 
37891  1272 
with A have "a < b" "f b < f a" by auto 
1273 
with C have "\<not> l \<ge> 0" by (auto simp add: not_le algebra_simps) 

1274 
(metis A add_le_cancel_right assms(1) less_eq_real_def mult_right_mono real_add_left_mono real_le_linear real_le_refl) 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1275 
with prems show False 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1276 
by (metis DERIV_unique order_less_imp_le) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1277 
qed 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1278 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1279 
lemma DERIV_neg_imp_decreasing: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1280 
fixes a::real and b::real and f::"real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1281 
assumes "a < b" and 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1282 
"\<forall>x. a \<le> x & x \<le> b > (\<exists>y. DERIV f x :> y & y < 0)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1283 
shows "f a > f b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1284 
proof  
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1285 
have "(%x. f x) a < (%x. f x) b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1286 
apply (rule DERIV_pos_imp_increasing [of a b "%x. f x"]) 
33690  1287 
using assms 
1288 
apply auto 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1289 
apply (metis DERIV_minus neg_0_less_iff_less) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1290 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1291 
thus ?thesis 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1292 
by simp 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1293 
qed 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1294 

abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1295 
lemma DERIV_nonpos_imp_nonincreasing: 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1296 
fixes a::real and b::real and f::"real => real" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1297 
assumes "a \<le> b" and 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1298 
"\<forall>x. a \<le> x & x \<le> b > (\<exists>y. DERIV f x :> y & y \<le> 0)" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1299 
shows "f a \<ge> f b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1300 
proof  
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1301 
have "(%x. f x) a \<le> (%x. f x) b" 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1302 
apply (rule DERIV_nonneg_imp_nonincreasing [of a b "%x. f x"]) 
33690  1303 
using assms 
1304 
apply auto 

33654
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1305 
apply (metis DERIV_minus neg_0_le_iff_le) 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1306 
done 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1307 
thus ?thesis 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1308 
by simp 
abf780db30ea
A number of theorems contributed by Jeremy Avigad
paulson
parents:
31902
diff
changeset

1309 
qed 
21164  1310 

29975  1311 
subsection {* Continuous injective functions *} 
1312 

21164  1313 
text{*Dull lemma: an continuous injection on an interval must have a 
1314 
strict maximum at an end point, not in the middle.*} 

1315 

1316 
lemma lemma_isCont_inj: 

1317 
fixes f :: "real \<Rightarrow> real" 

1318 
assumes d: "0 < d" 

1319 
and inj [rule_format]: "\<forall>z. \<bar>zx\<bar> \<le> d > g(f z) = z" 

1320 
and cont: "\<forall>z. \<bar>zx\<bar> \<le> d > isCont f z" 

1321 
shows "\<exists>z. \<bar>zx\<bar> \<le> d & f x < f z" 

1322 
proof (rule ccontr) 

1323 
assume "~ (\<exists>z. \<bar>zx\<bar> \<le> d & f x < f z)" 

1324 
hence all [rule_format]: "\<forall>z. \<bar>z  x\<bar> \<le> d > f z \<le> f x" by auto 

1325 
show False 

1326 
proof (cases rule: linorder_le_cases [of "f(xd)" "f(x+d)"]) 

1327 
case le 

1328 
from d cont all [of "x+d"] 

1329 
have flef: "f(x+d) \<le> f x" 

1330 
and xlex: "x  d \<le> x" 

1331 
and cont': "\<forall>z. x  d \<le> z \<and> z \<le> x \<longrightarrow> isCont f z" 

1332 
by (auto simp add: abs_if) 

1333 
from IVT [OF le flef xlex cont'] 

1334 
obtain x' where "xd \<le> x'" "x' \<le> x" "f x' = f(x+d)" by blast 

1335 
moreover 

1336 
hence "g(f x') = g (f(x+d))" by simp 

1337 
ultimately show False using d inj [of x'] inj [of "x+d"] 

22998  1338 
by (simp add: abs_le_iff) 
21164  1339 
next 
1340 
case ge 

1341 
from d cont all [of "xd"] 

1342 
have flef: "f(xd) \<le> f x" 

1343 
and xlex: "x \<le> x+d" 

1344 
and cont': "\<forall>z. x \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" 

1345 
by (auto simp add: abs_if) 

1346 
from IVT2 [OF ge flef xlex cont'] 

1347 
obtain x' where "x \<le> x'" "x' \<le> x+d" "f x' = f(xd)" by blast 

1348 
moreover 

1349 
hence "g(f x') = g (f(xd))" by simp 

1350 
ultimately show False using d inj [of x'] inj [of "xd"] 

22998  1351 
by (simp add: abs_le_iff) 
21164  1352 
qed 
1353 
qed 

1354 

1355 

1356 
text{*Similar version for lower bound.*} 

1357 

1358 
lemma lemma_isCont_inj2: 

1359 
fixes f g :: "real \<Rightarrow> real" 

1360 
shows "[0 < d; \<forall>z. \<bar>zx\<bar> \<le> d > g(f z) = z; 

1361 
\<forall>z. \<bar>zx\<bar> \<le> d > isCont f z ] 

1362 
==> \<exists>z. \<bar>zx\<bar> \<le> d & f z < f x" 

1363 
apply (insert lemma_isCont_inj 

1364 
[where f = "%x.  f x" and g = "%y. g(y)" and x = x and d = d]) 

1365 
apply (simp add: isCont_minus linorder_not_le) 

1366 
done 

1367 

1368 
text{*Show there's an interval surrounding @{term "f(x)"} in 

1369 
@{text "f[[x  d, x + d]]"} .*} 

1370 

1371 
lemma isCont_inj_range: 

1372 
fixes f :: "real \<Rightarrow> real" 

1373 
assumes d: "0 < d" 

1374 
and inj: "\<forall>z. \<bar>zx\<bar> \<le> d > g(f z) = z" 

1375 
and cont: "\<forall>z. \<bar>zx\<bar> \<le> d > isCont f z" 

1376 
shows "\<exists>e>0. \<forall>y. \<bar>y  f x\<bar> \<le> e > (\<exists>z. \<bar>zx\<bar> \<le> d & f z = y)" 

1377 
proof  

1378 
have "xd \<le> x+d" "\<forall>z. xd \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" using cont d 

22998  1379 
by (auto simp add: abs_le_iff) 
21164  1380 
from isCont_Lb_Ub [OF this] 
1381 
obtain L M 

1382 
where all1 [rule_format]: "\<forall>z. xd \<le> z \<and> z \<le> x+d \<longrightarrow> L \<le> f z \<and> f z \<le> M" 

1383 
and all2 [rule_format]: 

1384 
"\<forall>y. L \<le> y \<and> y \<le> M \<longrightarrow> (\<exists>z. xd \<le> z \<and> z \<le> x+d \<and> f z = y)" 

1385 
by auto 

1386 
with d have "L \<le> f x & f x \<le> M" by simp 

1387 
moreover have "L \<noteq> f x" 

1388 
proof  

1389 
from lemma_isCont_inj2 [OF d inj cont] 

1390 
obtain u where "\<bar>u  x\<bar> \<le> d" "f u < f x" by auto 

1391 
thus ?thesis using all1 [of u] by arith 

1392 
qed 

1393 
moreover have "f x \<noteq> M" 

1394 
proof  

1395 
from lemma_isCont_inj [OF d inj cont] 

1396 
obtain u where "\<bar>u  x\<bar> \<le> d" "f x < f u" by auto 

1397 
thus ?thesis using all1 [of u] by arith 

1398 
qed 

1399 
ultimately have "L < f x & f x < M" by arith 

1400 
hence "0 < f x  L" "0 < M  f x" by arith+ 
