author | wenzelm |
Sat, 17 Oct 2009 14:43:18 +0200 | |
changeset 32960 | 69916a850301 |
parent 24147 | edc90be09ac1 |
child 35274 | 1cb90bbbf45e |
permissions | -rw-r--r-- |
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 |
|
13798 | 6 |
header{*Common Declarations for Chandy and Charpentier's Allocator*} |
7 |
||
18556 | 8 |
theory AllocBase imports "../UNITY_Main" begin |
11194
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
9 |
|
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
10 |
consts |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
11 |
NbT :: nat (*Number of tokens in system*) |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
12 |
Nclients :: nat (*Number of clients*) |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
13 |
|
13798 | 14 |
axioms |
15 |
NbT_pos: "0 < NbT" |
|
11194
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
16 |
|
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
17 |
(*This function merely sums the elements of a list*) |
13798 | 18 |
consts tokens :: "nat list => nat" |
11194
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
19 |
primrec |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
20 |
"tokens [] = 0" |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
21 |
"tokens (x#xs) = x + tokens xs" |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
22 |
|
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
23 |
consts |
13798 | 24 |
bag_of :: "'a list => 'a multiset" |
11194
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
25 |
|
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
26 |
primrec |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
27 |
"bag_of [] = {#}" |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
28 |
"bag_of (x#xs) = {#x#} + bag_of xs" |
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
29 |
|
13798 | 30 |
lemma setsum_fun_mono [rule_format]: |
31 |
"!!f :: nat=>nat. |
|
32 |
(ALL i. i<n --> f i <= g i) --> |
|
33 |
setsum f (lessThan n) <= setsum g (lessThan n)" |
|
34 |
apply (induct_tac "n") |
|
35 |
apply (auto simp add: lessThan_Suc) |
|
36 |
done |
|
37 |
||
38 |
lemma tokens_mono_prefix [rule_format]: |
|
39 |
"ALL xs. xs <= ys --> tokens xs <= tokens ys" |
|
40 |
apply (induct_tac "ys") |
|
41 |
apply (auto simp add: prefix_Cons) |
|
42 |
done |
|
43 |
||
44 |
lemma mono_tokens: "mono tokens" |
|
45 |
apply (unfold mono_def) |
|
46 |
apply (blast intro: tokens_mono_prefix) |
|
47 |
done |
|
48 |
||
49 |
||
50 |
(** bag_of **) |
|
51 |
||
52 |
lemma bag_of_append [simp]: "bag_of (l@l') = bag_of l + bag_of l'" |
|
53 |
apply (induct_tac "l", simp) |
|
14738 | 54 |
apply (simp add: add_ac) |
13798 | 55 |
done |
56 |
||
57 |
lemma mono_bag_of: "mono (bag_of :: 'a list => ('a::order) multiset)" |
|
58 |
apply (rule monoI) |
|
59 |
apply (unfold prefix_def) |
|
60 |
apply (erule genPrefix.induct, auto) |
|
61 |
apply (simp add: union_le_mono) |
|
62 |
apply (erule order_trans) |
|
63 |
apply (rule union_upper1) |
|
64 |
done |
|
65 |
||
66 |
(** setsum **) |
|
67 |
||
68 |
declare setsum_cong [cong] |
|
69 |
||
70 |
lemma bag_of_sublist_lemma: |
|
15074 | 71 |
"(\<Sum>i\<in> A Int lessThan k. {#if i<k then f i else g i#}) = |
72 |
(\<Sum>i\<in> A Int lessThan k. {#f i#})" |
|
14114 | 73 |
by (rule setsum_cong, auto) |
13798 | 74 |
|
75 |
lemma bag_of_sublist: |
|
76 |
"bag_of (sublist l A) = |
|
15074 | 77 |
(\<Sum>i\<in> A Int lessThan (length l). {# l!i #})" |
13798 | 78 |
apply (rule_tac xs = l in rev_induct, simp) |
79 |
apply (simp add: sublist_append Int_insert_right lessThan_Suc nth_append |
|
14738 | 80 |
bag_of_sublist_lemma add_ac) |
13798 | 81 |
done |
82 |
||
83 |
||
84 |
lemma bag_of_sublist_Un_Int: |
|
85 |
"bag_of (sublist l (A Un B)) + bag_of (sublist l (A Int B)) = |
|
86 |
bag_of (sublist l A) + bag_of (sublist l B)" |
|
15045 | 87 |
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
|
88 |
(A Int {..<length l}) Int (B Int {..<length l}) ") |
13798 | 89 |
apply (simp add: bag_of_sublist Int_Un_distrib2 setsum_Un_Int, blast) |
90 |
done |
|
91 |
||
92 |
lemma bag_of_sublist_Un_disjoint: |
|
93 |
"A Int B = {} |
|
94 |
==> bag_of (sublist l (A Un B)) = |
|
95 |
bag_of (sublist l A) + bag_of (sublist l B)" |
|
14114 | 96 |
by (simp add: bag_of_sublist_Un_Int [symmetric]) |
13798 | 97 |
|
98 |
lemma bag_of_sublist_UN_disjoint [rule_format]: |
|
99 |
"[| finite I; ALL i:I. ALL j:I. i~=j --> A i Int A j = {} |] |
|
100 |
==> bag_of (sublist l (UNION I A)) = |
|
15074 | 101 |
(\<Sum>i\<in>I. bag_of (sublist l (A i)))" |
13798 | 102 |
apply (simp del: UN_simps |
103 |
add: UN_simps [symmetric] add: bag_of_sublist) |
|
104 |
apply (subst setsum_UN_disjoint, auto) |
|
105 |
done |
|
106 |
||
11194
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff
changeset
|
107 |
end |