src/HOL/Library/Multiset_Order.thy
author desharna
Wed, 10 May 2023 08:56:32 +0200
changeset 78016 b0ef3aae2bdb
parent 78014 24f0cd70790b
child 78017 db041670d6bb
permissions -rw-r--r--
tuned theory structure
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
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   314
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   315
paragraph \<open>Totality\<close>
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   316
77063
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   317
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
   318
  "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
   319
  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
   320
      totalp_onD totalp_onI)
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   321
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   322
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
   323
  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
   324
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   325
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
   326
  "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
   327
  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
   328
      totalp_onI)
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   329
4b37cc497d7e added lemmas totalp_on_multpDM, totalp_multpDM, totalp_on_multpHO, and totalp_multpHO
desharna
parents: 76682
diff changeset
   330
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
   331
  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
   332
78016
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   333
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   334
paragraph \<open>Type Classes\<close>
b0ef3aae2bdb tuned theory structure
desharna
parents: 78014
diff changeset
   335
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   336
context preorder
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   337
begin
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   338
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   339
lemma order_mult: "class.order
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   340
  (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y} \<or> M = N)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   341
  (\<lambda>M N. (M, N) \<in> mult {(x, y). x < y})"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   342
  (is "class.order ?le ?less")
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   343
proof -
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   344
  have irrefl: "\<And>M :: 'a multiset. \<not> ?less M M"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   345
  proof
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   346
    fix M :: "'a multiset"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   347
    have "trans {(x'::'a, x). x' < x}"
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   348
      by (rule transI) (blast intro: less_trans)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   349
    moreover
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   350
    assume "(M, M) \<in> mult {(x, y). x < y}"
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   351
    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
   352
      \<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
   353
      by (rule mult_implies_one_step)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   354
    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
   355
      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
   356
    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
   357
    have "finite (set_mset K)" by simp
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   358
    moreover note aux2
60495
d7ff0a1df90a renamed Multiset.set_of to the canonical set_mset
nipkow
parents: 60397
diff changeset
   359
    ultimately have "set_mset K = {}"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   360
      by (induct rule: finite_induct)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   361
       (simp, metis (mono_tags) insert_absorb insert_iff insert_not_empty less_irrefl less_trans)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   362
    with aux1 show False by simp
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   363
  qed
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   364
  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
   365
    unfolding mult_def by (blast intro: trancl_trans)
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   366
  show "class.order ?le ?less"
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   367
    by standard (auto simp add: less_eq_multiset_def irrefl dest: trans)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   368
qed
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   369
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60397
diff changeset
   370
text \<open>The Dershowitz--Manna ordering:\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   371
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   372
definition less_multiset\<^sub>D\<^sub>M where
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   373
  "less_multiset\<^sub>D\<^sub>M M N \<longleftrightarrow>
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   374
   (\<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
   375
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   376
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60397
diff changeset
   377
text \<open>The Huet--Oppen ordering:\<close>
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   378
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   379
definition less_multiset\<^sub>H\<^sub>O where
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   380
  "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
   381
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 61424
diff changeset
   382
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
   383
  "(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
   384
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   385
  using multp_imp_multp\<^sub>H\<^sub>O[of "(<)"]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   386
  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
   387
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   388
lemma less_multiset\<^sub>D\<^sub>M_imp_mult:
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   389
  "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
   390
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   391
  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
   392
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   393
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
   394
  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
   395
  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
   396
  by (rule multp\<^sub>H\<^sub>O_imp_multp\<^sub>D\<^sub>M)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   397
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   398
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
   399
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   400
  using multp_eq_multp\<^sub>D\<^sub>M[of "(<)", simplified]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   401
  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
   402
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   403
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
   404
  unfolding multp_def[of "(<)", symmetric]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   405
  using multp_eq_multp\<^sub>H\<^sub>O[of "(<)", simplified]
7b0a241732c1 added definitions multp{DM,HO} and corresponding lemmas
desharna
parents: 74867
diff changeset
   406
  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
   407
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   408
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
   409
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
   410
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   411
end
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   412
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   413
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
   414
  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
   415
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   416
lemma less_multiset\<^sub>D\<^sub>M:
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   417
  "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
   418
  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
   419
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   420
lemma less_multiset\<^sub>H\<^sub>O:
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   421
  "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
   422
  by (rule mult\<^sub>H\<^sub>O[folded multp_def less_multiset_def])
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   423
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   424
lemma subset_eq_imp_le_multiset:
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   425
  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
   426
  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
   427
  by (simp add: less_le_not_le subseteq_mset_def)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   428
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   429
(* FIXME: "le" should be "less" in this and other names *)
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   430
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
   431
  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
   432
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   433
lemma less_eq_multiset_empty_left[simp]:
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   434
  shows "{#} \<le> M"
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   435
  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
   436
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   437
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
   438
  unfolding less_multiset\<^sub>H\<^sub>O
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   439
  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
   440
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   441
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
   442
  by (metis less_eq_multiset_empty_left antisym)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   443
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   444
(* 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
   445
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
   446
  by (simp add: less_multiset\<^sub>H\<^sub>O)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   447
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   448
(* 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
   449
lemma le_multiset_empty_right[simp]: "\<not> M < {#}"
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   450
  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
   451
67020
c32254ab1901 added FIXMEs
blanchet
parents: 65546
diff changeset
   452
(* FIXME: "le" should be "less" in this and other names *)
64587
8355a6e2df79 standardized notation
haftmann
parents: 64418
diff changeset
   453
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
   454
  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
   455
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   456
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
   457
begin
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   458
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   459
lemma less_eq_multiset\<^sub>H\<^sub>O:
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   460
  "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
   461
  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
   462
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   463
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
   464
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   465
lemma
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   466
  fixes M N :: "'a multiset"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   467
  shows
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   468
    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
   469
    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
   470
  by simp_all
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   471
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   472
lemma
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   473
  fixes M N :: "'a multiset"
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   474
  shows
63525
f01d1e393f3f more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63410
diff changeset
   475
    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
   476
    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
   477
    by simp_all
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   478
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   479
end
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   480
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   481
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
   482
  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
   483
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   484
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
   485
  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
   486
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   487
lemma subset_imp_less_mset: "A \<subset># B \<Longrightarrow> A < B"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   488
  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
   489
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   490
lemma image_mset_strict_mono:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   491
  assumes
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   492
    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
   493
    less: "M < N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   494
  shows "image_mset f M < image_mset f N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   495
proof -
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   496
  obtain Y X where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   497
    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
   498
    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
   499
    using less[unfolded less_multiset\<^sub>D\<^sub>M] by blast
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   500
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   501
  have x_sub_M: "X \<subseteq># M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   502
    using M_eq by simp
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   503
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   504
  let ?fY = "image_mset f Y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   505
  let ?fX = "image_mset f X"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   506
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   507
  show ?thesis
74867
4220dcd6c22e restored lemmas less_multiset{DM,HO} inadvertently changed by c256bba593f3
desharna
parents: 74864
diff changeset
   508
    unfolding less_multiset\<^sub>D\<^sub>M
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   509
  proof (intro exI conjI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   510
    show "image_mset f M = image_mset f N - ?fY + ?fX"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   511
      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
   512
      by (metis image_mset_Diff image_mset_union)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   513
  next
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   514
    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
   515
      using ex_y by moura
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   516
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   517
    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
   518
    proof (intro allI impI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   519
      fix fx
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   520
      assume "fx \<in># ?fX"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   521
      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
   522
        by auto
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   523
      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
   524
        using y[rule_format, OF x_in] by blast+
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   525
      hence "f (y x) \<in># ?fY \<and> f x < f (y x)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   526
        using mono_f y_sub_N x_sub_M x_in
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   527
        by (metis image_eqI in_image_mset mset_subset_eqD)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   528
      thus "\<exists>fy. fy \<in># ?fY \<and> fx < fy"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   529
        unfolding fx by auto
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   530
    qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   531
  qed (auto simp: y_nemp y_sub_N image_mset_subseteq_mono)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   532
qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   533
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   534
lemma image_mset_mono:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   535
  assumes
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   536
    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
   537
    less: "M \<le> N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   538
  shows "image_mset f M \<le> image_mset f N"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   539
  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
   540
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   541
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
   542
proof (rule iffI)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   543
  assume M_lt_y: "M < {#y#}"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   544
  show "\<forall>x \<in># M. x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   545
  proof
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   546
    fix x
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   547
    assume x_in: "x \<in># M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   548
    hence M: "M - {#x#} + {#x#} = M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   549
      by (meson insert_DiffM2)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   550
    hence "\<not> {#x#} < {#y#} \<Longrightarrow> x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   551
      using x_in M_lt_y
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   552
      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
   553
    also have "\<not> {#y#} < M"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   554
      using M_lt_y mset_le_not_sym by blast
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   555
    ultimately show "x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   556
      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
   557
        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
   558
        set_mset_eq_empty_iff x_in)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   559
  qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   560
next
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   561
  assume y_max: "\<forall>x \<in># M. x < y"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   562
  show "M < {#y#}"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   563
    by (rule all_lt_Max_imp_lt_mset) (auto intro!: y_max)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   564
qed
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   565
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   566
lemma mset_le_single_right_iff[simp]:
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   567
  "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
   568
  by (meson less_eq_multiset_def mset_lt_single_right_iff)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   569
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   570
77834
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   571
subsubsection \<open>Simplifications\<close>
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   572
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   573
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
   574
  assumes "n \<noteq> 0"
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   575
  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
   576
proof (rule iffI)
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   577
  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
   578
  hence
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   579
    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
   580
    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
   581
    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
   582
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   583
  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
   584
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   585
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   586
  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
   587
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   588
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   589
  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
   590
    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
   591
next
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   592
  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
   593
  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
   594
    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
   595
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   596
  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
   597
    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
   598
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   599
  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
   600
    (\<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
   601
    by auto
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   602
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   603
  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
   604
    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
   605
qed
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   606
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   607
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
   608
  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
   609
  by (simp add: numeral_Bit0)
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   610
52e753197496 added lemmas multpHO_repeat_mset_repeat_mset[simp] and multpHO_double_double[simp]
desharna
parents: 77355
diff changeset
   611
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   612
subsection \<open>Simprocs\<close>
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   613
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   614
lemma mset_le_add_iff1:
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   615
  "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
   616
proof -
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   617
  assume "j \<le> i"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   618
  then have "j + (i - j) = i"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   619
    using le_add_diff_inverse by blast
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   620
  then show ?thesis
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   621
    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
   622
qed
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   623
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   624
lemma mset_le_add_iff2:
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   625
  "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
   626
proof -
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   627
  assume "i \<le> j"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   628
  then have "i + (j - i) = j"
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   629
    using le_add_diff_inverse by blast
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   630
  then show ?thesis
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   631
    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
   632
qed
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   633
65027
2b8583507891 renaming multiset simprocs
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64978
diff changeset
   634
simproc_setup msetless_cancel
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   635
  ("(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
   636
   "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
   637
   "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
   638
   "repeat_mset p m < n" | "m < repeat_mset p n") =
65031
52e2c99f3711 use the cancellation simprocs directly
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 65028
diff changeset
   639
  \<open>fn phi => Cancel_Simprocs.less_cancel\<close>
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   640
65027
2b8583507891 renaming multiset simprocs
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64978
diff changeset
   641
simproc_setup msetle_cancel
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   642
  ("(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
   643
   "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
   644
   "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
   645
   "repeat_mset p m \<le> n" | "m \<le> repeat_mset p n") =
65031
52e2c99f3711 use the cancellation simprocs directly
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 65028
diff changeset
   646
  \<open>fn phi => Cancel_Simprocs.less_eq_cancel\<close>
63793
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   647
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   648
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   649
subsection \<open>Additional facts and instantiations\<close>
e68a0b651eb5 add_mset constructor in multisets
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63525
diff changeset
   650
63388
a095acd4cfbf instantiate multiset with multiset ordering
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63310
diff changeset
   651
lemma ex_gt_count_imp_le_multiset:
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   652
  "(\<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
   653
  unfolding less_multiset\<^sub>H\<^sub>O
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   654
  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
   655
64418
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   656
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
   657
  unfolding less_multiset\<^sub>H\<^sub>O by simp
64418
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   658
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   659
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
   660
  unfolding less_eq_multiset\<^sub>H\<^sub>O by force
91eae3a1be51 more lemmas
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 64076
diff changeset
   661
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   662
instance multiset :: (linorder) linordered_cancel_ab_semigroup_add
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   663
  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
   664
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   665
lemma less_eq_multiset_total:
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   666
  fixes M N :: "'a :: linorder multiset"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   667
  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
   668
  by simp
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   669
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   670
instantiation multiset :: (wellorder) wellorder
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   671
begin
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   672
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   673
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
   674
  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
   675
74864
c256bba593f3 redefined less_multiset to be based on multp
desharna
parents: 74806
diff changeset
   676
instance by standard (metis less_multiset_def multp_def wf wf_def wf_mult)
59813
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   677
6320064f22bb more multiset theorems
blanchet
parents:
diff changeset
   678
end
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   679
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   680
instantiation multiset :: (preorder) order_bot
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   681
begin
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   682
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   683
definition bot_multiset :: "'a multiset" where "bot_multiset = {#}"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   684
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   685
instance by standard (simp add: bot_multiset_def)
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   686
63409
3f3223b90239 moved lemmas and locales around (with minor incompatibilities)
blanchet
parents: 63407
diff changeset
   687
end
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   688
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   689
instance multiset :: (preorder) no_top
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   690
proof standard
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   691
  fix x :: "'a multiset"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   692
  obtain a :: 'a where True by simp
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   693
  have "x < x + (x + {#a#})"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   694
    by simp
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   695
  then show "\<exists>y. x < y"
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   696
    by blast
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   697
qed
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   698
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   699
instance multiset :: (preorder) ordered_cancel_comm_monoid_add
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   700
  by standard
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   701
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   702
instantiation multiset :: (linorder) distrib_lattice
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   703
begin
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   704
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   705
definition inf_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   706
  "inf_multiset A B = (if A < B then A else B)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   707
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   708
definition sup_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   709
  "sup_multiset A B = (if B > A then B else A)"
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   710
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   711
instance
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   712
  by intro_classes (auto simp: inf_multiset_def sup_multiset_def)
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   713
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
   714
end
65546
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   715
7c58f69451b0 moved lemmas from AFP to Isabelle
blanchet
parents: 65031
diff changeset
   716
end