# HG changeset patch # User wenzelm # Date 1468435676 -7200 # Node ID ea8dfb0ed10e636732f29c418428b83eef66b28a # Parent 2033a3960c36249f5f15094f4458219551fa0323 misc tuning and modernization; diff -r 2033a3960c36 -r ea8dfb0ed10e src/HOL/Library/BigO.thy --- a/src/HOL/Library/BigO.thy Wed Jul 13 20:14:16 2016 +0200 +++ b/src/HOL/Library/BigO.thy Wed Jul 13 20:47:56 2016 +0200 @@ -5,7 +5,10 @@ section \Big O notation\ theory BigO - imports Complex_Main Function_Algebras Set_Algebras + imports + Complex_Main + Function_Algebras + Set_Algebras begin text \ diff -r 2033a3960c36 -r ea8dfb0ed10e src/HOL/Library/Convex.thy --- a/src/HOL/Library/Convex.thy Wed Jul 13 20:14:16 2016 +0200 +++ b/src/HOL/Library/Convex.thy Wed Jul 13 20:47:56 2016 +0200 @@ -6,7 +6,7 @@ section \Convexity in real vector spaces\ theory Convex -imports Product_Vector + imports Product_Vector begin subsection \Convexity\ @@ -24,24 +24,27 @@ shows "u *\<^sub>R x + v *\<^sub>R y \ s" using assms unfolding convex_def by fast -lemma convex_alt: - "convex s \ (\x\s. \y\s. \u. 0 \ u \ u \ 1 \ ((1 - u) *\<^sub>R x + u *\<^sub>R y) \ s)" +lemma convex_alt: "convex s \ (\x\s. \y\s. \u. 0 \ u \ u \ 1 \ ((1 - u) *\<^sub>R x + u *\<^sub>R y) \ s)" (is "_ \ ?alt") proof - assume alt[rule_format]: ?alt - { - fix x y and u v :: real - assume mem: "x \ s" "y \ s" - assume "0 \ u" "0 \ v" - moreover - assume "u + v = 1" - then have "u = 1 - v" by auto - ultimately have "u *\<^sub>R x + v *\<^sub>R y \ s" - using alt[OF mem] by auto - } - then show "convex s" - unfolding convex_def by auto -qed (auto simp: convex_def) + show "convex s" if alt: ?alt + proof - + { + fix x y and u v :: real + assume mem: "x \ s" "y \ s" + assume "0 \ u" "0 \ v" + moreover + assume "u + v = 1" + then have "u = 1 - v" by auto + ultimately have "u *\<^sub>R x + v *\<^sub>R y \ s" + using alt [rule_format, OF mem] by auto + } + then show ?thesis + unfolding convex_def by auto + qed + show ?alt if "convex s" + using that by (auto simp: convex_def) +qed lemma convexD_alt: assumes "convex s" "a \ s" "b \ s" "0 \ u" "u \ 1" @@ -53,7 +56,7 @@ shows "((u/(u+v)) *\<^sub>R x + (v/(u+v)) *\<^sub>R y) \ S" apply (rule convexD) using assms - apply (simp_all add: zero_le_divide_iff add_divide_distrib [symmetric]) + apply (simp_all add: zero_le_divide_iff add_divide_distrib [symmetric]) done lemma convex_empty[intro,simp]: "convex {}" @@ -270,12 +273,12 @@ case False then show ?thesis using *[rule_format, of "{x, y}" "\ z. if z = x then 1 - \ else \"] ** - by auto + by auto next case True then show ?thesis using *[rule_format, of "{x, y}" "\ z. 1"] ** - by (auto simp: field_simps real_vector.scale_left_diff_distrib) + by (auto simp: field_simps real_vector.scale_left_diff_distrib) qed qed qed @@ -293,8 +296,8 @@ have if_distrib_arg: "\P f g x. (if P then f else g) x = (if P then f x else g x)" by simp show "(\x\t. u x *\<^sub>R x) \ s" - using sum[THEN spec[where x="\x. if x\t then u x else 0"]] as * - by (auto simp: assms setsum.If_cases if_distrib if_distrib_arg) + using sum[THEN spec[where x="\x. if x\t then u x else 0"]] as * + by (auto simp: assms setsum.If_cases if_distrib if_distrib_arg) qed (erule_tac x=s in allE, erule_tac x=u in allE, auto) @@ -306,39 +309,45 @@ lemma convex_onI [intro?]: assumes "\t x y. t > 0 \ t < 1 \ x \ A \ y \ A \ - f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" - shows "convex_on A f" + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + shows "convex_on A f" unfolding convex_on_def proof clarify - fix x y u v assume A: "x \ A" "y \ A" "(u::real) \ 0" "v \ 0" "u + v = 1" - from A(5) have [simp]: "v = 1 - u" by (simp add: algebra_simps) - from A(1-4) show "f (u *\<^sub>R x + v *\<^sub>R y) \ u * f x + v * f y" using assms[of u y x] + fix x y + fix u v :: real + assume A: "x \ A" "y \ A" "u \ 0" "v \ 0" "u + v = 1" + from A(5) have [simp]: "v = 1 - u" + by (simp add: algebra_simps) + from A(1-4) show "f (u *\<^sub>R x + v *\<^sub>R y) \ u * f x + v * f y" + using assms[of u y x] by (cases "u = 0 \ u = 1") (auto simp: algebra_simps) qed lemma convex_on_linorderI [intro?]: fixes A :: "('a::{linorder,real_vector}) set" assumes "\t x y. t > 0 \ t < 1 \ x \ A \ y \ A \ x < y \ - f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" - shows "convex_on A f" + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + shows "convex_on A f" proof - fix t x y assume A: "x \ A" "y \ A" "(t::real) > 0" "t < 1" - with assms[of t x y] assms[of "1 - t" y x] + fix x y + fix t :: real + assume A: "x \ A" "y \ A" "t > 0" "t < 1" + with assms [of t x y] assms [of "1 - t" y x] show "f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" by (cases x y rule: linorder_cases) (auto simp: algebra_simps) qed lemma convex_onD: assumes "convex_on A f" - shows "\t x y. t \ 0 \ t \ 1 \ x \ A \ y \ A \ - f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" - using assms unfolding convex_on_def by auto + shows "\t x y. t \ 0 \ t \ 1 \ x \ A \ y \ A \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + using assms by (auto simp: convex_on_def) lemma convex_onD_Icc: assumes "convex_on {x..y} f" "x \ (y :: _ :: {real_vector,preorder})" - shows "\t. t \ 0 \ t \ 1 \ - f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" - using assms(2) by (intro convex_onD[OF assms(1)]) simp_all + shows "\t. t \ 0 \ t \ 1 \ + f ((1 - t) *\<^sub>R x + t *\<^sub>R y) \ (1 - t) * f x + t * f y" + using assms(2) by (intro convex_onD [OF assms(1)]) simp_all lemma convex_on_subset: "convex_on t f \ s \ t \ convex_on s f" unfolding convex_on_def by auto @@ -370,7 +379,8 @@ and "convex_on s f" shows "convex_on s (\x. c * f x)" proof - - have *: "\u c fx v fy :: real. u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)" + have *: "u * (c * fx) + v * (c * fy) = c * (u * fx + v * fy)" + for u c fx v fy :: real by (simp add: field_simps) show ?thesis using assms(2) and mult_left_mono [OF _ assms(1)] unfolding convex_on_def and * by auto @@ -517,20 +527,24 @@ assume *: "y > 0" "x > 0" "\ \ 0" "\ \ 1" { assume "\ = 0" - then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y = y" by simp - then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" using * by simp + then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y = y" + by simp + then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" + using * by simp } moreover { assume "\ = 1" - then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" using * by simp + then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" + using * by simp } moreover { assume "\ \ 1" "\ \ 0" - then have "\ > 0" "(1 - \) > 0" using * by auto - then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" using * - by (auto simp: add_pos_pos) + then have "\ > 0" "(1 - \) > 0" + using * by auto + then have "\ *\<^sub>R x + (1 - \) *\<^sub>R y > 0" + using * by (auto simp: add_pos_pos) } ultimately show "(1 - \) *\<^sub>R y + \ *\<^sub>R x > 0" by fastforce @@ -550,11 +564,14 @@ using assms proof (induct s arbitrary: a rule: finite_ne_induct) case (singleton i) - then have ai: "a i = 1" by auto - then show ?case by auto + then have ai: "a i = 1" + by auto + then show ?case + by auto next case (insert i s) - then have "convex_on C f" by simp + then have "convex_on C f" + by simp from this[unfolded convex_on_def, rule_format] have conv: "\x y \. x \ C \ y \ C \ 0 \ \ \ \ \ 1 \ f (\ *\<^sub>R x + (1 - \) *\<^sub>R y) \ \ * f x + (1 - \) * f y" @@ -593,8 +610,7 @@ unfolding setsum_divide_distrib by simp have "convex C" using insert by auto then have asum: "(\ j \ s. ?a j *\<^sub>R y j) \ C" - using insert convex_setsum[OF \finite s\ - \convex C\ a1 a_nonneg] by auto + using insert convex_setsum [OF \finite s\ \convex C\ a1 a_nonneg] by auto have asum_le: "f (\ j \ s. ?a j *\<^sub>R y j) \ (\ j \ s. ?a j * f (y j))" using a_nonneg a1 insert by blast have "f (\ j \ insert i s. a j *\<^sub>R y j) = f ((\ j \ s. a j *\<^sub>R y j) + a i *\<^sub>R y i)" @@ -611,10 +627,12 @@ using conv[of "y i" "(\ j \ s. ?a j *\<^sub>R y j)" "a i", OF yai(1) asum yai(2) ai1] by (auto simp: add.commute) also have "\ \ (1 - a i) * (\ j \ s. ?a j * f (y j)) + a i * f (y i)" - using add_right_mono[OF mult_left_mono[of _ _ "1 - a i", - OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] by simp + using add_right_mono [OF mult_left_mono [of _ _ "1 - a i", + OF asum_le less_imp_le[OF i0]], of "a i * f (y i)"] + by simp also have "\ = (\ j \ s. (1 - a i) * ?a j * f (y j)) + a i * f (y i)" - unfolding setsum_right_distrib[of "1 - a i" "\ j. ?a j * f (y j)"] using i0 by auto + unfolding setsum_right_distrib[of "1 - a i" "\ j. ?a j * f (y j)"] + using i0 by auto also have "\ = (\ j \ s. a j * f (y j)) + a i * f (y i)" using i0 by auto also have "\ = (\ j \ insert i s. a j * f (y j))" @@ -635,9 +653,9 @@ fix \ :: real assume *: "convex_on C f" "x \ C" "y \ C" "0 \ \" "\ \ 1" from this[unfolded convex_on_def, rule_format] - have "\u v. 0 \ u \ 0 \ v \ u + v = 1 \ f (u *\<^sub>R x + v *\<^sub>R y) \ u * f x + v * f y" + have "0 \ u \ 0 \ v \ u + v = 1 \ f (u *\<^sub>R x + v *\<^sub>R y) \ u * f x + v * f y" for u v by auto - from this[of "\" "1 - \", simplified] * + from this [of "\" "1 - \", simplified] * show "f (\ *\<^sub>R x + (1 - \) *\<^sub>R y) \ \ * f x + (1 - \) * f y" by auto next @@ -701,8 +719,8 @@ using * unfolding convex_alt by fastforce have geq: "\ * (f x - f ?x) + (1 - \) * (f y - f ?x) \ \ * f' ?x * (x - ?x) + (1 - \) * f' ?x * (y - ?x)" - using add_mono[OF mult_left_mono[OF leq[OF xpos *(2)] \\ \ 0\] - mult_left_mono[OF leq[OF xpos *(3)] \1 - \ \ 0\]] + using add_mono [OF mult_left_mono [OF leq [OF xpos *(2)] \\ \ 0\] + mult_left_mono [OF leq [OF xpos *(3)] \1 - \ \ 0\]] by auto then have "\ * f x + (1 - \) * f y - f ?x \ 0" by (auto simp: field_simps) @@ -728,14 +746,14 @@ have "?\ * x + (1 - ?\) * y = (y - z) * x / (y - x) + (1 - (y - z) / (y - x)) * y" by (auto simp: field_simps) also have "\ = ((y - z) * x + (y - x - (y - z)) * y) / (y - x)" - using assms unfolding add_divide_distrib by (auto simp: field_simps) + using assms by (simp only: add_divide_distrib) (auto simp: field_simps) also have "\ = z" using assms by (auto simp: field_simps) finally show ?thesis using comb by auto qed - show "z \ C" using z less assms - unfolding atLeastAtMost_iff le_less by auto + show "z \ C" + using z less assms by (auto simp: le_less) qed lemma f''_imp_f': @@ -744,20 +762,21 @@ and f': "\x. x \ C \ DERIV f x :> (f' x)" and f'': "\x. x \ C \ DERIV f' x :> (f'' x)" and pos: "\x. x \ C \ f'' x \ 0" - and "x \ C" "y \ C" + and x: "x \ C" + and y: "y \ C" shows "f' x * (y - x) \ f y - f x" using assms proof - - { - fix x y :: real - assume *: "x \ C" "y \ C" "y > x" - then have ge: "y - x > 0" "y - x \ 0" + have less_imp: "f y - f x \ f' x * (y - x)" "f' y * (x - y) \ f x - f y" + if *: "x \ C" "y \ C" "y > x" for x y :: real + proof - + from * have ge: "y - x > 0" "y - x \ 0" by auto from * have le: "x - y < 0" "x - y \ 0" by auto then obtain z1 where z1: "z1 > x" "z1 < y" "f y - f x = (y - x) * f' z1" using subsetD[OF atMostAtLeast_subset_convex[OF \convex C\ \x \ C\ \y \ C\ \x < y\], - THEN f', THEN MVT2[OF \x < y\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] + THEN f', THEN MVT2[OF \x < y\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] by auto then have "z1 \ C" using atMostAtLeast_subset_convex \convex C\ \x \ C\ \y \ C\ \x < y\ @@ -766,11 +785,11 @@ by (simp add: field_simps) obtain z2 where z2: "z2 > x" "z2 < z1" "f' z1 - f' x = (z1 - x) * f'' z2" using subsetD[OF atMostAtLeast_subset_convex[OF \convex C\ \x \ C\ \z1 \ C\ \x < z1\], - THEN f'', THEN MVT2[OF \x < z1\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 + THEN f'', THEN MVT2[OF \x < z1\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 by auto obtain z3 where z3: "z3 > z1" "z3 < y" "f' y - f' z1 = (y - z1) * f'' z3" using subsetD[OF atMostAtLeast_subset_convex[OF \convex C\ \z1 \ C\ \y \ C\ \z1 < y\], - THEN f'', THEN MVT2[OF \z1 < y\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 + THEN f'', THEN MVT2[OF \z1 < y\, rule_format, unfolded atLeastAtMost_iff[symmetric]]] z1 by auto have "f' y - (f x - f y) / (x - y) = f' y - f' z1" using * z1' by auto @@ -818,22 +837,18 @@ by (simp add: algebra_simps) then have "f y - f x - f' x * (y - x) \ 0" using ge by auto - then have "f y - f x \ f' x * (y - x)" "f' y * (x - y) \ f x - f y" + then show "f y - f x \ f' x * (y - x)" "f' y * (x - y) \ f x - f y" using res by auto - } note less_imp = this - { - fix x y :: real - assume "x \ C" "y \ C" "x \ y" - then have"f y - f x \ f' x * (y - x)" - unfolding neq_iff using less_imp by auto - } - moreover - { - fix x y :: real - assume "x \ C" "y \ C" "x = y" - then have "f y - f x \ f' x * (y - x)" by auto - } - ultimately show ?thesis using assms by blast + qed + show ?thesis + proof (cases "x = y") + case True + with x y show ?thesis by auto + next + case False + with less_imp x y show ?thesis + by (auto simp: neq_iff) + qed qed lemma f''_ge0_imp_convex: @@ -855,10 +870,10 @@ using DERIV_log by auto then have f': "\z. z > 0 \ DERIV (\ z. - log b z) z :> - 1 / (ln b * z)" by (auto simp: DERIV_minus) - have "\z :: real. z > 0 \ DERIV inverse z :> - (inverse z ^ Suc (Suc 0))" + have "\z::real. z > 0 \ DERIV inverse z :> - (inverse z ^ Suc (Suc 0))" using less_imp_neq[THEN not_sym, THEN DERIV_inverse] by auto from this[THEN DERIV_cmult, of _ "- 1 / ln b"] - have "\z :: real. z > 0 \ + have "\z::real. z > 0 \ DERIV (\ z. (- 1 / ln b) * inverse z) z :> (- 1 / ln b) * (- (inverse z ^ Suc (Suc 0)))" by auto then have f''0: "\z::real. z > 0 \ @@ -866,9 +881,9 @@ unfolding inverse_eq_divide by (auto simp: mult.assoc) have f''_ge0: "\z::real. z > 0 \ 1 / (ln b * z * z) \ 0" using \b > 1\ by (auto intro!: less_imp_le) - from f''_ge0_imp_convex[OF pos_is_convex, - unfolded greaterThan_iff, OF f' f''0 f''_ge0] - show ?thesis by auto + from f''_ge0_imp_convex[OF pos_is_convex, unfolded greaterThan_iff, OF f' f''0 f''_ge0] + show ?thesis + by auto qed @@ -876,45 +891,59 @@ lemma convex_on_realI: assumes "connected A" - assumes "\x. x \ A \ (f has_real_derivative f' x) (at x)" - assumes "\x y. x \ A \ y \ A \ x \ y \ f' x \ f' y" - shows "convex_on A f" + and "\x. x \ A \ (f has_real_derivative f' x) (at x)" + and "\x y. x \ A \ y \ A \ x \ y \ f' x \ f' y" + shows "convex_on A f" proof (rule convex_on_linorderI) fix t x y :: real - assume t: "t > 0" "t < 1" and xy: "x \ A" "y \ A" "x < y" + assume t: "t > 0" "t < 1" + assume xy: "x \ A" "y \ A" "x < y" define z where "z = (1 - t) * x + t * y" - with \connected A\ and xy have ivl: "{x..y} \ A" using connected_contains_Icc by blast + with \connected A\ and xy have ivl: "{x..y} \ A" + using connected_contains_Icc by blast - from xy t have xz: "z > x" by (simp add: z_def algebra_simps) - have "y - z = (1 - t) * (y - x)" by (simp add: z_def algebra_simps) - also from xy t have "... > 0" by (intro mult_pos_pos) simp_all - finally have yz: "z < y" by simp + from xy t have xz: "z > x" + by (simp add: z_def algebra_simps) + have "y - z = (1 - t) * (y - x)" + by (simp add: z_def algebra_simps) + also from xy t have "\ > 0" + by (intro mult_pos_pos) simp_all + finally have yz: "z < y" + by simp from assms xz yz ivl t have "\\. \ > x \ \ < z \ f z - f x = (z - x) * f' \" by (intro MVT2) (auto intro!: assms(2)) - then obtain \ where \: "\ > x" "\ < z" "f' \ = (f z - f x) / (z - x)" by auto + then obtain \ where \: "\ > x" "\ < z" "f' \ = (f z - f x) / (z - x)" + by auto from assms xz yz ivl t have "\\. \ > z \ \ < y \ f y - f z = (y - z) * f' \" by (intro MVT2) (auto intro!: assms(2)) - then obtain \ where \: "\ > z" "\ < y" "f' \ = (f y - f z) / (y - z)" by auto + then obtain \ where \: "\ > z" "\ < y" "f' \ = (f y - f z) / (y - z)" + by auto from \(3) have "(f y - f z) / (y - z) = f' \" .. - also from \ \ ivl have "\ \ A" "\ \ A" by auto - with \ \ have "f' \ \ f' \" by (intro assms(3)) auto + also from \ \ ivl have "\ \ A" "\ \ A" + by auto + with \ \ have "f' \ \ f' \" + by (intro assms(3)) auto also from \(3) have "f' \ = (f z - f x) / (z - x)" . finally have "(f y - f z) * (z - x) \ (f z - f x) * (y - z)" using xz yz by (simp add: field_simps) - also have "z - x = t * (y - x)" by (simp add: z_def algebra_simps) - also have "y - z = (1 - t) * (y - x)" by (simp add: z_def algebra_simps) - finally have "(f y - f z) * t \ (f z - f x) * (1 - t)" using xy by simp - thus "(1 - t) * f x + t * f y \ f ((1 - t) *\<^sub>R x + t *\<^sub>R y)" + also have "z - x = t * (y - x)" + by (simp add: z_def algebra_simps) + also have "y - z = (1 - t) * (y - x)" + by (simp add: z_def algebra_simps) + finally have "(f y - f z) * t \ (f z - f x) * (1 - t)" + using xy by simp + then show "(1 - t) * f x + t * f y \ f ((1 - t) *\<^sub>R x + t *\<^sub>R y)" by (simp add: z_def algebra_simps) qed lemma convex_on_inverse: assumes "A \ {0<..}" - shows "convex_on A (inverse :: real \ real)" + shows "convex_on A (inverse :: real \ real)" proof (rule convex_on_subset[OF _ assms], intro convex_on_realI[of _ _ "\x. -inverse (x^2)"]) - fix u v :: real assume "u \ {0<..}" "v \ {0<..}" "u \ v" + fix u v :: real + assume "u \ {0<..}" "v \ {0<..}" "u \ v" with assms show "-inverse (u^2) \ -inverse (v^2)" by (intro le_imp_neg_le le_imp_inverse_le power_mono) (simp_all) qed (insert assms, auto intro!: derivative_eq_intros simp: divide_simps power2_eq_square) @@ -922,40 +951,47 @@ lemma convex_onD_Icc': assumes "convex_on {x..y} f" "c \ {x..y}" defines "d \ y - x" - shows "f c \ (f y - f x) / d * (c - x) + f x" -proof (cases y x rule: linorder_cases) - assume less: "x < y" - hence d: "d > 0" by (simp add: d_def) + shows "f c \ (f y - f x) / d * (c - x) + f x" +proof (cases x y rule: linorder_cases) + case less + then have d: "d > 0" + by (simp add: d_def) from assms(2) less have A: "0 \ (c - x) / d" "(c - x) / d \ 1" by (simp_all add: d_def divide_simps) - have "f c = f (x + (c - x) * 1)" by simp - also from less have "1 = ((y - x) / d)" by (simp add: d_def) + have "f c = f (x + (c - x) * 1)" + by simp + also from less have "1 = ((y - x) / d)" + by (simp add: d_def) also from d have "x + (c - x) * \ = (1 - (c - x) / d) *\<^sub>R x + ((c - x) / d) *\<^sub>R y" by (simp add: field_simps) - also have "f \ \ (1 - (c - x) / d) * f x + (c - x) / d * f y" using assms less - by (intro convex_onD_Icc) simp_all - also from d have "\ = (f y - f x) / d * (c - x) + f x" by (simp add: field_simps) + also have "f \ \ (1 - (c - x) / d) * f x + (c - x) / d * f y" + using assms less by (intro convex_onD_Icc) simp_all + also from d have "\ = (f y - f x) / d * (c - x) + f x" + by (simp add: field_simps) finally show ?thesis . qed (insert assms(2), simp_all) lemma convex_onD_Icc'': assumes "convex_on {x..y} f" "c \ {x..y}" defines "d \ y - x" - shows "f c \ (f x - f y) / d * (y - c) + f y" -proof (cases y x rule: linorder_cases) - assume less: "x < y" - hence d: "d > 0" by (simp add: d_def) + shows "f c \ (f x - f y) / d * (y - c) + f y" +proof (cases x y rule: linorder_cases) + case less + then have d: "d > 0" + by (simp add: d_def) from assms(2) less have A: "0 \ (y - c) / d" "(y - c) / d \ 1" by (simp_all add: d_def divide_simps) - have "f c = f (y - (y - c) * 1)" by simp - also from less have "1 = ((y - x) / d)" by (simp add: d_def) + have "f c = f (y - (y - c) * 1)" + by simp + also from less have "1 = ((y - x) / d)" + by (simp add: d_def) also from d have "y - (y - c) * \ = (1 - (1 - (y - c) / d)) *\<^sub>R x + (1 - (y - c) / d) *\<^sub>R y" by (simp add: field_simps) - also have "f \ \ (1 - (1 - (y - c) / d)) * f x + (1 - (y - c) / d) * f y" using assms less - by (intro convex_onD_Icc) (simp_all add: field_simps) - also from d have "\ = (f x - f y) / d * (y - c) + f y" by (simp add: field_simps) + also have "f \ \ (1 - (1 - (y - c) / d)) * f x + (1 - (y - c) / d) * f y" + using assms less by (intro convex_onD_Icc) (simp_all add: field_simps) + also from d have "\ = (f x - f y) / d * (y - c) + f y" + by (simp add: field_simps) finally show ?thesis . qed (insert assms(2), simp_all) - end diff -r 2033a3960c36 -r ea8dfb0ed10e src/HOL/Library/Set_Algebras.thy --- a/src/HOL/Library/Set_Algebras.thy Wed Jul 13 20:14:16 2016 +0200 +++ b/src/HOL/Library/Set_Algebras.thy Wed Jul 13 20:47:56 2016 +0200 @@ -7,13 +7,13 @@ section \Algebraic operations on sets\ theory Set_Algebras -imports Main + imports Main begin text \ - This library lifts operations like addition and multiplication to - sets. It was designed to support asymptotic calculations. See the - comments at the top of @{file "BigO.thy"}. + This library lifts operations like addition and multiplication to sets. It + was designed to support asymptotic calculations. See the comments at the top + of @{file "BigO.thy"}. \ instantiation set :: (plus) plus