# HG changeset patch # User haftmann # Date 1291304355 -3600 # Node ID 3c45d6753fd0e031255ab3906ba2a0ba9fa317a7 # Parent 7046acb44f7a41fc8b042947ca6f722406ba8215# Parent da4bdafeef7c5cd98e53eef44c5733529bc47a07 merged diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Complete_Lattice.thy --- a/src/HOL/Complete_Lattice.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Complete_Lattice.thy Thu Dec 02 16:39:15 2010 +0100 @@ -172,6 +172,18 @@ "(\m. m \ B \ \n\A. f n \ g m) \ (INF n:A. f n) \ (INF n:B. g n)" by (force intro!: Inf_mono simp: INFI_def) +lemma SUP_subset: "A \ B \ SUPR A f \ SUPR B f" + by (intro SUP_mono) auto + +lemma INF_subset: "A \ B \ INFI B f \ INFI A f" + by (intro INF_mono) auto + +lemma SUP_commute: "(SUP i:A. SUP j:B. f i j) = (SUP j:B. SUP i:A. f i j)" + by (iprover intro: SUP_leI le_SUPI order_trans antisym) + +lemma INF_commute: "(INF i:A. INF j:B. f i j) = (INF j:B. INF i:A. f i j)" + by (iprover intro: INF_leI le_INFI order_trans antisym) + end lemma less_Sup_iff: @@ -184,6 +196,16 @@ shows "Inf S < a \ (\x\S. x < a)" unfolding not_le[symmetric] le_Inf_iff by auto +lemma less_SUP_iff: + fixes a :: "'a::{complete_lattice,linorder}" + shows "a < (SUP i:A. f i) \ (\x\A. a < f x)" + unfolding SUPR_def less_Sup_iff by auto + +lemma INF_less_iff: + fixes a :: "'a::{complete_lattice,linorder}" + shows "(INF i:A. f i) < a \ (\x\A. f x < a)" + unfolding INFI_def Inf_less_iff by auto + subsection {* @{typ bool} and @{typ "_ \ _"} as complete lattice *} instantiation bool :: complete_lattice diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Decision_Procs/Approximation.thy --- a/src/HOL/Decision_Procs/Approximation.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Decision_Procs/Approximation.thy Thu Dec 02 16:39:15 2010 +0100 @@ -1,18 +1,26 @@ -(* Author: Johannes Hoelzl 2008 / 2009 *) +(* Author: Johannes Hoelzl, TU Muenchen + Coercions removed by Dmitriy Traytel *) header {* Prove Real Valued Inequalities by Computation *} -theory Approximation -imports Complex_Main Float Reflection Dense_Linear_Order Efficient_Nat +theory Approximation_coercion +imports Complex_Main Float Reflection "~~/src/HOL/Decision_Procs/Dense_Linear_Order" Efficient_Nat begin +declare [[coercion_map map]] +declare [[coercion_map "% f g h . g o h o f"]] +declare [[coercion_map "% f g (x,y) . (f x, g y)"]] +declare [[coercion int]] +declare [[coercion "% x . Float x 0"]] +declare [[coercion "real::float\real"]] + section "Horner Scheme" subsection {* Define auxiliary helper @{text horner} function *} primrec horner :: "(nat \ nat) \ (nat \ nat \ nat) \ nat \ nat \ nat \ real \ real" where "horner F G 0 i k x = 0" | -"horner F G (Suc n) i k x = 1 / real k - x * horner F G n (F i) (G i k) x" +"horner F G (Suc n) i k x = 1 / k - x * horner F G n (F i) (G i k) x" lemma horner_schema': fixes x :: real and a :: "nat \ real" shows "a 0 - x * (\ i=0.. i=0.. nat" and G :: "nat \ nat \ nat" and F :: "nat \ nat" assumes f_Suc: "\n. f (Suc n) = G ((F ^^ n) s) (f n)" - shows "horner F G n ((F ^^ j') s) (f j') x = (\ j = 0..< n. -1 ^ j * (1 / real (f (j' + j))) * x ^ j)" + shows "horner F G n ((F ^^ j') s) (f j') x = (\ j = 0..< n. -1 ^ j * (1 / (f (j' + j))) * x ^ j)" proof (induct n arbitrary: i k j') case (Suc n) show ?case unfolding horner.simps Suc[where j'="Suc j'", unfolded funpow.simps comp_def f_Suc] - using horner_schema'[of "\ j. 1 / real (f (j' + j))"] by auto + using horner_schema'[of "\ j. 1 / (f (j' + j))"] by auto qed auto lemma horner_bounds': + fixes lb :: "nat \ nat \ nat \ float \ float" and ub :: "nat \ nat \ nat \ float \ float" assumes "0 \ real x" and f_Suc: "\n. f (Suc n) = G ((F ^^ n) s) (f n)" and lb_0: "\ i k x. lb 0 i k x = 0" - and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 (int k) - x * (ub n (F i) (G i k) x)" + and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 k - x * (ub n (F i) (G i k) x)" and ub_0: "\ i k x. ub 0 i k x = 0" - and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 (int k) - x * (lb n (F i) (G i k) x)" - shows "real (lb n ((F ^^ j') s) (f j') x) \ horner F G n ((F ^^ j') s) (f j') (real x) \ - horner F G n ((F ^^ j') s) (f j') (real x) \ real (ub n ((F ^^ j') s) (f j') x)" + and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 k - x * (lb n (F i) (G i k) x)" + shows "(lb n ((F ^^ j') s) (f j') x) \ horner F G n ((F ^^ j') s) (f j') x \ + horner F G n ((F ^^ j') s) (f j') x \ (ub n ((F ^^ j') s) (f j') x)" (is "?lb n j' \ ?horner n j' \ ?horner n j' \ ?ub n j'") proof (induct n arbitrary: j') case 0 thus ?case unfolding lb_0 ub_0 horner.simps by auto @@ -47,16 +56,17 @@ case (Suc n) have "?lb (Suc n) j' \ ?horner (Suc n) j'" unfolding lb_Suc ub_Suc horner.simps real_of_float_sub diff_minus proof (rule add_mono) - show "real (lapprox_rat prec 1 (int (f j'))) \ 1 / real (f j')" using lapprox_rat[of prec 1 "int (f j')"] by auto + show "(lapprox_rat prec 1 (f j')) \ 1 / (f j')" using lapprox_rat[of prec 1 "f j'"] by auto from Suc[where j'="Suc j'", unfolded funpow.simps comp_def f_Suc, THEN conjunct2] `0 \ real x` - show "- real (x * ub n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) x) \ - (real x * horner F G n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) (real x))" + show "- real (x * ub n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) x) \ + - (x * horner F G n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) x)" unfolding real_of_float_mult neg_le_iff_le by (rule mult_left_mono) qed moreover have "?horner (Suc n) j' \ ?ub (Suc n) j'" unfolding ub_Suc ub_Suc horner.simps real_of_float_sub diff_minus proof (rule add_mono) - show "1 / real (f j') \ real (rapprox_rat prec 1 (int (f j')))" using rapprox_rat[of 1 "int (f j')" prec] by auto + show "1 / (f j') \ (rapprox_rat prec 1 (f j'))" using rapprox_rat[of 1 "f j'" prec] by auto from Suc[where j'="Suc j'", unfolded funpow.simps comp_def f_Suc, THEN conjunct1] `0 \ real x` - show "- (real x * horner F G n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) (real x)) \ + show "- (x * horner F G n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) x) \ - real (x * lb n (F ((F ^^ j') s)) (G ((F ^^ j') s) (f j')) x)" unfolding real_of_float_mult neg_le_iff_le by (rule mult_left_mono) qed @@ -75,11 +85,11 @@ lemma horner_bounds: fixes F :: "nat \ nat" and G :: "nat \ nat \ nat" assumes "0 \ real x" and f_Suc: "\n. f (Suc n) = G ((F ^^ n) s) (f n)" and lb_0: "\ i k x. lb 0 i k x = 0" - and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 (int k) - x * (ub n (F i) (G i k) x)" + and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 k - x * (ub n (F i) (G i k) x)" and ub_0: "\ i k x. ub 0 i k x = 0" - and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 (int k) - x * (lb n (F i) (G i k) x)" - shows "real (lb n ((F ^^ j') s) (f j') x) \ (\j=0..j=0.. real (ub n ((F ^^ j') s) (f j') x)" (is "?ub") + and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 k - x * (lb n (F i) (G i k) x)" + shows "(lb n ((F ^^ j') s) (f j') x) \ (\j=0..j=0.. (ub n ((F ^^ j') s) (f j') x)" (is "?ub") proof - have "?lb \ ?ub" using horner_bounds'[where lb=lb, OF `0 \ real x` f_Suc lb_0 lb_Suc ub_0 ub_Suc] @@ -90,11 +100,11 @@ lemma horner_bounds_nonpos: fixes F :: "nat \ nat" and G :: "nat \ nat \ nat" assumes "real x \ 0" and f_Suc: "\n. f (Suc n) = G ((F ^^ n) s) (f n)" and lb_0: "\ i k x. lb 0 i k x = 0" - and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 (int k) + x * (ub n (F i) (G i k) x)" + and lb_Suc: "\ n i k x. lb (Suc n) i k x = lapprox_rat prec 1 k + x * (ub n (F i) (G i k) x)" and ub_0: "\ i k x. ub 0 i k x = 0" - and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 (int k) + x * (lb n (F i) (G i k) x)" - shows "real (lb n ((F ^^ j') s) (f j') x) \ (\j=0..j=0.. real (ub n ((F ^^ j') s) (f j') x)" (is "?ub") + and ub_Suc: "\ n i k x. ub (Suc n) i k x = rapprox_rat prec 1 k + x * (lb n (F i) (G i k) x)" + shows "(lb n ((F ^^ j') s) (f j') x) \ (\j=0..j=0.. (ub n ((F ^^ j') s) (f j') x)" (is "?ub") proof - { fix x y z :: float have "x - y * z = x + - y * z" by (cases x, cases y, cases z, simp add: plus_float.simps minus_float_def uminus_float.simps times_float.simps algebra_simps) @@ -102,13 +112,13 @@ { fix x :: float have "- (- x) = x" by (cases x, auto simp add: uminus_float.simps) } note minus_minus = this - have move_minus: "real (-x) = -1 * real x" by auto - - have sum_eq: "(\j=0..j = 0..j=0..j = 0.. {0 ..< n}" - show "1 / real (f (j' + j)) * real x ^ j = -1 ^ j * (1 / real (f (j' + j))) * real (- x) ^ j" + show "1 / (f (j' + j)) * real x ^ j = -1 ^ j * (1 / (f (j' + j))) * real (- x) ^ j" unfolding move_minus power_mult_distrib mult_assoc[symmetric] unfolding mult_commute unfolding mult_assoc[of "-1 ^ j", symmetric] power_mult_distrib[symmetric] by auto @@ -159,15 +169,16 @@ else if u < 0 then (u ^ n, l ^ n) else (0, (max (-l) u) ^ n))" -lemma float_power_bnds: assumes "(l1, u1) = float_power_bnds n l u" and "x \ {real l .. real u}" - shows "x ^ n \ {real l1..real u1}" +lemma float_power_bnds: fixes x :: real + assumes "(l1, u1) = float_power_bnds n l u" and "x \ {l .. u}" + shows "x ^ n \ {l1..u1}" proof (cases "even n") case True show ?thesis proof (cases "0 < l") case True hence "odd n \ 0 < l" and "0 \ real l" unfolding less_float_def by auto have u1: "u1 = u ^ n" and l1: "l1 = l ^ n" using assms unfolding float_power_bnds_def if_P[OF `odd n \ 0 < l`] by auto - have "real l ^ n \ x ^ n" and "x ^ n \ real u ^ n " using `0 \ real l` and assms unfolding atLeastAtMost_iff using power_mono[of "real l" x] power_mono[of x "real u"] by auto + have "real l ^ n \ x ^ n" and "x ^ n \ real u ^ n " using `0 \ real l` and assms unfolding atLeastAtMost_iff using power_mono[of l x] power_mono[of x u] by auto thus ?thesis using assms `0 < l` unfolding atLeastAtMost_iff l1 u1 float_power less_float_def by auto next case False hence P: "\ (odd n \ 0 < l)" using `even n` by auto @@ -198,7 +209,7 @@ thus ?thesis unfolding atLeastAtMost_iff l1 u1 float_power less_float_def by auto qed -lemma bnds_power: "\ x l u. (l1, u1) = float_power_bnds n l u \ x \ {real l .. real u} \ real l1 \ x ^ n \ x ^ n \ real u1" +lemma bnds_power: "\ (x::real) l u. (l1, u1) = float_power_bnds n l u \ x \ {l .. u} \ l1 \ x ^ n \ x ^ n \ u1" using float_power_bnds by auto section "Square root" @@ -242,25 +253,25 @@ qed lemma sqrt_iteration_bound: assumes "0 < real x" - shows "sqrt (real x) < real (sqrt_iteration prec n x)" + shows "sqrt x < (sqrt_iteration prec n x)" proof (induct n) case 0 show ?case proof (cases x) case (Float m e) hence "0 < m" using float_pos_m_pos[unfolded less_float_def] assms by auto - hence "0 < sqrt (real m)" by auto - - have int_nat_bl: "int (nat (bitlen m)) = bitlen m" using bitlen_ge0 by auto - - have "real x = (real m / 2^nat (bitlen m)) * pow2 (e + int (nat (bitlen m)))" + hence "0 < sqrt m" by auto + + have int_nat_bl: "(nat (bitlen m)) = bitlen m" using bitlen_ge0 by auto + + have "x = (m / 2^nat (bitlen m)) * pow2 (e + (nat (bitlen m)))" unfolding pow2_add pow2_int Float real_of_float_simp by auto - also have "\ < 1 * pow2 (e + int (nat (bitlen m)))" + also have "\ < 1 * pow2 (e + nat (bitlen m))" proof (rule mult_strict_right_mono, auto) show "real m < 2^nat (bitlen m)" using bitlen_bounds[OF `0 < m`, THEN conjunct2] unfolding real_of_int_less_iff[of m, symmetric] by auto qed - finally have "sqrt (real x) < sqrt (pow2 (e + bitlen m))" unfolding int_nat_bl by auto + finally have "sqrt x < sqrt (pow2 (e + bitlen m))" unfolding int_nat_bl by auto also have "\ \ pow2 ((e + bitlen m) div 2 + 1)" proof - let ?E = "e + bitlen m" @@ -295,18 +306,18 @@ next case (Suc n) let ?b = "sqrt_iteration prec n x" - have "0 < sqrt (real x)" using `0 < real x` by auto + have "0 < sqrt x" using `0 < real x` by auto also have "\ < real ?b" using Suc . - finally have "sqrt (real x) < (real ?b + real x / real ?b)/2" using sqrt_ub_pos_pos_1[OF Suc _ `0 < real x`] by auto - also have "\ \ (real ?b + real (float_divr prec x ?b))/2" by (rule divide_right_mono, auto simp add: float_divr) - also have "\ = real (Float 1 -1) * (real ?b + real (float_divr prec x ?b))" by auto + finally have "sqrt x < (?b + x / ?b)/2" using sqrt_ub_pos_pos_1[OF Suc _ `0 < real x`] by auto + also have "\ \ (?b + (float_divr prec x ?b))/2" by (rule divide_right_mono, auto simp add: float_divr) + also have "\ = (Float 1 -1) * (?b + (float_divr prec x ?b))" by auto finally show ?case unfolding sqrt_iteration.simps Let_def real_of_float_mult real_of_float_add right_distrib . qed lemma sqrt_iteration_lower_bound: assumes "0 < real x" shows "0 < real (sqrt_iteration prec n x)" (is "0 < ?sqrt") proof - - have "0 < sqrt (real x)" using assms by auto + have "0 < sqrt x" using assms by auto also have "\ < ?sqrt" using sqrt_iteration_bound[OF assms] . finally show ?thesis . qed @@ -324,31 +335,31 @@ qed lemma bnds_sqrt': - shows "sqrt (real x) \ { real (lb_sqrt prec x) .. real (ub_sqrt prec x) }" + shows "sqrt x \ {(lb_sqrt prec x) .. (ub_sqrt prec x) }" proof - { fix x :: float assume "0 < x" hence "0 < real x" and "0 \ real x" unfolding less_float_def by auto - hence sqrt_gt0: "0 < sqrt (real x)" by auto - hence sqrt_ub: "sqrt (real x) < real (sqrt_iteration prec prec x)" using sqrt_iteration_bound by auto - - have "real (float_divl prec x (sqrt_iteration prec prec x)) \ - real x / real (sqrt_iteration prec prec x)" by (rule float_divl) - also have "\ < real x / sqrt (real x)" + hence sqrt_gt0: "0 < sqrt x" by auto + hence sqrt_ub: "sqrt x < sqrt_iteration prec prec x" using sqrt_iteration_bound by auto + + have "(float_divl prec x (sqrt_iteration prec prec x)) \ + x / (sqrt_iteration prec prec x)" by (rule float_divl) + also have "\ < x / sqrt x" by (rule divide_strict_left_mono[OF sqrt_ub `0 < real x` mult_pos_pos[OF order_less_trans[OF sqrt_gt0 sqrt_ub] sqrt_gt0]]) - also have "\ = sqrt (real x)" - unfolding inverse_eq_iff_eq[of _ "sqrt (real x)", symmetric] + also have "\ = sqrt x" + unfolding inverse_eq_iff_eq[of _ "sqrt x", symmetric] sqrt_divide_self_eq[OF `0 \ real x`, symmetric] by auto - finally have "real (lb_sqrt prec x) \ sqrt (real x)" + finally have "lb_sqrt prec x \ sqrt x" unfolding lb_sqrt.simps if_P[OF `0 < x`] by auto } note lb = this { fix x :: float assume "0 < x" hence "0 < real x" unfolding less_float_def by auto - hence "0 < sqrt (real x)" by auto - hence "sqrt (real x) < real (sqrt_iteration prec prec x)" + hence "0 < sqrt x" by auto + hence "sqrt x < sqrt_iteration prec prec x" using sqrt_iteration_bound by auto - hence "sqrt (real x) \ real (ub_sqrt prec x)" + hence "sqrt x \ ub_sqrt prec x" unfolding ub_sqrt.simps if_P[OF `0 < x`] by auto } note ub = this @@ -369,20 +380,20 @@ qed qed qed -lemma bnds_sqrt: "\ x lx ux. (l, u) = (lb_sqrt prec lx, ub_sqrt prec ux) \ x \ {real lx .. real ux} \ real l \ sqrt x \ sqrt x \ real u" +lemma bnds_sqrt: "\ (x::real) lx ux. (l, u) = (lb_sqrt prec lx, ub_sqrt prec ux) \ x \ {lx .. ux} \ l \ sqrt x \ sqrt x \ u" proof ((rule allI) +, rule impI, erule conjE, rule conjI) - fix x lx ux + fix x :: real fix lx ux assume "(l, u) = (lb_sqrt prec lx, ub_sqrt prec ux)" - and x: "x \ {real lx .. real ux}" + and x: "x \ {lx .. ux}" hence l: "l = lb_sqrt prec lx " and u: "u = ub_sqrt prec ux" by auto - have "sqrt (real lx) \ sqrt x" using x by auto + have "sqrt lx \ sqrt x" using x by auto from order_trans[OF _ this] - show "real l \ sqrt x" unfolding l using bnds_sqrt'[of lx prec] by auto - - have "sqrt x \ sqrt (real ux)" using x by auto + show "l \ sqrt x" unfolding l using bnds_sqrt'[of lx prec] by auto + + have "sqrt x \ sqrt ux" using x by auto from order_trans[OF this] - show "sqrt x \ real u" unfolding u using bnds_sqrt'[of ux prec] by auto + show "sqrt x \ u" unfolding u using bnds_sqrt'[of ux prec] by auto qed section "Arcus tangens and \" @@ -400,25 +411,25 @@ and lb_arctan_horner :: "nat \ nat \ nat \ float \ float" where "ub_arctan_horner prec 0 k x = 0" | "ub_arctan_horner prec (Suc n) k x = - (rapprox_rat prec 1 (int k)) - x * (lb_arctan_horner prec n (k + 2) x)" + (rapprox_rat prec 1 k) - x * (lb_arctan_horner prec n (k + 2) x)" | "lb_arctan_horner prec 0 k x = 0" | "lb_arctan_horner prec (Suc n) k x = - (lapprox_rat prec 1 (int k)) - x * (ub_arctan_horner prec n (k + 2) x)" + (lapprox_rat prec 1 k) - x * (ub_arctan_horner prec n (k + 2) x)" lemma arctan_0_1_bounds': assumes "0 \ real x" "real x \ 1" and "even n" - shows "arctan (real x) \ {real (x * lb_arctan_horner prec n 1 (x * x)) .. real (x * ub_arctan_horner prec (Suc n) 1 (x * x))}" + shows "arctan x \ {(x * lb_arctan_horner prec n 1 (x * x)) .. (x * ub_arctan_horner prec (Suc n) 1 (x * x))}" proof - - let "?c i" = "-1^i * (1 / real (i * 2 + 1) * real x ^ (i * 2 + 1))" + let "?c i" = "-1^i * (1 / (i * 2 + (1::nat)) * real x ^ (i * 2 + 1))" let "?S n" = "\ i=0.. real (x * x)" by auto from `even n` obtain m where "2 * m = n" unfolding even_mult_two_ex by auto - have "arctan (real x) \ { ?S n .. ?S (Suc n) }" + have "arctan x \ { ?S n .. ?S (Suc n) }" proof (cases "real x = 0") case False hence "0 < real x" using `0 \ real x` by auto - hence prem: "0 < 1 / real (0 * 2 + (1::nat)) * real x ^ (0 * 2 + 1)" by auto + hence prem: "0 < 1 / (0 * 2 + (1::nat)) * real x ^ (0 * 2 + 1)" by auto have "\ real x \ \ 1" using `0 \ real x` `real x \ 1` by auto from mp[OF summable_Leibniz(2)[OF zeroseq_arctan_series[OF this] monoseq_arctan_series[OF this]] prem, THEN spec, of m, unfolded `2 * m = n`] @@ -433,34 +444,34 @@ and ub="\n i k x. ub_arctan_horner prec n k x", OF `0 \ real (x*x)` F lb_arctan_horner.simps ub_arctan_horner.simps] - { have "real (x * lb_arctan_horner prec n 1 (x*x)) \ ?S n" + { have "(x * lb_arctan_horner prec n 1 (x*x)) \ ?S n" using bounds(1) `0 \ real x` unfolding real_of_float_mult power_add power_one_right mult_assoc[symmetric] setsum_left_distrib[symmetric] unfolding mult_commute[where 'a=real] mult_commute[of _ "2::nat"] power_mult power2_eq_square[of "real x"] by (auto intro!: mult_left_mono) - also have "\ \ arctan (real x)" using arctan_bounds .. - finally have "real (x * lb_arctan_horner prec n 1 (x*x)) \ arctan (real x)" . } + also have "\ \ arctan x" using arctan_bounds .. + finally have "(x * lb_arctan_horner prec n 1 (x*x)) \ arctan x" . } moreover - { have "arctan (real x) \ ?S (Suc n)" using arctan_bounds .. - also have "\ \ real (x * ub_arctan_horner prec (Suc n) 1 (x*x))" + { have "arctan x \ ?S (Suc n)" using arctan_bounds .. + also have "\ \ (x * ub_arctan_horner prec (Suc n) 1 (x*x))" using bounds(2)[of "Suc n"] `0 \ real x` unfolding real_of_float_mult power_add power_one_right mult_assoc[symmetric] setsum_left_distrib[symmetric] unfolding mult_commute[where 'a=real] mult_commute[of _ "2::nat"] power_mult power2_eq_square[of "real x"] by (auto intro!: mult_left_mono) - finally have "arctan (real x) \ real (x * ub_arctan_horner prec (Suc n) 1 (x*x))" . } + finally have "arctan x \ (x * ub_arctan_horner prec (Suc n) 1 (x*x))" . } ultimately show ?thesis by auto qed lemma arctan_0_1_bounds: assumes "0 \ real x" "real x \ 1" - shows "arctan (real x) \ {real (x * lb_arctan_horner prec (get_even n) 1 (x * x)) .. real (x * ub_arctan_horner prec (get_odd n) 1 (x * x))}" + shows "arctan x \ {(x * lb_arctan_horner prec (get_even n) 1 (x * x)) .. (x * ub_arctan_horner prec (get_odd n) 1 (x * x))}" proof (cases "even n") case True obtain n' where "Suc n' = get_odd n" and "odd (Suc n')" using get_odd_ex by auto hence "even n'" unfolding even_Suc by auto - have "arctan (real x) \ real (x * ub_arctan_horner prec (get_odd n) 1 (x * x))" + have "arctan x \ x * ub_arctan_horner prec (get_odd n) 1 (x * x)" unfolding `Suc n' = get_odd n`[symmetric] using arctan_0_1_bounds'[OF `0 \ real x` `real x \ 1` `even n'`] by auto moreover - have "real (x * lb_arctan_horner prec (get_even n) 1 (x * x)) \ arctan (real x)" + have "x * lb_arctan_horner prec (get_even n) 1 (x * x) \ arctan x" unfolding get_even_def if_P[OF True] using arctan_0_1_bounds'[OF `0 \ real x` `real x \ 1` `even n`] by auto ultimately show ?thesis by auto next @@ -470,10 +481,10 @@ have "even n'" and "even (Suc (Suc n'))" by auto have "get_odd n = Suc n'" unfolding get_odd_def if_P[OF False] using `n = Suc n'` . - have "arctan (real x) \ real (x * ub_arctan_horner prec (get_odd n) 1 (x * x))" + have "arctan x \ x * ub_arctan_horner prec (get_odd n) 1 (x * x)" unfolding `get_odd n = Suc n'` using arctan_0_1_bounds'[OF `0 \ real x` `real x \ 1` `even n'`] by auto moreover - have "real (x * lb_arctan_horner prec (get_even n) 1 (x * x)) \ arctan (real x)" + have "(x * lb_arctan_horner prec (get_even n) 1 (x * x)) \ arctan x" unfolding get_even_def if_not_P[OF False] unfolding `n = Suc n'` using arctan_0_1_bounds'[OF `0 \ real x` `real x \ 1` `even (Suc (Suc n'))`] by auto ultimately show ?thesis by auto qed @@ -492,7 +503,7 @@ in ((Float 1 2) * ((Float 1 2) * A * (lb_arctan_horner prec (get_even (prec div 4 + 1)) 1 (A * A)) - B * (ub_arctan_horner prec (get_odd (prec div 14 + 1)) 1 (B * B)))))" -lemma pi_boundaries: "pi \ {real (lb_pi n) .. real (ub_pi n)}" +lemma pi_boundaries: "pi \ {(lb_pi n) .. (ub_pi n)}" proof - have machin_pi: "pi = 4 * (4 * arctan (1 / 5) - arctan (1 / 239))" unfolding machin[symmetric] by auto @@ -504,35 +515,35 @@ have "real ?k \ 1" unfolding rapprox_rat.simps(2)[OF zero_le_one `0 < k`] by (rule rapprox_posrat_le1, auto simp add: `0 < k` `1 \ k`) - have "1 / real k \ real ?k" using rapprox_rat[where x=1 and y=k] by auto - hence "arctan (1 / real k) \ arctan (real ?k)" by (rule arctan_monotone') - also have "\ \ real (?k * ub_arctan_horner prec (get_odd n) 1 (?k * ?k))" + have "1 / k \ ?k" using rapprox_rat[where x=1 and y=k] by auto + hence "arctan (1 / k) \ arctan ?k" by (rule arctan_monotone') + also have "\ \ (?k * ub_arctan_horner prec (get_odd n) 1 (?k * ?k))" using arctan_0_1_bounds[OF `0 \ real ?k` `real ?k \ 1`] by auto - finally have "arctan (1 / (real k)) \ real (?k * ub_arctan_horner prec (get_odd n) 1 (?k * ?k))" . + finally have "arctan (1 / k) \ ?k * ub_arctan_horner prec (get_odd n) 1 (?k * ?k)" . } note ub_arctan = this { fix prec n :: nat fix k :: int assume "1 < k" hence "0 \ k" and "0 < k" by auto let ?k = "lapprox_rat prec 1 k" have "1 div k = 0" using div_pos_pos_trivial[OF _ `1 < k`] by auto - have "1 / real k \ 1" using `1 < k` by auto + have "1 / k \ 1" using `1 < k` by auto have "\n. 0 \ real ?k" using lapprox_rat_bottom[where x=1 and y=k, OF zero_le_one `0 < k`] by (auto simp add: `1 div k = 0`) - have "\n. real ?k \ 1" using lapprox_rat by (rule order_trans, auto simp add: `1 / real k \ 1`) - - have "real ?k \ 1 / real k" using lapprox_rat[where x=1 and y=k] by auto - - have "real (?k * lb_arctan_horner prec (get_even n) 1 (?k * ?k)) \ arctan (real ?k)" + have "\n. real ?k \ 1" using lapprox_rat by (rule order_trans, auto simp add: `1 / k \ 1`) + + have "?k \ 1 / k" using lapprox_rat[where x=1 and y=k] by auto + + have "?k * lb_arctan_horner prec (get_even n) 1 (?k * ?k) \ arctan ?k" using arctan_0_1_bounds[OF `0 \ real ?k` `real ?k \ 1`] by auto - also have "\ \ arctan (1 / real k)" using `real ?k \ 1 / real k` by (rule arctan_monotone') - finally have "real (?k * lb_arctan_horner prec (get_even n) 1 (?k * ?k)) \ arctan (1 / (real k))" . + also have "\ \ arctan (1 / k)" using `?k \ 1 / k` by (rule arctan_monotone') + finally have "?k * lb_arctan_horner prec (get_even n) 1 (?k * ?k) \ arctan (1 / k)" . } note lb_arctan = this - have "pi \ real (ub_pi n)" + have "pi \ ub_pi n" unfolding ub_pi_def machin_pi Let_def real_of_float_mult real_of_float_sub unfolding Float_num using lb_arctan[of 239] ub_arctan[of 5] by (auto intro!: mult_left_mono add_mono simp add: diff_minus simp del: lapprox_rat.simps rapprox_rat.simps) moreover - have "real (lb_pi n) \ pi" + have "lb_pi n \ pi" unfolding lb_pi_def machin_pi Let_def real_of_float_mult real_of_float_sub Float_num using lb_arctan[of 5] ub_arctan[of 239] by (auto intro!: mult_left_mono add_mono simp add: diff_minus simp del: lapprox_rat.simps rapprox_rat.simps) @@ -566,7 +577,7 @@ declare lb_arctan_horner.simps[simp del] lemma lb_arctan_bound': assumes "0 \ real x" - shows "real (lb_arctan prec x) \ arctan (real x)" + shows "lb_arctan prec x \ arctan x" proof - have "\ x < 0" and "0 \ x" unfolding less_float_def le_float_def using `0 \ real x` by auto let "?ub_horner x" = "x * ub_arctan_horner prec (get_odd (prec div 4 + 1)) 1 (x * x)" @@ -586,16 +597,16 @@ have sqr_ge0: "0 \ 1 + real x * real x" using sum_power2_ge_zero[of 1 "real x", unfolded numeral_2_eq_2] by auto hence divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg) - have "sqrt (real (1 + x * x)) \ real (ub_sqrt prec (1 + x * x))" + have "sqrt (1 + x * x) \ ub_sqrt prec (1 + x * x)" using bnds_sqrt'[of "1 + x * x"] by auto - hence "?R \ real ?fR" by auto + hence "?R \ ?fR" by auto hence "0 < ?fR" and "0 < real ?fR" unfolding less_float_def using `0 < ?R` by auto - have monotone: "real (float_divl prec x ?fR) \ real x / ?R" + have monotone: "(float_divl prec x ?fR) \ x / ?R" proof - - have "real ?DIV \ real x / real ?fR" by (rule float_divl) - also have "\ \ real x / ?R" by (rule divide_left_mono[OF `?R \ real ?fR` `0 \ real x` mult_pos_pos[OF order_less_le_trans[OF divisor_gt0 `?R \ real ?fR`] divisor_gt0]]) + have "?DIV \ real x / ?fR" by (rule float_divl) + also have "\ \ x / ?R" by (rule divide_left_mono[OF `?R \ ?fR` `0 \ real x` mult_pos_pos[OF order_less_le_trans[OF divisor_gt0 `?R \ real ?fR`] divisor_gt0]]) finally show ?thesis . qed @@ -603,20 +614,20 @@ proof (cases "x \ Float 1 1") case True - have "real x \ sqrt (real (1 + x * x))" using real_sqrt_sum_squares_ge2[where x=1, unfolded numeral_2_eq_2] by auto - also have "\ \ real (ub_sqrt prec (1 + x * x))" + have "x \ sqrt (1 + x * x)" using real_sqrt_sum_squares_ge2[where x=1, unfolded numeral_2_eq_2] by auto + also have "\ \ (ub_sqrt prec (1 + x * x))" using bnds_sqrt'[of "1 + x * x"] by auto - finally have "real x \ real ?fR" by auto - moreover have "real ?DIV \ real x / real ?fR" by (rule float_divl) + finally have "real x \ ?fR" by auto + moreover have "?DIV \ real x / ?fR" by (rule float_divl) ultimately have "real ?DIV \ 1" unfolding divide_le_eq_1_pos[OF `0 < real ?fR`, symmetric] by auto have "0 \ real ?DIV" using float_divl_lower_bound[OF `0 \ x` `0 < ?fR`] unfolding le_float_def by auto - have "real (Float 1 1 * ?lb_horner ?DIV) \ 2 * arctan (real (float_divl prec x ?fR))" unfolding real_of_float_mult[of "Float 1 1"] Float_num + have "(Float 1 1 * ?lb_horner ?DIV) \ 2 * arctan (float_divl prec x ?fR)" unfolding real_of_float_mult[of "Float 1 1"] Float_num using arctan_0_1_bounds[OF `0 \ real ?DIV` `real ?DIV \ 1`] by auto - also have "\ \ 2 * arctan (real x / ?R)" + also have "\ \ 2 * arctan (x / ?R)" using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono) - also have "2 * arctan (real x / ?R) = arctan (real x)" using arctan_half[symmetric] unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . + also have "2 * arctan (x / ?R) = arctan x" using arctan_half[symmetric] unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . finally show ?thesis unfolding lb_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_P[OF True] . next case False @@ -624,27 +635,27 @@ hence "1 \ real x" by auto let "?invx" = "float_divr prec 1 x" - have "0 \ arctan (real x)" using arctan_monotone'[OF `0 \ real x`] using arctan_tan[of 0, unfolded tan_zero] by auto + have "0 \ arctan x" using arctan_monotone'[OF `0 \ real x`] using arctan_tan[of 0, unfolded tan_zero] by auto show ?thesis proof (cases "1 < ?invx") case True show ?thesis unfolding lb_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_not_P[OF False] if_P[OF True] - using `0 \ arctan (real x)` by auto + using `0 \ arctan x` by auto next case False hence "real ?invx \ 1" unfolding less_float_def by auto have "0 \ real ?invx" by (rule order_trans[OF _ float_divr], auto simp add: `0 \ real x`) - have "1 / real x \ 0" and "0 < 1 / real x" using `0 < real x` by auto - - have "arctan (1 / real x) \ arctan (real ?invx)" unfolding real_of_float_1[symmetric] by (rule arctan_monotone', rule float_divr) - also have "\ \ real (?ub_horner ?invx)" using arctan_0_1_bounds[OF `0 \ real ?invx` `real ?invx \ 1`] by auto - finally have "pi / 2 - real (?ub_horner ?invx) \ arctan (real x)" - using `0 \ arctan (real x)` arctan_inverse[OF `1 / real x \ 0`] + have "1 / x \ 0" and "0 < 1 / x" using `0 < real x` by auto + + have "arctan (1 / x) \ arctan ?invx" unfolding real_of_float_1[symmetric] by (rule arctan_monotone', rule float_divr) + also have "\ \ (?ub_horner ?invx)" using arctan_0_1_bounds[OF `0 \ real ?invx` `real ?invx \ 1`] by auto + finally have "pi / 2 - (?ub_horner ?invx) \ arctan x" + using `0 \ arctan x` arctan_inverse[OF `1 / x \ 0`] unfolding real_sgn_pos[OF `0 < 1 / real x`] le_diff_eq by auto moreover - have "real (lb_pi prec * Float 1 -1) \ pi / 2" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto + have "lb_pi prec * Float 1 -1 \ pi / 2" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto ultimately show ?thesis unfolding lb_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_not_P[OF `\ x \ Float 1 1`] if_not_P[OF False] by auto @@ -654,7 +665,7 @@ qed lemma ub_arctan_bound': assumes "0 \ real x" - shows "arctan (real x) \ real (ub_arctan prec x)" + shows "arctan x \ ub_arctan prec x" proof - have "\ x < 0" and "0 \ x" unfolding less_float_def le_float_def using `0 \ real x` by auto @@ -677,16 +688,16 @@ hence divisor_gt0: "0 < ?R" by (auto intro: add_pos_nonneg) - have "real (lb_sqrt prec (1 + x * x)) \ sqrt (real (1 + x * x))" + have "lb_sqrt prec (1 + x * x) \ sqrt (1 + x * x)" using bnds_sqrt'[of "1 + x * x"] by auto - hence "real ?fR \ ?R" by auto + hence "?fR \ ?R" by auto have "0 < real ?fR" unfolding real_of_float_add real_of_float_1 by (rule order_less_le_trans[OF zero_less_one], auto simp add: lb_sqrt_lower_bound[OF `0 \ real (1 + x*x)`]) - have monotone: "real x / ?R \ real (float_divr prec x ?fR)" + have monotone: "x / ?R \ (float_divr prec x ?fR)" proof - - from divide_left_mono[OF `real ?fR \ ?R` `0 \ real x` mult_pos_pos[OF divisor_gt0 `0 < real ?fR`]] - have "real x / ?R \ real x / real ?fR" . - also have "\ \ real ?DIV" by (rule float_divr) + from divide_left_mono[OF `?fR \ ?R` `0 \ real x` mult_pos_pos[OF divisor_gt0 `0 < real ?fR`]] + have "x / ?R \ x / ?fR" . + also have "\ \ ?DIV" by (rule float_divr) finally show ?thesis . qed @@ -696,20 +707,20 @@ show ?thesis proof (cases "?DIV > 1") case True - have "pi / 2 \ real (ub_pi prec * Float 1 -1)" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto + have "pi / 2 \ ub_pi prec * Float 1 -1" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_left using pi_boundaries by auto from order_less_le_trans[OF arctan_ubound this, THEN less_imp_le] show ?thesis unfolding ub_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_P[OF `x \ Float 1 1`] if_P[OF True] . next case False hence "real ?DIV \ 1" unfolding less_float_def by auto - have "0 \ real x / ?R" using `0 \ real x` `0 < ?R` unfolding real_0_le_divide_iff by auto + have "0 \ x / ?R" using `0 \ real x` `0 < ?R` unfolding real_0_le_divide_iff by auto hence "0 \ real ?DIV" using monotone by (rule order_trans) - have "arctan (real x) = 2 * arctan (real x / ?R)" using arctan_half unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . - also have "\ \ 2 * arctan (real ?DIV)" + have "arctan x = 2 * arctan (x / ?R)" using arctan_half unfolding numeral_2_eq_2 power_Suc2 power_0 mult_1_left . + also have "\ \ 2 * arctan (?DIV)" using arctan_monotone'[OF monotone] by (auto intro!: mult_left_mono) - also have "\ \ real (Float 1 1 * ?ub_horner ?DIV)" unfolding real_of_float_mult[of "Float 1 1"] Float_num + also have "\ \ (Float 1 1 * ?ub_horner ?DIV)" unfolding real_of_float_mult[of "Float 1 1"] Float_num using arctan_0_1_bounds[OF `0 \ real ?DIV` `real ?DIV \ 1`] by auto finally show ?thesis unfolding ub_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_P[OF `x \ Float 1 1`] if_not_P[OF False] . qed @@ -721,20 +732,20 @@ hence "0 < x" unfolding less_float_def by auto let "?invx" = "float_divl prec 1 x" - have "0 \ arctan (real x)" using arctan_monotone'[OF `0 \ real x`] using arctan_tan[of 0, unfolded tan_zero] by auto + have "0 \ arctan x" using arctan_monotone'[OF `0 \ real x`] using arctan_tan[of 0, unfolded tan_zero] by auto have "real ?invx \ 1" unfolding less_float_def by (rule order_trans[OF float_divl], auto simp add: `1 \ real x` divide_le_eq_1_pos[OF `0 < real x`]) have "0 \ real ?invx" unfolding real_of_float_0[symmetric] by (rule float_divl_lower_bound[unfolded le_float_def], auto simp add: `0 < x`) - have "1 / real x \ 0" and "0 < 1 / real x" using `0 < real x` by auto - - have "real (?lb_horner ?invx) \ arctan (real ?invx)" using arctan_0_1_bounds[OF `0 \ real ?invx` `real ?invx \ 1`] by auto - also have "\ \ arctan (1 / real x)" unfolding real_of_float_1[symmetric] by (rule arctan_monotone', rule float_divl) - finally have "arctan (real x) \ pi / 2 - real (?lb_horner ?invx)" - using `0 \ arctan (real x)` arctan_inverse[OF `1 / real x \ 0`] - unfolding real_sgn_pos[OF `0 < 1 / real x`] le_diff_eq by auto + have "1 / x \ 0" and "0 < 1 / x" using `0 < real x` by auto + + have "(?lb_horner ?invx) \ arctan (?invx)" using arctan_0_1_bounds[OF `0 \ real ?invx` `real ?invx \ 1`] by auto + also have "\ \ arctan (1 / x)" unfolding real_of_float_1[symmetric] by (rule arctan_monotone', rule float_divl) + finally have "arctan x \ pi / 2 - (?lb_horner ?invx)" + using `0 \ arctan x` arctan_inverse[OF `1 / x \ 0`] + unfolding real_sgn_pos[OF `0 < 1 / x`] le_diff_eq by auto moreover - have "pi / 2 \ real (ub_pi prec * Float 1 -1)" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_right using pi_boundaries by auto + have "pi / 2 \ ub_pi prec * Float 1 -1" unfolding real_of_float_mult Float_num times_divide_eq_right mult_1_right using pi_boundaries by auto ultimately show ?thesis unfolding ub_arctan.simps Let_def if_not_P[OF `\ x < 0`] if_not_P[OF `\ x \ Float 1 -1`] if_not_P[OF `\ x \ Float 1 1`] if_not_P[OF False] by auto @@ -743,34 +754,34 @@ qed lemma arctan_boundaries: - "arctan (real x) \ {real (lb_arctan prec x) .. real (ub_arctan prec x)}" + "arctan x \ {(lb_arctan prec x) .. (ub_arctan prec x)}" proof (cases "0 \ x") case True hence "0 \ real x" unfolding le_float_def by auto show ?thesis using ub_arctan_bound'[OF `0 \ real x`] lb_arctan_bound'[OF `0 \ real x`] unfolding atLeastAtMost_iff by auto next let ?mx = "-x" case False hence "x < 0" and "0 \ real ?mx" unfolding le_float_def less_float_def by auto - hence bounds: "real (lb_arctan prec ?mx) \ arctan (real ?mx) \ arctan (real ?mx) \ real (ub_arctan prec ?mx)" + hence bounds: "lb_arctan prec ?mx \ arctan ?mx \ arctan ?mx \ ub_arctan prec ?mx" using ub_arctan_bound'[OF `0 \ real ?mx`] lb_arctan_bound'[OF `0 \ real ?mx`] by auto show ?thesis unfolding real_of_float_minus arctan_minus lb_arctan.simps[where x=x] ub_arctan.simps[where x=x] Let_def if_P[OF `x < 0`] unfolding atLeastAtMost_iff using bounds[unfolded real_of_float_minus arctan_minus] by auto qed -lemma bnds_arctan: "\ x lx ux. (l, u) = (lb_arctan prec lx, ub_arctan prec ux) \ x \ {real lx .. real ux} \ real l \ arctan x \ arctan x \ real u" +lemma bnds_arctan: "\ (x::real) lx ux. (l, u) = (lb_arctan prec lx, ub_arctan prec ux) \ x \ {lx .. ux} \ l \ arctan x \ arctan x \ u" proof (rule allI, rule allI, rule allI, rule impI) - fix x lx ux - assume "(l, u) = (lb_arctan prec lx, ub_arctan prec ux) \ x \ {real lx .. real ux}" - hence l: "lb_arctan prec lx = l " and u: "ub_arctan prec ux = u" and x: "x \ {real lx .. real ux}" by auto + fix x :: real fix lx ux + assume "(l, u) = (lb_arctan prec lx, ub_arctan prec ux) \ x \ {lx .. ux}" + hence l: "lb_arctan prec lx = l " and u: "ub_arctan prec ux = u" and x: "x \ {lx .. ux}" by auto { from arctan_boundaries[of lx prec, unfolded l] - have "real l \ arctan (real lx)" by (auto simp del: lb_arctan.simps) + have "l \ arctan lx" by (auto simp del: lb_arctan.simps) also have "\ \ arctan x" using x by (auto intro: arctan_monotone') - finally have "real l \ arctan x" . + finally have "l \ arctan x" . } moreover - { have "arctan x \ arctan (real ux)" using x by (auto intro: arctan_monotone') - also have "\ \ real u" using arctan_boundaries[of ux prec, unfolded u] by (auto simp del: ub_arctan.simps) - finally have "arctan x \ real u" . - } ultimately show "real l \ arctan x \ arctan x \ real u" .. + { have "arctan x \ arctan ux" using x by (auto intro: arctan_monotone') + also have "\ \ u" using arctan_boundaries[of ux prec, unfolded u] by (auto simp del: ub_arctan.simps) + finally have "arctan x \ u" . + } ultimately show "l \ arctan x \ arctan x \ u" .. qed section "Sinus and Cosinus" @@ -781,14 +792,13 @@ and lb_sin_cos_aux :: "nat \ nat \ nat \ nat \ float \ float" where "ub_sin_cos_aux prec 0 i k x = 0" | "ub_sin_cos_aux prec (Suc n) i k x = - (rapprox_rat prec 1 (int k)) - x * (lb_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)" + (rapprox_rat prec 1 k) - x * (lb_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)" | "lb_sin_cos_aux prec 0 i k x = 0" | "lb_sin_cos_aux prec (Suc n) i k x = - (lapprox_rat prec 1 (int k)) - x * (ub_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)" - + (lapprox_rat prec 1 k) - x * (ub_sin_cos_aux prec n (i + 2) (k * i * (i + 1)) x)" lemma cos_aux: - shows "real (lb_sin_cos_aux prec n 1 1 (x * x)) \ (\ i=0.. i=0.. real (ub_sin_cos_aux prec n 1 1 (x * x))" (is "?ub") + shows "(lb_sin_cos_aux prec n 1 1 (x * x)) \ (\ i=0.. i=0.. (ub_sin_cos_aux prec n 1 1 (x * x))" (is "?ub") proof - have "0 \ real (x * x)" unfolding real_of_float_mult by auto let "?f n" = "fact (2 * n)" @@ -803,8 +813,8 @@ show "?lb" and "?ub" by (auto simp add: power_mult power2_eq_square[of "real x"]) qed -lemma cos_boundaries: assumes "0 \ real x" and "real x \ pi / 2" - shows "cos (real x) \ {real (lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) .. real (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))}" +lemma cos_boundaries: assumes "0 \ real x" and "x \ pi / 2" + shows "cos x \ {(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) .. (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))}" proof (cases "real x = 0") case False hence "real x \ 0" by auto hence "0 < x" and "0 < real x" using `0 \ real x` unfolding less_float_def by auto @@ -828,17 +838,17 @@ { fix n :: nat assume "0 < n" hence "0 < 2 * n" by auto obtain t where "0 < t" and "t < real x" and - cos_eq: "cos (real x) = (\ i = 0 ..< 2 * n. (if even(i) then (-1 ^ (i div 2))/(real (fact i)) else 0) * (real x) ^ i) - + (cos (t + 1/2 * real (2 * n) * pi) / real (fact (2*n))) * (real x)^(2*n)" + cos_eq: "cos x = (\ i = 0 ..< 2 * n. (if even(i) then (-1 ^ (i div 2))/(real (fact i)) else 0) * (real x) ^ i) + + (cos (t + 1/2 * (2 * n) * pi) / real (fact (2*n))) * (real x)^(2*n)" (is "_ = ?SUM + ?rest / ?fact * ?pow") using Maclaurin_cos_expansion2[OF `0 < real x` `0 < 2 * n`] by auto - have "cos t * -1^n = cos t * cos (real n * pi) + sin t * sin (real n * pi)" by auto - also have "\ = cos (t + real n * pi)" using cos_add by auto + have "cos t * -1^n = cos t * cos (n * pi) + sin t * sin (n * pi)" by auto + also have "\ = cos (t + n * pi)" using cos_add by auto also have "\ = ?rest" by auto finally have "cos t * -1^n = ?rest" . moreover - have "t \ pi / 2" using `t < real x` and `real x \ pi / 2` by auto + have "t \ pi / 2" using `t < real x` and `x \ pi / 2` by auto hence "0 \ cos t" using `0 < t` and cos_ge_zero by auto ultimately have even: "even n \ 0 \ ?rest" and odd: "odd n \ 0 \ - ?rest " by auto @@ -847,41 +857,41 @@ { assume "even n" - have "real (lb_sin_cos_aux prec n 1 1 (x * x)) \ ?SUM" + have "(lb_sin_cos_aux prec n 1 1 (x * x)) \ ?SUM" unfolding morph_to_if_power[symmetric] using cos_aux by auto - also have "\ \ cos (real x)" + also have "\ \ cos x" proof - from even[OF `even n`] `0 < ?fact` `0 < ?pow` have "0 \ (?rest / ?fact) * ?pow" by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le) thus ?thesis unfolding cos_eq by auto qed - finally have "real (lb_sin_cos_aux prec n 1 1 (x * x)) \ cos (real x)" . + finally have "(lb_sin_cos_aux prec n 1 1 (x * x)) \ cos x" . } note lb = this { assume "odd n" - have "cos (real x) \ ?SUM" + have "cos x \ ?SUM" proof - from `0 < ?fact` and `0 < ?pow` and odd[OF `odd n`] have "0 \ (- ?rest) / ?fact * ?pow" by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le) thus ?thesis unfolding cos_eq by auto qed - also have "\ \ real (ub_sin_cos_aux prec n 1 1 (x * x))" + also have "\ \ (ub_sin_cos_aux prec n 1 1 (x * x))" unfolding morph_to_if_power[symmetric] using cos_aux by auto - finally have "cos (real x) \ real (ub_sin_cos_aux prec n 1 1 (x * x))" . + finally have "cos x \ (ub_sin_cos_aux prec n 1 1 (x * x))" . } note ub = this and lb } note ub = this(1) and lb = this(2) - have "cos (real x) \ real (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))" using ub[OF odd_pos[OF get_odd] get_odd] . - moreover have "real (lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) \ cos (real x)" + have "cos x \ (ub_sin_cos_aux prec (get_odd n) 1 1 (x * x))" using ub[OF odd_pos[OF get_odd] get_odd] . + moreover have "(lb_sin_cos_aux prec (get_even n) 1 1 (x * x)) \ cos x" proof (cases "0 < get_even n") case True show ?thesis using lb[OF True get_even] . next case False hence "get_even n = 0" by auto - have "- (pi / 2) \ real x" by (rule order_trans[OF _ `0 < real x`[THEN less_imp_le]], auto) - with `real x \ pi / 2` + have "- (pi / 2) \ x" by (rule order_trans[OF _ `0 < real x`[THEN less_imp_le]], auto) + with `x \ pi / 2` show ?thesis unfolding `get_even n = 0` lb_sin_cos_aux.simps real_of_float_minus real_of_float_0 using cos_ge_zero by auto qed ultimately show ?thesis by auto @@ -898,8 +908,8 @@ qed lemma sin_aux: assumes "0 \ real x" - shows "real (x * lb_sin_cos_aux prec n 2 1 (x * x)) \ (\ i=0.. i=0.. real (x * ub_sin_cos_aux prec n 2 1 (x * x))" (is "?ub") + shows "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \ (\ i=0.. i=0.. (x * ub_sin_cos_aux prec n 2 1 (x * x))" (is "?ub") proof - have "0 \ real (x * x)" unfolding real_of_float_mult by auto let "?f n" = "fact (2 * n + 1)" @@ -917,8 +927,8 @@ by (auto intro!: mult_left_mono simp add: power_mult power2_eq_square[of "real x"]) qed -lemma sin_boundaries: assumes "0 \ real x" and "real x \ pi / 2" - shows "sin (real x) \ {real (x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) .. real (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))}" +lemma sin_boundaries: assumes "0 \ real x" and "x \ pi / 2" + shows "sin x \ {(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) .. (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))}" proof (cases "real x = 0") case False hence "real x \ 0" by auto hence "0 < x" and "0 < real x" using `0 \ real x` unfolding less_float_def by auto @@ -940,14 +950,14 @@ { fix n :: nat assume "0 < n" hence "0 < 2 * n + 1" by auto obtain t where "0 < t" and "t < real x" and - sin_eq: "sin (real x) = (\ i = 0 ..< 2 * n + 1. (if even(i) then 0 else (-1 ^ ((i - Suc 0) div 2))/(real (fact i))) * (real x) ^ i) - + (sin (t + 1/2 * real (2 * n + 1) * pi) / real (fact (2*n + 1))) * (real x)^(2*n + 1)" + sin_eq: "sin x = (\ i = 0 ..< 2 * n + 1. (if even(i) then 0 else (-1 ^ ((i - Suc 0) div 2))/(real (fact i))) * (real x) ^ i) + + (sin (t + 1/2 * (2 * n + 1) * pi) / real (fact (2*n + 1))) * (real x)^(2*n + 1)" (is "_ = ?SUM + ?rest / ?fact * ?pow") using Maclaurin_sin_expansion3[OF `0 < 2 * n + 1` `0 < real x`] by auto have "?rest = cos t * -1^n" unfolding sin_add cos_add real_of_nat_add left_distrib right_distrib by auto moreover - have "t \ pi / 2" using `t < real x` and `real x \ pi / 2` by auto + have "t \ pi / 2" using `t < real x` and `x \ pi / 2` by auto hence "0 \ cos t" using `0 < t` and cos_ge_zero by auto ultimately have even: "even n \ 0 \ ?rest" and odd: "odd n \ 0 \ - ?rest " by auto @@ -956,22 +966,22 @@ { assume "even n" - have "real (x * lb_sin_cos_aux prec n 2 1 (x * x)) \ + have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \ (\ i = 0 ..< 2 * n. (if even(i) then 0 else (-1 ^ ((i - Suc 0) div 2))/(real (fact i))) * (real x) ^ i)" using sin_aux[OF `0 \ real x`] unfolding setsum_morph[symmetric] by auto also have "\ \ ?SUM" by auto - also have "\ \ sin (real x)" + also have "\ \ sin x" proof - from even[OF `even n`] `0 < ?fact` `0 < ?pow` have "0 \ (?rest / ?fact) * ?pow" by (metis mult_nonneg_nonneg divide_nonneg_pos less_imp_le) thus ?thesis unfolding sin_eq by auto qed - finally have "real (x * lb_sin_cos_aux prec n 2 1 (x * x)) \ sin (real x)" . + finally have "(x * lb_sin_cos_aux prec n 2 1 (x * x)) \ sin x" . } note lb = this { assume "odd n" - have "sin (real x) \ ?SUM" + have "sin x \ ?SUM" proof - from `0 < ?fact` and `0 < ?pow` and odd[OF `odd n`] have "0 \ (- ?rest) / ?fact * ?pow" @@ -980,20 +990,20 @@ qed also have "\ \ (\ i = 0 ..< 2 * n. (if even(i) then 0 else (-1 ^ ((i - Suc 0) div 2))/(real (fact i))) * (real x) ^ i)" by auto - also have "\ \ real (x * ub_sin_cos_aux prec n 2 1 (x * x))" + also have "\ \ (x * ub_sin_cos_aux prec n 2 1 (x * x))" using sin_aux[OF `0 \ real x`] unfolding setsum_morph[symmetric] by auto - finally have "sin (real x) \ real (x * ub_sin_cos_aux prec n 2 1 (x * x))" . + finally have "sin x \ (x * ub_sin_cos_aux prec n 2 1 (x * x))" . } note ub = this and lb } note ub = this(1) and lb = this(2) - have "sin (real x) \ real (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))" using ub[OF odd_pos[OF get_odd] get_odd] . - moreover have "real (x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) \ sin (real x)" + have "sin x \ (x * ub_sin_cos_aux prec (get_odd n) 2 1 (x * x))" using ub[OF odd_pos[OF get_odd] get_odd] . + moreover have "(x * lb_sin_cos_aux prec (get_even n) 2 1 (x * x)) \ sin x" proof (cases "0 < get_even n") case True show ?thesis using lb[OF True get_even] . next case False hence "get_even n = 0" by auto - with `real x \ pi / 2` `0 \ real x` + with `x \ pi / 2` `0 \ real x` show ?thesis unfolding `get_even n = 0` ub_sin_cos_aux.simps real_of_float_minus real_of_float_0 using sin_ge_zero by auto qed ultimately show ?thesis by auto @@ -1027,8 +1037,8 @@ else if x < 1 then half (horner (x * Float 1 -1)) else half (half (horner (x * Float 1 -2))))" -lemma lb_cos: assumes "0 \ real x" and "real x \ pi" - shows "cos (real x) \ {real (lb_cos prec x) .. real (ub_cos prec x)}" (is "?cos x \ { real (?lb x) .. real (?ub x) }") +lemma lb_cos: assumes "0 \ real x" and "x \ pi" + shows "cos x \ {(lb_cos prec x) .. (ub_cos prec x)}" (is "?cos x \ {(?lb x) .. (?ub x) }") proof - { fix x :: real have "cos x = cos (x / 2 + x / 2)" by auto @@ -1046,42 +1056,42 @@ show ?thesis proof (cases "x < Float 1 -1") - case True hence "real x \ pi / 2" unfolding less_float_def using pi_ge_two by auto + case True hence "x \ pi / 2" unfolding less_float_def using pi_ge_two by auto show ?thesis unfolding lb_cos_def[where x=x] ub_cos_def[where x=x] if_not_P[OF `\ x < 0`] if_P[OF `x < Float 1 -1`] Let_def - using cos_boundaries[OF `0 \ real x` `real x \ pi / 2`] . + using cos_boundaries[OF `0 \ real x` `x \ pi / 2`] . next case False - { fix y x :: float let ?x2 = "real (x * Float 1 -1)" - assume "real y \ cos ?x2" and "-pi \ real x" and "real x \ pi" + { fix y x :: float let ?x2 = "(x * Float 1 -1)" + assume "y \ cos ?x2" and "-pi \ x" and "x \ pi" hence "- (pi / 2) \ ?x2" and "?x2 \ pi / 2" using pi_ge_two unfolding real_of_float_mult Float_num by auto hence "0 \ cos ?x2" by (rule cos_ge_zero) - have "real (?lb_half y) \ cos (real x)" + have "(?lb_half y) \ cos x" proof (cases "y < 0") case True show ?thesis using cos_ge_minus_one unfolding if_P[OF True] by auto next case False hence "0 \ real y" unfolding less_float_def by auto - from mult_mono[OF `real y \ cos ?x2` `real y \ cos ?x2` `0 \ cos ?x2` this] + from mult_mono[OF `y \ cos ?x2` `y \ cos ?x2` `0 \ cos ?x2` this] have "real y * real y \ cos ?x2 * cos ?x2" . hence "2 * real y * real y \ 2 * cos ?x2 * cos ?x2" by auto - hence "2 * real y * real y - 1 \ 2 * cos (real x / 2) * cos (real x / 2) - 1" unfolding Float_num real_of_float_mult by auto + hence "2 * real y * real y - 1 \ 2 * cos (x / 2) * cos (x / 2) - 1" unfolding Float_num real_of_float_mult by auto thus ?thesis unfolding if_not_P[OF False] x_half Float_num real_of_float_mult real_of_float_sub by auto qed } note lb_half = this - { fix y x :: float let ?x2 = "real (x * Float 1 -1)" - assume ub: "cos ?x2 \ real y" and "- pi \ real x" and "real x \ pi" + { fix y x :: float let ?x2 = "(x * Float 1 -1)" + assume ub: "cos ?x2 \ y" and "- pi \ x" and "x \ pi" hence "- (pi / 2) \ ?x2" and "?x2 \ pi / 2" using pi_ge_two unfolding real_of_float_mult Float_num by auto hence "0 \ cos ?x2" by (rule cos_ge_zero) - have "cos (real x) \ real (?ub_half y)" + have "cos x \ (?ub_half y)" proof - have "0 \ real y" using `0 \ cos ?x2` ub by (rule order_trans) from mult_mono[OF ub ub this `0 \ cos ?x2`] have "cos ?x2 * cos ?x2 \ real y * real y" . hence "2 * cos ?x2 * cos ?x2 \ 2 * real y * real y" by auto - hence "2 * cos (real x / 2) * cos (real x / 2) - 1 \ 2 * real y * real y - 1" unfolding Float_num real_of_float_mult by auto + hence "2 * cos (x / 2) * cos (x / 2) - 1 \ 2 * real y * real y - 1" unfolding Float_num real_of_float_mult by auto thus ?thesis unfolding x_half real_of_float_mult Float_num real_of_float_sub by auto qed } note ub_half = this @@ -1089,44 +1099,44 @@ let ?x2 = "x * Float 1 -1" let ?x4 = "x * Float 1 -1 * Float 1 -1" - have "-pi \ real x" using pi_ge_zero[THEN le_imp_neg_le, unfolded minus_zero] `0 \ real x` by (rule order_trans) + have "-pi \ x" using pi_ge_zero[THEN le_imp_neg_le, unfolded minus_zero] `0 \ real x` by (rule order_trans) show ?thesis proof (cases "x < 1") case True hence "real x \ 1" unfolding less_float_def by auto - have "0 \ real ?x2" and "real ?x2 \ pi / 2" using pi_ge_two `0 \ real x` unfolding real_of_float_mult Float_num using assms by auto + have "0 \ real ?x2" and "?x2 \ pi / 2" using pi_ge_two `0 \ real x` unfolding real_of_float_mult Float_num using assms by auto from cos_boundaries[OF this] - have lb: "real (?lb_horner ?x2) \ ?cos ?x2" and ub: "?cos ?x2 \ real (?ub_horner ?x2)" by auto - - have "real (?lb x) \ ?cos x" + have lb: "(?lb_horner ?x2) \ ?cos ?x2" and ub: "?cos ?x2 \ (?ub_horner ?x2)" by auto + + have "(?lb x) \ ?cos x" proof - - from lb_half[OF lb `-pi \ real x` `real x \ pi`] + from lb_half[OF lb `-pi \ x` `x \ pi`] show ?thesis unfolding lb_cos_def[where x=x] Let_def using `\ x < 0` `\ x < Float 1 -1` `x < 1` by auto qed - moreover have "?cos x \ real (?ub x)" + moreover have "?cos x \ (?ub x)" proof - - from ub_half[OF ub `-pi \ real x` `real x \ pi`] + from ub_half[OF ub `-pi \ x` `x \ pi`] show ?thesis unfolding ub_cos_def[where x=x] Let_def using `\ x < 0` `\ x < Float 1 -1` `x < 1` by auto qed ultimately show ?thesis by auto next case False - have "0 \ real ?x4" and "real ?x4 \ pi / 2" using pi_ge_two `0 \ real x` `real x \ pi` unfolding real_of_float_mult Float_num by auto + have "0 \ real ?x4" and "?x4 \ pi / 2" using pi_ge_two `0 \ real x` `x \ pi` unfolding real_of_float_mult Float_num by auto from cos_boundaries[OF this] - have lb: "real (?lb_horner ?x4) \ ?cos ?x4" and ub: "?cos ?x4 \ real (?ub_horner ?x4)" by auto + have lb: "(?lb_horner ?x4) \ ?cos ?x4" and ub: "?cos ?x4 \ (?ub_horner ?x4)" by auto have eq_4: "?x2 * Float 1 -1 = x * Float 1 -2" by (cases x, auto simp add: times_float.simps) - have "real (?lb x) \ ?cos x" + have "(?lb x) \ ?cos x" proof - - have "-pi \ real ?x2" and "real ?x2 \ pi" unfolding real_of_float_mult Float_num using pi_ge_two `0 \ real x` `real x \ pi` by auto - from lb_half[OF lb_half[OF lb this] `-pi \ real x` `real x \ pi`, unfolded eq_4] + have "-pi \ ?x2" and "?x2 \ pi" unfolding real_of_float_mult Float_num using pi_ge_two `0 \ real x` `x \ pi` by auto + from lb_half[OF lb_half[OF lb this] `-pi \ x` `x \ pi`, unfolded eq_4] show ?thesis unfolding lb_cos_def[where x=x] if_not_P[OF `\ x < 0`] if_not_P[OF `\ x < Float 1 -1`] if_not_P[OF `\ x < 1`] Let_def . qed - moreover have "?cos x \ real (?ub x)" + moreover have "?cos x \ (?ub x)" proof - - have "-pi \ real ?x2" and "real ?x2 \ pi" unfolding real_of_float_mult Float_num using pi_ge_two `0 \ real x` `real x \ pi` by auto - from ub_half[OF ub_half[OF ub this] `-pi \ real x` `real x \ pi`, unfolded eq_4] + have "-pi \ ?x2" and "?x2 \ pi" unfolding real_of_float_mult Float_num using pi_ge_two `0 \ real x` ` x \ pi` by auto + from ub_half[OF ub_half[OF ub this] `-pi \ x` `x \ pi`, unfolded eq_4] show ?thesis unfolding ub_cos_def[where x=x] if_not_P[OF `\ x < 0`] if_not_P[OF `\ x < Float 1 -1`] if_not_P[OF `\ x < 1`] Let_def . qed ultimately show ?thesis by auto @@ -1134,10 +1144,10 @@ qed qed -lemma lb_cos_minus: assumes "-pi \ real x" and "real x \ 0" - shows "cos (real (-x)) \ {real (lb_cos prec (-x)) .. real (ub_cos prec (-x))}" +lemma lb_cos_minus: assumes "-pi \ x" and "real x \ 0" + shows "cos (real(-x)) \ {(lb_cos prec (-x)) .. (ub_cos prec (-x))}" proof - - have "0 \ real (-x)" and "real (-x) \ pi" using `-pi \ real x` `real x \ 0` by auto + have "0 \ real (-x)" and "(-x) \ pi" using `-pi \ x` `real x \ 0` by auto from lb_cos[OF this] show ?thesis . qed @@ -1156,49 +1166,49 @@ else (Float -1 0, Float 1 0))" lemma floor_int: - obtains k :: int where "real k = real (floor_fl f)" + obtains k :: int where "real k = (floor_fl f)" proof - - assume *: "\ k :: int. real k = real (floor_fl f) \ thesis" + assume *: "\ k :: int. real k = (floor_fl f) \ thesis" obtain m e where fl: "Float m e = floor_fl f" by (cases "floor_fl f", auto) from floor_pos_exp[OF this] - have "real (m* 2^(nat e)) = real (floor_fl f)" + have "real (m* 2^(nat e)) = (floor_fl f)" by (auto simp add: fl[symmetric] real_of_float_def pow2_def) from *[OF this] show thesis by blast qed -lemma float_remove_real_numeral[simp]: "real (number_of k :: float) = number_of k" +lemma float_remove_real_numeral[simp]: "(number_of k :: float) = (number_of k :: real)" proof - - have "real (number_of k :: float) = real k" + have "(number_of k :: float) = real k" unfolding number_of_float_def real_of_float_def pow2_def by auto - also have "\ = real (number_of k :: int)" + also have "\ = (number_of k :: int)" by (simp add: number_of_is_id) finally show ?thesis by auto qed -lemma cos_periodic_nat[simp]: fixes n :: nat shows "cos (x + real n * 2 * pi) = cos x" +lemma cos_periodic_nat[simp]: fixes n :: nat shows "cos (x + n * (2 * pi)) = cos x" proof (induct n arbitrary: x) case (Suc n) - have split_pi_off: "x + real (Suc n) * 2 * pi = (x + real n * 2 * pi) + 2 * pi" + have split_pi_off: "x + (Suc n) * (2 * pi) = (x + n * (2 * pi)) + 2 * pi" unfolding Suc_eq_plus1 real_of_nat_add real_of_one left_distrib by auto show ?case unfolding split_pi_off using Suc by auto qed auto -lemma cos_periodic_int[simp]: fixes i :: int shows "cos (x + real i * 2 * pi) = cos x" +lemma cos_periodic_int[simp]: fixes i :: int shows "cos (x + i * (2 * pi)) = cos x" proof (cases "0 \ i") - case True hence i_nat: "real i = real (nat i)" by auto + case True hence i_nat: "real i = nat i" by auto show ?thesis unfolding i_nat by auto next - case False hence i_nat: "real i = - real (nat (-i))" by auto - have "cos x = cos (x + real i * 2 * pi - real i * 2 * pi)" by auto - also have "\ = cos (x + real i * 2 * pi)" + case False hence i_nat: "i = - real (nat (-i))" by auto + have "cos x = cos (x + i * (2 * pi) - i * (2 * pi))" by auto + also have "\ = cos (x + i * (2 * pi))" unfolding i_nat mult_minus_left diff_minus_eq_add by (rule cos_periodic_nat) finally show ?thesis by auto qed -lemma bnds_cos: "\ x lx ux. (l, u) = bnds_cos prec lx ux \ x \ {real lx .. real ux} \ real l \ cos x \ cos x \ real u" +lemma bnds_cos: "\ (x::real) lx ux. (l, u) = bnds_cos prec lx ux \ x \ {lx .. ux} \ l \ cos x \ cos x \ u" proof ((rule allI | rule impI | erule conjE) +) - fix x lx ux - assume bnds: "(l, u) = bnds_cos prec lx ux" and x: "x \ {real lx .. real ux}" + fix x :: real fix lx ux + assume bnds: "(l, u) = bnds_cos prec lx ux" and x: "x \ {lx .. ux}" let ?lpi = "round_down prec (lb_pi prec)" let ?upi = "round_up prec (ub_pi prec)" @@ -1206,78 +1216,78 @@ let ?lx = "lx - ?k * 2 * (if ?k < 0 then ?lpi else ?upi)" let ?ux = "ux - ?k * 2 * (if ?k < 0 then ?upi else ?lpi)" - obtain k :: int where k: "real k = real ?k" using floor_int . - - have upi: "pi \ real ?upi" and lpi: "real ?lpi \ pi" + obtain k :: int where k: "k = real ?k" using floor_int . + + have upi: "pi \ ?upi" and lpi: "?lpi \ pi" using round_up[of "ub_pi prec" prec] pi_boundaries[of prec] round_down[of prec "lb_pi prec"] by auto - hence "real ?lx \ x - real k * 2 * pi \ x - real k * 2 * pi \ real ?ux" + hence "?lx \ x - k * (2 * pi) \ x - k * (2 * pi) \ ?ux" using x by (cases "k = 0") (auto intro!: add_mono simp add: diff_minus k[symmetric] less_float_def) note lx = this[THEN conjunct1] and ux = this[THEN conjunct2] - hence lx_less_ux: "real ?lx \ real ?ux" by (rule order_trans) - - { assume "- ?lpi \ ?lx" and x_le_0: "x - real k * 2 * pi \ 0" + hence lx_less_ux: "?lx \ real ?ux" by (rule order_trans) + + { assume "- ?lpi \ ?lx" and x_le_0: "x - k * (2 * pi) \ 0" with lpi[THEN le_imp_neg_le] lx - have pi_lx: "- pi \ real ?lx" and lx_0: "real ?lx \ 0" + have pi_lx: "- pi \ ?lx" and lx_0: "real ?lx \ 0" by (simp_all add: le_float_def) - have "real (lb_cos prec (- ?lx)) \ cos (real (- ?lx))" + have "(lb_cos prec (- ?lx)) \ cos (real (- ?lx))" using lb_cos_minus[OF pi_lx lx_0] by simp - also have "\ \ cos (x + real (-k) * 2 * pi)" + also have "\ \ cos (x + (-k) * (2 * pi))" using cos_monotone_minus_pi_0'[OF pi_lx lx x_le_0] by (simp only: real_of_float_minus real_of_int_minus cos_minus diff_minus mult_minus_left) - finally have "real (lb_cos prec (- ?lx)) \ cos x" + finally have "(lb_cos prec (- ?lx)) \ cos x" unfolding cos_periodic_int . } note negative_lx = this - { assume "0 \ ?lx" and pi_x: "x - real k * 2 * pi \ pi" + { assume "0 \ ?lx" and pi_x: "x - k * (2 * pi) \ pi" with lx - have pi_lx: "real ?lx \ pi" and lx_0: "0 \ real ?lx" + have pi_lx: "?lx \ pi" and lx_0: "0 \ real ?lx" by (auto simp add: le_float_def) - have "cos (x + real (-k) * 2 * pi) \ cos (real ?lx)" + have "cos (x + (-k) * (2 * pi)) \ cos ?lx" using cos_monotone_0_pi'[OF lx_0 lx pi_x] by (simp only: real_of_float_minus real_of_int_minus cos_minus diff_minus mult_minus_left) - also have "\ \ real (ub_cos prec ?lx)" + also have "\ \ (ub_cos prec ?lx)" using lb_cos[OF lx_0 pi_lx] by simp - finally have "cos x \ real (ub_cos prec ?lx)" + finally have "cos x \ (ub_cos prec ?lx)" unfolding cos_periodic_int . } note positive_lx = this - { assume pi_x: "- pi \ x - real k * 2 * pi" and "?ux \ 0" + { assume pi_x: "- pi \ x - k * (2 * pi)" and "?ux \ 0" with ux - have pi_ux: "- pi \ real ?ux" and ux_0: "real ?ux \ 0" + have pi_ux: "- pi \ ?ux" and ux_0: "real ?ux \ 0" by (simp_all add: le_float_def) - have "cos (x + real (-k) * 2 * pi) \ cos (real (- ?ux))" + have "cos (x + (-k) * (2 * pi)) \ cos (real (- ?ux))" using cos_monotone_minus_pi_0'[OF pi_x ux ux_0] by (simp only: real_of_float_minus real_of_int_minus cos_minus diff_minus mult_minus_left) - also have "\ \ real (ub_cos prec (- ?ux))" + also have "\ \ (ub_cos prec (- ?ux))" using lb_cos_minus[OF pi_ux ux_0, of prec] by simp - finally have "cos x \ real (ub_cos prec (- ?ux))" + finally have "cos x \ (ub_cos prec (- ?ux))" unfolding cos_periodic_int . } note negative_ux = this - { assume "?ux \ ?lpi" and x_ge_0: "0 \ x - real k * 2 * pi" + { assume "?ux \ ?lpi" and x_ge_0: "0 \ x - k * (2 * pi)" with lpi ux - have pi_ux: "real ?ux \ pi" and ux_0: "0 \ real ?ux" + have pi_ux: "?ux \ pi" and ux_0: "0 \ real ?ux" by (simp_all add: le_float_def) - have "real (lb_cos prec ?ux) \ cos (real ?ux)" + have "(lb_cos prec ?ux) \ cos ?ux" using lb_cos[OF ux_0 pi_ux] by simp - also have "\ \ cos (x + real (-k) * 2 * pi)" + also have "\ \ cos (x + (-k) * (2 * pi))" using cos_monotone_0_pi'[OF x_ge_0 ux pi_ux] by (simp only: real_of_float_minus real_of_int_minus cos_minus diff_minus mult_minus_left) - finally have "real (lb_cos prec ?ux) \ cos x" + finally have "(lb_cos prec ?ux) \ cos x" unfolding cos_periodic_int . } note positive_ux = this - show "real l \ cos x \ cos x \ real u" + show "l \ cos x \ cos x \ u" proof (cases "- ?lpi \ ?lx \ ?ux \ 0") case True with bnds have l: "l = lb_cos prec (-?lx)" @@ -1285,8 +1295,8 @@ by (auto simp add: bnds_cos_def Let_def) from True lpi[THEN le_imp_neg_le] lx ux - have "- pi \ x - real k * 2 * pi" - and "x - real k * 2 * pi \ 0" + have "- pi \ x - k * (2 * pi)" + and "x - k * (2 * pi) \ 0" by (auto simp add: le_float_def) with True negative_ux negative_lx show ?thesis unfolding l u by simp @@ -1298,8 +1308,8 @@ by (auto simp add: bnds_cos_def Let_def) from True lpi lx ux - have "0 \ x - real k * 2 * pi" - and "x - real k * 2 * pi \ pi" + have "0 \ x - k * (2 * pi)" + and "x - k * (2 * pi) \ pi" by (auto simp add: le_float_def) with True positive_ux positive_lx show ?thesis unfolding l u by simp @@ -1311,7 +1321,7 @@ by (auto simp add: bnds_cos_def Let_def) show ?thesis unfolding u l using negative_lx positive_ux Cond - by (cases "x - real k * 2 * pi < 0", simp_all add: real_of_float_min) + by (cases "x - k * (2 * pi) < 0", simp_all add: real_of_float_min) next case False note 3 = this show ?thesis proof (cases "0 \ ?lx \ ?ux \ 2 * ?lpi") case True note Cond = this with bnds 1 2 3 @@ -1320,37 +1330,37 @@ by (auto simp add: bnds_cos_def Let_def) have "cos x \ real u" - proof (cases "x - real k * 2 * pi < pi") - case True hence "x - real k * 2 * pi \ pi" by simp + proof (cases "x - k * (2 * pi) < pi") + case True hence "x - k * (2 * pi) \ pi" by simp from positive_lx[OF Cond[THEN conjunct1] this] show ?thesis unfolding u by (simp add: real_of_float_max) next - case False hence "pi \ x - real k * 2 * pi" by simp - hence pi_x: "- pi \ x - real k * 2 * pi - 2 * pi" by simp - - have "real ?ux \ 2 * pi" using Cond lpi by (auto simp add: le_float_def) - hence "x - real k * 2 * pi - 2 * pi \ 0" using ux by simp + case False hence "pi \ x - k * (2 * pi)" by simp + hence pi_x: "- pi \ x - k * (2 * pi) - 2 * pi" by simp + + have "?ux \ 2 * pi" using Cond lpi by (auto simp add: le_float_def) + hence "x - k * (2 * pi) - 2 * pi \ 0" using ux by simp have ux_0: "real (?ux - 2 * ?lpi) \ 0" using Cond by (auto simp add: le_float_def) from 2 and Cond have "\ ?ux \ ?lpi" by auto hence "- ?lpi \ ?ux - 2 * ?lpi" by (auto simp add: le_float_def) - hence pi_ux: "- pi \ real (?ux - 2 * ?lpi)" + hence pi_ux: "- pi \ (?ux - 2 * ?lpi)" using lpi[THEN le_imp_neg_le] by (auto simp add: le_float_def) - have x_le_ux: "x - real k * 2 * pi - 2 * pi \ real (?ux - 2 * ?lpi)" + have x_le_ux: "x - k * (2 * pi) - 2 * pi \ (?ux - 2 * ?lpi)" using ux lpi by auto - have "cos x = cos (x + real (-k) * 2 * pi + real (-1 :: int) * 2 * pi)" + have "cos x = cos (x + (-k) * (2 * pi) + (-1::int) * (2 * pi))" unfolding cos_periodic_int .. - also have "\ \ cos (real (?ux - 2 * ?lpi))" + also have "\ \ cos ((?ux - 2 * ?lpi))" using cos_monotone_minus_pi_0'[OF pi_x x_le_ux ux_0] by (simp only: real_of_float_minus real_of_int_minus real_of_one number_of_Min diff_minus mult_minus_left mult_1_left) - also have "\ = cos (real (- (?ux - 2 * ?lpi)))" + also have "\ = cos ((- (?ux - 2 * ?lpi)))" unfolding real_of_float_minus cos_minus .. - also have "\ \ real (ub_cos prec (- (?ux - 2 * ?lpi)))" + also have "\ \ (ub_cos prec (- (?ux - 2 * ?lpi)))" using lb_cos_minus[OF pi_ux ux_0] by simp finally show ?thesis unfolding u by (simp add: real_of_float_max) qed @@ -1362,37 +1372,37 @@ and u: "u = max (ub_cos prec (?lx + 2 * ?lpi)) (ub_cos prec (-?ux))" by (auto simp add: bnds_cos_def Let_def) - have "cos x \ real u" - proof (cases "-pi < x - real k * 2 * pi") - case True hence "-pi \ x - real k * 2 * pi" by simp + have "cos x \ u" + proof (cases "-pi < x - k * (2 * pi)") + case True hence "-pi \ x - k * (2 * pi)" by simp from negative_ux[OF this Cond[THEN conjunct2]] show ?thesis unfolding u by (simp add: real_of_float_max) next - case False hence "x - real k * 2 * pi \ -pi" by simp - hence pi_x: "x - real k * 2 * pi + 2 * pi \ pi" by simp - - have "-2 * pi \ real ?lx" using Cond lpi by (auto simp add: le_float_def) - - hence "0 \ x - real k * 2 * pi + 2 * pi" using lx by simp + case False hence "x - k * (2 * pi) \ -pi" by simp + hence pi_x: "x - k * (2 * pi) + 2 * pi \ pi" by simp + + have "-2 * pi \ ?lx" using Cond lpi by (auto simp add: le_float_def) + + hence "0 \ x - k * (2 * pi) + 2 * pi" using lx by simp have lx_0: "0 \ real (?lx + 2 * ?lpi)" using Cond lpi by (auto simp add: le_float_def) from 1 and Cond have "\ -?lpi \ ?lx" by auto hence "?lx + 2 * ?lpi \ ?lpi" by (auto simp add: le_float_def) - hence pi_lx: "real (?lx + 2 * ?lpi) \ pi" + hence pi_lx: "(?lx + 2 * ?lpi) \ pi" using lpi[THEN le_imp_neg_le] by (auto simp add: le_float_def) - have lx_le_x: "real (?lx + 2 * ?lpi) \ x - real k * 2 * pi + 2 * pi" + have lx_le_x: "(?lx + 2 * ?lpi) \ x - k * (2 * pi) + 2 * pi" using lx lpi by auto - have "cos x = cos (x + real (-k) * 2 * pi + real (1 :: int) * 2 * pi)" + have "cos x = cos (x + (-k) * (2 * pi) + (1 :: int) * (2 * pi))" unfolding cos_periodic_int .. - also have "\ \ cos (real (?lx + 2 * ?lpi))" + also have "\ \ cos ((?lx + 2 * ?lpi))" using cos_monotone_0_pi'[OF lx_0 lx_le_x pi_x] by (simp only: real_of_float_minus real_of_int_minus real_of_one number_of_Min diff_minus mult_minus_left mult_1_left) - also have "\ \ real (ub_cos prec (?lx + 2 * ?lpi))" + also have "\ \ (ub_cos prec (?lx + 2 * ?lpi))" using lb_cos[OF lx_0 pi_lx] by simp finally show ?thesis unfolding u by (simp add: real_of_float_max) qed @@ -1413,7 +1423,7 @@ "lb_exp_horner prec (Suc n) i k x = lapprox_rat prec 1 (int k) + x * ub_exp_horner prec n (i + 1) (k * i) x" lemma bnds_exp_horner: assumes "real x \ 0" - shows "exp (real x) \ { real (lb_exp_horner prec (get_even n) 1 1 x) .. real (ub_exp_horner prec (get_odd n) 1 1 x) }" + shows "exp x \ { lb_exp_horner prec (get_even n) 1 1 x .. ub_exp_horner prec (get_odd n) 1 1 x }" proof - { fix n have F: "\ m. ((\i. i + 1) ^^ n) m = n + m" by (induct n, auto) @@ -1422,18 +1432,18 @@ note bounds = horner_bounds_nonpos[where f="fact" and lb="lb_exp_horner prec" and ub="ub_exp_horner prec" and j'=0 and s=1, OF assms f_eq lb_exp_horner.simps ub_exp_horner.simps] - { have "real (lb_exp_horner prec (get_even n) 1 1 x) \ (\j = 0.. (\j = 0.. \ exp (real x)" + also have "\ \ exp x" proof - - obtain t where "\t\ \ \real x\" and "exp (real x) = (\m = 0..t\ \ \real x\" and "exp x = (\m = 0.. exp t / real (fact (get_even n)) * (real x) ^ (get_even n)" by (auto intro!: mult_nonneg_nonneg divide_nonneg_pos simp add: get_even zero_le_even_power exp_gt_zero) ultimately show ?thesis using get_odd exp_gt_zero by (auto intro!: mult_nonneg_nonneg) qed - finally have "real (lb_exp_horner prec (get_even n) 1 1 x) \ exp (real x)" . + finally have "lb_exp_horner prec (get_even n) 1 1 x \ exp x" . } moreover { have x_less_zero: "real x ^ get_odd n \ 0" @@ -1446,15 +1456,15 @@ show ?thesis by (rule less_imp_le, auto simp add: power_less_zero_eq get_odd `real x < 0`) qed - obtain t where "\t\ \ \real x\" and "exp (real x) = (\m = 0..t\ \ \real x\" and "exp x = (\m = 0.. 0" by (auto intro!: mult_nonneg_nonpos divide_nonpos_pos simp add: x_less_zero exp_gt_zero) - ultimately have "exp (real x) \ (\j = 0.. (\j = 0.. \ real (ub_exp_horner prec (get_odd n) 1 1 x)" + also have "\ \ ub_exp_horner prec (get_odd n) 1 1 x" using bounds(2) by auto - finally have "exp (real x) \ real (ub_exp_horner prec (get_odd n) 1 1 x)" . + finally have "exp x \ ub_exp_horner prec (get_odd n) 1 1 x" . } ultimately show ?thesis by auto qed @@ -1477,11 +1487,11 @@ proof - have eq4: "4 = Suc (Suc (Suc (Suc 0)))" by auto - have "1 / 4 = real (Float 1 -2)" unfolding Float_num by auto - also have "\ \ real (lb_exp_horner 1 (get_even 4) 1 1 (- 1))" + have "1 / 4 = (Float 1 -2)" unfolding Float_num by auto + also have "\ \ lb_exp_horner 1 (get_even 4) 1 1 (- 1)" unfolding get_even_def eq4 by (auto simp add: lapprox_posrat_def rapprox_posrat_def normfloat.simps) - also have "\ \ exp (real (- 1 :: float))" using bnds_exp_horner[where x="- 1"] by auto + also have "\ \ exp (- 1 :: float)" using bnds_exp_horner[where x="- 1"] by auto finally show ?thesis unfolding real_of_float_minus real_of_float_1 . qed @@ -1492,7 +1502,7 @@ have pos_horner: "\ x. 0 < ?horner x" unfolding Let_def by (cases "?lb_horner x \ 0", auto simp add: le_float_def less_float_def) moreover { fix x :: float fix num :: nat have "0 < real (?horner x) ^ num" using `0 < ?horner x`[unfolded less_float_def real_of_float_0] by (rule zero_less_power) - also have "\ = real ((?horner x) ^ num)" using float_power by auto + also have "\ = (?horner x) ^ num" using float_power by auto finally have "0 < real ((?horner x) ^ num)" . } ultimately show ?thesis @@ -1501,7 +1511,7 @@ qed lemma exp_boundaries': assumes "x \ 0" - shows "exp (real x) \ { real (lb_exp prec x) .. real (ub_exp prec x)}" + shows "exp x \ { (lb_exp prec x) .. (ub_exp prec x)}" proof - let "?lb_exp_horner x" = "lb_exp_horner prec (get_even (prec + 2)) 1 1 x" let "?ub_exp_horner x" = "ub_exp_horner prec (get_odd (prec + 2)) 1 1 x" @@ -1513,9 +1523,9 @@ show ?thesis proof (cases "?lb_exp_horner x \ 0") from `\ x < - 1` have "- 1 \ real x" unfolding less_float_def by auto - hence "exp (- 1) \ exp (real x)" unfolding exp_le_cancel_iff . + hence "exp (- 1) \ exp x" unfolding exp_le_cancel_iff . from order_trans[OF exp_m1_ge_quarter this] - have "real (Float 1 -2) \ exp (real x)" unfolding Float_num . + have "Float 1 -2 \ exp x" unfolding Float_num . moreover case True ultimately show ?thesis using bnds_exp_horner `real x \ 0` `\ x > 0` `\ x < - 1` by auto next @@ -1539,27 +1549,27 @@ hence "(0::nat) < 2 ^ nat e" by auto ultimately have "0 < ?num" by auto hence "real ?num \ 0" by auto - have e_nat: "int (nat e) = e" using `0 \ e` by auto - have num_eq: "real ?num = real (- floor_fl x)" using `0 < nat (- m)` + have e_nat: "(nat e) = e" using `0 \ e` by auto + have num_eq: "real ?num = - floor_fl x" using `0 < nat (- m)` unfolding Float_floor real_of_float_minus real_of_float_simp real_of_nat_mult pow2_int[of "nat e", unfolded e_nat] real_of_nat_power by auto have "0 < - floor_fl x" using `0 < ?num`[unfolded real_of_nat_less_iff[symmetric]] unfolding less_float_def num_eq[symmetric] real_of_float_0 real_of_nat_zero . hence "real (floor_fl x) < 0" unfolding less_float_def by auto - have "exp (real x) \ real (ub_exp prec x)" + have "exp x \ ub_exp prec x" proof - have div_less_zero: "real (float_divr prec x (- floor_fl x)) \ 0" using float_divr_nonpos_pos_upper_bound[OF `x \ 0` `0 < - floor_fl x`] unfolding le_float_def real_of_float_0 . - have "exp (real x) = exp (real ?num * (real x / real ?num))" using `real ?num \ 0` by auto - also have "\ = exp (real x / real ?num) ^ ?num" unfolding exp_real_of_nat_mult .. - also have "\ \ exp (real (float_divr prec x (- floor_fl x))) ^ ?num" unfolding num_eq + have "exp x = exp (?num * (x / ?num))" using `real ?num \ 0` by auto + also have "\ = exp (x / ?num) ^ ?num" unfolding exp_real_of_nat_mult .. + also have "\ \ exp (float_divr prec x (- floor_fl x)) ^ ?num" unfolding num_eq by (rule power_mono, rule exp_le_cancel_iff[THEN iffD2], rule float_divr) auto - also have "\ \ real ((?ub_exp_horner (float_divr prec x (- floor_fl x))) ^ ?num)" unfolding float_power + also have "\ \ (?ub_exp_horner (float_divr prec x (- floor_fl x))) ^ ?num" unfolding float_power by (rule power_mono, rule bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct2], auto) finally show ?thesis unfolding ub_exp.simps if_not_P[OF `\ 0 < x`] if_P[OF `x < - 1`] float.cases Float_floor Let_def . qed moreover - have "real (lb_exp prec x) \ exp (real x)" + have "lb_exp prec x \ exp x" proof - let ?divl = "float_divl prec x (- Float m e)" let ?horner = "?lb_exp_horner ?divl" @@ -1571,25 +1581,25 @@ have div_less_zero: "real (float_divl prec x (- floor_fl x)) \ 0" using `real (floor_fl x) < 0` `real x \ 0` by (auto intro!: order_trans[OF float_divl] divide_nonpos_neg) - have "real ((?lb_exp_horner (float_divl prec x (- floor_fl x))) ^ ?num) \ - exp (real (float_divl prec x (- floor_fl x))) ^ ?num" unfolding float_power + have "(?lb_exp_horner (float_divl prec x (- floor_fl x))) ^ ?num \ + exp (float_divl prec x (- floor_fl x)) ^ ?num" unfolding float_power using `0 \ real ?horner`[unfolded Float_floor[symmetric]] bnds_exp_horner[OF div_less_zero, unfolded atLeastAtMost_iff, THEN conjunct1] by (auto intro!: power_mono) - also have "\ \ exp (real x / real ?num) ^ ?num" unfolding num_eq + also have "\ \ exp (x / ?num) ^ ?num" unfolding num_eq using float_divl by (auto intro!: power_mono simp del: real_of_float_minus) - also have "\ = exp (real ?num * (real x / real ?num))" unfolding exp_real_of_nat_mult .. - also have "\ = exp (real x)" using `real ?num \ 0` by auto + also have "\ = exp (?num * (x / ?num))" unfolding exp_real_of_nat_mult .. + also have "\ = exp x" using `real ?num \ 0` by auto finally show ?thesis unfolding lb_exp.simps if_not_P[OF `\ 0 < x`] if_P[OF `x < - 1`] float.cases Float_floor Let_def if_not_P[OF False] by auto next case True have "real (floor_fl x) \ 0" and "real (floor_fl x) \ 0" using `real (floor_fl x) < 0` by auto from divide_right_mono_neg[OF floor_fl[of x] `real (floor_fl x) \ 0`, unfolded divide_self[OF `real (floor_fl x) \ 0`]] - have "- 1 \ real x / real (- floor_fl x)" unfolding real_of_float_minus by auto + have "- 1 \ x / (- floor_fl x)" unfolding real_of_float_minus by auto from order_trans[OF exp_m1_ge_quarter this[unfolded exp_le_cancel_iff[where x="- 1", symmetric]]] - have "real (Float 1 -2) \ exp (real x / real (- floor_fl x))" unfolding Float_num . - hence "real (Float 1 -2) ^ ?num \ exp (real x / real (- floor_fl x)) ^ ?num" + have "Float 1 -2 \ exp (x / (- floor_fl x))" unfolding Float_num . + hence "real (Float 1 -2) ^ ?num \ exp (x / (- floor_fl x)) ^ ?num" by (auto intro!: power_mono simp add: Float_num) - also have "\ = exp (real x)" unfolding num_eq exp_real_of_nat_mult[symmetric] using `real (floor_fl x) \ 0` by auto + also have "\ = exp x" unfolding num_eq exp_real_of_nat_mult[symmetric] using `real (floor_fl x) \ 0` by auto finally show ?thesis unfolding lb_exp.simps if_not_P[OF `\ 0 < x`] if_P[OF `x < - 1`] float.cases Float_floor Let_def if_P[OF True] float_power . qed @@ -1598,7 +1608,7 @@ qed qed -lemma exp_boundaries: "exp (real x) \ { real (lb_exp prec x) .. real (ub_exp prec x)}" +lemma exp_boundaries: "exp x \ { lb_exp prec x .. ub_exp prec x }" proof - show ?thesis proof (cases "0 < x") @@ -1607,51 +1617,51 @@ next case True hence "-x \ 0" unfolding less_float_def le_float_def by auto - have "real (lb_exp prec x) \ exp (real x)" + have "lb_exp prec x \ exp x" proof - from exp_boundaries'[OF `-x \ 0`] - have ub_exp: "exp (- real x) \ real (ub_exp prec (-x))" unfolding atLeastAtMost_iff real_of_float_minus by auto - - have "real (float_divl prec 1 (ub_exp prec (-x))) \ 1 / real (ub_exp prec (-x))" using float_divl[where x=1] by auto - also have "\ \ exp (real x)" + have ub_exp: "exp (- real x) \ ub_exp prec (-x)" unfolding atLeastAtMost_iff real_of_float_minus by auto + + have "float_divl prec 1 (ub_exp prec (-x)) \ 1 / ub_exp prec (-x)" using float_divl[where x=1] by auto + also have "\ \ exp x" using ub_exp[unfolded inverse_le_iff_le[OF order_less_le_trans[OF exp_gt_zero ub_exp] exp_gt_zero, symmetric]] unfolding exp_minus nonzero_inverse_inverse_eq[OF exp_not_eq_zero] inverse_eq_divide by auto finally show ?thesis unfolding lb_exp.simps if_P[OF True] . qed moreover - have "exp (real x) \ real (ub_exp prec x)" + have "exp x \ ub_exp prec x" proof - have "\ 0 < -x" using `0 < x` unfolding less_float_def by auto from exp_boundaries'[OF `-x \ 0`] - have lb_exp: "real (lb_exp prec (-x)) \ exp (- real x)" unfolding atLeastAtMost_iff real_of_float_minus by auto - - have "exp (real x) \ real (1 :: float) / real (lb_exp prec (-x))" + have lb_exp: "lb_exp prec (-x) \ exp (- real x)" unfolding atLeastAtMost_iff real_of_float_minus by auto + + have "exp x \ (1 :: float) / lb_exp prec (-x)" using lb_exp[unfolded inverse_le_iff_le[OF exp_gt_zero lb_exp_pos[OF `\ 0 < -x`, unfolded less_float_def real_of_float_0], symmetric]] unfolding exp_minus nonzero_inverse_inverse_eq[OF exp_not_eq_zero] inverse_eq_divide real_of_float_1 by auto - also have "\ \ real (float_divr prec 1 (lb_exp prec (-x)))" using float_divr . + also have "\ \ float_divr prec 1 (lb_exp prec (-x))" using float_divr . finally show ?thesis unfolding ub_exp.simps if_P[OF True] . qed ultimately show ?thesis by auto qed qed -lemma bnds_exp: "\ x lx ux. (l, u) = (lb_exp prec lx, ub_exp prec ux) \ x \ {real lx .. real ux} \ real l \ exp x \ exp x \ real u" +lemma bnds_exp: "\ (x::real) lx ux. (l, u) = (lb_exp prec lx, ub_exp prec ux) \ x \ {lx .. ux} \ l \ exp x \ exp x \ u" proof (rule allI, rule allI, rule allI, rule impI) - fix x lx ux - assume "(l, u) = (lb_exp prec lx, ub_exp prec ux) \ x \ {real lx .. real ux}" - hence l: "lb_exp prec lx = l " and u: "ub_exp prec ux = u" and x: "x \ {real lx .. real ux}" by auto + fix x::real and lx ux + assume "(l, u) = (lb_exp prec lx, ub_exp prec ux) \ x \ {lx .. ux}" + hence l: "lb_exp prec lx = l " and u: "ub_exp prec ux = u" and x: "x \ {lx .. ux}" by auto { from exp_boundaries[of lx prec, unfolded l] - have "real l \ exp (real lx)" by (auto simp del: lb_exp.simps) + have "l \ exp lx" by (auto simp del: lb_exp.simps) also have "\ \ exp x" using x by auto - finally have "real l \ exp x" . + finally have "l \ exp x" . } moreover - { have "exp x \ exp (real ux)" using x by auto - also have "\ \ real u" using exp_boundaries[of ux prec, unfolded u] by (auto simp del: ub_exp.simps) - finally have "exp x \ real u" . - } ultimately show "real l \ exp x \ exp x \ real u" .. + { have "exp x \ exp ux" using x by auto + also have "\ \ u" using exp_boundaries[of ux prec, unfolded u] by (auto simp del: ub_exp.simps) + finally have "exp x \ u" . + } ultimately show "l \ exp x \ exp x \ u" .. qed section "Logarithm" @@ -1692,8 +1702,8 @@ lemma ln_float_bounds: assumes "0 \ real x" and "real x < 1" - shows "real (x * lb_ln_horner prec (get_even n) 1 x) \ ln (real x + 1)" (is "?lb \ ?ln") - and "ln (real x + 1) \ real (x * ub_ln_horner prec (get_odd n) 1 x)" (is "?ln \ ?ub") + shows "x * lb_ln_horner prec (get_even n) 1 x \ ln (x + 1)" (is "?lb \ ?ln") + and "ln (x + 1) \ x * ub_ln_horner prec (get_odd n) 1 x" (is "?ln \ ?ub") proof - obtain ev where ev: "get_even n = 2 * ev" using get_even_double .. obtain od where od: "get_odd n = 2 * od + 1" using get_odd_double .. @@ -1734,18 +1744,18 @@ in (Float 1 -1 * lb_ln_horner prec (get_even prec) 1 (Float 1 -1)) + (third * lb_ln_horner prec (get_even prec) 1 third))" -lemma ub_ln2: "ln 2 \ real (ub_ln2 prec)" (is "?ub_ln2") - and lb_ln2: "real (lb_ln2 prec) \ ln 2" (is "?lb_ln2") +lemma ub_ln2: "ln 2 \ ub_ln2 prec" (is "?ub_ln2") + and lb_ln2: "lb_ln2 prec \ ln 2" (is "?lb_ln2") proof - let ?uthird = "rapprox_rat (max prec 1) 1 3" let ?lthird = "lapprox_rat prec 1 3" have ln2_sum: "ln 2 = ln (1/2 + 1) + ln (1 / 3 + 1)" using ln_add[of "3 / 2" "1 / 2"] by auto - have lb3: "real ?lthird \ 1 / 3" using lapprox_rat[of prec 1 3] by auto + have lb3: "?lthird \ 1 / 3" using lapprox_rat[of prec 1 3] by auto hence lb3_ub: "real ?lthird < 1" by auto have lb3_lb: "0 \ real ?lthird" using lapprox_rat_bottom[of 1 3] by auto - have ub3: "1 / 3 \ real ?uthird" using rapprox_rat[of 1 3] by auto + have ub3: "1 / 3 \ ?uthird" using rapprox_rat[of 1 3] by auto hence ub3_lb: "0 \ real ?uthird" by auto have lb2: "0 \ real (Float 1 -1)" and ub2: "real (Float 1 -1) < 1" unfolding Float_num by auto @@ -1761,16 +1771,16 @@ show ?ub_ln2 unfolding ub_ln2_def Let_def real_of_float_add ln2_sum Float_num(4)[symmetric] proof (rule add_mono, fact ln_float_bounds(2)[OF lb2 ub2]) have "ln (1 / 3 + 1) \ ln (real ?uthird + 1)" unfolding ln_le_cancel_iff[OF third_gt0 uthird_gt0] using ub3 by auto - also have "\ \ real (?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird)" + also have "\ \ ?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird" using ln_float_bounds(2)[OF ub3_lb ub3_ub] . - finally show "ln (1 / 3 + 1) \ real (?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird)" . + finally show "ln (1 / 3 + 1) \ ?uthird * ub_ln_horner prec (get_odd prec) 1 ?uthird" . qed show ?lb_ln2 unfolding lb_ln2_def Let_def real_of_float_add ln2_sum Float_num(4)[symmetric] proof (rule add_mono, fact ln_float_bounds(1)[OF lb2 ub2]) - have "real (?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird) \ ln (real ?lthird + 1)" + have "?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird \ ln (real ?lthird + 1)" using ln_float_bounds(1)[OF lb3_lb lb3_ub] . also have "\ \ ln (1 / 3 + 1)" unfolding ln_le_cancel_iff[OF lthird_gt0 third_gt0] using lb3 by auto - finally show "real (?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird) \ ln (1 / 3 + 1)" . + finally show "?lthird * lb_ln_horner prec (get_even prec) 1 ?lthird \ ln (1 / 3 + 1)" . qed qed @@ -1806,7 +1816,7 @@ show False using `float_divr prec 1 x < 1` unfolding less_float_def le_float_def by auto qed -lemma ln_shifted_float: assumes "0 < m" shows "ln (real (Float m e)) = ln 2 * real (e + (bitlen m - 1)) + ln (real (Float m (- (bitlen m - 1))))" +lemma ln_shifted_float: assumes "0 < m" shows "ln (Float m e) = ln 2 * (e + (bitlen m - 1)) + ln (Float m (- (bitlen m - 1)))" proof - let ?B = "2^nat (bitlen m - 1)" have "0 < real m" and "\X. (0 :: real) < 2^X" and "0 < (2 :: real)" and "m \ 0" using assms by auto @@ -1830,7 +1840,7 @@ qed lemma ub_ln_lb_ln_bounds': assumes "1 \ x" - shows "real (the (lb_ln prec x)) \ ln (real x) \ ln (real x) \ real (the (ub_ln prec x))" + shows "the (lb_ln prec x) \ ln x \ ln x \ the (ub_ln prec x)" (is "?lb \ ?ln \ ?ln \ ?ub") proof (cases "x < Float 1 1") case True @@ -1838,7 +1848,7 @@ have "\ x \ 0" and "\ x < 1" using `1 \ x` unfolding less_float_def le_float_def by auto hence "0 \ real (x - 1)" using `1 \ x` unfolding less_float_def Float_num by auto - have [simp]: "real (Float 3 -1) = 3 / 2" by (simp add: real_of_float_def pow2_def) + have [simp]: "(Float 3 -1) = 3 / 2" by (simp add: real_of_float_def pow2_def) show ?thesis proof (cases "x \ Float 3 -1") @@ -1847,10 +1857,10 @@ using ln_float_bounds[OF `0 \ real (x - 1)` `real (x - 1) < 1`, of prec] `\ x \ 0` `\ x < 1` True by auto next - case False hence *: "3 / 2 < real x" by (auto simp add: le_float_def) - - with ln_add[of "3 / 2" "real x - 3 / 2"] - have add: "ln (real x) = ln (3 / 2) + ln (real x * 2 / 3)" + case False hence *: "3 / 2 < x" by (auto simp add: le_float_def) + + with ln_add[of "3 / 2" "x - 3 / 2"] + have add: "ln x = ln (3 / 2) + ln (real x * 2 / 3)" by (auto simp add: algebra_simps diff_divide_distrib) let "?ub_horner x" = "x * ub_ln_horner prec (get_odd prec) 1 x" @@ -1858,7 +1868,7 @@ { have up: "real (rapprox_rat prec 2 3) \ 1" by (rule rapprox_rat_le1) simp_all - have low: "2 / 3 \ real (rapprox_rat prec 2 3)" + have low: "2 / 3 \ rapprox_rat prec 2 3" by (rule order_trans[OF _ rapprox_rat]) simp from mult_less_le_imp_less[OF * low] * have pos: "0 < real (x * rapprox_rat prec 2 3 - 1)" by auto @@ -1871,26 +1881,26 @@ show "0 < real x * 2 / 3" using * by simp show "0 < real (x * rapprox_rat prec 2 3 - 1) + 1" using pos by auto qed - also have "\ \ real (?ub_horner (x * rapprox_rat prec 2 3 - 1))" + also have "\ \ ?ub_horner (x * rapprox_rat prec 2 3 - 1)" proof (rule ln_float_bounds(2)) from mult_less_le_imp_less[OF `real x < 2` up] low * show "real (x * rapprox_rat prec 2 3 - 1) < 1" by auto show "0 \ real (x * rapprox_rat prec 2 3 - 1)" using pos by auto qed - finally have "ln (real x) - \ real (?ub_horner (Float 1 -1)) - + real (?ub_horner (x * rapprox_rat prec 2 3 - 1))" + finally have "ln x + \ ?ub_horner (Float 1 -1) + + ?ub_horner (x * rapprox_rat prec 2 3 - 1)" using ln_float_bounds(2)[of "Float 1 -1" prec prec] add by auto } moreover { let ?max = "max (x * lapprox_rat prec 2 3 - 1) 0" - have up: "real (lapprox_rat prec 2 3) \ 2/3" + have up: "lapprox_rat prec 2 3 \ 2/3" by (rule order_trans[OF lapprox_rat], simp) have low: "0 \ real (lapprox_rat prec 2 3)" using lapprox_rat_bottom[of 2 3 prec] by simp - have "real (?lb_horner ?max) + have "?lb_horner ?max \ ln (real ?max + 1)" proof (rule ln_float_bounds(1)) from mult_less_le_imp_less[OF `real x < 2` up] * low @@ -1906,8 +1916,8 @@ by (cases "0 < real x * real (lapprox_posrat prec 2 3) - 1", auto simp add: real_of_float_max min_max.sup_absorb1) qed - finally have "real (?lb_horner (Float 1 -1)) + real (?lb_horner ?max) - \ ln (real x)" + finally have "?lb_horner (Float 1 -1) + ?lb_horner ?max + \ ln x" using ln_float_bounds(1)[of "Float 1 -1" prec prec] add by auto } ultimately show ?thesis unfolding lb_ln.simps unfolding ub_ln.simps Let_def @@ -1927,7 +1937,7 @@ have "0 < m" and "m \ 0" using float_pos_m_pos `0 < x` Float by auto { - have "real (lb_ln2 prec * ?s) \ ln 2 * real (e + (bitlen m - 1))" (is "?lb2 \ _") + have "lb_ln2 prec * ?s \ ln 2 * (e + (bitlen m - 1))" (is "?lb2 \ _") unfolding real_of_float_mult real_of_float_ge0_exp[OF order_refl] nat_0 power_0 mult_1_right using lb_ln2[of prec] proof (rule mult_right_mono) @@ -1939,8 +1949,8 @@ from bitlen_div[OF `0 < m`, unfolded normalized_float[OF `m \ 0`, symmetric]] have "0 \ real (?x - 1)" and "real (?x - 1) < 1" by auto from ln_float_bounds(1)[OF this] - have "real ((?x - 1) * lb_ln_horner prec (get_even prec) 1 (?x - 1)) \ ln (real ?x)" (is "?lb_horner \ _") by auto - ultimately have "?lb2 + ?lb_horner \ ln (real x)" + have "(?x - 1) * lb_ln_horner prec (get_even prec) 1 (?x - 1) \ ln ?x" (is "?lb_horner \ _") by auto + ultimately have "?lb2 + ?lb_horner \ ln x" unfolding Float ln_shifted_float[OF `0 < m`, of e] by auto } moreover @@ -1948,9 +1958,9 @@ from bitlen_div[OF `0 < m`, unfolded normalized_float[OF `m \ 0`, symmetric]] have "0 \ real (?x - 1)" and "real (?x - 1) < 1" by auto from ln_float_bounds(2)[OF this] - have "ln (real ?x) \ real ((?x - 1) * ub_ln_horner prec (get_odd prec) 1 (?x - 1))" (is "_ \ ?ub_horner") by auto + have "ln ?x \ (?x - 1) * ub_ln_horner prec (get_odd prec) 1 (?x - 1)" (is "_ \ ?ub_horner") by auto moreover - have "ln 2 * real (e + (bitlen m - 1)) \ real (ub_ln2 prec * ?s)" (is "_ \ ?ub2") + have "ln 2 * (e + (bitlen m - 1)) \ ub_ln2 prec * ?s" (is "_ \ ?ub2") unfolding real_of_float_mult real_of_float_ge0_exp[OF order_refl] nat_0 power_0 mult_1_right using ub_ln2[of prec] proof (rule mult_right_mono) @@ -1958,7 +1968,7 @@ from float_gt1_scale[OF this] show "0 \ real (e + (bitlen m - 1))" by auto qed - ultimately have "ln (real x) \ ?ub2 + ?ub_horner" + ultimately have "ln x \ ?ub2 + ?ub_horner" unfolding Float ln_shifted_float[OF `0 < m`, of e] by auto } ultimately show ?thesis unfolding lb_ln.simps unfolding ub_ln.simps @@ -1969,7 +1979,7 @@ qed lemma ub_ln_lb_ln_bounds: assumes "0 < x" - shows "real (the (lb_ln prec x)) \ ln (real x) \ ln (real x) \ real (the (ub_ln prec x))" + shows "the (lb_ln prec x) \ ln x \ ln x \ the (ub_ln prec x)" (is "?lb \ ?ln \ ?ln \ ?ub") proof (cases "x < 1") case False hence "1 \ x" unfolding less_float_def le_float_def by auto @@ -1985,27 +1995,27 @@ have A': "1 \ ?divl" using float_divl_pos_less1_bound[OF `0 < x` `x < 1`] unfolding le_float_def less_float_def by auto hence B: "0 < real ?divl" unfolding le_float_def by auto - have "ln (real ?divl) \ ln (1 / real x)" unfolding ln_le_cancel_iff[OF B A] using float_divl[of _ 1 x] by auto - hence "ln (real x) \ - ln (real ?divl)" unfolding nonzero_inverse_eq_divide[OF `real x \ 0`, symmetric] ln_inverse[OF `0 < real x`] by auto + have "ln ?divl \ ln (1 / x)" unfolding ln_le_cancel_iff[OF B A] using float_divl[of _ 1 x] by auto + hence "ln x \ - ln ?divl" unfolding nonzero_inverse_eq_divide[OF `real x \ 0`, symmetric] ln_inverse[OF `0 < real x`] by auto from this ub_ln_lb_ln_bounds'[OF A', THEN conjunct1, THEN le_imp_neg_le] - have "?ln \ real (- the (lb_ln prec ?divl))" unfolding real_of_float_minus by (rule order_trans) + have "?ln \ - the (lb_ln prec ?divl)" unfolding real_of_float_minus by (rule order_trans) } moreover { let ?divr = "float_divr prec 1 x" have A': "1 \ ?divr" using float_divr_pos_less1_lower_bound[OF `0 < x` `x < 1`] unfolding le_float_def less_float_def by auto hence B: "0 < real ?divr" unfolding le_float_def by auto - have "ln (1 / real x) \ ln (real ?divr)" unfolding ln_le_cancel_iff[OF A B] using float_divr[of 1 x] by auto - hence "- ln (real ?divr) \ ln (real x)" unfolding nonzero_inverse_eq_divide[OF `real x \ 0`, symmetric] ln_inverse[OF `0 < real x`] by auto + have "ln (1 / x) \ ln ?divr" unfolding ln_le_cancel_iff[OF A B] using float_divr[of 1 x] by auto + hence "- ln ?divr \ ln x" unfolding nonzero_inverse_eq_divide[OF `real x \ 0`, symmetric] ln_inverse[OF `0 < real x`] by auto from ub_ln_lb_ln_bounds'[OF A', THEN conjunct2, THEN le_imp_neg_le] this - have "real (- the (ub_ln prec ?divr)) \ ?ln" unfolding real_of_float_minus by (rule order_trans) + have "- the (ub_ln prec ?divr) \ ?ln" unfolding real_of_float_minus by (rule order_trans) } ultimately show ?thesis unfolding lb_ln.simps[where x=x] ub_ln.simps[where x=x] unfolding if_not_P[OF `\ x \ 0`] if_P[OF True] by auto qed lemma lb_ln: assumes "Some y = lb_ln prec x" - shows "real y \ ln (real x)" and "0 < real x" + shows "y \ ln x" and "0 < real x" proof - have "0 < x" proof (rule ccontr) @@ -2013,12 +2023,12 @@ thus False using assms by auto qed thus "0 < real x" unfolding less_float_def by auto - have "real (the (lb_ln prec x)) \ ln (real x)" using ub_ln_lb_ln_bounds[OF `0 < x`] .. - thus "real y \ ln (real x)" unfolding assms[symmetric] by auto + have "the (lb_ln prec x) \ ln x" using ub_ln_lb_ln_bounds[OF `0 < x`] .. + thus "y \ ln x" unfolding assms[symmetric] by auto qed lemma ub_ln: assumes "Some y = ub_ln prec x" - shows "ln (real x) \ real y" and "0 < real x" + shows "ln x \ y" and "0 < real x" proof - have "0 < x" proof (rule ccontr) @@ -2026,25 +2036,25 @@ thus False using assms by auto qed thus "0 < real x" unfolding less_float_def by auto - have "ln (real x) \ real (the (ub_ln prec x))" using ub_ln_lb_ln_bounds[OF `0 < x`] .. - thus "ln (real x) \ real y" unfolding assms[symmetric] by auto + have "ln x \ the (ub_ln prec x)" using ub_ln_lb_ln_bounds[OF `0 < x`] .. + thus "ln x \ y" unfolding assms[symmetric] by auto qed -lemma bnds_ln: "\ x lx ux. (Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \ x \ {real lx .. real ux} \ real l \ ln x \ ln x \ real u" +lemma bnds_ln: "\ (x::real) lx ux. (Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \ x \ {lx .. ux} \ l \ ln x \ ln x \ u" proof (rule allI, rule allI, rule allI, rule impI) - fix x lx ux - assume "(Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \ x \ {real lx .. real ux}" - hence l: "Some l = lb_ln prec lx " and u: "Some u = ub_ln prec ux" and x: "x \ {real lx .. real ux}" by auto - - have "ln (real ux) \ real u" and "0 < real ux" using ub_ln u by auto - have "real l \ ln (real lx)" and "0 < real lx" and "0 < x" using lb_ln[OF l] x by auto - - from ln_le_cancel_iff[OF `0 < real lx` `0 < x`] `real l \ ln (real lx)` - have "real l \ ln x" using x unfolding atLeastAtMost_iff by auto + fix x::real and lx ux + assume "(Some l, Some u) = (lb_ln prec lx, ub_ln prec ux) \ x \ {lx .. ux}" + hence l: "Some l = lb_ln prec lx " and u: "Some u = ub_ln prec ux" and x: "x \ {lx .. ux}" by auto + + have "ln ux \ u" and "0 < real ux" using ub_ln u by auto + have "l \ ln lx" and "0 < real lx" and "0 < x" using lb_ln[OF l] x by auto + + from ln_le_cancel_iff[OF `0 < real lx` `0 < x`] `l \ ln lx` + have "l \ ln x" using x unfolding atLeastAtMost_iff by auto moreover - from ln_le_cancel_iff[OF `0 < x` `0 < real ux`] `ln (real ux) \ real u` - have "ln x \ real u" using x unfolding atLeastAtMost_iff by auto - ultimately show "real l \ ln x \ ln x \ real u" .. + from ln_le_cancel_iff[OF `0 < x` `0 < real ux`] `ln ux \ real u` + have "ln x \ u" using x unfolding atLeastAtMost_iff by auto + ultimately show "l \ ln x \ ln x \ u" .. qed section "Implement floatarith" @@ -2084,7 +2094,7 @@ "interpret_floatarith (Exp a) vs = exp (interpret_floatarith a vs)" | "interpret_floatarith (Ln a) vs = ln (interpret_floatarith a vs)" | "interpret_floatarith (Power a n) vs = (interpret_floatarith a vs)^n" | -"interpret_floatarith (Num f) vs = real f" | +"interpret_floatarith (Num f) vs = f" | "interpret_floatarith (Var n) vs = vs ! n" lemma interpret_floatarith_divide: "interpret_floatarith (Mult a (Inverse b)) vs = (interpret_floatarith a vs) / (interpret_floatarith b vs)" @@ -2223,9 +2233,9 @@ qed lemma approx_approx': - assumes Pa: "\l u. Some (l, u) = approx prec a vs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" + assumes Pa: "\l u. Some (l, u) = approx prec a vs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" and approx': "Some (l, u) = approx' prec a vs" - shows "real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" + shows "l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" proof - obtain l' u' where S: "Some (l', u') = approx prec a vs" using approx' unfolding approx'.simps by (cases "approx prec a vs", auto) @@ -2238,18 +2248,18 @@ lemma lift_bin': assumes lift_bin'_Some: "Some (l, u) = lift_bin' (approx' prec a bs) (approx' prec b bs) f" - and Pa: "\l u. Some (l, u) = approx prec a bs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" (is "\l u. _ = ?g a \ ?P l u a") - and Pb: "\l u. Some (l, u) = approx prec b bs \ real l \ interpret_floatarith b xs \ interpret_floatarith b xs \ real u" - shows "\ l1 u1 l2 u2. (real l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u1) \ - (real l2 \ interpret_floatarith b xs \ interpret_floatarith b xs \ real u2) \ + and Pa: "\l u. Some (l, u) = approx prec a bs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" (is "\l u. _ = ?g a \ ?P l u a") + and Pb: "\l u. Some (l, u) = approx prec b bs \ l \ interpret_floatarith b xs \ interpret_floatarith b xs \ u" + shows "\ l1 u1 l2 u2. (l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ u1) \ + (l2 \ interpret_floatarith b xs \ interpret_floatarith b xs \ u2) \ l = fst (f l1 u1 l2 u2) \ u = snd (f l1 u1 l2 u2)" proof - { fix l u assume "Some (l, u) = approx' prec a bs" with approx_approx'[of prec a bs, OF _ this] Pa - have "real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" by auto } note Pa = this + have "l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" by auto } note Pa = this { fix l u assume "Some (l, u) = approx' prec b bs" with approx_approx'[of prec b bs, OF _ this] Pb - have "real l \ interpret_floatarith b xs \ interpret_floatarith b xs \ real u" by auto } note Pb = this + have "l \ interpret_floatarith b xs \ interpret_floatarith b xs \ u" by auto } note Pb = this from lift_bin'_f[where g="\a. approx' prec a bs" and P = ?P, OF lift_bin'_Some, OF Pa Pb] show ?thesis by auto @@ -2280,26 +2290,26 @@ lemma lift_un': assumes lift_un'_Some: "Some (l, u) = lift_un' (approx' prec a bs) f" - and Pa: "\l u. Some (l, u) = approx prec a bs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" (is "\l u. _ = ?g a \ ?P l u a") - shows "\ l1 u1. (real l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u1) \ + and Pa: "\l u. Some (l, u) = approx prec a bs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" (is "\l u. _ = ?g a \ ?P l u a") + shows "\ l1 u1. (l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ u1) \ l = fst (f l1 u1) \ u = snd (f l1 u1)" proof - { fix l u assume "Some (l, u) = approx' prec a bs" with approx_approx'[of prec a bs, OF _ this] Pa - have "real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" by auto } note Pa = this + have "l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" by auto } note Pa = this from lift_un'_f[where g="\a. approx' prec a bs" and P = ?P, OF lift_un'_Some, OF Pa] show ?thesis by auto qed lemma lift_un'_bnds: - assumes bnds: "\ x lx ux. (l, u) = f lx ux \ x \ { real lx .. real ux } \ real l \ f' x \ f' x \ real u" + assumes bnds: "\ (x::real) lx ux. (l, u) = f lx ux \ x \ { lx .. ux } \ l \ f' x \ f' x \ u" and lift_un'_Some: "Some (l, u) = lift_un' (approx' prec a bs) f" - and Pa: "\l u. Some (l, u) = approx prec a bs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" + and Pa: "\l u. Some (l, u) = approx prec a bs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" shows "real l \ f' (interpret_floatarith a xs) \ f' (interpret_floatarith a xs) \ real u" proof - from lift_un'[OF lift_un'_Some Pa] - obtain l1 u1 where "real l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ real u1" and "l = fst (f l1 u1)" and "u = snd (f l1 u1)" by blast - hence "(l, u) = f l1 u1" and "interpret_floatarith a xs \ {real l1 .. real u1}" by auto + obtain l1 u1 where "l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ u1" and "l = fst (f l1 u1)" and "u = snd (f l1 u1)" by blast + hence "(l, u) = f l1 u1" and "interpret_floatarith a xs \ {l1 .. u1}" by auto thus ?thesis using bnds by auto qed @@ -2345,46 +2355,46 @@ lemma lift_un: assumes lift_un_Some: "Some (l, u) = lift_un (approx' prec a bs) f" - and Pa: "\l u. Some (l, u) = approx prec a bs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" (is "\l u. _ = ?g a \ ?P l u a") - shows "\ l1 u1. (real l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u1) \ + and Pa: "\l u. Some (l, u) = approx prec a bs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" (is "\l u. _ = ?g a \ ?P l u a") + shows "\ l1 u1. (l1 \ interpret_floatarith a xs \ interpret_floatarith a xs \ u1) \ Some l = fst (f l1 u1) \ Some u = snd (f l1 u1)" proof - { fix l u assume "Some (l, u) = approx' prec a bs" with approx_approx'[of prec a bs, OF _ this] Pa - have "real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" by auto } note Pa = this + have "l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" by auto } note Pa = this from lift_un_f[where g="\a. approx' prec a bs" and P = ?P, OF lift_un_Some, OF Pa] show ?thesis by auto qed lemma lift_un_bnds: - assumes bnds: "\ x lx ux. (Some l, Some u) = f lx ux \ x \ { real lx .. real ux } \ real l \ f' x \ f' x \ real u" + assumes bnds: "\ (x::real) lx ux. (Some l, Some u) = f lx ux \ x \ { lx .. ux } \ l \ f' x \ f' x \ u" and lift_un_Some: "Some (l, u) = lift_un (approx' prec a bs) f" - and Pa: "\l u. Some (l, u) = approx prec a bs \ real l \ interpret_floatarith a xs \ interpret_floatarith a xs \ real u" + and Pa: "\l u. Some (l, u) = approx prec a bs \ l \ interpret_floatarith a xs \ interpret_floatarith a xs \ u" shows "real l \ f' (interpret_floatarith a xs) \ f' (interpret_floatarith a xs) \ real u" proof - from lift_un[OF lift_un_Some Pa] - obtain l1 u1 where "real l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ real u1" and "Some l = fst (f l1 u1)" and "Some u = snd (f l1 u1)" by blast - hence "(Some l, Some u) = f l1 u1" and "interpret_floatarith a xs \ {real l1 .. real u1}" by auto + obtain l1 u1 where "l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ u1" and "Some l = fst (f l1 u1)" and "Some u = snd (f l1 u1)" by blast + hence "(Some l, Some u) = f l1 u1" and "interpret_floatarith a xs \ {l1 .. u1}" by auto thus ?thesis using bnds by auto qed lemma approx: assumes "bounded_by xs vs" and "Some (l, u) = approx prec arith vs" (is "_ = ?g arith") - shows "real l \ interpret_floatarith arith xs \ interpret_floatarith arith xs \ real u" (is "?P l u arith") + shows "l \ interpret_floatarith arith xs \ interpret_floatarith arith xs \ u" (is "?P l u arith") using `Some (l, u) = approx prec arith vs` proof (induct arith arbitrary: l u x) case (Add a b) from lift_bin'[OF Add.prems[unfolded approx.simps]] Add.hyps obtain l1 u1 l2 u2 where "l = l1 + l2" and "u = u1 + u2" - "real l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ real u1" - "real l2 \ interpret_floatarith b xs" and "interpret_floatarith b xs \ real u2" unfolding fst_conv snd_conv by blast + "l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ u1" + "l2 \ interpret_floatarith b xs" and "interpret_floatarith b xs \ u2" unfolding fst_conv snd_conv by blast thus ?case unfolding interpret_floatarith.simps by auto next case (Minus a) from lift_un'[OF Minus.prems[unfolded approx.simps]] Minus.hyps obtain l1 u1 where "l = -u1" and "u = -l1" - "real l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ real u1" unfolding fst_conv snd_conv by blast + "l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ u1" unfolding fst_conv snd_conv by blast thus ?case unfolding interpret_floatarith.simps using real_of_float_minus by auto next case (Mult a b) @@ -2392,8 +2402,8 @@ obtain l1 u1 l2 u2 where l: "l = float_nprt l1 * float_pprt u2 + float_nprt u1 * float_nprt u2 + float_pprt l1 * float_pprt l2 + float_pprt u1 * float_nprt l2" and u: "u = float_pprt u1 * float_pprt u2 + float_pprt l1 * float_nprt u2 + float_nprt u1 * float_pprt l2 + float_nprt l1 * float_nprt l2" - and "real l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ real u1" - and "real l2 \ interpret_floatarith b xs" and "interpret_floatarith b xs \ real u2" unfolding fst_conv snd_conv by blast + and "l1 \ interpret_floatarith a xs" and "interpret_floatarith a xs \ u1" + and "l2 \ interpret_floatarith b xs" and "interpret_floatarith b xs \ u2" unfolding fst_conv snd_conv by blast thus ?case unfolding interpret_floatarith.simps l u real_of_float_add real_of_float_mult real_of_float_nprt real_of_float_pprt using mult_le_prts mult_ge_prts by auto next @@ -2401,13 +2411,13 @@ from lift_un[OF Inverse.prems[unfolded approx.simps], unfolded if_distrib[of fst] if_distrib[of snd] fst_conv snd_conv] Inverse.hyps obtain l1 u1 where l': "Some l = (if 0 < l1 \ u1 < 0 then Some (float_divl prec 1 u1) else None)" and u': "Some u = (if 0 < l1 \ u1 < 0 then Some (float_divr prec 1 l1) else None)" - and l1: "real l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ real u1" by blast + and l1: "l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ u1" by blast have either: "0 < l1 \ u1 < 0" proof (rule ccontr) assume P: "\ (0 < l1 \ u1 < 0)" show False using l' unfolding if_not_P[OF P] by auto qed moreover have l1_le_u1: "real l1 \ real u1" using l1 u1 by auto ultimately have "real l1 \ 0" and "real u1 \ 0" unfolding less_float_def by auto - have inv: "inverse (real u1) \ inverse (interpret_floatarith a xs) - \ inverse (interpret_floatarith a xs) \ inverse (real l1)" + have inv: "inverse u1 \ inverse (interpret_floatarith a xs) + \ inverse (interpret_floatarith a xs) \ inverse l1" proof (cases "0 < l1") case True hence "0 < real u1" and "0 < real l1" "0 < interpret_floatarith a xs" unfolding less_float_def using l1_le_u1 l1 by auto @@ -2426,33 +2436,33 @@ qed from l' have "l = float_divl prec 1 u1" by (cases "0 < l1 \ u1 < 0", auto) - hence "real l \ inverse (real u1)" unfolding nonzero_inverse_eq_divide[OF `real u1 \ 0`] using float_divl[of prec 1 u1] by auto + hence "l \ inverse u1" unfolding nonzero_inverse_eq_divide[OF `real u1 \ 0`] using float_divl[of prec 1 u1] by auto also have "\ \ inverse (interpret_floatarith a xs)" using inv by auto - finally have "real l \ inverse (interpret_floatarith a xs)" . + finally have "l \ inverse (interpret_floatarith a xs)" . moreover from u' have "u = float_divr prec 1 l1" by (cases "0 < l1 \ u1 < 0", auto) - hence "inverse (real l1) \ real u" unfolding nonzero_inverse_eq_divide[OF `real l1 \ 0`] using float_divr[of 1 l1 prec] by auto - hence "inverse (interpret_floatarith a xs) \ real u" by (rule order_trans[OF inv[THEN conjunct2]]) + hence "inverse l1 \ u" unfolding nonzero_inverse_eq_divide[OF `real l1 \ 0`] using float_divr[of 1 l1 prec] by auto + hence "inverse (interpret_floatarith a xs) \ u" by (rule order_trans[OF inv[THEN conjunct2]]) ultimately show ?case unfolding interpret_floatarith.simps using l1 u1 by auto next case (Abs x) from lift_un'[OF Abs.prems[unfolded approx.simps], unfolded fst_conv snd_conv] Abs.hyps obtain l1 u1 where l': "l = (if l1 < 0 \ 0 < u1 then 0 else min \l1\ \u1\)" and u': "u = max \l1\ \u1\" - and l1: "real l1 \ interpret_floatarith x xs" and u1: "interpret_floatarith x xs \ real u1" by blast + and l1: "l1 \ interpret_floatarith x xs" and u1: "interpret_floatarith x xs \ u1" by blast thus ?case unfolding l' u' by (cases "l1 < 0 \ 0 < u1", auto simp add: real_of_float_min real_of_float_max real_of_float_abs less_float_def) next case (Min a b) from lift_bin'[OF Min.prems[unfolded approx.simps], unfolded fst_conv snd_conv] Min.hyps obtain l1 u1 l2 u2 where l': "l = min l1 l2" and u': "u = min u1 u2" - and l1: "real l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ real u1" - and l1: "real l2 \ interpret_floatarith b xs" and u1: "interpret_floatarith b xs \ real u2" by blast + and l1: "l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ u1" + and l1: "l2 \ interpret_floatarith b xs" and u1: "interpret_floatarith b xs \ u2" by blast thus ?case unfolding l' u' by (auto simp add: real_of_float_min) next case (Max a b) from lift_bin'[OF Max.prems[unfolded approx.simps], unfolded fst_conv snd_conv] Max.hyps obtain l1 u1 l2 u2 where l': "l = max l1 l2" and u': "u = max u1 u2" - and l1: "real l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ real u1" - and l1: "real l2 \ interpret_floatarith b xs" and u1: "interpret_floatarith b xs \ real u2" by blast + and l1: "l1 \ interpret_floatarith a xs" and u1: "interpret_floatarith a xs \ u1" + and l1: "l2 \ interpret_floatarith b xs" and u1: "interpret_floatarith b xs \ u2" by blast thus ?case unfolding l' u' by (auto simp add: real_of_float_max) next case (Cos a) with lift_un'_bnds[OF bnds_cos] show ?case by auto next case (Arctan a) with lift_un'_bnds[OF bnds_arctan] show ?case by auto @@ -2511,8 +2521,8 @@ lemma lazy_conj: "(if A then B else False) = (A \ B)" by simp lemma approx_form_approx_form': - assumes "approx_form' prec f s n l u bs ss" and "x \ { real l .. real u }" - obtains l' u' where "x \ { real l' .. real u' }" + assumes "approx_form' prec f s n l u bs ss" and "(x::real) \ { l .. u }" + obtains l' u' where "x \ { l' .. u' }" and "approx_form prec f (bs[n := Some (l', u')]) ss" using assms proof (induct s arbitrary: l u) case 0 @@ -2522,18 +2532,18 @@ case (Suc s) let ?m = "(l + u) * Float 1 -1" - have "real l \ real ?m" and "real ?m \ real u" + have "real l \ ?m" and "?m \ real u" unfolding le_float_def using Suc.prems by auto - with `x \ { real l .. real u }` - have "x \ { real l .. real ?m} \ x \ { real ?m .. real u }" by auto + with `x \ { l .. u }` + have "x \ { l .. ?m} \ x \ { ?m .. u }" by auto thus thesis proof (rule disjE) - assume *: "x \ { real l .. real ?m }" + assume *: "x \ { l .. ?m }" with Suc.hyps[OF _ _ *] Suc.prems show thesis by (simp add: Let_def lazy_conj) next - assume *: "x \ { real ?m .. real u }" + assume *: "x \ { ?m .. u }" with Suc.hyps[OF _ _ *] Suc.prems show thesis by (simp add: Let_def lazy_conj) qed @@ -2553,12 +2563,13 @@ and u_eq: "Some (l', u) = approx prec b vs" and approx_form': "approx_form' prec f (ss ! n) n l u vs ss" by (cases "approx prec a vs", simp) (cases "approx prec b vs", auto) + { assume "xs ! n \ { interpret_floatarith a xs .. interpret_floatarith b xs }" with approx[OF Bound.prems(2) l_eq] and approx[OF Bound.prems(2) u_eq] - have "xs ! n \ { real l .. real u}" by auto + have "xs ! n \ { l .. u}" by auto from approx_form_approx_form'[OF approx_form' this] - obtain lx ux where bnds: "xs ! n \ { real lx .. real ux }" + obtain lx ux where bnds: "xs ! n \ { lx .. ux }" and approx_form: "approx_form prec f (vs[n := Some (lx, ux)]) ss" . from `bounded_by xs vs` bnds @@ -2579,9 +2590,9 @@ { assume bnds: "xs ! n = interpret_floatarith a xs" with approx[OF Assign.prems(2) bnd_eq] - have "xs ! n \ { real l .. real u}" by auto + have "xs ! n \ { l .. u}" by auto from approx_form_approx_form'[OF approx_form' this] - obtain lx ux where bnds: "xs ! n \ { real lx .. real ux }" + obtain lx ux where bnds: "xs ! n \ { lx .. ux }" and approx_form: "approx_form prec f (vs[n := Some (lx, ux)]) ss" . from `bounded_by xs vs` bnds @@ -2789,13 +2800,13 @@ assumes "n < length xs" and bnd: "bounded_by xs vs" and isD: "isDERIV_approx prec n f vs" and app: "Some (l, u) = approx prec (DERIV_floatarith n f) vs" (is "_ = approx _ ?D _") - shows "\x. real l \ x \ x \ real u \ + shows "\(x::real). l \ x \ x \ u \ DERIV (\ x. interpret_floatarith f (xs[n := x])) (xs!n) :> x" (is "\ x. _ \ _ \ DERIV (?i f) _ :> _") proof (rule exI[of _ "?i ?D (xs!n)"], rule conjI[OF _ conjI]) let "?i f x" = "interpret_floatarith f (xs[n := x])" from approx[OF bnd app] - show "real l \ ?i ?D (xs!n)" and "?i ?D (xs!n) \ real u" + show "l \ ?i ?D (xs!n)" and "?i ?D (xs!n) \ u" using `n < length xs` by auto from DERIV_floatarith[OF `n < length xs`, of f "xs!n"] isDERIV_approx[OF bnd isD] show "DERIV (?i f) (xs!n) :> (?i ?D (xs!n))" by simp @@ -2845,24 +2856,24 @@ lemma approx_tse_generic: assumes "bounded_by xs vs" - and bnd_c: "bounded_by (xs[x := real c]) vs" and "x < length vs" and "x < length xs" + and bnd_c: "bounded_by (xs[x := c]) vs" and "x < length vs" and "x < length xs" and bnd_x: "vs ! x = Some (lx, ux)" and ate: "Some (l, u) = approx_tse prec x s c k f vs" - shows "\ n. (\ m < n. \ z \ {real lx .. real ux}. + shows "\ n. (\ m < n. \ (z::real) \ {lx .. ux}. DERIV (\ y. interpret_floatarith ((DERIV_floatarith x ^^ m) f) (xs[x := y])) z :> (interpret_floatarith ((DERIV_floatarith x ^^ (Suc m)) f) (xs[x := z]))) - \ (\ t \ {real lx .. real ux}. (\ i = 0.. j \ {k.. (\ (t::real) \ {lx .. ux}. (\ i = 0.. j \ {k.. j \ {k.. {real l .. real u})" (is "\ n. ?taylor f k l u n") + (xs!x - c)^n \ {l .. u})" (is "\ n. ?taylor f k l u n") using ate proof (induct s arbitrary: k f l u) case 0 - { fix t assume "t \ {real lx .. real ux}" + { fix t::real assume "t \ {lx .. ux}" note bounded_by_update_var[OF `bounded_by xs vs` bnd_x this] from approx[OF this 0[unfolded approx_tse.simps]] - have "(interpret_floatarith f (xs[x := t])) \ {real l .. real u}" + have "(interpret_floatarith f (xs[x := t])) \ {l .. u}" by (auto simp add: algebra_simps) } thus ?case by (auto intro!: exI[of _ 0]) next @@ -2872,10 +2883,10 @@ case False note ap = Suc.prems[unfolded approx_tse.simps if_not_P[OF False]] - { fix t assume "t \ {real lx .. real ux}" + { fix t::real assume "t \ {lx .. ux}" note bounded_by_update_var[OF `bounded_by xs vs` bnd_x this] from approx[OF this ap] - have "(interpret_floatarith f (xs[x := t])) \ {real l .. real u}" + have "(interpret_floatarith f (xs[x := t])) \ {l .. u}" by (auto simp add: algebra_simps) } thus ?thesis by (auto intro!: exI[of _ 0]) next @@ -2892,11 +2903,11 @@ by (auto elim!: lift_bin) blast from bnd_c `x < length xs` - have bnd: "bounded_by (xs[x:=real c]) (vs[x:= Some (c,c)])" + have bnd: "bounded_by (xs[x:=c]) (vs[x:= Some (c,c)])" by (auto intro!: bounded_by_update) from approx[OF this a] - have f_c: "interpret_floatarith ((DERIV_floatarith x ^^ 0) f) (xs[x := real c]) \ { real l1 .. real u1 }" + have f_c: "interpret_floatarith ((DERIV_floatarith x ^^ 0) f) (xs[x := c]) \ { l1 .. u1 }" (is "?f 0 (real c) \ _") by auto @@ -2906,14 +2917,14 @@ note funpow_Suc = this[symmetric] from Suc.hyps[OF ate, unfolded this] obtain n - where DERIV_hyp: "\ m z. \ m < n ; z \ { real lx .. real ux } \ \ DERIV (?f (Suc m)) z :> ?f (Suc (Suc m)) z" - and hyp: "\ t \ {real lx .. real ux}. (\ i = 0.. j \ {Suc k.. j \ {Suc k.. {real l2 .. real u2}" + where DERIV_hyp: "\ m z. \ m < n ; (z::real) \ { lx .. ux } \ \ DERIV (?f (Suc m)) z :> ?f (Suc (Suc m)) z" + and hyp: "\ t \ {real lx .. real ux}. (\ i = 0.. j \ {Suc k.. j \ {Suc k.. {l2 .. u2}" (is "\ t \ _. ?X (Suc k) f n t \ _") by blast - { fix m z - assume "m < Suc n" and bnd_z: "z \ { real lx .. real ux }" + { fix m and z::real + assume "m < Suc n" and bnd_z: "z \ { lx .. ux }" have "DERIV (?f m) z :> ?f (Suc m) z" proof (cases m) case 0 @@ -2931,26 +2942,26 @@ have setsum_move0: "\ k F. setsum F {0.. k. F (Suc k)) {0.. "xs!x - real c" - - { fix t assume t: "t \ {real lx .. real ux}" + def C \ "xs!x - c" + + { fix t::real assume t: "t \ {lx .. ux}" hence "bounded_by [xs!x] [vs!x]" using `bounded_by xs vs`[THEN bounded_byE, OF `x < length vs`] by (cases "vs!x", auto simp add: bounded_by_def) with hyp[THEN bspec, OF t] f_c - have "bounded_by [?f 0 (real c), ?X (Suc k) f n t, xs!x] [Some (l1, u1), Some (l2, u2), vs!x]" + have "bounded_by [?f 0 c, ?X (Suc k) f n t, xs!x] [Some (l1, u1), Some (l2, u2), vs!x]" by (auto intro!: bounded_by_Cons) from approx[OF this final, unfolded atLeastAtMost_iff[symmetric]] - have "?X (Suc k) f n t * (xs!x - real c) * inverse (real k) + ?f 0 (real c) \ {real l .. real u}" + have "?X (Suc k) f n t * (xs!x - real c) * inverse k + ?f 0 c \ {l .. u}" by (auto simp add: algebra_simps) - also have "?X (Suc k) f n t * (xs!x - real c) * inverse (real k) + ?f 0 (real c) = - (\ i = 0.. j \ {k.. j \ {k.. i = 0.. j \ {k.. j \ {k.. {real l .. real u}" . } + finally have "?T \ {l .. u}" . } thus ?thesis using DERIV by blast qed qed @@ -2965,28 +2976,28 @@ lemma approx_tse: assumes "bounded_by xs vs" - and bnd_x: "vs ! x = Some (lx, ux)" and bnd_c: "real c \ {real lx .. real ux}" + and bnd_x: "vs ! x = Some (lx, ux)" and bnd_c: "real c \ {lx .. ux}" and "x < length vs" and "x < length xs" and ate: "Some (l, u) = approx_tse prec x s c 1 f vs" - shows "interpret_floatarith f xs \ { real l .. real u }" + shows "interpret_floatarith f xs \ { l .. u }" proof - def F \ "\ n z. interpret_floatarith ((DERIV_floatarith x ^^ n) f) (xs[x := z])" hence F0: "F 0 = (\ z. interpret_floatarith f (xs[x := z]))" by auto - hence "bounded_by (xs[x := real c]) vs" and "x < length vs" "x < length xs" + hence "bounded_by (xs[x := c]) vs" and "x < length vs" "x < length xs" using `bounded_by xs vs` bnd_x bnd_c `x < length vs` `x < length xs` by (auto intro!: bounded_by_update_var) from approx_tse_generic[OF `bounded_by xs vs` this bnd_x ate] obtain n where DERIV: "\ m z. m < n \ real lx \ z \ z \ real ux \ DERIV (F m) z :> F (Suc m) z" - and hyp: "\ t. t \ {real lx .. real ux} \ - (\ j = 0.. {real l .. real u}" (is "\ t. _ \ ?taylor t \ _") + and hyp: "\ (t::real). t \ {lx .. ux} \ + (\ j = 0.. {l .. u}" (is "\ t. _ \ ?taylor t \ _") unfolding F_def atLeastAtMost_iff[symmetric] setprod_fact by blast - have bnd_xs: "xs ! x \ { real lx .. real ux }" + have bnd_xs: "xs ! x \ { lx .. ux }" using `bounded_by xs vs`[THEN bounded_byE, OF `x < length vs`] bnd_x by auto show ?thesis @@ -2995,28 +3006,28 @@ next case (Suc n') show ?thesis - proof (cases "xs ! x = real c") + proof (cases "xs ! x = c") case True from True[symmetric] hyp[OF bnd_xs] Suc show ?thesis unfolding F_def Suc setsum_head_upt_Suc[OF zero_less_Suc] setsum_shift_bounds_Suc_ivl by auto next case False - have "real lx \ real c" "real c \ real ux" "real lx \ xs!x" "xs!x \ real ux" + have "lx \ real c" "real c \ ux" "lx \ xs!x" "xs!x \ ux" using Suc bnd_c `bounded_by xs vs`[THEN bounded_byE, OF `x < length vs`] bnd_x by auto from Taylor.taylor[OF zero_less_Suc, of F, OF F0 DERIV[unfolded Suc] this False] - obtain t where t_bnd: "if xs ! x < real c then xs ! x < t \ t < real c else real c < t \ t < xs ! x" + obtain t::real where t_bnd: "if xs ! x < c then xs ! x < t \ t < c else c < t \ t < xs ! x" and fl_eq: "interpret_floatarith f (xs[x := xs ! x]) = - (\m = 0..m = 0.. {real lx .. real ux}" - by (cases "xs ! x < real c", auto) + from t_bnd bnd_xs bnd_c have *: "t \ {lx .. ux}" + by (cases "xs ! x < c", auto) have "interpret_floatarith f (xs[x := xs ! x]) = ?taylor t" unfolding fl_eq Suc by (auto simp add: algebra_simps divide_inverse) - also have "\ \ {real l .. real u}" using * by (rule hyp) + also have "\ \ {l .. u}" using * by (rule hyp) finally show ?thesis by simp qed qed @@ -3032,8 +3043,9 @@ approx_tse_form' prec t f s m u cmp else False))" lemma approx_tse_form': - assumes "approx_tse_form' prec t f s l u cmp" and "x \ {real l .. real u}" - shows "\ l' u' ly uy. x \ { real l' .. real u' } \ real l \ real l' \ real u' \ real u \ cmp ly uy \ + fixes x :: real + assumes "approx_tse_form' prec t f s l u cmp" and "x \ {l .. u}" + shows "\ l' u' ly uy. x \ { l' .. u' } \ real l \ l' \ u' \ real u \ cmp ly uy \ approx_tse prec 0 t ((l' + u') * Float 1 -1) 1 f [Some (l', u')] = Some (ly, uy)" using assms proof (induct s arbitrary: l u) case 0 @@ -3049,66 +3061,68 @@ and u: "approx_tse_form' prec t f s ?m u cmp" by (auto simp add: Let_def lazy_conj) - have m_l: "real l \ real ?m" and m_u: "real ?m \ real u" + have m_l: "real l \ ?m" and m_u: "?m \ real u" unfolding le_float_def using Suc.prems by auto - with `x \ { real l .. real u }` - have "x \ { real l .. real ?m} \ x \ { real ?m .. real u }" by auto + with `x \ { l .. u }` + have "x \ { l .. ?m} \ x \ { ?m .. u }" by auto thus ?case proof (rule disjE) - assume "x \ { real l .. real ?m}" + assume "x \ { l .. ?m}" from Suc.hyps[OF l this] obtain l' u' ly uy - where "x \ { real l' .. real u' } \ real l \ real l' \ real u' \ real ?m \ cmp ly uy \ + where "x \ { l' .. u' } \ real l \ l' \ real u' \ ?m \ cmp ly uy \ approx_tse prec 0 t ((l' + u') * Float 1 -1) 1 f [Some (l', u')] = Some (ly, uy)" by blast with m_u show ?thesis by (auto intro!: exI) next - assume "x \ { real ?m .. real u }" + assume "x \ { ?m .. u }" from Suc.hyps[OF u this] obtain l' u' ly uy - where "x \ { real l' .. real u' } \ real ?m \ real l' \ real u' \ real u \ cmp ly uy \ + where "x \ { l' .. u' } \ ?m \ real l' \ u' \ real u \ cmp ly uy \ approx_tse prec 0 t ((l' + u') * Float 1 -1) 1 f [Some (l', u')] = Some (ly, uy)" by blast with m_u show ?thesis by (auto intro!: exI) qed qed lemma approx_tse_form'_less: + fixes x :: real assumes tse: "approx_tse_form' prec t (Add a (Minus b)) s l u (\ l u. 0 < l)" - and x: "x \ {real l .. real u}" + and x: "x \ {l .. u}" shows "interpret_floatarith b [x] < interpret_floatarith a [x]" proof - from approx_tse_form'[OF tse x] obtain l' u' ly uy - where x': "x \ { real l' .. real u' }" and "real l \ real l'" - and "real u' \ real u" and "0 < ly" + where x': "x \ { l' .. u' }" and "l \ real l'" + and "real u' \ u" and "0 < ly" and tse: "approx_tse prec 0 t ((l' + u') * Float 1 -1) 1 (Add a (Minus b)) [Some (l', u')] = Some (ly, uy)" by blast hence "bounded_by [x] [Some (l', u')]" by (auto simp add: bounded_by_def) from approx_tse[OF this _ _ _ _ tse[symmetric], of l' u'] x' - have "real ly \ interpret_floatarith a [x] - interpret_floatarith b [x]" + have "ly \ interpret_floatarith a [x] - interpret_floatarith b [x]" by (auto simp add: diff_minus) from order_less_le_trans[OF `0 < ly`[unfolded less_float_def] this] show ?thesis by auto qed lemma approx_tse_form'_le: + fixes x :: real assumes tse: "approx_tse_form' prec t (Add a (Minus b)) s l u (\ l u. 0 \ l)" - and x: "x \ {real l .. real u}" + and x: "x \ {l .. u}" shows "interpret_floatarith b [x] \ interpret_floatarith a [x]" proof - from approx_tse_form'[OF tse x] obtain l' u' ly uy - where x': "x \ { real l' .. real u' }" and "real l \ real l'" - and "real u' \ real u" and "0 \ ly" + where x': "x \ { l' .. u' }" and "l \ real l'" + and "real u' \ u" and "0 \ ly" and tse: "approx_tse prec 0 t ((l' + u') * Float 1 -1) 1 (Add a (Minus b)) [Some (l', u')] = Some (ly, uy)" by blast hence "bounded_by [x] [Some (l', u')]" by (auto simp add: bounded_by_def) from approx_tse[OF this _ _ _ _ tse[symmetric], of l' u'] x' - have "real ly \ interpret_floatarith a [x] - interpret_floatarith b [x]" + have "ly \ interpret_floatarith a [x] - interpret_floatarith b [x]" by (auto simp add: diff_minus) from order_trans[OF `0 \ ly`[unfolded le_float_def] this] show ?thesis by auto @@ -3146,7 +3160,7 @@ { let "?f z" = "interpret_floatarith z [x]" assume "?f i \ { ?f a .. ?f b }" with approx[OF _ a[symmetric], of "[x]"] approx[OF _ b[symmetric], of "[x]"] - have bnd: "x \ { real l .. real u'}" unfolding bounded_by_def i by auto + have bnd: "x \ { l .. u'}" unfolding bounded_by_def i by auto have "interpret_form f' [x]" proof (cases f') @@ -3425,7 +3439,7 @@ | calculated_subterms (@{const HOL.implies} $ _ $ t) = calculated_subterms t | calculated_subterms (@{term "op <= :: real \ real \ bool"} $ t1 $ t2) = [t1, t2] | calculated_subterms (@{term "op < :: real \ real \ bool"} $ t1 $ t2) = [t1, t2] - | calculated_subterms (@{term "op : :: real \ real set \ bool"} $ t1 $ + | calculated_subterms (@{term "op : :: real \ real set \ bool"} $ t1 $ (@{term "atLeastAtMost :: real \ real \ real set"} $ t2 $ t3)) = [t1, t2, t3] | calculated_subterms t = raise TERM ("calculated_subterms", [t]) @@ -3552,3 +3566,4 @@ *} end + diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Borel_Space.thy --- a/src/HOL/Probability/Borel_Space.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Borel_Space.thy Thu Dec 02 16:39:15 2010 +0100 @@ -6,12 +6,6 @@ imports Sigma_Algebra Positive_Infinite_Real Multivariate_Analysis begin -lemma (in sigma_algebra) sets_sigma_subset: - assumes "space N = space M" - assumes "sets N \ sets M" - shows "sets (sigma N) \ sets M" - by (unfold assms sets_sigma, rule sigma_sets_subset, rule assms) - lemma LIMSEQ_max: "u ----> (x::real) \ (\i. max (u i) 0) ----> max x 0" by (fastsimp intro!: LIMSEQ_I dest!: LIMSEQ_D) @@ -612,13 +606,10 @@ then show ?thesis by (intro sets_sigma_subset) auto qed -lemma algebra_eqI: assumes "sets A = sets (B::'a algebra)" "space A = space B" - shows "A = B" using assms by auto - lemma borel_eq_atMost: "borel = (sigma \space=UNIV, sets=range (\ a. {.. a::'a\ordered_euclidean_space})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using halfspace_le_span_atMost halfspace_span_halfspace_le open_span_halfspace by auto @@ -629,7 +620,7 @@ lemma borel_eq_atLeastAtMost: "borel = (sigma \space=UNIV, sets=range (\ (a :: 'a\ordered_euclidean_space, b). {a .. b})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using atMost_span_atLeastAtMost halfspace_le_span_atMost halfspace_span_halfspace_le open_span_halfspace @@ -641,7 +632,7 @@ lemma borel_eq_greaterThan: "borel = (sigma \space=UNIV, sets=range (\ (a :: 'a\ordered_euclidean_space). {a <..})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using halfspace_le_span_greaterThan halfspace_span_halfspace_le open_span_halfspace @@ -653,7 +644,7 @@ lemma borel_eq_lessThan: "borel = (sigma \space=UNIV, sets=range (\ (a :: 'a\ordered_euclidean_space). {..< a})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using halfspace_le_span_lessThan halfspace_span_halfspace_ge open_span_halfspace @@ -665,7 +656,7 @@ lemma borel_eq_greaterThanLessThan: "borel = (sigma \space=UNIV, sets=range (\ (a, b). {a <..< (b :: 'a \ ordered_euclidean_space)})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets ?SIGMA \ sets borel" by (rule borel.sets_sigma_subset) auto show "sets borel \ sets ?SIGMA" @@ -686,7 +677,7 @@ lemma borel_eq_halfspace_le: "borel = (sigma \space=UNIV, sets=range (\ (a, i). {x::'a::ordered_euclidean_space. x$$i \ a})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using open_span_halfspace halfspace_span_halfspace_le by auto show "sets ?SIGMA \ sets borel" @@ -696,7 +687,7 @@ lemma borel_eq_halfspace_less: "borel = (sigma \space=UNIV, sets=range (\ (a, i). {x::'a::ordered_euclidean_space. x$$i < a})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using open_span_halfspace . show "sets ?SIGMA \ sets borel" @@ -706,7 +697,7 @@ lemma borel_eq_halfspace_gt: "borel = (sigma \space=UNIV, sets=range (\ (a, i). {x::'a::ordered_euclidean_space. a < x$$i})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using halfspace_le_span_halfspace_gt open_span_halfspace halfspace_span_halfspace_le by auto show "sets ?SIGMA \ sets borel" @@ -716,7 +707,7 @@ lemma borel_eq_halfspace_ge: "borel = (sigma \space=UNIV, sets=range (\ (a, i). {x::'a::ordered_euclidean_space. a \ x$$i})\)" (is "_ = ?SIGMA") -proof (rule algebra_eqI, rule antisym) +proof (intro algebra.equality antisym) show "sets borel \ sets ?SIGMA" using halfspace_span_halfspace_ge open_span_halfspace by auto show "sets ?SIGMA \ sets borel" @@ -1025,7 +1016,6 @@ then obtain T x where T: "open T" "Real ` (T \ {0..}) = B - {\}" and x: "\ \ B \ 0 \ x" "\ \ B \ {Real x <..} \ B" unfolding open_pinfreal_def by blast - have "Real -` B = Real -` (B - {\})" by auto also have "\ = Real -` (Real ` (T \ {0..}))" using T by simp also have "\ = (if 0 \ T then T \ {.. 0} else T \ {0..})" @@ -1231,12 +1221,10 @@ hence **: "\a. {x\space M. f x < a} \ sets M" unfolding less_eq_le_pinfreal_measurable unfolding greater_eq_le_measurable . - show "f \ borel_measurable M" unfolding borel_measurable_pinfreal_eq_real borel_measurable_iff_greater proof safe have "f -` {\} \ space M = space M - {x\space M. f x < \}" by auto then show \: "f -` {\} \ space M \ sets M" using ** by auto - fix a have "{w \ space M. a < real (f w)} = (if 0 \ a then {w\space M. Real a < f w} - (f -` {\} \ space M) else space M)" @@ -1367,14 +1355,14 @@ by induct auto qed (simp add: borel_measurable_const) -lemma (in sigma_algebra) borel_measurable_pinfreal_min[intro, simp]: +lemma (in sigma_algebra) borel_measurable_pinfreal_min[simp, intro]: fixes f g :: "'a \ pinfreal" assumes "f \ borel_measurable M" assumes "g \ borel_measurable M" shows "(\x. min (g x) (f x)) \ borel_measurable M" using assms unfolding min_def by (auto intro!: measurable_If) -lemma (in sigma_algebra) borel_measurable_pinfreal_max[intro]: +lemma (in sigma_algebra) borel_measurable_pinfreal_max[simp, intro]: fixes f g :: "'a \ pinfreal" assumes "f \ borel_measurable M" and "g \ borel_measurable M" @@ -1421,7 +1409,7 @@ using assms by auto qed -lemma (in sigma_algebra) borel_measurable_psuminf: +lemma (in sigma_algebra) borel_measurable_psuminf[simp, intro]: assumes "\i. f i \ borel_measurable M" shows "(\x. (\\<^isub>\ i. f i x)) \ borel_measurable M" using assms unfolding psuminf_def @@ -1437,7 +1425,6 @@ proof - let "?pu x i" = "max (u i x) 0" let "?nu x i" = "max (- u i x) 0" - { fix x assume x: "x \ space M" have "(?pu x) ----> max (u' x) 0" "(?nu x) ----> max (- u' x) 0" @@ -1447,10 +1434,8 @@ "(SUP n. INF m. Real (- u (n + m) x)) = Real (- u' x)" by (simp_all add: Real_max'[symmetric]) } note eq = this - have *: "\x. real (Real (u' x)) - real (Real (- u' x)) = u' x" by auto - have "(SUP n. INF m. (\x. Real (u (n + m) x))) \ borel_measurable M" "(SUP n. INF m. (\x. Real (- u (n + m) x))) \ borel_measurable M" using u by (auto intro: borel_measurable_SUP borel_measurable_INF borel_measurable_Real) diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Complete_Measure.thy --- a/src/HOL/Probability/Complete_Measure.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Complete_Measure.thy Thu Dec 02 16:39:15 2010 +0100 @@ -189,56 +189,13 @@ qed qed -lemma (in sigma_algebra) simple_functionD': - assumes "simple_function f" - shows "f -` {x} \ space M \ sets M" -proof cases - assume "x \ f`space M" from simple_functionD(2)[OF assms this] show ?thesis . -next - assume "x \ f`space M" then have "f -` {x} \ space M = {}" by auto - then show ?thesis by auto -qed - -lemma (in sigma_algebra) simple_function_If: - assumes sf: "simple_function f" "simple_function g" and A: "A \ sets M" - shows "simple_function (\x. if x \ A then f x else g x)" (is "simple_function ?IF") -proof - - def F \ "\x. f -` {x} \ space M" and G \ "\x. g -` {x} \ space M" - show ?thesis unfolding simple_function_def - proof safe - have "?IF ` space M \ f ` space M \ g ` space M" by auto - from finite_subset[OF this] assms - show "finite (?IF ` space M)" unfolding simple_function_def by auto - next - fix x assume "x \ space M" - then have *: "?IF -` {?IF x} \ space M = (if x \ A - then ((F (f x) \ A) \ (G (f x) - (G (f x) \ A))) - else ((F (g x) \ A) \ (G (g x) - (G (g x) \ A))))" - using sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def) - have [intro]: "\x. F x \ sets M" "\x. G x \ sets M" - unfolding F_def G_def using sf[THEN simple_functionD'] by auto - show "?IF -` {?IF x} \ space M \ sets M" unfolding * using A by auto - qed -qed - -lemma (in measure_space) null_sets_finite_UN: - assumes "finite S" "\i. i \ S \ A i \ null_sets" - shows "(\i\S. A i) \ null_sets" -proof (intro CollectI conjI) - show "(\i\S. A i) \ sets M" using assms by (intro finite_UN) auto - have "\ (\i\S. A i) \ (\i\S. \ (A i))" - using assms by (intro measure_finitely_subadditive) auto - then show "\ (\i\S. A i) = 0" - using assms by auto -qed - lemma (in completeable_measure_space) completion_ex_simple_function: assumes f: "completion.simple_function f" shows "\f'. simple_function f' \ (AE x. f x = f' x)" proof - let "?F x" = "f -` {x} \ space M" have F: "\x. ?F x \ sets completion" and fin: "finite (f`space M)" - using completion.simple_functionD'[OF f] + using completion.simple_functionD[OF f] completion.simple_functionD[OF f] by simp_all have "\x. \N. N \ null_sets \ null_part (?F x) \ N" using F null_part by auto diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Lebesgue_Integration.thy --- a/src/HOL/Probability/Lebesgue_Integration.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Lebesgue_Integration.thy Thu Dec 02 16:39:15 2010 +0100 @@ -6,20 +6,6 @@ imports Measure Borel_Space begin -lemma image_set_cong: - assumes A: "\x. x \ A \ \y\B. f x = g y" - assumes B: "\y. y \ B \ \x\A. g y = f x" - shows "f ` A = g ` B" -proof safe - fix x assume "x \ A" - with A obtain y where "f x = g y" "y \ B" by auto - then show "f x \ g ` B" by auto -next - fix y assume "y \ B" - with B obtain x where "g y = f x" "x \ A" by auto - then show "g y \ f ` A" by auto -qed - lemma sums_If_finite: assumes finite: "finite {r. P r}" shows "(\r. if P r then f r else 0) sums (\r\{r. P r}. f r)" (is "?F sums _") @@ -57,9 +43,15 @@ lemma (in sigma_algebra) simple_functionD: assumes "simple_function g" - shows "finite (g ` space M)" - "x \ g ` space M \ g -` {x} \ space M \ sets M" - using assms unfolding simple_function_def by auto + shows "finite (g ` space M)" and "g -` X \ space M \ sets M" +proof - + show "finite (g ` space M)" + using assms unfolding simple_function_def by auto + have "g -` X \ space M = g -` (X \ g`space M) \ space M" by auto + also have "\ = (\x\X \ g`space M. g-`{x} \ space M)" by auto + finally show "g -` X \ space M \ sets M" using assms + by (auto intro!: finite_UN simp del: UN_simps simp: simple_function_def) +qed lemma (in sigma_algebra) simple_function_indicator_representation: fixes f ::"'a \ pinfreal" @@ -516,9 +508,7 @@ proof - interpret v: measure_space M \ by (rule measure_space_cong) fact - have "\x. x \ space M \ f -` {f x} \ space M \ sets M" - using `simple_function f`[THEN simple_functionD(2)] by auto - with assms show ?thesis + from simple_functionD[OF `simple_function f`] assms show ?thesis unfolding simple_integral_def v.simple_integral_def by (auto intro!: setsum_cong) qed @@ -629,6 +619,28 @@ by (auto simp: setsum_right_distrib field_simps intro!: setsum_cong) qed +lemma (in sigma_algebra) simple_function_If: + assumes sf: "simple_function f" "simple_function g" and A: "A \ sets M" + shows "simple_function (\x. if x \ A then f x else g x)" (is "simple_function ?IF") +proof - + def F \ "\x. f -` {x} \ space M" and G \ "\x. g -` {x} \ space M" + show ?thesis unfolding simple_function_def + proof safe + have "?IF ` space M \ f ` space M \ g ` space M" by auto + from finite_subset[OF this] assms + show "finite (?IF ` space M)" unfolding simple_function_def by auto + next + fix x assume "x \ space M" + then have *: "?IF -` {?IF x} \ space M = (if x \ A + then ((F (f x) \ A) \ (G (f x) - (G (f x) \ A))) + else ((F (g x) \ A) \ (G (g x) - (G (g x) \ A))))" + using sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def) + have [intro]: "\x. F x \ sets M" "\x. G x \ sets M" + unfolding F_def G_def using sf[THEN simple_functionD(2)] by auto + show "?IF -` {?IF x} \ space M \ sets M" unfolding * using A by auto + qed +qed + lemma (in measure_space) simple_integral_mono_AE: assumes "simple_function f" and "simple_function g" and mono: "AE x. f x \ g x" @@ -652,8 +664,8 @@ obtain N where N: "{x\space M. \ f x \ g x} \ N" "N \ sets M" "\ N = 0" using mono by (auto elim!: AE_E) have "?S x \ N" using N `x \ space M` False by auto - moreover have "?S x \ sets M" using assms `x \ space M` - by (rule_tac Int) (auto intro!: simple_functionD(2)) + moreover have "?S x \ sets M" using assms + by (rule_tac Int) (auto intro!: simple_functionD) ultimately have "\ (?S x) \ \ N" using `N \ sets M` by (auto intro!: measure_mono) then show ?thesis using `\ N = 0` by auto @@ -831,8 +843,67 @@ section "Continuous posititve integration" definition (in measure_space) + "positive_integral f = SUPR {g. simple_function g \ g \ f} simple_integral" + +lemma (in measure_space) positive_integral_alt: "positive_integral f = - (SUP g : {g. simple_function g \ g \ f \ \ \ g`space M}. simple_integral g)" + (SUPR {g. simple_function g \ g \ f \ \ \ g`space M} simple_integral)" (is "_ = ?alt") +proof (rule antisym SUP_leI) + show "positive_integral f \ ?alt" unfolding positive_integral_def + proof (safe intro!: SUP_leI) + fix g assume g: "simple_function g" "g \ f" + let ?G = "g -` {\} \ space M" + show "simple_integral g \ + SUPR {g. simple_function g \ g \ f \ \ \ g ` space M} simple_integral" + (is "simple_integral g \ SUPR ?A simple_integral") + proof cases + let ?g = "\x. indicator (space M - ?G) x * g x" + have g': "simple_function ?g" + using g by (auto intro: simple_functionD) + moreover + assume "\ ?G = 0" + then have "AE x. g x = ?g x" using g + by (intro AE_I[where N="?G"]) + (auto intro: simple_functionD simp: indicator_def) + with g(1) g' have "simple_integral g = simple_integral ?g" + by (rule simple_integral_cong_AE) + moreover have "?g \ g" by (auto simp: le_fun_def indicator_def) + from this `g \ f` have "?g \ f" by (rule order_trans) + moreover have "\ \ ?g ` space M" + by (auto simp: indicator_def split: split_if_asm) + ultimately show ?thesis by (auto intro!: le_SUPI) + next + assume "\ ?G \ 0" + then have "?G \ {}" by auto + then have "\ \ g`space M" by force + then have "space M \ {}" by auto + have "SUPR ?A simple_integral = \" + proof (intro SUP_\[THEN iffD2] allI impI) + fix x assume "x < \" + then guess n unfolding less_\_Ex_of_nat .. note n = this + then have "0 < n" by (intro neq0_conv[THEN iffD1] notI) simp + let ?g = "\x. (of_nat n / (if \ ?G = \ then 1 else \ ?G)) * indicator ?G x" + show "\i\?A. x < simple_integral i" + proof (intro bexI impI CollectI conjI) + show "simple_function ?g" using g + by (auto intro!: simple_functionD simple_function_add) + have "?g \ g" by (auto simp: le_fun_def indicator_def) + from this g(2) show "?g \ f" by (rule order_trans) + show "\ \ ?g ` space M" + using `\ ?G \ 0` by (auto simp: indicator_def split: split_if_asm) + have "x < (of_nat n / (if \ ?G = \ then 1 else \ ?G)) * \ ?G" + using n `\ ?G \ 0` `0 < n` + by (auto simp: pinfreal_noteq_omega_Ex field_simps) + also have "\ = simple_integral ?g" using g `space M \ {}` + by (subst simple_integral_indicator) + (auto simp: image_constant ac_simps dest: simple_functionD) + finally show "x < simple_integral ?g" . + qed + qed + then show ?thesis by simp + qed + qed +qed (auto intro!: SUP_subset simp: positive_integral_def) lemma (in measure_space) positive_integral_cong_measure: assumes "\A. A \ sets M \ \ A = \ A" @@ -849,7 +920,7 @@ lemma (in measure_space) positive_integral_alt1: "positive_integral f = (SUP g : {g. simple_function g \ (\x\space M. g x \ f x \ g x \ \)}. simple_integral g)" - unfolding positive_integral_def SUPR_def + unfolding positive_integral_alt SUPR_def proof (safe intro!: arg_cong[where f=Sup]) fix g let ?g = "\x. if x \ space M then g x else f x" assume "simple_function g" "\x\space M. g x \ f x \ g x \ \" @@ -866,75 +937,6 @@ by auto qed -lemma (in measure_space) positive_integral_alt: - "positive_integral f = - (SUP g : {g. simple_function g \ g \ f}. simple_integral g)" - apply(rule order_class.antisym) unfolding positive_integral_def - apply(rule SUPR_subset) apply blast apply(rule SUPR_mono_lim) -proof safe fix u assume u:"simple_function u" and uf:"u \ f" - let ?u = "\n x. if u x = \ then Real (real (n::nat)) else u x" - have su:"\n. simple_function (?u n)" using simple_function_compose1[OF u] . - show "\b. \n. b n \ {g. simple_function g \ g \ f \ \ \ g ` space M} \ - (\n. simple_integral (b n)) ----> simple_integral u" - apply(rule_tac x="?u" in exI, safe) apply(rule su) - proof- fix n::nat have "?u n \ u" unfolding le_fun_def by auto - also note uf finally show "?u n \ f" . - let ?s = "{x \ space M. u x = \}" - show "(\n. simple_integral (?u n)) ----> simple_integral u" - proof(cases "\ ?s = 0") - case True have *:"\n. {x\space M. ?u n x \ u x} = {x\space M. u x = \}" by auto - have *:"\n. simple_integral (?u n) = simple_integral u" - apply(rule simple_integral_cong'[OF su u]) unfolding * True .. - show ?thesis unfolding * by auto - next case False note m0=this - have s:"{x \ space M. u x = \} \ sets M" using u by (auto simp: borel_measurable_simple_function) - have "\ = simple_integral (\x. \ * indicator {x\space M. u x = \} x)" - apply(subst simple_integral_mult) using s - unfolding simple_integral_indicator_only[OF s] using False by auto - also have "... \ simple_integral u" - apply (rule simple_integral_mono) - apply (rule simple_function_mult) - apply (rule simple_function_const) - apply(rule ) prefer 3 apply(subst indicator_def) - using s u by auto - finally have *:"simple_integral u = \" by auto - show ?thesis unfolding * Lim_omega_pos - proof safe case goal1 - from real_arch_simple[of "B / real (\ ?s)"] guess N0 .. note N=this - def N \ "Suc N0" have N:"real N \ B / real (\ ?s)" "N > 0" - unfolding N_def using N by auto - show ?case apply-apply(rule_tac x=N in exI,safe) - proof- case goal1 - have "Real B \ Real (real N) * \ ?s" - proof(cases "\ ?s = \") - case True thus ?thesis using `B>0` N by auto - next case False - have *:"B \ real N * real (\ ?s)" - using N(1) apply-apply(subst (asm) pos_divide_le_eq) - apply rule using m0 False by auto - show ?thesis apply(subst Real_real'[THEN sym,OF False]) - apply(subst pinfreal_times,subst if_P) defer - apply(subst pinfreal_less_eq,subst if_P) defer - using * N `B>0` by(auto intro: mult_nonneg_nonneg) - qed - also have "... \ Real (real n) * \ ?s" - apply(rule mult_right_mono) using goal1 by auto - also have "... = simple_integral (\x. Real (real n) * indicator ?s x)" - apply(subst simple_integral_mult) apply(rule simple_function_indicator[OF s]) - unfolding simple_integral_indicator_only[OF s] .. - also have "... \ simple_integral (\x. if u x = \ then Real (real n) else u x)" - apply(rule simple_integral_mono) apply(rule simple_function_mult) - apply(rule simple_function_const) - apply(rule simple_function_indicator) apply(rule s su)+ by auto - finally show ?case . - qed qed qed - fix x assume x:"\ = (if u x = \ then Real (real n) else u x)" "x \ space M" - hence "u x = \" apply-apply(rule ccontr) by auto - hence "\ = Real (real n)" using x by auto - thus False by auto - qed -qed - lemma (in measure_space) positive_integral_cong: assumes "\x. x \ space M \ f x = g x" shows "positive_integral f = positive_integral g" @@ -947,7 +949,7 @@ lemma (in measure_space) positive_integral_eq_simple_integral: assumes "simple_function f" shows "positive_integral f = simple_integral f" - unfolding positive_integral_alt + unfolding positive_integral_def proof (safe intro!: pinfreal_SUPI) fix g assume "simple_function g" "g \ f" with assms show "simple_integral g \ simple_integral f" @@ -1008,6 +1010,12 @@ shows "positive_integral u \ positive_integral v" using mono by (auto intro!: AE_cong positive_integral_mono_AE) +lemma image_set_cong: + assumes A: "\x. x \ A \ \y\B. f x = g y" + assumes B: "\y. y \ B \ \x\A. g y = f x" + shows "f ` A = g ` B" + using assms by blast + lemma (in measure_space) positive_integral_vimage: fixes g :: "'a \ pinfreal" and f :: "'d \ 'a" assumes f: "bij_betw f S (space M)" @@ -1020,14 +1028,12 @@ from assms have inv: "bij_betw (the_inv_into S f) (space M) S" by (rule bij_betw_the_inv_into) then have inv_fun: "the_inv_into S f \ space M \ S" unfolding bij_betw_def by auto - have surj: "f`S = space M" using f unfolding bij_betw_def by simp have inj: "inj_on f S" using f unfolding bij_betw_def by simp have inv_f: "\x. x \ space M \ f (the_inv_into S f x) = x" using f_the_inv_into_f[of f S] f unfolding bij_betw_def by auto - from simple_integral_vimage[OF assms, symmetric] have *: "simple_integral = T.simple_integral \ (\g. g \ f)" by (simp add: comp_def) show ?thesis @@ -1181,7 +1187,7 @@ by (auto intro!: SUP_leI positive_integral_mono) next show "positive_integral u \ (SUP i. positive_integral (f i))" - unfolding positive_integral_def[of u] + unfolding positive_integral_alt[of u] by (auto intro!: SUP_leI positive_integral_SUP_approx[OF assms]) qed qed @@ -1194,7 +1200,6 @@ proof - have "?u \ borel_measurable M" using borel_measurable_SUP[of _ f] assms by (simp add: SUPR_fun_expand) - show ?thesis proof (rule antisym) show "(SUP j. positive_integral (f j)) \ positive_integral ?u" @@ -1205,9 +1210,10 @@ using assms by (simp cong: measurable_cong) moreover have iso: "rf \ ru" using assms unfolding rf_def ru_def unfolding isoton_def SUPR_fun_expand le_fun_def fun_eq_iff + using SUP_const[OF UNIV_not_empty] by (auto simp: restrict_def le_fun_def SUPR_fun_expand fun_eq_iff) ultimately have "positive_integral ru \ (SUP i. positive_integral (rf i))" - unfolding positive_integral_def[of ru] + unfolding positive_integral_alt[of ru] by (auto simp: le_fun_def intro!: SUP_leI positive_integral_SUP_approx) then show "positive_integral ?u \ (SUP i. positive_integral (f i))" unfolding ru_def rf_def by (simp cong: positive_integral_cong) @@ -1523,19 +1529,18 @@ apply (rule arg_cong[where f=Sup]) proof (auto simp add: image_iff simple_integral_restricted[OF `A \ sets M`]) fix g assume "simple_function (\x. g x * indicator A x)" - "g \ f" "\x\A. \ \ g x" - then show "\x. simple_function x \ x \ (\x. f x * indicator A x) \ (\y\space M. \ \ x y) \ + "g \ f" + then show "\x. simple_function x \ x \ (\x. f x * indicator A x) \ simple_integral (\x. g x * indicator A x) = simple_integral x" apply (rule_tac exI[of _ "\x. g x * indicator A x"]) by (auto simp: indicator_def le_fun_def) next fix g assume g: "simple_function g" "g \ (\x. f x * indicator A x)" - "\x\space M. \ \ g x" then have *: "(\x. g x * indicator A x) = g" "\x. g x * indicator A x = g x" "\x. g x \ f x" by (auto simp: le_fun_def fun_eq_iff indicator_def split: split_if_asm) - from g show "\x. simple_function (\xa. x xa * indicator A xa) \ x \ f \ (\xa\A. \ \ x xa) \ + from g show "\x. simple_function (\xa. x xa * indicator A xa) \ x \ f \ simple_integral g = simple_integral (\xa. x xa * indicator A xa)" using `A \ sets M`[THEN sets_into_space] apply (rule_tac exI[of _ "\x. g x * indicator A x"]) @@ -2299,7 +2304,7 @@ qed lemma (in finite_measure_space) simple_function_finite[simp, intro]: "simple_function f" - unfolding simple_function_def sets_eq_Pow using finite_space by auto + unfolding simple_function_def using finite_space by auto lemma (in finite_measure_space) borel_measurable_finite[intro, simp]: "f \ borel_measurable M" by (auto intro: borel_measurable_simple_function) @@ -2310,7 +2315,7 @@ have *: "positive_integral f = positive_integral (\x. \y\space M. f y * indicator {y} x)" by (auto intro!: positive_integral_cong simp add: indicator_def if_distrib setsum_cases[OF finite_space]) show ?thesis unfolding * using borel_measurable_finite[of f] - by (simp add: positive_integral_setsum positive_integral_cmult_indicator sets_eq_Pow) + by (simp add: positive_integral_setsum positive_integral_cmult_indicator) qed lemma (in finite_measure_space) integral_finite_singleton: @@ -2322,9 +2327,9 @@ "positive_integral (\x. Real (- f x)) = (\x \ space M. Real (- f x) * \ {x})" unfolding positive_integral_finite_eq_setsum by auto show "integrable f" using finite_space finite_measure - by (simp add: setsum_\ integrable_def sets_eq_Pow) + by (simp add: setsum_\ integrable_def) show ?I using finite_measure - apply (simp add: integral_def sets_eq_Pow real_of_pinfreal_setsum[symmetric] + apply (simp add: integral_def real_of_pinfreal_setsum[symmetric] real_of_pinfreal_mult[symmetric] setsum_subtractf[symmetric]) by (rule setsum_cong) (simp_all split: split_if) qed diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Lebesgue_Measure.thy --- a/src/HOL/Probability/Lebesgue_Measure.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Lebesgue_Measure.thy Thu Dec 02 16:39:15 2010 +0100 @@ -4,89 +4,6 @@ imports Product_Measure Gauge_Measure Complete_Measure begin -lemma (in complete_lattice) SUP_pair: - "(SUP i:A. SUP j:B. f i j) = (SUP p:A\B. (\ (i, j). f i j) p)" (is "?l = ?r") -proof (intro antisym SUP_leI) - fix i j assume "i \ A" "j \ B" - then have "(case (i,j) of (i,j) \ f i j) \ ?r" - by (intro SUPR_upper) auto - then show "f i j \ ?r" by auto -next - fix p assume "p \ A \ B" - then obtain i j where "p = (i,j)" "i \ A" "j \ B" by auto - have "f i j \ (SUP j:B. f i j)" using `j \ B` by (intro SUPR_upper) - also have "(SUP j:B. f i j) \ ?l" using `i \ A` by (intro SUPR_upper) - finally show "(case p of (i, j) \ f i j) \ ?l" using `p = (i,j)` by simp -qed - -lemma (in complete_lattice) SUP_surj_compose: - assumes *: "f`A = B" shows "SUPR A (g \ f) = SUPR B g" - unfolding SUPR_def unfolding *[symmetric] - by (simp add: image_compose) - -lemma (in complete_lattice) SUP_swap: - "(SUP i:A. SUP j:B. f i j) = (SUP j:B. SUP i:A. f i j)" -proof - - have *: "(\(i,j). (j,i)) ` (B \ A) = A \ B" by auto - show ?thesis - unfolding SUP_pair SUP_surj_compose[symmetric, OF *] - by (auto intro!: arg_cong[where f=Sup] image_eqI simp: comp_def SUPR_def) -qed - -lemma SUP_\: "(SUP i:A. f i) = \ \ (\x<\. \i\A. x < f i)" -proof - assume *: "(SUP i:A. f i) = \" - show "(\x<\. \i\A. x < f i)" unfolding *[symmetric] - proof (intro allI impI) - fix x assume "x < SUPR A f" then show "\i\A. x < f i" - unfolding less_SUP_iff by auto - qed -next - assume *: "\x<\. \i\A. x < f i" - show "(SUP i:A. f i) = \" - proof (rule pinfreal_SUPI) - fix y assume **: "\i. i \ A \ f i \ y" - show "\ \ y" - proof cases - assume "y < \" - from *[THEN spec, THEN mp, OF this] - obtain i where "i \ A" "\ (f i \ y)" by auto - with ** show ?thesis by auto - qed auto - qed auto -qed - -lemma psuminf_commute: - shows "(\\<^isub>\ i j. f i j) = (\\<^isub>\ j i. f i j)" -proof - - have "(SUP n. \ i < n. SUP m. \ j < m. f i j) = (SUP n. SUP m. \ i < n. \ j < m. f i j)" - apply (subst SUPR_pinfreal_setsum) - by auto - also have "\ = (SUP m n. \ j < m. \ i < n. f i j)" - apply (subst SUP_swap) - apply (subst setsum_commute) - by auto - also have "\ = (SUP m. \ j < m. SUP n. \ i < n. f i j)" - apply (subst SUPR_pinfreal_setsum) - by auto - finally show ?thesis - unfolding psuminf_def by auto -qed - -lemma psuminf_SUP_eq: - assumes "\n i. f n i \ f (Suc n) i" - shows "(\\<^isub>\ i. SUP n::nat. f n i) = (SUP n::nat. \\<^isub>\ i. f n i)" -proof - - { fix n :: nat - have "(\ii 'a::ordered_euclidean_space set" where @@ -838,20 +755,6 @@ qed qed -lemma Real_mult_nonneg: assumes "x \ 0" "y \ 0" - shows "Real (x * y) = Real x * Real y" using assms by auto - -lemma Real_setprod: assumes "\x\A. f x \ 0" shows "Real (setprod f A) = setprod (\x. Real (f x)) A" -proof(cases "finite A") - case True thus ?thesis using assms - proof(induct A) case (insert x A) - have "0 \ setprod f A" apply(rule setprod_nonneg) using insert by auto - thus ?case unfolding setprod_insert[OF insert(1-2)] apply- - apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym]) - using insert by auto - qed auto -qed auto - lemma e2p_Int:"e2p ` A \ e2p ` B = e2p ` (A \ B)" (is "?L = ?R") apply(rule image_Int[THEN sym]) using bij_euclidean_component unfolding bij_betw_def by auto diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Measure.thy --- a/src/HOL/Probability/Measure.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Measure.thy Thu Dec 02 16:39:15 2010 +0100 @@ -651,27 +651,6 @@ abbreviation (in measure_space) "null_sets \ {N\sets M. \ N = 0}" -definition (in measure_space) - almost_everywhere :: "('a \ bool) \ bool" (binder "AE " 10) where - "almost_everywhere P \ (\N\null_sets. { x \ space M. \ P x } \ N)" - -lemma (in measure_space) AE_I': - "N \ null_sets \ {x\space M. \ P x} \ N \ (AE x. P x)" - unfolding almost_everywhere_def by auto - -lemma (in measure_space) AE_iff_null_set: - assumes "{x\space M. \ P x} \ sets M" (is "?P \ sets M") - shows "(AE x. P x) \ {x\space M. \ P x} \ null_sets" -proof - assume "AE x. P x" then obtain N where N: "N \ sets M" "?P \ N" "\ N = 0" - unfolding almost_everywhere_def by auto - moreover have "\ ?P \ \ N" - using assms N(1,2) by (auto intro: measure_mono) - ultimately show "?P \ null_sets" using assms by auto -next - assume "?P \ null_sets" with assms show "AE x. P x" by (auto intro: AE_I') -qed - lemma (in measure_space) null_sets_Un[intro]: assumes "N \ null_sets" "N' \ null_sets" shows "N \ N' \ null_sets" @@ -703,6 +682,17 @@ using assms by auto qed +lemma (in measure_space) null_sets_finite_UN: + assumes "finite S" "\i. i \ S \ A i \ null_sets" + shows "(\i\S. A i) \ null_sets" +proof (intro CollectI conjI) + show "(\i\S. A i) \ sets M" using assms by (intro finite_UN) auto + have "\ (\i\S. A i) \ (\i\S. \ (A i))" + using assms by (intro measure_finitely_subadditive) auto + then show "\ (\i\S. A i) = 0" + using assms by auto +qed + lemma (in measure_space) null_set_Int1: assumes "B \ null_sets" "A \ sets M" shows "A \ B \ null_sets" using assms proof (intro CollectI conjI) @@ -741,6 +731,29 @@ by (subst measure_additive[symmetric]) auto qed +section "Formalise almost everywhere" + +definition (in measure_space) + almost_everywhere :: "('a \ bool) \ bool" (binder "AE " 10) where + "almost_everywhere P \ (\N\null_sets. { x \ space M. \ P x } \ N)" + +lemma (in measure_space) AE_I': + "N \ null_sets \ {x\space M. \ P x} \ N \ (AE x. P x)" + unfolding almost_everywhere_def by auto + +lemma (in measure_space) AE_iff_null_set: + assumes "{x\space M. \ P x} \ sets M" (is "?P \ sets M") + shows "(AE x. P x) \ {x\space M. \ P x} \ null_sets" +proof + assume "AE x. P x" then obtain N where N: "N \ sets M" "?P \ N" "\ N = 0" + unfolding almost_everywhere_def by auto + moreover have "\ ?P \ \ N" + using assms N(1,2) by (auto intro: measure_mono) + ultimately show "?P \ null_sets" using assms by auto +next + assume "?P \ null_sets" with assms show "AE x. P x" by (auto intro: AE_I') +qed + lemma (in measure_space) AE_True[intro, simp]: "AE x. True" unfolding almost_everywhere_def by auto @@ -1409,7 +1422,7 @@ show "\ {x} \ \" by (auto simp: insert_absorb[OF *] Diff_subset) } qed -sublocale finite_measure_space < finite_measure +sublocale finite_measure_space \ finite_measure proof show "\ (space M) \ \" unfolding sum_over_space[symmetric] setsum_\ diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Positive_Infinite_Real.thy --- a/src/HOL/Probability/Positive_Infinite_Real.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Positive_Infinite_Real.thy Thu Dec 02 16:39:15 2010 +0100 @@ -6,14 +6,6 @@ imports Complex_Main Nat_Bijection Multivariate_Analysis begin -lemma range_const[simp]: "range (\x. c) = {c}" by auto - -lemma (in complete_lattice) SUPR_const[simp]: "(SUP i. c) = c" - unfolding SUPR_def by simp - -lemma (in complete_lattice) INFI_const[simp]: "(INF i. c) = c" - unfolding INFI_def by simp - lemma (in complete_lattice) Sup_start: assumes *: "\x. f x \ f 0" shows "(SUP n. f n) = f 0" @@ -94,6 +86,26 @@ ultimately show ?thesis by simp qed +lemma (in complete_lattice) lim_INF_le_lim_SUP: + fixes f :: "nat \ 'a" + shows "(SUP n. INF m. f (n + m)) \ (INF n. SUP m. f (n + m))" +proof (rule SUP_leI, rule le_INFI) + fix i j show "(INF m. f (i + m)) \ (SUP m. f (j + m))" + proof (cases rule: le_cases) + assume "i \ j" + have "(INF m. f (i + m)) \ f (i + (j - i))" by (rule INF_leI) simp + also have "\ = f (j + 0)" using `i \ j` by auto + also have "\ \ (SUP m. f (j + m))" by (rule le_SUPI) simp + finally show ?thesis . + next + assume "j \ i" + have "(INF m. f (i + m)) \ f (i + 0)" by (rule INF_leI) simp + also have "\ = f (j + (i - j))" using `j \ i` by auto + also have "\ \ (SUP m. f (j + m))" by (rule le_SUPI) simp + finally show ?thesis . + qed +qed + text {* We introduce the the positive real numbers as needed for measure theory. @@ -348,6 +360,20 @@ lemma real_of_pinfreal_mult: "real X * real Y = real (X * Y :: pinfreal)" by (cases X, cases Y) (auto simp: zero_le_mult_iff) +lemma Real_mult_nonneg: assumes "x \ 0" "y \ 0" + shows "Real (x * y) = Real x * Real y" using assms by auto + +lemma Real_setprod: assumes "\x\A. f x \ 0" shows "Real (setprod f A) = setprod (\x. Real (f x)) A" +proof(cases "finite A") + case True thus ?thesis using assms + proof(induct A) case (insert x A) + have "0 \ setprod f A" apply(rule setprod_nonneg) using insert by auto + thus ?case unfolding setprod_insert[OF insert(1-2)] apply- + apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym]) + using insert by auto + qed auto +qed auto + subsection "@{typ pinfreal} is a linear order" instantiation pinfreal :: linorder @@ -549,6 +575,14 @@ lemma pinfreal_of_nat[simp]: "of_nat m = Real (real m)" by (induct m) (auto simp: real_of_nat_Suc one_pinfreal_def simp del: Real_1) +lemma less_\_Ex_of_nat: "x < \ \ (\n. x < of_nat n)" +proof safe + assume "x < \" + then obtain r where "0 \ r" "x = Real r" by (cases x) auto + moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto + ultimately show "\n. x < of_nat n" by (auto simp: real_eq_of_nat) +qed auto + lemma real_of_pinfreal_mono: fixes a b :: pinfreal assumes "b \ \" "a \ b" @@ -831,6 +865,29 @@ qed simp qed simp +lemma SUP_\: "(SUP i:A. f i) = \ \ (\x<\. \i\A. x < f i)" +proof + assume *: "(SUP i:A. f i) = \" + show "(\x<\. \i\A. x < f i)" unfolding *[symmetric] + proof (intro allI impI) + fix x assume "x < SUPR A f" then show "\i\A. x < f i" + unfolding less_SUP_iff by auto + qed +next + assume *: "\x<\. \i\A. x < f i" + show "(SUP i:A. f i) = \" + proof (rule pinfreal_SUPI) + fix y assume **: "\i. i \ A \ f i \ y" + show "\ \ y" + proof cases + assume "y < \" + from *[THEN spec, THEN mp, OF this] + obtain i where "i \ A" "\ (f i \ y)" by auto + with ** show ?thesis by auto + qed auto + qed auto +qed + subsubsection {* Equivalence between @{text "f ----> x"} and @{text SUP} on @{typ pinfreal} *} lemma monoseq_monoI: "mono f \ monoseq f" @@ -1241,7 +1298,6 @@ have [intro, simp]: "\A. inj_on f A" using `bij f` unfolding bij_def by (auto intro: subset_inj_on) have f[intro, simp]: "\x. f (inv f x) = x" using `bij f` unfolding bij_def by (auto intro: surj_f_inv_f) - show ?thesis proof (rule psuminf_equality) fix n @@ -1266,49 +1322,6 @@ qed qed -lemma psuminf_2dimen: - fixes f:: "nat * nat \ pinfreal" - assumes fsums: "\m. g m = (\\<^isub>\ n. f (m,n))" - shows "psuminf (f \ prod_decode) = psuminf g" -proof (rule psuminf_equality) - fix n :: nat - let ?P = "prod_decode ` {.. prod_decode) {.. \ setsum f ({..Max (fst ` ?P)} \ {..Max (snd ` ?P)})" - proof (safe intro!: setsum_mono3 Max_ge image_eqI) - fix a b x assume "(a, b) = prod_decode x" - from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)" - by simp_all - qed simp_all - also have "\ = (\m\Max (fst ` ?P). (\n\Max (snd ` ?P). f (m,n)))" - unfolding setsum_cartesian_product by simp - also have "\ \ (\m\Max (fst ` ?P). g m)" - by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc - simp: fsums lessThan_Suc_atMost[symmetric]) - also have "\ \ psuminf g" - by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc - simp: lessThan_Suc_atMost[symmetric]) - finally show "setsum (f \ prod_decode) {.. psuminf g" . -next - fix y assume *: "\n. setsum (f \ prod_decode) {.. y" - have g: "g = (\m. \\<^isub>\ n. f (m,n))" unfolding fsums[symmetric] .. - show "psuminf g \ y" unfolding g - proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound) - fix N M :: nat - let ?P = "{.. {..nm (\(m, n)\?P. f (m, n))" - unfolding setsum_commute[of _ _ "{.. \ (\(m,n)\(prod_decode ` {..?M}). f (m, n))" - by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]]) - also have "\ \ y" using *[of "Suc ?M"] - by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex - inj_prod_decode del: setsum_lessThan_Suc) - finally show "(\nm y" . - qed -qed - lemma pinfreal_mult_less_right: assumes "b * a < c * a" "0 < a" "a < \" shows "b < c" @@ -1384,6 +1397,80 @@ qed simp qed simp +lemma psuminf_SUP_eq: + assumes "\n i. f n i \ f (Suc n) i" + shows "(\\<^isub>\ i. SUP n::nat. f n i) = (SUP n::nat. \\<^isub>\ i. f n i)" +proof - + { fix n :: nat + have "(\ii\<^isub>\ i j. f i j) = (\\<^isub>\ j i. f i j)" +proof - + have "(SUP n. \ i < n. SUP m. \ j < m. f i j) = (SUP n. SUP m. \ i < n. \ j < m. f i j)" + apply (subst SUPR_pinfreal_setsum) + by auto + also have "\ = (SUP m n. \ j < m. \ i < n. f i j)" + apply (subst SUP_commute) + apply (subst setsum_commute) + by auto + also have "\ = (SUP m. \ j < m. SUP n. \ i < n. f i j)" + apply (subst SUPR_pinfreal_setsum) + by auto + finally show ?thesis + unfolding psuminf_def by auto +qed + +lemma psuminf_2dimen: + fixes f:: "nat * nat \ pinfreal" + assumes fsums: "\m. g m = (\\<^isub>\ n. f (m,n))" + shows "psuminf (f \ prod_decode) = psuminf g" +proof (rule psuminf_equality) + fix n :: nat + let ?P = "prod_decode ` {.. prod_decode) {.. \ setsum f ({..Max (fst ` ?P)} \ {..Max (snd ` ?P)})" + proof (safe intro!: setsum_mono3 Max_ge image_eqI) + fix a b x assume "(a, b) = prod_decode x" + from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)" + by simp_all + qed simp_all + also have "\ = (\m\Max (fst ` ?P). (\n\Max (snd ` ?P). f (m,n)))" + unfolding setsum_cartesian_product by simp + also have "\ \ (\m\Max (fst ` ?P). g m)" + by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc + simp: fsums lessThan_Suc_atMost[symmetric]) + also have "\ \ psuminf g" + by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc + simp: lessThan_Suc_atMost[symmetric]) + finally show "setsum (f \ prod_decode) {.. psuminf g" . +next + fix y assume *: "\n. setsum (f \ prod_decode) {.. y" + have g: "g = (\m. \\<^isub>\ n. f (m,n))" unfolding fsums[symmetric] .. + show "psuminf g \ y" unfolding g + proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound) + fix N M :: nat + let ?P = "{.. {..nm (\(m, n)\?P. f (m, n))" + unfolding setsum_commute[of _ _ "{.. \ (\(m,n)\(prod_decode ` {..?M}). f (m, n))" + by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]]) + also have "\ \ y" using *[of "Suc ?M"] + by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex + inj_prod_decode del: setsum_lessThan_Suc) + finally show "(\nm y" . + qed +qed + lemma Real_max: assumes "x \ 0" "y \ 0" shows "Real (max x y) = max (Real x) (Real y)" @@ -2076,20 +2163,6 @@ lemma real_Real_max:"real (Real x) = max x 0" unfolding real_Real by auto -lemma (in complete_lattice) SUPR_upper: - "x \ A \ f x \ SUPR A f" - unfolding SUPR_def apply(rule Sup_upper) by auto - -lemma (in complete_lattice) SUPR_subset: - assumes "A \ B" shows "SUPR A f \ SUPR B f" - apply(rule SUP_leI) apply(rule SUPR_upper) using assms by auto - -lemma (in complete_lattice) SUPR_mono: - assumes "\a\A. \b\B. f b \ f a" - shows "SUPR A f \ SUPR B f" - unfolding SUPR_def apply(rule Sup_mono) - using assms by auto - lemma Sup_lim: assumes "\n. b n \ s" "b ----> (a::pinfreal)" shows "a \ Sup s" @@ -2161,11 +2234,6 @@ unfolding Real_real using om by auto qed qed -lemma less_SUP_iff: - fixes a :: pinfreal - shows "(a < (SUP i:A. f i)) \ (\x\A. a < f x)" - unfolding SUPR_def less_Sup_iff by auto - lemma Sup_mono_lim: assumes "\a\A. \b. \n. b n \ B \ b ----> (a::pinfreal)" shows "Sup A \ Sup B" @@ -2371,26 +2439,6 @@ shows "a \ a - b \ a \ 0 \ a \ \ \ b = 0" by (cases a, cases b, auto split: split_if_asm) -lemma lim_INF_le_lim_SUP: - fixes f :: "nat \ pinfreal" - shows "(SUP n. INF m. f (n + m)) \ (INF n. SUP m. f (n + m))" -proof (rule complete_lattice_class.SUP_leI, rule complete_lattice_class.le_INFI) - fix i j show "(INF m. f (i + m)) \ (SUP m. f (j + m))" - proof (cases rule: le_cases) - assume "i \ j" - have "(INF m. f (i + m)) \ f (i + (j - i))" by (rule INF_leI) simp - also have "\ = f (j + 0)" using `i \ j` by auto - also have "\ \ (SUP m. f (j + m))" by (rule le_SUPI) simp - finally show ?thesis . - next - assume "j \ i" - have "(INF m. f (i + m)) \ f (i + 0)" by (rule INF_leI) simp - also have "\ = f (j + (i - j))" using `j \ i` by auto - also have "\ \ (SUP m. f (j + m))" by (rule le_SUPI) simp - finally show ?thesis . - qed -qed - lemma lim_INF_eq_lim_SUP: fixes X :: "nat \ real" assumes "\i. 0 \ X i" and "0 \ x" @@ -2707,4 +2755,21 @@ lemma lessThan_0_Empty: "{..< 0 :: pinfreal} = {}" by auto +lemma real_of_pinfreal_inverse[simp]: + fixes X :: pinfreal + shows "real (inverse X) = 1 / real X" + by (cases X) (auto simp: inverse_eq_divide) + +lemma real_of_pinfreal_le_0[simp]: "real (X :: pinfreal) \ 0 \ (X = 0 \ X = \)" + by (cases X) auto + +lemma real_of_pinfreal_less_0[simp]: "\ (real (X :: pinfreal) < 0)" + by (cases X) auto + +lemma abs_real_of_pinfreal[simp]: "\real (X :: pinfreal)\ = real X" + by simp + +lemma zero_less_real_of_pinfreal: "0 < real (X :: pinfreal) \ X \ 0 \ X \ \" + by (cases X) auto + end diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Product_Measure.thy --- a/src/HOL/Probability/Product_Measure.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Product_Measure.thy Thu Dec 02 16:39:15 2010 +0100 @@ -2,28 +2,6 @@ imports Lebesgue_Integration begin -lemma in_sigma[intro, simp]: "A \ sets M \ A \ sets (sigma M)" - unfolding sigma_def by (auto intro!: sigma_sets.Basic) - -lemma (in sigma_algebra) sigma_eq[simp]: "sigma M = M" - unfolding sigma_def sigma_sets_eq by simp - -lemma vimage_algebra_sigma: - assumes E: "sets E \ Pow (space E)" - and f: "f \ space F \ space E" - and "\A. A \ sets F \ A \ (\X. f -` X \ space F) ` sets E" - and "\A. A \ sets E \ f -` A \ space F \ sets F" - shows "sigma_algebra.vimage_algebra (sigma E) (space F) f = sigma F" -proof - - interpret sigma_algebra "sigma E" - using assms by (intro sigma_algebra_sigma) auto - have eq: "sets F = (\X. f -` X \ space F) ` sets E" - using assms by auto - show "vimage_algebra (space F) f = sigma F" - unfolding vimage_algebra_def using assms - by (simp add: sigma_def eq sigma_sets_vimage) -qed - lemma times_Int_times: "A \ B \ C \ D = (A \ C) \ (B \ D)" by auto @@ -786,13 +764,10 @@ positive_integral f" proof - interpret Q: pair_sigma_finite M2 \2 M1 \1 by default - have s: "\x y. (case (x, y) of (x, y) \ f (y, x)) = f (y, x)" by simp have t: "(\x. f (case x of (x, y) \ (y, x))) = (\(x, y). f (y, x))" by (auto simp: fun_eq_iff) - have bij: "bij_betw (\(x, y). (y, x)) (space M2 \ space M1) (space P)" by (auto intro!: inj_onI simp: space_pair_algebra bij_betw_def) - note pair_sigma_algebra_measurable[OF f] from Q.positive_integral_fst_measurable[OF this] have "M2.positive_integral (\y. M1.positive_integral (\x. f (x, y))) = @@ -890,7 +865,7 @@ lemma (in finite_product_sigma_algebra) P_empty: "I = {} \ P = \ space = {\k. undefined}, sets = { {}, {\k. undefined} }\" - unfolding product_algebra_def by (simp add: sigma_def) + unfolding product_algebra_def by (simp add: sigma_def image_constant) lemma (in finite_product_sigma_algebra) in_P[simp, intro]: "\ \i. i \ I \ A i \ sets (M i) \ \ Pi\<^isub>E I A \ sets P" @@ -930,7 +905,6 @@ using E1 E2 by (auto simp add: pair_algebra_def) interpret E: sigma_algebra ?E unfolding pair_algebra_def using E1 E2 by (intro sigma_algebra_sigma) auto - { fix A assume "A \ sets E1" then have "fst -` A \ space ?E = A \ (\i. S2 i)" using E1 2 unfolding isoton_def pair_algebra_def by auto @@ -954,7 +928,6 @@ "fst \ measurable ?E (sigma E1) \ snd \ measurable ?E (sigma E2)" using E1 E2 by (subst (1 2) E.measurable_iff_sigma) (auto simp: pair_algebra_def sets_sigma) - { fix A B assume A: "A \ sets (sigma E1)" and B: "B \ sets (sigma E2)" with proj have "fst -` A \ space ?E \ sets ?E" "snd -` B \ space ?E \ sets ?E" unfolding measurable_def by simp_all @@ -966,7 +939,6 @@ by (intro E.sigma_sets_subset) (auto simp add: pair_algebra_def sets_sigma) then have subset: "sets ?S \ sets ?E" by (simp add: sets_sigma pair_algebra_def) - have "sets ?S = sets ?E" proof (intro set_eqI iffI) fix A assume "A \ sets ?E" then show "A \ sets ?S" @@ -1286,7 +1258,7 @@ by (auto intro!: exI[of _ "\A. if A = {} then 0 else 1"] sigma_algebra_sigma sigma_algebra.finite_additivity_sufficient simp add: positive_def additive_def sets_sigma sigma_finite_measure_def - sigma_finite_measure_axioms_def) + sigma_finite_measure_axioms_def image_constant) next case (insert i I) interpret finite_product_sigma_finite M \ I by default fact @@ -1304,7 +1276,6 @@ unfolding product_singleton_vimage_algebra_eq[OF `i \ I` `finite I`, symmetric] using bij_betw_restrict_I_i[OF `i \ I`, of M] by (intro P.measure_space_isomorphic) auto - show ?case proof (intro exI[of _ ?\] conjI ballI) { fix A assume A: "A \ (\ i\insert i I. sets (M i))" @@ -1322,7 +1293,6 @@ apply fastsimp using `i \ I` `finite I` prod[of A] by (auto simp: ac_simps) } note product = this - show "sigma_finite_measure I'.P ?\" proof from I'.sigma_finite_pairs guess F :: "'i \ nat \ 'a set" .. @@ -1395,7 +1365,7 @@ have "\A. measure (Pi\<^isub>E {} A) = 1" using assms by (subst measure_times) auto then show ?thesis - unfolding positive_integral_alt simple_function_def simple_integral_def_raw + unfolding positive_integral_def simple_function_def simple_integral_def_raw proof (simp add: P_empty, intro antisym) show "f (\k. undefined) \ (SUP f:{g. g \ f}. f (\k. undefined))" by (intro le_SUPI) auto @@ -1455,17 +1425,13 @@ have "finite (I \ J)" using fin by auto interpret IJ: finite_product_sigma_finite M \ "I \ J" by default fact interpret P: pair_sigma_finite I.P I.measure J.P J.measure by default - let ?f = "\x. ((\i\I. x i), (\i\J. x i))" - have P_borel: "(\x. f (case x of (x, y) \ merge I x J y)) \ borel_measurable P.P" by (subst product_product_vimage_algebra_eq[OF IJ fin, symmetric]) (auto simp: space_pair_algebra intro!: IJ.measurable_vimage f) - have split_f_image[simp]: "\F. ?f ` (Pi\<^isub>E (I \ J) F) = (Pi\<^isub>E I F) \ (Pi\<^isub>E J F)" apply auto apply (rule_tac x="merge I a J b" in image_eqI) by (auto dest: extensional_restrict) - have "IJ.positive_integral f = IJ.positive_integral (\x. f (restrict x (I \ J)))" by (auto intro!: IJ.positive_integral_cong arg_cong[where f=f] dest!: extensional_restrict) also have "\ = I.positive_integral (\x. J.positive_integral (\y. f (merge I x J y)))" diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Radon_Nikodym.thy --- a/src/HOL/Probability/Radon_Nikodym.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Radon_Nikodym.thy Thu Dec 02 16:39:15 2010 +0100 @@ -69,6 +69,8 @@ qed qed +subsection "Absolutely continuous" + definition (in measure_space) "absolutely_continuous \ = (\N\null_sets. \ N = (0 :: pinfreal))" @@ -111,6 +113,14 @@ finally show "\ N = 0" . qed +lemma (in measure_space) density_is_absolutely_continuous: + assumes "\A. A \ sets M \ \ A = positive_integral (\x. f x * indicator A x)" + shows "absolutely_continuous \" + using assms unfolding absolutely_continuous_def + by (simp add: positive_integral_null_set) + +subsection "Existence of the Radon-Nikodym derivative" + lemma (in finite_measure) Radon_Nikodym_aux_epsilon: fixes e :: real assumes "0 < e" assumes "finite_measure M s" @@ -120,21 +130,17 @@ proof - let "?d A" = "real (\ A) - real (s A)" interpret M': finite_measure M s by fact - let "?A A" = "if (\B\sets M. B \ space M - A \ -e < ?d B) then {} else (SOME B. B \ sets M \ B \ space M - A \ ?d B \ -e)" def A \ "\n. ((\B. B \ ?A B) ^^ n) {}" - have A_simps[simp]: "A 0 = {}" "\n. A (Suc n) = (A n \ ?A (A n))" unfolding A_def by simp_all - { fix A assume "A \ sets M" have "?A A \ sets M" by (auto intro!: someI2[of _ _ "\A. A \ sets M"] simp: not_less) } note A'_in_sets = this - { fix n have "A n \ sets M" proof (induct n) case (Suc n) thus "A (Suc n) \ sets M" @@ -142,7 +148,6 @@ qed (simp add: A_def) } note A_in_sets = this hence "range A \ sets M" by auto - { fix n B assume Ex: "\B. B \ sets M \ B \ space M - A n \ ?d B \ -e" hence False: "\ (\B\sets M. B \ space M - A n \ -e < ?d B)" by (auto simp: not_less) @@ -156,7 +161,6 @@ finally show "?d (A n \ B) \ ?d (A n) - e" . qed } note dA_epsilon = this - { fix n have "?d (A (Suc n)) \ ?d (A n)" proof (cases "\B. B\sets M \ B \ space M - A n \ ?d B \ - e") case True from dA_epsilon[OF this] show ?thesis using `0 < e` by simp @@ -166,7 +170,6 @@ thus ?thesis by simp qed } note dA_mono = this - show ?thesis proof (cases "\n. \B\sets M. B \ space M - A n \ -e < ?d B") case True then obtain n where B: "\B. \ B \ sets M; B \ space M - A n\ \ -e < ?d B" by blast @@ -220,11 +223,8 @@ proof - let "?d A" = "real (\ A) - real (s A)" let "?P A B n" = "A \ sets M \ A \ B \ ?d B \ ?d A \ (\C\sets M. C \ A \ - 1 / real (Suc n) < ?d C)" - interpret M': finite_measure M s by fact - let "?r S" = "restricted_space S" - { fix S n assume S: "S \ sets M" hence **: "\X. X \ op \ S ` sets M \ X \ sets M \ X \ S" by auto @@ -242,11 +242,9 @@ qed hence "\A. ?P A S n" by auto } note Ex_P = this - def A \ "nat_rec (space M) (\n A. SOME B. ?P B A n)" have A_Suc: "\n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def) have A_0[simp]: "A 0 = space M" unfolding A_def by simp - { fix i have "A i \ sets M" unfolding A_def proof (induct i) case (Suc i) @@ -254,19 +252,15 @@ by (rule someI2_ex) simp qed simp } note A_in_sets = this - { fix n have "?P (A (Suc n)) (A n) n" using Ex_P[OF A_in_sets] unfolding A_Suc by (rule someI2_ex) simp } note P_A = this - have "range A \ sets M" using A_in_sets by auto - have A_mono: "\i. A (Suc i) \ A i" using P_A by simp have mono_dA: "mono (\i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc) have epsilon: "\C i. \ C \ sets M; C \ A (Suc i) \ \ - 1 / real (Suc i) < ?d C" using P_A by auto - show ?thesis proof (safe intro!: bexI[of _ "\i. A i"]) show "(\i. A i) \ sets M" using A_in_sets by auto @@ -298,24 +292,19 @@ shows "\f \ borel_measurable M. \A\sets M. \ A = positive_integral (\x. f x * indicator A x)" proof - interpret M': finite_measure M \ using assms(1) . - def G \ "{g \ borel_measurable M. \A\sets M. positive_integral (\x. g x * indicator A x) \ \ A}" have "(\x. 0) \ G" unfolding G_def by auto hence "G \ {}" by auto - { fix f g assume f: "f \ G" and g: "g \ G" have "(\x. max (g x) (f x)) \ G" (is "?max \ G") unfolding G_def proof safe show "?max \ borel_measurable M" using f g unfolding G_def by auto - let ?A = "{x \ space M. f x \ g x}" have "?A \ sets M" using f g unfolding G_def by auto - fix A assume "A \ sets M" hence sets: "?A \ A \ sets M" "(space M - ?A) \ A \ sets M" using `?A \ sets M` by auto have union: "((?A \ A) \ ((space M - ?A) \ A)) = A" using sets_into_space[OF `A \ sets M`] by auto - have "\x. x \ space M \ max (g x) (f x) * indicator A x = g x * indicator (?A \ A) x + f x * indicator ((space M - ?A) \ A) x" by (auto simp: indicator_def max_def) @@ -331,14 +320,12 @@ finally show "positive_integral (\x. max (g x) (f x) * indicator A x) \ \ A" . qed } note max_in_G = this - { fix f g assume "f \ g" and f: "\i. f i \ G" have "g \ G" unfolding G_def proof safe from `f \ g` have [simp]: "g = (SUP i. f i)" unfolding isoton_def by simp have f_borel: "\i. f i \ borel_measurable M" using f unfolding G_def by simp thus "g \ borel_measurable M" by (auto intro!: borel_measurable_SUP) - fix A assume "A \ sets M" hence "\i. (\x. f i x * indicator A x) \ borel_measurable M" using f_borel by (auto intro!: borel_measurable_indicator) @@ -350,7 +337,6 @@ using f `A \ sets M` unfolding G_def by (auto intro!: SUP_leI) qed } note SUP_in_G = this - let ?y = "SUP g : G. positive_integral g" have "?y \ \ (space M)" unfolding G_def proof (safe intro!: SUP_leI) @@ -385,7 +371,6 @@ hence isoton_g: "?g \ f" by (simp add: isoton_def le_fun_def f_def) from SUP_in_G[OF this g_in_G] have "f \ G" . hence [simp, intro]: "f \ borel_measurable M" unfolding G_def by auto - have "(\i. positive_integral (?g i)) \ positive_integral f" using isoton_g g_in_G by (auto intro!: positive_integral_isoton simp: G_def f_def) hence "positive_integral f = (SUP i. positive_integral (?g i))" @@ -398,9 +383,7 @@ by (auto intro!: SUP_mono positive_integral_mono Max_ge) qed finally have int_f_eq_y: "positive_integral f = ?y" . - let "?t A" = "\ A - positive_integral (\x. f x * indicator A x)" - have "finite_measure M ?t" proof show "?t {} = 0" by simp @@ -435,9 +418,7 @@ qed qed then interpret M: finite_measure M ?t . - have ac: "absolutely_continuous ?t" using `absolutely_continuous \` unfolding absolutely_continuous_def by auto - have upper_bound: "\A\sets M. ?t A \ 0" proof (rule ccontr) assume "\ ?thesis" @@ -460,7 +441,6 @@ ultimately have b: "b \ 0" "b \ \" using M'.finite_measure_of_space by (auto simp: pinfreal_inverse_eq_0 finite_measure_of_space) - have "finite_measure M (\A. b * \ A)" (is "finite_measure M ?b") proof show "?b {} = 0" by simp @@ -469,7 +449,6 @@ unfolding countably_additive_def psuminf_cmult_right using measure_countably_additive by auto qed - from M.Radon_Nikodym_aux[OF this] obtain A0 where "A0 \ sets M" and space_less_A0: "real (?t (space M)) - real (b * \ (space M)) \ real (?t A0) - real (b * \ A0)" and @@ -479,9 +458,7 @@ using M'.finite_measure b finite_measure by (cases "b * \ B", cases "?t B") (auto simp: field_simps) } note bM_le_t = this - let "?f0 x" = "f x + b * indicator A0 x" - { fix A assume A: "A \ sets M" hence "A \ A0 \ sets M" using `A0 \ sets M` by auto have "positive_integral (\x. ?f0 x * indicator A x) = @@ -492,7 +469,6 @@ using `A0 \ sets M` `A \ A0 \ sets M` A by (simp add: borel_measurable_indicator positive_integral_add positive_integral_cmult_indicator) } note f0_eq = this - { fix A assume A: "A \ sets M" hence "A \ A0 \ sets M" using `A0 \ sets M` by auto have f_le_v: "positive_integral (\x. f x * indicator A x) \ \ A" @@ -511,18 +487,15 @@ finally have "positive_integral (\x. ?f0 x * indicator A x) \ \ A" . } hence "?f0 \ G" using `A0 \ sets M` unfolding G_def by (auto intro!: borel_measurable_indicator borel_measurable_pinfreal_add borel_measurable_pinfreal_times) - have real: "?t (space M) \ \" "?t A0 \ \" "b * \ (space M) \ \" "b * \ A0 \ \" using `A0 \ sets M` b finite_measure[of A0] M.finite_measure[of A0] finite_measure_of_space M.finite_measure_of_space by auto - have int_f_finite: "positive_integral f \ \" using M'.finite_measure_of_space pos_t unfolding pinfreal_zero_less_diff_iff by (auto cong: positive_integral_cong) - have "?t (space M) > b * \ (space M)" unfolding b_def apply (simp add: field_simps) apply (subst mult_assoc[symmetric]) @@ -539,18 +512,15 @@ hence "0 < \ A0" using ac unfolding absolutely_continuous_def using `A0 \ sets M` by auto hence "0 < b * \ A0" using b by auto - from int_f_finite this have "?y + 0 < positive_integral f + b * \ A0" unfolding int_f_eq_y by (rule pinfreal_less_add) also have "\ = positive_integral ?f0" using f0_eq[OF top] `A0 \ sets M` sets_into_space by (simp cong: positive_integral_cong) finally have "?y < positive_integral ?f0" by simp - moreover from `?f0 \ G` have "positive_integral ?f0 \ ?y" by (auto intro!: le_SUPI) ultimately show False by auto qed - show ?thesis proof (safe intro!: bexI[of _ f]) fix A assume "A\sets M" @@ -575,10 +545,8 @@ interpret v: measure_space M \ by fact let ?Q = "{Q\sets M. \ Q \ \}" let ?a = "SUP Q:?Q. \ Q" - have "{} \ ?Q" using v.empty_measure by auto then have Q_not_empty: "?Q \ {}" by blast - have "?a \ \ (space M)" using sets_into_space by (auto intro!: SUP_leI measure_mono top) then have "?a \ \" using finite_measure_of_space @@ -596,9 +564,7 @@ show "range ?O \ sets M" using Q' by (auto intro!: finite_UN) show "\i. ?O i \ ?O (Suc i)" by fastsimp qed - have Q'_sets: "\i. Q' i \ sets M" using Q' by auto - have O_sets: "\i. ?O i \ sets M" using Q' by (auto intro!: finite_UN Un) then have O_in_G: "\i. ?O i \ ?Q" @@ -611,7 +577,6 @@ finally show "\ (?O i) \ \" unfolding pinfreal_less_\ by auto qed auto have O_mono: "\n. ?O n \ ?O (Suc n)" by fastsimp - have a_eq: "?a = \ (\i. ?O i)" unfolding Union[symmetric] proof (rule antisym) show "?a \ (SUP i. \ (?O i))" unfolding a_Lim @@ -625,14 +590,11 @@ using O_in_G[of i] by (auto intro!: exI[of _ "?O i"]) qed qed - let "?O_0" = "(\i. ?O i)" have "?O_0 \ sets M" using Q' by auto - def Q \ "\i. case i of 0 \ Q' 0 | Suc n \ ?O (Suc n) - ?O n" { fix i have "Q i \ sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) } note Q_sets = this - show ?thesis proof (intro bexI exI conjI ballI impI allI) show "disjoint_family Q" @@ -640,7 +602,6 @@ split: nat.split_asm) show "range Q \ sets M" using Q_sets by auto - { fix A assume A: "A \ sets M" "A \ space M - ?O_0" show "\ A = 0 \ \ A = 0 \ 0 < \ A \ \ A = \" proof (rule disjCI, simp) @@ -677,7 +638,6 @@ with `\ A \ 0` show ?thesis by auto qed qed } - { fix i show "\ (Q i) \ \" proof (cases i) case 0 then show ?thesis @@ -688,9 +648,7 @@ using `?O n \ ?Q` `?O (Suc n) \ ?Q` O_mono using v.measure_Diff[of "?O n" "?O (Suc n)"] by auto qed } - show "space M - ?O_0 \ sets M" using Q'_sets by auto - { fix j have "(\i\j. ?O i) = (\i\j. Q i)" proof (induct j) case 0 then show ?case by (simp add: Q_def) @@ -713,7 +671,6 @@ shows "\f \ borel_measurable M. \A\sets M. \ A = positive_integral (\x. f x * indicator A x)" proof - interpret v: measure_space M \ by fact - from split_space_into_finite_sets_and_rest[OF assms] obtain Q0 and Q :: "nat \ 'a set" where Q: "disjoint_family Q" "range Q \ sets M" @@ -721,7 +678,6 @@ and in_Q0: "\A. A \ sets M \ A \ Q0 \ \ A = 0 \ \ A = 0 \ 0 < \ A \ \ A = \" and Q_fin: "\i. \ (Q i) \ \" by force from Q have Q_sets: "\i. Q i \ sets M" by auto - have "\i. \f. f\borel_measurable M \ (\A\sets M. \ (Q i \ A) = positive_integral (\x. f x * indicator (Q i \ A) x))" proof @@ -729,7 +685,6 @@ have indicator_eq: "\f x A. (f x :: pinfreal) * indicator (Q i \ A) x * indicator (Q i) x = (f x * indicator (Q i) x) * indicator A x" unfolding indicator_def by auto - have fm: "finite_measure (restricted_space (Q i)) \" (is "finite_measure ?R \") by (rule restricted_finite_measure[OF Q_sets[of i]]) then interpret R: finite_measure ?R . @@ -843,12 +798,6 @@ section "Uniqueness of densities" -lemma (in measure_space) density_is_absolutely_continuous: - assumes "\A. A \ sets M \ \ A = positive_integral (\x. f x * indicator A x)" - shows "absolutely_continuous \" - using assms unfolding absolutely_continuous_def - by (simp add: positive_integral_null_set) - lemma (in measure_space) finite_density_unique: assumes borel: "f \ borel_measurable M" "g \ borel_measurable M" and fin: "positive_integral f < \" @@ -973,19 +922,16 @@ using h_borel by (rule measure_space_density) interpret h: finite_measure M "\A. positive_integral (\x. h x * indicator A x)" by default (simp cong: positive_integral_cong add: fin) - interpret f: measure_space M "\A. positive_integral (\x. f x * indicator A x)" using borel(1) by (rule measure_space_density) interpret f': measure_space M "\A. positive_integral (\x. f' x * indicator A x)" using borel(2) by (rule measure_space_density) - { fix A assume "A \ sets M" then have " {x \ space M. h x \ 0 \ indicator A x \ (0::pinfreal)} = A" using pos sets_into_space by (force simp: indicator_def) then have "positive_integral (\xa. h xa * indicator A xa) = 0 \ A \ null_sets" using h_borel `A \ sets M` by (simp add: positive_integral_0_iff) } note h_null_sets = this - { fix A assume "A \ sets M" have "positive_integral (\x. h x * (f x * indicator A x)) = f.positive_integral (\x. h x * indicator A x)" @@ -1101,7 +1047,7 @@ qed qed -section "Radon Nikodym derivative" +section "Radon-Nikodym derivative" definition (in sigma_finite_measure) "RN_deriv \ \ SOME f. f \ borel_measurable M \ diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Probability/Sigma_Algebra.thy --- a/src/HOL/Probability/Sigma_Algebra.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Probability/Sigma_Algebra.thy Thu Dec 02 16:39:15 2010 +0100 @@ -397,6 +397,18 @@ by (auto intro: sigma_sets.Empty sigma_sets_top) qed +lemma (in sigma_algebra) sets_sigma_subset: + assumes "space N = space M" + assumes "sets N \ sets M" + shows "sets (sigma N) \ sets M" + by (unfold assms sets_sigma, rule sigma_sets_subset, rule assms) + +lemma in_sigma[intro, simp]: "A \ sets M \ A \ sets (sigma M)" + unfolding sigma_def by (auto intro!: sigma_sets.Basic) + +lemma (in sigma_algebra) sigma_eq[simp]: "sigma M = M" + unfolding sigma_def sigma_sets_eq by simp + section {* Measurable functions *} definition @@ -859,6 +871,22 @@ qed qed +lemma vimage_algebra_sigma: + assumes E: "sets E \ Pow (space E)" + and f: "f \ space F \ space E" + and "\A. A \ sets F \ A \ (\X. f -` X \ space F) ` sets E" + and "\A. A \ sets E \ f -` A \ space F \ sets F" + shows "sigma_algebra.vimage_algebra (sigma E) (space F) f = sigma F" +proof - + interpret sigma_algebra "sigma E" + using assms by (intro sigma_algebra_sigma) auto + have eq: "sets F = (\X. f -` X \ space F) ` sets E" + using assms by auto + show "vimage_algebra (space F) f = sigma F" + unfolding vimage_algebra_def using assms + by (simp add: sigma_def eq sigma_sets_vimage) +qed + section {* Conditional space *} definition (in algebra) @@ -1149,7 +1177,6 @@ section {* Dynkin systems *} - locale dynkin_system = fixes M :: "'a algebra" assumes space_closed: "sets M \ Pow (space M)" diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Set.thy --- a/src/HOL/Set.thy Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Set.thy Thu Dec 02 16:39:15 2010 +0100 @@ -882,7 +882,6 @@ lemma rangeE [elim?]: "b \ range (\x. f x) ==> (!!x. b = f x ==> P) ==> P" by blast - subsubsection {* Some rules with @{text "if"} *} text{* Elimination of @{text"{x. \ & x=t & \}"}. *} diff -r da4bdafeef7c -r 3c45d6753fd0 src/HOL/Tools/Metis/metis_reconstruct.ML --- a/src/HOL/Tools/Metis/metis_reconstruct.ML Thu Dec 02 16:39:07 2010 +0100 +++ b/src/HOL/Tools/Metis/metis_reconstruct.ML Thu Dec 02 16:39:15 2010 +0100 @@ -554,22 +554,32 @@ fun count p xs = fold (fn x => if p x then Integer.add 1 else I) xs 0 fun replay_one_inference ctxt mode skolem_params (fol_th, inf) thpairs = - let - val _ = trace_msg ctxt (fn () => "=============================================") - val _ = trace_msg ctxt (fn () => "METIS THM: " ^ Metis_Thm.toString fol_th) - val _ = trace_msg ctxt (fn () => "INFERENCE: " ^ Metis_Proof.inferenceToString inf) - val th = step ctxt mode skolem_params thpairs (fol_th, inf) - |> flexflex_first_order - val _ = trace_msg ctxt (fn () => "ISABELLE THM: " ^ Display.string_of_thm ctxt th) - val _ = trace_msg ctxt (fn () => "=============================================") - val num_metis_lits = - fol_th |> Metis_Thm.clause |> Metis_LiteralSet.toList - |> count is_metis_literal_genuine - val num_isabelle_lits = - th |> prems_of |> count is_isabelle_literal_genuine - val _ = if num_metis_lits = num_isabelle_lits then () - else error "Cannot replay Metis proof in Isabelle: Out of sync." - in (fol_th, th) :: thpairs end + if not (null thpairs) andalso prop_of (snd (hd thpairs)) aconv @{prop False} then + (* Isabelle sometimes identifies literals (premises) that are distinct in + Metis (e.g., because of type variables). We give the Isabelle proof the + benefice of the doubt. *) + thpairs + else + let + val _ = trace_msg ctxt + (fn () => "=============================================") + val _ = trace_msg ctxt + (fn () => "METIS THM: " ^ Metis_Thm.toString fol_th) + val _ = trace_msg ctxt + (fn () => "INFERENCE: " ^ Metis_Proof.inferenceToString inf) + val th = step ctxt mode skolem_params thpairs (fol_th, inf) + |> flexflex_first_order + val _ = trace_msg ctxt + (fn () => "ISABELLE THM: " ^ Display.string_of_thm ctxt th) + val _ = trace_msg ctxt + (fn () => "=============================================") + val num_metis_lits = + count is_metis_literal_genuine + (Metis_LiteralSet.toList (Metis_Thm.clause fol_th)) + val num_isabelle_lits = count is_isabelle_literal_genuine (prems_of th) + val _ = if num_metis_lits >= num_isabelle_lits then () + else error "Cannot replay Metis proof in Isabelle: Out of sync." + in (fol_th, th) :: thpairs end fun term_instantiate thy = cterm_instantiate o map (pairself (cterm_of thy)) diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/General/markup.scala --- a/src/Pure/General/markup.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/General/markup.scala Thu Dec 02 16:39:15 2010 +0100 @@ -227,15 +227,14 @@ { def apply(timing: isabelle.Timing): Markup = Markup(TIMING, List( - (ELAPSED, Double(timing.elapsed)), - (CPU, Double(timing.cpu)), - (GC, Double(timing.gc)))) + (ELAPSED, Double(timing.elapsed.seconds)), + (CPU, Double(timing.cpu.seconds)), + (GC, Double(timing.gc.seconds)))) def unapply(markup: Markup): Option[isabelle.Timing] = markup match { case Markup(TIMING, List( - (ELAPSED, Double(elapsed)), - (CPU, Double(cpu)), - (GC, Double(gc)))) => Some(isabelle.Timing(elapsed, cpu, gc)) + (ELAPSED, Double(elapsed)), (CPU, Double(cpu)), (GC, Double(gc)))) => + Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc))) case _ => None } } diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/General/timing.scala --- a/src/Pure/General/timing.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/General/timing.scala Thu Dec 02 16:39:15 2010 +0100 @@ -6,15 +6,27 @@ package isabelle - -sealed case class Timing(val elapsed: Double, cpu: Double, gc: Double) +object Time { - private def print_time(seconds: Double): String = - String.format(java.util.Locale.ROOT, "%.3f", seconds.asInstanceOf[AnyRef]) - - def message: String = - print_time(elapsed) + "s elapsed time, " + - print_time(cpu) + "s cpu time, " + - print_time(gc) + "s GC time" + def seconds(s: Double): Time = new Time((s * 1000.0) round) } +class Time(val ms: Long) +{ + def seconds: Double = ms / 1000.0 + + def min(t: Time): Time = if (ms < t.ms) this else t + def max(t: Time): Time = if (ms > t.ms) this else t + + override def toString = + String.format(java.util.Locale.ROOT, "%.3f", seconds.asInstanceOf[AnyRef]) + def message: String = toString + "s" +} + +class Timing(val elapsed: Time, val cpu: Time, val gc: Time) +{ + def message: String = + elapsed.message + " elapsed time, " + cpu.message + " cpu time, " + gc.message + " GC time" + override def toString = message +} + diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/System/isabelle_process.scala --- a/src/Pure/System/isabelle_process.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/System/isabelle_process.scala Thu Dec 02 16:39:15 2010 +0100 @@ -61,7 +61,7 @@ } -class Isabelle_Process(system: Isabelle_System, timeout: Int, receiver: Actor, args: String*) +class Isabelle_Process(system: Isabelle_System, timeout: Time, receiver: Actor, args: String*) { import Isabelle_Process._ @@ -69,7 +69,7 @@ /* demo constructor */ def this(args: String*) = - this(new Isabelle_System, 10000, + this(new Isabelle_System, Time.seconds(10), actor { loop { react { case res => Console.println(res) } } }, args: _*) @@ -141,7 +141,7 @@ { val (startup_failed, startup_output) = { - val expired = System.currentTimeMillis() + timeout + val expired = System.currentTimeMillis() + timeout.ms val result = new StringBuilder(100) var finished: Option[Boolean] = None diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/System/session.scala --- a/src/Pure/System/session.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/System/session.scala Thu Dec 02 16:39:15 2010 +0100 @@ -36,13 +36,13 @@ /* real time parameters */ // FIXME properties or settings (!?) // user input (e.g. text edits, cursor movement) - val input_delay = 300 + val input_delay = Time.seconds(0.3) // prover output (markup, common messages) - val output_delay = 100 + val output_delay = Time.seconds(0.1) // GUI layout updates - val update_delay = 500 + val update_delay = Time.seconds(0.5) /* pervasive event buses */ @@ -74,15 +74,13 @@ Simple_Thread.actor("command_change_buffer", daemon = true) //{{{ { - import scala.compat.Platform.currentTime - var changed: Set[Command] = Set() var flush_time: Option[Long] = None def flush_timeout: Long = flush_time match { case None => 5000L - case Some(time) => (time - currentTime) max 0 + case Some(time) => (time - System.currentTimeMillis()) max 0 } def flush() @@ -94,9 +92,9 @@ def invoke() { - val now = currentTime + val now = System.currentTimeMillis() flush_time match { - case None => flush_time = Some(now + output_delay) + case None => flush_time = Some(now + output_delay.ms) case Some(time) => if (now >= time) flush() } } @@ -136,7 +134,7 @@ private case object Interrupt_Prover private case class Edit_Version(edits: List[Document.Edit_Text]) - private case class Start(timeout: Int, args: List[String]) + private case class Start(timeout: Time, args: List[String]) private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true) { @@ -288,7 +286,7 @@ /** main methods **/ - def start(timeout: Int, args: List[String]) { session_actor ! Start(timeout, args) } + def start(timeout: Time, args: List[String]) { session_actor ! Start(timeout, args) } def stop() { command_change_buffer !? Stop; session_actor !? Stop } diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/System/swing_thread.scala --- a/src/Pure/System/swing_thread.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/System/swing_thread.scala Thu Dec 02 16:39:15 2010 +0100 @@ -44,12 +44,12 @@ /* delayed actions */ - private def delayed_action(first: Boolean)(time_span: Int)(action: => Unit): () => Unit = + private def delayed_action(first: Boolean)(time: Time)(action: => Unit): () => Unit = { val listener = new ActionListener { override def actionPerformed(e: ActionEvent) { Swing_Thread.assert(); action } } - val timer = new Timer(time_span, listener) + val timer = new Timer(time.ms.toInt, listener) timer.setRepeats(false) def invoke() { if (first) timer.start() else timer.restart() } diff -r da4bdafeef7c -r 3c45d6753fd0 src/Pure/library.scala --- a/src/Pure/library.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Pure/library.scala Thu Dec 02 16:39:15 2010 +0100 @@ -137,12 +137,12 @@ def timeit[A](message: String)(e: => A) = { - val start = System.nanoTime() + val start = System.currentTimeMillis() val result = Exn.capture(e) - val stop = System.nanoTime() + val stop = System.currentTimeMillis() System.err.println( (if (message == null || message.isEmpty) "" else message + ": ") + - ((stop - start).toDouble / 1000000) + "ms elapsed time") + new Time(stop - start).message + " elapsed time") Exn.release(result) } } diff -r da4bdafeef7c -r 3c45d6753fd0 src/Tools/jEdit/plugin/Isabelle.props --- a/src/Tools/jEdit/plugin/Isabelle.props Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Tools/jEdit/plugin/Isabelle.props Thu Dec 02 16:39:15 2010 +0100 @@ -32,8 +32,8 @@ options.isabelle.tooltip-margin.title=Tooltip Margin options.isabelle.tooltip-margin=40 options.isabelle.tooltip-dismiss-delay.title=Tooltip Dismiss Delay (global) -options.isabelle.tooltip-dismiss-delay=8000 -options.isabelle.startup-timeout=10000 +options.isabelle.tooltip-dismiss-delay=8.0 +options.isabelle.startup-timeout=10.0 options.isabelle.auto-start.title=Auto Start options.isabelle.auto-start=true diff -r da4bdafeef7c -r 3c45d6753fd0 src/Tools/jEdit/src/jedit/document_model.scala --- a/src/Tools/jEdit/src/jedit/document_model.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Tools/jEdit/src/jedit/document_model.scala Thu Dec 02 16:39:15 2010 +0100 @@ -63,7 +63,7 @@ extends TokenMarker.LineContext(dummy_rules, prev) { override def hashCode: Int = line - override def equals(that: Any) = + override def equals(that: Any): Boolean = that match { case other: Line_Context => line == other.line case _ => false diff -r da4bdafeef7c -r 3c45d6753fd0 src/Tools/jEdit/src/jedit/isabelle_options.scala --- a/src/Tools/jEdit/src/jedit/isabelle_options.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Tools/jEdit/src/jedit/isabelle_options.scala Thu Dec 02 16:39:15 2010 +0100 @@ -7,6 +7,8 @@ package isabelle.jedit +import isabelle._ + import javax.swing.JSpinner import scala.swing.CheckBox @@ -39,7 +41,8 @@ tooltip_margin.setValue(Isabelle.Int_Property("tooltip-margin", 40)) addComponent(Isabelle.Property("tooltip-margin.title"), tooltip_margin) - tooltip_dismiss_delay.setValue(Isabelle.Int_Property("tooltip-dismiss-delay", 8000)) + tooltip_dismiss_delay.setValue( + Isabelle.Time_Property("tooltip-dismiss-delay", Time.seconds(8.0)).ms.toInt) addComponent(Isabelle.Property("tooltip-dismiss-delay.title"), tooltip_dismiss_delay) } @@ -58,7 +61,7 @@ Isabelle.Int_Property("tooltip-margin") = tooltip_margin.getValue().asInstanceOf[Int] - Isabelle.Int_Property("tooltip-dismiss-delay") = - tooltip_dismiss_delay.getValue().asInstanceOf[Int] + Isabelle.Time_Property("tooltip-dismiss-delay") = + Time.seconds(tooltip_dismiss_delay.getValue().asInstanceOf[Int]) } } diff -r da4bdafeef7c -r 3c45d6753fd0 src/Tools/jEdit/src/jedit/plugin.scala --- a/src/Tools/jEdit/src/jedit/plugin.scala Thu Dec 02 16:39:07 2010 +0100 +++ b/src/Tools/jEdit/src/jedit/plugin.scala Thu Dec 02 16:39:15 2010 +0100 @@ -70,6 +70,26 @@ jEdit.setIntegerProperty(OPTION_PREFIX + name, value) } + object Double_Property + { + def apply(name: String): Double = + jEdit.getDoubleProperty(OPTION_PREFIX + name, 0.0) + def apply(name: String, default: Double): Double = + jEdit.getDoubleProperty(OPTION_PREFIX + name, default) + def update(name: String, value: Double) = + jEdit.setDoubleProperty(OPTION_PREFIX + name, value) + } + + object Time_Property + { + def apply(name: String): Time = + Time.seconds(Double_Property(name)) + def apply(name: String, default: Time): Time = + Time.seconds(Double_Property(name, default.seconds)) + def update(name: String, value: Time) = + Double_Property.update(name, value.seconds) + } + /* font */ @@ -100,14 +120,14 @@ Int_Property("tooltip-font-size", 10).toString + "px; \">" + // FIXME proper scaling (!?) HTML.encode(text) + "" - def tooltip_dismiss_delay(): Int = - Int_Property("tooltip-dismiss-delay", 8000) max 500 + def tooltip_dismiss_delay(): Time = + Time_Property("tooltip-dismiss-delay", Time.seconds(8.0)) max Time.seconds(0.5) def setup_tooltips() { Swing_Thread.now { val manager = javax.swing.ToolTipManager.sharedInstance - manager.setDismissDelay(tooltip_dismiss_delay()) + manager.setDismissDelay(tooltip_dismiss_delay().ms.toInt) } } @@ -210,7 +230,7 @@ def start_session() { - val timeout = Int_Property("startup-timeout") max 1000 + val timeout = Time_Property("startup-timeout", Time.seconds(10)) max Time.seconds(5) val modes = system.getenv("JEDIT_PRINT_MODE").split(",").toList.map("-m" + _) val logic = { val logic = Property("logic")