src/HOL/Library/Multiset_Order.thy
author desharna
Mon, 08 May 2023 11:16:45 +0200
changeset 77986 0f92caebc19a
parent 77834 52e753197496
child 77988 3e5f6e31c4fd
permissions -rw-r--r--
added lemma multpHO_implies_one_step_strong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/Library/Multiset_Order.thy
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     3
    Author:     Jasmin Blanchette, Inria, LORIA, MPII
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     4
*)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     5
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60397
diff changeset
     6
section \<open>More Theorems about the Multiset Order\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     7
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     8
theory Multiset_Order
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
     9
imports Multiset
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
    10
begin
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
    11
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
    12
subsection \<open>Alternative Characterizations\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
    13
74869
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    14
subsubsection \<open>The Dershowitz--Manna Ordering\<close>
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    15
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    16
definition multp\<^sub>D\<^sub>M where
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    17
  "multp\<^sub>D\<^sub>M r M N \<longleftrightarrow>
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    18
   (\<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: 74867
diff changeset
    19
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    20
lemma multp\<^sub>D\<^sub>M_imp_multp:
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    21
  "multp\<^sub>D\<^sub>M r M N \<Longrightarrow> multp r M N"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    22
proof -
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    23
  assume "multp\<^sub>D\<^sub>M r M N"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    24
  then obtain X Y where
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    25
    "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: 74867
diff changeset
    26
    unfolding multp\<^sub>D\<^sub>M_def by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    27
  then have "multp r (N - X + Y) (N - X + X)"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    28
    by (intro one_step_implies_multp) (auto simp: Bex_def trans_def)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    29
  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: 74867
diff changeset
    30
    by (metis subset_mset.diff_add)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    31
qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    32
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    33
subsubsection \<open>The Huet--Oppen Ordering\<close>
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    34
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    35
definition multp\<^sub>H\<^sub>O where
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    36
  "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: 74867
diff changeset
    37
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    38
lemma multp_imp_multp\<^sub>H\<^sub>O:
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    39
  assumes "asymp r" and "transp r"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    40
  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: 74867
diff changeset
    41
  unfolding multp_def mult_def
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    42
proof (induction rule: trancl_induct)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    43
  case (base P)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    44
  then show ?case
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    45
    using \<open>asymp r\<close>
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    46
    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: 74867
diff changeset
    47
        dest!: Suc_lessD)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    48
next
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    49
  case (step N P)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    50
  from step(3) have "M \<noteq> N" and
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    51
    **: "\<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: 74867
diff changeset
    52
    by (simp_all add: multp\<^sub>H\<^sub>O_def)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    53
  from step(2) obtain M0 a K where
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    54
    *: "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: 74867
diff changeset
    55
    using \<open>asymp r\<close> by (auto elim: mult1_lessE)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    56
  from \<open>M \<noteq> N\<close> ** *(1,2,3) have "M \<noteq> P"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    57
    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: 74869
diff changeset
    58
    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: 74867
diff changeset
    59
        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: 74867
diff changeset
    60
  moreover
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    61
  { assume "count P a \<le> count M a"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    62
    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: 74867
diff changeset
    63
      by (auto simp add: not_in_iff)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    64
      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: 74867
diff changeset
    65
        by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    66
      with * have "count N z \<le> count P z"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    67
        using \<open>asymp r\<close>
76682
e260dabc88e6 added predicates asym_on and asymp_on and redefined asym and asymp to be abbreviations
desharna
parents: 74869
diff changeset
    68
        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: 74867
diff changeset
    69
            diff_single_trivial in_diff_count not_le_imp_less)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    70
      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: 74867
diff changeset
    71
  } note count_a = this
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    72
  { fix y
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    73
    assume count_y: "count P y < count M y"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    74
    have "\<exists>x. r y x \<and> count M x < count P x"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    75
    proof (cases "y = a")
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    76
      case True
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    77
      with count_y count_a show ?thesis by auto
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    78
    next
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    79
      case False
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    80
      show ?thesis
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    81
      proof (cases "y \<in># K")
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    82
        case True
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    83
        with *(4) have "r y a" by simp
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    84
        then show ?thesis
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    85
          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: 74867
diff changeset
    86
      next
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    87
        case False
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    88
        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: 74867
diff changeset
    89
          by (simp add: not_in_iff)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    90
        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: 74867
diff changeset
    91
        show ?thesis
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    92
        proof (cases "z \<in># K")
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    93
          case True
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    94
          with *(4) have "r z a" by simp
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    95
          with z(1) show ?thesis
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    96
            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: 74867
diff changeset
    97
        next
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    98
          case False
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
    99
          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: 74867
diff changeset
   100
            by (auto simp add: not_in_iff)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   101
          with z show ?thesis by auto
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   102
        qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   103
      qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   104
    qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   105
  }
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   106
  ultimately show ?case unfolding multp\<^sub>H\<^sub>O_def by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   107
qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   108
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   109
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: 74867
diff changeset
   110
unfolding multp\<^sub>D\<^sub>M_def
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   111
proof (intro iffI exI conjI)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   112
  assume "multp\<^sub>H\<^sub>O r M N"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   113
  then obtain z where z: "count M z < count N z"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   114
    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: 74867
diff changeset
   115
  define X where "X = N - M"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   116
  define Y where "Y = M - N"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   117
  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: 74867
diff changeset
   118
  from z show "X \<subseteq># N" unfolding X_def by auto
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   119
  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: 74867
diff changeset
   120
  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: 74867
diff changeset
   121
  proof (intro allI impI)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   122
    fix k
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   123
    assume "k \<in># Y"
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   124
    then have "count N k < count M k" unfolding Y_def
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   125
      by (auto simp add: in_diff_count)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   126
    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: 74867
diff changeset
   127
      unfolding multp\<^sub>H\<^sub>O_def by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   128
    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: 74867
diff changeset
   129
      by (auto simp add: in_diff_count)
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   130
  qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   131
qed
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   132
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   133
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: 74867
diff changeset
   134
  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: 74867
diff changeset
   135
  by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   136
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   137
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: 74867
diff changeset
   138
  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: 74867
diff changeset
   139
  by blast
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   140
77354
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   141
lemma multp\<^sub>D\<^sub>M_plus_plusI[simp]:
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   142
  assumes "multp\<^sub>D\<^sub>M R M1 M2"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   143
  shows "multp\<^sub>D\<^sub>M R (M + M1) (M + M2)"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   144
proof -
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   145
  from assms obtain X Y where
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   146
    "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)"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   147
  unfolding multp\<^sub>D\<^sub>M_def by auto
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   148
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   149
  show "multp\<^sub>D\<^sub>M R (M + M1) (M + M2)"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   150
    unfolding multp\<^sub>D\<^sub>M_def
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   151
  proof (intro exI conjI)
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   152
    show "X \<noteq> {#}"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   153
      using \<open>X \<noteq> {#}\<close> by simp
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   154
  next
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   155
    show "X \<subseteq># M + M2"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   156
      using \<open>X \<subseteq># M2\<close>
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   157
      by (simp add: subset_mset.add_increasing)
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   158
  next
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   159
    show "M + M1 = M + M2 - X + Y"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   160
      using \<open>X \<subseteq># M2\<close> \<open>M1 = M2 - X + Y\<close>
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   161
      by (metis multiset_diff_union_assoc union_assoc)
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   162
  next
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   163
    show "\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> R k a)"
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   164
      using \<open>\<forall>k. k \<in># Y \<longrightarrow> (\<exists>a. a \<in># X \<and> R k a)\<close> by simp
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   165
  qed
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   166
qed
347d7133c171 added lemma multpDM_plus_plusI[simp]
desharna
parents: 77353
diff changeset
   167
77104
9678b533119e added lemma multpHO_plus_plus[simp]
desharna
parents: 77064
diff changeset
   168
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"
9678b533119e added lemma multpHO_plus_plus[simp]
desharna
parents: 77064
diff changeset
   169
  unfolding multp\<^sub>H\<^sub>O_def by simp
9678b533119e added lemma multpHO_plus_plus[simp]
desharna
parents: 77064
diff changeset
   170
77355
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   171
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: 77354
diff changeset
   172
  unfolding multp\<^sub>D\<^sub>M_def
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   173
  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: 77354
diff changeset
   174
      set_mset_empty subset_mset.lessE)
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   175
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   176
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: 77354
diff changeset
   177
  unfolding multp\<^sub>H\<^sub>O_def
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   178
  by (simp add: leD mset_subset_eq_count)
b23367be6051 added lemmas strict_subset_implies_multpDM and strict_subset_implies_multpHO
desharna
parents: 77354
diff changeset
   179
77986
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   180
lemma multp\<^sub>H\<^sub>O_implies_one_step_strong:
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   181
  assumes "multp\<^sub>H\<^sub>O R A B"
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   182
  defines "J \<equiv> B - A" and "K \<equiv> A - B"
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   183
  shows "J \<noteq> {#}" and "\<forall>k \<in># K. \<exists>x \<in># J. R k x"
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   184
proof -
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   185
  show "J \<noteq> {#}"
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   186
  using \<open>multp\<^sub>H\<^sub>O R A B\<close>
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   187
  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
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   188
      multp\<^sub>H\<^sub>O_plus_plus subset_mset.add_diff_inverse subset_mset.le_zero_eq)
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   189
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   190
  show "\<forall>k\<in>#K. \<exists>x\<in>#J. R k x"
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   191
    using \<open>multp\<^sub>H\<^sub>O R A B\<close>
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   192
    by (metis J_def K_def in_diff_count multp\<^sub>H\<^sub>O_def)
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   193
qed
0f92caebc19a added lemma multpHO_implies_one_step_strong
desharna
parents: 77834
diff changeset
   194
77063
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   195
77353
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   196
subsubsection \<open>Monotonicity\<close>
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   197
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   198
lemma multp\<^sub>D\<^sub>M_mono_strong:
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   199
  "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: 77281
diff changeset
   200
  unfolding multp\<^sub>D\<^sub>M_def
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   201
  by (metis add_diff_cancel_left' in_diffD subset_mset.diff_add)
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   202
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   203
lemma multp\<^sub>H\<^sub>O_mono_strong:
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   204
  "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: 77281
diff changeset
   205
  unfolding multp\<^sub>H\<^sub>O_def
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   206
  by (metis count_inI less_zeroE)
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   207
42accfbf4d85 added lemmas multpDM_mono_strong and multpHO_mono_strong
desharna
parents: 77281
diff changeset
   208
74869
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   209
subsubsection \<open>Properties of Preorders\<close>
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   210
77064
e06463478a3f added lemma irreflp_on_multpHO[simp]
desharna
parents: 77063
diff changeset
   211
lemma irreflp_on_multp\<^sub>H\<^sub>O[simp]: "irreflp_on B (multp\<^sub>H\<^sub>O R)"
e06463478a3f added lemma irreflp_on_multpHO[simp]
desharna
parents: 77063
diff changeset
   212
    by (simp add: irreflp_onI multp\<^sub>H\<^sub>O_def)
e06463478a3f added lemma irreflp_on_multpHO[simp]
desharna
parents: 77063
diff changeset
   213
77281
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   214
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: 77104
diff changeset
   215
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: 77104
diff changeset
   216
build a counterexample.\<close>
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   217
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   218
lemma asymp_not_liftable_to_multp\<^sub>H\<^sub>O:
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   219
  fixes a b c d :: 'a
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   220
  assumes "distinct [a, b, c, d]"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   221
  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: 77104
diff changeset
   222
proof -
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   223
  define R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" where
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   224
    "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: 77104
diff changeset
   225
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   226
  from assms(1) have "{#a, b#} \<noteq> {#c, d#}"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   227
    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: 77104
diff changeset
   228
        set_mset_add_mset_insert set_mset_single)
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   229
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   230
  from assms(1) have "asymp R"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   231
    by (auto simp: R_def intro: asymp_onI)
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   232
  moreover have "\<not> asymp (multp\<^sub>H\<^sub>O R)"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   233
    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: 77104
diff changeset
   234
  proof (intro exI conjI)
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   235
    show "multp\<^sub>H\<^sub>O R {#a, b#} {#c, d#}"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   236
      unfolding multp\<^sub>H\<^sub>O_def
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   237
      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: 77104
diff changeset
   238
  next
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   239
    show "multp\<^sub>H\<^sub>O R {#c, d#} {#a, b#}"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   240
      unfolding multp\<^sub>H\<^sub>O_def
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   241
      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: 77104
diff changeset
   242
  qed
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   243
  ultimately show ?thesis
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   244
    unfolding not_all not_imp by auto
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   245
qed
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   246
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   247
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: 77104
diff changeset
   248
also asymmetric.\<close>
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   249
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   250
lemma asymp_multp\<^sub>H\<^sub>O:
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   251
  assumes "asymp R" and "transp R"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   252
  shows "asymp (multp\<^sub>H\<^sub>O R)"
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   253
  using assms
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   254
  by (metis asymp_on_iff_irreflp_on_if_transp_on irreflp_multp multp_eq_multp\<^sub>H\<^sub>O transp_multp)
3a2670c37e5c added lemmas asymp_not_liftable_to_multpHO and asymp_multpHO
desharna
parents: 77104
diff changeset
   255
77063
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   256
lemma totalp_on_multp\<^sub>D\<^sub>M:
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   257
  "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: 76682
diff changeset
   258
  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: 76682
diff changeset
   259
      totalp_onD totalp_onI)
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   260
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   261
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: 76682
diff changeset
   262
  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: 76682
diff changeset
   263
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   264
lemma totalp_on_multp\<^sub>H\<^sub>O:
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   265
  "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: 76682
diff changeset
   266
  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: 76682
diff changeset
   267
      totalp_onI)
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   268
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   269
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: 76682
diff changeset
   270
  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: 76682
diff changeset
   271
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   272
context preorder
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   273
begin
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   274
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   275
lemma order_mult: "class.order
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   276
  (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y} \<or> M = N)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   277
  (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y})"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   278
  (is "class.order ?le ?less")
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   279
proof -
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   280
  have irrefl: "\<And>M :: 'a multiset. \<not> ?less M M"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   281
  proof
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   282
    fix M :: "'a multiset"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   283
    have "trans {(x'::'a, x). x' < x}"
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   284
      by (rule transI) (blast intro: less_trans)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   285
    moreover
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   286
    assume "(M, M) \<in> mult {(x, y). x < y}"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   287
    ultimately have "\<exists>I J K. M = I + J \<and> M = I + K
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   288
      \<and> J \<noteq> {#} \<and> (\<forall>k\<in>set_mset K. \<exists>j\<in>set_mset J. (k, j) \<in> {(x, y). x < y})"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   289
      by (rule mult_implies_one_step)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   290
    then obtain I J K where "M = I + J" and "M = I + K"
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   291
      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
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   292
    then have aux1: "K \<noteq> {#}" and aux2: "\<forall>k\<in>set_mset K. \<exists>j\<in>set_mset K. k < j" by auto
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   293
    have "finite (set_mset K)" by simp
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   294
    moreover note aux2
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   295
    ultimately have "set_mset K = {}"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   296
      by (induct rule: finite_induct)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   297
       (simp, metis (mono_tags) insert_absorb insert_iff insert_not_empty less_irrefl less_trans)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   298
    with aux1 show False by simp
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   299
  qed
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   300
  have trans: "\<And>K M N :: 'a multiset. ?less K M \<Longrightarrow> ?less M N \<Longrightarrow> ?less K N"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   301
    unfolding mult_def by (blast intro: trancl_trans)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   302
  show "class.order ?le ?less"
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   303
    by standard (auto simp add: less_eq_multiset_def irrefl dest: trans)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   304
qed
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   305
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60397
diff changeset
   306
text \<open>The Dershowitz--Manna ordering:\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   307
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   308
definition less_multiset\<^sub>D\<^sub>M where
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   309
  "less_multiset\<^sub>D\<^sub>M M N \<longleftrightarrow>
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   310
   (\<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
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   311
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   312
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60397
diff changeset
   313
text \<open>The Huet--Oppen ordering:\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   314
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   315
definition less_multiset\<^sub>H\<^sub>O where
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   316
  "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))"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   317
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61424
diff changeset
   318
lemma mult_imp_less_multiset\<^sub>H\<^sub>O:
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61424
diff changeset
   319
  "(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: 74867
diff changeset
   320
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   321
  using multp_imp_multp\<^sub>H\<^sub>O[of "(<)"]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   322
  by (simp add: less_multiset\<^sub>H\<^sub>O_def multp\<^sub>H\<^sub>O_def)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   323
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   324
lemma less_multiset\<^sub>D\<^sub>M_imp_mult:
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   325
  "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: 74867
diff changeset
   326
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   327
  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
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   328
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   329
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: 74867
diff changeset
   330
  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: 74867
diff changeset
   331
  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: 74867
diff changeset
   332
  by (rule multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   333
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   334
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: 74867
diff changeset
   335
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   336
  using multp_eq_multp\<^sub>D\<^sub>M[of "(<)", simplified]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   337
  by (simp add: multp\<^sub>D\<^sub>M_def less_multiset\<^sub>D\<^sub>M_def)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   338
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   339
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: 74867
diff changeset
   340
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   341
  using multp_eq_multp\<^sub>H\<^sub>O[of "(<)", simplified]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   342
  by (simp add: multp\<^sub>H\<^sub>O_def less_multiset\<^sub>H\<^sub>O_def)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   343
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   344
lemmas mult\<^sub>D\<^sub>M = mult_less_multiset\<^sub>D\<^sub>M[unfolded less_multiset\<^sub>D\<^sub>M_def]
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   345
lemmas mult\<^sub>H\<^sub>O = mult_less_multiset\<^sub>H\<^sub>O[unfolded less_multiset\<^sub>H\<^sub>O_def]
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   346
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   347
end
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   348
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   349
lemma less_multiset_less_multiset\<^sub>H\<^sub>O: "M < N \<longleftrightarrow> less_multiset\<^sub>H\<^sub>O M N"
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   350
  unfolding less_multiset_def multp_def mult\<^sub>H\<^sub>O less_multiset\<^sub>H\<^sub>O_def ..
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   351
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   352
lemma less_multiset\<^sub>D\<^sub>M:
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   353
  "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: 74864
diff changeset
   354
  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: 74864
diff changeset
   355
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   356
lemma less_multiset\<^sub>H\<^sub>O:
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   357
  "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: 74864
diff changeset
   358
  by (rule mult\<^sub>H\<^sub>O[folded multp_def less_multiset_def])
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   359
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   360
lemma subset_eq_imp_le_multiset:
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   361
  shows "M \<subseteq># N \<Longrightarrow> M \<le> N"
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   362
  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: 59958
diff changeset
   363
  by (simp add: less_le_not_le subseteq_mset_def)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   364
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   365
(* FIXME: "le" should be "less" in this and other names *)
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   366
lemma le_multiset_right_total: "M < add_mset x M"
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   367
  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: 63310
diff changeset
   368
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   369
lemma less_eq_multiset_empty_left[simp]:
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   370
  shows "{#} \<le> M"
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   371
  by (simp add: subset_eq_imp_le_multiset)
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   372
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   373
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: 74864
diff changeset
   374
  unfolding less_multiset\<^sub>H\<^sub>O
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   375
  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: 63407
diff changeset
   376
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   377
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: 63310
diff changeset
   378
  by (metis less_eq_multiset_empty_left antisym)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   379
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   380
(* FIXME: "le" should be "less" in this and other names *)
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   381
lemma le_multiset_empty_left[simp]: "M \<noteq> {#} \<Longrightarrow> {#} < M"
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   382
  by (simp add: less_multiset\<^sub>H\<^sub>O)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   383
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   384
(* FIXME: "le" should be "less" in this and other names *)
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   385
lemma le_multiset_empty_right[simp]: "\<not> M < {#}"
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   386
  using subset_mset.le_zero_eq less_multiset_def multp_def less_multiset\<^sub>D\<^sub>M by blast
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   387
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   388
(* FIXME: "le" should be "less" in this and other names *)
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   389
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: 63407
diff changeset
   390
  by (drule subset_mset.diff_add[symmetric]) (metis union_le_mono2)
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   391
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   392
instantiation multiset :: (preorder) ordered_ab_semigroup_monoid_add_imp_le
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   393
begin
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   394
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   395
lemma less_eq_multiset\<^sub>H\<^sub>O:
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   396
  "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: 74864
diff changeset
   397
  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: 63407
diff changeset
   398
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   399
instance by standard (auto simp: less_eq_multiset\<^sub>H\<^sub>O)
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   400
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   401
lemma
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   402
  fixes M N :: "'a multiset"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   403
  shows
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   404
    less_eq_multiset_plus_left: "N \<le> (M + N)" and
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   405
    less_eq_multiset_plus_right: "M \<le> (M + N)"
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   406
  by simp_all
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   407
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   408
lemma
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   409
  fixes M N :: "'a multiset"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   410
  shows
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   411
    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: 63410
diff changeset
   412
    le_multiset_plus_right_nonempty: "N \<noteq> {#} \<Longrightarrow> M < M + N"
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   413
    by simp_all
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   414
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   415
end
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   416
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   417
lemma all_lt_Max_imp_lt_mset: "N \<noteq> {#} \<Longrightarrow> (\<forall>a \<in># M. a < Max (set_mset N)) \<Longrightarrow> M < N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   418
  by (meson Max_in[OF finite_set_mset] ex_gt_imp_less_multiset set_mset_eq_empty_iff)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   419
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   420
lemma lt_imp_ex_count_lt: "M < N \<Longrightarrow> \<exists>y. count M y < count N y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   421
  by (meson less_eq_multiset\<^sub>H\<^sub>O less_le_not_le)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   422
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   423
lemma subset_imp_less_mset: "A \<subset># B \<Longrightarrow> A < B"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   424
  by (simp add: order.not_eq_order_implies_strict subset_eq_imp_le_multiset)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   425
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   426
lemma image_mset_strict_mono:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   427
  assumes
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   428
    mono_f: "\<forall>x \<in> set_mset M. \<forall>y \<in> set_mset N. x < y \<longrightarrow> f x < f y" and
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   429
    less: "M < N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   430
  shows "image_mset f M < image_mset f N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   431
proof -
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   432
  obtain Y X where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   433
    y_nemp: "Y \<noteq> {#}" and y_sub_N: "Y \<subseteq># N" and M_eq: "M = N - Y + X" and
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   434
    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: 74864
diff changeset
   435
    using less[unfolded less_multiset\<^sub>D\<^sub>M] by blast
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   436
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   437
  have x_sub_M: "X \<subseteq># M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   438
    using M_eq by simp
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   439
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   440
  let ?fY = "image_mset f Y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   441
  let ?fX = "image_mset f X"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   442
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   443
  show ?thesis
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   444
    unfolding less_multiset\<^sub>D\<^sub>M
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   445
  proof (intro exI conjI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   446
    show "image_mset f M = image_mset f N - ?fY + ?fX"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   447
      using M_eq[THEN arg_cong, of "image_mset f"] y_sub_N
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   448
      by (metis image_mset_Diff image_mset_union)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   449
  next
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   450
    obtain y where y: "\<forall>x. x \<in># X \<longrightarrow> y x \<in># Y \<and> x < y x"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   451
      using ex_y by moura
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   452
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   453
    show "\<forall>fx. fx \<in># ?fX \<longrightarrow> (\<exists>fy. fy \<in># ?fY \<and> fx < fy)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   454
    proof (intro allI impI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   455
      fix fx
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   456
      assume "fx \<in># ?fX"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   457
      then obtain x where fx: "fx = f x" and x_in: "x \<in># X"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   458
        by auto
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   459
      hence y_in: "y x \<in># Y" and y_gt: "x < y x"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   460
        using y[rule_format, OF x_in] by blast+
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   461
      hence "f (y x) \<in># ?fY \<and> f x < f (y x)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   462
        using mono_f y_sub_N x_sub_M x_in
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   463
        by (metis image_eqI in_image_mset mset_subset_eqD)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   464
      thus "\<exists>fy. fy \<in># ?fY \<and> fx < fy"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   465
        unfolding fx by auto
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   466
    qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   467
  qed (auto simp: y_nemp y_sub_N image_mset_subseteq_mono)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   468
qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   469
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   470
lemma image_mset_mono:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   471
  assumes
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   472
    mono_f: "\<forall>x \<in> set_mset M. \<forall>y \<in> set_mset N. x < y \<longrightarrow> f x < f y" and
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   473
    less: "M \<le> N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   474
  shows "image_mset f M \<le> image_mset f N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   475
  by (metis eq_iff image_mset_strict_mono less less_imp_le mono_f order.not_eq_order_implies_strict)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   476
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   477
lemma mset_lt_single_right_iff[simp]: "M < {#y#} \<longleftrightarrow> (\<forall>x \<in># M. x < y)" for y :: "'a::linorder"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   478
proof (rule iffI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   479
  assume M_lt_y: "M < {#y#}"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   480
  show "\<forall>x \<in># M. x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   481
  proof
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   482
    fix x
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   483
    assume x_in: "x \<in># M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   484
    hence M: "M - {#x#} + {#x#} = M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   485
      by (meson insert_DiffM2)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   486
    hence "\<not> {#x#} < {#y#} \<Longrightarrow> x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   487
      using x_in M_lt_y
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   488
      by (metis diff_single_eq_union le_multiset_empty_left less_add_same_cancel2 mset_le_trans)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   489
    also have "\<not> {#y#} < M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   490
      using M_lt_y mset_le_not_sym by blast
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   491
    ultimately show "x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   492
      by (metis (no_types) Max_ge all_lt_Max_imp_lt_mset empty_iff finite_set_mset insertE
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   493
        less_le_trans linorder_less_linear mset_le_not_sym set_mset_add_mset_insert
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   494
        set_mset_eq_empty_iff x_in)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   495
  qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   496
next
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   497
  assume y_max: "\<forall>x \<in># M. x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   498
  show "M < {#y#}"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   499
    by (rule all_lt_Max_imp_lt_mset) (auto intro!: y_max)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   500
qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   501
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   502
lemma mset_le_single_right_iff[simp]:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   503
  "M \<le> {#y#} \<longleftrightarrow> M = {#y#} \<or> (\<forall>x \<in># M. x < y)" for y :: "'a::linorder"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   504
  by (meson less_eq_multiset_def mset_lt_single_right_iff)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   505
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   506
77834
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   507
subsubsection \<open>Simplifications\<close>
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   508
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   509
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: 77355
diff changeset
   510
  assumes "n \<noteq> 0"
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   511
  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: 77355
diff changeset
   512
proof (rule iffI)
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   513
  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: 77355
diff changeset
   514
  hence
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   515
    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: 77355
diff changeset
   516
    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: 77355
diff changeset
   517
    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: 77355
diff changeset
   518
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   519
  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: 77355
diff changeset
   520
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   521
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   522
  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: 77355
diff changeset
   523
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   524
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   525
  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: 77355
diff changeset
   526
    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: 77355
diff changeset
   527
next
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   528
  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: 77355
diff changeset
   529
  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: 77355
diff changeset
   530
    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: 77355
diff changeset
   531
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   532
  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: 77355
diff changeset
   533
    by (simp add: assms repeat_mset_cancel1)
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   534
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   535
  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: 77355
diff changeset
   536
    (\<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: 77355
diff changeset
   537
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   538
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   539
  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: 77355
diff changeset
   540
    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: 77355
diff changeset
   541
qed
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   542
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   543
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: 77355
diff changeset
   544
  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: 77355
diff changeset
   545
  by (simp add: numeral_Bit0)
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   546
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   547
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   548
subsection \<open>Simprocs\<close>
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   549
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   550
lemma mset_le_add_iff1:
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   551
  "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: 63525
diff changeset
   552
proof -
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   553
  assume "j \<le> i"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   554
  then have "j + (i - j) = i"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   555
    using le_add_diff_inverse by blast
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   556
  then show ?thesis
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   557
    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: 63525
diff changeset
   558
qed
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   559
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   560
lemma mset_le_add_iff2:
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   561
  "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: 63525
diff changeset
   562
proof -
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   563
  assume "i \<le> j"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   564
  then have "i + (j - i) = j"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   565
    using le_add_diff_inverse by blast
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   566
  then show ?thesis
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   567
    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: 63525
diff changeset
   568
qed
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   569
65027
2b8583507891 renaming multiset simprocs
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64978
diff changeset
   570
simproc_setup msetless_cancel
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   571
  ("(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: 65027
diff changeset
   572
   "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: 65027
diff changeset
   573
   "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: 65027
diff changeset
   574
   "repeat_mset p m < n" | "m < repeat_mset p n") =
65031
52e2c99f3711 use the cancellation simprocs directly
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 65028
diff changeset
   575
  \<open>fn phi => Cancel_Simprocs.less_cancel\<close>
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   576
65027
2b8583507891 renaming multiset simprocs
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64978
diff changeset
   577
simproc_setup msetle_cancel
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   578
  ("(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: 65027
diff changeset
   579
   "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: 65027
diff changeset
   580
   "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: 65027
diff changeset
   581
   "repeat_mset p m \<le> n" | "m \<le> repeat_mset p n") =
65031
52e2c99f3711 use the cancellation simprocs directly
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 65028
diff changeset
   582
  \<open>fn phi => Cancel_Simprocs.less_eq_cancel\<close>
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   583
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   584
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   585
subsection \<open>Additional facts and instantiations\<close>
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   586
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   587
lemma ex_gt_count_imp_le_multiset:
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   588
  "(\<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: 74864
diff changeset
   589
  unfolding less_multiset\<^sub>H\<^sub>O
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   590
  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: 63409
diff changeset
   591
64418
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   592
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: 74864
diff changeset
   593
  unfolding less_multiset\<^sub>H\<^sub>O by simp
64418
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   594
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   595
lemma mset_le_single_iff[iff]: "{#x#} \<le> {#y#} \<longleftrightarrow> x \<le> y" for x y :: "'a::order"
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   596
  unfolding less_eq_multiset\<^sub>H\<^sub>O by force
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   597
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   598
instance multiset :: (linorder) linordered_cancel_ab_semigroup_add
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   599
  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: 63409
diff changeset
   600
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   601
lemma less_eq_multiset_total:
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   602
  fixes M N :: "'a :: linorder multiset"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   603
  shows "\<not> M \<le> N \<Longrightarrow> N \<le> M"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   604
  by simp
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   605
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   606
instantiation multiset :: (wellorder) wellorder
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   607
begin
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   608
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   609
lemma wf_less_multiset: "wf {(M :: 'a multiset, N). M < N}"
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   610
  unfolding less_multiset_def multp_def by (auto intro: wf_mult wf)
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   611
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   612
instance by standard (metis less_multiset_def multp_def wf wf_def wf_mult)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   613
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   614
end
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   615
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   616
instantiation multiset :: (preorder) order_bot
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   617
begin
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   618
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   619
definition bot_multiset :: "'a multiset" where "bot_multiset = {#}"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   620
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   621
instance by standard (simp add: bot_multiset_def)
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   622
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   623
end
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   624
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   625
instance multiset :: (preorder) no_top
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   626
proof standard
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   627
  fix x :: "'a multiset"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   628
  obtain a :: 'a where True by simp
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   629
  have "x < x + (x + {#a#})"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   630
    by simp
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   631
  then show "\<exists>y. x < y"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   632
    by blast
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   633
qed
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   634
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   635
instance multiset :: (preorder) ordered_cancel_comm_monoid_add
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   636
  by standard
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   637
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   638
instantiation multiset :: (linorder) distrib_lattice
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   639
begin
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   640
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   641
definition inf_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   642
  "inf_multiset A B = (if A < B then A else B)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   643
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   644
definition sup_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   645
  "sup_multiset A B = (if B > A then B else A)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   646
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   647
instance
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   648
  by intro_classes (auto simp: inf_multiset_def sup_multiset_def)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   649
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   650
end
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   651
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   652
end