src/HOL/UNITY/Comp/AllocBase.thy
author haftmann
Fri, 26 Feb 2016 22:44:11 +0100
changeset 62430 9527ff088c15
parent 60515 484559628038
child 62608 19f87fa0cfcb
permissions -rw-r--r--
more succint formulation of membership for multisets, similar to lists; discontinued ASCII notation for multiset membership; more theorems on multisets, dropping redundant interpretation; modernized notation; some annotations concerning future work
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
58889
5b7a9633cfa8 modernized header uniformly as section;
wenzelm
parents: 57514
diff changeset
     6
section{*Common Declarations for Chandy and Charpentier's Allocator*}
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
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    15
(*This function merely sums the elements of a list*)
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35274
diff changeset
    16
primrec tokens :: "nat list => nat" where
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    17
  "tokens [] = 0"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 35274
diff changeset
    18
| "tokens (x#xs) = x + tokens xs"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    19
60515
484559628038 renamed multiset_of -> mset
nipkow
parents: 60397
diff changeset
    20
abbreviation (input) "bag_of \<equiv> mset"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    21
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    22
lemma setsum_fun_mono [rule_format]:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    23
     "!!f :: nat=>nat.  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    24
      (ALL i. i<n --> f i <= g i) -->  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    25
      setsum f (lessThan n) <= setsum g (lessThan n)"
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    26
apply (induct_tac "n")
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    27
apply (auto simp add: lessThan_Suc)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    28
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    29
46911
6d2a2f0e904e tuned proofs;
wenzelm
parents: 45827
diff changeset
    30
lemma tokens_mono_prefix: "xs <= ys ==> tokens xs <= tokens ys"
6d2a2f0e904e tuned proofs;
wenzelm
parents: 45827
diff changeset
    31
  by (induct ys arbitrary: xs) (auto simp add: prefix_Cons)
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
lemma mono_tokens: "mono tokens"
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    34
apply (unfold mono_def)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    35
apply (blast intro: tokens_mono_prefix)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    36
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    37
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
(** bag_of **)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    40
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    41
lemma bag_of_append [simp]: "bag_of (l@l') = bag_of l + bag_of l'"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57418
diff changeset
    42
  by (induct l) (simp_all add: ac_simps)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    43
62430
9527ff088c15 more succint formulation of membership for multisets, similar to lists;
haftmann
parents: 60515
diff changeset
    44
lemma subseteq_le_multiset: "A #\<subseteq># A + B"
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    45
unfolding le_multiset_def apply (cases B; simp)
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    46
apply (rule HOL.disjI1)
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    47
apply (rule union_less_mono2[of "{#}" "_ + {#_#}" A, simplified])
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    48
apply (simp add: less_multiset\<^sub>H\<^sub>O)
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    49
done
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    50
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    51
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
    52
apply (rule monoI)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    53
apply (unfold prefix_def)
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    54
apply (erule genPrefix.induct, simp_all add: add_right_mono)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    55
apply (erule order_trans)
60397
f8a513fedb31 Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents: 58889
diff changeset
    56
apply (simp add: less_eq_multiset_def subseteq_le_multiset)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    57
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    58
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    59
(** setsum **)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    60
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    61
declare setsum.cong [cong]
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    62
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    63
lemma bag_of_sublist_lemma:
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    64
     "(\<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
    65
      (\<Sum>i\<in> A Int lessThan k. {#f i#})"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    66
by (rule setsum.cong, auto)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    67
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    68
lemma bag_of_sublist:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    69
     "bag_of (sublist l A) =  
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    70
      (\<Sum>i\<in> A Int lessThan (length l). {# l!i #})"
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    71
apply (rule_tac xs = l in rev_induct, simp)
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    72
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
    73
                 bag_of_sublist_lemma ac_simps)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    74
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    75
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    76
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    77
lemma bag_of_sublist_Un_Int:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    78
     "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
    79
      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
    80
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
    81
                    (A Int {..<length l}) Int (B Int {..<length l}) ")
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    82
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
    83
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    84
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    85
lemma bag_of_sublist_Un_disjoint:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    86
     "A Int B = {}  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    87
      ==> bag_of (sublist l (A Un B)) =  
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    88
          bag_of (sublist l A) + bag_of (sublist l B)"
14114
e97ca1034caa tidying
paulson
parents: 13798
diff changeset
    89
by (simp add: bag_of_sublist_Un_Int [symmetric])
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    90
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    91
lemma bag_of_sublist_UN_disjoint [rule_format]:
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    92
     "[| 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
    93
      ==> bag_of (sublist l (UNION I A)) =   
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 15045
diff changeset
    94
          (\<Sum>i\<in>I. bag_of (sublist l (A i)))"
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    95
apply (simp del: UN_simps 
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    96
            add: UN_simps [symmetric] add: bag_of_sublist)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 46911
diff changeset
    97
apply (subst setsum.UNION_disjoint, auto)
13798
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    98
done
4c1a53627500 conversion to new-style theories and tidying
paulson
parents: 13786
diff changeset
    99
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   100
end