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