src/HOL/UNITY/Alloc.ML
author paulson
Sun, 13 Jun 1999 13:57:31 +0200
changeset 6828 ea6832d74353
parent 6815 de4d358bf01e
child 6837 1bd850260747
permissions -rw-r--r--
not working but taking shape
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     1
(*  Title:      HOL/UNITY/Alloc
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     2
    ID:         $Id$
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     4
    Copyright   1998  University of Cambridge
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     5
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     6
Specification of Chandy and Charpentier's Allocator
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     7
*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     8
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     9
Addsimps [sub_def];
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    10
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    11
Goalw [sysOfAlloc_def] "inj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    12
by (rtac injI 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    13
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    14
qed "inj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    15
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    16
Goalw [sysOfAlloc_def] "surj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    17
by (res_inst_tac [("f", "%s. ((| allocGiv = allocGiv s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    18
\                                allocAsk = allocAsk s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    19
\                                allocRel = allocRel s |), \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    20
\                             client s)")] surjI 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    21
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    22
qed "surj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    23
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    24
AddIffs [inj_sysOfAlloc, surj_sysOfAlloc];
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    25
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    26
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    27
Open_locale "System";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    28
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    29
val Alloc = thm "Alloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    30
val Client = thm "Client";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    31
val Network = thm "Network";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    32
val System_def = thm "System_def";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    33
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    34
AddIffs [finite_lessThan];
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    35
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    36
(*could move to PPROD.ML, but function "sub" is needed there*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    37
Goal "lift_set i {s. P (f s)} = {s. P (f (sub i s))}";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    38
by (asm_simp_tac (simpset() addsimps [lift_set_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    39
qed "lift_set_sub";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    40
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    41
(*ONE OF THESE IS REDUNDANT!*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    42
Goal "lift_set i {s. P (f s)} = {s. P (f (s i))}";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    43
by (asm_simp_tac (simpset() addsimps [lift_set_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    44
qed "lift_set_sub2";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    45
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    46
Goalw [Increasing_def]
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    47
     "[| i: I;  finite I |]  \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    48
\     ==> ((PPI x:I. F) : Increasing (f o sub i)) = (F : Increasing f)";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    49
by (subgoal_tac "ALL z. {s. z <= (f o sub i) s} = lift_set i {s. z <= f s}" 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    50
by (asm_simp_tac (simpset() addsimps [lift_set_sub]) 2);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    51
by (asm_full_simp_tac (simpset() addsimps [PFUN_Stable]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    52
qed "PFUN_Increasing";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    53
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    54
(*FUN.ML*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    55
(*left-to-right inclusion holds even if I is empty*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    56
Goalw [inj_on_def]
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    57
   "[| inj_on f C;  ALL i:I. B i <= C;  j:I |] \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    58
\   ==> f `` (INT i:I. B i) = (INT i:I. f `` B i)";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    59
by (Blast_tac 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    60
qed "inj_on_image_INT";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    61
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    62
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    63
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    64
Goal "lift_prog i `` Increasing f <= Increasing (f o sub i)";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    65
by (asm_simp_tac 
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    66
    (simpset() addsimps [Increasing_def,
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    67
			 inj_lift_prog RS inj_on_image_INT]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    68
auto();
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    69
by (dres_inst_tac [("x","z")] spec 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    70
auto();
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    71
by (asm_simp_tac (simpset() addsimps [lift_set_sub2 RS sym,
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    72
				      lift_prog_Stable_eq]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    73
qed "image_lift_prog_Increasing";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    74
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    75
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    76
Goal "i < Nclients ==> \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    77
\     lift_prog i Client : range (lift_prog i) guar Increasing (rel o sub i)";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    78
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    79
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    80
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    81
Goal "i < Nclients ==> System : Increasing (sub i o allocRel)";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    82
by (cut_facts_tac [Client] 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    83
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    84
    (simpset() addsimps [System_def,
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    85
			 client_spec_def, client_increasing_def,
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    86
			 guarantees_Int_right]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    87
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    88
by (dtac lift_prog_guarantees 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    89
by (dtac (UNIV_I RSN (2, guaranteesD)) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    90
back();
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    91
by (dtac (lessThan_iff RS iffD2 RS PFUN_Increasing RS iffD2) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    92
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    93
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    94
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    95
by (full_simp_tac (simpset() addsimps [read_instantiate [("f1","rel"),("I1","lessThan Nclients")] (PFUN_Increasing RS sym)]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    96
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    97
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    98
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    99
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   100
Goal "System : system_spec";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   101
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   102
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   103
    (simpset() addsimps [alloc_spec_def, alloc_safety_def, System_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   104
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   105
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   106
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   107
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   108
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   109
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   110
(*partial system...*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   111
Goal "[| Alloc : alloc_spec;  Network : network_spec |] \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   112
\     ==> (extend sysOfAlloc Alloc) Join Network : system_spec";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   113
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   114
(*partial system...*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   115
Goal "[| Client : client_spec;  Network : network_spec |] \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   116
\     ==> (extend sysOfClient (PPI x: lessThan Nclients. Client)) \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   117
\         Join Network : system_spec";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   118
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   119
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   120
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   121
Goal "[| Alloc : alloc_spec;  Client : client_spec;  \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   122
\        Network : network_spec |] \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   123
\     ==> (extend sysOfAlloc Alloc) \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   124
\         Join (extend sysOfClient (PPI x: lessThan Nclients. Client)) \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   125
\         Join Network : system_spec";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   126
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   127
    (simpset() addsimps [system_spec_def, system_safety_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   128
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   129
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   130
    (simpset() addsimps [client_spec_def, client_increasing_def,
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   131
			 guarantees_Int_right]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   132
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   133
by (dtac (UNIV_I RSN (2, guaranteesD)) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   134
back();
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   135
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   136
    (simpset() addsimps [network_spec_def, network_rel_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   137
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   138
by (subgoal_tac "" 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   139
by (full_simp_tac
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   140
    (simpset() addsimps [alloc_spec_def, alloc_safety_def]) 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   141
by Auto_tac;
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   142
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   143
by (Simp_tac 1);
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   144
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   145
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   146
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   147
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   148
(*Generalized version allowing different clients*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   149
Goal "[| Alloc : alloc_spec;  \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   150
\        Client : (lessThan Nclients) funcset client_spec;  \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   151
\        Network : network_spec |] \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   152
\     ==> (extend sysOfAlloc Alloc) \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   153
\         Join (extend sysOfClient (PPROD (lessThan Nclients) Client)) \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   154
\         Join Network : system_spec";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   155