src/HOL/UNITY/AllocImpl.ML
author paulson
Tue, 20 Jun 2000 11:52:38 +0200
changeset 9091 8ae7a2e5119b
parent 9027 daeccd9f885f
child 9106 0fe9200f64bd
permissions -rw-r--r--
another brick in the wall
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9027
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/AllocImpl
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     2
    ID:         $Id$
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     4
    Copyright   2000  University of Cambridge
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     5
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     6
Implementation of a multiple-client allocator from a single-client allocator
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     7
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     8
add_path "../Induct";
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
     9
time_use_thy "AllocImpl";
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    10
*)
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    11
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    12
AddIs [impOfSubs subset_preserves_o];
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    13
Addsimps [funPair_o_distrib];
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    14
Addsimps [Always_INT_distrib];
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    15
Delsimps [o_apply];
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    16
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    17
(*Eliminate the "o" operator*)
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    18
val o_simp = simplify (simpset() addsimps [o_def]);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    19
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    20
Goalw [merge_spec_def,merge_eqOut_def]
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    21
     "[| M: merge_spec; G: preserves merge.Out; G: preserves merge.iOut |] \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    22
\ ==> M Join G : Always {s. length (merge.Out s) = length (merge.iOut s)}";  
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    23
by (force_tac (claset() addDs [guaranteesD], simpset()) 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    24
qed "Merge_Always_Out_eq_iOut";
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    25
9091
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    26
(*******ALLOCBASE.ML***)
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    27
Goal "[| finite A; finite B; A Int B = {} |] \
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    28
\     ==> bag_of (sublist l (A Un B)) = \
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    29
\         bag_of (sublist l A) + bag_of (sublist l B)"; 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    30
by (asm_simp_tac (simpset() addsimps [bag_of_sublist_Un_Int RS sym]) 1);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    31
qed "bag_of_sublist_Un_disjoint";
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    32
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    33
Goal "[| finite I;  ALL i:I. finite (A i);     \
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    34
\        ALL i:I. ALL j:I. A i Int A j = {} |] \
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    35
\     ==> bag_of (sublist l (UNION I A)) =  \
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    36
\         setsum (%i. bag_of (sublist l (A i))) I";  
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    37
by (asm_simp_tac (simpset() addcongs [setsum_cong]
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    38
			    addsimps [bag_of_sublist, setsum_UN_disjoint]) 1);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    39
qed_spec_mp "bag_of_sublist_UN_disjoint";
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    40
9027
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    41
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    42
Goal "M : merge_spec \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    43
\ ==> M : (INT i: lessThan Nclients. Increasing (sub i o merge.In)) \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    44
\             guarantees[funPair merge.Out merge.iOut]  \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    45
\                (bag_of o merge.Out) Fols \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    46
\                (%s. setsum (%i. (bag_of o sub i o merge.In) s) \
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    47
\                            (lessThan Nclients))";
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    48
by (rtac guaranteesI 1);
9091
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    49
by (res_inst_tac 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    50
    [("f", "%s. setsum (%i. bag_of (sublist (merge.Out s) 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    51
                                    {k. k < size(merge.iOut s) & 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    52
                                        nth(merge.iOut s)k = i}))
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    53
                       (lessThan Nclients)")] 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    54
    Always_Follows 1);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    55
by (rtac UNIV_AlwaysI 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    56
by (Clarify_tac 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    57
by (stac (bag_of_sublist_UN_disjoint RS sym) 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    58
by (force_tac (claset(), simpset() addsimps []) 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    59
by (blast_tac (claset() addIs [bounded_nat_set_is_finite]) 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    60
by (Clarify_tac 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    61
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    62
by (simp_tac (simpset() addsimps [o_def]) 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    63
by (asm_full_simp_tac (simpset() delsimps [sublist_upt_eq_take]
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    64
                                 addsimps [bag_of_sublist]) 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    65
by (rtac Follows_trans 1); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    66
by (rtac Follows_setsum 2);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    67
by (asm_full_simp_tac (simpset() addsimps []) 3);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    68
by (Clarify_tac 2); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    69
by (asm_full_simp_tac (simpset() addsimps [o_assoc RS sym]) 2); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    70
by (rtac (impOfSubs (mono_bag_of RS mono_Follows_o)) 2);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    71
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    72
(*Now need to invoke the merge_follows guarantee*)
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    73
 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    74
by (asm_full_simp_tac (simpset() addsimps [merge_spec_def,merge_follows_def]) 2); 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    75
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    76
9027
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    77
by (res_inst_tac [("f", "%s. bag_of (sublist (merge.Out s) {..length(merge.iOut s)(})")] 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    78
                  Always_Follows 1);
9091
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    79
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    80
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    81
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    82
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    83
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    84
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    85
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    86
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    87
by (rtac guaranteesI 1);
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    88
by (res_inst_tac 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    89
    [("f", "%s. bag_of (sublist (merge.Out s) {..length(merge.iOut s)(})")] 
8ae7a2e5119b another brick in the wall
paulson
parents: 9027
diff changeset
    90
    Always_Follows 1);
9027
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    91
by (etac (Merge_Always_Out_eq_iOut RS Always_Compl_Un_eq RS iffD1) 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    92
by (force_tac (claset() addIs [UNIV_AlwaysI], simpset() addsimps [o_apply]) 3);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    93
by (Asm_full_simp_tac 1); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    94
by (Asm_full_simp_tac 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    95
by (asm_full_simp_tac (simpset() delsimps [sublist_upt_eq_take]
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    96
                                 addsimps [bag_of_sublist]) 1); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    97
by (rtac Follows_trans 1); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    98
by (rtac Follows_setsum 2);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
    99
by (asm_full_simp_tac (simpset() addsimps []) 3);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   100
by (Clarify_tac 2); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   101
by (asm_full_simp_tac (simpset() addsimps [o_assoc RS sym]) 2); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   102
by (rtac (impOfSubs (mono_bag_of RS mono_Follows_o)) 2);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   103
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   104
(*Now need to invoke the merge_follows guarantee*)
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   105
 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   106
by (asm_full_simp_tac (simpset() addsimps [merge_spec_def,merge_follows_def]) 2); 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   107
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   108
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   109
by (res_inst_tac [("f", "%s. bag_of (sublist (merge.Out s) {..length(merge.iOut s)(})")] 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   110
                  Always_Follows 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   111
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   112
setsum (%i. if i < length l then {# nth l i #} else {#}) {..length (iOut s)(}
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   113
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   114
             : (%s. bag_of
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   115
                     (sublist (merge.Out s) {..length (iOut s)(})) Fols
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   116
               (%s. setsum (%i. (bag_of o sub i o merge.In) s)
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   117
                     {..Nclients(})
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   118
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   119
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   120
	  (%s. sublist (merge.Out s) 
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   121
                       {k. k < size(merge.iOut s) & nth(merge.iOut s)k = i})
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   122
	  Fols (sub i o merge.In))"
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   123
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   124
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   125
by Auto_tac;
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   126
by (dtac guaranteesD 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   127
by Auto_tac;
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   128
by (rtac guaranteesI 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   129
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   130
merge_eqOut
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   131
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   132
Always_Int_eq
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   133
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   134
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   135
by (simp_tac (simpset() addsimps [o_def]) 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   136
by (subgoal_tac
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   137
    "ALL s. merge.Out s = sublist (merge.Out s) {..length(merge.iOut s)(}" 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   138
by (etac ssubst 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   139
by (asm_simp_tac (simpset() addsimps [bag_of_sublist]) 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   140
by (stac bag_of_sublist 1);
daeccd9f885f The Allocator Implementation (not yet working)
paulson
parents:
diff changeset
   141