src/HOL/HOLCF/IOA/NTP/Multiset.thy
author wenzelm
Tue, 29 Mar 2011 17:47:11 +0200
changeset 42151 4da4fc77664b
parent 41310 65631ca437c9
child 47026 36dacca8a95c
permissions -rw-r--r--
tuned headers;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42151
4da4fc77664b tuned headers;
wenzelm
parents: 41310
diff changeset
     1
(*  Title:      HOL/HOLCF/IOA/NTP/Multiset.thy
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
     2
    Author:     Tobias Nipkow & Konrad Slind
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
     3
*)
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
     4
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     5
header {* Axiomatic multisets *}
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
     6
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     7
theory Multiset
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     8
imports Lemmas
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     9
begin
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    10
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    11
typedecl
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    12
  'a multiset
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    13
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    14
consts
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    15
41310
65631ca437c9 proper identifiers for consts and types;
wenzelm
parents: 40774
diff changeset
    16
  emptym :: "'a multiset"                        ("{|}")
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    17
  addm   :: "['a multiset, 'a] => 'a multiset"
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    18
  delm   :: "['a multiset, 'a] => 'a multiset"
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    19
  countm :: "['a multiset, 'a => bool] => nat"
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    20
  count  :: "['a multiset, 'a] => nat"
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    21
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    22
axioms
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    23
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    24
delm_empty_def:
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    25
  "delm {|} x = {|}"
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    26
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    27
delm_nonempty_def:
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    28
  "delm (addm M x) y == (if x=y then M else addm (delm M y) x)"
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    29
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    30
countm_empty_def:
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    31
   "countm {|} P == 0"
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    32
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    33
countm_nonempty_def:
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    34
   "countm (addm M x) P == countm M P + (if P x then Suc 0 else 0)"
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    35
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    36
count_def:
3852
e694c660055b fixed dots;
wenzelm
parents: 3073
diff changeset
    37
   "count M x == countm M (%y. y = x)"
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    38
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    39
"induction":
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    40
   "[| P({|}); !!M x. P(M) ==> P(addm M x) |] ==> P(M)"
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    41
19739
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    42
lemma count_empty: 
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    43
   "count {|} x = 0"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    44
  by (simp add: Multiset.count_def Multiset.countm_empty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    45
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    46
lemma count_addm_simp: 
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    47
     "count (addm M x) y = (if y=x then Suc(count M y) else count M y)"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    48
  by (simp add: Multiset.count_def Multiset.countm_nonempty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    49
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    50
lemma count_leq_addm: "count M y <= count (addm M x) y"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    51
  by (simp add: count_addm_simp)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    52
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    53
lemma count_delm_simp: 
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    54
     "count (delm M x) y = (if y=x then count M y - 1 else count M y)"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    55
apply (unfold Multiset.count_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    56
apply (rule_tac M = "M" in Multiset.induction)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    57
apply (simp (no_asm_simp) add: Multiset.delm_empty_def Multiset.countm_empty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    58
apply (simp add: Multiset.delm_nonempty_def Multiset.countm_nonempty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    59
apply safe
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    60
apply simp
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    61
done
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    62
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    63
lemma countm_props: "!!M. (!x. P(x) --> Q(x)) ==> (countm M P <= countm M Q)"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    64
apply (rule_tac M = "M" in Multiset.induction)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    65
 apply (simp (no_asm) add: Multiset.countm_empty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    66
apply (simp (no_asm) add: Multiset.countm_nonempty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    67
apply auto
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    68
done
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    69
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    70
lemma countm_spurious_delm: "!!P. ~P(obj) ==> countm M P = countm (delm M obj) P"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    71
  apply (rule_tac M = "M" in Multiset.induction)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    72
  apply (simp (no_asm) add: Multiset.delm_empty_def Multiset.countm_empty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    73
  apply (simp (no_asm_simp) add: Multiset.countm_nonempty_def Multiset.delm_nonempty_def)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    74
  done
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    75
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    76
25161
aa8474398030 changed back from ~=0 to >0
nipkow
parents: 25141
diff changeset
    77
lemma pos_count_imp_pos_countm [rule_format (no_asm)]: "!!P. P(x) ==> 0<count M x --> countm M P > 0"
19739
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    78
  apply (rule_tac M = "M" in Multiset.induction)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    79
  apply (simp (no_asm) add: Multiset.delm_empty_def Multiset.count_def Multiset.countm_empty_def)
25161
aa8474398030 changed back from ~=0 to >0
nipkow
parents: 25141
diff changeset
    80
  apply (simp add: Multiset.count_def Multiset.delm_nonempty_def Multiset.countm_nonempty_def)
19739
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    81
  done
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    82
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    83
lemma countm_done_delm: 
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    84
   "!!P. P(x) ==> 0<count M x --> countm (delm M x) P = countm M P - 1"
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    85
  apply (rule_tac M = "M" in Multiset.induction)
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    86
  apply (simp (no_asm) add: Multiset.delm_empty_def Multiset.countm_empty_def)
25161
aa8474398030 changed back from ~=0 to >0
nipkow
parents: 25141
diff changeset
    87
  apply (simp (no_asm_simp) add: count_addm_simp Multiset.delm_nonempty_def Multiset.countm_nonempty_def pos_count_imp_pos_countm)
19739
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    88
  apply auto
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    89
  done
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    90
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    91
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    92
declare count_addm_simp [simp] count_delm_simp [simp]
c58ef2aa5430 removed legacy ML scripts;
wenzelm
parents: 17244
diff changeset
    93
  Multiset.countm_empty_def [simp] Multiset.delm_empty_def [simp] count_empty [simp]
17244
0b2ff9541727 converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    94
3073
88366253a09a Old NTP files now running under the IOA meta theory based on HOLCF;
mueller
parents:
diff changeset
    95
end