# HG changeset patch # User wenzelm # Date 1590347483 -7200 # Node ID 45f85e283ce075981e52f02f612dbcd796e96d27 # Parent 86cfb9fa3da82b14c3bcb5e2a247ae422b9d01d6# Parent 2bf0283fc9755a9d6b8e868f116c4ae0574f5c64 merged diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/Analysis/Abstract_Topology.thy --- a/src/HOL/Analysis/Abstract_Topology.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/Analysis/Abstract_Topology.thy Sun May 24 21:11:23 2020 +0200 @@ -2673,7 +2673,8 @@ then have "False" using homeomorphic_map_closure_of [OF hom] hom unfolding homeomorphic_eq_everything_map - by (metis (no_types, lifting) Diff_subset S closure_of_subset_topspace inj_on_image_mem_iff_alt inj_on_image_set_diff) } + by (metis Diff_subset S closure_of_subset_topspace inj_on_image_mem_iff inj_on_image_set_diff) + } ultimately show ?thesis by (auto simp: interior_of_closure_of) qed @@ -2700,7 +2701,7 @@ then have "y \ topspace X" by (simp add: in_closure_of) then have "f y \ f ` (X interior_of S)" - by (meson hom homeomorphic_eq_everything_map inj_on_image_mem_iff_alt interior_of_subset_topspace y(3)) + by (meson hom homeomorphic_map_def inj_on_image_mem_iff interior_of_subset_topspace y(3)) then show "x \ Y interior_of f ` S" using S hom homeomorphic_map_interior_of y(1) by blast qed diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/Analysis/Starlike.thy --- a/src/HOL/Analysis/Starlike.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/Analysis/Starlike.thy Sun May 24 21:11:23 2020 +0200 @@ -3519,7 +3519,7 @@ ultimately have "f a \ f ` closed_segment c b" by blast then have a: "a \ closed_segment c b" - by (meson ends_in_segment inj_on_image_mem_iff_alt injf subset_closed_segment that) + by (meson ends_in_segment inj_on_image_mem_iff injf subset_closed_segment that) have cb: "closed_segment c b \ closed_segment a b" by (simp add: closed_segment_subset that) show "f a = f c" @@ -3539,7 +3539,7 @@ ultimately have "f b \ f ` closed_segment a c" by blast then have b: "b \ closed_segment a c" - by (meson ends_in_segment inj_on_image_mem_iff_alt injf subset_closed_segment that) + by (meson ends_in_segment inj_on_image_mem_iff injf subset_closed_segment that) have ca: "closed_segment a c \ closed_segment a b" by (simp add: closed_segment_subset that) show "f b = f c" diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/BNF_Wellorder_Embedding.thy --- a/src/HOL/BNF_Wellorder_Embedding.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/BNF_Wellorder_Embedding.thy Sun May 24 21:11:23 2020 +0200 @@ -1003,55 +1003,29 @@ with * show "iso r r' f" unfolding iso_def by auto qed -lemma iso_iff2: -assumes "Well_order r" -shows "iso r r' f = (bij_betw f (Field r) (Field r') \ - (\a \ Field r. \b \ Field r. - (((a,b) \ r) = ((f a, f b) \ r'))))" -using assms -proof(auto simp add: iso_def) - fix a b - assume "embed r r' f" - hence "compat r r' f" using embed_compat[of r] by auto - moreover assume "(a,b) \ r" - ultimately show "(f a, f b) \ r'" using compat_def[of r] by auto -next - let ?f' = "inv_into (Field r) f" - assume "embed r r' f" and 1: "bij_betw f (Field r) (Field r')" - hence "embed r' r ?f'" using assms - by (auto simp add: inv_into_Field_embed_bij_betw) - hence 2: "compat r' r ?f'" using embed_compat[of r'] by auto - fix a b assume *: "a \ Field r" "b \ Field r" and **: "(f a,f b) \ r'" - hence "?f'(f a) = a \ ?f'(f b) = b" using 1 - by (auto simp add: bij_betw_inv_into_left) - thus "(a,b) \ r" using ** 2 compat_def[of r' r ?f'] by fastforce +lemma iso_iff2: "iso r r' f \ + bij_betw f (Field r) (Field r') \ + (\a \ Field r. \b \ Field r. (a, b) \ r \ (f a, f b) \ r')" + (is "?lhs = ?rhs") +proof + assume L: ?lhs + then have "bij_betw f (Field r) (Field r')" and emb: "embed r r' f" + by (auto simp: bij_betw_def iso_def) + then obtain g where g: "\x. x \ Field r \ g (f x) = x" + by (auto simp: bij_betw_iff_bijections) + moreover + have "(a, b) \ r" if "a \ Field r" "b \ Field r" "(f a, f b) \ r'" for a b + using that emb g g [OF FieldI1] \\yes it's weird\ + by (force simp add: embed_def under_def bij_betw_iff_bijections) + ultimately show ?rhs + using L by (auto simp: compat_def iso_def dest: embed_compat) next - assume *: "bij_betw f (Field r) (Field r')" and - **: "\a\Field r. \b\Field r. ((a, b) \ r) = ((f a, f b) \ r')" - have 1: "\ a. under r a \ Field r \ under r' (f a) \ Field r'" - by (auto simp add: under_Field) - have 2: "inj_on f (Field r)" using * by (auto simp add: bij_betw_def) - {fix a assume ***: "a \ Field r" - have "bij_betw f (under r a) (under r' (f a))" - proof(unfold bij_betw_def, auto) - show "inj_on f (under r a)" using 1 2 subset_inj_on by blast - next - fix b assume "b \ under r a" - hence "a \ Field r \ b \ Field r \ (b,a) \ r" - unfolding under_def by (auto simp add: Field_def Range_def Domain_def) - with 1 ** show "f b \ under r' (f a)" - unfolding under_def by auto - next - fix b' assume "b' \ under r' (f a)" - hence 3: "(b',f a) \ r'" unfolding under_def by simp - hence "b' \ Field r'" unfolding Field_def by auto - with * obtain b where "b \ Field r \ f b = b'" - unfolding bij_betw_def by force - with 3 ** *** - show "b' \ f ` (under r a)" unfolding under_def by blast - qed - } - thus "embed r r' f" unfolding embed_def using * by auto + assume R: ?rhs + then show ?lhs + apply (clarsimp simp add: iso_def embed_def under_def bij_betw_iff_bijections) + apply (rule_tac x="g" in exI) + apply (fastforce simp add: intro: FieldI1)+ + done qed lemma iso_iff3: diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/Data_Structures/Balance.thy --- a/src/HOL/Data_Structures/Balance.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/Data_Structures/Balance.thy Sun May 24 21:11:23 2020 +0200 @@ -42,23 +42,23 @@ lemma bal_inorder: "\ n \ length xs; bal n xs = (t,zs) \ \ xs = inorder t @ zs \ size t = n" -proof(induction n xs arbitrary: t zs rule: bal.induct) - case (1 n xs) show ?case +proof(induction n arbitrary: xs t zs rule: less_induct) + case (less n) show ?case proof cases - assume "n = 0" thus ?thesis using 1 by (simp add: bal_simps) + assume "n = 0" thus ?thesis using less.prems by (simp add: bal_simps) next assume [arith]: "n \ 0" let ?m = "n div 2" let ?m' = "n - 1 - ?m" - from "1.prems"(2) obtain l r ys where + from less.prems(2) obtain l r ys where b1: "bal ?m xs = (l,ys)" and b2: "bal ?m' (tl ys) = (r,zs)" and t: "t = \l, hd ys, r\" by(auto simp: bal_simps split: prod.splits) have IH1: "xs = inorder l @ ys \ size l = ?m" - using b1 "1.prems"(1) by(intro "1.IH"(1)) auto + using b1 less.prems(1) by(intro less.IH) auto have IH2: "tl ys = inorder r @ zs \ size r = ?m'" - using b1 b2 IH1 "1.prems"(1) by(intro "1.IH"(2)) auto - show ?thesis using t IH1 IH2 "1.prems"(1) hd_Cons_tl[of ys] by fastforce + using b2 IH1 less.prems(1) by(intro less.IH) auto + show ?thesis using t IH1 IH2 less.prems(1) hd_Cons_tl[of ys] by fastforce qed qed @@ -102,24 +102,24 @@ lemma min_height_bal: "\ n \ length xs; bal n xs = (t,zs) \ \ min_height t = nat(\log 2 (n + 1)\)" -proof(induction n xs arbitrary: t zs rule: bal.induct) - case (1 n xs) +proof(induction n arbitrary: xs t zs rule: less_induct) + case (less n) show ?case proof cases - assume "n = 0" thus ?thesis using "1.prems"(2) by (simp add: bal_simps) + assume "n = 0" thus ?thesis using less.prems(2) by (simp add: bal_simps) next assume [arith]: "n \ 0" let ?m = "n div 2" let ?m' = "n - 1 - ?m" - from "1.prems" obtain l r ys where + from less.prems obtain l r ys where b1: "bal ?m xs = (l,ys)" and b2: "bal ?m' (tl ys) = (r,zs)" and t: "t = \l, hd ys, r\" by(auto simp: bal_simps split: prod.splits) let ?hl = "nat (floor(log 2 (?m + 1)))" let ?hr = "nat (floor(log 2 (?m' + 1)))" - have IH1: "min_height l = ?hl" using "1.IH"(1) b1 "1.prems"(1) by simp + have IH1: "min_height l = ?hl" using less.IH[OF _ _ b1] less.prems(1) by simp have IH2: "min_height r = ?hr" - using "1.prems"(1) bal_length[OF _ b1] b1 b2 by(intro "1.IH"(2)) auto + using less.prems(1) bal_length[OF _ b1] b2 by(intro less.IH) auto have "(n+1) div 2 \ 1" by arith hence 0: "log 2 ((n+1) div 2) \ 0" by simp have "?m' \ ?m" by arith @@ -138,24 +138,24 @@ lemma height_bal: "\ n \ length xs; bal n xs = (t,zs) \ \ height t = nat \log 2 (n + 1)\" -proof(induction n xs arbitrary: t zs rule: bal.induct) - case (1 n xs) show ?case +proof(induction n arbitrary: xs t zs rule: less_induct) + case (less n) show ?case proof cases assume "n = 0" thus ?thesis - using "1.prems" by (simp add: bal_simps) + using less.prems by (simp add: bal_simps) next assume [arith]: "n \ 0" let ?m = "n div 2" let ?m' = "n - 1 - ?m" - from "1.prems" obtain l r ys where + from less.prems obtain l r ys where b1: "bal ?m xs = (l,ys)" and b2: "bal ?m' (tl ys) = (r,zs)" and t: "t = \l, hd ys, r\" by(auto simp: bal_simps split: prod.splits) let ?hl = "nat \log 2 (?m + 1)\" let ?hr = "nat \log 2 (?m' + 1)\" - have IH1: "height l = ?hl" using "1.IH"(1) b1 "1.prems"(1) by simp + have IH1: "height l = ?hl" using less.IH[OF _ _ b1] less.prems(1) by simp have IH2: "height r = ?hr" - using b1 b2 bal_length[OF _ b1] "1.prems"(1) by(intro "1.IH"(2)) auto + using b2 bal_length[OF _ b1] less.prems(1) by(intro less.IH) auto have 0: "log 2 (?m + 1) \ 0" by simp have "?m' \ ?m" by arith hence le: "?hr \ ?hl" @@ -205,23 +205,23 @@ by (simp add: balance_tree_def) lemma wbalanced_bal: "\ n \ length xs; bal n xs = (t,ys) \ \ wbalanced t" -proof(induction n xs arbitrary: t ys rule: bal.induct) - case (1 n xs) +proof(induction n arbitrary: xs t ys rule: less_induct) + case (less n) show ?case proof cases assume "n = 0" - thus ?thesis using "1.prems"(2) by(simp add: bal_simps) + thus ?thesis using less.prems(2) by(simp add: bal_simps) next assume [arith]: "n \ 0" - with "1.prems" obtain l ys r zs where + with less.prems obtain l ys r zs where rec1: "bal (n div 2) xs = (l, ys)" and rec2: "bal (n - 1 - n div 2) (tl ys) = (r, zs)" and t: "t = \l, hd ys, r\" by(auto simp add: bal_simps split: prod.splits) - have l: "wbalanced l" using "1.IH"(1)[OF \n\0\ refl _ rec1] "1.prems"(1) by linarith + have l: "wbalanced l" using less.IH[OF _ _ rec1] less.prems(1) by linarith have "wbalanced r" - using rec1 rec2 bal_length[OF _ rec1] "1.prems"(1) by(intro "1.IH"(2)) auto - with l t bal_length[OF _ rec1] "1.prems"(1) bal_inorder[OF _ rec1] bal_inorder[OF _ rec2] + using rec1 rec2 bal_length[OF _ rec1] less.prems(1) by(intro less.IH) auto + with l t bal_length[OF _ rec1] less.prems(1) bal_inorder[OF _ rec1] bal_inorder[OF _ rec2] show ?thesis by auto qed qed diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/Fun.thy --- a/src/HOL/Fun.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/Fun.thy Sun May 24 21:11:23 2020 +0200 @@ -507,10 +507,6 @@ lemma inj_on_image_mem_iff: "inj_on f B \ a \ B \ A \ B \ f a \ f ` A \ a \ A" by (auto simp: inj_on_def) -(*FIXME DELETE*) -lemma inj_on_image_mem_iff_alt: "inj_on f B \ A \ B \ f a \ f ` A \ a \ B \ a \ A" - by (blast dest: inj_onD) - lemma inj_image_mem_iff: "inj f \ f a \ f ` A \ a \ A" by (blast dest: injD) @@ -614,7 +610,20 @@ using * bij_betw_subset[of f "A \ {b}" _ A] by blast qed -text \Important examples\ +lemma inj_on_disjoint_Un: + assumes "inj_on f A" and "inj_on g B" + and "f ` A \ g ` B = {}" + shows "inj_on (\x. if x \ A then f x else g x) (A \ B)" + using assms by (simp add: inj_on_def disjoint_iff) (blast) + +lemma bij_betw_disjoint_Un: + assumes "bij_betw f A C" and "bij_betw g B D" + and "A \ B = {}" + and "C \ D = {}" + shows "bij_betw (\x. if x \ A then f x else g x) (A \ B) (C \ D)" + using assms by (auto simp: inj_on_disjoint_Un bij_betw_def) + +subsubsection \Important examples\ context cancel_semigroup_add begin @@ -859,27 +868,18 @@ unfolding the_inv_into_def inj_on_def by blast lemma f_the_inv_into_f: "inj_on f A \ y \ f ` A \ f (the_inv_into A f y) = y" - apply (simp add: the_inv_into_def) - apply (rule the1I2) - apply (blast dest: inj_onD) - apply blast - done + unfolding the_inv_into_def + by (rule the1I2; blast dest: inj_onD) lemma the_inv_into_into: "inj_on f A \ x \ f ` A \ A \ B \ the_inv_into A f x \ B" - apply (simp add: the_inv_into_def) - apply (rule the1I2) - apply (blast dest: inj_onD) - apply blast - done + unfolding the_inv_into_def + by (rule the1I2; blast dest: inj_onD) lemma the_inv_into_onto [simp]: "inj_on f A \ the_inv_into A f ` (f ` A) = A" by (fast intro: the_inv_into_into the_inv_into_f_f [symmetric]) lemma the_inv_into_f_eq: "inj_on f A \ f x = y \ x \ A \ the_inv_into A f y = x" - apply (erule subst) - apply (erule the_inv_into_f_f) - apply assumption - done + by (force simp add: the_inv_into_f_f) lemma the_inv_into_comp: "inj_on f (g ` A) \ inj_on g A \ x \ f ` g ` A \ @@ -896,6 +896,17 @@ lemma bij_betw_the_inv_into: "bij_betw f A B \ bij_betw (the_inv_into A f) B A" by (auto simp add: bij_betw_def inj_on_the_inv_into the_inv_into_into) +lemma bij_betw_iff_bijections: + "bij_betw f A B \ (\g. (\x \ A. f x \ B \ g(f x) = x) \ (\y \ B. g y \ A \ f(g y) = y))" + (is "?lhs = ?rhs") +proof + assume L: ?lhs + then show ?rhs + apply (rule_tac x="the_inv_into A f" in exI) + apply (auto simp: bij_betw_def f_the_inv_into_f the_inv_into_f_f the_inv_into_into) + done +qed (force intro: bij_betw_byWitness) + abbreviation the_inv :: "('a \ 'b) \ ('b \ 'a)" where "the_inv f \ the_inv_into UNIV f" diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/Library/Equipollence.thy --- a/src/HOL/Library/Equipollence.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/Library/Equipollence.thy Sun May 24 21:11:23 2020 +0200 @@ -98,21 +98,6 @@ by (auto simp: inj_on_def) qed auto -lemma bij_betw_iff_bijections: - "bij_betw f A B \ (\g. (\x \ A. f x \ B \ g(f x) = x) \ (\y \ B. g y \ A \ f(g y) = y))" - (is "?lhs = ?rhs") -proof - assume L: ?lhs - then show ?rhs - apply (rule_tac x="the_inv_into A f" in exI) - apply (auto simp: bij_betw_def f_the_inv_into_f the_inv_into_f_f the_inv_into_into) - done -next - assume ?rhs - then show ?lhs - by (auto simp: bij_betw_def inj_on_def image_def; metis) -qed - lemma eqpoll_iff_bijections: "A \ B \ (\f g. (\x \ A. f x \ B \ g(f x) = x) \ (\y \ B. g y \ A \ f(g y) = y))" by (auto simp: eqpoll_def bij_betw_iff_bijections) diff -r 2bf0283fc975 -r 45f85e283ce0 src/HOL/List.thy --- a/src/HOL/List.thy Sun May 24 21:01:51 2020 +0200 +++ b/src/HOL/List.thy Sun May 24 21:11:23 2020 +0200 @@ -365,8 +365,6 @@ "sorted_wrt P [] = True" | "sorted_wrt P (x # ys) = ((\y \ set ys. P x y) \ sorted_wrt P ys)" -(* FIXME: define sorted in terms of sorted_wrt *) - text \A class-based sorted predicate:\ context linorder @@ -412,6 +410,9 @@ "stable_sort_key sk = (\f xs k. filter (\y. f y = k) (sk f xs) = filter (\y. f y = k) xs)" +lemma strict_sorted_iff: "strict_sorted l \ sorted l \ distinct l" +by (induction l) (auto iff: antisym_conv1) + end @@ -6049,6 +6050,13 @@ case False thus ?thesis by simp qed +lemma length_sorted_list_of_set [simp]: "length (sorted_list_of_set A) = card A" +proof (cases "finite A") + case True + then show ?thesis + by(metis distinct_card distinct_sorted_list_of_set set_sorted_list_of_set) +qed auto + lemmas sorted_list_of_set = set_sorted_list_of_set sorted_sorted_list_of_set distinct_sorted_list_of_set lemma sorted_list_of_set_sort_remdups [code]: @@ -6069,28 +6077,18 @@ with assms show ?thesis by simp qed -end - -lemma sorted_list_of_set_range [simp]: - "sorted_list_of_set {m.. sorted l \ distinct l" - by (induction l) (use less_le in auto) - lemma strict_sorted_list_of_set [simp]: "strict_sorted (sorted_list_of_set A)" by (simp add: strict_sorted_iff) lemma finite_set_strict_sorted: - fixes A :: "'a::linorder set" assumes "finite A" - obtains l where "strict_sorted l" "List.set l = A" "length l = card A" + obtains l where "strict_sorted l" "set l = A" "length l = card A" by (metis assms distinct_card distinct_sorted_list_of_set set_sorted_list_of_set strict_sorted_list_of_set) lemma strict_sorted_equal: assumes "strict_sorted xs" and "strict_sorted ys" - and "list.set ys = list.set xs" + and "set ys = set xs" shows "ys = xs" using assms proof (induction xs arbitrary: ys) @@ -6111,9 +6109,63 @@ qed qed auto -lemma strict_sorted_equal_Uniq: "\\<^sub>\\<^sub>1xs. strict_sorted xs \ list.set xs = A" +lemma strict_sorted_equal_Uniq: "\\<^sub>\\<^sub>1xs. strict_sorted xs \ set xs = A" by (simp add: Uniq_def strict_sorted_equal) +lemma sorted_list_of_set_inject: + assumes "sorted_list_of_set A = sorted_list_of_set B" "finite A" "finite B" + shows "A = B" + using assms set_sorted_list_of_set by fastforce + +lemma sorted_list_of_set_unique: + assumes "finite A" + shows "strict_sorted l \ set l = A \ length l = card A \ sorted_list_of_set A = l" + using assms strict_sorted_equal by force + +end + +lemma sorted_list_of_set_range [simp]: + "sorted_list_of_set {m.. j" + shows "sorted_list_of_set {i<..j} = Suc i # sorted_list_of_set {Suc i<..j}" + using sorted_list_of_set_greaterThanLessThan [of i "Suc j"] + by (metis assms greaterThanAtMost_def greaterThanLessThan_eq le_imp_less_Suc lessThan_Suc_atMost) + +lemma nth_sorted_list_of_set_greaterThanLessThan: + "n < j - Suc i \ sorted_list_of_set {i<.. sorted_list_of_set {i<..j} ! n = Suc (i+n)" + using nth_sorted_list_of_set_greaterThanLessThan [of n "Suc j" i] + by (simp add: greaterThanAtMost_def greaterThanLessThan_eq lessThan_Suc_atMost) + subsubsection \\lists\: the list-forming operator over sets\