src/HOL/Library/Multiset_Order.thy
 author haftmann Sat Dec 17 15:22:13 2016 +0100 (2016-12-17) changeset 64587 8355a6e2df79 parent 64418 91eae3a1be51 child 64978 5b9ba120d222 permissions -rw-r--r--
standardized notation
 blanchet@59813 ` 1` ```(* Title: HOL/Library/Multiset_Order.thy ``` blanchet@59813 ` 2` ``` Author: Dmitriy Traytel, TU Muenchen ``` blanchet@59813 ` 3` ``` Author: Jasmin Blanchette, Inria, LORIA, MPII ``` blanchet@59813 ` 4` ```*) ``` blanchet@59813 ` 5` wenzelm@60500 ` 6` ```section \More Theorems about the Multiset Order\ ``` blanchet@59813 ` 7` blanchet@59813 ` 8` ```theory Multiset_Order ``` blanchet@59813 ` 9` ```imports Multiset ``` blanchet@59813 ` 10` ```begin ``` blanchet@59813 ` 11` blanchet@63409 ` 12` ```subsection \Alternative characterizations\ ``` blanchet@59813 ` 13` Mathias@63410 ` 14` ```context preorder ``` blanchet@59813 ` 15` ```begin ``` blanchet@59813 ` 16` blanchet@59813 ` 17` ```lemma order_mult: "class.order ``` blanchet@59813 ` 18` ``` (\M N. (M, N) \ mult {(x, y). x < y} \ M = N) ``` blanchet@59813 ` 19` ``` (\M N. (M, N) \ mult {(x, y). x < y})" ``` blanchet@59813 ` 20` ``` (is "class.order ?le ?less") ``` blanchet@59813 ` 21` ```proof - ``` blanchet@59813 ` 22` ``` have irrefl: "\M :: 'a multiset. \ ?less M M" ``` blanchet@59813 ` 23` ``` proof ``` blanchet@59813 ` 24` ``` fix M :: "'a multiset" ``` blanchet@59813 ` 25` ``` have "trans {(x'::'a, x). x' < x}" ``` Mathias@63410 ` 26` ``` by (rule transI) (blast intro: less_trans) ``` blanchet@59813 ` 27` ``` moreover ``` blanchet@59813 ` 28` ``` assume "(M, M) \ mult {(x, y). x < y}" ``` blanchet@59813 ` 29` ``` ultimately have "\I J K. M = I + J \ M = I + K ``` nipkow@60495 ` 30` ``` \ J \ {#} \ (\k\set_mset K. \j\set_mset J. (k, j) \ {(x, y). x < y})" ``` blanchet@59813 ` 31` ``` by (rule mult_implies_one_step) ``` blanchet@59813 ` 32` ``` then obtain I J K where "M = I + J" and "M = I + K" ``` nipkow@60495 ` 33` ``` and "J \ {#}" and "(\k\set_mset K. \j\set_mset J. (k, j) \ {(x, y). x < y})" by blast ``` nipkow@60495 ` 34` ``` then have aux1: "K \ {#}" and aux2: "\k\set_mset K. \j\set_mset K. k < j" by auto ``` nipkow@60495 ` 35` ``` have "finite (set_mset K)" by simp ``` blanchet@59813 ` 36` ``` moreover note aux2 ``` nipkow@60495 ` 37` ``` ultimately have "set_mset K = {}" ``` blanchet@59813 ` 38` ``` by (induct rule: finite_induct) ``` blanchet@59813 ` 39` ``` (simp, metis (mono_tags) insert_absorb insert_iff insert_not_empty less_irrefl less_trans) ``` blanchet@59813 ` 40` ``` with aux1 show False by simp ``` blanchet@59813 ` 41` ``` qed ``` blanchet@59813 ` 42` ``` have trans: "\K M N :: 'a multiset. ?less K M \ ?less M N \ ?less K N" ``` blanchet@59813 ` 43` ``` unfolding mult_def by (blast intro: trancl_trans) ``` blanchet@59813 ` 44` ``` show "class.order ?le ?less" ``` Mathias@63388 ` 45` ``` by standard (auto simp add: less_eq_multiset_def irrefl dest: trans) ``` blanchet@59813 ` 46` ```qed ``` blanchet@59813 ` 47` wenzelm@60500 ` 48` ```text \The Dershowitz--Manna ordering:\ ``` blanchet@59813 ` 49` blanchet@59813 ` 50` ```definition less_multiset\<^sub>D\<^sub>M where ``` blanchet@59813 ` 51` ``` "less_multiset\<^sub>D\<^sub>M M N \ ``` haftmann@64587 ` 52` ``` (\X Y. X \ {#} \ X \# N \ M = (N - X) + Y \ (\k. k \# Y \ (\a. a \# X \ k < a)))" ``` blanchet@59813 ` 53` blanchet@59813 ` 54` wenzelm@60500 ` 55` ```text \The Huet--Oppen ordering:\ ``` blanchet@59813 ` 56` blanchet@59813 ` 57` ```definition less_multiset\<^sub>H\<^sub>O where ``` blanchet@59813 ` 58` ``` "less_multiset\<^sub>H\<^sub>O M N \ M \ N \ (\y. count N y < count M y \ (\x. y < x \ count M x < count N x))" ``` blanchet@59813 ` 59` haftmann@62430 ` 60` ```lemma mult_imp_less_multiset\<^sub>H\<^sub>O: ``` haftmann@62430 ` 61` ``` "(M, N) \ mult {(x, y). x < y} \ less_multiset\<^sub>H\<^sub>O M N" ``` haftmann@62430 ` 62` ```proof (unfold mult_def, induct rule: trancl_induct) ``` blanchet@59813 ` 63` ``` case (base P) ``` haftmann@62430 ` 64` ``` then show ?case ``` haftmann@62430 ` 65` ``` by (auto elim!: mult1_lessE simp add: count_eq_zero_iff less_multiset\<^sub>H\<^sub>O_def split: if_splits dest!: Suc_lessD) ``` blanchet@59813 ` 66` ```next ``` blanchet@59813 ` 67` ``` case (step N P) ``` haftmann@62430 ` 68` ``` from step(3) have "M \ N" and ``` haftmann@62430 ` 69` ``` **: "\y. count N y < count M y \ (\x>y. count M x < count N x)" ``` haftmann@62430 ` 70` ``` by (simp_all add: less_multiset\<^sub>H\<^sub>O_def) ``` blanchet@59813 ` 71` ``` from step(2) obtain M0 a K where ``` Mathias@63793 ` 72` ``` *: "P = add_mset a M0" "N = M0 + K" "a \# K" "\b. b \# K \ b < a" ``` haftmann@62430 ` 73` ``` by (blast elim: mult1_lessE) ``` Mathias@63410 ` 74` ``` from \M \ N\ ** *(1,2,3) have "M \ P" by (force dest: *(4) elim!: less_asym split: if_splits ) ``` blanchet@59813 ` 75` ``` moreover ``` blanchet@59813 ` 76` ``` { assume "count P a \ count M a" ``` haftmann@62430 ` 77` ``` with \a \# K\ have "count N a < count M a" unfolding *(1,2) ``` haftmann@62430 ` 78` ``` by (auto simp add: not_in_iff) ``` haftmann@62430 ` 79` ``` with ** obtain z where z: "z > a" "count M z < count N z" ``` haftmann@62430 ` 80` ``` by blast ``` haftmann@62430 ` 81` ``` with * have "count N z \ count P z" ``` Mathias@63410 ` 82` ``` by (auto elim: less_asym intro: count_inI) ``` blanchet@59813 ` 83` ``` with z have "\z > a. count M z < count P z" by auto ``` blanchet@59813 ` 84` ``` } note count_a = this ``` blanchet@59813 ` 85` ``` { fix y ``` blanchet@59813 ` 86` ``` assume count_y: "count P y < count M y" ``` blanchet@59813 ` 87` ``` have "\x>y. count M x < count P x" ``` blanchet@59813 ` 88` ``` proof (cases "y = a") ``` blanchet@59813 ` 89` ``` case True ``` blanchet@59813 ` 90` ``` with count_y count_a show ?thesis by auto ``` blanchet@59813 ` 91` ``` next ``` blanchet@59813 ` 92` ``` case False ``` blanchet@59813 ` 93` ``` show ?thesis ``` blanchet@59813 ` 94` ``` proof (cases "y \# K") ``` blanchet@59813 ` 95` ``` case True ``` haftmann@62430 ` 96` ``` with *(4) have "y < a" by simp ``` blanchet@59813 ` 97` ``` then show ?thesis by (cases "count P a \ count M a") (auto dest: count_a intro: less_trans) ``` blanchet@59813 ` 98` ``` next ``` blanchet@59813 ` 99` ``` case False ``` haftmann@62430 ` 100` ``` with \y \ a\ have "count P y = count N y" unfolding *(1,2) ``` haftmann@62430 ` 101` ``` by (simp add: not_in_iff) ``` haftmann@62430 ` 102` ``` with count_y ** obtain z where z: "z > y" "count M z < count N z" by auto ``` blanchet@59813 ` 103` ``` show ?thesis ``` blanchet@59813 ` 104` ``` proof (cases "z \# K") ``` blanchet@59813 ` 105` ``` case True ``` haftmann@62430 ` 106` ``` with *(4) have "z < a" by simp ``` blanchet@59813 ` 107` ``` with z(1) show ?thesis ``` blanchet@59813 ` 108` ``` by (cases "count P a \ count M a") (auto dest!: count_a intro: less_trans) ``` blanchet@59813 ` 109` ``` next ``` blanchet@59813 ` 110` ``` case False ``` haftmann@62430 ` 111` ``` with \a \# K\ have "count N z \ count P z" unfolding * ``` haftmann@62430 ` 112` ``` by (auto simp add: not_in_iff) ``` blanchet@59813 ` 113` ``` with z show ?thesis by auto ``` blanchet@59813 ` 114` ``` qed ``` blanchet@59813 ` 115` ``` qed ``` blanchet@59813 ` 116` ``` qed ``` blanchet@59813 ` 117` ``` } ``` haftmann@62430 ` 118` ``` ultimately show ?case unfolding less_multiset\<^sub>H\<^sub>O_def by blast ``` blanchet@59813 ` 119` ```qed ``` blanchet@59813 ` 120` blanchet@59813 ` 121` ```lemma less_multiset\<^sub>D\<^sub>M_imp_mult: ``` blanchet@59813 ` 122` ``` "less_multiset\<^sub>D\<^sub>M M N \ (M, N) \ mult {(x, y). x < y}" ``` blanchet@59813 ` 123` ```proof - ``` blanchet@59813 ` 124` ``` assume "less_multiset\<^sub>D\<^sub>M M N" ``` blanchet@59813 ` 125` ``` then obtain X Y where ``` haftmann@64587 ` 126` ``` "X \ {#}" and "X \# N" and "M = N - X + Y" and "\k. k \# Y \ (\a. a \# X \ k < a)" ``` blanchet@59813 ` 127` ``` unfolding less_multiset\<^sub>D\<^sub>M_def by blast ``` blanchet@59813 ` 128` ``` then have "(N - X + Y, N - X + X) \ mult {(x, y). x < y}" ``` blanchet@59813 ` 129` ``` by (intro one_step_implies_mult) (auto simp: Bex_def trans_def) ``` haftmann@64587 ` 130` ``` with \M = N - X + Y\ \X \# N\ show "(M, N) \ mult {(x, y). x < y}" ``` Mathias@60397 ` 131` ``` by (metis subset_mset.diff_add) ``` blanchet@59813 ` 132` ```qed ``` blanchet@59813 ` 133` blanchet@59813 ` 134` ```lemma less_multiset\<^sub>H\<^sub>O_imp_less_multiset\<^sub>D\<^sub>M: "less_multiset\<^sub>H\<^sub>O M N \ less_multiset\<^sub>D\<^sub>M M N" ``` blanchet@59813 ` 135` ```unfolding less_multiset\<^sub>D\<^sub>M_def ``` blanchet@59813 ` 136` ```proof (intro iffI exI conjI) ``` blanchet@59813 ` 137` ``` assume "less_multiset\<^sub>H\<^sub>O M N" ``` blanchet@59813 ` 138` ``` then obtain z where z: "count M z < count N z" ``` blanchet@59813 ` 139` ``` unfolding less_multiset\<^sub>H\<^sub>O_def by (auto simp: multiset_eq_iff nat_neq_iff) ``` wenzelm@63040 ` 140` ``` define X where "X = N - M" ``` wenzelm@63040 ` 141` ``` define Y where "Y = M - N" ``` blanchet@59813 ` 142` ``` from z show "X \ {#}" unfolding X_def by (auto simp: multiset_eq_iff not_less_eq_eq Suc_le_eq) ``` haftmann@64587 ` 143` ``` from z show "X \# N" unfolding X_def by auto ``` blanchet@59813 ` 144` ``` show "M = (N - X) + Y" unfolding X_def Y_def multiset_eq_iff count_union count_diff by force ``` blanchet@59813 ` 145` ``` show "\k. k \# Y \ (\a. a \# X \ k < a)" ``` blanchet@59813 ` 146` ``` proof (intro allI impI) ``` blanchet@59813 ` 147` ``` fix k ``` blanchet@59813 ` 148` ``` assume "k \# Y" ``` haftmann@62430 ` 149` ``` then have "count N k < count M k" unfolding Y_def ``` haftmann@62430 ` 150` ``` by (auto simp add: in_diff_count) ``` wenzelm@60500 ` 151` ``` with \less_multiset\<^sub>H\<^sub>O M N\ obtain a where "k < a" and "count M a < count N a" ``` blanchet@59813 ` 152` ``` unfolding less_multiset\<^sub>H\<^sub>O_def by blast ``` haftmann@62430 ` 153` ``` then show "\a. a \# X \ k < a" unfolding X_def ``` haftmann@62430 ` 154` ``` by (auto simp add: in_diff_count) ``` blanchet@59813 ` 155` ``` qed ``` blanchet@59813 ` 156` ```qed ``` blanchet@59813 ` 157` blanchet@59813 ` 158` ```lemma mult_less_multiset\<^sub>D\<^sub>M: "(M, N) \ mult {(x, y). x < y} \ less_multiset\<^sub>D\<^sub>M M N" ``` blanchet@59813 ` 159` ``` by (metis less_multiset\<^sub>D\<^sub>M_imp_mult less_multiset\<^sub>H\<^sub>O_imp_less_multiset\<^sub>D\<^sub>M mult_imp_less_multiset\<^sub>H\<^sub>O) ``` blanchet@59813 ` 160` blanchet@59813 ` 161` ```lemma mult_less_multiset\<^sub>H\<^sub>O: "(M, N) \ mult {(x, y). x < y} \ less_multiset\<^sub>H\<^sub>O M N" ``` blanchet@59813 ` 162` ``` by (metis less_multiset\<^sub>D\<^sub>M_imp_mult less_multiset\<^sub>H\<^sub>O_imp_less_multiset\<^sub>D\<^sub>M mult_imp_less_multiset\<^sub>H\<^sub>O) ``` blanchet@59813 ` 163` blanchet@59813 ` 164` ```lemmas mult\<^sub>D\<^sub>M = mult_less_multiset\<^sub>D\<^sub>M[unfolded less_multiset\<^sub>D\<^sub>M_def] ``` blanchet@59813 ` 165` ```lemmas mult\<^sub>H\<^sub>O = mult_less_multiset\<^sub>H\<^sub>O[unfolded less_multiset\<^sub>H\<^sub>O_def] ``` blanchet@59813 ` 166` blanchet@59813 ` 167` ```end ``` blanchet@59813 ` 168` blanchet@59813 ` 169` blanchet@59813 ` 170` ```lemma less_multiset_less_multiset\<^sub>H\<^sub>O: ``` Mathias@63388 ` 171` ``` "M < N \ less_multiset\<^sub>H\<^sub>O M N" ``` blanchet@59813 ` 172` ``` unfolding less_multiset_def mult\<^sub>H\<^sub>O less_multiset\<^sub>H\<^sub>O_def .. ``` blanchet@59813 ` 173` blanchet@59813 ` 174` ```lemmas less_multiset\<^sub>D\<^sub>M = mult\<^sub>D\<^sub>M[folded less_multiset_def] ``` blanchet@59813 ` 175` ```lemmas less_multiset\<^sub>H\<^sub>O = mult\<^sub>H\<^sub>O[folded less_multiset_def] ``` blanchet@59813 ` 176` Mathias@63388 ` 177` ```lemma subset_eq_imp_le_multiset: ``` haftmann@64587 ` 178` ``` shows "M \# N \ M \ N" ``` Mathias@63388 ` 179` ``` unfolding less_eq_multiset_def less_multiset\<^sub>H\<^sub>O ``` Mathias@60397 ` 180` ``` by (simp add: less_le_not_le subseteq_mset_def) ``` blanchet@59813 ` 181` Mathias@63388 ` 182` ```lemma le_multiset_right_total: ``` Mathias@63793 ` 183` ``` shows "M < add_mset x M" ``` Mathias@63388 ` 184` ``` unfolding less_eq_multiset_def less_multiset\<^sub>H\<^sub>O by simp ``` Mathias@63388 ` 185` Mathias@63388 ` 186` ```lemma less_eq_multiset_empty_left[simp]: ``` Mathias@63388 ` 187` ``` shows "{#} \ M" ``` Mathias@63388 ` 188` ``` by (simp add: subset_eq_imp_le_multiset) ``` Mathias@63388 ` 189` blanchet@63409 ` 190` ```lemma ex_gt_imp_less_multiset: "(\y. y \# N \ (\x. x \# M \ x < y)) \ M < N" ``` blanchet@63409 ` 191` ``` unfolding less_multiset\<^sub>H\<^sub>O ``` blanchet@63409 ` 192` ``` by (metis count_eq_zero_iff count_greater_zero_iff less_le_not_le) ``` blanchet@63409 ` 193` Mathias@63388 ` 194` ```lemma less_eq_multiset_empty_right[simp]: ``` blanchet@63409 ` 195` ``` "M \ {#} \ \ M \ {#}" ``` Mathias@63388 ` 196` ``` by (metis less_eq_multiset_empty_left antisym) ``` blanchet@59813 ` 197` blanchet@63409 ` 198` ```lemma le_multiset_empty_left[simp]: "M \ {#} \ {#} < M" ``` Mathias@63388 ` 199` ``` by (simp add: less_multiset\<^sub>H\<^sub>O) ``` blanchet@59813 ` 200` blanchet@63409 ` 201` ```lemma le_multiset_empty_right[simp]: "\ M < {#}" ``` Mathias@64076 ` 202` ``` using subset_mset.le_zero_eq less_multiset\<^sub>D\<^sub>M by blast ``` blanchet@59813 ` 203` haftmann@64587 ` 204` ```lemma union_le_diff_plus: "P \# M \ N < P \ M - P + N < M" ``` blanchet@63409 ` 205` ``` by (drule subset_mset.diff_add[symmetric]) (metis union_le_mono2) ``` blanchet@63409 ` 206` Mathias@63525 ` 207` ```instantiation multiset :: (preorder) ordered_ab_semigroup_monoid_add_imp_le ``` blanchet@63409 ` 208` ```begin ``` blanchet@63409 ` 209` blanchet@63409 ` 210` ```lemma less_eq_multiset\<^sub>H\<^sub>O: ``` blanchet@63409 ` 211` ``` "M \ N \ (\y. count N y < count M y \ (\x. y < x \ count M x < count N x))" ``` blanchet@63409 ` 212` ``` by (auto simp: less_eq_multiset_def less_multiset\<^sub>H\<^sub>O) ``` blanchet@63409 ` 213` Mathias@63410 ` 214` ```instance by standard (auto simp: less_eq_multiset\<^sub>H\<^sub>O) ``` blanchet@63409 ` 215` blanchet@59813 ` 216` ```lemma ``` blanchet@63409 ` 217` ``` fixes M N :: "'a multiset" ``` blanchet@59813 ` 218` ``` shows ``` Mathias@63525 ` 219` ``` less_eq_multiset_plus_left: "N \ (M + N)" and ``` Mathias@63525 ` 220` ``` less_eq_multiset_plus_right: "M \ (M + N)" ``` Mathias@63410 ` 221` ``` by simp_all ``` blanchet@59813 ` 222` blanchet@59813 ` 223` ```lemma ``` blanchet@63409 ` 224` ``` fixes M N :: "'a multiset" ``` blanchet@59813 ` 225` ``` shows ``` Mathias@63525 ` 226` ``` le_multiset_plus_left_nonempty: "M \ {#} \ N < M + N" and ``` Mathias@63525 ` 227` ``` le_multiset_plus_right_nonempty: "N \ {#} \ M < M + N" ``` Mathias@63525 ` 228` ``` by simp_all ``` Mathias@63388 ` 229` Mathias@63410 ` 230` ```end ``` Mathias@63410 ` 231` Mathias@63793 ` 232` Mathias@63793 ` 233` ```subsection \Simprocs\ ``` Mathias@63793 ` 234` Mathias@63793 ` 235` ```lemma mset_le_add_iff1: ``` Mathias@63793 ` 236` ``` "j \ (i::nat) \ (repeat_mset i u + m \ repeat_mset j u + n) = (repeat_mset (i-j) u + m \ n)" ``` Mathias@63793 ` 237` ```proof - ``` Mathias@63793 ` 238` ``` assume "j \ i" ``` Mathias@63793 ` 239` ``` then have "j + (i - j) = i" ``` Mathias@63793 ` 240` ``` using le_add_diff_inverse by blast ``` Mathias@63793 ` 241` ``` then show ?thesis ``` Mathias@63793 ` 242` ``` by (metis (no_types) add_le_cancel_left left_add_mult_distrib_mset) ``` Mathias@63793 ` 243` ```qed ``` Mathias@63793 ` 244` Mathias@63793 ` 245` ```lemma mset_le_add_iff2: ``` Mathias@63793 ` 246` ``` "i \ (j::nat) \ (repeat_mset i u + m \ repeat_mset j u + n) = (m \ repeat_mset (j-i) u + n)" ``` Mathias@63793 ` 247` ```proof - ``` Mathias@63793 ` 248` ``` assume "i \ j" ``` Mathias@63793 ` 249` ``` then have "i + (j - i) = j" ``` Mathias@63793 ` 250` ``` using le_add_diff_inverse by blast ``` Mathias@63793 ` 251` ``` then show ?thesis ``` Mathias@63793 ` 252` ``` by (metis (no_types) add_le_cancel_left left_add_mult_distrib_mset) ``` Mathias@63793 ` 253` ```qed ``` Mathias@63793 ` 254` Mathias@63793 ` 255` ```lemma mset_less_add_iff1: ``` Mathias@63793 ` 256` ``` "j \ (i::nat) \ (repeat_mset i u + m < repeat_mset j u + n) = (repeat_mset (i-j) u + m < n)" ``` Mathias@63793 ` 257` ``` by (simp add: less_le_not_le mset_le_add_iff1 mset_le_add_iff2) ``` Mathias@63793 ` 258` Mathias@63793 ` 259` ```lemma mset_less_add_iff2: ``` Mathias@63793 ` 260` ``` "i \ (j::nat) \ (repeat_mset i u + m < repeat_mset j u + n) = (m < repeat_mset (j-i) u + n)" ``` Mathias@63793 ` 261` ``` by (simp add: less_le_not_le mset_le_add_iff1 mset_le_add_iff2) ``` Mathias@63793 ` 262` Mathias@63793 ` 263` ```ML_file "multiset_order_simprocs.ML" ``` Mathias@63793 ` 264` Mathias@63793 ` 265` ```simproc_setup msetless_cancel_numerals ``` Mathias@63793 ` 266` ``` ("(l::'a::preorder multiset) + m < n" | "(l::'a multiset) < m + n" | ``` Mathias@63793 ` 267` ``` "add_mset a m < n" | "m < add_mset a n") = ``` Mathias@63793 ` 268` ``` \fn phi => Multiset_Order_Simprocs.less_cancel_msets\ ``` Mathias@63793 ` 269` Mathias@63793 ` 270` ```simproc_setup msetle_cancel_numerals ``` Mathias@63793 ` 271` ``` ("(l::'a::preorder multiset) + m \ n" | "(l::'a multiset) \ m + n" | ``` Mathias@63793 ` 272` ``` "add_mset a m \ n" | "m \ add_mset a n") = ``` Mathias@63793 ` 273` ``` \fn phi => Multiset_Order_Simprocs.le_cancel_msets\ ``` Mathias@63793 ` 274` Mathias@63793 ` 275` Mathias@63793 ` 276` ```subsection \Additional facts and instantiations\ ``` Mathias@63793 ` 277` Mathias@63388 ` 278` ```lemma ex_gt_count_imp_le_multiset: ``` Mathias@63410 ` 279` ``` "(\y :: 'a :: order. y \# M + N \ y \ x) \ count M x < count N x \ M < N" ``` haftmann@62430 ` 280` ``` unfolding less_multiset\<^sub>H\<^sub>O ``` Mathias@63410 ` 281` ``` by (metis count_greater_zero_iff le_imp_less_or_eq less_imp_not_less not_gr_zero union_iff) ``` Mathias@63410 ` 282` Mathias@64418 ` 283` ```lemma mset_lt_single_iff[iff]: "{#x#} < {#y#} \ x < y" ``` Mathias@64418 ` 284` ``` unfolding less_multiset\<^sub>H\<^sub>O by simp ``` Mathias@64418 ` 285` Mathias@64418 ` 286` ```lemma mset_le_single_iff[iff]: "{#x#} \ {#y#} \ x \ y" for x y :: "'a::order" ``` Mathias@64418 ` 287` ``` unfolding less_eq_multiset\<^sub>H\<^sub>O by force ``` Mathias@64418 ` 288` blanchet@59813 ` 289` Mathias@63410 ` 290` ```instance multiset :: (linorder) linordered_cancel_ab_semigroup_add ``` Mathias@63410 ` 291` ``` by standard (metis less_eq_multiset\<^sub>H\<^sub>O not_less_iff_gr_or_eq) ``` Mathias@63410 ` 292` Mathias@63410 ` 293` ```lemma less_eq_multiset_total: ``` Mathias@63410 ` 294` ``` fixes M N :: "'a :: linorder multiset" ``` Mathias@63410 ` 295` ``` shows "\ M \ N \ N \ M" ``` Mathias@63410 ` 296` ``` by simp ``` blanchet@63409 ` 297` blanchet@63409 ` 298` ```instantiation multiset :: (wellorder) wellorder ``` blanchet@63409 ` 299` ```begin ``` blanchet@63409 ` 300` blanchet@63409 ` 301` ```lemma wf_less_multiset: "wf {(M :: 'a multiset, N). M < N}" ``` blanchet@63409 ` 302` ``` unfolding less_multiset_def by (auto intro: wf_mult wf) ``` blanchet@63409 ` 303` blanchet@63409 ` 304` ```instance by standard (metis less_multiset_def wf wf_def wf_mult) ``` blanchet@59813 ` 305` blanchet@59813 ` 306` ```end ``` blanchet@63409 ` 307` Mathias@63410 ` 308` ```instantiation multiset :: (preorder) order_bot ``` Mathias@63410 ` 309` ```begin ``` Mathias@63410 ` 310` Mathias@63410 ` 311` ```definition bot_multiset :: "'a multiset" where "bot_multiset = {#}" ``` Mathias@63410 ` 312` Mathias@63410 ` 313` ```instance by standard (simp add: bot_multiset_def) ``` Mathias@63410 ` 314` blanchet@63409 ` 315` ```end ``` Mathias@63410 ` 316` Mathias@63410 ` 317` ```instance multiset :: (preorder) no_top ``` Mathias@63410 ` 318` ```proof standard ``` Mathias@63410 ` 319` ``` fix x :: "'a multiset" ``` Mathias@63410 ` 320` ``` obtain a :: 'a where True by simp ``` Mathias@63410 ` 321` ``` have "x < x + (x + {#a#})" ``` Mathias@63410 ` 322` ``` by simp ``` Mathias@63410 ` 323` ``` then show "\y. x < y" ``` Mathias@63410 ` 324` ``` by blast ``` Mathias@63410 ` 325` ```qed ``` Mathias@63410 ` 326` Mathias@63410 ` 327` ```instance multiset :: (preorder) ordered_cancel_comm_monoid_add ``` Mathias@63410 ` 328` ``` by standard ``` Mathias@63410 ` 329` Mathias@63410 ` 330` ```end ```