# HG changeset patch # User paulson # Date 1736716569 0 # Node ID 2cf8f8e4c1fda7ef255ebaae2c687abbb2359f97 # Parent 8d790d757bfbb554349ff5c1206db5c4f5f95826 Simplified a lot of messy proofs diff -r 8d790d757bfb -r 2cf8f8e4c1fd src/HOL/Library/Extended_Nonnegative_Real.thy --- a/src/HOL/Library/Extended_Nonnegative_Real.thy Fri Jan 10 21:08:18 2025 +0100 +++ b/src/HOL/Library/Extended_Nonnegative_Real.thy Sun Jan 12 21:16:09 2025 +0000 @@ -1619,7 +1619,7 @@ shows "I \ {} \ (SUP i\I. f i + c) = (SUP i\I. f i) + c" apply transfer apply (simp add: SUP_ereal_add_left) - by (metis SUP_upper all_not_in_conv ereal_le_add_mono1 max.absorb2 max.bounded_iff) + by (metis SUP_upper all_not_in_conv add_increasing2 max.absorb2 max.bounded_iff) lemma ennreal_SUP_const_minus: fixes f :: "'a \ ennreal" diff -r 8d790d757bfb -r 2cf8f8e4c1fd src/HOL/Library/Extended_Real.thy --- a/src/HOL/Library/Extended_Real.thy Fri Jan 10 21:08:18 2025 +0100 +++ b/src/HOL/Library/Extended_Real.thy Sun Jan 12 21:16:09 2025 +0000 @@ -68,10 +68,10 @@ lemma sup_continuous_iff_at_left: fixes f :: "'a::{complete_linorder, linorder_topology, first_countable_topology} \ - 'b::{complete_linorder, linorder_topology}" + 'b::{complete_linorder, linorder_topology}" shows "sup_continuous f \ (\x. continuous (at_left x) f) \ mono f" - using sup_continuous_at_left[of f] continuous_at_left_imp_sup_continuous[of f] - sup_continuous_mono[of f] by auto + using continuous_at_left_imp_sup_continuous sup_continuous_at_left sup_continuous_mono + by blast lemma continuous_at_right_imp_inf_continuous: fixes f :: "'a::{complete_linorder, linorder_topology} \ 'b::{complete_linorder, linorder_topology}" @@ -79,8 +79,11 @@ shows "inf_continuous f" unfolding inf_continuous_def proof safe - fix M :: "nat \ 'a" assume "decseq M" then show "f (INF i. M i) = (INF i. f (M i))" - using continuous_at_Inf_mono [OF assms, of "range M"] by (simp add: image_comp) + fix M :: "nat \ 'a" + assume "decseq M" + then show "f (INF i. M i) = (INF i. f (M i))" + using continuous_at_Inf_mono [OF assms, of "range M"] + by (simp add: image_comp) qed lemma inf_continuous_at_right: @@ -96,9 +99,10 @@ show ?thesis unfolding continuous_within proof (intro tendsto_at_right_sequentially[of _ top]) - fix S :: "nat \ 'a" assume S: "decseq S" and S_x: "S \ x" - from S_x have x_eq: "x = (INF i. S i)" - by (rule LIMSEQ_unique) (intro LIMSEQ_INF S) + fix S :: "nat \ 'a" + assume S: "decseq S" and S_x: "S \ x" + then have x_eq: "x = (INF i. S i)" + using INF_Lim by blast show "(\n. f (S n)) \ f x" unfolding x_eq inf_continuousD[OF f S] using S inf_continuous_mono[OF f] by (intro LIMSEQ_INF) (auto simp: mono_def antimono_def) @@ -109,8 +113,8 @@ fixes f :: "'a::{complete_linorder, linorder_topology, first_countable_topology} \ 'b::{complete_linorder, linorder_topology}" shows "inf_continuous f \ (\x. continuous (at_right x) f) \ mono f" - using inf_continuous_at_right[of f] continuous_at_right_imp_inf_continuous[of f] - inf_continuous_mono[of f] by auto + using continuous_at_right_imp_inf_continuous inf_continuous_at_right inf_continuous_mono + by blast instantiation enat :: linorder_topology begin @@ -167,7 +171,7 @@ then obtain n m where "{enat n<..} \ A" "{enat m<..} \ B" by auto then have "{enat (max n m) <..} \ A \ B" - by (auto simp add: subset_eq Ball_def max_def simp flip: enat_ord_code(1)) + by (auto simp: subset_eq Ball_def max_def simp flip: enat_ord_code(1)) then show ?case by auto next @@ -185,7 +189,7 @@ proof (rule antisym) show "nhds \ \ (INF i. principal {enat i..})" unfolding nhds_def - using Ioi_le_Ico by (intro INF_greatest INF_lower) (auto simp add: open_enat_iff) + using Ioi_le_Ico by (intro INF_greatest INF_lower) (auto simp: open_enat_iff) show "(INF i. principal {enat i..}) \ nhds \" unfolding nhds_def by (intro INF_greatest) (force intro: INF_lower2[of "Suc _"] simp add: open_enat_iff Suc_ile_eq) @@ -200,16 +204,15 @@ by (rule order_trans[OF _ add_mono[of aa aa 0 ba]]) auto then have [simp]: "enat i \ ba \ enat i \ aa + ba" for aa ba i by (metis add.commute) - fix a b :: enat show "((\x. fst x + snd x) \ a + b) (nhds a \\<^sub>F nhds b)" - apply (auto simp: nhds_enat filterlim_INF prod_filter_INF1 prod_filter_INF2 - filterlim_principal principal_prod_principal eventually_principal) - subgoal for i - by (auto intro!: eventually_INF1[of i] simp: eventually_principal) - subgoal for j i - by (auto intro!: eventually_INF1[of i] simp: eventually_principal) - subgoal for j i - by (auto intro!: eventually_INF1[of i] simp: eventually_principal) - done + fix a b :: enat + have "\\<^sub>F x in INF m n. principal ({enat n..} \ {enat m..}). enat i \ fst x + snd x" + "\\<^sub>F x in INF n. principal ({enat n..} \ {enat j}). enat i \ fst x + snd x" + "\\<^sub>F x in INF n. principal ({enat j} \ {enat n..}). enat i \ fst x + snd x" + for i j + by (auto intro!: eventually_INF1[of i] simp: eventually_principal) + then show "((\x. fst x + snd x) \ a + b) (nhds a \\<^sub>F nhds b)" + by (auto simp: nhds_enat filterlim_INF prod_filter_INF1 prod_filter_INF2 + filterlim_principal principal_prod_principal eventually_principal) qed text \ @@ -221,8 +224,6 @@ datatype ereal = ereal real | PInfty | MInfty -lemma ereal_cong: "x = y \ ereal x = ereal y" by simp - instantiation ereal :: uminus begin @@ -252,12 +253,12 @@ lemma shows PInfty_eq_infinity[simp]: "PInfty = \" - and MInfty_eq_minfinity[simp]: "MInfty = - \" - and MInfty_neq_PInfty[simp]: "\ \ - (\::ereal)" "- \ \ (\::ereal)" - and MInfty_neq_ereal[simp]: "ereal r \ - \" "- \ \ ereal r" + and MInfty_eq_minfinity[simp]: "MInfty = -\" + and MInfty_neq_PInfty[simp]: "\ \ - (\::ereal)" "-\ \ (\::ereal)" + and MInfty_neq_ereal[simp]: "ereal r \ -\" "-\ \ ereal r" and PInfty_neq_ereal[simp]: "ereal r \ \" "\ \ ereal r" and PInfty_cases[simp]: "(case \ of ereal r \ f r | PInfty \ y | MInfty \ z) = y" - and MInfty_cases[simp]: "(case - \ of ereal r \ f r | PInfty \ y | MInfty \ z) = z" + and MInfty_cases[simp]: "(case -\ of ereal r \ f r | PInfty \ y | MInfty \ z) = z" by (simp_all add: infinity_ereal_def) declare @@ -366,7 +367,7 @@ "ereal r + ereal p = ereal (r + p)" | "\ + a = (\::ereal)" | "a + \ = (\::ereal)" -| "ereal r + -\ = - \" +| "ereal r + -\ = -\" | "-\ + ereal p = -(\::ereal)" | "-\ + -\ = -(\::ereal)" proof goal_cases @@ -410,7 +411,7 @@ lemma ereal_0_plus [simp]: "ereal 0 + x = x" and plus_ereal_0 [simp]: "x + ereal 0 = x" -by(simp_all flip: zero_ereal_def) + by(simp_all flip: zero_ereal_def) instance ereal :: numeral .. @@ -451,13 +452,13 @@ using assms by (cases rule: ereal3_cases[of a b c]) auto lemma ereal_real: "ereal (real_of_ereal x) = (if \x\ = \ then 0 else x)" - by (cases x) simp_all + by auto lemma real_of_ereal_add: fixes a b :: ereal shows "real_of_ereal (a + b) = (if (\a\ = \) \ (\b\ = \) \ (\a\ \ \) \ (\b\ \ \) then real_of_ereal a + real_of_ereal b else 0)" - by (cases rule: ereal2_cases[of a b]) auto + by auto subsubsection "Linear order on \<^typ>\ereal\" @@ -485,14 +486,14 @@ lemma ereal_infty_less[simp]: fixes x :: ereal shows "x < \ \ (x \ \)" - "-\ < x \ (x \ -\)" - by (cases x, simp_all) (cases x, simp_all) + "-\ < x \ (x \ -\)" + by (cases x, simp_all)+ lemma ereal_infty_less_eq[simp]: fixes x :: ereal shows "\ \ x \ x = \" and "x \ -\ \ x = -\" - by (auto simp add: less_eq_ereal_def) + by (auto simp: less_eq_ereal_def) lemma ereal_less[simp]: "ereal r < 0 \ (r < 0)" @@ -511,7 +512,7 @@ "0 \ ereal r \ 0 \ r" "ereal r \ 1 \ r \ 1" "1 \ ereal r \ 1 \ r" - by (auto simp add: less_eq_ereal_def zero_ereal_def one_ereal_def) + by (auto simp: less_eq_ereal_def zero_ereal_def one_ereal_def) lemma ereal_infty_less_eq2: "a \ b \ a = \ \ b = (\::ereal)" @@ -527,16 +528,12 @@ by (cases rule: ereal2_cases[of x y]) auto show "x \ y \ y \ x " by (cases rule: ereal2_cases[of x y]) auto - { - assume "x \ y" "y \ x" - then show "x = y" - by (cases rule: ereal2_cases[of x y]) auto - } - { - assume "x \ y" "y \ z" - then show "x \ z" - by (cases rule: ereal3_cases[of x y z]) auto - } + assume "x \ y" + then show "y \ x \ x = y" + by (cases rule: ereal2_cases[of x y]) auto + show "y \ z \ x \ z" + using \x \ y\ + by (cases rule: ereal3_cases[of x y z]) auto qed end @@ -566,12 +563,12 @@ lemma ereal_MInfty_lessI[intro, simp]: fixes a :: ereal shows "a \ -\ \ -\ < a" - by (cases a) auto + by simp lemma ereal_less_PInfty[intro, simp]: fixes a :: ereal shows "a \ \ \ a < \" - by (cases a) auto + by simp lemma ereal_less_ereal_Ex: fixes a b :: ereal @@ -590,7 +587,7 @@ assumes "a < b" and "c < d" shows "a + c < b + d" using assms - by (cases a; force simp add: elim: less_ereal.elims) + by (cases a; force simp: elim: less_ereal.elims) lemma ereal_minus_le_minus[simp]: fixes a b :: ereal @@ -643,7 +640,8 @@ lemma real_of_ereal_pos: fixes x :: ereal - shows "0 \ x \ 0 \ real_of_ereal x" by (cases x) auto + shows "0 \ x \ 0 \ real_of_ereal x" + by (cases x) auto lemmas real_of_ereal_ord_simps = ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff @@ -660,12 +658,12 @@ lemma ereal_abs_leI: fixes x y :: ereal shows "\ x \ y; -x \ y \ \ \x\ \ y" -by(cases x y rule: ereal2_cases)(simp_all) + by(cases x y rule: ereal2_cases)(simp_all) lemma ereal_abs_add: fixes a b::ereal shows "abs(a+b) \ abs a + abs b" -by (cases rule: ereal2_cases[of a b]) (auto) + by (cases rule: ereal2_cases[of a b]) (auto) lemma real_of_ereal_le_0[simp]: "real_of_ereal (x :: ereal) \ 0 \ x \ 0 \ x = \" by (cases x) auto @@ -703,22 +701,13 @@ shows "\a\ \ \ \ c < b \ a + c < a + b" by (cases rule: ereal2_cases[of b c]) auto -lemma ereal_add_nonneg_eq_0_iff: - fixes a b :: ereal - shows "0 \ a \ 0 \ b \ a + b = 0 \ a = 0 \ b = 0" - by (cases a b rule: ereal2_cases) auto - lemma ereal_uminus_eq_reorder: "- a = b \ a = (-b::ereal)" by auto -lemma ereal_uminus_less_reorder: "- a < b \ -b < (a::ereal)" - by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus) - -lemma ereal_less_uminus_reorder: "a < - b \ b < - (a::ereal)" - by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus) - -lemma ereal_uminus_le_reorder: "- a \ b \ -b \ (a::ereal)" - by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_le_minus) +lemma ereal_uminus_less_reorder: "- a < b \ -b < a" + and ereal_less_uminus_reorder: "a < - b \ b < - a" + and ereal_uminus_le_reorder: "- a \ b \ -b \ a" for a::ereal + using ereal_minus_le_minus ereal_minus_less_minus by fastforce+ lemmas ereal_uminus_reorder = ereal_uminus_eq_reorder ereal_uminus_less_reorder ereal_uminus_le_reorder @@ -726,7 +715,7 @@ lemma ereal_bot: fixes x :: ereal assumes "\B. x \ ereal B" - shows "x = - \" + shows "x = -\" proof (cases x) case (real r) with assms[of "r - 1"] show ?thesis @@ -777,13 +766,7 @@ unfolding incseq_def by auto lemma sum_ereal[simp]: "(\x\A. ereal (f x)) = ereal (\x\A. f x)" -proof (cases "finite A") - case True - then show ?thesis by induct auto -next - case False - then show ?thesis by simp -qed + by (induction A rule: infinite_finite_induct) auto lemma sum_list_ereal [simp]: "sum_list (map (\x. ereal (f x)) xs) = ereal (sum_list (map f xs))" by (induction xs) simp_all @@ -794,11 +777,7 @@ proof safe assume *: "sum f P = \" show "finite P" - proof (rule ccontr) - assume "\ finite P" - with * show False - by auto - qed + by (metis "*" Infty_neq_0(2) sum.infinite) show "\i\P. f i = \" proof (rule ccontr) assume "\ ?thesis" @@ -831,7 +810,8 @@ assume "\ ?thesis" then have "\i\A. \r. f i = ereal r" by auto - from bchoice[OF this] obtain r where "\x\A. f x = ereal (r x)" .. + then obtain r where "\x\A. f x = ereal (r x)" + by metis with * show False by auto qed @@ -855,33 +835,13 @@ shows "(\x\S. real_of_ereal (f x)) = real_of_ereal (sum f S)" proof - have "\x\S. \r. f x = ereal r" - proof - fix x - assume "x \ S" - from assms[OF this] show "\r. f x = ereal r" - by (cases "f x") auto - qed - from bchoice[OF this] obtain r where "\x\S. f x = ereal (r x)" .. + using assms by blast + then obtain r where "\x\S. f x = ereal (r x)" + by metis then show ?thesis by simp qed -lemma sum_ereal_0: - fixes f :: "'a \ ereal" - assumes "finite A" - and "\i. i \ A \ 0 \ f i" - shows "(\x\A. f x) = 0 \ (\i\A. f i = 0)" -proof - assume "sum f A = 0" with assms show "\i\A. f i = 0" - proof (induction A) - case (insert a A) - then have "f a = 0 \ (\a\A. f a) = 0" - by (subst ereal_add_nonneg_eq_0_iff[symmetric]) (simp_all add: sum_nonneg) - with insert show ?case - by simp - qed simp -qed auto - subsubsection "Multiplication" instantiation ereal :: "{comm_monoid_mult,sgn}" @@ -954,7 +914,7 @@ lemma ereal_zero_mult[simp]: fixes a :: ereal shows "0 * a = 0" - by (cases a) (simp_all add: zero_ereal_def) + by (metis ereal_mult_zero mult.commute) lemma ereal_m1_less_0[simp]: "-(1::ereal) < 0" by (simp add: zero_ereal_def one_ereal_def) @@ -990,7 +950,7 @@ by (cases x y rule: ereal2_cases) (auto simp: abs_mult) lemma ereal_0_less_1[simp]: "0 < (1::ereal)" - by (simp_all add: zero_ereal_def one_ereal_def) + by (simp add: zero_ereal_def one_ereal_def) lemma ereal_mult_minus_left[simp]: fixes a b :: ereal @@ -1003,11 +963,11 @@ by (cases rule: ereal2_cases[of a b]) auto lemma ereal_mult_infty[simp]: - "a * (\::ereal) = (if a = 0 then 0 else if 0 < a then \ else - \)" + "a * (\::ereal) = (if a = 0 then 0 else if 0 < a then \ else -\)" by (cases a) auto lemma ereal_infty_mult[simp]: - "(\::ereal) * a = (if a = 0 then 0 else if 0 < a then \ else - \)" + "(\::ereal) * a = (if a = 0 then 0 else if 0 < a then \ else -\)" by (cases a) auto lemma ereal_mult_strict_right_mono: @@ -1036,29 +996,31 @@ lemma ereal_mult_left_mono: fixes a b c :: ereal shows "a \ b \ 0 \ c \ c * a \ c * b" - using ereal_mult_right_mono - by (simp add: mult.commute[of c]) + by (simp add: ereal_mult_right_mono mult.commute) lemma ereal_mult_mono: fixes a b c d::ereal assumes "b \ 0" "c \ 0" "a \ b" "c \ d" shows "a * c \ b * d" -by (metis ereal_mult_right_mono mult.commute order_trans assms) + by (metis ereal_mult_right_mono mult.commute order_trans assms) lemma ereal_mult_mono': fixes a b c d::ereal assumes "a \ 0" "c \ 0" "a \ b" "c \ d" shows "a * c \ b * d" -by (metis ereal_mult_right_mono mult.commute order_trans assms) + by (metis ereal_mult_right_mono mult.commute order_trans assms) lemma ereal_mult_mono_strict: fixes a b c d::ereal assumes "b > 0" "c > 0" "a < b" "c < d" shows "a * c < b * d" proof - - have "c < \" using \c < d\ by auto - then have "a * c < b * c" by (metis ereal_mult_strict_left_mono[OF assms(3) assms(2)] mult.commute) - moreover have "b * c \ b * d" using assms(2) assms(4) by (simp add: assms(1) ereal_mult_left_mono less_imp_le) + have "c < \" using \c < d\ + by auto + then have "a * c < b * c" + by (metis ereal_mult_strict_left_mono[OF assms(3) assms(2)] mult.commute) + moreover have "b * c \ b * d" + using assms(1,4) ereal_mult_left_mono by force ultimately show ?thesis by simp qed @@ -1141,7 +1103,7 @@ lemma sum_ereal_right_distrib: fixes f :: "'a \ ereal" shows "(\i. i \ A \ 0 \ f i) \ r * sum f A = (\n\A. r * f n)" - by (induct A rule: infinite_finite_induct) (auto simp: ereal_right_distrib sum_nonneg) + by (induct A rule: infinite_finite_induct) (auto simp: ereal_right_distrib sum_nonneg) lemma sum_ereal_left_distrib: "(\i. i \ A \ 0 \ f i) \ sum f A * r = (\n\A. f n * r :: ereal)" @@ -1185,53 +1147,36 @@ lemma prod_ereal_0: fixes f :: "'a \ ereal" shows "(\i\A. f i) = 0 \ finite A \ (\i\A. f i = 0)" -proof (cases "finite A") - case True - then show ?thesis by (induct A) auto -qed auto + by (induction A rule: infinite_finite_induct) auto lemma prod_ereal_pos: fixes f :: "'a \ ereal" - assumes pos: "\i. i \ I \ 0 \ f i" + assumes "\i. i \ I \ 0 \ f i" shows "0 \ (\i\I. f i)" -proof (cases "finite I") - case True - from this pos show ?thesis - by induct auto -qed auto + using assms + by (induction I rule: infinite_finite_induct) auto lemma prod_PInf: fixes f :: "'a \ ereal" assumes "\i. i \ I \ 0 \ f i" shows "(\i\I. f i) = \ \ finite I \ (\i\I. f i = \) \ (\i\I. f i \ 0)" -proof (cases "finite I") - case True - from this assms show ?thesis - proof (induct I) - case (insert i I) - then have pos: "0 \ f i" "0 \ prod f I" - by (auto intro!: prod_ereal_pos) - from insert have "(\j\insert i I. f j) = \ \ prod f I * f i = \" - by auto - also have "\ \ (prod f I = \ \ f i = \) \ f i \ 0 \ prod f I \ 0" - using prod_ereal_pos[of I f] pos - by (cases rule: ereal2_cases[of "f i" "prod f I"]) auto - also have "\ \ finite (insert i I) \ (\j\insert i I. f j = \) \ (\j\insert i I. f j \ 0)" - using insert by (auto simp: prod_ereal_0) - finally show ?case . - qed simp + using assms +proof (induction I rule: infinite_finite_induct) + case (insert i I) + then have pos: "0 \ f i" "0 \ prod f I" + by (auto intro!: prod_ereal_pos) + from insert have "(\j\insert i I. f j) = \ \ prod f I * f i = \" + by auto + also have "\ \ (prod f I = \ \ f i = \) \ f i \ 0 \ prod f I \ 0" + using prod_ereal_pos[of I f] pos + by (cases rule: ereal2_cases[of "f i" "prod f I"]) auto + also have "\ \ finite (insert i I) \ (\j\insert i I. f j = \) \ (\j\insert i I. f j \ 0)" + using insert by (auto simp: prod_ereal_0) + finally show ?case . qed auto lemma prod_ereal: "(\i\A. ereal (f i)) = ereal (prod f A)" -proof (cases "finite A") - case True - then show ?thesis - by induct (auto simp: one_ereal_def) -next - case False - then show ?thesis - by (simp add: one_ereal_def) -qed + by (induction A rule: infinite_finite_induct) (auto simp: one_ereal_def) subsubsection \Power\ @@ -1268,18 +1213,7 @@ lemma ereal_uminus_lessThan[simp]: fixes a :: ereal shows "uminus ` {.. - ereal r = -\" - "ereal r - \ = -\" + "ereal r -\ = -\" "(\::ereal) - x = \" - "-(\::ereal) - \ = -\" + "-(\::ereal) -\ = -\" "x - -y = x + y" "x - 0 = x" "0 - x = -x" by (simp_all add: minus_ereal_def) lemma ereal_x_minus_x[simp]: "x - x = (if \x\ = \ then \ else 0::ereal)" - by (cases x) simp_all + by auto lemma ereal_eq_minus_iff: fixes x y z :: ereal @@ -1381,7 +1315,7 @@ lemma ereal_add_le_add_iff2: fixes a b c :: ereal shows "a + c \ b + c \ a \ b \ c = \ \ (c = -\ \ a \ \ \ b \ \)" -by(cases rule: ereal3_cases[of a b c])(simp_all add: field_simps) + by (metis (no_types, lifting) add.commute ereal_add_le_add_iff) lemma ereal_mult_le_mult_iff: fixes a b c :: ereal @@ -1413,8 +1347,7 @@ lemma ereal_between: fixes x e :: ereal - assumes "\x\ \ \" - and "0 < e" + assumes "\x\ \ \" and "0 < e" shows "x - e < x" and "x < x + e" using assms by (cases x, cases e, auto)+ @@ -1435,11 +1368,11 @@ by(cases x y z rule: ereal3_cases) simp_all lemma ereal_add_uminus_conv_diff: fixes x y z :: ereal shows "- x + y = y - x" - by(cases x y rule: ereal2_cases) simp_all + by (simp add: add.commute minus_ereal_def) lemma ereal_minus_diff_eq: fixes x y :: ereal - shows "\ x = \ \ y \ \; x = -\ \ y \ - \ \ \ - (x - y) = y - x" + shows "\ x = \ \ y \ \; x = -\ \ y \ -\ \ \ - (x - y) = y - x" by(cases x y rule: ereal2_cases) simp_all lemma ediff_le_self [simp]: "x - y \ (x :: enat)" @@ -1522,10 +1455,9 @@ lemma zero_le_divide_ereal[simp]: fixes a :: ereal - assumes "0 \ a" - and "0 \ b" + assumes "0 \ a" and "0 \ b" shows "0 \ a / b" - using assms by (cases rule: ereal2_cases[of a b]) (auto simp: zero_le_divide_iff) + by (simp add: assms divide_ereal_def ereal_inverse_nonneg_iff) lemma ereal_le_divide_pos: fixes x y z :: ereal @@ -1582,15 +1514,14 @@ lemma ereal_mult_less_right: fixes a b c :: ereal - assumes "b * a < c * a" - and "0 < a" - and "a < \" + assumes "b * a < c * a" "0 < a" "a < \" shows "b < c" using assms - by (cases rule: ereal3_cases[of a b c]) - (auto split: if_split_asm simp: zero_less_mult_iff zero_le_mult_iff) - -lemma ereal_mult_divide: fixes a b :: ereal shows "0 < b \ b < \ \ b * (a / b) = a" + by (metis order.asym ereal_mult_strict_left_mono linorder_neqE mult.commute) + +lemma ereal_mult_divide: + fixes a b :: ereal + shows "0 < b \ b < \ \ b * (a / b) = a" by (cases a b rule: ereal2_cases) auto lemma ereal_power_divide: @@ -1609,12 +1540,10 @@ with z[of "1 / 2"] show "x \ y" by (simp add: one_ereal_def) next - case (real r) - note r = this + case r: (real r) show "x \ y" proof (cases y) - case (real p) - note p = this + case p: (real p) have "r \ p" proof (rule field_le_mult_one_interval) fix z :: real @@ -1624,7 +1553,7 @@ qed then show "x \ y" using p r by simp - qed (insert y, simp_all) + qed (use y in simp_all) qed simp lemma ereal_divide_right_mono[simp]: @@ -1647,16 +1576,15 @@ lemma ereal_divide_zero_left[simp]: fixes a :: ereal shows "0 / a = 0" - by (cases a) (auto simp: zero_ereal_def) + using ereal_divide_eq_0_iff by blast lemma ereal_times_divide_eq_left[simp]: fixes a b c :: ereal shows "b / c * a = b * a / c" - by (cases a b c rule: ereal3_cases) (auto simp: field_simps zero_less_mult_iff mult_less_0_iff) + by (metis divide_ereal_def mult.assoc mult.commute) lemma ereal_times_divide_eq: "a * (b / c :: ereal) = a * b / c" - by (cases a b c rule: ereal3_cases) - (auto simp: field_simps zero_less_mult_iff) + by (metis ereal_times_divide_eq_left mult.commute) lemma ereal_inverse_real [simp]: "\z\ \ \ \ z \ 0 \ ereal (inverse (real_of_ereal z)) = inverse z" by auto @@ -1672,29 +1600,26 @@ lemma ereal_distrib_left: fixes a b c :: ereal assumes "a \ \ \ b \ -\" - and "a \ -\ \ b \ \" - and "\c\ \ \" + and "a \ -\ \ b \ \" + and "\c\ \ \" shows "c * (a + b) = c * a + c * b" -using assms -by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) + by (metis assms ereal_distrib mult.commute) lemma ereal_distrib_minus_left: fixes a b c :: ereal assumes "a \ \ \ b \ \" - and "a \ -\ \ b \ -\" - and "\c\ \ \" + and "a \ -\ \ b \ -\" + and "\c\ \ \" shows "c * (a - b) = c * a - c * b" -using assms -by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) + using assms ereal_distrib_left ereal_uminus_eq_reorder minus_ereal_def by auto lemma ereal_distrib_minus_right: fixes a b c :: ereal assumes "a \ \ \ b \ \" - and "a \ -\ \ b \ -\" - and "\c\ \ \" + and "a \ -\ \ b \ -\" + and "\c\ \ \" shows "(a - b) * c = a * c - b * c" -using assms -by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps) + by (metis assms ereal_distrib_minus_left mult.commute) subsection "Complete lattice" @@ -1780,8 +1705,13 @@ show "Inf {} = (top::ereal)" unfolding top_ereal_def Inf_ereal_def using ereal_infty_less_eq(1) ereal_less_eq(1) by blast -qed (auto intro: someI2_ex ereal_complete_Sup ereal_complete_Inf - simp: Sup_ereal_def Inf_ereal_def bot_ereal_def top_ereal_def) + show "\x::ereal. \A. x \ A \ Inf A \ x" + "\A z. (\x::ereal. x \ A \ z \ x) \ z \ Inf A" + by (auto intro: someI2_ex ereal_complete_Inf simp: Inf_ereal_def) + show "\x::ereal. \A. x \ A \ x \ Sup A" + "\A z. (\x::ereal. x \ A \ x \ z) \ Sup A \ z" + by (auto intro: someI2_ex ereal_complete_Sup simp: Sup_ereal_def) +qed end @@ -1844,7 +1774,7 @@ (if M = \ then UNIV else if M = -\ then {} else {..< real_of_ereal M}) - else if M = - \ then {} + else if M = -\ then {} else if M = \ then {real_of_ereal N<..} else {real_of_ereal N <..< real_of_ereal M})" proof (cases "M = -\ \ M = \ \ N = -\ \ N = \") @@ -1865,7 +1795,7 @@ fixes a b::ereal shows "real_of_ereal ` {a<.. then if b = \ then UNIV else {.. then if b = \ then UNIV else {.. then {real_of_ereal a<..} else {real_of_ereal a <..< real_of_ereal b}) else {})" by (cases a; cases b; simp add: real_atLeastGreaterThan_eq not_less) @@ -1873,31 +1803,34 @@ shows not_inftyI: "a < b \ b < c \ abs b \ \" by force -lemma - interval_neqs: +context fixes r s t::real - shows "{r<.. {t<..}" - and "{r<.. {.. UNIV" - and "{r<..} \ {.. UNIV" - and "{.. UNIV" - and "{} \ {r<..}" - and "{} \ {.. {t<..}" + by (simp add: set_eq_iff) (meson linordered_field_no_ub nless_le order_less_trans) + +lemma interval_Ioo_neq_Iio: "{r<.. {.. UNIV" + and interval_Ioi_neq_UNIV: "{r<..} \ UNIV" + and interval_Iio_neq_UNIV: "{.. UNIV" + by auto + +lemma interval_Ioi_neq_Iio: "{r<..} \ {.. {r<..}" + and interval_empty_neq_Iio: "{} \ {.. real_of_ereal ` {a<.. real_of_ereal ` {a<.. s" - shows "a \ - \" -proof (cases b) - case (real r) - then show ?thesis - using assms real_greaterThanLessThan_minus_infinity_eq by force -next - case PInf - then show ?thesis - using t real_greaterThanLessThan_infinity_eq by auto -next - case MInf - then show ?thesis - using s by auto -qed +shows "a \ -\" + by (metis UNIV_I assms empty_iff lessThan_iff order_le_less_trans + real_greaterThanLessThan_minus_infinity_eq) subsection "Topological space" @@ -2005,13 +1926,19 @@ by (metis ereal_uminus_reorder(2) eventually_at_topological greaterThan_iff open_greaterThan) qed + + lemma at_infty_ereal_eq_at_top: "at \ = filtermap ereal at_top" - unfolding filter_eq_iff eventually_at_filter eventually_at_top_linorder eventually_filtermap - top_ereal_def[symmetric] - apply (subst eventually_nhds_top[of 0]) - apply (auto simp: top_ereal_def less_le ereal_all_split ereal_ex_split) - apply (metis PInfty_neq_ereal(2) ereal_less_eq(3) ereal_top le_cases order_trans) - done +proof - + have "\P b. \z. b \ z \ b \ z \ P (ereal z) \ \N. \n\N. P (ereal n)" + by (metis gt_ex order_less_le order_less_le_trans) + then show ?thesis + unfolding filter_eq_iff eventually_at_filter eventually_at_top_linorder eventually_filtermap + top_ereal_def[symmetric] + apply (subst eventually_nhds_top[of 0]) + apply (auto simp: top_ereal_def less_le ereal_all_split ereal_ex_split) + done +qed lemma ereal_Lim_uminus: "(f \ f0) net \ ((\x. - f x::ereal) \ - f0) net" using tendsto_uminus_ereal[of f f0 net] tendsto_uminus_ereal[of "\x. - f x" "- f0" net] @@ -2024,7 +1951,8 @@ by (cases a b c rule: ereal3_cases) (auto simp: field_simps) lemma tendsto_cmult_ereal[tendsto_intros, simp, intro]: - assumes c: "\c\ \ \" and f: "(f \ x) F" shows "((\x. c * f x::ereal) \ c * x) F" + assumes c: "\c\ \ \" and f: "(f \ x) F" + shows "((\x. c * f x::ereal) \ c * x) F" proof - have *: "((\x. c * f x::ereal) \ c * x) F" if "0 < c" "c < \" for c :: ereal using that @@ -2039,7 +1967,7 @@ using c by (cases c) auto then show ?thesis proof (elim disjE conjE) - assume "- \ < c" "c < 0" + assume "-\ < c" "c < 0" then have "0 < - c" "- c < \" by (auto simp: ereal_uminus_reorder ereal_less_uminus_reorder[of 0]) then have "((\x. (- c) * f x) \ (- c) * x) F" @@ -2050,26 +1978,28 @@ qed lemma tendsto_cmult_ereal_not_0[tendsto_intros, simp, intro]: - assumes "x \ 0" and f: "(f \ x) F" shows "((\x. c * f x::ereal) \ c * x) F" + assumes "x \ 0" and f: "(f \ x) F" + shows "((\x. c * f x::ereal) \ c * x) F" proof cases assume "\c\ = \" show ?thesis proof (rule filterlim_cong[THEN iffD1, OF refl refl _ tendsto_const]) have "0 < x \ x < 0" - using \x \ 0\ by (auto simp add: neq_iff) + using \x \ 0\ by (auto simp: neq_iff) then show "eventually (\x'. c * x = c * f x') F" proof assume "0 < x" from order_tendstoD(1)[OF f this] show ?thesis - by eventually_elim (insert \0 \\c\ = \\, auto) + by eventually_elim (use \0 \\c\ = \\ in auto) next assume "x < 0" from order_tendstoD(2)[OF f this] show ?thesis - by eventually_elim (insert \x<0\ \\c\ = \\, auto) + by eventually_elim (use \x<0\ \\c\ = \\ in auto) qed qed qed (rule tendsto_cmult_ereal[OF _ f]) lemma tendsto_cadd_ereal[tendsto_intros, simp, intro]: - assumes c: "y \ - \" "x \ - \" and f: "(f \ x) F" shows "((\x. f x + y::ereal) \ x + y) F" + assumes c: "y \ -\" "x \ -\" and f: "(f \ x) F" + shows "((\x. f x + y::ereal) \ x + y) F" apply (intro tendsto_compose[OF _ f]) apply (auto intro!: order_tendstoI simp: eventually_at_topological) apply (rule_tac x="{a - y <..}" in exI) @@ -2079,7 +2009,8 @@ done lemma tendsto_add_left_ereal[tendsto_intros, simp, intro]: - assumes c: "\y\ \ \" and f: "(f \ x) F" shows "((\x. f x + y::ereal) \ x + y) F" + assumes c: "\y\ \ \" and f: "(f \ x) F" + shows "((\x. f x + y::ereal) \ x + y) F" apply (intro tendsto_compose[OF _ f]) apply (auto intro!: order_tendstoI simp: eventually_at_topological) apply (rule_tac x="{a - y <..}" in exI) @@ -2150,12 +2081,6 @@ shows "(INF x\S. - f x) = - (SUP x\S. f x)" using ereal_Inf_uminus_image_eq [of "f ` S"] by (simp add: image_comp) -lemma ereal_SUP_uminus: - fixes f :: "'a \ ereal" - shows "(SUP i \ R. - f i) = - (INF i \ R. f i)" - using ereal_Sup_uminus_image_eq[of "f`R"] - by (simp add: image_image) - lemma ereal_SUP_not_infty: fixes f :: "_ \ ereal" shows "A \ {} \ l \ -\ \ u \ \ \ \a\A. l \ f a \ f a \ u \ \Sup (f ` A)\ \ \" @@ -2171,13 +2096,7 @@ lemma ereal_image_uminus_shift: fixes X Y :: "ereal set" shows "uminus ` X = Y \ X = uminus ` Y" -proof - assume "uminus ` X = Y" - then have "uminus ` uminus ` X = uminus ` Y" - by (simp add: inj_image_eq_iff) - then show "X = uminus ` Y" - by (simp add: image_image) -qed (simp add: image_image) + by (metis ereal_minus_minus_image) lemma Sup_eq_MInfty: fixes S :: "ereal set" @@ -2200,7 +2119,7 @@ shows "\ \ S \ Sup S = \" unfolding top_ereal_def[symmetric] by auto -lemma not_MInfty_nonneg[simp]: "0 \ (x::ereal) \ x \ - \" +lemma not_MInfty_nonneg[simp]: "0 \ (x::ereal) \ x \ -\" by auto lemma Sup_ereal_close: @@ -2215,15 +2134,11 @@ assumes "\Inf X\ \ \" and "0 < e" shows "\x\X. x < Inf X + e" -proof (rule Inf_less_iff[THEN iffD1]) - show "Inf X < Inf X + e" - using assms by (cases e) auto -qed + by (meson Inf_less_iff assms ereal_between(2)) lemma SUP_PInfty: "(\n::nat. \i\A. ereal (real n) \ f i) \ (SUP i\A. f i :: ereal) = \" - unfolding top_ereal_def[symmetric] SUP_eq_top_iff - by (metis MInfty_neq_PInfty(2) PInfty_neq_ereal(2) less_PInf_Ex_of_nat less_ereal.elims(2) less_le_trans) + by (meson SUP_upper2 less_PInf_Ex_of_nat linorder_not_less) lemma SUP_nat_Infty: "(SUP i. ereal (real i)) = \" by (rule SUP_PInfty) auto @@ -2231,7 +2146,7 @@ lemma SUP_ereal_add_left: assumes "I \ {}" "c \ -\" shows "(SUP i\I. f i + c :: ereal) = (SUP i\I. f i) + c" -proof (cases "(SUP i\I. f i) = - \") +proof (cases "(SUP i\I. f i) = -\") case True then have "\i. i \ I \ f i = -\" unfolding Sup_eq_MInfty by auto @@ -2254,7 +2169,7 @@ assumes "I \ {}" "c \ -\" shows "(SUP i\I. c - f i :: ereal) = c - (INF i\I. f i)" using SUP_ereal_add_right[OF assms, of "\i. - f i"] - by (simp add: ereal_SUP_uminus minus_ereal_def) + by (simp add: ereal_SUP_uminus_eq minus_ereal_def) lemma SUP_ereal_minus_left: assumes "I \ {}" "c \ \" @@ -2269,15 +2184,14 @@ using \\c\ \ \\ by (cases c b rule: ereal2_cases) auto show ?thesis using SUP_ereal_add_right[OF \I \ {}\, of "-c" f] \\c\ \ \\ - by (auto simp add: * ereal_SUP_uminus_eq) + by (auto simp: * ereal_SUP_uminus_eq) qed lemma SUP_ereal_le_addI: fixes f :: "'i \ ereal" assumes "\i. f i + y \ z" and "y \ -\" shows "Sup (f ` UNIV) + y \ z" - unfolding SUP_ereal_add_left[OF UNIV_not_empty \y \ -\\, symmetric] - by (rule SUP_least assms)+ + by (metis SUP_ereal_add_left SUP_least UNIV_not_empty assms) lemma SUP_combine: fixes f :: "'a::semilattice_sup \ 'a::semilattice_sup \ 'b::complete_lattice" @@ -2295,13 +2209,21 @@ assumes inc: "incseq f" "incseq g" and pos: "\i. f i \ -\" "\i. g i \ -\" shows "(SUP i. f i + g i) = Sup (f ` UNIV) + Sup (g ` UNIV)" - apply (subst SUP_ereal_add_left[symmetric, OF UNIV_not_empty]) - apply (metis SUP_upper UNIV_I assms(4) ereal_infty_less_eq(2)) - apply (subst (2) add.commute) - apply (subst SUP_ereal_add_left[symmetric, OF UNIV_not_empty assms(3)]) - apply (subst (2) add.commute) - apply (rule SUP_combine[symmetric] add_mono inc[THEN monoD] | assumption)+ - done +proof - + have "\i j k l. \i \ j; k \ l\ \ f i + g k \ f j + g l" + by (meson add_mono inc incseq_def) + then have "(SUP i. f i + g i) = (SUP i j. f i + g j)" + by (simp add: SUP_combine) + also have "... = (SUP i j. g j + f i)" + by (simp add: add.commute) + also have "... = (SUP i. Sup (range g) + f i)" + by (simp add: SUP_ereal_add_left pos(1)) + also have "... = (SUP i. f i + Sup (range g))" + by (simp add: add.commute) + also have "... = Sup (f ` UNIV) + Sup (g ` UNIV)" + by (simp add: SUP_eq_iff SUP_ereal_add_left pos(2)) + finally show ?thesis . +qed lemma INF_eq_minf: "(INF i\I. f i::ereal) \ -\ \ (\b>-\. \i\I. b \ f i)" unfolding bot_ereal_def[symmetric] INF_eq_bot_iff by (auto simp: not_less) @@ -2328,11 +2250,8 @@ assumes nonneg: "\i. i \ I \ 0 \ f i" "\i. i \ I \ 0 \ g i" assumes directed: "\i j. i \ I \ j \ I \ \k\I. f i + g j \ f k + g k" shows "(INF i\I. f i + g i) = (INF i\I. f i) + (INF i\I. g i)" -proof cases - assume "I = {}" then show ?thesis - by (simp add: top_ereal_def) -next - assume "I \ {}" +proof (cases "I = {}") + case False show ?thesis proof (rule antisym) show "(INF i\I. f i) + (INF i\I. g i) \ (INF i\I. f i + g i)" @@ -2346,7 +2265,7 @@ using nonneg by (intro INF_ereal_add_left \I \ {}\) (auto simp: INF_eq_minf intro!: exI[of _ 0]) finally show "(INF i\I. f i + g i) \ (INF i\I. f i) + (INF i\I. g i)" . qed -qed +qed (simp add: top_ereal_def) lemma INF_ereal_add: fixes f :: "nat \ ereal" @@ -2363,34 +2282,24 @@ also have "\ = Inf (f ` UNIV) + Inf (g ` UNIV)" unfolding ereal_INF_uminus_eq using assms INF_less - by (subst SUP_ereal_add) (auto simp: ereal_SUP_uminus fin *) + by (subst SUP_ereal_add) (auto simp: ereal_SUP_uminus_eq fin *) finally show ?thesis . qed lemma SUP_ereal_add_pos: fixes f g :: "nat \ ereal" - assumes inc: "incseq f" "incseq g" - and pos: "\i. 0 \ f i" "\i. 0 \ g i" + assumes "incseq f" "incseq g" + and "\i. 0 \ f i" "\i. 0 \ g i" shows "(SUP i. f i + g i) = Sup (f ` UNIV) + Sup (g ` UNIV)" -proof (intro SUP_ereal_add inc) - fix i - show "f i \ -\" "g i \ -\" - using pos[of i] by auto -qed + by (simp add: SUP_ereal_add assms) lemma SUP_ereal_sum: fixes f g :: "'a \ nat \ ereal" assumes "\n. n \ A \ incseq (f n)" and pos: "\n i. n \ A \ 0 \ f n i" shows "(SUP i. \n\A. f n i) = (\n\A. Sup ((f n) ` UNIV))" -proof (cases "finite A") - case True - then show ?thesis using assms - by induct (auto simp: incseq_sumI2 sum_nonneg SUP_ereal_add_pos) -next - case False - then show ?thesis by simp -qed + using assms + by (induction A rule: infinite_finite_induct) (auto simp: incseq_sumI2 sum_nonneg SUP_ereal_add_pos) lemma SUP_ereal_mult_left: fixes f :: "'a \ ereal" @@ -2454,18 +2363,11 @@ then obtain f where f: "?P f" .. then have "range f \ A" "incseq f" by (auto simp: incseq_Suc_iff) - moreover - have "(SUP i. f i) = Sup A" - proof (rule tendsto_unique) - show "f \ (SUP i. f i)" - by (rule LIMSEQ_SUP \incseq f\)+ - show "f \ Sup A" - using l f - by (intro tendsto_sandwich[OF _ _ l_Sup tendsto_const]) - (auto simp: Sup_upper) - qed simp - ultimately show ?thesis - by auto + then have "(SUP i. f i) = Sup A" + by (meson LIMSEQ_SUP LIMSEQ_le Sup_subset_mono f l_Sup + order_class.order_eq_iff) + then show ?thesis + by (metis \incseq f\ \range f \ A\) qed lemma Inf_countable_INF: @@ -2534,7 +2436,7 @@ lemmas ereal_of_enat_pushout = ereal_of_enat_pushin[symmetric] lemma ereal_of_enat_nonneg: "ereal_of_enat n \ 0" -by(cases n) simp_all + by simp lemma ereal_of_enat_Sup: assumes "A \ {}" shows "ereal_of_enat (Sup A) = (SUP a \ A. ereal_of_enat a)" @@ -2584,15 +2486,11 @@ by (intro exI[of _ "max x z"]) fastforce next case (Basis S) - { - fix x - have "x \ \ \ \t. x \ ereal t" - by (cases x) auto - } - moreover note Basis + moreover have "x \ \ \ \t. x \ ereal t" for x + by (cases x) auto ultimately show ?case by (auto split: ereal.split) -qed (fastforce simp add: vimage_Union)+ +qed (fastforce simp: vimage_Union)+ lemma open_MInfty: "open A \ -\ \ A \ (\x. {.. A)" unfolding open_ereal_generated @@ -2604,15 +2502,11 @@ by (intro exI[of _ "min x z"]) fastforce next case (Basis S) - { - fix x - have "x \ - \ \ \t. ereal t \ x" - by (cases x) auto - } - moreover note Basis + moreover have "x \ -\ \ \t. ereal t \ x" for x + by (cases x) auto ultimately show ?case by (auto split: ereal.split) -qed (fastforce simp add: vimage_Union)+ +qed (fastforce simp: vimage_Union)+ lemma open_ereal_vimage: "open S \ open (ereal -` S)" by (intro open_vimage continuous_intros) @@ -2627,7 +2521,7 @@ using less_ereal.elims(2) by fastforce ultimately show ?case by auto -qed (auto simp add: image_Union image_Int) +qed (auto simp: image_Union image_Int) lemma open_image_real_of_ereal: fixes X::"ereal set" @@ -2674,14 +2568,12 @@ qed lemma open_PInfty2: - assumes "open A" - and "\ \ A" + assumes "open A" and "\ \ A" obtains x where "{ereal x<..} \ A" using open_PInfty[OF assms] by auto lemma open_MInfty2: - assumes "open A" - and "-\ \ A" + assumes "open A" and "-\ \ A" obtains x where "{.. A" using open_MInfty[OF assms] by auto @@ -2727,17 +2619,9 @@ lemma ereal_open_cont_interval2: fixes S :: "ereal set" - assumes "open S" - and "x \ S" - and x: "\x\ \ \" + assumes "open S" and "x \ S" and "\x\ \ \" obtains a b where "a < x" and "x < b" and "{a <..< b} \ S" -proof - - obtain e where "0 < e" "{x - e<.. S" - using assms by (rule ereal_open_cont_interval) - with that[of "x - e" "x + e"] ereal_between[OF x, of e] - show thesis - by auto -qed + by (meson assms ereal_between ereal_open_cont_interval) subsubsection \Convergent sequences\ @@ -2768,10 +2652,10 @@ lemma tendsto_PInfty: "(f \ \) F \ (\r. eventually (\x. ereal r < f x) F)" proof - - { - fix l :: ereal + { fix l :: ereal assume "\r. eventually (\x. ereal r < f x) F" - from this[THEN spec, of "real_of_ereal l"] have "l \ \ \ eventually (\x. l < f x) F" + from this[THEN spec, of "real_of_ereal l"] + have "l \ \ \ eventually (\x. l < f x) F" by (cases l) (auto elim: eventually_mono) } then show ?thesis @@ -2779,19 +2663,16 @@ qed lemma tendsto_PInfty': "(f \ \) F = (\r>c. eventually (\x. ereal r < f x) F)" -proof (subst tendsto_PInfty, intro iffI allI impI) - assume A: "\r>c. eventually (\x. ereal r < f x) F" - fix r :: real - from A have A: "eventually (\x. ereal r < f x) F" if "r > c" for r using that by blast - show "eventually (\x. ereal r < f x) F" - proof (cases "r > c") - case False - hence B: "ereal r \ ereal (c + 1)" by simp - have "c < c + 1" by simp - from A[OF this] show "eventually (\x. ereal r < f x) F" - by eventually_elim (rule le_less_trans[OF B]) - qed (simp add: A) -qed simp +proof - + { fix r :: real + assume "\r>c. eventually (\x. ereal r < f x) F" + then have "eventually (\x. ereal r < f x) F" + if "r > c" for r using that by blast + then have "eventually (\x. ereal r < f x) F" + by (smt (verit, del_insts) ereal_less_le eventually_mono gt_ex) + } then show ?thesis + using tendsto_PInfty by blast +qed lemma tendsto_PInfty_eq_at_top: "((\z. ereal (f z)) \ \) F \ (LIM z F. f z :> at_top)" @@ -2998,18 +2879,18 @@ lemma ereal_less_divide_pos: fixes x y :: ereal shows "x > 0 \ x \ \ \ y < z / x \ x * y < z" - by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) + by (simp add: ereal_less_divide_iff mult.commute) lemma ereal_divide_less_pos: fixes x y z :: ereal shows "x > 0 \ x \ \ \ y / x < z \ y < x * z" - by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps) + by (simp add: ereal_divide_less_iff mult.commute) lemma ereal_divide_eq: fixes a b c :: ereal shows "b \ 0 \ \b\ \ \ \ a / b = c \ a = b * c" - by (cases rule: ereal3_cases[of a b c]) - (simp_all add: field_simps) + by (metis ereal_divide_same ereal_times_divide_eq mult.commute + mult.right_neutral) lemma ereal_inverse_not_MInfty[simp]: "inverse (a::ereal) \ -\" by (cases a) auto @@ -3023,15 +2904,7 @@ using assms by auto lemma real_ereal_id: "real_of_ereal \ ereal = id" -proof - - { - fix x - have "(real_of_ereal \ ereal) x = id x" - by auto - } - then show ?thesis - using ext by blast -qed + by auto lemma open_image_ereal: "open(UNIV-{ \ , (-\ :: ereal)})" by (metis range_ereal open_ereal open_UNIV) @@ -3040,7 +2913,7 @@ fixes a b c :: ereal shows "c * (a + b) \ c * a + c * b" by (cases rule: ereal3_cases[of a b c]) - (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff) + (auto simp: field_simps not_le mult_le_0_iff mult_less_0_iff) lemma ereal_pos_distrib: fixes a b c :: ereal @@ -3049,7 +2922,7 @@ shows "c * (a + b) = c * a + c * b" using assms by (cases rule: ereal3_cases[of a b c]) - (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff) + (auto simp: field_simps not_le mult_le_0_iff mult_less_0_iff) lemma ereal_LimI_finite: fixes x :: ereal @@ -3092,12 +2965,9 @@ qed lemma tendsto_obtains_N: - assumes "f \ f0" - assumes "open S" - and "f0 \ S" + assumes "f \ f0" "open S" "f0 \ S" obtains N where "\n\N. f n \ S" - using assms using tendsto_def - using lim_explicit[of f f0] assms by auto + using assms lim_explicit by blast lemma ereal_LimI_finite_iff: fixes x :: ereal @@ -3110,10 +2980,8 @@ fix r :: ereal assume "r > 0" then obtain N where "\n\N. u n \ {x - r <..< x + r}" - apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) - using lim ereal_between[of x r] assms \r > 0\ - apply auto - done + using lim ereal_between[of x r] assms \r > 0\ tendsto_obtains_N[of u x "{x - r <..< x + r}"] + by auto then have "\N. \n\N. u n < x + r \ x < u n + r" using ereal_minus_less[of r x] by (cases r) auto @@ -3129,7 +2997,7 @@ lemma ereal_Limsup_uminus: fixes f :: "'a \ ereal" shows "Limsup net (\x. - (f x)) = - Liminf net f" - unfolding Limsup_def Liminf_def ereal_SUP_uminus ereal_INF_uminus_eq .. + unfolding Limsup_def Liminf_def ereal_SUP_uminus_eq ereal_INF_uminus_eq .. lemma liminf_bounded_iff: fixes x :: "nat \ ereal" @@ -3148,7 +3016,7 @@ let ?INF = "\P g. Inf (g ` (Collect P))" show "?F \ {}" by (auto intro: eventually_True) - show "(SUP P\?F. ?INF P g) \ - \" + show "(SUP P\?F. ?INF P g) \ -\" unfolding bot_ereal_def[symmetric] SUP_bot_conv INF_eq_bot_iff by (auto intro!: exI[of _ 0] ev simp: bot_ereal_def) have "(SUP P\?F. ?INF P f + (SUP P\?F. ?INF P g)) \ (SUP P\?F. (SUP P'\?F. ?INF P f + ?INF P' g))" @@ -3161,7 +3029,7 @@ by (intro add_mono INF_mono) auto also have "\ = (SUP P'\?F. ?INF ?P' f + ?INF P' g)" proof (rule SUP_ereal_add_right[symmetric]) - show "Inf (f ` {x. P x \ 0 \ f x}) \ - \" + show "Inf (f ` {x. P x \ 0 \ f x}) \ -\" unfolding bot_ereal_def[symmetric] INF_eq_bot_iff by (auto intro!: exI[of _ 0] ev simp: bot_ereal_def) qed fact @@ -3186,7 +3054,7 @@ and x: "x \ 0" shows "(SUP i\Y. f i) * ereal x = (SUP i\Y. f i * ereal x)" (is "?lhs = ?rhs") proof(cases "x = 0") - case True thus ?thesis by(auto simp add: nonempty zero_ereal_def[symmetric]) + case True thus ?thesis by(auto simp: nonempty zero_ereal_def[symmetric]) next case False show ?thesis @@ -3216,7 +3084,7 @@ lemma Sup_ereal_mult_left': "\ Y \ {}; x \ 0 \ \ ereal x * (SUP i\Y. f i) = (SUP i\Y. ereal x * f i)" -by(subst (1 2) mult.commute)(rule Sup_ereal_mult_right') + by (smt (verit) Sup.SUP_cong Sup_ereal_mult_right' mult.commute) lemma sup_continuous_add[order_continuous_intros]: fixes f g :: "'a::complete_lattice \ ereal" @@ -3240,9 +3108,10 @@ using sup_continuous_mult_right[of c f] by (simp add: mult_ac) lemma sup_continuous_ereal_of_enat[order_continuous_intros]: - assumes f: "sup_continuous f" shows "sup_continuous (\x. ereal_of_enat (f x))" - by (rule sup_continuous_compose[OF _ f]) - (auto simp: sup_continuous_def ereal_of_enat_SUP) + assumes f: "sup_continuous f" + shows "sup_continuous (\x. ereal_of_enat (f x))" + by (metis UNIV_not_empty ereal_of_enat_SUP f sup_continuous_compose + sup_continuous_def) subsubsection \Sums\ @@ -3250,14 +3119,7 @@ fixes f :: "nat \ ereal" assumes "\i. 0 \ f i" shows "f sums (SUP n. \ii. \j=0.. ereal" @@ -3279,32 +3141,17 @@ lemma suminf_bound: fixes f :: "nat \ ereal" - assumes "\N. (\n x" - and pos: "\n. 0 \ f n" + assumes "\N. (\n x" "\n. 0 \ f n" shows "suminf f \ x" -proof (rule Lim_bounded) - have "summable f" using pos[THEN summable_ereal_pos] . - then show "(\N. \n suminf f" - by (auto dest!: summable_sums simp: sums_def atLeast0LessThan) - show "\n\0. sum f {.. x" - using assms by auto -qed + by (simp add: SUP_least assms suminf_ereal_eq_SUP) lemma suminf_bound_add: fixes f :: "nat \ ereal" assumes "\N. (\n x" - and pos: "\n. 0 \ f n" + and "\n. 0 \ f n" and "y \ -\" shows "suminf f + y \ x" -proof (cases y) - case (real r) - then have "\N. (\n x - y" - using assms by (simp add: ereal_le_minus) - then have "(\ n. f n) \ x - y" - using pos by (rule suminf_bound) - then show "(\ n. f n) + y \ x" - using assms real by (simp add: ereal_le_minus) -qed (insert assms, auto) + by (simp add: SUP_ereal_le_addI assms suminf_ereal_eq_SUP) lemma suminf_upper: fixes f :: "nat \ ereal" @@ -3325,20 +3172,7 @@ assumes "\N. f N \ g N" and "\N. 0 \ f N" shows "suminf f \ suminf g" -proof (safe intro!: suminf_bound) - fix n - { - fix N - have "0 \ g N" - using assms(2,1)[of N] by auto - } - have "sum f {.. sum g {.. \ suminf g" - using \\N. 0 \ g N\ - by (rule suminf_upper) - finally show "sum f {.. suminf g" . -qed (rule assms(2)) + by (meson assms order_trans suminf_le summable_ereal_pos) lemma suminf_half_series_ereal: "(\n. (1/2 :: ereal) ^ Suc n) = 1" using sums_ereal[THEN iffD2, OF power_half_series, THEN sums_unique, symmetric] @@ -3353,17 +3187,14 @@ unfolding sum.distrib by (intro assms add_nonneg_nonneg SUP_ereal_add_pos incseq_sumI sum_nonneg ballI) with assms show ?thesis - by (subst (1 2 3) suminf_ereal_eq_SUP) auto + by (simp add: suminf_ereal_eq_SUP) qed lemma suminf_cmult_ereal: fixes f g :: "nat \ ereal" - assumes "\i. 0 \ f i" - and "0 \ a" + assumes "\i. 0 \ f i" and "0 \ a" shows "(\i. a * f i) = a * suminf f" - by (auto simp: sum_ereal_right_distrib[symmetric] assms - ereal_zero_le_0_iff sum_nonneg suminf_ereal_eq_SUP - intro!: SUP_ereal_mult_left) + by (simp add: assms sum_nonneg suminf_ereal_eq_SUP sum_ereal_right_distrib flip: SUP_ereal_mult_left) lemma suminf_PInfty: fixes f :: "nat \ ereal" @@ -3384,14 +3215,9 @@ shows "\f'. f = (\x. ereal (f' x))" proof - have "\i. \r. f i = ereal r" - proof - fix i - show "\r. f i = ereal r" - using suminf_PInfty[OF assms] assms(1)[of i] - by (cases "f i") auto - qed - from choice[OF this] show ?thesis - by auto + by (metis abs_ereal_ge0 abs_neq_infinity_cases assms suminf_PInfty) + then show ?thesis + by metis qed lemma summable_ereal: @@ -3431,19 +3257,15 @@ and fin: "suminf f \ \" "suminf g \ \" shows "(\i. f i - g i) = suminf f - suminf g" proof - - { - fix i - have "0 \ f i" - using ord[of i] by auto - } + have 0: "0 \ f i" for i + using ord order_trans by blast moreover - from suminf_PInfty_fun[OF \\i. 0 \ f i\ fin(1)] obtain f' where [simp]: "f = (\x. ereal (f' x))" .. - from suminf_PInfty_fun[OF \\i. 0 \ g i\ fin(2)] obtain g' where [simp]: "g = (\x. ereal (g' x))" .. - { - fix i - have "0 \ f i - g i" - using ord[of i] by (auto simp: ereal_le_minus_iff) - } + obtain f' where [simp]: "f = (\x. ereal (f' x))" + using 0 fin(1) suminf_PInfty_fun by presburger + obtain g' where [simp]: "g = (\x. ereal (g' x))" + using fin(2) ord(2) suminf_PInfty_fun by presburger + have "0 \ f i - g i" for i + using ord(1) by auto moreover have "suminf (\i. f i - g i) \ suminf f" using assms by (auto intro!: suminf_le_pos simp: field_simps) @@ -3458,12 +3280,7 @@ qed lemma suminf_ereal_PInf [simp]: "(\x. \::ereal) = \" -proof - - have "(\i) \ (\x. \::ereal)" - by (rule suminf_upper) auto - then show ?thesis - by simp -qed + by (metis ereal_less_eq(1) suminf_PInfty) lemma summable_real_of_ereal: fixes f :: "nat \ ereal" @@ -3475,14 +3292,8 @@ using assms by (auto intro: suminf_0_le) with fin obtain r where r: "ereal r = (\i. f i)" by (cases "(\i. f i)") auto - { - fix i - have "f i \ \" - using f by (intro suminf_PInfty[OF _ fin]) auto - then have "\f i\ \ \" - using f[of i] by auto - } - note fin = this + have fin: "\f i\ \ \" for i + by (simp add: assms(2) f suminf_PInfty) have "(\i. ereal (real_of_ereal (f i))) sums (\i. ereal (real_of_ereal (f i)))" using f by (auto intro!: summable_ereal_pos simp: ereal_le_real_iff zero_ereal_def) @@ -3503,24 +3314,15 @@ by (auto intro!: SUP_ereal_sum [symmetric]) show ?thesis using assms - apply (subst (1 2) suminf_ereal_eq_SUP) - apply (auto intro!: SUP_upper2 SUP_commute simp: *) - done + by (auto simp: suminf_ereal_eq_SUP SUP_upper2 * intro!: SUP_commute) qed lemma suminf_sum_ereal: fixes f :: "_ \ _ \ ereal" assumes nonneg: "\i a. a \ A \ 0 \ f i a" shows "(\i. \a\A. f i a) = (\a\A. \i. f i a)" -proof (cases "finite A") - case True - then show ?thesis - using nonneg - by induct (simp_all add: suminf_add_ereal sum_nonneg) -next - case False - then show ?thesis by simp -qed + using nonneg +by (induction A rule: infinite_finite_induct; simp add: suminf_add_ereal sum_nonneg) lemma suminf_ereal_eq_0: fixes f :: "nat \ ereal" @@ -3583,12 +3385,7 @@ lemma suminf_ereal_finite_neg: assumes "summable f" shows "(\x. ereal (f x)) \ -\" -proof- - from assms obtain x where "f sums x" by blast - hence "(\x. ereal (f x)) sums ereal x" by (simp add: sums_ereal) - from sums_unique[OF this] have "(\x. ereal (f x)) = ereal x" .. - thus "(\x. ereal (f x)) \ -\" by simp_all -qed + by (simp add: assms suminf_ereal') lemma SUP_ereal_add_directed: fixes f g :: "'a \ ereal" @@ -3685,7 +3482,7 @@ by (auto simp: image_iff ereal_uminus_eq_reorder) then show "open (range uminus :: ereal set)" by simp -qed (auto simp add: image_Union image_Int) +qed (auto simp: image_Union image_Int) lemma ereal_uminus_complement: fixes S :: "ereal set" @@ -3864,7 +3661,7 @@ and at_right_MInf: "at_right (-\) = filtermap ereal at_bot" unfolding filter_eq_iff eventually_filtermap eventually_at_top_dense eventually_at_bot_dense eventually_at_left[OF ereal_less(5)] eventually_at_right[OF ereal_less(6)] - by (auto simp add: ereal_all_split ereal_ex_split) + by (auto simp: ereal_all_split ereal_ex_split) lemma ereal_tendsto_simps1: "((f \ real_of_ereal) \ y) (at_left (ereal x)) \ (f \ y) (at_left x)" @@ -3998,7 +3795,7 @@ from assms show "continuous_on UNIV (\a. a * ereal c)" using tendsto_cmult_ereal[of "ereal c" "\x. x" ] by (force simp: continuous_on_def mult_ac) -qed (insert assms, auto simp: mono_def ereal_mult_right_mono) +qed (use assms in \auto simp: mono_def ereal_mult_right_mono\) lemma Liminf_ereal_mult_right: assumes "F \ bot" "(c::real) \ 0" @@ -4025,7 +3822,7 @@ lemma limsup_ereal_mult_left: "(c::real) \ 0 \ limsup (\n. ereal c * f n) = ereal c * limsup f" - by (subst (1 2) mult.commute, rule limsup_ereal_mult_right) simp_all + by (simp add: Limsup_ereal_mult_left) lemma Limsup_add_ereal_right: "F \ bot \ abs c \ \ \ Limsup F (\n. g n + (c :: ereal)) = Limsup F g + c" @@ -4081,45 +3878,39 @@ by(cases a) simp_all lemma not_infty_ereal: "\x\ \ \ \ (\x'. x = ereal x')" -by(cases x) simp_all + by auto lemma neq_PInf_trans: fixes x y :: ereal shows "\ y \ \; x \ y \ \ x \ \" -by auto + by auto lemma mult_2_ereal: "ereal 2 * x = x + x" -by(cases x) simp_all + by(cases x) simp_all lemma ereal_diff_le_self: "0 \ y \ x - y \ (x :: ereal)" -by(cases x y rule: ereal2_cases) simp_all + by(cases x y rule: ereal2_cases) simp_all lemma ereal_le_add_self: "0 \ y \ x \ x + (y :: ereal)" -by(cases x y rule: ereal2_cases) simp_all + by(cases x y rule: ereal2_cases) simp_all lemma ereal_le_add_self2: "0 \ y \ x \ y + (x :: ereal)" -by(cases x y rule: ereal2_cases) simp_all - -lemma ereal_le_add_mono1: "\ x \ y; 0 \ (z :: ereal) \ \ x \ y + z" -using add_mono by fastforce - -lemma ereal_le_add_mono2: "\ x \ z; 0 \ (y :: ereal) \ \ x \ y + z" -using add_mono by fastforce + by(cases x y rule: ereal2_cases) simp_all lemma ereal_diff_nonpos: fixes a b :: ereal shows "\ a \ b; a = \ \ b \ \; a = -\ \ b \ -\ \ \ a - b \ 0" by (cases rule: ereal2_cases[of a b]) auto lemma minus_ereal_0 [simp]: "x - ereal 0 = x" -by(simp flip: zero_ereal_def) + by(simp flip: zero_ereal_def) lemma ereal_diff_eq_0_iff: fixes a b :: ereal shows "(\a\ = \ \ \b\ \ \) \ a - b = 0 \ a = b" -by(cases a b rule: ereal2_cases) simp_all + by(cases a b rule: ereal2_cases) simp_all lemma SUP_ereal_eq_0_iff_nonneg: fixes f :: "_ \ ereal" and A assumes nonneg: "\x\A. f x \ 0" - and A:"A \ {}" - shows "(SUP x\A. f x) = 0 \ (\x\A. f x = 0)" (is "?lhs \ ?rhs") + and A:"A \ {}" + shows "(SUP x\A. f x) = 0 \ (\x\A. f x = 0)" (is "?lhs \ _") proof(intro iffI ballI) fix x assume "?lhs" "x \ A" @@ -4129,32 +3920,38 @@ lemma ereal_divide_le_posI: fixes x y z :: ereal - shows "x > 0 \ z \ - \ \ z \ x * y \ z / x \ y" -by (cases rule: ereal3_cases[of x y z])(auto simp: field_simps split: if_split_asm) - -lemma add_diff_eq_ereal: fixes x y z :: ereal + shows "x > 0 \ z \ -\ \ z \ x * y \ z / x \ y" + by (cases rule: ereal3_cases[of x y z])(auto simp: field_simps split: if_split_asm) + +lemma add_diff_eq_ereal: + fixes x y z :: ereal shows "x + (y - z) = x + y - z" -by(cases x y z rule: ereal3_cases) simp_all + by(cases x y z rule: ereal3_cases) simp_all lemma ereal_diff_gr0: - fixes a b :: ereal shows "a < b \ 0 < b - a" + fixes a b :: ereal + shows "a < b \ 0 < b - a" by (cases rule: ereal2_cases[of a b]) auto -lemma ereal_minus_minus: fixes x y z :: ereal shows +lemma ereal_minus_minus: + fixes x y z :: ereal shows "(\y\ = \ \ \z\ \ \) \ x - (y - z) = x + z - y" -by(cases x y z rule: ereal3_cases) simp_all - -lemma diff_add_eq_ereal: fixes a b c :: ereal shows "a - b + c = a + c - b" -by(cases a b c rule: ereal3_cases) simp_all - -lemma diff_diff_commute_ereal: fixes x y z :: ereal shows "x - y - z = x - z - y" -by(cases x y z rule: ereal3_cases) simp_all - -lemma ereal_diff_eq_MInfty_iff: fixes x y :: ereal shows "x - y = -\ \ x = -\ \ y \ -\ \ y = \ \ \x\ \ \" -by(cases x y rule: ereal2_cases) simp_all - -lemma ereal_diff_add_inverse: fixes x y :: ereal shows "\x\ \ \ \ x + y - x = y" -by(cases x y rule: ereal2_cases) simp_all + by(cases x y z rule: ereal3_cases) simp_all + +lemma diff_diff_commute_ereal: + fixes x y z :: ereal + shows "x - y - z = x - z - y" + by (metis add_diff_eq_ereal ereal_add_uminus_conv_diff) + +lemma ereal_diff_eq_MInfty_iff: + fixes x y :: ereal + shows "x - y = -\ \ x = -\ \ y \ -\ \ y = \ \ \x\ \ \" + by(cases x y rule: ereal2_cases) simp_all + +lemma ereal_diff_add_inverse: + fixes x y :: ereal + shows "\x\ \ \ \ x + y - x = y" + by(cases x y rule: ereal2_cases) simp_all lemma tendsto_diff_ereal: fixes x y :: ereal @@ -4186,7 +3983,7 @@ text \A small list of simple arithmetic expressions.\ -value "- \ :: ereal" +value "-\ :: ereal" value "\-\\ :: ereal" value "4 + 5 / 4 - ereal 2 :: ereal" value "ereal 3 < \" diff -r 8d790d757bfb -r 2cf8f8e4c1fd src/HOL/Library/Word.thy --- a/src/HOL/Library/Word.thy Fri Jan 10 21:08:18 2025 +0100 +++ b/src/HOL/Library/Word.thy Sun Jan 12 21:16:09 2025 +0000 @@ -99,20 +99,10 @@ proof - have even_word_unfold: "even k \ (\l. take_bit LENGTH('a) k = take_bit LENGTH('a) (2 * l))" (is "?P \ ?Q") for k :: int - proof - assume ?P - then show ?Q - by auto - next - assume ?Q - then obtain l where "take_bit LENGTH('a) k = take_bit LENGTH('a) (2 * l)" .. - then have "even (take_bit LENGTH('a) k)" - by simp - then show ?P - by simp - qed - show ?thesis by (simp only: even_word_unfold [abs_def] dvd_def [where ?'a = "'a word", abs_def]) - transfer_prover + by (metis dvd_triv_left evenE even_take_bit_eq len_not_eq_0) + show ?thesis + unfolding even_word_unfold [abs_def] dvd_def [where ?'a = "'a word", abs_def] + by transfer_prover qed end @@ -898,26 +888,17 @@ for a b :: \'a::len word\ using that by transfer (auto simp: nat_less_le bit_eq_iff bit_take_bit_iff) -lemma bit_imp_le_length: - \n < LENGTH('a)\ if \bit w n\ - for w :: \'a::len word\ - using that by transfer simp +lemma bit_imp_le_length: \n < LENGTH('a)\ if \bit w n\ for w :: \'a::len word\ + by (meson bit_word.rep_eq that) lemma not_bit_length [simp]: \\ bit w LENGTH('a)\ for w :: \'a::len word\ - by transfer simp + using bit_imp_le_length by blast lemma finite_bit_word [simp]: \finite {n. bit w n}\ for w :: \'a::len word\ -proof - - have \{n. bit w n} \ {0..LENGTH('a)}\ - by (auto dest: bit_imp_le_length) - moreover have \finite {0..LENGTH('a)}\ - by simp - ultimately show ?thesis - by (rule finite_subset) -qed + by (metis bit_imp_le_length bounded_nat_set_is_finite mem_Collect_eq) lemma bit_numeral_word_iff [simp]: \bit (numeral w :: 'a::len word) n @@ -969,16 +950,7 @@ proof - show \take_bit LENGTH('a) (push_bit n k) = take_bit LENGTH('a) (push_bit n l)\ if \take_bit LENGTH('a) k = take_bit LENGTH('a) l\ for k l :: int and n :: nat - proof - - from that - have \take_bit (LENGTH('a) - n) (take_bit LENGTH('a) k) - = take_bit (LENGTH('a) - n) (take_bit LENGTH('a) l)\ - by simp - moreover have \min (LENGTH('a) - n) LENGTH('a) = LENGTH('a) - n\ - by simp - ultimately show ?thesis - by (simp add: take_bit_push_bit) - qed + by (metis le_add2 push_bit_take_bit take_bit_tightened that) qed lift_definition drop_bit_word :: \nat \ 'a word \ 'a word\ @@ -1335,12 +1307,7 @@ lemma uint_div_distrib: \uint (v div w) = uint v div uint w\ -proof - - have \int (unat (v div w)) = int (unat v div unat w)\ - by (simp add: unat_div_distrib) - then show ?thesis - by (simp add: of_nat_div) -qed + by (metis int_ops(8) of_nat_unat unat_div_distrib) lemma unat_drop_bit_eq: \unat (drop_bit n w) = drop_bit n (unat w)\ @@ -1348,12 +1315,7 @@ lemma uint_mod_distrib: \uint (v mod w) = uint v mod uint w\ -proof - - have \int (unat (v mod w)) = int (unat v mod unat w)\ - by (simp add: unat_mod_distrib) - then show ?thesis - by (simp add: of_nat_mod) -qed + by (metis int_ops(9) of_nat_unat unat_mod_distrib) context semiring_bit_operations begin @@ -1570,18 +1532,8 @@ fix k :: int show \take_bit LENGTH('a) (take_bit LENGTH('a) 1 div take_bit LENGTH('a) k) = take_bit LENGTH('a) (of_bool (take_bit LENGTH('a) k = take_bit LENGTH('a) 1))\ - proof (cases \take_bit LENGTH('a) k > 1\) - case False - with take_bit_nonnegative [of \LENGTH('a)\ k] - have \take_bit LENGTH('a) k = 0 \ take_bit LENGTH('a) k = 1\ - by linarith - then show ?thesis - by auto - next - case True - then show ?thesis - by simp - qed + using take_bit_nonnegative [of \LENGTH('a)\ k] + by (smt (verit, best) div_by_1 of_bool_eq take_bit_of_0 take_bit_of_1 zdiv_eq_0_iff) qed lemma mod_word_one [simp]: @@ -1594,17 +1546,7 @@ lemma mod_word_by_minus_1_eq [simp]: \w mod - 1 = w * of_bool (w < - 1)\ for w :: \'a::len word\ -proof (cases \w = - 1\) - case True - then show ?thesis - by simp -next - case False - moreover have \w < - 1\ - using False by (simp add: word_order.not_eq_extremum) - ultimately show ?thesis - by (simp add: mod_word_less) -qed + using mod_word_less word_order.not_eq_extremum by fastforce text \Legacy theorems:\ @@ -1776,12 +1718,12 @@ lemma wi_less: "(word_of_int n < (word_of_int m :: 'a::len word)) = (n mod 2 ^ LENGTH('a) < m mod 2 ^ LENGTH('a))" - by transfer (simp add: take_bit_eq_mod) + by (simp add: uint_word_of_int word_less_def) lemma wi_le: "(word_of_int n \ (word_of_int m :: 'a::len word)) = (n mod 2 ^ LENGTH('a) \ m mod 2 ^ LENGTH('a))" - by transfer (simp add: take_bit_eq_mod) + by (simp add: uint_word_of_int word_le_def) subsection \Bit-wise operations\ @@ -1790,21 +1732,17 @@ includes bit_operations_syntax begin -lemma uint_take_bit_eq: - \uint (take_bit n w) = take_bit n (uint w)\ - by transfer (simp add: ac_simps) - lemma take_bit_word_eq_self: \take_bit n w = w\ if \LENGTH('a) \ n\ for w :: \'a::len word\ using that by transfer simp lemma take_bit_length_eq [simp]: \take_bit LENGTH('a) w = w\ for w :: \'a::len word\ - by (rule take_bit_word_eq_self) simp + by (simp add: nat_le_linear take_bit_word_eq_self) lemma bit_word_of_int_iff: \bit (word_of_int k :: 'a::len word) n \ n < LENGTH('a) \ bit k n\ - by transfer rule + by (metis Word_eq_word_of_int bit_word.abs_eq) lemma bit_uint_iff: \bit (uint w) n \ n < LENGTH('a) \ bit w n\ @@ -1819,13 +1757,13 @@ lemma bit_word_ucast_iff: \bit (ucast w :: 'b::len word) n \ n < LENGTH('a) \ n < LENGTH('b) \ bit w n\ for w :: \'a::len word\ - by transfer (simp add: bit_take_bit_iff ac_simps) + by (meson bit_imp_possible_bit bit_unsigned_iff possible_bit_word) lemma bit_word_scast_iff: \bit (scast w :: 'b::len word) n \ n < LENGTH('b) \ (bit w n \ LENGTH('a) \ n \ bit w (LENGTH('a) - Suc 0))\ for w :: \'a::len word\ - by transfer (auto simp: bit_signed_take_bit_iff le_less min_def) + by (metis One_nat_def bit_sint_iff bit_word_of_int_iff of_int_sint) lemma bit_word_iff_drop_bit_and [code]: \bit a n \ drop_bit n a AND 1 = 1\ for a :: \'a::len word\ @@ -1848,7 +1786,8 @@ lemma map_bit_range_eq_if_take_bit_eq: \map (bit k) [0.. if \take_bit n k = take_bit n l\ for k l :: int -using that proof (induction n arbitrary: k l) + using that +proof (induction n arbitrary: k l) case 0 then show ?case by simp @@ -1861,7 +1800,7 @@ moreover have \bit (r div 2) = bit r \ Suc\ for r :: int by (simp add: fun_eq_iff bit_Suc) moreover from Suc.prems have \even k \ even l\ - by (auto simp: take_bit_Suc elim!: evenE oddE) arith+ + by (metis Zero_neq_Suc even_take_bit_eq) ultimately show ?case by (simp only: map_Suc_upt upt_conv_Cons flip: list.map_comp) (simp add: bit_0) qed @@ -1917,10 +1856,9 @@ \bit (signed_drop_bit m w) n \ bit w (if LENGTH('a) - m \ n \ n < LENGTH('a) then LENGTH('a) - 1 else m + n)\ for w :: \'a::len word\ apply transfer - apply (auto simp: bit_drop_bit_eq bit_signed_take_bit_iff not_le min_def) - apply (metis Suc_pred add.commute le_less_Suc_eq len_gt_0 less_diff_conv) - apply (metis le_antisym less_eq_decr_length_iff) - done + apply (simp add: bit_drop_bit_eq bit_signed_take_bit_iff not_le min_def) + by (metis add.commute add_lessD1 le_antisym less_diff_conv less_eq_decr_length_iff + nat_less_le) lemma [code]: \Word.the_int (signed_drop_bit n w) = take_bit LENGTH('a) (drop_bit n (Word.the_signed_int w))\ @@ -1968,18 +1906,19 @@ lemma set_bit_eq_idem_iff: \Bit_Operations.set_bit n w = w \ bit w n \ n \ LENGTH('a)\ for w :: \'a::len word\ - by (simp add: bit_eq_iff) (auto simp: bit_simps not_le) + unfolding bit_eq_iff + by (auto simp: bit_simps not_le) lemma unset_bit_eq_idem_iff: \unset_bit n w = w \ bit w n \ n \ LENGTH('a)\ for w :: \'a::len word\ - by (simp add: bit_eq_iff) (auto simp: bit_simps dest: bit_imp_le_length) + unfolding bit_eq_iff + by (auto simp: bit_simps dest: bit_imp_le_length) lemma flip_bit_eq_idem_iff: \flip_bit n w = w \ n \ LENGTH('a)\ for w :: \'a::len word\ - using linorder_le_less_linear - by (simp add: bit_eq_iff) (auto simp: bit_simps) + by (simp add: flip_bit_eq_if set_bit_eq_idem_iff unset_bit_eq_idem_iff) subsection \Rotation\ @@ -1988,28 +1927,20 @@ is \\n k. concat_bit (LENGTH('a) - n mod LENGTH('a)) (drop_bit (n mod LENGTH('a)) (take_bit LENGTH('a) k)) (take_bit (n mod LENGTH('a)) k)\ - subgoal for n k l - by (simp add: concat_bit_def nat_le_iff less_imp_le - take_bit_tightened [of \LENGTH('a)\ k l \n mod LENGTH('a::len)\]) - done + using take_bit_tightened by fastforce lift_definition word_rotl :: \nat \ 'a::len word \ 'a::len word\ is \\n k. concat_bit (n mod LENGTH('a)) (drop_bit (LENGTH('a) - n mod LENGTH('a)) (take_bit LENGTH('a) k)) (take_bit (LENGTH('a) - n mod LENGTH('a)) k)\ - subgoal for n k l - by (simp add: concat_bit_def nat_le_iff less_imp_le - take_bit_tightened [of \LENGTH('a)\ k l \LENGTH('a) - n mod LENGTH('a::len)\]) - done + using take_bit_tightened by fastforce lift_definition word_roti :: \int \ 'a::len word \ 'a::len word\ is \\r k. concat_bit (LENGTH('a) - nat (r mod int LENGTH('a))) (drop_bit (nat (r mod int LENGTH('a))) (take_bit LENGTH('a) k)) (take_bit (nat (r mod int LENGTH('a))) k)\ - subgoal for r k l - by (simp add: concat_bit_def nat_le_iff less_imp_le - take_bit_tightened [of \LENGTH('a)\ k l \nat (r mod int LENGTH('a::len))\]) - done + by (smt (verit, best) len_gt_0 nat_le_iff of_nat_0_less_iff pos_mod_bound + take_bit_tightened) lemma word_rotl_eq_word_rotr [code]: \word_rotl n = (word_rotr (LENGTH('a) - n mod LENGTH('a)) :: 'a::len word \ 'a word)\ @@ -2177,12 +2108,12 @@ by transfer simp lemma word_numeral_alt: "numeral b = word_of_int (numeral b)" - by (induct b, simp_all only: numeral.simps word_of_int_homs) + by simp declare word_numeral_alt [symmetric, code_abbrev] lemma word_neg_numeral_alt: "- numeral b = word_of_int (- numeral b)" - by (simp only: word_numeral_alt wi_hom_neg) + by simp declare word_neg_numeral_alt [symmetric, code_abbrev] @@ -2269,18 +2200,14 @@ by (fact of_int_1) lemma word_of_int_neg_1 [simp]: "word_of_int (- 1) = - 1" - by (simp add: wi_hom_syms) + by simp lemma word_of_int_numeral [simp] : "(word_of_int (numeral bin) :: 'a::len word) = numeral bin" - by (fact of_int_numeral) - -lemma word_of_int_neg_numeral [simp]: - "(word_of_int (- numeral bin) :: 'a::len word) = - numeral bin" - by (fact of_int_neg_numeral) + by simp lemma word_int_case_wi: "word_int_case f (word_of_int i :: 'b word) = f (i mod 2 ^ LENGTH('b::len))" - by transfer (simp add: take_bit_eq_mod) + by (simp add: uint_word_of_int word_int_case_eq_uint) lemma word_int_split: "P (word_int_case f x) = @@ -2290,7 +2217,7 @@ lemma word_int_split_asm: "P (word_int_case f x) = (\n. x = (word_of_int n :: 'b::len word) \ 0 \ n \ n < 2 ^ LENGTH('b::len) \ \ P (f n))" - by transfer (auto simp: take_bit_eq_mod) + using word_int_split by auto lemma uint_range_size: "0 \ uint w \ uint w < 2 ^ size w" by transfer simp @@ -2316,7 +2243,7 @@ lemma bin_nth_uint_imp: "bit (uint w) n \ n < LENGTH('a)" for w :: "'a::len word" - by transfer (simp add: bit_take_bit_iff) + by (simp add: bit_uint_iff) lemma bin_nth_sint: "LENGTH('a) \ n \ @@ -2490,13 +2417,7 @@ lemma bit_last_iff: \bit w (LENGTH('a) - Suc 0) \ sint w < 0\ (is \?P \ ?Q\) for w :: \'a::len word\ -proof - - have \?P \ bit (uint w) (LENGTH('a) - Suc 0)\ - by (simp add: bit_uint_iff) - also have \\ \ ?Q\ - by (simp add: sint_uint) - finally show ?thesis . -qed + by (simp add: bit_unsigned_iff sint_uint) lemma drop_bit_eq_zero_iff_not_bit_last: \drop_bit (LENGTH('a) - Suc 0) w = 0 \ \ bit w (LENGTH('a) - Suc 0)\ @@ -2624,7 +2545,7 @@ lemma take_bit_word_beyond_length_eq: \take_bit n w = w\ if \LENGTH('a) \ n\ for w :: \'a::len word\ - using that by transfer simp + by (simp add: take_bit_word_eq_self that) lemmas word_div_no [simp] = word_div_def [of "numeral a" "numeral b"] for a b lemmas word_mod_no [simp] = word_mod_def [of "numeral a" "numeral b"] for a b @@ -2726,28 +2647,39 @@ and "uint (1 :: 'a word) = take_bit (LENGTH('a)) 1" by (simp_all add: uint_word_ariths take_bit_eq_mod) -lemma sint_word_ariths: +context fixes a b :: "'a::len word" - shows "sint (a + b) = signed_take_bit (LENGTH('a) - 1) (sint a + sint b)" - and "sint (a - b) = signed_take_bit (LENGTH('a) - 1) (sint a - sint b)" - and "sint (a * b) = signed_take_bit (LENGTH('a) - 1) (sint a * sint b)" - and "sint (- a) = signed_take_bit (LENGTH('a) - 1) (- sint a)" - and "sint (word_succ a) = signed_take_bit (LENGTH('a) - 1) (sint a + 1)" - and "sint (word_pred a) = signed_take_bit (LENGTH('a) - 1) (sint a - 1)" - and "sint (0 :: 'a word) = signed_take_bit (LENGTH('a) - 1) 0" - and "sint (1 :: 'a word) = signed_take_bit (LENGTH('a) - 1) 1" - subgoal - by transfer (simp add: signed_take_bit_add) - subgoal - by transfer (simp add: signed_take_bit_diff) - subgoal - by transfer (simp add: signed_take_bit_mult) - subgoal - by transfer (simp add: signed_take_bit_minus) - apply (metis of_int_sint scast_id sint_sbintrunc' wi_hom_succ) - apply (metis of_int_sint scast_id sint_sbintrunc' wi_hom_pred) - apply (simp_all add: sint_uint) - done +begin + +lemma sint_word_add: "sint (a + b) = signed_take_bit (LENGTH('a) - 1) (sint a + sint b)" + by transfer (simp add: signed_take_bit_add) + +lemma sint_word_diff: "sint (a - b) = signed_take_bit (LENGTH('a) - 1) (sint a - sint b)" + by transfer (simp add: signed_take_bit_diff) + +lemma sint_word_mult: "sint (a * b) = signed_take_bit (LENGTH('a) - 1) (sint a * sint b)" + by transfer (simp add: signed_take_bit_mult) + +lemma sint_word_minus: "sint (- a) = signed_take_bit (LENGTH('a) - 1) (- sint a)" + by transfer (simp add: signed_take_bit_minus) + +lemma sint_word_succ: "sint (word_succ a) = signed_take_bit (LENGTH('a) - 1) (sint a + 1)" + by (metis of_int_sint scast_id sint_sbintrunc' wi_hom_succ) + +lemma sint_word_pred: "sint (word_pred a) = signed_take_bit (LENGTH('a) - 1) (sint a - 1)" + by (metis of_int_sint scast_id sint_sbintrunc' wi_hom_pred) + +lemma sint_word_01: + "sint (0 :: 'a word) = signed_take_bit (LENGTH('a) - 1) 0" + "sint (1 :: 'a word) = signed_take_bit (LENGTH('a) - 1) 1" + by (simp_all add: sint_uint) + +end + + +lemmas sint_word_ariths = + sint_word_add sint_word_diff sint_word_mult sint_word_minus + sint_word_succ sint_word_pred sint_word_01 lemma word_pred_0_n1: "word_pred 0 = word_of_int (- 1)" unfolding word_pred_m1 by simp @@ -2831,24 +2763,14 @@ lemma mod_eq_0_imp_udvd [intro?]: \v udvd w\ if \w mod v = 0\ -proof - - from that have \unat (w mod v) = unat 0\ - by simp - then have \unat w mod unat v = 0\ - by (simp add: unat_mod_distrib) - then have \unat v dvd unat w\ .. - then show ?thesis - by (simp add: udvd_iff_dvd) -qed + by (metis mod_0_imp_dvd that udvd_iff_dvd unat_0 unat_mod_distrib) lemma udvd_imp_dvd: \v dvd w\ if \v udvd w\ for v w :: \'a::len word\ proof - from that obtain u :: \'a word\ where \unat w = unat v * unat u\ .. - then have \(word_of_nat (unat w) :: 'a word) = word_of_nat (unat v * unat u)\ - by simp then have \w = v * u\ - by simp + by (metis of_nat_mult of_nat_unat word_mult_def word_of_int_uint) then show \v dvd w\ .. qed @@ -2890,8 +2812,7 @@ with \1 \ uint w\ have "nat ((uint w - 1) mod 2 ^ LENGTH('a)) = nat (uint w) - 1" by (auto simp del: nat_uint_eq) then show ?thesis - by (simp only: unat_eq_nat_uint word_arith_wis mod_diff_right_eq) - (metis of_int_1 uint_word_of_int unsigned_1) + by (metis uint_word_ariths(6) unat_eq_nat_uint word_pred_m1) qed lemma measure_unat: "p \ 0 \ unat (p - 1) < unat p" @@ -2981,7 +2902,7 @@ then unat a + unat b else unat a + unat b - 2 ^ LENGTH('a))\ for a b :: \'a::len word\ apply (auto simp: not_less le_iff_add) - apply (metis (mono_tags, lifting) of_nat_add of_nat_unat take_bit_nat_eq_self_iff unsigned_less unsigned_of_nat unsigned_word_eqI) + using of_nat_inverse apply force by (smt (verit, ccfv_SIG) numeral_Bit0 numerals(1) of_nat_0_le_iff of_nat_1 of_nat_add of_nat_eq_iff of_nat_power of_nat_unat uint_plus_if') lemma unat_sub_if_size: @@ -2996,11 +2917,12 @@ also have "\ = nat (uint x + 2 ^ LENGTH('a)) - nat (uint y)" by (simp add: nat_diff_distrib') also have "\ = nat (uint x) + 2 ^ LENGTH('a) - nat (uint y)" - by (metis nat_add_distrib nat_eq_numeral_power_cancel_iff order_less_imp_le unsigned_0 unsigned_greater_eq unsigned_less) + by (simp add: nat_add_distrib nat_power_eq) finally have "nat (uint x - uint y + 2 ^ LENGTH('a)) = nat (uint x) + 2 ^ LENGTH('a) - nat (uint y)" . } then show ?thesis - by (simp add: word_size) (metis nat_diff_distrib' uint_sub_if' un_ui_le unat_eq_nat_uint unsigned_greater_eq) + by (metis nat_diff_distrib' uint_range_size uint_sub_if' un_ui_le unat_eq_nat_uint + word_size) qed lemmas unat_sub_if' = unat_sub_if_size [unfolded word_size] @@ -3144,8 +3066,7 @@ lemma sub_wrap_lt: "x < x - z \ x < z" for x z :: "'a::len word" - by (simp add: word_less_def uint_sub_lem) - (meson linorder_not_le uint_minus_simple_iff uint_sub_lem word_less_iff_unsigned) + by (meson linorder_not_le word_sub_le_iff) lemma sub_wrap: "x \ x - z \ z = 0 \ x < z" for x z :: "'a::len word" @@ -3237,8 +3158,8 @@ by uint_arith lemma udvd_incr_lem: - "up < uq \ up = ua + n * uint K \ - uq = ua + n' * uint K \ up + uint K \ uq" + "\up < uq; up = ua + n * uint K; uq = ua + n' * uint K\ + \ up + uint K \ uq" by auto (metis int_distrib(1) linorder_not_less mult.left_neutral mult_right_mono uint_nonnegative zless_imp_add1_zle) lemma udvd_incr': @@ -3251,7 +3172,7 @@ assumes "p < q" "uint p = ua + n * uint K" "uint q = ua + n' * uint K" shows "uint q = ua + n' * uint K \ p \ q - K" proof - - have "\w wa. uint (w::'a word) \ uint wa + uint (w - wa)" + have "\w v. uint (w::'a word) \ uint v + uint (w - v)" by (metis (no_types) add_diff_cancel_left' diff_add_cancel uint_add_le) moreover have "uint K + uint p \ uint q" using assms by (metis (no_types) add_diff_cancel_left' diff_add_cancel udvd_incr_lem word_less_def) @@ -3271,9 +3192,8 @@ "p < a + s \ a \ a + s \ K udvd s \ K udvd p - a \ a \ p \ 0 < K \ p \ p + K \ p + K \ a + s" unfolding udvd_unfold_int - apply (simp add: uint_arith_simps split: if_split_asm) - apply (metis (no_types, opaque_lifting) le_add_diff_inverse le_less_trans udvd_incr_lem) - using uint_lt2p [of s] by simp + by (smt (verit, best) diff_add_cancel leD udvd_incr_lem uint_plus_if' + word_less_eq_iff_unsigned word_sub_le) subsection \Arithmetic type class instantiations\ @@ -3372,13 +3292,13 @@ Abs_fnat_hom_1 word_arith_nat_div word_arith_nat_mod -lemma unat_cong: "x = y \ unat x = unat y" - by (fact arg_cong) - lemma unat_of_nat: \unat (word_of_nat x :: 'a::len word) = x mod 2 ^ LENGTH('a)\ by transfer (simp flip: take_bit_eq_mod add: nat_take_bit_eq) +lemma unat_cong: "x = y \ unat x = unat y" + by (fact arg_cong) + lemmas unat_word_ariths = word_arith_nat_defs [THEN trans [OF unat_cong unat_of_nat]] @@ -3732,18 +3652,13 @@ lemma word_eq_reverseI: \v = w\ if \word_reverse v = word_reverse w\ -proof - - from that have \word_reverse (word_reverse v) = word_reverse (word_reverse w)\ - by simp - then show ?thesis - by simp -qed + by (metis that word_rev_rev) lemma uint_2p: "(0::'a::len word) < 2 ^ n \ uint (2 ^ n::'a::len word) = 2 ^ n" by (cases \n < LENGTH('a)\; transfer; force) lemma word_of_int_2p: "(word_of_int (2 ^ n) :: 'a::len word) = 2 ^ n" - by (induct n) (simp_all add: wi_hom_syms) + by simp subsubsection \shift functions in terms of lists of bools\ @@ -3907,10 +3822,8 @@ by (metis take_bit_eq_mask take_bit_int_less_exp unsigned_take_bit_eq) lemma mask_eq_iff: "w AND mask n = w \ uint w < 2 ^ n" - apply (auto simp flip: take_bit_eq_mask) - apply (metis take_bit_int_eq_self_iff uint_take_bit_eq) - apply (simp add: take_bit_int_eq_self unsigned_take_bit_eq word_uint_eqI) - done + by (metis and_mask_bintr and_mask_lt_2p take_bit_int_eq_self take_bit_nonnegative + uint_sint word_of_int_uint) lemma and_mask_dvd: "2 ^ n dvd uint w \ w AND mask n = 0" by (simp flip: take_bit_eq_mask take_bit_eq_mod unsigned_take_bit_eq add: dvd_eq_mod_eq_0 uint_0_iff) @@ -4180,7 +4093,7 @@ assume \m < LENGTH('a)\ then have \int (LENGTH('a) - Suc ((m + n) mod LENGTH('a))) = int ((LENGTH('a) + LENGTH('a) - Suc (m + n mod LENGTH('a))) mod LENGTH('a))\ - apply (simp only: of_nat_diff of_nat_mod) + unfolding of_nat_diff of_nat_mod apply (simp add: Suc_le_eq add_less_le_mono of_nat_mod algebra_simps) apply (simp only: mod_diff_left_eq [symmetric, of \int LENGTH('a) * 2\] mod_mult_self1_is_0 diff_0 minus_mod_int_eq) apply (simp add: mod_simps) @@ -4379,7 +4292,8 @@ and 4: "x' + y' = z'" shows "(x + y) mod b = z' mod b'" proof - - from 1 2[symmetric] 3[symmetric] have "(x + y) mod b = (x' mod b' + y' mod b') mod b'" + from 1 2[symmetric] 3[symmetric] + have "(x + y) mod b = (x' mod b' + y' mod b') mod b'" by (simp add: mod_add_eq) also have "\ = (x' + y') mod b'" by (simp add: mod_add_eq) @@ -4481,7 +4395,7 @@ then have eq: "1 + n - m = 1 + (n - m)" by simp with False have "m \ n" - by (metis "suc.prems" add.commute dual_order.antisym eq_iff_diff_eq_0 inc_le leI) + using inc_le linorder_not_le suc.prems word_le_minus_mono_left by fastforce with False "suc.hyps" show ?thesis using suc.IH [of "f 0 z" "f \ (+) 1"] by (simp add: word_rec_in2 eq add.assoc o_def)