src/HOL/UNITY/Alloc.ML
author paulson
Mon, 04 Oct 1999 13:47:28 +0200
changeset 7689 affe0c2fdfbf
parent 7540 8af61a565a4a
child 7826 c6a8b73b6c2a
permissions -rw-r--r--
working snapshot (even Alloc)
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
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    74
(**SHOULD NOT BE NECESSARY: The various injections into the system
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    75
   state need to be treated symmetrically or done automatically*)
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    76
Goalw [sysOfClient_def] "inj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    77
by (rtac injI 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    78
by (auto_tac (claset() addSDs [inj_sysOfAlloc RS injD]
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    79
		       addSWrapper record_split_wrapper, simpset()));
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    80
qed "inj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    81
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    82
Goalw [sysOfClient_def] "surj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    83
by (cut_facts_tac [surj_sysOfAlloc] 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    84
by (rewtac surj_def);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    85
by Auto_tac;
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    86
by (Blast_tac 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    87
qed "surj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    88
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    89
AddIffs [inj_sysOfClient, surj_sysOfClient];
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    90
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    91
Goalw [good_map_def] "good_map sysOfClient";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    92
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    93
qed "good_map_sysOfClient";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
    94
Addsimps [good_map_sysOfClient];
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    95
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    96
(*MUST BE AUTOMATED: even the statement of such results*)
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    97
Goal "!!s. inv sysOfClient s = \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    98
\            (client s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    99
\             (| allocGiv = allocGiv s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   100
\                allocAsk = allocAsk s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   101
\                allocRel = allocRel s|) )";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   102
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
   103
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
   104
	      simpset() addsimps [sysOfAlloc_def, sysOfClient_def]));
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   105
qed "inv_sysOfClient_eq";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   106
Addsimps [inv_sysOfClient_eq];
6837
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   107
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   108
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   109
Open_locale "System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   110
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   111
val Alloc = thm "Alloc";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   112
val Client = thm "Client";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   113
val Network = thm "Network";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   114
val System_def = thm "System_def";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   115
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   116
AddIffs [finite_lessThan];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   117
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   118
(*Client : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   119
val Client_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   120
    rewrite_rule [client_spec_def, client_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   121
		  client_bounded_def, client_progress_def] Client;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   122
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   123
Goal "Client : UNIV guarantees Increasing ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   124
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   125
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   126
qed "Client_Increasing_ask";
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
Goal "Client : UNIV guarantees Increasing rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   129
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   130
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   131
qed "Client_Increasing_rel";
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
AddIffs [Client_Increasing_ask, Client_Increasing_rel];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   134
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   135
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
   136
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   137
by Auto_tac;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   138
qed "Client_Bounded";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   139
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   140
(*Client_Progress is cumbersome to state*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   141
val Client_Progress = Client_Spec RS IntD2;
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   142
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   143
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   144
(*Network : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   145
val Network_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   146
    rewrite_rule [network_spec_def, network_ask_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   147
		  network_giv_def, network_rel_def] Network;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   148
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   149
(*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
   150
  exporting it from the locale*)
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   151
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
   152
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
   153
val Network_Rel = Network_Spec RS IntD2 RS INT_D;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   154
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   155
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   156
(*Alloc : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   157
val Alloc_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   158
    rewrite_rule [alloc_spec_def, alloc_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   159
		  alloc_safety_def, alloc_progress_def] Alloc;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   160
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   161
Goal "i < Nclients ==> Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   162
by (cut_facts_tac [Alloc_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   163
by (asm_full_simp_tac (simpset() addsimps [guarantees_INT_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   164
qed "Alloc_Increasing";
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
val Alloc_Safety = Alloc_Spec RS IntD1 RS IntD2;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   167
val Alloc_Progress = (Alloc_Spec RS IntD2
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   168
                      |> simplify (simpset() addsimps [guarantees_INT_right]))
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   169
                     RS bspec RS spec;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   170
		     
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   171
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   172
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   173
(*Not sure what to say about the other components because they involve
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   174
  extend*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   175
Goalw [System_def] "Network <= System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   176
by (blast_tac (claset() addIs [componentI]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   177
qed "Network_component_System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   178
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   179
Goalw [System_def] "(extend sysOfAlloc Alloc) <= System";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   180
by (blast_tac (claset() addIs [componentI]) 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   181
qed "Alloc_component_System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   182
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   183
AddIffs [Network_component_System, Alloc_component_System];
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   184
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   185
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   186
fun alloc_export th = good_map_sysOfAlloc RS export th;
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   187
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   188
fun client_export th = good_map_sysOfClient RS export th;
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   189
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   190
(* F : UNIV guarantees Increasing func
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   191
   ==> 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
   192
val extend_Client_guar_Increasing =
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   193
  client_export extend_guar_Increasing
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   194
  |> simplify (simpset() addsimps [inv_sysOfClient_eq]);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   195
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   196
(*NEED AUTOMATIC PROPAGATION of Alloc_Increasing*)
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   197
Goal "i < Nclients \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   198
\ ==> extend sysOfAlloc Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   199
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
   200
by (auto_tac (claset(), simpset() addsimps [o_def]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   201
qed "extend_Alloc_Increasing_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   202
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   203
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   204
(*** Proof of the safety property (1) ***)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   205
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   206
(*safety (1), step 1*)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   207
Goalw [System_def]
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   208
     "i < Nclients ==> System : Increasing (rel o sub i o client)";
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   209
by (rtac (extend_Client_guar_Increasing RS guarantees_Join_I2 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   210
	  RS guaranteesD) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   211
by (rtac (lift_prog_guar_Increasing RS guarantees_PLam_I) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   212
(*gets Client_Increasing_rel from simpset*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   213
by Auto_tac;
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   214
qed "System_Increasing_rel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   215
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   216
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   217
(*safety (1), step 2*)
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   218
Goal "i < Nclients ==> System : Increasing (sub i o allocRel)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   219
by (rtac Follows_Increasing1 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   220
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
   221
			       System_Increasing_rel]) 1);
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   222
qed "System_Increasing_allocRel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   223
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   224
(*safety (1), step 3*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   225
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
   226
\                  <= 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
   227
by (res_inst_tac 
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   228
    [("X", "(INT i : lessThan Nclients. Increasing (sub i o allocRel))")] 
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   229
    component_guaranteesD 1);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   230
by (rtac Alloc_component_System 3);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   231
by (force_tac (claset(), simpset() addsimps [System_Increasing_allocRel]) 2);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   232
by (rtac (Alloc_Safety RS project_guarantees) 1);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   233
by Auto_tac;
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   234
(*1: Increasing precondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   235
by (stac (alloc_export project_Increasing) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   236
by (force_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   237
    (claset(),
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   238
     simpset() addsimps [o_def, alloc_export project_Increasing]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   239
(*2: Always postcondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   240
by (dtac (subset_refl RS alloc_export project_Always_D) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   241
by (asm_full_simp_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   242
     (simpset() addsimps [alloc_export Collect_eq_extend_set RS sym]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   243
qed "System_sum_bounded";
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   244
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   245
(*safety (1), step 4*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   246
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   247
\                         {s. (tokens o giv o sub i o client) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   248
\                          <= (tokens o sub i o allocGiv) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   249
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   250
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   251
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   252
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   253
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
   254
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
   255
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   256
by (blast_tac (claset() addIs [Network_Giv RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   257
	  extend_Alloc_Increasing_allocGiv RS component_guaranteesD]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   258
qed "System_Always_giv_le_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   259
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   260
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   261
(*safety (1), step 5*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   262
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   263
\                         {s. (tokens o sub i o allocRel) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   264
\                          <= (tokens o rel o sub i o client) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   265
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   266
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   267
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   268
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   269
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
   270
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
   271
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   272
by (blast_tac (claset() addIs [Network_Rel RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   273
			       System_Increasing_rel]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   274
qed "System_Always_allocRel_le_rel";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   275
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   276
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   277
(*safety (1), step 6*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   278
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
   279
\              <= 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
   280
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
   281
			   System_Always_allocRel_le_rel] RS Always_weaken) 1);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   282
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   283
by (rtac (sum_mono RS order_trans) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   284
by (dtac order_trans 2);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   285
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
   286
by (assume_tac 3);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   287
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   288
qed "System_safety";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   289
7689
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   290
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   291
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   292
(*** Proof of the progress property (2) ***)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   293
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   294
(*we begin with proofs identical to System_Increasing_rel and
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   295
  System_Increasing_allocRel: tactics needed!*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   296
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   297
(*progress (2), step 1*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   298
Goalw [System_def]
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   299
     "i < Nclients ==> System : Increasing (ask o sub i o client)";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   300
by (rtac (extend_Client_guar_Increasing RS guarantees_Join_I2 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   301
	  RS guaranteesD) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   302
by (rtac (lift_prog_guar_Increasing RS guarantees_PLam_I) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   303
by Auto_tac;
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   304
qed "System_Increasing_ask";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   305
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   306
(*progress (2), step 2*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   307
Goal "i < Nclients ==> System : Increasing (sub i o allocAsk)";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   308
by (rtac Follows_Increasing1 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   309
by (blast_tac (claset() addIs [Network_Ask RS component_guaranteesD,
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   310
			       System_Increasing_ask]) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   311
qed "System_Increasing_allocAsk";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   312
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   313
(*progress (2), step 3*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   314
(*All this trouble just to lift "Client_Bounded" through two extemd ops*)
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   315
Goalw [System_def]
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   316
     "i < Nclients \
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   317
\   ==> System : Always \
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   318
\                 {s. ALL elt : set ((ask o sub i o client) s). elt <= NbT}";
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   319
by (rtac (lift_prog_guar_Always RS 
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   320
	  guarantees_PLam_I RS client_export extend_guar_Always RS
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   321
	  guarantees_Join_I2 RS guaranteesD RS Always_weaken) 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   322
by (stac Always_UNIV_eq 1 THEN rtac Client_Bounded 1);
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   323
by (auto_tac(claset(),
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   324
	 simpset() addsimps [Collect_eq_lift_set RS sym,
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   325
			     client_export Collect_eq_extend_set RS sym]));
affe0c2fdfbf working snapshot (even Alloc)
paulson
parents: 7540
diff changeset
   326
qed "System_Bounded";