| author | paulson <lp15@cam.ac.uk> | 
| Mon, 23 Oct 2023 16:19:19 +0100 | |
| changeset 78820 | b356019e8d49 | 
| parent 78099 | 4d9349989d94 | 
| child 79669 | a3e7a323780f | 
| permissions | -rw-r--r-- | 
| 59813 | 1 | (* Title: HOL/Library/Multiset_Order.thy | 
| 2 | Author: Dmitriy Traytel, TU Muenchen | |
| 3 | Author: Jasmin Blanchette, Inria, LORIA, MPII | |
| 77990 | 4 | Author: Martin Desharnais, MPI-INF Saarbruecken | 
| 59813 | 5 | *) | 
| 6 | ||
| 60500 | 7 | section \<open>More Theorems about the Multiset Order\<close> | 
| 59813 | 8 | |
| 9 | theory Multiset_Order | |
| 10 | imports Multiset | |
| 11 | begin | |
| 12 | ||
| 65546 | 13 | subsection \<open>Alternative Characterizations\<close> | 
| 59813 | 14 | |
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 15 | subsubsection \<open>The Dershowitz--Manna Ordering\<close> | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 16 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 17 | definition multp\<^sub>D\<^sub>M where | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 18 | "multp\<^sub>D\<^sub>M r M N \<longleftrightarrow> | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 19 |    (\<exists>X Y. X \<noteq> {#} \<and> X \<subseteq># N \<and> M = (N - X) + Y \<and> (\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> r k a)))"
 | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 20 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 21 | lemma multp\<^sub>D\<^sub>M_imp_multp: | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 22 | "multp\<^sub>D\<^sub>M r M N \<Longrightarrow> multp r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 23 | proof - | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 24 | assume "multp\<^sub>D\<^sub>M r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 25 | then obtain X Y where | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 26 |     "X \<noteq> {#}" and "X \<subseteq># N" and "M = N - X + Y" and "\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> r k a)"
 | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 27 | unfolding multp\<^sub>D\<^sub>M_def by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 28 | then have "multp r (N - X + Y) (N - X + X)" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 29 | by (intro one_step_implies_multp) (auto simp: Bex_def trans_def) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 30 | with \<open>M = N - X + Y\<close> \<open>X \<subseteq># N\<close> show "multp r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 31 | by (metis subset_mset.diff_add) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 32 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 33 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 34 | subsubsection \<open>The Huet--Oppen Ordering\<close> | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 35 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 36 | definition multp\<^sub>H\<^sub>O where | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 37 | "multp\<^sub>H\<^sub>O r M N \<longleftrightarrow> M \<noteq> N \<and> (\<forall>y. count N y < count M y \<longrightarrow> (\<exists>x. r y x \<and> count M x < count N x))" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 38 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 39 | lemma multp_imp_multp\<^sub>H\<^sub>O: | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 40 | assumes "asymp r" and "transp r" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 41 | shows "multp r M N \<Longrightarrow> multp\<^sub>H\<^sub>O r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 42 | unfolding multp_def mult_def | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 43 | proof (induction rule: trancl_induct) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 44 | case (base P) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 45 | then show ?case | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 46 | using \<open>asymp r\<close> | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 47 | by (auto elim!: mult1_lessE simp: count_eq_zero_iff multp\<^sub>H\<^sub>O_def split: if_splits | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 48 | dest!: Suc_lessD) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 49 | next | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 50 | case (step N P) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 51 | from step(3) have "M \<noteq> N" and | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 52 | **: "\<And>y. count N y < count M y \<Longrightarrow> (\<exists>x. r y x \<and> count M x < count N x)" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 53 | by (simp_all add: multp\<^sub>H\<^sub>O_def) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 54 | from step(2) obtain M0 a K where | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 55 | *: "P = add_mset a M0" "N = M0 + K" "a \<notin># K" "\<And>b. b \<in># K \<Longrightarrow> r b a" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 56 | using \<open>asymp r\<close> by (auto elim: mult1_lessE) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 57 | from \<open>M \<noteq> N\<close> ** *(1,2,3) have "M \<noteq> P" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 58 | using *(4) \<open>asymp r\<close> | 
| 76682 
e260dabc88e6
added predicates asym_on and asymp_on and redefined asym and asymp to be abbreviations
 desharna parents: 
74869diff
changeset | 59 | by (metis asympD add_cancel_right_right add_diff_cancel_left' add_mset_add_single count_inI | 
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 60 | count_union diff_diff_add_mset diff_single_trivial in_diff_count multi_member_last) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 61 | moreover | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 62 |   { assume "count P a \<le> count M a"
 | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 63 | with \<open>a \<notin># K\<close> have "count N a < count M a" unfolding *(1,2) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 64 | by (auto simp add: not_in_iff) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 65 | with ** obtain z where z: "r a z" "count M z < count N z" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 66 | by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 67 | with * have "count N z \<le> count P z" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 68 | using \<open>asymp r\<close> | 
| 76682 
e260dabc88e6
added predicates asym_on and asymp_on and redefined asym and asymp to be abbreviations
 desharna parents: 
74869diff
changeset | 69 | by (metis add_diff_cancel_left' add_mset_add_single asympD diff_diff_add_mset | 
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 70 | diff_single_trivial in_diff_count not_le_imp_less) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 71 | with z have "\<exists>z. r a z \<and> count M z < count P z" by auto | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 72 | } note count_a = this | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 73 |   { fix y
 | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 74 | assume count_y: "count P y < count M y" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 75 | have "\<exists>x. r y x \<and> count M x < count P x" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 76 | proof (cases "y = a") | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 77 | case True | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 78 | with count_y count_a show ?thesis by auto | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 79 | next | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 80 | case False | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 81 | show ?thesis | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 82 | proof (cases "y \<in># K") | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 83 | case True | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 84 | with *(4) have "r y a" by simp | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 85 | then show ?thesis | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 86 | by (cases "count P a \<le> count M a") (auto dest: count_a intro: \<open>transp r\<close>[THEN transpD]) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 87 | next | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 88 | case False | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 89 | with \<open>y \<noteq> a\<close> have "count P y = count N y" unfolding *(1,2) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 90 | by (simp add: not_in_iff) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 91 | with count_y ** obtain z where z: "r y z" "count M z < count N z" by auto | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 92 | show ?thesis | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 93 | proof (cases "z \<in># K") | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 94 | case True | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 95 | with *(4) have "r z a" by simp | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 96 | with z(1) show ?thesis | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 97 | by (cases "count P a \<le> count M a") (auto dest!: count_a intro: \<open>transp r\<close>[THEN transpD]) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 98 | next | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 99 | case False | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 100 | with \<open>a \<notin># K\<close> have "count N z \<le> count P z" unfolding * | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 101 | by (auto simp add: not_in_iff) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 102 | with z show ?thesis by auto | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 103 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 104 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 105 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 106 | } | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 107 | ultimately show ?case unfolding multp\<^sub>H\<^sub>O_def by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 108 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 109 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 110 | lemma multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M: "multp\<^sub>H\<^sub>O r M N \<Longrightarrow> multp\<^sub>D\<^sub>M r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 111 | unfolding multp\<^sub>D\<^sub>M_def | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 112 | proof (intro iffI exI conjI) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 113 | assume "multp\<^sub>H\<^sub>O r M N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 114 | then obtain z where z: "count M z < count N z" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 115 | unfolding multp\<^sub>H\<^sub>O_def by (auto simp: multiset_eq_iff nat_neq_iff) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 116 | define X where "X = N - M" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 117 | define Y where "Y = M - N" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 118 |   from z show "X \<noteq> {#}" unfolding X_def by (auto simp: multiset_eq_iff not_less_eq_eq Suc_le_eq)
 | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 119 | from z show "X \<subseteq># N" unfolding X_def by auto | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 120 | show "M = (N - X) + Y" unfolding X_def Y_def multiset_eq_iff count_union count_diff by force | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 121 | show "\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> r k a)" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 122 | proof (intro allI impI) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 123 | fix k | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 124 | assume "k \<in># Y" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 125 | then have "count N k < count M k" unfolding Y_def | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 126 | by (auto simp add: in_diff_count) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 127 | with \<open>multp\<^sub>H\<^sub>O r M N\<close> obtain a where "r k a" and "count M a < count N a" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 128 | unfolding multp\<^sub>H\<^sub>O_def by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 129 | then show "\<exists>a. a \<in># X \<and> r k a" unfolding X_def | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 130 | by (auto simp add: in_diff_count) | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 131 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 132 | qed | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 133 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 134 | lemma multp_eq_multp\<^sub>D\<^sub>M: "asymp r \<Longrightarrow> transp r \<Longrightarrow> multp r = multp\<^sub>D\<^sub>M r" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 135 | using multp\<^sub>D\<^sub>M_imp_multp multp_imp_multp\<^sub>H\<^sub>O[THEN multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 136 | by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 137 | |
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 138 | lemma multp_eq_multp\<^sub>H\<^sub>O: "asymp r \<Longrightarrow> transp r \<Longrightarrow> multp r = multp\<^sub>H\<^sub>O r" | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 139 | using multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M[THEN multp\<^sub>D\<^sub>M_imp_multp] multp_imp_multp\<^sub>H\<^sub>O | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 140 | by blast | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 141 | |
| 77354 | 142 | lemma multp\<^sub>D\<^sub>M_plus_plusI[simp]: | 
| 143 | assumes "multp\<^sub>D\<^sub>M R M1 M2" | |
| 144 | shows "multp\<^sub>D\<^sub>M R (M + M1) (M + M2)" | |
| 145 | proof - | |
| 146 | from assms obtain X Y where | |
| 147 |     "X \<noteq> {#}" and "X \<subseteq># M2" and "M1 = M2 - X + Y" and "\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> R k a)"
 | |
| 148 | unfolding multp\<^sub>D\<^sub>M_def by auto | |
| 149 | ||
| 150 | show "multp\<^sub>D\<^sub>M R (M + M1) (M + M2)" | |
| 151 | unfolding multp\<^sub>D\<^sub>M_def | |
| 152 | proof (intro exI conjI) | |
| 153 |     show "X \<noteq> {#}"
 | |
| 154 |       using \<open>X \<noteq> {#}\<close> by simp
 | |
| 155 | next | |
| 156 | show "X \<subseteq># M + M2" | |
| 157 | using \<open>X \<subseteq># M2\<close> | |
| 158 | by (simp add: subset_mset.add_increasing) | |
| 159 | next | |
| 160 | show "M + M1 = M + M2 - X + Y" | |
| 161 | using \<open>X \<subseteq># M2\<close> \<open>M1 = M2 - X + Y\<close> | |
| 162 | by (metis multiset_diff_union_assoc union_assoc) | |
| 163 | next | |
| 164 | show "\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> R k a)" | |
| 165 | using \<open>\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> R k a)\<close> by simp | |
| 166 | qed | |
| 167 | qed | |
| 168 | ||
| 77104 | 169 | lemma multp\<^sub>H\<^sub>O_plus_plus[simp]: "multp\<^sub>H\<^sub>O R (M + M1) (M + M2) \<longleftrightarrow> multp\<^sub>H\<^sub>O R M1 M2" | 
| 170 | unfolding multp\<^sub>H\<^sub>O_def by simp | |
| 171 | ||
| 77355 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 172 | lemma strict_subset_implies_multp\<^sub>D\<^sub>M: "A \<subset># B \<Longrightarrow> multp\<^sub>D\<^sub>M r A B" | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 173 | unfolding multp\<^sub>D\<^sub>M_def | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 174 | by (metis add.right_neutral add_diff_cancel_right' empty_iff mset_subset_eq_add_right | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 175 | set_mset_empty subset_mset.lessE) | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 176 | |
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 177 | lemma strict_subset_implies_multp\<^sub>H\<^sub>O: "A \<subset># B \<Longrightarrow> multp\<^sub>H\<^sub>O r A B" | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 178 | unfolding multp\<^sub>H\<^sub>O_def | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 179 | by (simp add: leD mset_subset_eq_count) | 
| 
b23367be6051
added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
 desharna parents: 
77354diff
changeset | 180 | |
| 77986 | 181 | lemma multp\<^sub>H\<^sub>O_implies_one_step_strong: | 
| 182 | assumes "multp\<^sub>H\<^sub>O R A B" | |
| 183 | defines "J \<equiv> B - A" and "K \<equiv> A - B" | |
| 184 |   shows "J \<noteq> {#}" and "\<forall>k \<in># K. \<exists>x \<in># J. R k x"
 | |
| 185 | proof - | |
| 186 |   show "J \<noteq> {#}"
 | |
| 187 | using \<open>multp\<^sub>H\<^sub>O R A B\<close> | |
| 188 | by (metis Diff_eq_empty_iff_mset J_def add.right_neutral multp\<^sub>D\<^sub>M_def multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M | |
| 189 | multp\<^sub>H\<^sub>O_plus_plus subset_mset.add_diff_inverse subset_mset.le_zero_eq) | |
| 190 | ||
| 191 | show "\<forall>k\<in>#K. \<exists>x\<in>#J. R k x" | |
| 192 | using \<open>multp\<^sub>H\<^sub>O R A B\<close> | |
| 193 | by (metis J_def K_def in_diff_count multp\<^sub>H\<^sub>O_def) | |
| 194 | qed | |
| 195 | ||
| 77988 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 196 | lemma multp\<^sub>H\<^sub>O_minus_inter_minus_inter_iff: | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 197 | fixes M1 M2 :: "_ multiset" | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 198 | shows "multp\<^sub>H\<^sub>O R (M1 - M2) (M2 - M1) \<longleftrightarrow> multp\<^sub>H\<^sub>O R M1 M2" | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 199 | by (metis diff_intersect_left_idem multiset_inter_commute multp\<^sub>H\<^sub>O_plus_plus | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 200 | subset_mset.add_diff_inverse subset_mset.inf.cobounded1) | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 201 | |
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 202 | lemma multp\<^sub>H\<^sub>O_iff_set_mset_less\<^sub>H\<^sub>O_set_mset: | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 203 | "multp\<^sub>H\<^sub>O R M1 M2 \<longleftrightarrow> (set_mset (M1 - M2) \<noteq> set_mset (M2 - M1) \<and> | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 204 | (\<forall>y \<in># M1 - M2. (\<exists>x \<in># M2 - M1. R y x)))" | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 205 | unfolding multp\<^sub>H\<^sub>O_minus_inter_minus_inter_iff[of R M1 M2, symmetric] | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 206 | unfolding multp\<^sub>H\<^sub>O_def | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 207 | unfolding count_minus_inter_lt_count_minus_inter_iff | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 208 | unfolding minus_inter_eq_minus_inter_iff | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 209 | by auto | 
| 
3e5f6e31c4fd
added lemmas multpHO_iff_set_mset_lessHO_set_mset and multpHO_minus_inter_minus_inter_iff
 desharna parents: 
77986diff
changeset | 210 | |
| 77063 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 211 | |
| 77353 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 212 | subsubsection \<open>Monotonicity\<close> | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 213 | |
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 214 | lemma multp\<^sub>D\<^sub>M_mono_strong: | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 215 | "multp\<^sub>D\<^sub>M R M1 M2 \<Longrightarrow> (\<And>x y. x \<in># M1 \<Longrightarrow> y \<in># M2 \<Longrightarrow> R x y \<Longrightarrow> S x y) \<Longrightarrow> multp\<^sub>D\<^sub>M S M1 M2" | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 216 | unfolding multp\<^sub>D\<^sub>M_def | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 217 | by (metis add_diff_cancel_left' in_diffD subset_mset.diff_add) | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 218 | |
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 219 | lemma multp\<^sub>H\<^sub>O_mono_strong: | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 220 | "multp\<^sub>H\<^sub>O R M1 M2 \<Longrightarrow> (\<And>x y. x \<in># M1 \<Longrightarrow> y \<in># M2 \<Longrightarrow> R x y \<Longrightarrow> S x y) \<Longrightarrow> multp\<^sub>H\<^sub>O S M1 M2" | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 221 | unfolding multp\<^sub>H\<^sub>O_def | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 222 | by (metis count_inI less_zeroE) | 
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 223 | |
| 
42accfbf4d85
added lemmas multpDM_mono_strong and multpHO_mono_strong
 desharna parents: 
77281diff
changeset | 224 | |
| 78016 | 225 | subsubsection \<open>Properties of Orders\<close> | 
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 226 | |
| 78016 | 227 | paragraph \<open>Asymmetry\<close> | 
| 77064 | 228 | |
| 77281 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 229 | text \<open>The following lemma is a negative result stating that asymmetry of an arbitrary binary | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 230 | relation cannot be simply lifted to @{const multp\<^sub>H\<^sub>O}. It suffices to have four distinct values to
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 231 | build a counterexample.\<close> | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 232 | |
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 233 | lemma asymp_not_liftable_to_multp\<^sub>H\<^sub>O: | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 234 | fixes a b c d :: 'a | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 235 | assumes "distinct [a, b, c, d]" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 236 | shows "\<not> (\<forall>(R :: 'a \<Rightarrow> 'a \<Rightarrow> bool). asymp R \<longrightarrow> asymp (multp\<^sub>H\<^sub>O R))" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 237 | proof - | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 238 | define R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" where | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 239 | "R = (\<lambda>x y. x = a \<and> y = c \<or> x = b \<and> y = d \<or> x = c \<and> y = b \<or> x = d \<and> y = a)" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 240 | |
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 241 |   from assms(1) have "{#a, b#} \<noteq> {#c, d#}"
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 242 | by (metis add_mset_add_single distinct.simps(2) list.set(1) list.simps(15) multi_member_this | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 243 | set_mset_add_mset_insert set_mset_single) | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 244 | |
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 245 | from assms(1) have "asymp R" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 246 | by (auto simp: R_def intro: asymp_onI) | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 247 | moreover have "\<not> asymp (multp\<^sub>H\<^sub>O R)" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 248 | unfolding asymp_on_def Set.ball_simps not_all not_imp not_not | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 249 | proof (intro exI conjI) | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 250 |     show "multp\<^sub>H\<^sub>O R {#a, b#} {#c, d#}"
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 251 | unfolding multp\<^sub>H\<^sub>O_def | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 252 |       using \<open>{#a, b#} \<noteq> {#c, d#}\<close> R_def assms by auto
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 253 | next | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 254 |     show "multp\<^sub>H\<^sub>O R {#c, d#} {#a, b#}"
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 255 | unfolding multp\<^sub>H\<^sub>O_def | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 256 |       using \<open>{#a, b#} \<noteq> {#c, d#}\<close> R_def assms by auto
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 257 | qed | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 258 | ultimately show ?thesis | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 259 | unfolding not_all not_imp by auto | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 260 | qed | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 261 | |
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 262 | text \<open>However, if the binary relation is both asymmetric and transitive, then @{const multp\<^sub>H\<^sub>O} is
 | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 263 | also asymmetric.\<close> | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 264 | |
| 77989 | 265 | lemma asymp_on_multp\<^sub>H\<^sub>O: | 
| 266 | assumes "asymp_on A R" and "transp_on A R" and | |
| 267 | B_sub_A: "\<And>M. M \<in> B \<Longrightarrow> set_mset M \<subseteq> A" | |
| 268 | shows "asymp_on B (multp\<^sub>H\<^sub>O R)" | |
| 269 | proof (rule asymp_onI) | |
| 270 | fix M1 M2 :: "'a multiset" | |
| 271 | assume "M1 \<in> B" "M2 \<in> B" "multp\<^sub>H\<^sub>O R M1 M2" | |
| 272 | ||
| 273 | from \<open>transp_on A R\<close> B_sub_A have tran: "transp_on (set_mset (M1 - M2)) R" | |
| 274 | using \<open>M1 \<in> B\<close> | |
| 275 | by (meson in_diffD subset_eq transp_on_subset) | |
| 276 | ||
| 277 | from \<open>asymp_on A R\<close> B_sub_A have asym: "asymp_on (set_mset (M1 - M2)) R" | |
| 278 | using \<open>M1 \<in> B\<close> | |
| 279 | by (meson in_diffD subset_eq asymp_on_subset) | |
| 280 | ||
| 281 | show "\<not> multp\<^sub>H\<^sub>O R M2 M1" | |
| 282 |   proof (cases "M1 - M2 = {#}")
 | |
| 283 | case True | |
| 284 | then show ?thesis | |
| 285 | using multp\<^sub>H\<^sub>O_implies_one_step_strong(1) by metis | |
| 286 | next | |
| 287 | case False | |
| 288 | hence "\<exists>m\<in>#M1 - M2. \<forall>x\<in>#M1 - M2. x \<noteq> m \<longrightarrow> \<not> R m x" | |
| 78014 
24f0cd70790b
added lemmas Finite_Set.bex_(min|max)_element_with_property and reordered assumptions of Finite_Set.bex_(min|max)_element
 desharna parents: 
77990diff
changeset | 289 | using Finite_Set.bex_max_element[of "set_mset (M1 - M2)" R, OF finite_set_mset asym tran] | 
| 77989 | 290 | by simp | 
| 291 | with \<open>transp_on A R\<close> B_sub_A have "\<exists>y\<in>#M2 - M1. \<forall>x\<in>#M1 - M2. \<not> R y x" | |
| 292 | using \<open>multp\<^sub>H\<^sub>O R M1 M2\<close>[THEN multp\<^sub>H\<^sub>O_implies_one_step_strong(2)] | |
| 293 | using asym[THEN irreflp_on_if_asymp_on, THEN irreflp_onD] | |
| 294 | by (metis \<open>M1 \<in> B\<close> \<open>M2 \<in> B\<close> in_diffD subsetD transp_onD) | |
| 295 | thus ?thesis | |
| 296 | unfolding multp\<^sub>H\<^sub>O_iff_set_mset_less\<^sub>H\<^sub>O_set_mset by simp | |
| 297 | qed | |
| 298 | qed | |
| 299 | ||
| 77281 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 300 | lemma asymp_multp\<^sub>H\<^sub>O: | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 301 | assumes "asymp R" and "transp R" | 
| 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 302 | shows "asymp (multp\<^sub>H\<^sub>O R)" | 
| 77989 | 303 | using assms asymp_on_multp\<^sub>H\<^sub>O[of UNIV, simplified] by metis | 
| 77281 
3a2670c37e5c
added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
 desharna parents: 
77104diff
changeset | 304 | |
| 78016 | 305 | |
| 306 | paragraph \<open>Irreflexivity\<close> | |
| 307 | ||
| 308 | lemma irreflp_on_multp\<^sub>H\<^sub>O[simp]: "irreflp_on B (multp\<^sub>H\<^sub>O R)" | |
| 309 | by (simp add: irreflp_onI multp\<^sub>H\<^sub>O_def) | |
| 310 | ||
| 311 | ||
| 312 | paragraph \<open>Transitivity\<close> | |
| 313 | ||
| 78017 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 314 | lemma transp_on_multp\<^sub>H\<^sub>O: | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 315 | assumes "asymp_on A R" and "transp_on A R" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 316 | B_sub_A: "\<And>M. M \<in> B \<Longrightarrow> set_mset M \<subseteq> A" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 317 | shows "transp_on B (multp\<^sub>H\<^sub>O R)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 318 | proof (rule transp_onI) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 319 | from assms have "asymp_on B (multp\<^sub>H\<^sub>O R)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 320 | using asymp_on_multp\<^sub>H\<^sub>O by metis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 321 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 322 | fix M1 M2 M3 | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 323 | assume hyps: "M1 \<in> B" "M2 \<in> B" "M3 \<in> B" "multp\<^sub>H\<^sub>O R M1 M2" "multp\<^sub>H\<^sub>O R M2 M3" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 324 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 325 | from assms have | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 326 | [intro]: "asymp_on (set_mset M1 \<union> set_mset M2) R" "transp_on (set_mset M1 \<union> set_mset M2) R" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 327 | using \<open>M1 \<in> B\<close> \<open>M2 \<in> B\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 328 | by (simp_all add: asymp_on_subset transp_on_subset) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 329 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 330 | from assms have "transp_on (set_mset M1) R" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 331 | by (meson transp_on_subset hyps(1)) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 332 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 333 | from \<open>multp\<^sub>H\<^sub>O R M1 M2\<close> have | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 334 | "M1 \<noteq> M2" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 335 | "\<forall>y. count M2 y < count M1 y \<longrightarrow> (\<exists>x. R y x \<and> count M1 x < count M2 x)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 336 | unfolding multp\<^sub>H\<^sub>O_def by simp_all | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 337 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 338 | from \<open>multp\<^sub>H\<^sub>O R M2 M3\<close> have | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 339 | "M2 \<noteq> M3" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 340 | "\<forall>y. count M3 y < count M2 y \<longrightarrow> (\<exists>x. R y x \<and> count M2 x < count M3 x)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 341 | unfolding multp\<^sub>H\<^sub>O_def by simp_all | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 342 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 343 | show "multp\<^sub>H\<^sub>O R M1 M3" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 344 | proof (rule ccontr) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 345 | let ?P = "\<lambda>x. count M3 x < count M1 x \<and> (\<forall>y. R x y \<longrightarrow> count M1 y \<ge> count M3 y)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 346 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 347 | assume "\<not> multp\<^sub>H\<^sub>O R M1 M3" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 348 | hence "M1 = M3 \<or> (\<exists>x. ?P x)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 349 | unfolding multp\<^sub>H\<^sub>O_def by force | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 350 | thus False | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 351 | proof (elim disjE) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 352 | assume "M1 = M3" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 353 | thus False | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 354 | using \<open>asymp_on B (multp\<^sub>H\<^sub>O R)\<close>[THEN asymp_onD] | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 355 | using \<open>M2 \<in> B\<close> \<open>M3 \<in> B\<close> \<open>multp\<^sub>H\<^sub>O R M1 M2\<close> \<open>multp\<^sub>H\<^sub>O R M2 M3\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 356 | by metis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 357 | next | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 358 | assume "\<exists>x. ?P x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 359 | hence "\<exists>x \<in># M1 + M2. ?P x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 360 | by (auto simp: count_inI) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 361 | have "\<exists>y \<in># M1 + M2. ?P y \<and> (\<forall>z \<in># M1 + M2. R y z \<longrightarrow> \<not> ?P z)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 362 | proof (rule Finite_Set.bex_max_element_with_property) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 363 | show "\<exists>x \<in># M1 + M2. ?P x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 364 | using \<open>\<exists>x. ?P x\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 365 | by (auto simp: count_inI) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 366 | qed auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 367 | then obtain x where | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 368 | "x \<in># M1 + M2" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 369 | "count M3 x < count M1 x" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 370 | "\<forall>y. R x y \<longrightarrow> count M1 y \<ge> count M3 y" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 371 | "\<forall>y \<in># M1 + M2. R x y \<longrightarrow> count M3 y < count M1 y \<longrightarrow> (\<exists>z. R y z \<and> count M1 z < count M3 z)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 372 | by force | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 373 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 374 | let ?Q = "\<lambda>x'. R\<^sup>=\<^sup>= x x' \<and> count M3 x' < count M2 x'" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 375 | show False | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 376 | proof (cases "\<exists>x'. ?Q x'") | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 377 | case True | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 378 | have "\<exists>y \<in># M1 + M2. ?Q y \<and> (\<forall>z \<in># M1 + M2. R y z \<longrightarrow> \<not> ?Q z)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 379 | proof (rule Finite_Set.bex_max_element_with_property) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 380 | show "\<exists>x \<in># M1 + M2. ?Q x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 381 | using \<open>\<exists>x. ?Q x\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 382 | by (auto simp: count_inI) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 383 | qed auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 384 | then obtain x' where | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 385 | "x' \<in># M1 + M2" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 386 | "R\<^sup>=\<^sup>= x x'" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 387 | "count M3 x' < count M2 x'" and | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 388 | maximality_x': "\<forall>z \<in># M1 + M2. R x' z \<longrightarrow> \<not> (R\<^sup>=\<^sup>= x z) \<or> count M3 z \<ge> count M2 z" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 389 | by (auto simp: linorder_not_less) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 390 | with \<open>multp\<^sub>H\<^sub>O R M2 M3\<close> obtain y' where | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 391 | "R x' y'" and "count M2 y' < count M3 y'" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 392 | unfolding multp\<^sub>H\<^sub>O_def by auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 393 | hence "count M2 y' < count M1 y'" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 394 | by (smt (verit) \<open>R\<^sup>=\<^sup>= x x'\<close> \<open>\<forall>y. R x y \<longrightarrow> count M3 y \<le> count M1 y\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 395 | \<open>count M3 x < count M1 x\<close> \<open>count M3 x' < count M2 x'\<close> assms(2) count_inI | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 396 | dual_order.strict_trans1 hyps(1) hyps(2) hyps(3) less_nat_zero_code B_sub_A subsetD | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 397 | sup2E transp_onD) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 398 | with \<open>multp\<^sub>H\<^sub>O R M1 M2\<close> obtain y'' where | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 399 | "R y' y''" and "count M1 y'' < count M2 y''" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 400 | unfolding multp\<^sub>H\<^sub>O_def by auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 401 | hence "count M3 y'' < count M2 y''" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 402 | by (smt (verit, del_insts) \<open>R x' y'\<close> \<open>R\<^sup>=\<^sup>= x x'\<close> \<open>\<forall>y. R x y \<longrightarrow> count M3 y \<le> count M1 y\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 403 | \<open>count M2 y' < count M3 y'\<close> \<open>count M3 x < count M1 x\<close> \<open>count M3 x' < count M2 x'\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 404 | assms(2) count_greater_zero_iff dual_order.strict_trans1 hyps(1) hyps(2) hyps(3) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 405 | less_nat_zero_code linorder_not_less B_sub_A subset_iff sup2E transp_onD) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 406 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 407 | moreover have "count M2 y'' \<le> count M3 y''" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 408 | proof - | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 409 | have "y'' \<in># M1 + M2" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 410 | by (metis \<open>count M1 y'' < count M2 y''\<close> count_inI not_less_iff_gr_or_eq union_iff) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 411 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 412 | moreover have "R x' y''" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 413 | by (metis \<open>R x' y'\<close> \<open>R y' y''\<close> \<open>count M2 y' < count M1 y'\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 414 | \<open>transp_on (set_mset M1 \<union> set_mset M2) R\<close> \<open>x' \<in># M1 + M2\<close> calculation count_inI | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 415 | nat_neq_iff set_mset_union transp_onD union_iff) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 416 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 417 | moreover have "R\<^sup>=\<^sup>= x y''" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 418 | using \<open>R\<^sup>=\<^sup>= x x'\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 419 | by (metis (mono_tags, opaque_lifting) \<open>transp_on (set_mset M1 \<union> set_mset M2) R\<close> | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 420 | \<open>x \<in># M1 + M2\<close> \<open>x' \<in># M1 + M2\<close> calculation(1) calculation(2) set_mset_union sup2I1 | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 421 | transp_onD transp_on_reflclp) | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 422 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 423 | ultimately show ?thesis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 424 | using maximality_x'[rule_format, of y''] by metis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 425 | qed | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 426 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 427 | ultimately show ?thesis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 428 | by linarith | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 429 | next | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 430 | case False | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 431 | hence "\<And>x'. R\<^sup>=\<^sup>= x x' \<Longrightarrow> count M2 x' \<le> count M3 x'" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 432 | by auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 433 | hence "count M2 x \<le> count M3 x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 434 | by simp | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 435 | hence "count M2 x < count M1 x" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 436 | using \<open>count M3 x < count M1 x\<close> by linarith | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 437 | with \<open>multp\<^sub>H\<^sub>O R M1 M2\<close> obtain y where | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 438 | "R x y" and "count M1 y < count M2 y" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 439 | unfolding multp\<^sub>H\<^sub>O_def by auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 440 | hence "count M3 y < count M2 y" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 441 | using \<open>\<forall>y. R x y \<longrightarrow> count M3 y \<le> count M1 y\<close> dual_order.strict_trans2 by metis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 442 | then show ?thesis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 443 | using False \<open>R x y\<close> by auto | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 444 | qed | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 445 | qed | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 446 | qed | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 447 | qed | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 448 | |
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 449 | lemma transp_multp\<^sub>H\<^sub>O: | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 450 | assumes "asymp R" and "transp R" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 451 | shows "transp (multp\<^sub>H\<^sub>O R)" | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 452 | using assms transp_on_multp\<^sub>H\<^sub>O[of UNIV, simplified] by metis | 
| 
db041670d6bb
added lemmas transp_on_multpHO and transp_multpHO
 desharna parents: 
78016diff
changeset | 453 | |
| 78016 | 454 | |
| 455 | paragraph \<open>Totality\<close> | |
| 456 | ||
| 77063 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 457 | lemma totalp_on_multp\<^sub>D\<^sub>M: | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 458 | "totalp_on A R \<Longrightarrow> (\<And>M. M \<in> B \<Longrightarrow> set_mset M \<subseteq> A) \<Longrightarrow> totalp_on B (multp\<^sub>D\<^sub>M R)" | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 459 | by (smt (verit, ccfv_SIG) count_inI in_mono multp\<^sub>H\<^sub>O_def multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M not_less_iff_gr_or_eq | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 460 | totalp_onD totalp_onI) | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 461 | |
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 462 | lemma totalp_multp\<^sub>D\<^sub>M: "totalp R \<Longrightarrow> totalp (multp\<^sub>D\<^sub>M R)" | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 463 | by (rule totalp_on_multp\<^sub>D\<^sub>M[of UNIV R UNIV, simplified]) | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 464 | |
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 465 | lemma totalp_on_multp\<^sub>H\<^sub>O: | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 466 | "totalp_on A R \<Longrightarrow> (\<And>M. M \<in> B \<Longrightarrow> set_mset M \<subseteq> A) \<Longrightarrow> totalp_on B (multp\<^sub>H\<^sub>O R)" | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 467 | by (smt (verit, ccfv_SIG) count_inI in_mono multp\<^sub>H\<^sub>O_def not_less_iff_gr_or_eq totalp_onD | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 468 | totalp_onI) | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 469 | |
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 470 | lemma totalp_multp\<^sub>H\<^sub>O: "totalp R \<Longrightarrow> totalp (multp\<^sub>H\<^sub>O R)" | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 471 | by (rule totalp_on_multp\<^sub>H\<^sub>O[of UNIV R UNIV, simplified]) | 
| 
4b37cc497d7e
added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
 desharna parents: 
76682diff
changeset | 472 | |
| 78016 | 473 | |
| 474 | paragraph \<open>Type Classes\<close> | |
| 475 | ||
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 476 | context preorder | 
| 59813 | 477 | begin | 
| 478 | ||
| 479 | lemma order_mult: "class.order | |
| 480 |   (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y} \<or> M = N)
 | |
| 481 |   (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y})"
 | |
| 482 | (is "class.order ?le ?less") | |
| 483 | proof - | |
| 484 | have irrefl: "\<And>M :: 'a multiset. \<not> ?less M M" | |
| 485 | proof | |
| 486 | fix M :: "'a multiset" | |
| 487 |     have "trans {(x'::'a, x). x' < x}"
 | |
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 488 | by (rule transI) (blast intro: less_trans) | 
| 59813 | 489 | moreover | 
| 490 |     assume "(M, M) \<in> mult {(x, y). x < y}"
 | |
| 491 | ultimately have "\<exists>I J K. M = I + J \<and> M = I + K | |
| 60495 | 492 |       \<and> J \<noteq> {#} \<and> (\<forall>k\<in>set_mset K. \<exists>j\<in>set_mset J. (k, j) \<in> {(x, y). x < y})"
 | 
| 59813 | 493 | by (rule mult_implies_one_step) | 
| 494 | then obtain I J K where "M = I + J" and "M = I + K" | |
| 60495 | 495 |       and "J \<noteq> {#}" and "(\<forall>k\<in>set_mset K. \<exists>j\<in>set_mset J. (k, j) \<in> {(x, y). x < y})" by blast
 | 
| 496 |     then have aux1: "K \<noteq> {#}" and aux2: "\<forall>k\<in>set_mset K. \<exists>j\<in>set_mset K. k < j" by auto
 | |
| 497 | have "finite (set_mset K)" by simp | |
| 59813 | 498 | moreover note aux2 | 
| 60495 | 499 |     ultimately have "set_mset K = {}"
 | 
| 59813 | 500 | by (induct rule: finite_induct) | 
| 501 | (simp, metis (mono_tags) insert_absorb insert_iff insert_not_empty less_irrefl less_trans) | |
| 502 | with aux1 show False by simp | |
| 503 | qed | |
| 504 | have trans: "\<And>K M N :: 'a multiset. ?less K M \<Longrightarrow> ?less M N \<Longrightarrow> ?less K N" | |
| 505 | unfolding mult_def by (blast intro: trancl_trans) | |
| 506 | show "class.order ?le ?less" | |
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 507 | by standard (auto simp add: less_eq_multiset_def irrefl dest: trans) | 
| 59813 | 508 | qed | 
| 509 | ||
| 60500 | 510 | text \<open>The Dershowitz--Manna ordering:\<close> | 
| 59813 | 511 | |
| 512 | definition less_multiset\<^sub>D\<^sub>M where | |
| 513 | "less_multiset\<^sub>D\<^sub>M M N \<longleftrightarrow> | |
| 64587 | 514 |    (\<exists>X Y. X \<noteq> {#} \<and> X \<subseteq># N \<and> M = (N - X) + Y \<and> (\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> k < a)))"
 | 
| 59813 | 515 | |
| 516 | ||
| 60500 | 517 | text \<open>The Huet--Oppen ordering:\<close> | 
| 59813 | 518 | |
| 519 | definition less_multiset\<^sub>H\<^sub>O where | |
| 520 | "less_multiset\<^sub>H\<^sub>O M N \<longleftrightarrow> M \<noteq> N \<and> (\<forall>y. count N y < count M y \<longrightarrow> (\<exists>x. y < x \<and> count M x < count N x))" | |
| 521 | ||
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61424diff
changeset | 522 | lemma mult_imp_less_multiset\<^sub>H\<^sub>O: | 
| 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61424diff
changeset | 523 |   "(M, N) \<in> mult {(x, y). x < y} \<Longrightarrow> less_multiset\<^sub>H\<^sub>O M N"
 | 
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 524 | unfolding multp_def[of "(<)", symmetric] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 525 | using multp_imp_multp\<^sub>H\<^sub>O[of "(<)"] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 526 | by (simp add: less_multiset\<^sub>H\<^sub>O_def multp\<^sub>H\<^sub>O_def) | 
| 59813 | 527 | |
| 528 | lemma less_multiset\<^sub>D\<^sub>M_imp_mult: | |
| 529 |   "less_multiset\<^sub>D\<^sub>M M N \<Longrightarrow> (M, N) \<in> mult {(x, y). x < y}"
 | |
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 530 | unfolding multp_def[of "(<)", symmetric] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 531 | by (rule multp\<^sub>D\<^sub>M_imp_multp[of "(<)" M N]) (simp add: less_multiset\<^sub>D\<^sub>M_def multp\<^sub>D\<^sub>M_def) | 
| 59813 | 532 | |
| 533 | lemma less_multiset\<^sub>H\<^sub>O_imp_less_multiset\<^sub>D\<^sub>M: "less_multiset\<^sub>H\<^sub>O M N \<Longrightarrow> less_multiset\<^sub>D\<^sub>M M N" | |
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 534 | unfolding less_multiset\<^sub>D\<^sub>M_def less_multiset\<^sub>H\<^sub>O_def | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 535 | unfolding multp\<^sub>D\<^sub>M_def[symmetric] multp\<^sub>H\<^sub>O_def[symmetric] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 536 | by (rule multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M) | 
| 59813 | 537 | |
| 538 | lemma mult_less_multiset\<^sub>D\<^sub>M: "(M, N) \<in> mult {(x, y). x < y} \<longleftrightarrow> less_multiset\<^sub>D\<^sub>M M N"
 | |
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 539 | unfolding multp_def[of "(<)", symmetric] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 540 | using multp_eq_multp\<^sub>D\<^sub>M[of "(<)", simplified] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 541 | by (simp add: multp\<^sub>D\<^sub>M_def less_multiset\<^sub>D\<^sub>M_def) | 
| 59813 | 542 | |
| 543 | lemma mult_less_multiset\<^sub>H\<^sub>O: "(M, N) \<in> mult {(x, y). x < y} \<longleftrightarrow> less_multiset\<^sub>H\<^sub>O M N"
 | |
| 74869 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 544 | unfolding multp_def[of "(<)", symmetric] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 545 | using multp_eq_multp\<^sub>H\<^sub>O[of "(<)", simplified] | 
| 
7b0a241732c1
added definitions multp{DM,HO} and corresponding lemmas
 desharna parents: 
74867diff
changeset | 546 | by (simp add: multp\<^sub>H\<^sub>O_def less_multiset\<^sub>H\<^sub>O_def) | 
| 59813 | 547 | |
| 548 | lemmas mult\<^sub>D\<^sub>M = mult_less_multiset\<^sub>D\<^sub>M[unfolded less_multiset\<^sub>D\<^sub>M_def] | |
| 549 | lemmas mult\<^sub>H\<^sub>O = mult_less_multiset\<^sub>H\<^sub>O[unfolded less_multiset\<^sub>H\<^sub>O_def] | |
| 550 | ||
| 551 | end | |
| 552 | ||
| 67020 | 553 | lemma less_multiset_less_multiset\<^sub>H\<^sub>O: "M < N \<longleftrightarrow> less_multiset\<^sub>H\<^sub>O M N" | 
| 74864 | 554 | unfolding less_multiset_def multp_def mult\<^sub>H\<^sub>O less_multiset\<^sub>H\<^sub>O_def .. | 
| 59813 | 555 | |
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 556 | lemma less_multiset\<^sub>D\<^sub>M: | 
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 557 |   "M < N \<longleftrightarrow> (\<exists>X Y. X \<noteq> {#} \<and> X \<subseteq># N \<and> M = N - X + Y \<and> (\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> k < a)))"
 | 
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 558 | by (rule mult\<^sub>D\<^sub>M[folded multp_def less_multiset_def]) | 
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 559 | |
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 560 | lemma less_multiset\<^sub>H\<^sub>O: | 
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 561 | "M < N \<longleftrightarrow> M \<noteq> N \<and> (\<forall>y. count N y < count M y \<longrightarrow> (\<exists>x>y. count M x < count N x))" | 
| 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 562 | by (rule mult\<^sub>H\<^sub>O[folded multp_def less_multiset_def]) | 
| 59813 | 563 | |
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 564 | lemma subset_eq_imp_le_multiset: | 
| 64587 | 565 | shows "M \<subseteq># N \<Longrightarrow> M \<le> N" | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 566 | unfolding less_eq_multiset_def less_multiset\<^sub>H\<^sub>O | 
| 60397 
f8a513fedb31
Renaming multiset operators < ~> <#,...
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
59958diff
changeset | 567 | by (simp add: less_le_not_le subseteq_mset_def) | 
| 59813 | 568 | |
| 67020 | 569 | (* FIXME: "le" should be "less" in this and other names *) | 
| 570 | lemma le_multiset_right_total: "M < add_mset x M" | |
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 571 | unfolding less_eq_multiset_def less_multiset\<^sub>H\<^sub>O by simp | 
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 572 | |
| 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 573 | lemma less_eq_multiset_empty_left[simp]: | 
| 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 574 |   shows "{#} \<le> M"
 | 
| 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 575 | by (simp add: subset_eq_imp_le_multiset) | 
| 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 576 | |
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 577 | lemma ex_gt_imp_less_multiset: "(\<exists>y. y \<in># N \<and> (\<forall>x. x \<in># M \<longrightarrow> x < y)) \<Longrightarrow> M < N" | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 578 | unfolding less_multiset\<^sub>H\<^sub>O | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 579 | by (metis count_eq_zero_iff count_greater_zero_iff less_le_not_le) | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 580 | |
| 67020 | 581 | lemma less_eq_multiset_empty_right[simp]: "M \<noteq> {#} \<Longrightarrow> \<not> M \<le> {#}"
 | 
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 582 | by (metis less_eq_multiset_empty_left antisym) | 
| 59813 | 583 | |
| 67020 | 584 | (* FIXME: "le" should be "less" in this and other names *) | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 585 | lemma le_multiset_empty_left[simp]: "M \<noteq> {#} \<Longrightarrow> {#} < M"
 | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 586 | by (simp add: less_multiset\<^sub>H\<^sub>O) | 
| 59813 | 587 | |
| 67020 | 588 | (* FIXME: "le" should be "less" in this and other names *) | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 589 | lemma le_multiset_empty_right[simp]: "\<not> M < {#}"
 | 
| 74864 | 590 | using subset_mset.le_zero_eq less_multiset_def multp_def less_multiset\<^sub>D\<^sub>M by blast | 
| 59813 | 591 | |
| 67020 | 592 | (* FIXME: "le" should be "less" in this and other names *) | 
| 64587 | 593 | lemma union_le_diff_plus: "P \<subseteq># M \<Longrightarrow> N < P \<Longrightarrow> M - P + N < M" | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 594 | by (drule subset_mset.diff_add[symmetric]) (metis union_le_mono2) | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 595 | |
| 63525 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 596 | instantiation multiset :: (preorder) ordered_ab_semigroup_monoid_add_imp_le | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 597 | begin | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 598 | |
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 599 | lemma less_eq_multiset\<^sub>H\<^sub>O: | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 600 | "M \<le> N \<longleftrightarrow> (\<forall>y. count N y < count M y \<longrightarrow> (\<exists>x. y < x \<and> count M x < count N x))" | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 601 | by (auto simp: less_eq_multiset_def less_multiset\<^sub>H\<^sub>O) | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 602 | |
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 603 | instance by standard (auto simp: less_eq_multiset\<^sub>H\<^sub>O) | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 604 | |
| 59813 | 605 | lemma | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 606 | fixes M N :: "'a multiset" | 
| 59813 | 607 | shows | 
| 63525 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 608 | less_eq_multiset_plus_left: "N \<le> (M + N)" and | 
| 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 609 | less_eq_multiset_plus_right: "M \<le> (M + N)" | 
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 610 | by simp_all | 
| 59813 | 611 | |
| 612 | lemma | |
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 613 | fixes M N :: "'a multiset" | 
| 59813 | 614 | shows | 
| 63525 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 615 |     le_multiset_plus_left_nonempty: "M \<noteq> {#} \<Longrightarrow> N < M + N" and
 | 
| 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 616 |     le_multiset_plus_right_nonempty: "N \<noteq> {#} \<Longrightarrow> M < M + N"
 | 
| 
f01d1e393f3f
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63410diff
changeset | 617 | by simp_all | 
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 618 | |
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 619 | end | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 620 | |
| 65546 | 621 | lemma all_lt_Max_imp_lt_mset: "N \<noteq> {#} \<Longrightarrow> (\<forall>a \<in># M. a < Max (set_mset N)) \<Longrightarrow> M < N"
 | 
| 622 | by (meson Max_in[OF finite_set_mset] ex_gt_imp_less_multiset set_mset_eq_empty_iff) | |
| 623 | ||
| 624 | lemma lt_imp_ex_count_lt: "M < N \<Longrightarrow> \<exists>y. count M y < count N y" | |
| 625 | by (meson less_eq_multiset\<^sub>H\<^sub>O less_le_not_le) | |
| 626 | ||
| 627 | lemma subset_imp_less_mset: "A \<subset># B \<Longrightarrow> A < B" | |
| 628 | by (simp add: order.not_eq_order_implies_strict subset_eq_imp_le_multiset) | |
| 629 | ||
| 630 | lemma image_mset_strict_mono: | |
| 631 | assumes | |
| 632 | mono_f: "\<forall>x \<in> set_mset M. \<forall>y \<in> set_mset N. x < y \<longrightarrow> f x < f y" and | |
| 633 | less: "M < N" | |
| 634 | shows "image_mset f M < image_mset f N" | |
| 635 | proof - | |
| 636 | obtain Y X where | |
| 637 |     y_nemp: "Y \<noteq> {#}" and y_sub_N: "Y \<subseteq># N" and M_eq: "M = N - Y + X" and
 | |
| 638 | ex_y: "\<forall>x. x \<in># X \<longrightarrow> (\<exists>y. y \<in># Y \<and> x < y)" | |
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 639 | using less[unfolded less_multiset\<^sub>D\<^sub>M] by blast | 
| 65546 | 640 | |
| 641 | have x_sub_M: "X \<subseteq># M" | |
| 642 | using M_eq by simp | |
| 643 | ||
| 644 | let ?fY = "image_mset f Y" | |
| 645 | let ?fX = "image_mset f X" | |
| 646 | ||
| 647 | show ?thesis | |
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 648 | unfolding less_multiset\<^sub>D\<^sub>M | 
| 65546 | 649 | proof (intro exI conjI) | 
| 650 | show "image_mset f M = image_mset f N - ?fY + ?fX" | |
| 651 | using M_eq[THEN arg_cong, of "image_mset f"] y_sub_N | |
| 652 | by (metis image_mset_Diff image_mset_union) | |
| 653 | next | |
| 654 | obtain y where y: "\<forall>x. x \<in># X \<longrightarrow> y x \<in># Y \<and> x < y x" | |
| 655 | using ex_y by moura | |
| 656 | ||
| 657 | show "\<forall>fx. fx \<in># ?fX \<longrightarrow> (\<exists>fy. fy \<in># ?fY \<and> fx < fy)" | |
| 658 | proof (intro allI impI) | |
| 659 | fix fx | |
| 660 | assume "fx \<in># ?fX" | |
| 661 | then obtain x where fx: "fx = f x" and x_in: "x \<in># X" | |
| 662 | by auto | |
| 663 | hence y_in: "y x \<in># Y" and y_gt: "x < y x" | |
| 664 | using y[rule_format, OF x_in] by blast+ | |
| 665 | hence "f (y x) \<in># ?fY \<and> f x < f (y x)" | |
| 666 | using mono_f y_sub_N x_sub_M x_in | |
| 667 | by (metis image_eqI in_image_mset mset_subset_eqD) | |
| 668 | thus "\<exists>fy. fy \<in># ?fY \<and> fx < fy" | |
| 669 | unfolding fx by auto | |
| 670 | qed | |
| 671 | qed (auto simp: y_nemp y_sub_N image_mset_subseteq_mono) | |
| 672 | qed | |
| 673 | ||
| 674 | lemma image_mset_mono: | |
| 675 | assumes | |
| 676 | mono_f: "\<forall>x \<in> set_mset M. \<forall>y \<in> set_mset N. x < y \<longrightarrow> f x < f y" and | |
| 677 | less: "M \<le> N" | |
| 678 | shows "image_mset f M \<le> image_mset f N" | |
| 679 | by (metis eq_iff image_mset_strict_mono less less_imp_le mono_f order.not_eq_order_implies_strict) | |
| 680 | ||
| 681 | lemma mset_lt_single_right_iff[simp]: "M < {#y#} \<longleftrightarrow> (\<forall>x \<in># M. x < y)" for y :: "'a::linorder"
 | |
| 682 | proof (rule iffI) | |
| 683 |   assume M_lt_y: "M < {#y#}"
 | |
| 684 | show "\<forall>x \<in># M. x < y" | |
| 685 | proof | |
| 686 | fix x | |
| 687 | assume x_in: "x \<in># M" | |
| 688 |     hence M: "M - {#x#} + {#x#} = M"
 | |
| 689 | by (meson insert_DiffM2) | |
| 690 |     hence "\<not> {#x#} < {#y#} \<Longrightarrow> x < y"
 | |
| 691 | using x_in M_lt_y | |
| 692 | by (metis diff_single_eq_union le_multiset_empty_left less_add_same_cancel2 mset_le_trans) | |
| 693 |     also have "\<not> {#y#} < M"
 | |
| 694 | using M_lt_y mset_le_not_sym by blast | |
| 695 | ultimately show "x < y" | |
| 696 | by (metis (no_types) Max_ge all_lt_Max_imp_lt_mset empty_iff finite_set_mset insertE | |
| 697 | less_le_trans linorder_less_linear mset_le_not_sym set_mset_add_mset_insert | |
| 698 | set_mset_eq_empty_iff x_in) | |
| 699 | qed | |
| 700 | next | |
| 701 | assume y_max: "\<forall>x \<in># M. x < y" | |
| 702 |   show "M < {#y#}"
 | |
| 703 | by (rule all_lt_Max_imp_lt_mset) (auto intro!: y_max) | |
| 704 | qed | |
| 705 | ||
| 706 | lemma mset_le_single_right_iff[simp]: | |
| 707 |   "M \<le> {#y#} \<longleftrightarrow> M = {#y#} \<or> (\<forall>x \<in># M. x < y)" for y :: "'a::linorder"
 | |
| 708 | by (meson less_eq_multiset_def mset_lt_single_right_iff) | |
| 709 | ||
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 710 | |
| 77834 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 711 | subsubsection \<open>Simplifications\<close> | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 712 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 713 | lemma multp\<^sub>H\<^sub>O_repeat_mset_repeat_mset[simp]: | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 714 | assumes "n \<noteq> 0" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 715 | shows "multp\<^sub>H\<^sub>O R (repeat_mset n A) (repeat_mset n B) \<longleftrightarrow> multp\<^sub>H\<^sub>O R A B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 716 | proof (rule iffI) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 717 | assume hyp: "multp\<^sub>H\<^sub>O R (repeat_mset n A) (repeat_mset n B)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 718 | hence | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 719 | 1: "repeat_mset n A \<noteq> repeat_mset n B" and | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 720 | 2: "\<forall>y. n * count B y < n * count A y \<longrightarrow> (\<exists>x. R y x \<and> n * count A x < n * count B x)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 721 | by (simp_all add: multp\<^sub>H\<^sub>O_def) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 722 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 723 | from 1 \<open>n \<noteq> 0\<close> have "A \<noteq> B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 724 | by auto | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 725 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 726 | moreover from 2 \<open>n \<noteq> 0\<close> have "\<forall>y. count B y < count A y \<longrightarrow> (\<exists>x. R y x \<and> count A x < count B x)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 727 | by auto | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 728 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 729 | ultimately show "multp\<^sub>H\<^sub>O R A B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 730 | by (simp add: multp\<^sub>H\<^sub>O_def) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 731 | next | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 732 | assume "multp\<^sub>H\<^sub>O R A B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 733 | hence 1: "A \<noteq> B" and 2: "\<forall>y. count B y < count A y \<longrightarrow> (\<exists>x. R y x \<and> count A x < count B x)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 734 | by (simp_all add: multp\<^sub>H\<^sub>O_def) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 735 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 736 | from 1 have "repeat_mset n A \<noteq> repeat_mset n B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 737 | by (simp add: assms repeat_mset_cancel1) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 738 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 739 | moreover from 2 have "\<forall>y. n * count B y < n * count A y \<longrightarrow> | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 740 | (\<exists>x. R y x \<and> n * count A x < n * count B x)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 741 | by auto | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 742 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 743 | ultimately show "multp\<^sub>H\<^sub>O R (repeat_mset n A) (repeat_mset n B)" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 744 | by (simp add: multp\<^sub>H\<^sub>O_def) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 745 | qed | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 746 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 747 | lemma multp\<^sub>H\<^sub>O_double_double[simp]: "multp\<^sub>H\<^sub>O R (A + A) (B + B) \<longleftrightarrow> multp\<^sub>H\<^sub>O R A B" | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 748 | using multp\<^sub>H\<^sub>O_repeat_mset_repeat_mset[of 2] | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 749 | by (simp add: numeral_Bit0) | 
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 750 | |
| 
52e753197496
added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
 desharna parents: 
77355diff
changeset | 751 | |
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 752 | subsection \<open>Simprocs\<close> | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 753 | |
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 754 | lemma mset_le_add_iff1: | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 755 | "j \<le> (i::nat) \<Longrightarrow> (repeat_mset i u + m \<le> repeat_mset j u + n) = (repeat_mset (i-j) u + m \<le> n)" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 756 | proof - | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 757 | assume "j \<le> i" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 758 | then have "j + (i - j) = i" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 759 | using le_add_diff_inverse by blast | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 760 | then show ?thesis | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 761 | by (metis (no_types) add_le_cancel_left left_add_mult_distrib_mset) | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 762 | qed | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 763 | |
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 764 | lemma mset_le_add_iff2: | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 765 | "i \<le> (j::nat) \<Longrightarrow> (repeat_mset i u + m \<le> repeat_mset j u + n) = (m \<le> repeat_mset (j-i) u + n)" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 766 | proof - | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 767 | assume "i \<le> j" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 768 | then have "i + (j - i) = j" | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 769 | using le_add_diff_inverse by blast | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 770 | then show ?thesis | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 771 | by (metis (no_types) add_le_cancel_left left_add_mult_distrib_mset) | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 772 | qed | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 773 | |
| 65027 
2b8583507891
renaming multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
64978diff
changeset | 774 | simproc_setup msetless_cancel | 
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 775 |   ("(l::'a::preorder multiset) + m < n" | "(l::'a multiset) < m + n" |
 | 
| 65028 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 776 | "add_mset a m < n" | "m < add_mset a n" | | 
| 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 777 | "replicate_mset p a < n" | "m < replicate_mset p a" | | 
| 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 778 | "repeat_mset p m < n" | "m < repeat_mset p n") = | 
| 78099 
4d9349989d94
more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
 wenzelm parents: 
78017diff
changeset | 779 | \<open>K Cancel_Simprocs.less_cancel\<close> | 
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 780 | |
| 65027 
2b8583507891
renaming multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
64978diff
changeset | 781 | simproc_setup msetle_cancel | 
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 782 |   ("(l::'a::preorder multiset) + m \<le> n" | "(l::'a multiset) \<le> m + n" |
 | 
| 65028 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 783 | "add_mset a m \<le> n" | "m \<le> add_mset a n" | | 
| 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 784 | "replicate_mset p a \<le> n" | "m \<le> replicate_mset p a" | | 
| 
87e003397834
adding simplification patterns to multiset simprocs
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
65027diff
changeset | 785 | "repeat_mset p m \<le> n" | "m \<le> repeat_mset p n") = | 
| 78099 
4d9349989d94
more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
 wenzelm parents: 
78017diff
changeset | 786 | \<open>K Cancel_Simprocs.less_eq_cancel\<close> | 
| 63793 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 787 | |
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 788 | |
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 789 | subsection \<open>Additional facts and instantiations\<close> | 
| 
e68a0b651eb5
add_mset constructor in multisets
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63525diff
changeset | 790 | |
| 63388 
a095acd4cfbf
instantiate multiset with multiset ordering
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63310diff
changeset | 791 | lemma ex_gt_count_imp_le_multiset: | 
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 792 | "(\<forall>y :: 'a :: order. y \<in># M + N \<longrightarrow> y \<le> x) \<Longrightarrow> count M x < count N x \<Longrightarrow> M < N" | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 793 | unfolding less_multiset\<^sub>H\<^sub>O | 
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 794 | by (metis count_greater_zero_iff le_imp_less_or_eq less_imp_not_less not_gr_zero union_iff) | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 795 | |
| 64418 | 796 | lemma mset_lt_single_iff[iff]: "{#x#} < {#y#} \<longleftrightarrow> x < y"
 | 
| 74867 
4220dcd6c22e
restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
 desharna parents: 
74864diff
changeset | 797 | unfolding less_multiset\<^sub>H\<^sub>O by simp | 
| 64418 | 798 | |
| 799 | lemma mset_le_single_iff[iff]: "{#x#} \<le> {#y#} \<longleftrightarrow> x \<le> y" for x y :: "'a::order"
 | |
| 800 | unfolding less_eq_multiset\<^sub>H\<^sub>O by force | |
| 801 | ||
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 802 | instance multiset :: (linorder) linordered_cancel_ab_semigroup_add | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 803 | by standard (metis less_eq_multiset\<^sub>H\<^sub>O not_less_iff_gr_or_eq) | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 804 | |
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 805 | lemma less_eq_multiset_total: | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 806 | fixes M N :: "'a :: linorder multiset" | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 807 | shows "\<not> M \<le> N \<Longrightarrow> N \<le> M" | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 808 | by simp | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 809 | |
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 810 | instantiation multiset :: (wellorder) wellorder | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 811 | begin | 
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 812 | |
| 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 813 | lemma wf_less_multiset: "wf {(M :: 'a multiset, N). M < N}"
 | 
| 74864 | 814 | unfolding less_multiset_def multp_def by (auto intro: wf_mult wf) | 
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 815 | |
| 74864 | 816 | instance by standard (metis less_multiset_def multp_def wf wf_def wf_mult) | 
| 59813 | 817 | |
| 818 | end | |
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 819 | |
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 820 | instantiation multiset :: (preorder) order_bot | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 821 | begin | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 822 | |
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 823 | definition bot_multiset :: "'a multiset" where "bot_multiset = {#}"
 | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 824 | |
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 825 | instance by standard (simp add: bot_multiset_def) | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 826 | |
| 63409 
3f3223b90239
moved lemmas and locales around (with minor incompatibilities)
 blanchet parents: 
63407diff
changeset | 827 | end | 
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 828 | |
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 829 | instance multiset :: (preorder) no_top | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 830 | proof standard | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 831 | fix x :: "'a multiset" | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 832 | obtain a :: 'a where True by simp | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 833 |   have "x < x + (x + {#a#})"
 | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 834 | by simp | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 835 | then show "\<exists>y. x < y" | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 836 | by blast | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 837 | qed | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 838 | |
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 839 | instance multiset :: (preorder) ordered_cancel_comm_monoid_add | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 840 | by standard | 
| 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 841 | |
| 65546 | 842 | instantiation multiset :: (linorder) distrib_lattice | 
| 843 | begin | |
| 844 | ||
| 845 | definition inf_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where | |
| 846 | "inf_multiset A B = (if A < B then A else B)" | |
| 847 | ||
| 848 | definition sup_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where | |
| 849 | "sup_multiset A B = (if B > A then B else A)" | |
| 850 | ||
| 851 | instance | |
| 852 | by intro_classes (auto simp: inf_multiset_def sup_multiset_def) | |
| 853 | ||
| 63410 
9789ccc2a477
more instantiations for multiset
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63409diff
changeset | 854 | end | 
| 65546 | 855 | |
| 856 | end |