src/HOL/UNITY/Comp/AllocBase.thy
author fleury <Mathias.Fleury@mpi-inf.mpg.de>
Thu, 07 Jul 2016 17:34:39 +0200
changeset 63410 9789ccc2a477
parent 63409 3f3223b90239
child 63882 018998c00003
permissions -rw-r--r--
more instantiations for multiset
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24147
diff changeset
     1
(*  Title:      HOL/UNITY/Comp/AllocBase.thy
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     3
    Copyright   1998  University of Cambridge
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     4
*)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     5
63146
f1ecba0272f9 isabelle update_cartouches -c -t;
wenzelm
parents: 62608
diff changeset
     6
section\<open>Common Declarations for Chandy and Charpentier's Allocator\<close>
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
     7
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
     8
theory AllocBase imports "../UNITY_Main" "~~/src/HOL/Library/Multiset_Order" begin
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     9
45827
66c68453455c modernized specifications;
wenzelm
parents: 39246
diff changeset
    10
consts Nclients :: nat  (*Number of clients*)
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    11
45827
66c68453455c modernized specifications;
wenzelm
parents: 39246
diff changeset
    12
axiomatization NbT :: nat  (*Number of tokens in system*)
66c68453455c modernized specifications;
wenzelm
parents: 39246
diff changeset
    13
  where NbT_pos: "0 < NbT"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    14
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    15
abbreviation (input) tokens :: "nat list \<Rightarrow> nat"
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    16
where
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    17
  "tokens \<equiv> listsum"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    18
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    19
abbreviation (input)
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    20
  "bag_of \<equiv> mset"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    21
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    22
lemma setsum_fun_mono:
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    23
  fixes f :: "nat \<Rightarrow> nat"
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    24
  shows "(\<And>i. i < n \<Longrightarrow> f i \<le> g i) \<Longrightarrow> setsum f {..<n} \<le> setsum g {..<n}"
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    25
  by (induct n) (auto simp add: lessThan_Suc add_le_mono)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    26
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    27
lemma tokens_mono_prefix: "xs \<le> ys \<Longrightarrow> tokens xs \<le> tokens ys"
46911
6d2a2f0e904e tuned proofs;
wenzelm
parents: 45827
diff changeset
    28
  by (induct ys arbitrary: xs) (auto simp add: prefix_Cons)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    29
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    30
lemma mono_tokens: "mono tokens"
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    31
  using tokens_mono_prefix by (rule monoI)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    32
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    33
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    34
(** bag_of **)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    35
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    36
lemma bag_of_append [simp]: "bag_of (l@l') = bag_of l + bag_of l'"
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    37
  by (fact mset_append)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    38
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    39
lemma mono_bag_of: "mono (bag_of :: 'a list => ('a::order) multiset)"
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    40
apply (rule monoI)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    41
apply (unfold prefix_def)
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    42
apply (erule genPrefix.induct, simp_all add: add_right_mono)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    43
apply (erule order_trans)
63410
9789ccc2a477 more instantiations for multiset
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 63409
diff changeset
    44
apply simp
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    45
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    46
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    47
(** setsum **)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    48
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    49
declare setsum.cong [cong]
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    50
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    51
lemma bag_of_sublist_lemma:
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    52
     "(\<Sum>i\<in> A Int lessThan k. {#if i<k then f i else g i#}) =  
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    53
      (\<Sum>i\<in> A Int lessThan k. {#f i#})"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    54
by (rule setsum.cong, auto)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    55
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    56
lemma bag_of_sublist:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    57
     "bag_of (sublist l A) =  
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    58
      (\<Sum>i\<in> A Int lessThan (length l). {# l!i #})"
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    59
apply (rule_tac xs = l in rev_induct, simp)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    60
apply (simp add: sublist_append Int_insert_right lessThan_Suc nth_append 
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57418
diff changeset
    61
                 bag_of_sublist_lemma ac_simps)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    62
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    63
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    64
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    65
lemma bag_of_sublist_Un_Int:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    66
     "bag_of (sublist l (A Un B)) + bag_of (sublist l (A Int B)) =  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    67
      bag_of (sublist l A) + bag_of (sublist l B)"
15045
d59f7e2e18d3 Moved to new m<..<n syntax for set intervals.
nipkow
parents: 14738
diff changeset
    68
apply (subgoal_tac "A Int B Int {..<length l} =
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24147
diff changeset
    69
                    (A Int {..<length l}) Int (B Int {..<length l}) ")
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    70
apply (simp add: bag_of_sublist Int_Un_distrib2 setsum.union_inter, blast)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    71
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    72
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    73
lemma bag_of_sublist_Un_disjoint:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    74
     "A Int B = {}  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    75
      ==> bag_of (sublist l (A Un B)) =  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    76
          bag_of (sublist l A) + bag_of (sublist l B)"
14114
e97ca1034caa tidying
paulson
parents: 13798
diff changeset
    77
by (simp add: bag_of_sublist_Un_Int [symmetric])
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    78
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    79
lemma bag_of_sublist_UN_disjoint [rule_format]:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    80
     "[| finite I; ALL i:I. ALL j:I. i~=j --> A i Int A j = {} |]  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    81
      ==> bag_of (sublist l (UNION I A)) =   
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    82
          (\<Sum>i\<in>I. bag_of (sublist l (A i)))"
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    83
apply (auto simp add: bag_of_sublist)
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    84
unfolding UN_simps [symmetric]
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    85
apply (subst setsum.UNION_disjoint)
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62430
diff changeset
    86
apply auto
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    87
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    88
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    89
end