src/HOL/UNITY/Alloc.ML
author paulson
Mon, 11 Oct 1999 10:53:39 +0200
changeset 7826 c6a8b73b6c2a
parent 7689 affe0c2fdfbf
child 7841 65d91d13fc13
permissions -rw-r--r--
working shapshot with "projecting" and "extending"
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
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
     7
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
     8
STOP USING o (COMPOSITION), since function application is naturally associative
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
     9
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
    10
guarantees_PLam_I looks wrong: refers to lift_prog
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    11
*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    12
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    13
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    14
Goal "(ALL i: lessThan n. f i <= g i) --> sum f n <= sum g n";
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    15
by (induct_tac "n" 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    16
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    17
by (dres_inst_tac [("x","n")] bspec 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    18
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    19
by (arith_tac 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    20
qed_spec_mp "sum_mono";
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    21
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    22
Goal "ALL xs. xs <= ys --> tokens xs <= tokens ys";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    23
by (induct_tac "ys" 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    24
by (auto_tac (claset(), simpset() addsimps [prefix_Cons]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    25
qed_spec_mp "tokens_mono_prefix";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    26
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    27
Goalw [mono_def] "mono tokens";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    28
by (blast_tac (claset() addIs [tokens_mono_prefix]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    29
qed "mono_tokens";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    30
6840
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    31
(*Generalized version allowing different clients*)
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    32
Goal "[| Alloc : alloc_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    33
\        Client : (lessThan Nclients) funcset client_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    34
\        Network : network_spec |] \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    35
\     ==> (extend sysOfAlloc Alloc) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    36
\         Join (extend sysOfClient (PLam (lessThan Nclients) Client)) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    37
\         Join Network : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    38
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    39
Goal "System : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    40
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    41
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    42
Goalw [sysOfAlloc_def] "inj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    43
by (rtac injI 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    44
by (auto_tac (claset() addSWrapper record_split_wrapper, simpset()));
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    45
qed "inj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    46
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    47
Goalw [sysOfAlloc_def] "surj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    48
by (res_inst_tac [("f", "%s. ((| allocGiv = allocGiv s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    49
\                                allocAsk = allocAsk s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    50
\                                allocRel = allocRel s |), \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    51
\                             client s)")] surjI 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    52
by (auto_tac (claset() addSWrapper record_split_wrapper, simpset()));
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    53
qed "surj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    54
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    55
AddIffs [inj_sysOfAlloc, surj_sysOfAlloc];
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    56
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    57
Goalw [good_map_def] "good_map sysOfAlloc";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    58
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    59
qed "good_map_sysOfAlloc";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
    60
Addsimps [good_map_sysOfAlloc];
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    61
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    62
(*MUST BE AUTOMATED: even the statement of such results*)
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    63
Goal "!!s. inv sysOfAlloc s = \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    64
\            ((| allocGiv = allocGiv s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    65
\                allocAsk = allocAsk s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    66
\                allocRel = allocRel s|), \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    67
\             client s)";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    68
by (rtac (inj_sysOfAlloc RS inv_f_eq) 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    69
by (auto_tac (claset() addSWrapper record_split_wrapper, 
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    70
	      simpset() addsimps [sysOfAlloc_def]));
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    71
qed "inv_sysOfAlloc_eq";
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    72
Addsimps [inv_sysOfAlloc_eq];
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    73
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    74
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    75
(*SHOULD NOT BE NECESSARY????????????????
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    76
Goal "!!z. (| allocGiv = allocGiv z, allocAsk = allocAsk z, \
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    77
\             allocRel = allocRel z |) = z";
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    78
by (auto_tac (claset() addSWrapper record_split_wrapper, 
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    79
	      simpset()));
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    80
qed "allocState_eq";
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    81
Addsimps [allocState_eq];
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    82
????*)
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
    83
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    84
(**SHOULD NOT BE NECESSARY: The various injections into the system
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    85
   state need to be treated symmetrically or done automatically*)
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    86
Goalw [sysOfClient_def] "inj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    87
by (rtac injI 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    88
by (auto_tac (claset() addSDs [inj_sysOfAlloc RS injD]
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    89
		       addSWrapper record_split_wrapper, simpset()));
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    90
qed "inj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    91
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    92
Goalw [sysOfClient_def] "surj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    93
by (cut_facts_tac [surj_sysOfAlloc] 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    94
by (rewtac surj_def);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    95
by Auto_tac;
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    96
by (Blast_tac 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    97
qed "surj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    98
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    99
AddIffs [inj_sysOfClient, surj_sysOfClient];
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   100
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   101
Goalw [good_map_def] "good_map sysOfClient";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   102
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   103
qed "good_map_sysOfClient";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   104
Addsimps [good_map_sysOfClient];
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   105
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   106
(*MUST BE AUTOMATED: even the statement of such results*)
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   107
Goal "!!s. inv sysOfClient s = \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   108
\            (client s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   109
\             (| allocGiv = allocGiv s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   110
\                allocAsk = allocAsk s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   111
\                allocRel = allocRel s|) )";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   112
by (rtac (inj_sysOfClient RS inv_f_eq) 1);
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   113
by (auto_tac (claset() addSWrapper record_split_wrapper, 
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   114
	      simpset() addsimps [sysOfAlloc_def, sysOfClient_def]));
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   115
qed "inv_sysOfClient_eq";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   116
Addsimps [inv_sysOfClient_eq];
6837
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   117
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   118
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   119
Open_locale "System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   120
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   121
val Alloc = thm "Alloc";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   122
val Client = thm "Client";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   123
val Network = thm "Network";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   124
val System_def = thm "System_def";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   125
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   126
AddIffs [finite_lessThan];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   127
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   128
(*Client : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   129
val Client_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   130
    rewrite_rule [client_spec_def, client_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   131
		  client_bounded_def, client_progress_def] Client;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   132
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   133
Goal "Client : UNIV guarantees Increasing ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   134
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   135
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   136
qed "Client_Increasing_ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   137
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   138
Goal "Client : UNIV guarantees Increasing rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   139
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   140
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   141
qed "Client_Increasing_rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   142
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   143
AddIffs [Client_Increasing_ask, Client_Increasing_rel];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   144
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   145
Goal "Client : UNIV guarantees Always {s. ALL elt : set (ask s). elt <= NbT}";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   146
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   147
by Auto_tac;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   148
qed "Client_Bounded";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   149
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   150
(*Client_Progress is cumbersome to state*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   151
val Client_Progress = Client_Spec RS IntD2;
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   152
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   153
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   154
(*Network : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   155
val Network_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   156
    rewrite_rule [network_spec_def, network_ask_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   157
		  network_giv_def, network_rel_def] Network;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   158
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   159
(*CANNOT use bind_thm: it puts the theorem into standard form, in effect
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   160
  exporting it from the locale*)
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   161
val Network_Ask = Network_Spec RS IntD1 RS IntD1 RS INT_D;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   162
val Network_Giv = Network_Spec RS IntD1 RS IntD2 RS INT_D;
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   163
val Network_Rel = Network_Spec RS IntD2 RS INT_D;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   164
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   165
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   166
(*Alloc : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   167
val Alloc_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   168
    rewrite_rule [alloc_spec_def, alloc_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   169
		  alloc_safety_def, alloc_progress_def] Alloc;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   170
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   171
Goal "i < Nclients ==> Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   172
by (cut_facts_tac [Alloc_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   173
by (asm_full_simp_tac (simpset() addsimps [guarantees_INT_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   174
qed "Alloc_Increasing";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   175
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   176
val Alloc_Safety = Alloc_Spec RS IntD1 RS IntD2;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   177
val Alloc_Progress = (Alloc_Spec RS IntD2
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   178
                      |> simplify (simpset() addsimps [guarantees_INT_right]))
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   179
                     RS bspec RS spec;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   180
		     
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   181
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   182
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   183
(*Not sure what to say about the other components because they involve
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   184
  extend*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   185
Goalw [System_def] "Network <= System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   186
by (blast_tac (claset() addIs [componentI]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   187
qed "Network_component_System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   188
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   189
Goalw [System_def] "(extend sysOfAlloc Alloc) <= System";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   190
by (blast_tac (claset() addIs [componentI]) 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   191
qed "Alloc_component_System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   192
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   193
AddIffs [Network_component_System, Alloc_component_System];
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   194
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   195
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   196
fun alloc_export th = good_map_sysOfAlloc RS export th |> simplify (simpset());
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   197
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   198
fun client_export th = good_map_sysOfClient RS export th |> simplify (simpset());
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   199
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   200
(* F : UNIV guarantees Increasing func
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   201
   ==> extend sysOfClient F : UNIV guarantees Increasing (func o client) *)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   202
val extend_Client_guar_Increasing =
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   203
  client_export extend_guar_Increasing;
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   204
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   205
(*NEED AUTOMATIC PROPAGATION of Alloc_Increasing*)
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   206
Goal "i < Nclients \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   207
\ ==> extend sysOfAlloc Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   208
by (dtac (Alloc_Increasing RS alloc_export extend_guar_Increasing) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   209
by (auto_tac (claset(), simpset() addsimps [o_def]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   210
qed "extend_Alloc_Increasing_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   211
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   212
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   213
(*** Proof of the safety property (1) ***)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   214
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   215
(*safety (1), step 1*)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   216
Goalw [System_def]
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   217
     "i < Nclients ==> System : Increasing (rel o sub i o client)";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   218
by (rtac (extend_Client_guar_Increasing RS guarantees_Join_I2 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   219
	  RS guaranteesD) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   220
by (rtac (lift_prog_guar_Increasing RS guarantees_PLam_I) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   221
(*gets Client_Increasing_rel from simpset*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   222
by Auto_tac;
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   223
qed "System_Increasing_rel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   224
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   225
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   226
(*safety (1), step 2*)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   227
Goal "i < Nclients ==> System : Increasing (sub i o allocRel)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   228
by (rtac Follows_Increasing1 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   229
by (blast_tac (claset() addIs [Network_Rel RS component_guaranteesD,
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   230
			       System_Increasing_rel]) 1);
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   231
qed "System_Increasing_allocRel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   232
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   233
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   234
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   235
(*safety (1), step 3*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   236
Goal "System : Always {s. sum (%i. (tokens o sub i o allocGiv) s) Nclients \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   237
\                  <= NbT + sum (%i. (tokens o sub i o allocRel) s) Nclients}";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   238
by (res_inst_tac 
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   239
    [("X", "(INT i : lessThan Nclients. Increasing (sub i o allocRel))")] 
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   240
    component_guaranteesD 1);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   241
by (rtac Alloc_component_System 3);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   242
by (force_tac (claset(), simpset() addsimps [System_Increasing_allocRel]) 2);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   243
by (rtac (Alloc_Safety RS project_guarantees) 1);
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   244
(*1: Increasing precondition*)
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   245
br (ballI RS projecting_INT) 1;
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   246
by (rtac (alloc_export projecting_Increasing RS projecting_weaken) 1);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   247
by Auto_tac;
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   248
by (asm_full_simp_tac (simpset() addsimps [o_def]) 1);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   249
(*2: Always postcondition*)
7826
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   250
by (rtac ((alloc_export extending_Always RS extending_weaken)) 1);
c6a8b73b6c2a working shapshot with "projecting" and "extending"
paulson
parents: 7689
diff changeset
   251
by Auto_tac;
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   252
by (asm_full_simp_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   253
     (simpset() addsimps [alloc_export Collect_eq_extend_set RS sym]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   254
qed "System_sum_bounded";
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   255
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   256
(*safety (1), step 4*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   257
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   258
\                         {s. (tokens o giv o sub i o client) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   259
\                          <= (tokens o sub i o allocGiv) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   260
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   261
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   262
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   263
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   264
by (simp_tac (HOL_ss addsimps [o_assoc RS sym]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   265
by (rtac (mono_tokens RS mono_Follows_o RS subsetD) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   266
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   267
by (blast_tac (claset() addIs [Network_Giv RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   268
	  extend_Alloc_Increasing_allocGiv RS component_guaranteesD]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   269
qed "System_Always_giv_le_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   270
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   271
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   272
(*safety (1), step 5*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   273
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   274
\                         {s. (tokens o sub i o allocRel) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   275
\                          <= (tokens o rel o sub i o client) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   276
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   277
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   278
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   279
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   280
by (simp_tac (HOL_ss addsimps [o_assoc RS sym]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   281
by (rtac (mono_tokens RS mono_Follows_o RS subsetD) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   282
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   283
by (blast_tac (claset() addIs [Network_Rel RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   284
			       System_Increasing_rel]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   285
qed "System_Always_allocRel_le_rel";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   286
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   287
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   288
(*safety (1), step 6*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   289
Goal "System : Always {s. sum (%i. (tokens o giv o sub i o client)s) Nclients \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   290
\              <= NbT + sum (%i. (tokens o rel o sub i o client)s) Nclients}";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   291
by (rtac (Always_Int_rule [System_sum_bounded, System_Always_giv_le_allocGiv, 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   292
			   System_Always_allocRel_le_rel] RS Always_weaken) 1);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   293
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   294
by (rtac (sum_mono RS order_trans) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   295
by (dtac order_trans 2);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   296
by (rtac ([order_refl, sum_mono] MRS add_le_mono) 2);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   297
by (assume_tac 3);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   298
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   299
qed "System_safety";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   300
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   301
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   302
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   303
(*** Proof of the progress property (2) ***)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   304
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   305
(*we begin with proofs identical to System_Increasing_rel and
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   306
  System_Increasing_allocRel: tactics needed!*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   307
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   308
(*progress (2), step 1*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   309
Goalw [System_def]
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   310
     "i < Nclients ==> System : Increasing (ask o sub i o client)";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   311
by (rtac (extend_Client_guar_Increasing RS guarantees_Join_I2 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   312
	  RS guaranteesD) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   313
by (rtac (lift_prog_guar_Increasing RS guarantees_PLam_I) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   314
by Auto_tac;
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   315
qed "System_Increasing_ask";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   316
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   317
(*progress (2), step 2*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   318
Goal "i < Nclients ==> System : Increasing (sub i o allocAsk)";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   319
by (rtac Follows_Increasing1 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   320
by (blast_tac (claset() addIs [Network_Ask RS component_guaranteesD,
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   321
			       System_Increasing_ask]) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   322
qed "System_Increasing_allocAsk";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   323
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   324
(*progress (2), step 3*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   325
(*All this trouble just to lift "Client_Bounded" through two extemd ops*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   326
Goalw [System_def]
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   327
     "i < Nclients \
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   328
\   ==> System : Always \
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   329
\                 {s. ALL elt : set ((ask o sub i o client) s). elt <= NbT}";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   330
by (rtac (lift_prog_guar_Always RS 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   331
	  guarantees_PLam_I RS client_export extend_guar_Always RS
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   332
	  guarantees_Join_I2 RS guaranteesD RS Always_weaken) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   333
by (stac Always_UNIV_eq 1 THEN rtac Client_Bounded 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   334
by (auto_tac(claset(),
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   335
	 simpset() addsimps [Collect_eq_lift_set RS sym,
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   336
			     client_export Collect_eq_extend_set RS sym]));
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   337
qed "System_Bounded";