src/HOL/UNITY/Alloc.ML
author paulson
Fri, 17 Sep 1999 10:31:38 +0200
changeset 7538 357873391561
parent 7537 875754b599df
child 7540 8af61a565a4a
permissions -rw-r--r--
new rule PLam_ensures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     1
(*  Title:      HOL/UNITY/Alloc
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     2
    ID:         $Id$
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     4
    Copyright   1998  University of Cambridge
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     5
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     6
Specification of Chandy and Charpentier's Allocator
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     7
*)
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
     8
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
     9
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    10
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
    11
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    12
(*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
    13
Goal "[| b:A;  a=b |] ==> a:A";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    14
by (etac ssubst 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    15
by (assume_tac 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    16
qed "subst_elem";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    17
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    18
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    19
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    20
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
    21
by (induct_tac "n" 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    22
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    23
by (dres_inst_tac [("x","n")] bspec 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 (arith_tac 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    26
qed_spec_mp "sum_mono";
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    27
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    28
6840
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    29
(*Generalized version allowing different clients*)
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    30
Goal "[| Alloc : alloc_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    31
\        Client : (lessThan Nclients) funcset client_spec;  \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    32
\        Network : network_spec |] \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    33
\     ==> (extend sysOfAlloc Alloc) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    34
\         Join (extend sysOfClient (PLam (lessThan Nclients) Client)) \
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    35
\         Join Network : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    36
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    37
Goal "System : system_spec";
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    38
0e5c82abfc71 another non-working snapshot
paulson
parents: 6837
diff changeset
    39
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    40
Goalw [sysOfAlloc_def] "inj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    41
by (rtac injI 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    42
by (auto_tac (claset() addSWrapper record_split_wrapper, simpset()));
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    43
qed "inj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    44
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    45
Goalw [sysOfAlloc_def] "surj sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    46
by (res_inst_tac [("f", "%s. ((| allocGiv = allocGiv s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    47
\                                allocAsk = allocAsk s,    \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    48
\                                allocRel = allocRel s |), \
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    49
\                             client s)")] surjI 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    50
by (auto_tac (claset() addSWrapper record_split_wrapper, simpset()));
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    51
qed "surj_sysOfAlloc";
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    52
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    53
AddIffs [inj_sysOfAlloc, surj_sysOfAlloc];
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    54
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    55
Goalw [good_map_def] "good_map sysOfAlloc";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    56
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    57
qed "good_map_sysOfAlloc";
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    58
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    59
(*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
    60
Goal "!!s. inv sysOfAlloc s = \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    61
\            ((| allocGiv = allocGiv s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    62
\                allocAsk = allocAsk s,   \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    63
\                allocRel = allocRel s|), \
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    64
\             client s)";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    65
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
    66
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
    67
	      simpset() addsimps [sysOfAlloc_def]));
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    68
qed "inv_sysOfAlloc_eq";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    69
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
    70
Addsimps [inv_sysOfAlloc_eq];
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
    71
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    72
(**SHOULD NOT BE NECESSARY: The various injections into the system
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
    73
   state need to be treated symmetrically or done automatically*)
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    74
Goalw [sysOfClient_def] "inj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    75
by (rtac injI 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    76
by (auto_tac (claset() addSDs [inj_sysOfAlloc RS injD]
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    77
		       addSWrapper record_split_wrapper, simpset()));
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    78
qed "inj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    79
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    80
Goalw [sysOfClient_def] "surj sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    81
by (cut_facts_tac [surj_sysOfAlloc] 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    82
by (rewtac surj_def);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    83
by Auto_tac;
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    84
by (Blast_tac 1);
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    85
qed "surj_sysOfClient";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    86
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    87
AddIffs [inj_sysOfClient, surj_sysOfClient];
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    88
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    89
Goalw [good_map_def] "good_map sysOfClient";
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    90
by Auto_tac;
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
    91
qed "good_map_sysOfClient";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
    92
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    93
(*MUST BE AUTOMATED: even the statement of such results*)
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    94
Goal "!!s. inv sysOfClient s = \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    95
\            (client s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    96
\             (| allocGiv = allocGiv s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    97
\                allocAsk = allocAsk s, \
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    98
\                allocRel = allocRel s|) )";
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    99
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
   100
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
   101
	      simpset() addsimps [sysOfAlloc_def, sysOfClient_def]));
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   102
qed "inv_sysOfClient_eq";
6837
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   103
1bd850260747 another snapshot, still not working
paulson
parents: 6828
diff changeset
   104
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   105
Open_locale "System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   106
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   107
val Alloc = thm "Alloc";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   108
val Client = thm "Client";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   109
val Network = thm "Network";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   110
val System_def = thm "System_def";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   111
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   112
AddIffs [finite_lessThan];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   113
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   114
(*Client : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   115
val Client_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   116
    rewrite_rule [client_spec_def, client_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   117
		  client_bounded_def, client_progress_def] Client;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   118
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   119
Goal "Client : UNIV guarantees Increasing ask";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   120
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   121
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   122
qed "Client_Increasing_ask";
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
Goal "Client : UNIV guarantees Increasing rel";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   125
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   126
by (asm_full_simp_tac (simpset() addsimps [guarantees_Int_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   127
qed "Client_Increasing_rel";
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
AddIffs [Client_Increasing_ask, Client_Increasing_rel];
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   130
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   131
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
   132
by (cut_facts_tac [Client_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   133
by Auto_tac;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   134
qed "Client_Bounded";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   135
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   136
(*Client_Progress is cumbersome to state*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   137
val Client_Progress = Client_Spec RS IntD2;
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   138
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   139
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   140
(*Network : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   141
val Network_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   142
    rewrite_rule [network_spec_def, network_ask_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   143
		  network_giv_def, network_rel_def] Network;
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
(*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
   146
  exporting it from the locale*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   147
val Network_Ask = Network_Spec RS IntD1 RS IntD1;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   148
val Network_Giv = Network_Spec RS IntD1 RS IntD2;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   149
val Network_Rel = Network_Spec RS IntD2 RS INT_D;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   150
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   151
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   152
(*Alloc : <unfolded specification> *)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   153
val Alloc_Spec =
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   154
    rewrite_rule [alloc_spec_def, alloc_increasing_def,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   155
		  alloc_safety_def, alloc_progress_def] Alloc;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   156
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   157
Goal "i < Nclients ==> Alloc : UNIV guarantees Increasing (sub i o allocAsk)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   158
by (cut_facts_tac [Alloc_Spec] 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   159
by (asm_full_simp_tac (simpset() addsimps [guarantees_INT_right]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   160
qed "Alloc_Increasing";
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
val Alloc_Safety = Alloc_Spec RS IntD1 RS IntD2;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   163
val Alloc_Progress = (Alloc_Spec RS IntD2
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   164
                      |> simplify (simpset() addsimps [guarantees_INT_right]))
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   165
                     RS bspec RS spec;
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   166
		     
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   167
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   168
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   169
(*Not sure what to say about the other components because they involve
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   170
  extend*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   171
Goalw [System_def] "Network <= System";
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   172
by (blast_tac (claset() addIs [componentI]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   173
qed "Network_component_System";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   174
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   175
Goalw [System_def] "(extend sysOfAlloc Alloc) <= System";
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   176
by (blast_tac (claset() addIs [componentI]) 1);
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   177
qed "Alloc_component_System";
7365
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
AddIffs [Network_component_System, Alloc_component_System];
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   180
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   181
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   182
(* F : UNIV guarantees Increasing func
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   183
   ==> 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
   184
val extend_Client_guar_Increasing =
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   185
  good_map_sysOfClient RS export extend_guar_Increasing
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   186
  |> simplify (simpset() addsimps [inv_sysOfClient_eq]);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   187
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   188
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   189
(** Proof of property (1) **)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   190
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   191
(*step 1*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   192
Goalw [System_def]
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   193
     "i < Nclients ==> System : Increasing (rel o sub i o client)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   194
by (rtac ([guaranteesI RS disjI2 RS guarantees_Join_I, UNIV_I] 
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   195
	  MRS guaranteesD) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   196
by (asm_simp_tac 
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   197
    (simpset() addsimps [guarantees_PLam_I, 
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   198
			 extend_Client_guar_Increasing RS guaranteesD,
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   199
			 lift_prog_guar_Increasing]) 1);
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
   200
qed "System_Increasing_rel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   201
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   202
(*Note: the first step above performs simple quantifier reasoning.  It could
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   203
  be replaced by a proof mentioning no guarantees primitives*)
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   204
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   205
7365
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   206
(*step 2*)
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   207
Goal "i < Nclients ==> System : Increasing (sub i o allocRel)";
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   208
by (rtac Follows_Increasing1 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   209
by (blast_tac (claset() addIs [Network_Rel RS component_guaranteesD,
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   210
			       System_Increasing_rel, Network]) 1);
b5bb32e0861c a bit further with property (1)
paulson
parents: 7347
diff changeset
   211
qed "System_Increasing_allocRel";
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   212
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   213
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   214
fun alloc_export th = good_map_sysOfAlloc RS export th;
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   215
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   216
val extend_Alloc_guar_Increasing =
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   217
  alloc_export extend_guar_Increasing
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   218
  |> simplify (simpset());
6828
ea6832d74353 not working but taking shape
paulson
parents: 6815
diff changeset
   219
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   220
(*step 2*)
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   221
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
   222
\                  <= 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
   223
by (res_inst_tac 
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   224
    [("X", "(INT i : lessThan Nclients. Increasing (sub i o allocRel))")] 
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   225
    component_guaranteesD 1);
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   226
by (rtac Alloc_component_System 3);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   227
by (force_tac (claset(), simpset() addsimps [System_Increasing_allocRel]) 2);
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   228
by (rtac (Alloc_Safety RS project_guarantees) 1);
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   229
by Auto_tac;
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   230
(*1: Increasing precondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   231
by (stac (alloc_export project_Increasing) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   232
by (force_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   233
    (claset(),
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   234
     simpset() addsimps [o_def, alloc_export project_Increasing]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   235
(*2: Always postcondition*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   236
by (dtac (subset_refl RS alloc_export project_Always_D) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   237
by (asm_full_simp_tac
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   238
     (simpset() addsimps [alloc_export Collect_eq_extend_set RS sym]) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   239
qed "System_sum_bounded";
7537
875754b599df working snapshot
paulson
parents: 7482
diff changeset
   240
7538
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   241
(*step 3*)
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   242
Goal "System : Always {s. sum (%i. (tokens o giv o sub i o client) s) Nclients \
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   243
\                  <= NbT + sum (%i. (tokens o rel o sub i o client) s) Nclients}";
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   244
by (rtac (System_sum_bounded RS Always_weaken) 1);
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   245
by Auto_tac;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   246
br order_trans 1;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   247
br sum_mono 1;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   248
bd order_trans 2;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   249
br add_le_mono 2;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   250
br order_refl 2;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   251
br sum_mono 2;
357873391561 new rule PLam_ensures
paulson
parents: 7537
diff changeset
   252
ba 3;
7482
7badd511844d working snapshot
paulson
parents: 7399
diff changeset
   253
by Auto_tac;
7399
cf780c2bcccf changed "component" infix in HOL/UNITY/Comp.thy to be overloaded <
paulson
parents: 7365
diff changeset
   254