# HG changeset patch # User paulson # Date 1712912312 -3600 # Node ID 0f9cd1a5edbea65b1b98c87d2311e0c26e22f9eb # Parent 646cd337bb0836adff89d429c110d5c39aedd9f1 Tidying ugly proofs diff -r 646cd337bb08 -r 0f9cd1a5edbe src/HOL/Analysis/Brouwer_Fixpoint.thy --- a/src/HOL/Analysis/Brouwer_Fixpoint.thy Wed Apr 10 11:32:48 2024 +0100 +++ b/src/HOL/Analysis/Brouwer_Fixpoint.thy Fri Apr 12 09:58:32 2024 +0100 @@ -36,11 +36,19 @@ by (metis path_connected_continuous_image retract_of_def retraction) lemma retract_of_simply_connected: - "\simply_connected T; S retract_of T\ \ simply_connected S" - apply (simp add: retract_of_def retraction_def Pi_iff, clarify) - apply (rule simply_connected_retraction_gen) - apply (force elim!: continuous_on_subset)+ - done + assumes T: "simply_connected T" and "S retract_of T" + shows "simply_connected S" +proof - + obtain r where r: "retraction T S r" + using assms by (metis retract_of_def) + have "S \ T" + by (meson \retraction T S r\ retraction) + then have "(\a. a) \ S \ T" + by blast + then show ?thesis + using simply_connected_retraction_gen [OF T] + by (metis (no_types) r retraction retraction_refl) +qed lemma retract_of_homotopically_trivial: assumes ts: "T retract_of S" @@ -56,10 +64,7 @@ then obtain k where "Retracts S r T k" unfolding Retracts_def using continuous_on_id by blast then show ?thesis - apply (rule Retracts.homotopically_trivial_retraction_gen) - using assms - apply (force simp: hom)+ - done + by (rule Retracts.homotopically_trivial_retraction_gen) (use assms hom in force)+ qed lemma retract_of_homotopically_trivial_null: @@ -74,9 +79,11 @@ then obtain k where "Retracts S r T k" unfolding Retracts_def by fastforce then show ?thesis - apply (rule Retracts.homotopically_trivial_retraction_null_gen) - apply (rule TrueI refl assms that | assumption)+ - done + proof (rule Retracts.homotopically_trivial_retraction_null_gen) + show "\f. \continuous_on U f; f \ U \ S\ + \ \c. homotopic_with_canon (\a. True) U S f (\x. c)" + using hom by blast + qed (use assms that in auto) qed lemma retraction_openin_vimage_iff: @@ -101,13 +108,13 @@ assumes "locally connected T" "S retract_of T" shows "locally connected S" using assms - by (metis Abstract_Topology_2.retraction_openin_vimage_iff idempotent_imp_retraction locally_connected_quotient_image retract_ofE) + by (metis retraction_openin_vimage_iff idempotent_imp_retraction locally_connected_quotient_image retract_ofE) lemma retract_of_locally_path_connected: assumes "locally path_connected T" "S retract_of T" shows "locally path_connected S" using assms - by (metis Abstract_Topology_2.retraction_openin_vimage_iff idempotent_imp_retraction locally_path_connected_quotient_image retract_ofE) + by (metis retraction_openin_vimage_iff idempotent_imp_retraction locally_path_connected_quotient_image retract_ofE) text \A few simple lemmas about deformation retracts\ @@ -137,15 +144,16 @@ then show ?rhs by (auto simp: retract_of_def retraction_def) next - assume ?rhs - then show ?lhs - apply (clarsimp simp add: retract_of_def retraction_def) - apply (rule_tac x=r in exI, simp) - apply (rule homotopic_with_trans, assumption) - apply (rule_tac f = "r \ f" and g="r \ id" in homotopic_with_eq) - apply (rule_tac Y=S in homotopic_with_compose_continuous_left) + assume R: ?rhs + have "\r f. \T \ S; continuous_on S r; homotopic_with_canon (\x. True) S S id f; + f \ S \ T; r \ S \ T; \x\T. r x = x\ + \ homotopic_with_canon (\x. True) S S f r" + apply (rule_tac f = "r \ f" and g="r \ id" in homotopic_with_eq) + apply (rule_tac Y=S in homotopic_with_compose_continuous_left) apply (auto simp: homotopic_with_sym Pi_iff) done + with R homotopic_with_trans show ?lhs + unfolding retract_of_def retraction_def by blast qed lemma deformation_retract_of_contractible_sing: @@ -959,7 +967,7 @@ qed } with ks_f' eq \a \ f' n\ \n \ 0\ show ?thesis apply (intro ex1I[of _ "f' ` {.. n}"]) - apply auto [] + apply auto [] apply metis done next @@ -1523,7 +1531,7 @@ (\x i. P x \ Q i \ l x i = 1 \ f x i \ x i)" unfolding all_conj_distrib [symmetric] apply (subst choice_iff[symmetric])+ - by (metis assms bot_nat_0.extremum nle_le zero_neq_one) + by (metis assms choice_iff bot_nat_0.extremum nle_le zero_neq_one) subsection \Brouwer's fixed point theorem\ @@ -1543,10 +1551,8 @@ by auto obtain d where d: "d > 0" "\x. x \ cbox 0 One \ d \ norm (f x - x)" - apply (rule brouwer_compactness_lemma[OF compact_cbox _ *]) - apply (rule continuous_intros assms)+ - apply blast - done + using brouwer_compactness_lemma[OF compact_cbox _ *] assms + by (metis (no_types, lifting) continuous_on_cong continuous_on_diff continuous_on_id) have *: "\x. x \ cbox 0 One \ f x \ cbox 0 One" "\x. x \ (cbox 0 One::'a set) \ (\i\Basis. True \ 0 \ x \ i \ x \ i \ 1)" using assms(2)[unfolded image_subset_iff Ball_def] @@ -1581,8 +1587,7 @@ case False then show ?thesis using label [OF \i \ Basis\] i(1) x y - apply (auto simp: inner_diff_left le_Suc_eq) - by (metis "*") + by (smt (verit, ccfv_threshold) inner_diff_left less_one order_le_less) qed also have "\ \ norm (f y - f x) + norm (y - x)" by (simp add: add_mono i(2) norm_bound_Basis_le) @@ -1980,9 +1985,8 @@ then obtain a where "a \ S" "a \ T" by blast define g where "g \ \z. if z \ closure S then f z else z" have "continuous_on (closure S \ closure(-S)) g" - unfolding g_def - apply (rule continuous_on_cases) - using fros fid frontier_closures by (auto simp: contf) + unfolding g_def using fros fid frontier_closures + by (intro continuous_on_cases) (auto simp: contf) moreover have "closure S \ closure(- S) = UNIV" using closure_Un by fastforce ultimately have contg: "continuous_on UNIV g" by metis @@ -2027,10 +2031,8 @@ proof - have "\d. 0 < d \ (a + d *\<^sub>R l) \ rel_frontier S \ (\e. 0 \ e \ e < d \ (a + e *\<^sub>R l) \ rel_interior S)" - if "(a + l) \ affine hull S" "l \ 0" for l - apply (rule ray_to_rel_frontier [OF \bounded S\ arelS]) - apply (rule that)+ - by metis + if "(a + l) \ affine hull S" "l \ 0" for l + using ray_to_rel_frontier [OF \bounded S\ arelS] that by metis then obtain dd where dd1: "\l. \(a + l) \ affine hull S; l \ 0\ \ 0 < dd l \ (a + dd l *\<^sub>R l) \ rel_frontier S" and dd2: "\l e. \(a + l) \ affine hull S; e < dd l; 0 \ e; l \ 0\ @@ -2071,11 +2073,11 @@ then have "0 < dd x" and inS: "a + dd x *\<^sub>R x \ rel_frontier S" using dd1 by auto moreover have "a + dd x *\<^sub>R x \ open_segment a (a + k *\<^sub>R x)" - using k \x \ 0\ \0 < dd x\ - apply (simp add: in_segment) - apply (rule_tac x = "dd x / k" in exI) - apply (simp add: that vector_add_divide_simps algebra_simps) - done + unfolding in_segment + proof (intro conjI exI) + show "a + dd x *\<^sub>R x = (1 - dd x / k) *\<^sub>R a + (dd x / k) *\<^sub>R (a + k *\<^sub>R x)" + using k by (simp add: that algebra_simps) + qed (use \x \ 0\ \0 < dd x\ that in auto) ultimately show ?thesis using segsub by (auto simp: rel_frontier_def) qed @@ -2094,47 +2096,45 @@ by (blast intro: continuous_on_subset) show ?thesis proof - show "homotopic_with_canon (\x. True) (T - {a}) (T - {a}) id (\x. a + dd (x - a) *\<^sub>R (x - a))" + show "homotopic_with_canon (\x. True) (T - {a}) (T - {a}) id (\x. a + dd (x-a) *\<^sub>R (x-a))" proof (rule homotopic_with_linear) show "continuous_on (T - {a}) id" by (intro continuous_intros continuous_on_compose) - show "continuous_on (T - {a}) (\x. a + dd (x - a) *\<^sub>R (x - a))" + show "continuous_on (T - {a}) (\x. a + dd (x-a) *\<^sub>R (x-a))" using contdd by (simp add: o_def) - show "closed_segment (id x) (a + dd (x - a) *\<^sub>R (x - a)) \ T - {a}" + show "closed_segment (id x) (a + dd (x-a) *\<^sub>R (x-a)) \ T - {a}" if "x \ T - {a}" for x proof (clarsimp simp: in_segment, intro conjI) fix u::real assume u: "0 \ u" "u \ 1" - have "a + dd (x - a) *\<^sub>R (x - a) \ T" + have "a + dd (x-a) *\<^sub>R (x-a) \ T" by (metis DiffD1 DiffD2 add.commute add.right_neutral affS dd1 diff_add_cancel relS singletonI subsetCE that) - then show "(1 - u) *\<^sub>R x + u *\<^sub>R (a + dd (x - a) *\<^sub>R (x - a)) \ T" + then show "(1 - u) *\<^sub>R x + u *\<^sub>R (a + dd (x-a) *\<^sub>R (x-a)) \ T" using convexD [OF \convex T\] that u by simp - have iff: "(1 - u) *\<^sub>R x + u *\<^sub>R (a + d *\<^sub>R (x - a)) = a \ - (1 - u + u * d) *\<^sub>R (x - a) = 0" for d + have iff: "(1 - u) *\<^sub>R x + u *\<^sub>R (a + d *\<^sub>R (x-a)) = a \ + (1 - u + u * d) *\<^sub>R (x-a) = 0" for d by (auto simp: algebra_simps) have "x \ T" "x \ a" using that by auto - then have axa: "a + (x - a) \ affine hull S" + then have axa: "a + (x-a) \ affine hull S" by (metis (no_types) add.commute affS diff_add_cancel rev_subsetD) - then have "\ dd (x - a) \ 0 \ a + dd (x - a) *\<^sub>R (x - a) \ rel_frontier S" + then have "\ dd (x-a) \ 0 \ a + dd (x-a) *\<^sub>R (x-a) \ rel_frontier S" using \x \ a\ dd1 by fastforce - with \x \ a\ show "(1 - u) *\<^sub>R x + u *\<^sub>R (a + dd (x - a) *\<^sub>R (x - a)) \ a" + with \x \ a\ show "(1 - u) *\<^sub>R x + u *\<^sub>R (a + dd (x-a) *\<^sub>R (x-a)) \ a" using less_eq_real_def mult_le_0_iff not_less u by (fastforce simp: iff) qed qed - show "retraction (T - {a}) (rel_frontier S) (\x. a + dd (x - a) *\<^sub>R (x - a))" + show "retraction (T - {a}) (rel_frontier S) (\x. a + dd (x-a) *\<^sub>R (x-a))" proof (simp add: retraction_def, intro conjI ballI) show "rel_frontier S \ T - {a}" using arelS relS rel_frontier_def by fastforce - show "continuous_on (T - {a}) (\x. a + dd (x - a) *\<^sub>R (x - a))" + show "continuous_on (T - {a}) (\x. a + dd (x-a) *\<^sub>R (x-a))" using contdd by (simp add: o_def) - show "(\x. a + dd (x - a) *\<^sub>R (x - a)) \ (T - {a}) \ rel_frontier S" - apply (auto simp: rel_frontier_def) - apply (metis Diff_subset add.commute affS dd1 diff_add_cancel eq_iff_diff_eq_0 rel_frontier_def subset_iff) - by (metis DiffE add.commute affS dd1 diff_add_cancel eq_iff_diff_eq_0 rel_frontier_def rev_subsetD) - show "a + dd (x - a) *\<^sub>R (x - a) = x" if x: "x \ rel_frontier S" for x + show "(\x. a + dd (x-a) *\<^sub>R (x-a)) \ (T - {a}) \ rel_frontier S" + unfolding Pi_iff using affS dd1 subset_eq by force + show "a + dd (x-a) *\<^sub>R (x-a) = x" if x: "x \ rel_frontier S" for x proof - have "x \ a" using that arelS by (auto simp: rel_frontier_def) - have False if "dd (x - a) < 1" + have False if "dd (x-a) < 1" proof - have "x \ closure S" using x by (auto simp: rel_frontier_def) @@ -2142,21 +2142,21 @@ by (metis rel_interior_closure_convex_segment [OF \convex S\ arelS]) have xaffS: "x \ affine hull S" using affS relS x by auto - then have "0 < dd (x - a)" and inS: "a + dd (x - a) *\<^sub>R (x - a) \ rel_frontier S" + then have "0 < dd (x-a)" and inS: "a + dd (x-a) *\<^sub>R (x-a) \ rel_frontier S" using dd1 by (auto simp: \x \ a\) - moreover have "a + dd (x - a) *\<^sub>R (x - a) \ open_segment a x" - using \x \ a\ \0 < dd (x - a)\ - apply (simp add: in_segment) - apply (rule_tac x = "dd (x - a)" in exI) - apply (simp add: algebra_simps that) - done + moreover have "a + dd (x-a) *\<^sub>R (x-a) \ open_segment a x" + unfolding in_segment + proof (intro exI conjI) + show "a + dd (x-a) *\<^sub>R (x-a) = (1 - dd (x-a)) *\<^sub>R a + (dd (x-a)) *\<^sub>R x" + by (simp add: algebra_simps) + qed (use \x \ a\ \0 < dd (x-a)\ that in auto) ultimately show ?thesis using segsub by (auto simp: rel_frontier_def) qed - moreover have False if "1 < dd (x - a)" + moreover have False if "1 < dd (x-a)" using x that dd2 [of "x - a" 1] \x \ a\ closure_affine_hull by (auto simp: rel_frontier_def) - ultimately have "dd (x - a) = 1" \ \similar to another proof above\ + ultimately have "dd (x-a) = 1" \ \similar to another proof above\ by fastforce with that show ?thesis by (simp add: rel_frontier_def) @@ -2211,13 +2211,13 @@ subsubsection\Borsuk-style characterization of separation\ lemma continuous_on_Borsuk_map: - "a \ S \ continuous_on S (\x. inverse(norm (x - a)) *\<^sub>R (x - a))" + "a \ S \ continuous_on S (\x. inverse(norm (x-a)) *\<^sub>R (x-a))" by (rule continuous_intros | force)+ lemma Borsuk_map_into_sphere: - "(\x. inverse(norm (x - a)) *\<^sub>R (x - a)) \ S \ sphere 0 1 \ (a \ S)" + "(\x. inverse(norm (x-a)) *\<^sub>R (x-a)) \ S \ sphere 0 1 \ (a \ S)" proof - - have "\x. \a \ S; x \ S\ \ inverse (norm (x - a)) * norm (x - a) = 1" + have "\x. \a \ S; x \ S\ \ inverse (norm (x-a)) * norm (x-a) = 1" by (metis left_inverse norm_eq_zero right_minus_eq) then show ?thesis by force @@ -2226,16 +2226,19 @@ lemma Borsuk_maps_homotopic_in_path_component: assumes "path_component (- S) a b" shows "homotopic_with_canon (\x. True) S (sphere 0 1) - (\x. inverse(norm(x - a)) *\<^sub>R (x - a)) + (\x. inverse(norm(x-a)) *\<^sub>R (x-a)) (\x. inverse(norm(x - b)) *\<^sub>R (x - b))" proof - - obtain g where "path g" "path_image g \ -S" "pathstart g = a" "pathfinish g = b" + obtain g where g: "path g" "path_image g \ -S" "pathstart g = a" "pathfinish g = b" using assms by (auto simp: path_component_def) - then show ?thesis - apply (simp add: path_def path_image_def pathstart_def pathfinish_def homotopic_with_def) - apply (rule_tac x = "\z. inverse(norm(snd z - (g \ fst)z)) *\<^sub>R (snd z - (g \ fst)z)" in exI) - apply (rule conjI continuous_intros | erule continuous_on_subset | fastforce simp: divide_simps sphere_def)+ - done + define h where "h \ \z. (snd z - (g \ fst) z) /\<^sub>R norm (snd z - (g \ fst) z)" + have "continuous_on ({0..1} \ S) h" + unfolding h_def using g by (intro continuous_intros) (auto simp: path_defs) + moreover + have "h ` ({0..1} \ S) \ sphere 0 1" + unfolding h_def using g by (auto simp: divide_simps path_defs) + ultimately show ?thesis + using g by (auto simp: h_def path_defs homotopic_with_def) qed lemma non_extensible_Borsuk_map: @@ -2243,7 +2246,7 @@ assumes "compact S" and cin: "C \ components(- S)" and boc: "bounded C" and "a \ C" shows "\ (\g. continuous_on (S \ C) g \ g \ (S \ C) \ sphere 0 1 \ - (\x \ S. g x = inverse(norm(x - a)) *\<^sub>R (x - a)))" + (\x \ S. g x = inverse(norm(x-a)) *\<^sub>R (x-a)))" proof - have "closed S" using assms by (simp add: compact_imp_closed) have "C \ -S" @@ -2258,7 +2261,7 @@ { fix g assume "continuous_on (S \ C) g" "g \ (S \ C) \ sphere 0 1" - and [simp]: "\x. x \ S \ g x = (x - a) /\<^sub>R norm (x - a)" + and [simp]: "\x. x \ S \ g x = (x-a) /\<^sub>R norm (x-a)" then have norm_g1[simp]: "\x. x \ S \ C \ norm (g x) = 1" by force have cb_eq: "cball a r = (S \ connected_component_set (- S) a) \ @@ -2269,12 +2272,12 @@ using \continuous_on (S \ C) g\ ceq by (intro continuous_intros) blast have cont2: "continuous_on (cball a r - connected_component_set (- S) a) - (\x. a + r *\<^sub>R ((x - a) /\<^sub>R norm (x - a)))" + (\x. a + r *\<^sub>R ((x-a) /\<^sub>R norm (x-a)))" by (rule continuous_intros | force simp: \a \ S\)+ have 1: "continuous_on (cball a r) (\x. if connected_component (- S) a x then a + r *\<^sub>R g x - else a + r *\<^sub>R ((x - a) /\<^sub>R norm (x - a)))" + else a + r *\<^sub>R ((x-a) /\<^sub>R norm (x-a)))" apply (subst cb_eq) apply (rule continuous_on_cases [OF _ _ cont1 cont2]) using \closed S\ ceq cin @@ -2285,7 +2288,7 @@ have "retraction (cball a r) (sphere a r) (\x. if x \ connected_component_set (- S) a then a + r *\<^sub>R g x - else a + r *\<^sub>R ((x - a) /\<^sub>R norm (x - a)))" + else a + r *\<^sub>R ((x-a) /\<^sub>R norm (x-a)))" using \0 < r\ \a \ S\ \a \ C\ r by (auto simp: norm_minus_commute retraction_def Pi_iff ceq dist_norm abs_if mult_less_0_iff divide_simps 1 2) @@ -2294,7 +2297,7 @@ [OF \0 < r\, of a, unfolded retract_of_def, simplified, rule_format, of "\x. if x \ connected_component_set (- S) a then a + r *\<^sub>R g x - else a + r *\<^sub>R inverse(norm(x - a)) *\<^sub>R (x - a)"] + else a + r *\<^sub>R inverse(norm(x-a)) *\<^sub>R (x-a)"] by blast } then show ?thesis @@ -2305,10 +2308,8 @@ lemma brouwer_surjective: fixes f :: "'n::euclidean_space \ 'n" - assumes "compact T" - and "convex T" - and "T \ {}" - and "continuous_on T f" + assumes T: "compact T" "convex T" "T \ {}" + and f: "continuous_on T f" and "\x y. \x\S; y\T\ \ x + (y - f y) \ T" and "x \ S" shows "\y\T. f y = x" @@ -2317,11 +2318,10 @@ by (auto simp add: algebra_simps) show ?thesis unfolding * - apply (rule brouwer[OF assms(1-3), of "\y. x + (y - f y)"]) - apply (intro continuous_intros) - using assms - apply auto - done + proof (rule brouwer[OF T]) + show "continuous_on T (\y. x + (y - f y))" + by (intro continuous_intros f) + qed (use assms in auto) qed lemma brouwer_surjective_cball: diff -r 646cd337bb08 -r 0f9cd1a5edbe src/HOL/Library/Groups_Big_Fun.thy --- a/src/HOL/Library/Groups_Big_Fun.thy Wed Apr 10 11:32:48 2024 +0100 +++ b/src/HOL/Library/Groups_Big_Fun.thy Fri Apr 12 09:58:32 2024 +0100 @@ -22,19 +22,14 @@ lemma expand_superset: assumes "finite A" and "{a. g a \ \<^bold>1} \ A" shows "G g = F.F g A" - apply (simp add: expand_set) - apply (rule F.same_carrierI [of A]) - apply (simp_all add: assms) - done + using F.mono_neutral_right assms expand_set by fastforce lemma conditionalize: assumes "finite A" shows "F.F g A = G (\a. if a \ A then g a else \<^bold>1)" using assms - apply (simp add: expand_set) - apply (rule F.same_carrierI [of A]) - apply auto - done + by (smt (verit, ccfv_threshold) Diff_iff F.mono_neutral_cong_right expand_set mem_Collect_eq subsetI) + lemma neutral [simp]: "G (\a. \<^bold>1) = \<^bold>1" @@ -140,30 +135,13 @@ by (auto simp add: finite_cartesian_product_iff) have *: "G (\a. G (g a)) = (F.F (\a. F.F (g a) {b. \a. g a b \ \<^bold>1}) {a. \b. g a b \ \<^bold>1})" - apply (subst expand_superset [of "?B"]) - apply (rule \finite ?B\) - apply auto - apply (subst expand_superset [of "?A"]) - apply (rule \finite ?A\) - apply auto - apply (erule F.not_neutral_contains_not_neutral) - apply auto - done - have "{p. (case p of (a, b) \ g a b) \ \<^bold>1} \ ?A \ ?B" + using \finite ?A\ \finite ?B\ expand_superset + by (smt (verit, del_insts) Collect_mono local.cong not_neutral_obtains_not_neutral) + have **: "{p. (case p of (a, b) \ g a b) \ \<^bold>1} \ ?A \ ?B" by auto - with subset have **: "{p. (case p of (a, b) \ g a b) \ \<^bold>1} \ C" - by blast show ?thesis - apply (simp add: *) - apply (simp add: F.cartesian_product) - apply (subst expand_superset [of C]) - apply (rule \finite C\) - apply (simp_all add: **) - apply (rule F.same_carrierI [of C]) - apply (rule \finite C\) - apply (simp_all add: subset) - apply auto - done + using \finite C\ expand_superset + using "*" ** F.cartesian_product fin_prod by force qed lemma cartesian_product2: @@ -231,37 +209,23 @@ fixes r :: "'a :: semiring_0" assumes "finite {a. g a \ 0}" shows "Sum_any g * r = (\n. g n * r)" -proof - - note assms - moreover have "{a. g a * r \ 0} \ {a. g a \ 0}" by auto - ultimately show ?thesis - by (simp add: sum_distrib_right Sum_any.expand_superset [of "{a. g a \ 0}"]) -qed + by (metis (mono_tags, lifting) Collect_mono Sum_any.expand_superset assms mult_zero_left sum_distrib_right) lemma Sum_any_right_distrib: fixes r :: "'a :: semiring_0" assumes "finite {a. g a \ 0}" shows "r * Sum_any g = (\n. r * g n)" -proof - - note assms - moreover have "{a. r * g a \ 0} \ {a. g a \ 0}" by auto - ultimately show ?thesis - by (simp add: sum_distrib_left Sum_any.expand_superset [of "{a. g a \ 0}"]) -qed + by (metis (mono_tags, lifting) Collect_mono Sum_any.expand_superset assms mult_zero_right sum_distrib_left) lemma Sum_any_product: fixes f g :: "'b \ 'a::semiring_0" assumes "finite {a. f a \ 0}" and "finite {b. g b \ 0}" shows "Sum_any f * Sum_any g = (\a. \b. f a * g b)" proof - - have subset_f: "{a. (\b. f a * g b) \ 0} \ {a. f a \ 0}" - by rule (simp, rule, auto) - moreover have subset_g: "\a. {b. f a * g b \ 0} \ {b. g b \ 0}" - by rule (simp, rule, auto) - ultimately show ?thesis using assms - by (auto simp add: Sum_any.expand_set [of f] Sum_any.expand_set [of g] - Sum_any.expand_superset [of "{a. f a \ 0}"] Sum_any.expand_superset [of "{b. g b \ 0}"] - sum_product) + have "\a. (\b. a * g b) = a * Sum_any g" + by (simp add: Sum_any_right_distrib assms(2)) + then show ?thesis + by (simp add: Sum_any_left_distrib assms(1)) qed lemma Sum_any_eq_zero_iff [simp]: diff -r 646cd337bb08 -r 0f9cd1a5edbe src/HOL/Library/Multiset.thy --- a/src/HOL/Library/Multiset.thy Wed Apr 10 11:32:48 2024 +0100 +++ b/src/HOL/Library/Multiset.thy Fri Apr 12 09:58:32 2024 +0100 @@ -559,10 +559,7 @@ lemma mset_subset_eq_exists_conv: "(A::'a multiset) \# B \ (\C. B = A + C)" unfolding subseteq_mset_def - apply (rule iffI) - apply (rule exI [where x = "B - A"]) - apply (auto intro: multiset_eq_iff [THEN iffD2]) - done + by (metis add_diff_cancel_left' count_diff count_union le_Suc_ex le_add_same_cancel1 multiset_eq_iff zero_le) interpretation subset_mset: ordered_cancel_comm_monoid_diff "(+)" 0 "(\#)" "(\#)" "(-)" by standard (simp, fact mset_subset_eq_exists_conv) @@ -629,14 +626,18 @@ by (metis mset_subset_eqD subsetI) lemma mset_subset_eq_insertD: - "add_mset x A \# B \ x \# B \ A \# B" -apply (rule conjI) - apply (simp add: mset_subset_eqD) - apply (clarsimp simp: subset_mset_def subseteq_mset_def) - apply safe - apply (erule_tac x = a in allE) - apply (auto split: if_split_asm) -done + assumes "add_mset x A \# B" + shows "x \# B \ A \# B" +proof + show "x \# B" + using assms by (simp add: mset_subset_eqD) + have "A \# add_mset x A" + by (metis (no_types) add_mset_add_single mset_subset_eq_add_left) + then have "A \# add_mset x A" + by (meson multi_self_add_other_not_self subset_mset.le_imp_less_or_eq) + then show "A \# B" + using assms subset_mset.strict_trans2 by blast +qed lemma mset_subset_insertD: "add_mset x A \# B \ x \# B \ A \# B" @@ -653,11 +654,7 @@ lemma insert_subset_eq_iff: "add_mset a A \# B \ a \# B \ A \# B - {#a#}" - using le_diff_conv2 [of "Suc 0" "count B a" "count A a"] - apply (auto simp add: subseteq_mset_def not_in_iff Suc_le_eq) - apply (rule ccontr) - apply (auto simp add: not_in_iff) - done + using mset_subset_eq_insertD subset_mset.le_diff_conv2 by fastforce lemma insert_union_subset_iff: "add_mset a A \# B \ a \# B \ A \# B - {#a#}" @@ -723,11 +720,12 @@ by (simp add: union_mset_def) global_interpretation subset_mset: semilattice_neutr_order \(\#)\ \{#}\ \(\#)\ \(\#)\ - apply standard - apply (simp_all add: multiset_eq_iff subseteq_mset_def subset_mset_def max_def) - apply (auto simp add: le_antisym dest: sym) - apply (metis nat_le_linear)+ - done +proof + show "\a b. (b \# a) = (a = a \# b)" + by (simp add: Diff_eq_empty_iff_mset union_mset_def) + show "\a b. (b \# a) = (a = a \# b \ a \ b)" + by (metis Diff_eq_empty_iff_mset add_cancel_left_right subset_mset_def union_mset_def) +qed (auto simp: multiset_eqI union_mset_def) interpretation subset_mset: semilattice_sup \(\#)\ \(\#)\ \(\#)\ proof - @@ -774,30 +772,8 @@ qed lemma disjunct_not_in: - "A \# B = {#} \ (\a. a \# A \ a \# B)" (is "?P \ ?Q") -proof - assume ?P - show ?Q - proof - fix a - from \?P\ have "min (count A a) (count B a) = 0" - by (simp add: multiset_eq_iff) - then have "count A a = 0 \ count B a = 0" - by (cases "count A a \ count B a") (simp_all add: min_def) - then show "a \# A \ a \# B" - by (simp add: not_in_iff) - qed -next - assume ?Q - show ?P - proof (rule multiset_eqI) - fix a - from \?Q\ have "count A a = 0 \ count B a = 0" - by (auto simp add: not_in_iff) - then show "count (A \# B) a = count {#} a" - by auto - qed -qed + "A \# B = {#} \ (\a. a \# A \ a \# B)" + by (metis disjoint_iff set_mset_eq_empty_iff set_mset_inter) lemma inter_mset_empty_distrib_right: "A \# (B + C) = {#} \ A \# B = {#} \ A \# C = {#}" by (meson disjunct_not_in union_iff) @@ -1148,15 +1124,7 @@ fix X :: "'a multiset" and A assume "X \ A" show "Inf A \# X" - proof (rule mset_subset_eqI) - fix x - from \X \ A\ have "A \ {}" by auto - hence "count (Inf A) x = (INF X\A. count X x)" - by (simp add: count_Inf_multiset_nonempty) - also from \X \ A\ have "\ \ count X x" - by (intro cInf_lower) simp_all - finally show "count (Inf A) x \ count X x" . - qed + by (metis \X \ A\ count_Inf_multiset_nonempty empty_iff image_eqI mset_subset_eqI wellorder_Inf_le1) next fix X :: "'a multiset" and A assume nonempty: "A \ {}" and le: "\Y. Y \ A \ X \# Y" @@ -1240,8 +1208,7 @@ using that by (auto simp: subseteq_mset_def algebra_simps not_in_iff) hence "Sup A \# Sup A - {#x#}" by (intro subset_mset.cSup_least nonempty) with \x \# Sup A\ show False - by (auto simp: subseteq_mset_def simp flip: count_greater_zero_iff - dest!: spec[of _ x]) + using mset_subset_diff_self by fastforce qed next fix x X assume "x \ set_mset X" "X \ A" @@ -1253,20 +1220,12 @@ lemma in_Sup_multiset_iff: assumes "subset_mset.bdd_above A" shows "x \# Sup A \ (\X\A. x \# X)" -proof - - from assms have "set_mset (Sup A) = (\X\A. set_mset X)" by (rule set_mset_Sup) - also have "x \ \ \ (\X\A. x \# X)" by simp - finally show ?thesis . -qed + by (simp add: assms set_mset_Sup) lemma in_Sup_multisetD: assumes "x \# Sup A" shows "\X\A. x \# X" -proof - - have "subset_mset.bdd_above A" - by (rule ccontr) (insert assms, simp_all add: Sup_multiset_unbounded) - with assms show ?thesis by (simp add: in_Sup_multiset_iff) -qed + using Sup_multiset_unbounded assms in_Sup_multiset_iff by fastforce interpretation subset_mset: distrib_lattice "(\#)" "(\#)" "(\#)" "(\#)" proof @@ -1328,11 +1287,7 @@ lemma multiset_filter_mono: assumes "A \# B" shows "filter_mset f A \# filter_mset f B" -proof - - from assms[unfolded mset_subset_eq_exists_conv] - obtain C where B: "B = A + C" by auto - show ?thesis unfolding B by auto -qed + by (metis assms filter_sup_mset subset_mset.order_iff) lemma filter_mset_eq_conv: "filter_mset P M = N \ N \# M \ (\b\#N. P b) \ (\a\#M - N. \ P a)" (is "?P \ ?Q") @@ -1421,16 +1376,16 @@ size_multiset_overloaded_def[THEN fun_cong, unfolded size_multiset_eq, simplified] lemma size_multiset_empty [simp]: "size_multiset f {#} = 0" -by (simp add: size_multiset_def) + by (simp add: size_multiset_def) lemma size_empty [simp]: "size {#} = 0" -by (simp add: size_multiset_overloaded_def) + by (simp add: size_multiset_overloaded_def) lemma size_multiset_single : "size_multiset f {#b#} = Suc (f b)" -by (simp add: size_multiset_eq) + by (simp add: size_multiset_eq) lemma size_single: "size {#b#} = 1" -by (simp add: size_multiset_overloaded_def size_multiset_single) + by (simp add: size_multiset_overloaded_def size_multiset_single) lemma sum_wcount_Int: "finite A \ sum (wcount f N) (A \ set_mset N) = sum (wcount f N) A" @@ -1439,20 +1394,18 @@ lemma size_multiset_union [simp]: "size_multiset f (M + N::'a multiset) = size_multiset f M + size_multiset f N" -apply (simp add: size_multiset_def sum_Un_nat sum.distrib sum_wcount_Int wcount_union) -apply (subst Int_commute) -apply (simp add: sum_wcount_Int) -done + apply (simp add: size_multiset_def sum_Un_nat sum.distrib sum_wcount_Int wcount_union) + by (metis add_implies_diff finite_set_mset inf.commute sum_wcount_Int) lemma size_multiset_add_mset [simp]: "size_multiset f (add_mset a M) = Suc (f a) + size_multiset f M" - unfolding add_mset_add_single[of _ M] size_multiset_union by (auto simp: size_multiset_single) + by (metis add.commute add_mset_add_single size_multiset_single size_multiset_union) lemma size_add_mset [simp]: "size (add_mset a A) = Suc (size A)" -by (simp add: size_multiset_overloaded_def wcount_add_mset) + by (simp add: size_multiset_overloaded_def wcount_add_mset) lemma size_union [simp]: "size (M + N::'a multiset) = size M + size N" -by (auto simp add: size_multiset_overloaded_def) + by (auto simp add: size_multiset_overloaded_def) lemma size_multiset_eq_0_iff_empty [iff]: "size_multiset f M = 0 \ M = {#}" @@ -1462,23 +1415,15 @@ by (auto simp add: size_multiset_overloaded_def) lemma nonempty_has_size: "(S \ {#}) = (0 < size S)" -by (metis gr0I gr_implies_not0 size_empty size_eq_0_iff_empty) + by (metis gr0I gr_implies_not0 size_empty size_eq_0_iff_empty) lemma size_eq_Suc_imp_elem: "size M = Suc n \ \a. a \# M" -apply (unfold size_multiset_overloaded_eq) -apply (drule sum_SucD) -apply auto -done + using all_not_in_conv by fastforce lemma size_eq_Suc_imp_eq_union: assumes "size M = Suc n" shows "\a N. M = add_mset a N" -proof - - from assms obtain a where "a \# M" - by (erule size_eq_Suc_imp_elem [THEN exE]) - then have "M = add_mset a (M - {#a#})" by simp - then show ?thesis by blast -qed + by (metis assms insert_DiffM size_eq_Suc_imp_elem) lemma size_mset_mono: fixes A B :: "'a multiset" @@ -1491,7 +1436,7 @@ qed lemma size_filter_mset_lesseq[simp]: "size (filter_mset f M) \ size M" -by (rule size_mset_mono[OF multiset_filter_subset]) + by (rule size_mset_mono[OF multiset_filter_subset]) lemma size_Diff_submset: "M \# M' \ size (M' - M) = size M' - size(M::'a multiset)" @@ -1560,22 +1505,21 @@ qed (simp add: empty) lemma multi_nonempty_split: "M \ {#} \ \A a. M = add_mset a A" -by (induct M) auto + by (induct M) auto lemma multiset_cases [cases type]: - obtains (empty) "M = {#}" - | (add) x N where "M = add_mset x N" + obtains (empty) "M = {#}" | (add) x N where "M = add_mset x N" by (induct M) simp_all lemma multi_drop_mem_not_eq: "c \# B \ B - {#c#} \ B" -by (cases "B = {#}") (auto dest: multi_member_split) + by (cases "B = {#}") (auto dest: multi_member_split) lemma union_filter_mset_complement[simp]: "\x. P x = (\ Q x) \ filter_mset P M + filter_mset Q M = M" -by (subst multiset_eq_iff) auto + by (subst multiset_eq_iff) auto lemma multiset_partition: "M = {#x \# M. P x#} + {#x \# M. \ P x#}" -by simp + by simp lemma mset_subset_size: "A \# B \ size A < size B" proof (induct A arbitrary: B) @@ -1587,8 +1531,7 @@ have "add_mset x A \# B" by (meson add.prems subset_mset_def) then show ?case - by (metis (no_types) add.prems add.right_neutral add_diff_cancel_left' leD nat_neq_iff - size_Diff_submset size_eq_0_iff_empty size_mset_mono subset_mset.le_iff_add subset_mset_def) + using add.prems subset_mset.less_eqE by fastforce qed lemma size_1_singleton_mset: "size M = 1 \ \a. M = {#a#}" @@ -1605,19 +1548,17 @@ text \Well-foundedness of strict subset relation\ lemma wf_subset_mset_rel: "wf {(M, N :: 'a multiset). M \# N}" -apply (rule wf_measure [THEN wf_subset, where f1=size]) -apply (clarsimp simp: measure_def inv_image_def mset_subset_size) -done + using mset_subset_size wfP_def wfP_if_convertible_to_nat by blast lemma wfP_subset_mset[simp]: "wfP (\#)" by (rule wf_subset_mset_rel[to_pred]) lemma full_multiset_induct [case_names less]: -assumes ih: "\B. \(A::'a multiset). A \# B \ P A \ P B" -shows "P B" -apply (rule wf_subset_mset_rel [THEN wf_induct]) -apply (rule ih, auto) -done + assumes ih: "\B. \(A::'a multiset). A \# B \ P A \ P B" + shows "P B" + apply (rule wf_subset_mset_rel [THEN wf_induct]) + apply (rule ih, auto) + done lemma multi_subset_induct [consumes 2, case_names empty add]: assumes "F \# A" @@ -1912,9 +1853,7 @@ proof (cases "x \# B") case True with add.prems have "image_mset f A = image_mset f (B - {#x#}) + C" - by (smt (verit, del_insts) add.left_commute add_cancel_right_left diff_union_cancelL - diff_union_single_conv image_mset_union union_mset_add_mset_left - union_mset_add_mset_right) + by (smt (verit) add_mset_add_mset_same_iff image_mset_add_mset insert_DiffM union_mset_add_mset_left) with add.IH have "\M3'. A = B - {#x#} + M3' \ image_mset f M3' = C" by (smt (verit, del_insts) True Un_insert_left Un_insert_right add.prems(2) inj_on_insert insert_DiffM set_mset_add_mset_insert) @@ -2035,12 +1974,7 @@ lemma set_eq_iff_mset_remdups_eq: \set x = set y \ mset (remdups x) = mset (remdups y)\ -apply (rule iffI) -apply (simp add: set_eq_iff_mset_eq_distinct[THEN iffD1]) -apply (drule distinct_remdups [THEN distinct_remdups - [THEN set_eq_iff_mset_eq_distinct [THEN iffD2]]]) -apply simp -done + using set_eq_iff_mset_eq_distinct by fastforce lemma mset_eq_imp_distinct_iff: \distinct xs \ distinct ys\ if \mset xs = mset ys\ @@ -2255,14 +2189,14 @@ lemma set_sorted_list_of_multiset [simp]: "set (sorted_list_of_multiset M) = set_mset M" -by (induct M) (simp_all add: set_insort_key) + by (induct M) (simp_all add: set_insort_key) lemma sorted_list_of_mset_set [simp]: "sorted_list_of_multiset (mset_set A) = sorted_list_of_set A" -by (cases "finite A") (induct A rule: finite_induct, simp_all) + by (cases "finite A") (induct A rule: finite_induct, simp_all) lemma mset_upt [simp]: "mset [m.. {#the (map_of xs i). i \# mset (map fst xs)#} = mset (map snd xs)" @@ -2308,7 +2242,7 @@ unfolding replicate_mset_def by (induct n) auto lemma set_mset_replicate_mset_subset[simp]: "set_mset (replicate_mset n x) = (if n = 0 then {} else {x})" - by (auto split: if_splits) + by auto lemma size_replicate_mset[simp]: "size (replicate_mset n M) = n" by (induct n, simp_all) @@ -2530,8 +2464,8 @@ shows "size {#x \# M. P x#} < size M" proof - have "size (filter_mset P M) \ size M" - using assms by (metis add.right_neutral add_diff_cancel_left' count_filter_mset mem_Collect_eq - multiset_partition nonempty_has_size set_mset_def size_union) + using assms + by (metis dual_order.strict_iff_order filter_mset_eq_conv mset_subset_size subset_mset.nless_le) then show ?thesis by (meson leD nat_neq_iff size_filter_mset_lesseq) qed @@ -3956,17 +3890,11 @@ by (force simp: mult1_def) lemma union_le_mono2: "B < D \ C + B < C + (D::'a::preorder multiset)" -apply (unfold less_multiset_def multp_def mult_def) -apply (erule trancl_induct) - apply (blast intro: mult1_union) -apply (blast intro: mult1_union trancl_trans) -done + unfolding less_multiset_def multp_def mult_def + by (induction rule: trancl_induct; blast intro: mult1_union trancl_trans) lemma union_le_mono1: "B < D \ B + C < D + (C::'a::preorder multiset)" -apply (subst add.commute [of B C]) -apply (subst add.commute [of D C]) -apply (erule union_le_mono2) -done + by (metis add.commute union_le_mono2) lemma union_less_mono: fixes A B C D :: "'a::preorder multiset" @@ -3991,8 +3919,8 @@ definition "ms_weak = ms_strict \ Id" lemma ms_reduction_pair: "reduction_pair (ms_strict, ms_weak)" -unfolding reduction_pair_def ms_strict_def ms_weak_def pair_less_def -by (auto intro: wf_mult1 wf_trancl simp: mult_def) + unfolding reduction_pair_def ms_strict_def ms_weak_def pair_less_def + by (auto intro: wf_mult1 wf_trancl simp: mult_def) lemma smsI: "(set_mset A, set_mset B) \ max_strict \ (Z + A, Z + B) \ ms_strict" @@ -4268,11 +4196,7 @@ lemma [code]: \ \not very efficient, but representation-ignorant!\ "mset_set A = mset (sorted_list_of_set A)" - apply (cases "finite A") - apply simp_all - apply (induct A rule: finite_induct) - apply simp_all - done + by (metis mset_sorted_list_of_multiset sorted_list_of_mset_set) declare size_mset [code] @@ -4313,18 +4237,15 @@ hence id: "mset ys = add_mset x (mset (ys1 @ ys2))" by auto show ?thesis unfolding subset_eq_mset_impl.simps - unfolding Some option.simps split - unfolding id - using Cons[of "ys1 @ ys2"] - unfolding subset_mset_def subseteq_mset_def by auto + by (simp add: Some id Cons) qed qed lemma [code]: "mset xs \# mset ys \ subset_eq_mset_impl xs ys \ None" - using subset_eq_mset_impl[of xs ys] by (cases "subset_eq_mset_impl xs ys", auto) + by (simp add: subset_eq_mset_impl) lemma [code]: "mset xs \# mset ys \ subset_eq_mset_impl xs ys = Some True" - using subset_eq_mset_impl[of xs ys] by (cases "subset_eq_mset_impl xs ys", auto) + using subset_eq_mset_impl by blast instantiation multiset :: (equal) equal begin @@ -4519,14 +4440,10 @@ rel: rel_mset pred: pred_mset proof - - show "image_mset id = id" - by (rule image_mset.id) show "image_mset (g \ f) = image_mset g \ image_mset f" for f g unfolding comp_def by (rule ext) (simp add: comp_def image_mset.compositionality) show "(\z. z \ set_mset X \ f z = g z) \ image_mset f X = image_mset g X" for f g X by (induct X) simp_all - show "set_mset \ image_mset f = (`) f \ set_mset" for f - by auto show "card_order natLeq" by (rule natLeq_card_order) show "BNF_Cardinal_Arithmetic.cinfinite natLeq" @@ -4538,34 +4455,15 @@ (auto simp: finite_iff_ordLess_natLeq[symmetric]) show "rel_mset R OO rel_mset S \ rel_mset (R OO S)" for R S unfolding rel_mset_def[abs_def] OO_def - apply clarify - subgoal for X Z Y xs ys' ys zs - apply (drule list_all2_reorder_left_invariance [where xs = ys' and ys = zs and xs' = ys]) - apply (auto intro: list_all2_trans) - done - done + by (smt (verit, ccfv_SIG) list_all2_reorder_left_invariance list_all2_trans predicate2I) show "rel_mset R = (\x y. \z. set_mset z \ {(x, y). R x y} \ image_mset fst z = x \ image_mset snd z = y)" for R unfolding rel_mset_def[abs_def] - apply (rule ext)+ - apply safe - apply (rule_tac x = "mset (zip xs ys)" in exI; - auto simp: in_set_zip list_all2_iff simp flip: mset_map) - apply (rename_tac XY) - apply (cut_tac X = XY in ex_mset) - apply (erule exE) - apply (rename_tac xys) - apply (rule_tac x = "map fst xys" in exI) - apply (auto simp: mset_map) - apply (rule_tac x = "map snd xys" in exI) - apply (auto simp: mset_map list_all2I subset_eq zip_map_fst_snd) - done - show "z \ set_mset {#} \ False" for z - by auto + by (metis (no_types, lifting) ex_mset list.in_rel mem_Collect_eq mset_map set_mset_mset) show "pred_mset P = (\x. Ball (set_mset x) P)" for P by (simp add: fun_eq_iff pred_mset_iff) -qed +qed auto inductive rel_mset' :: \('a \ 'b \ bool) \ 'a multiset \ 'b multiset \ bool\ where @@ -4609,10 +4507,7 @@ and addL: "\a M N. P M N \ P (add_mset a M) N" and addR: "\a M N. P M N \ P M (add_mset a N)" shows "P M N" -apply(induct N rule: multiset_induct) - apply(induct M rule: multiset_induct, rule empty, erule addL) - apply(induct M rule: multiset_induct, erule addR, erule addR) -done + by (induct N rule: multiset_induct; induct M rule: multiset_induct) (auto simp: assms) lemma multiset_induct2_size[consumes 1, case_names empty add]: assumes c: "size M = size N" diff -r 646cd337bb08 -r 0f9cd1a5edbe src/HOL/Library/Poly_Mapping.thy --- a/src/HOL/Library/Poly_Mapping.thy Wed Apr 10 11:32:48 2024 +0100 +++ b/src/HOL/Library/Poly_Mapping.thy Fri Apr 12 09:58:32 2024 +0100 @@ -459,7 +459,7 @@ {b. \a. (f a * g b when k = a + b) \ 0} \ {a. f a \ 0} \ {b. g b \ 0}" by auto ultimately show ?thesis using fin_g - by (auto simp add: prod_fun_def + by (auto simp: prod_fun_def Sum_any.cartesian_product [of "{a. f a \ 0} \ {b. g b \ 0}"] Sum_any_right_distrib mult_when) qed @@ -526,14 +526,13 @@ have "?lhs k = (\(ab, c). (\(a, b). f a * g b when ab = a + b) * h c when k = ab + c)" by (simp add: prod_fun_unfold_prod) also have "\ = (\(ab, c). (\(a, b). f a * g b * h c when k = ab + c when ab = a + b))" - apply (subst Sum_any_left_distrib) - using fin_fg apply (simp add: split_def) - apply (subst Sum_any_when_independent [symmetric]) - apply (simp add: when_when when_mult mult_when split_def conj_commute) + using fin_fg + apply (simp add: Sum_any_left_distrib split_def flip: Sum_any_when_independent) + apply (simp add: when_when when_mult mult_when conj_commute) done also have "\ = (\(ab, c, a, b). f a * g b * h c when k = ab + c when ab = a + b)" apply (subst Sum_any.cartesian_product2 [of "(?FG' \ ?H) \ ?FG"]) - apply (auto simp add: finite_cartesian_product_iff fin_fg fin_fg' fin_h dest: mult_not_zero) + apply (auto simp: finite_cartesian_product_iff fin_fg fin_fg' fin_h dest: mult_not_zero) done also have "\ = (\(ab, c, a, b). f a * g b * h c when k = a + b + c when ab = a + b)" by (rule Sum_any.cong) (simp add: split_def when_def) @@ -558,7 +557,7 @@ qed also have "\ = (\(a, bc). (\(b, c). f a * g b * h c when bc = b + c when k = a + bc))" apply (subst Sum_any.cartesian_product2 [of "(?F \ ?GH') \ ?GH"]) - apply (auto simp add: finite_cartesian_product_iff fin_f fin_gh fin_gh' ac_simps dest: mult_not_zero) + apply (auto simp: finite_cartesian_product_iff fin_f fin_gh fin_gh' ac_simps dest: mult_not_zero) done also have "\ = (\(a, bc). f a * (\(b, c). g b * h c when bc = b + c) when k = a + bc)" apply (subst Sum_any_right_distrib) @@ -580,10 +579,8 @@ assume fin_h: "finite {k. h k \ 0}" show "prod_fun (\k. f k + g k) h = (\k. prod_fun f h k + prod_fun g h k)" apply (rule ext) - apply (auto simp add: prod_fun_def algebra_simps) - apply (subst Sum_any.distrib) - using fin_f fin_g apply (auto intro: finite_mult_not_eq_zero_rightI) - done + apply (simp add: prod_fun_def algebra_simps) + by (simp add: Sum_any.distrib fin_f fin_g finite_mult_not_eq_zero_rightI) qed show "a * (b + c) = a * b + a * c" proof transfer @@ -593,15 +590,8 @@ assume fin_h: "finite {k. h k \ 0}" show "prod_fun f (\k. g k + h k) = (\k. prod_fun f g k + prod_fun f h k)" apply (rule ext) - apply (auto simp add: prod_fun_def Sum_any.distrib algebra_simps when_add_distrib) - apply (subst Sum_any.distrib) - apply (simp_all add: algebra_simps) - apply (auto intro: fin_g fin_h) - apply (subst Sum_any.distrib) - apply (simp_all add: algebra_simps) - using fin_f apply (rule finite_mult_not_eq_zero_rightI) - using fin_f apply (rule finite_mult_not_eq_zero_rightI) - done + apply (auto simp: prod_fun_def Sum_any.distrib algebra_simps when_add_distrib fin_g fin_h) + by (simp add: Sum_any.distrib fin_f finite_mult_not_eq_zero_rightI) qed show "0 * a = 0" by transfer (simp add: prod_fun_def [abs_def]) @@ -632,16 +622,10 @@ using fin_g by auto from fin_f fin_g have "finite {(a, b). f a \ 0 \ g b \ 0}" (is "finite ?AB") by simp - show "prod_fun f g k = prod_fun g f k" - apply (simp add: prod_fun_def) - apply (subst Sum_any_right_distrib) - apply (rule fin2) - apply (subst Sum_any_right_distrib) - apply (rule fin1) - apply (subst Sum_any.swap [of ?AB]) - apply (fact \finite ?AB\) - apply (auto simp add: mult_when ac_simps) - done + have "(\a. \n. f a * (g n when k = a + n)) = (\a. \n. g a * (f n when k = a + n))" + by (subst Sum_any.swap [OF \finite ?AB\]) (auto simp: mult_when ac_simps) + then show "prod_fun f g k = prod_fun g f k" + by (simp add: prod_fun_def Sum_any_right_distrib [OF fin2] Sum_any_right_distrib [OF fin1]) qed qed show "(a + b) * c = a * c + b * c" @@ -651,12 +635,8 @@ assume fin_g: "finite {k. g k \ 0}" assume fin_h: "finite {k. h k \ 0}" show "prod_fun (\k. f k + g k) h = (\k. prod_fun f h k + prod_fun g h k)" - apply (auto simp add: prod_fun_def fun_eq_iff algebra_simps) - apply (subst Sum_any.distrib) - using fin_f apply (rule finite_mult_not_eq_zero_rightI) - using fin_g apply (rule finite_mult_not_eq_zero_rightI) - apply simp_all - done + by (auto simp: prod_fun_def fun_eq_iff algebra_simps + Sum_any.distrib fin_f fin_g finite_mult_not_eq_zero_rightI) qed qed @@ -720,7 +700,7 @@ lemma lookup_single: "lookup (single k v) k' = (v when k = k')" - by transfer rule + by (simp add: single.rep_eq) lemma lookup_single_eq [simp]: "lookup (single k v) k = v" @@ -810,11 +790,7 @@ lemma lookup_of_int: "lookup (of_int l) k = (of_int l when k = 0)" -proof - - have "lookup (of_int l) k = lookup (single 0 (of_int l)) k" - by simp - then show ?thesis unfolding lookup_single by simp -qed + by (metis lookup_single_not_eq single.rep_eq single_of_int) subsection \Integral domains\ @@ -841,10 +817,10 @@ by simp assume "f \ (\a. 0)" then obtain a where "f a \ 0" - by (auto simp add: fun_eq_iff) + by (auto simp: fun_eq_iff) assume "g \ (\b. 0)" then obtain b where "g b \ 0" - by (auto simp add: fun_eq_iff) + by (auto simp: fun_eq_iff) from \f a \ 0\ and \g b \ 0\ have "F \ {}" and "G \ {}" by auto note Max_F = \finite F\ \F \ {}\ @@ -860,7 +836,7 @@ define q where "q = Max F + Max G" have "(\(a, b). f a * g b when q = a + b) = (\(a, b). f a * g b when q = a + b when a \ F \ b \ G)" - by (rule Sum_any.cong) (auto simp add: split_def when_def q_def intro: ccontr) + by (rule Sum_any.cong) (auto simp: split_def when_def q_def intro: ccontr) also have "\ = (\(a, b). f a * g b when (Max F, Max G) = (a, b))" proof (rule Sum_any.cong) @@ -873,7 +849,7 @@ by auto show "(case ab of (a, b) \ f a * g b when q = a + b when a \ F \ b \ G) = (case ab of (a, b) \ f a * g b when (Max F, Max G) = (a, b))" - by (auto simp add: split_def when_def q_def dest: add_strict_mono [of a "Max F" b "Max G"]) + by (auto simp: split_def when_def q_def dest: add_strict_mono [of a "Max F" b "Max G"]) qed also have "\ = (\ab. (case ab of (a, b) \ f a * g b) when (Max F, Max G) = ab)" @@ -883,7 +859,7 @@ finally have "prod_fun f g q \ 0" by (simp add: prod_fun_unfold_prod) then show "prod_fun f g \ (\k. 0)" - by (auto simp add: fun_eq_iff) + by (auto simp: fun_eq_iff) qed qed @@ -954,7 +930,7 @@ by (blast intro: less_funI) } with * show "less_fun (\k. h k + f k) (\k. h k + g k) \ (\k. h k + f k) = (\k. h k + g k)" - by (auto simp add: fun_eq_iff) + by (auto simp: fun_eq_iff) qed instance poly_mapping :: (linorder, "{ordered_comm_monoid_add, ordered_ab_semigroup_add_imp_le, cancel_comm_monoid_add, linorder}") linordered_cancel_ab_semigroup_add @@ -1036,7 +1012,7 @@ lemma range_one [simp]: "range 1 = {1}" - by transfer (auto simp add: when_def) + by transfer (auto simp: when_def) lemma keys_single [simp]: "keys (single k v) = (if v = 0 then {} else {k})" @@ -1044,13 +1020,12 @@ lemma range_single [simp]: "range (single k v) = (if v = 0 then {} else {v})" - by transfer (auto simp add: when_def) + by transfer (auto simp: when_def) lemma keys_mult: "keys (f * g) \ {a + b | a b. a \ keys f \ b \ keys g}" apply transfer - apply (auto simp add: prod_fun_def dest!: mult_not_zero elim!: Sum_any.not_neutral_obtains_not_neutral) - apply blast + apply (force simp: prod_fun_def dest!: mult_not_zero elim!: Sum_any.not_neutral_obtains_not_neutral) done lemma setsum_keys_plus_distrib: @@ -1064,13 +1039,7 @@ proof - let ?A = "Poly_Mapping.keys p \ Poly_Mapping.keys q" have "?lhs = (\k\?A. f k (Poly_Mapping.lookup p k + Poly_Mapping.lookup q k))" - apply(rule sum.mono_neutral_cong_left) - apply(simp_all add: Poly_Mapping.keys_add) - apply(transfer fixing: f) - apply(auto simp add: hom_0)[1] - apply(transfer fixing: f) - apply(auto simp add: hom_0)[1] - done + by(intro sum.mono_neutral_cong_left) (auto simp: sum.mono_neutral_cong_left hom_0 in_keys_iff lookup_add) also have "\ = (\k\?A. f k (Poly_Mapping.lookup p k) + f k (Poly_Mapping.lookup q k))" by(rule sum.cong)(simp_all add: hom_plus) also have "\ = (\k\?A. f k (Poly_Mapping.lookup p k)) + (\k\?A. f k (Poly_Mapping.lookup q k))" @@ -1138,14 +1107,14 @@ shows "degree f - 1 \ keys f" proof - from assms have "keys f \ {}" - by (auto simp add: degree_def) + by (auto simp: degree_def) then show ?thesis unfolding degree_def by (simp add: mono_Max_commute [symmetric] mono_Suc) qed lemma in_keys_less_degree: "n \ keys f \ n < degree f" -unfolding degree_def by transfer (auto simp add: Max_gr_iff) +unfolding degree_def by transfer (auto simp: Max_gr_iff) lemma beyond_degree_lookup_zero: "degree f \ n \ lookup f n = 0" @@ -1307,7 +1276,7 @@ { fix x have "prod_fun (\k'. s when 0 = k') p x = (\l :: 'a. if l = 0 then s * (\q. p q when x = q) else 0)" - by(auto simp add: prod_fun_def when_def intro: Sum_any.cong simp del: Sum_any.delta) + by(auto simp: prod_fun_def when_def intro: Sum_any.cong simp del: Sum_any.delta) also have "\ = (\k. s * p k when p k \ 0) x" by(simp add: when_def) also note calculation } then show "(\k. s * p k when p k \ 0) = prod_fun (\k'. s when 0 = k') p" @@ -1316,10 +1285,10 @@ lemma map_single [simp]: "(c = 0 \ f 0 = 0) \ map f (single x c) = single x (f c)" -by transfer(auto simp add: fun_eq_iff when_def) + by transfer(auto simp: fun_eq_iff when_def) lemma map_eq_zero_iff: "map f p = 0 \ (\k \ keys p. f (lookup p k) = 0)" -by transfer(auto simp add: fun_eq_iff when_def) + by transfer(auto simp: fun_eq_iff when_def) subsection \Canonical dense representation of @{typ "nat \\<^sub>0 'a"}\ @@ -1345,7 +1314,7 @@ proof (transfer, rule ext) fix n :: nat and v :: 'a show "nth_default 0 [v] n = (v when 0 = n)" - by (auto simp add: nth_default_def nth_append) + by (auto simp: nth_default_def nth_append) qed lemma nth_replicate [simp]: @@ -1353,7 +1322,7 @@ proof (transfer, rule ext) fix m n :: nat and v :: 'a show "nth_default 0 (replicate n 0 @ [v]) m = (v when n = m)" - by (auto simp add: nth_default_def nth_append) + by (auto simp: nth_default_def nth_append) qed lemma nth_strip_while [simp]: @@ -1379,16 +1348,16 @@ { fix n assume "nth_default 0 xs n \ 0" then have "n < length xs" and "xs ! n \ 0" - by (auto simp add: nth_default_def split: if_splits) + by (auto simp: nth_default_def split: if_splits) then have "(n, xs ! n) \ {(n, v). (n, v) \ set (enumerate 0 xs) \ v \ 0}" (is "?x \ ?A") - by (auto simp add: in_set_conv_nth enumerate_eq_zip) + by (auto simp: in_set_conv_nth enumerate_eq_zip) then have "fst ?x \ fst ` ?A" by blast then have "n \ fst ` {(n, v). (n, v) \ set (enumerate 0 xs) \ v \ 0}" by simp } then show "{k. nth_default 0 xs k \ 0} = fst ` {(n, v). (n, v) \ set (enumerate 0 xs) \ v \ 0}" - by (auto simp add: in_enumerate_iff_nth_default_eq) + by (auto simp: in_enumerate_iff_nth_default_eq) qed lemma range_nth [simp]: @@ -1409,16 +1378,16 @@ with * obtain n where n: "n < length xs" "xs ! n \ 0" by (fastforce simp add: no_trailing_unfold last_conv_nth neq_Nil_conv) then have "?bound = Max (Suc ` {k. (k < length xs \ xs ! k \ (0::'a)) \ k < length xs})" - by (subst Max_insert) (auto simp add: nth_default_def) + by (subst Max_insert) (auto simp: nth_default_def) also let ?A = "{k. k < length xs \ xs ! k \ 0}" have "{k. (k < length xs \ xs ! k \ (0::'a)) \ k < length xs} = ?A" by auto also have "Max (Suc ` ?A) = Suc (Max ?A)" using n - by (subst mono_Max_commute [where f = Suc, symmetric]) (auto simp add: mono_Suc) + by (subst mono_Max_commute [where f = Suc, symmetric]) (auto simp: mono_Suc) also { have "Max ?A \ ?A" using n Max_in [of ?A] by fastforce hence "Suc (Max ?A) \ length xs" by simp moreover from * False have "length xs - 1 \ ?A" - by(auto simp add: no_trailing_unfold last_conv_nth) + by(auto simp: no_trailing_unfold last_conv_nth) hence "length xs - 1 \ Max ?A" using Max_ge[of ?A "length xs - 1"] by auto hence "length xs \ Suc (Max ?A)" by simp ultimately have "Suc (Max ?A) = length xs" by simp } @@ -1433,7 +1402,7 @@ lemma nth_idem: "nth (List.map (lookup f) [0.. n" @@ -1444,7 +1413,7 @@ then have "[0..k' \ ?keys. f k' + g (m k') when k' = k)" by (simp add: sum.delta when_def) also have "\ < (\k' \ ?keys. Suc (f k' + g (m k')))" using * - by (intro sum_strict_mono) (auto simp add: when_def) + by (intro sum_strict_mono) (auto simp: when_def) also have "\ \ g 0 + \" by simp finally have "f k + g (m k) < \" . then show "f k + g (m k) < g 0 + (\k | m k \ 0. Suc (f k + g (m k)))" @@ -1599,7 +1568,7 @@ "m = m' \ g 0 = g' 0 \ (\k. k \ keys m' \ f k = f' k) \ (\v. v \ range m' \ g v = g' v) \ poly_mapping_size f g m = poly_mapping_size f' g' m'" - by (auto simp add: poly_mapping_size_def intro!: sum.cong) + by (auto simp: poly_mapping_size_def intro!: sum.cong) instantiation poly_mapping :: (type, zero) size begin @@ -1623,7 +1592,7 @@ lemma mapp_cong [fundef_cong]: "\ m = m'; \k. k \ keys m' \ f k (lookup m' k) = f' k (lookup m' k) \ \ mapp f m = mapp f' m'" - by transfer (auto simp add: fun_eq_iff) + by transfer (auto simp: fun_eq_iff) lemma lookup_mapp: "lookup (mapp f p) k = (f k (lookup p k) when k \ keys p)" @@ -1688,8 +1657,6 @@ lemma keys_cmul_iff [iff]: "i \ Poly_Mapping.keys (frag_cmul c x) \ i \ Poly_Mapping.keys x \ c \ 0" - apply auto - apply (meson subsetD keys_cmul) by (metis in_keys_iff lookup_frag_cmul mult_eq_0_iff) lemma keys_minus [simp]: "Poly_Mapping.keys(-a) = Poly_Mapping.keys a" @@ -1697,7 +1664,7 @@ lemma keys_diff: "Poly_Mapping.keys(a - b) \ Poly_Mapping.keys a \ Poly_Mapping.keys b" - by (auto simp add: in_keys_iff lookup_minus) + by (auto simp: in_keys_iff lookup_minus) lemma keys_eq_empty [simp]: "Poly_Mapping.keys c = {} \ c = 0" by (metis in_keys_iff keys_zero lookup_zero poly_mapping_eqI) @@ -1769,10 +1736,11 @@ by (auto simp: frag_extend_def Poly_Mapping.lookup_add frag_cmul_distrib) also have "... = (\i \ Poly_Mapping.keys a \ Poly_Mapping.keys b. frag_cmul (poly_mapping.lookup a i) (f i) + frag_cmul (poly_mapping.lookup b i) (f i))" - apply (rule sum.mono_neutral_cong_left) - using keys_add [of a b] - apply (auto simp add: in_keys_iff plus_poly_mapping.rep_eq frag_cmul_distrib [symmetric]) - done + proof (rule sum.mono_neutral_cong_left) + show "\i\keys a \ keys b - keys (a + b). + frag_cmul (lookup a i) (f i) + frag_cmul (lookup b i) (f i) = 0" + by (metis DiffD2 frag_cmul_distrib frag_cmul_zero in_keys_iff lookup_add) + qed (auto simp: keys_add) also have "... = (frag_extend f a) + (frag_extend f b)" by (auto simp: * sum.distrib frag_extend_def) finally show ?thesis . @@ -1814,9 +1782,15 @@ shows "P(frag_cmul k c)" proof - have "P (frag_cmul (int n) c)" for n - apply (induction n) - apply (simp_all add: assms frag_cmul_distrib) - by (metis add.left_neutral add_diff_cancel_right' add_uminus_conv_diff P) + proof (induction n) + case 0 + then show ?case + by (simp add: assms) + next + case (Suc n) + then show ?case + by (metis assms diff_0 diff_minus_eq_add frag_cmul_distrib frag_cmul_one of_nat_Suc) + qed then show ?thesis by (metis (no_types, opaque_lifting) add_diff_eq assms(2) diff_add_cancel frag_cmul_distrib int_diff_cases) qed @@ -1840,14 +1814,11 @@ by simp have Pfrag: "P (frag_cmul (poly_mapping.lookup c i) (frag_of i))" by (metis "0" diff frag_closure_minus_cmul insert.prems insert_subset sing subset_iff) - show ?case - apply (simp add: insert.hyps) - apply (subst ab) - using insert apply (blast intro: assms Pfrag) - done + with insert show ?case + by (metis (mono_tags, lifting) "0" ab diff insert_subset sum.insert) qed then show ?thesis - by (subst frag_expansion) (auto simp add: frag_extend_def) + by (subst frag_expansion) (auto simp: frag_extend_def) qed lemma frag_extend_compose: