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