src/HOL/UNITY/Alloc.ML
author paulson
Mon, 20 Sep 1999 10:40:40 +0200
changeset 7540 8af61a565a4a
parent 7538 357873391561
child 7689 affe0c2fdfbf
permissions -rw-r--r--
working Safety proof for the system at last
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
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     9
*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    10
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    11
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    12
Goal "~ f #2 ==> ~ (!t::nat. (#0 <= t & t <= #10) --> f t)";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    13
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    14
(*Useful examples:  singletonI RS subst_elem,  subst_elem RSN (2,IntI) *)
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    15
Goal "[| b:A;  a=b |] ==> a:A";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    16
by (etac ssubst 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    17
by (assume_tac 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    18
qed "subst_elem";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    19
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    20
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    21
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    22
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
    23
by (induct_tac "n" 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    24
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    25
by (dres_inst_tac [("x","n")] bspec 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    26
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    27
by (arith_tac 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    28
qed_spec_mp "sum_mono";
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    29
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    30
Goal "ALL xs. xs <= ys --> tokens xs <= tokens ys";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    31
by (induct_tac "ys" 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    32
by (auto_tac (claset(), simpset() addsimps [prefix_Cons]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    33
qed_spec_mp "tokens_mono_prefix";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    34
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    35
Goalw [mono_def] "mono tokens";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    36
by (blast_tac (claset() addIs [tokens_mono_prefix]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
    37
qed "mono_tokens";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    38
6840
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    39
(*Generalized version allowing different clients*)
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    40
Goal "[| Alloc : alloc_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    41
\        Client : (lessThan Nclients) funcset client_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    42
\        Network : network_spec |] \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    43
\     ==> (extend sysOfAlloc Alloc) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    44
\         Join (extend sysOfClient (PLam (lessThan Nclients) Client)) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    45
\         Join Network : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    46
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    47
Goal "System : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    48
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    49
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    50
Goalw [sysOfAlloc_def] "inj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    51
by (rtac injI 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 "inj_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
Goalw [sysOfAlloc_def] "surj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    56
by (res_inst_tac [("f", "%s. ((| allocGiv = allocGiv s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    57
\                                allocAsk = allocAsk s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    58
\                                allocRel = allocRel s |), \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    59
\                             client s)")] surjI 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    60
by (auto_tac (claset() addSWrapper record_split_wrapper, simpset()));
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    61
qed "surj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    62
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    63
AddIffs [inj_sysOfAlloc, surj_sysOfAlloc];
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    64
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    65
Goalw [good_map_def] "good_map sysOfAlloc";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    66
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    67
qed "good_map_sysOfAlloc";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    68
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    69
(*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
    70
Goal "!!s. inv sysOfAlloc s = \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    71
\            ((| allocGiv = allocGiv s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    72
\                allocAsk = allocAsk s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    73
\                allocRel = allocRel s|), \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    74
\             client s)";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    75
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
    76
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
    77
	      simpset() addsimps [sysOfAlloc_def]));
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    78
qed "inv_sysOfAlloc_eq";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    79
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    80
Addsimps [inv_sysOfAlloc_eq];
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    81
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    82
(**SHOULD NOT BE NECESSARY: The various injections into the system
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    83
   state need to be treated symmetrically or done automatically*)
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    84
Goalw [sysOfClient_def] "inj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    85
by (rtac injI 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    86
by (auto_tac (claset() addSDs [inj_sysOfAlloc RS injD]
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    87
		       addSWrapper record_split_wrapper, simpset()));
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    88
qed "inj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    89
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    90
Goalw [sysOfClient_def] "surj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    91
by (cut_facts_tac [surj_sysOfAlloc] 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    92
by (rewtac surj_def);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    93
by Auto_tac;
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    94
by (Blast_tac 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    95
qed "surj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    96
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    97
AddIffs [inj_sysOfClient, surj_sysOfClient];
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    98
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    99
Goalw [good_map_def] "good_map sysOfClient";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   100
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   101
qed "good_map_sysOfClient";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   102
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   103
(*MUST BE AUTOMATED: even the statement of such results*)
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   104
Goal "!!s. inv sysOfClient s = \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   105
\            (client s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   106
\             (| allocGiv = allocGiv s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   107
\                allocAsk = allocAsk s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   108
\                allocRel = allocRel s|) )";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   109
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
   110
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
   111
	      simpset() addsimps [sysOfAlloc_def, sysOfClient_def]));
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   112
qed "inv_sysOfClient_eq";
6837
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   113
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   114
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   115
Open_locale "System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   116
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   117
val Alloc = thm "Alloc";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   118
val Client = thm "Client";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   119
val Network = thm "Network";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   120
val System_def = thm "System_def";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   121
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   122
AddIffs [finite_lessThan];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   123
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   124
(*Client : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   125
val Client_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   126
    rewrite_rule [client_spec_def, client_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   127
		  client_bounded_def, client_progress_def] Client;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   128
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   129
Goal "Client : UNIV guarantees Increasing ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   130
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   131
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   132
qed "Client_Increasing_ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   133
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   134
Goal "Client : UNIV guarantees Increasing rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   135
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   136
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   137
qed "Client_Increasing_rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   138
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   139
AddIffs [Client_Increasing_ask, Client_Increasing_rel];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   140
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   141
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
   142
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   143
by Auto_tac;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   144
qed "Client_Bounded";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   145
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   146
(*Client_Progress is cumbersome to state*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   147
val Client_Progress = Client_Spec RS IntD2;
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   148
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   149
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   150
(*Network : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   151
val Network_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   152
    rewrite_rule [network_spec_def, network_ask_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   153
		  network_giv_def, network_rel_def] Network;
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
(*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
   156
  exporting it from the locale*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   157
val Network_Ask = Network_Spec RS IntD1 RS IntD1;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   158
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
   159
val Network_Rel = Network_Spec RS IntD2 RS INT_D;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   160
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   161
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   162
(*Alloc : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   163
val Alloc_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   164
    rewrite_rule [alloc_spec_def, alloc_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   165
		  alloc_safety_def, alloc_progress_def] Alloc;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   166
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   167
Goal "i < Nclients ==> Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   168
by (cut_facts_tac [Alloc_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   169
by (asm_full_simp_tac (simpset() addsimps [guarantees_INT_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   170
qed "Alloc_Increasing";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   171
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   172
val Alloc_Safety = Alloc_Spec RS IntD1 RS IntD2;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   173
val Alloc_Progress = (Alloc_Spec RS IntD2
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   174
                      |> simplify (simpset() addsimps [guarantees_INT_right]))
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   175
                     RS bspec RS spec;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   176
		     
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   177
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   178
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   179
(*Not sure what to say about the other components because they involve
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   180
  extend*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   181
Goalw [System_def] "Network <= System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   182
by (blast_tac (claset() addIs [componentI]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   183
qed "Network_component_System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   184
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   185
Goalw [System_def] "(extend sysOfAlloc Alloc) <= System";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   186
by (blast_tac (claset() addIs [componentI]) 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   187
qed "Alloc_component_System";
7365
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
AddIffs [Network_component_System, Alloc_component_System];
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   190
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   191
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   192
(* F : UNIV guarantees Increasing func
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   193
   ==> 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
   194
val extend_Client_guar_Increasing =
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   195
  good_map_sysOfClient RS export extend_guar_Increasing
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   196
  |> simplify (simpset() addsimps [inv_sysOfClient_eq]);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   197
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   198
fun alloc_export th = good_map_sysOfAlloc RS export th;
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   199
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   200
(*NEED AUTOMATIC PROPAGATION of Alloc_Increasing*)
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   201
Goal "i < Nclients \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   202
\ ==> extend sysOfAlloc Alloc : UNIV guarantees Increasing (sub i o allocGiv)";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   203
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
   204
by (auto_tac (claset(), simpset() addsimps [o_def]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   205
qed "extend_Alloc_Increasing_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   206
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   207
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   208
(** Proof of property (1) **)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   209
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   210
(*step 1*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   211
Goalw [System_def]
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   212
     "i < Nclients ==> System : Increasing (rel o sub i o client)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   213
by (rtac ([guaranteesI RS disjI2 RS guarantees_Join_I, UNIV_I] 
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   214
	  MRS guaranteesD) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   215
by (asm_simp_tac 
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   216
    (simpset() addsimps [guarantees_PLam_I, 
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   217
			 extend_Client_guar_Increasing RS guaranteesD,
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   218
			 lift_prog_guar_Increasing]) 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   219
qed "System_Increasing_rel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   220
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   221
(*Note: the first step above performs simple quantifier reasoning.  It could
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   222
  be replaced by a proof mentioning no guarantees primitives*)
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   223
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   224
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   225
(*step 2*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   226
Goal "i < Nclients ==> System : Increasing (sub i o allocRel)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   227
by (rtac Follows_Increasing1 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   228
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
   229
			       System_Increasing_rel]) 1);
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   230
qed "System_Increasing_allocRel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   231
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   232
(*step 2*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   233
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
   234
\                  <= 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
   235
by (res_inst_tac 
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   236
    [("X", "(INT i : lessThan Nclients. Increasing (sub i o allocRel))")] 
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   237
    component_guaranteesD 1);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   238
by (rtac Alloc_component_System 3);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   239
by (force_tac (claset(), simpset() addsimps [System_Increasing_allocRel]) 2);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   240
by (rtac (Alloc_Safety RS project_guarantees) 1);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   241
by Auto_tac;
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   242
(*1: Increasing precondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   243
by (stac (alloc_export project_Increasing) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   244
by (force_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   245
    (claset(),
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   246
     simpset() addsimps [o_def, alloc_export project_Increasing]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   247
(*2: Always postcondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   248
by (dtac (subset_refl RS alloc_export project_Always_D) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   249
by (asm_full_simp_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   250
     (simpset() addsimps [alloc_export Collect_eq_extend_set RS sym]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   251
qed "System_sum_bounded";
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   252
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   253
(*step 3*)
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   254
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   255
\                         {s. (tokens o giv o sub i o client) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   256
\                          <= (tokens o sub i o allocGiv) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   257
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   258
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   259
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   260
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   261
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
   262
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
   263
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   264
by (blast_tac (claset() addIs [Network_Giv RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   265
	  extend_Alloc_Increasing_allocGiv RS component_guaranteesD]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   266
qed "System_Always_giv_le_allocGiv";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   267
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   268
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   269
Goal "System : Always (INT i: lessThan Nclients. \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   270
\                         {s. (tokens o sub i o allocRel) s \
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   271
\                          <= (tokens o rel o sub i o client) s})";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   272
by (auto_tac (claset(), 
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   273
	      simpset() delsimps [o_apply]
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   274
			addsimps [Always_INT_distrib]));
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   275
by (rtac Follows_Bounded 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   276
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
   277
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
   278
by (simp_tac (HOL_ss addsimps [o_assoc]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   279
by (blast_tac (claset() addIs [Network_Rel RS component_guaranteesD,
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   280
			       System_Increasing_rel]) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   281
qed "System_Always_allocRel_le_rel";
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   282
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   283
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   284
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
   285
\              <= 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
   286
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
   287
			   System_Always_allocRel_le_rel] RS Always_weaken) 1);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   288
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   289
by (rtac (sum_mono RS order_trans) 1);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   290
by (dtac order_trans 2);
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   291
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
   292
by (assume_tac 3);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   293
by Auto_tac;
7540
8af61a565a4a working Safety proof for the system at last
paulson
parents: 7538
diff changeset
   294
qed "System_safety";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   295