| author | bulwahn | 
| Thu, 08 Nov 2012 19:55:37 +0100 | |
| changeset 50036 | aa83d943c18b | 
| parent 46911 | 6d2a2f0e904e | 
| child 51703 | f2e92fc0c8aa | 
| permissions | -rw-r--r-- | 
| 37936 | 1 | (* Title: HOL/UNITY/Comp/Alloc.thy | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 3 | Copyright 1998 University of Cambridge | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 4 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 5 | Specification of Chandy and Charpentier's Allocator | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 6 | *) | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 7 | |
| 17310 | 8 | theory Alloc | 
| 21710 | 9 | imports AllocBase "../PPROD" | 
| 17310 | 10 | begin | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 11 | |
| 21710 | 12 | subsection{*State definitions.  OUTPUT variables are locals*}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 13 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 14 | record clientState = | 
| 21710 | 15 |   giv :: "nat list"   --{*client's INPUT history:  tokens GRANTED*}
 | 
| 16 |   ask :: "nat list"   --{*client's OUTPUT history: tokens REQUESTED*}
 | |
| 17 |   rel :: "nat list"   --{*client's OUTPUT history: tokens RELEASED*}
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 18 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 19 | record 'a clientState_d = | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 20 | clientState + | 
| 21710 | 21 |   dummy :: 'a       --{*dummy field for new variables*}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 22 | |
| 36866 | 23 | definition | 
| 21710 | 24 |   --{*DUPLICATED FROM Client.thy, but with "tok" removed*}
 | 
| 25 |   --{*Maybe want a special theory section to declare such maps*}
 | |
| 17310 | 26 | non_dummy :: "'a clientState_d => clientState" | 
| 36866 | 27 | where "non_dummy s = (|giv = giv s, ask = ask s, rel = rel s|)" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 28 | |
| 36866 | 29 | definition | 
| 21710 | 30 |   --{*Renaming map to put a Client into the standard form*}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 31 | client_map :: "'a clientState_d => clientState*'a" | 
| 36866 | 32 | where "client_map = funPair non_dummy dummy" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 33 | |
| 24147 | 34 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 35 | record allocState = | 
| 21710 | 36 |   allocGiv :: "nat => nat list"   --{*OUTPUT history: source of "giv" for i*}
 | 
| 37 |   allocAsk :: "nat => nat list"   --{*INPUT: allocator's copy of "ask" for i*}
 | |
| 38 |   allocRel :: "nat => nat list"   --{*INPUT: allocator's copy of "rel" for i*}
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 39 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 40 | record 'a allocState_d = | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 41 | allocState + | 
| 21710 | 42 |   dummy    :: 'a                --{*dummy field for new variables*}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 43 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 44 | record 'a systemState = | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 45 | allocState + | 
| 21710 | 46 |   client :: "nat => clientState"  --{*states of all clients*}
 | 
| 47 |   dummy  :: 'a                    --{*dummy field for new variables*}
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 48 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 49 | |
| 21710 | 50 | --{** Resource allocation system specification **}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 51 | |
| 36866 | 52 | definition | 
| 21710 | 53 |   --{*spec (1)*}
 | 
| 17310 | 54 | system_safety :: "'a systemState program set" | 
| 36866 | 55 | where "system_safety = | 
| 15074 | 56 |      Always {s. (SUM i: lessThan Nclients. (tokens o giv o sub i o client)s)
 | 
| 21710 | 57 | \<le> NbT + (SUM i: lessThan Nclients. (tokens o rel o sub i o client)s)}" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 58 | |
| 36866 | 59 | definition | 
| 21710 | 60 |   --{*spec (2)*}
 | 
| 17310 | 61 | system_progress :: "'a systemState program set" | 
| 36866 | 62 | where "system_progress = (INT i : lessThan Nclients. | 
| 24147 | 63 | INT h. | 
| 64 |                           {s. h \<le> (ask o sub i o client)s} LeadsTo
 | |
| 36866 | 65 |                           {s. h pfixLe (giv o sub i o client) s})"
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 66 | |
| 36866 | 67 | definition | 
| 17310 | 68 | system_spec :: "'a systemState program set" | 
| 36866 | 69 | where "system_spec = system_safety Int system_progress" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 70 | |
| 21710 | 71 | --{** Client specification (required) ***}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 72 | |
| 36866 | 73 | definition | 
| 21710 | 74 |   --{*spec (3)*}
 | 
| 17310 | 75 | client_increasing :: "'a clientState_d program set" | 
| 36866 | 76 | where "client_increasing = UNIV guarantees Increasing ask Int Increasing rel" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 77 | |
| 36866 | 78 | definition | 
| 21710 | 79 |   --{*spec (4)*}
 | 
| 17310 | 80 | client_bounded :: "'a clientState_d program set" | 
| 36866 | 81 |   where "client_bounded = UNIV guarantees  Always {s. ALL elt : set (ask s). elt \<le> NbT}"
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 82 | |
| 36866 | 83 | definition | 
| 21710 | 84 |   --{*spec (5)*}
 | 
| 17310 | 85 | client_progress :: "'a clientState_d program set" | 
| 36866 | 86 | where "client_progress = | 
| 24147 | 87 | Increasing giv guarantees | 
| 88 |          (INT h. {s. h \<le> giv s & h pfixGe ask s}
 | |
| 89 |                  LeadsTo {s. tokens h \<le> (tokens o rel) s})"
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 90 | |
| 36866 | 91 | definition | 
| 21710 | 92 |   --{*spec: preserves part*}
 | 
| 17310 | 93 | client_preserves :: "'a clientState_d program set" | 
| 36866 | 94 | where "client_preserves = preserves giv Int preserves clientState_d.dummy" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 95 | |
| 36866 | 96 | definition | 
| 21710 | 97 |   --{*environmental constraints*}
 | 
| 17310 | 98 | client_allowed_acts :: "'a clientState_d program set" | 
| 36866 | 99 | where "client_allowed_acts = | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 100 |        {F. AllowedActs F =
 | 
| 24147 | 101 | insert Id (UNION (preserves (funPair rel ask)) Acts)}" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 102 | |
| 36866 | 103 | definition | 
| 17310 | 104 | client_spec :: "'a clientState_d program set" | 
| 36866 | 105 | where "client_spec = client_increasing Int client_bounded Int client_progress | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 106 | Int client_allowed_acts Int client_preserves" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 107 | |
| 21710 | 108 | --{** Allocator specification (required) **}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 109 | |
| 36866 | 110 | definition | 
| 21710 | 111 |   --{*spec (6)*}
 | 
| 17310 | 112 | alloc_increasing :: "'a allocState_d program set" | 
| 36866 | 113 | where "alloc_increasing = | 
| 24147 | 114 | UNIV guarantees | 
| 115 | (INT i : lessThan Nclients. Increasing (sub i o allocGiv))" | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 116 | |
| 36866 | 117 | definition | 
| 21710 | 118 |   --{*spec (7)*}
 | 
| 17310 | 119 | alloc_safety :: "'a allocState_d program set" | 
| 36866 | 120 | where "alloc_safety = | 
| 24147 | 121 | (INT i : lessThan Nclients. Increasing (sub i o allocRel)) | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 122 | guarantees | 
| 24147 | 123 |          Always {s. (SUM i: lessThan Nclients. (tokens o sub i o allocGiv)s)
 | 
| 21710 | 124 | \<le> NbT + (SUM i: lessThan Nclients. (tokens o sub i o allocRel)s)}" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 125 | |
| 36866 | 126 | definition | 
| 21710 | 127 |   --{*spec (8)*}
 | 
| 17310 | 128 | alloc_progress :: "'a allocState_d program set" | 
| 36866 | 129 | where "alloc_progress = | 
| 24147 | 130 | (INT i : lessThan Nclients. Increasing (sub i o allocAsk) Int | 
| 131 | Increasing (sub i o allocRel)) | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 132 | Int | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 133 |          Always {s. ALL i<Nclients.
 | 
| 24147 | 134 | ALL elt : set ((sub i o allocAsk) s). elt \<le> NbT} | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 135 | Int | 
| 24147 | 136 | (INT i : lessThan Nclients. | 
| 137 |           INT h. {s. h \<le> (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s}
 | |
| 138 | LeadsTo | |
| 139 |                  {s. tokens h \<le> (tokens o sub i o allocRel)s})
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 140 | guarantees | 
| 24147 | 141 | (INT i : lessThan Nclients. | 
| 142 |               INT h. {s. h \<le> (sub i o allocAsk) s}
 | |
| 143 | LeadsTo | |
| 144 |                      {s. h pfixLe (sub i o allocGiv) s})"
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 145 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 146 | (*NOTE: to follow the original paper, the formula above should have had | 
| 24147 | 147 |         INT h. {s. h i \<le> (sub i o allocGiv)s & h i pfixGe (sub i o allocAsk)s}
 | 
| 148 | LeadsTo | |
| 149 |                {s. tokens h i \<le> (tokens o sub i o allocRel)s})
 | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 150 | thus h should have been a function variable. However, only h i is ever | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 151 | looked at.*) | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 152 | |
| 36866 | 153 | definition | 
| 21710 | 154 |   --{*spec: preserves part*}
 | 
| 17310 | 155 | alloc_preserves :: "'a allocState_d program set" | 
| 36866 | 156 | where "alloc_preserves = preserves allocRel Int preserves allocAsk Int | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 157 | preserves allocState_d.dummy" | 
| 24147 | 158 | |
| 36866 | 159 | definition | 
| 21710 | 160 |   --{*environmental constraints*}
 | 
| 17310 | 161 | alloc_allowed_acts :: "'a allocState_d program set" | 
| 36866 | 162 | where "alloc_allowed_acts = | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 163 |        {F. AllowedActs F =
 | 
| 24147 | 164 | insert Id (UNION (preserves allocGiv) Acts)}" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 165 | |
| 36866 | 166 | definition | 
| 17310 | 167 | alloc_spec :: "'a allocState_d program set" | 
| 36866 | 168 | where "alloc_spec = alloc_increasing Int alloc_safety Int alloc_progress Int | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 169 | alloc_allowed_acts Int alloc_preserves" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 170 | |
| 21710 | 171 | --{** Network specification **}
 | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 172 | |
| 36866 | 173 | definition | 
| 21710 | 174 |   --{*spec (9.1)*}
 | 
| 17310 | 175 | network_ask :: "'a systemState program set" | 
| 36866 | 176 | where "network_ask = (INT i : lessThan Nclients. | 
| 24147 | 177 | Increasing (ask o sub i o client) guarantees | 
| 36866 | 178 | ((sub i o allocAsk) Fols (ask o sub i o client)))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 179 | |
| 36866 | 180 | definition | 
| 21710 | 181 |   --{*spec (9.2)*}
 | 
| 17310 | 182 | network_giv :: "'a systemState program set" | 
| 36866 | 183 | where "network_giv = (INT i : lessThan Nclients. | 
| 24147 | 184 | Increasing (sub i o allocGiv) | 
| 185 | guarantees | |
| 36866 | 186 | ((giv o sub i o client) Fols (sub i o allocGiv)))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 187 | |
| 36866 | 188 | definition | 
| 21710 | 189 |   --{*spec (9.3)*}
 | 
| 17310 | 190 | network_rel :: "'a systemState program set" | 
| 36866 | 191 | where "network_rel = (INT i : lessThan Nclients. | 
| 24147 | 192 | Increasing (rel o sub i o client) | 
| 193 | guarantees | |
| 36866 | 194 | ((sub i o allocRel) Fols (rel o sub i o client)))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 195 | |
| 36866 | 196 | definition | 
| 21710 | 197 |   --{*spec: preserves part*}
 | 
| 17310 | 198 | network_preserves :: "'a systemState program set" | 
| 36866 | 199 | where "network_preserves = | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 200 | preserves allocGiv Int | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 201 | (INT i : lessThan Nclients. preserves (rel o sub i o client) Int | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 202 | preserves (ask o sub i o client))" | 
| 24147 | 203 | |
| 36866 | 204 | definition | 
| 21710 | 205 |   --{*environmental constraints*}
 | 
| 17310 | 206 | network_allowed_acts :: "'a systemState program set" | 
| 36866 | 207 | where "network_allowed_acts = | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 208 |        {F. AllowedActs F =
 | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 209 | insert Id | 
| 24147 | 210 | (UNION (preserves allocRel Int | 
| 211 | (INT i: lessThan Nclients. preserves(giv o sub i o client))) | |
| 212 | Acts)}" | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 213 | |
| 36866 | 214 | definition | 
| 17310 | 215 | network_spec :: "'a systemState program set" | 
| 36866 | 216 | where "network_spec = network_ask Int network_giv Int | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 217 | network_rel Int network_allowed_acts Int | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 218 | network_preserves" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 219 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 220 | |
| 21710 | 221 | --{** State mappings **}
 | 
| 36866 | 222 | definition | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 223 | sysOfAlloc :: "((nat => clientState) * 'a) allocState_d => 'a systemState" | 
| 36866 | 224 | where "sysOfAlloc = (%s. let (cl,xtr) = allocState_d.dummy s | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 225 | in (| allocGiv = allocGiv s, | 
| 24147 | 226 | allocAsk = allocAsk s, | 
| 227 | allocRel = allocRel s, | |
| 228 | client = cl, | |
| 36866 | 229 | dummy = xtr|))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 230 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 231 | |
| 36866 | 232 | definition | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 233 | sysOfClient :: "(nat => clientState) * 'a allocState_d => 'a systemState" | 
| 36866 | 234 | where "sysOfClient = (%(cl,al). (| allocGiv = allocGiv al, | 
| 24147 | 235 | allocAsk = allocAsk al, | 
| 236 | allocRel = allocRel al, | |
| 237 | client = cl, | |
| 36866 | 238 | systemState.dummy = allocState_d.dummy al|))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 239 | |
| 36866 | 240 | axiomatization Alloc :: "'a allocState_d program" | 
| 241 | where Alloc: "Alloc : alloc_spec" | |
| 24147 | 242 | |
| 36866 | 243 | axiomatization Client :: "'a clientState_d program" | 
| 244 | where Client: "Client : client_spec" | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 245 | |
| 36866 | 246 | axiomatization Network :: "'a systemState program" | 
| 247 | where Network: "Network : network_spec" | |
| 248 | ||
| 249 | definition System :: "'a systemState program" | |
| 250 | where "System = rename sysOfAlloc Alloc Join Network Join | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 251 | (rename sysOfClient | 
| 24147 | 252 | (plam x: lessThan Nclients. rename client_map Client))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 253 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 254 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 255 | (** | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 256 | locale System = | 
| 24147 | 257 | fixes | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 258 | Alloc :: 'a allocState_d program | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 259 | Client :: 'a clientState_d program | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 260 | Network :: 'a systemState program | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 261 | System :: 'a systemState program | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 262 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 263 | assumes | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 264 | Alloc "Alloc : alloc_spec" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 265 | Client "Client : client_spec" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 266 | Network "Network : network_spec" | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 267 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 268 | defines | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 269 | System_def | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 270 | "System == rename sysOfAlloc Alloc | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 271 | Join | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 272 | Network | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 273 | Join | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 274 | (rename sysOfClient | 
| 24147 | 275 | (plam x: lessThan Nclients. rename client_map Client))" | 
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 276 | **) | 
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 277 | |
| 21632 | 278 | declare subset_preserves_o [THEN [2] rev_subsetD, intro] | 
| 279 | declare subset_preserves_o [THEN [2] rev_subsetD, simp] | |
| 280 | declare funPair_o_distrib [simp] | |
| 281 | declare Always_INT_distrib [simp] | |
| 282 | declare o_apply [simp del] | |
| 283 | ||
| 284 | (*For rewriting of specifications related by "guarantees"*) | |
| 285 | lemmas [simp] = | |
| 286 | rename_image_constrains | |
| 287 | rename_image_stable | |
| 288 | rename_image_increasing | |
| 289 | rename_image_invariant | |
| 290 | rename_image_Constrains | |
| 291 | rename_image_Stable | |
| 292 | rename_image_Increasing | |
| 293 | rename_image_Always | |
| 294 | rename_image_leadsTo | |
| 295 | rename_image_LeadsTo | |
| 296 | rename_preserves | |
| 297 | rename_image_preserves | |
| 298 | lift_image_preserves | |
| 299 | bij_image_INT | |
| 300 | bij_is_inj [THEN image_Int] | |
| 301 | bij_image_Collect_eq | |
| 302 | ||
| 303 | ML {*
 | |
| 304 | (*Splits up conjunctions & intersections: like CONJUNCTS in the HOL system*) | |
| 24147 | 305 | fun list_of_Int th = | 
| 21632 | 306 | (list_of_Int (th RS conjunct1) @ list_of_Int (th RS conjunct2)) | 
| 307 | handle THM _ => (list_of_Int (th RS IntD1) @ list_of_Int (th RS IntD2)) | |
| 24147 | 308 |     handle THM _ => (list_of_Int (th RS @{thm INT_D}))
 | 
| 21632 | 309 | handle THM _ => (list_of_Int (th RS bspec)) | 
| 310 | handle THM _ => [th]; | |
| 311 | *} | |
| 312 | ||
| 313 | lemmas lessThanBspec = lessThan_iff [THEN iffD2, THEN [2] bspec] | |
| 314 | ||
| 30528 | 315 | attribute_setup normalized = {*
 | 
| 24147 | 316 | let | 
| 317 | fun normalized th = | |
| 318 | normalized (th RS spec | |
| 319 |       handle THM _ => th RS @{thm lessThanBspec}
 | |
| 320 | handle THM _ => th RS bspec | |
| 321 |       handle THM _ => th RS (@{thm guarantees_INT_right_iff} RS iffD1))
 | |
| 322 | handle THM _ => th; | |
| 21632 | 323 | in | 
| 30528 | 324 | Scan.succeed (Thm.rule_attribute (K normalized)) | 
| 21632 | 325 | end | 
| 42814 | 326 | *} | 
| 21632 | 327 | |
| 328 | (*** bijectivity of sysOfAlloc [MUST BE AUTOMATED] ***) | |
| 329 | ML {*
 | |
| 42767 | 330 | fun record_auto_tac ctxt = | 
| 42793 | 331 | let val ctxt' = | 
| 44871 | 332 | ctxt | 
| 42793 | 333 | |> map_claset (fn cs => cs addSWrapper Record.split_wrapper) | 
| 42795 
66fcc9882784
clarified map_simpset versus Simplifier.map_simpset_global;
 wenzelm parents: 
42793diff
changeset | 334 | |> map_simpset (fn ss => ss addsimps | 
| 
66fcc9882784
clarified map_simpset versus Simplifier.map_simpset_global;
 wenzelm parents: 
42793diff
changeset | 335 |        [@{thm sysOfAlloc_def}, @{thm sysOfClient_def},
 | 
| 
66fcc9882784
clarified map_simpset versus Simplifier.map_simpset_global;
 wenzelm parents: 
42793diff
changeset | 336 |         @{thm client_map_def}, @{thm non_dummy_def}, @{thm funPair_def},
 | 
| 
66fcc9882784
clarified map_simpset versus Simplifier.map_simpset_global;
 wenzelm parents: 
42793diff
changeset | 337 |         @{thm o_apply}, @{thm Let_def}])
 | 
| 42793 | 338 | in auto_tac ctxt' end; | 
| 339 | ||
| 21632 | 340 | *} | 
| 341 | ||
| 42814 | 342 | method_setup record_auto = {* Scan.succeed (SIMPLE_METHOD o record_auto_tac) *}
 | 
| 21632 | 343 | |
| 344 | lemma inj_sysOfAlloc [iff]: "inj sysOfAlloc" | |
| 345 | apply (unfold sysOfAlloc_def Let_def) | |
| 346 | apply (rule inj_onI) | |
| 24147 | 347 | apply record_auto | 
| 21632 | 348 | done | 
| 349 | ||
| 21710 | 350 | text{*We need the inverse; also having it simplifies the proof of surjectivity*}
 | 
| 24147 | 351 | lemma inv_sysOfAlloc_eq [simp]: "!!s. inv sysOfAlloc s = | 
| 352 | (| allocGiv = allocGiv s, | |
| 353 | allocAsk = allocAsk s, | |
| 354 | allocRel = allocRel s, | |
| 21632 | 355 | allocState_d.dummy = (client s, dummy s) |)" | 
| 356 | apply (rule inj_sysOfAlloc [THEN inv_f_eq]) | |
| 24147 | 357 | apply record_auto | 
| 21632 | 358 | done | 
| 359 | ||
| 360 | lemma surj_sysOfAlloc [iff]: "surj sysOfAlloc" | |
| 40702 | 361 | apply (simp add: surj_iff_all) | 
| 24147 | 362 | apply record_auto | 
| 21632 | 363 | done | 
| 364 | ||
| 365 | lemma bij_sysOfAlloc [iff]: "bij sysOfAlloc" | |
| 366 | apply (blast intro: bijI) | |
| 367 | done | |
| 368 | ||
| 369 | ||
| 21710 | 370 | subsubsection{*bijectivity of @{term sysOfClient}*}
 | 
| 21632 | 371 | |
| 372 | lemma inj_sysOfClient [iff]: "inj sysOfClient" | |
| 373 | apply (unfold sysOfClient_def) | |
| 374 | apply (rule inj_onI) | |
| 24147 | 375 | apply record_auto | 
| 21632 | 376 | done | 
| 377 | ||
| 24147 | 378 | lemma inv_sysOfClient_eq [simp]: "!!s. inv sysOfClient s = | 
| 379 | (client s, | |
| 380 | (| allocGiv = allocGiv s, | |
| 381 | allocAsk = allocAsk s, | |
| 382 | allocRel = allocRel s, | |
| 21632 | 383 | allocState_d.dummy = systemState.dummy s|) )" | 
| 384 | apply (rule inj_sysOfClient [THEN inv_f_eq]) | |
| 24147 | 385 | apply record_auto | 
| 21632 | 386 | done | 
| 387 | ||
| 388 | lemma surj_sysOfClient [iff]: "surj sysOfClient" | |
| 40702 | 389 | apply (simp add: surj_iff_all) | 
| 24147 | 390 | apply record_auto | 
| 21632 | 391 | done | 
| 392 | ||
| 393 | lemma bij_sysOfClient [iff]: "bij sysOfClient" | |
| 394 | apply (blast intro: bijI) | |
| 395 | done | |
| 396 | ||
| 397 | ||
| 21710 | 398 | subsubsection{*bijectivity of @{term client_map}*}
 | 
| 21632 | 399 | |
| 400 | lemma inj_client_map [iff]: "inj client_map" | |
| 401 | apply (unfold inj_on_def) | |
| 24147 | 402 | apply record_auto | 
| 21632 | 403 | done | 
| 404 | ||
| 24147 | 405 | lemma inv_client_map_eq [simp]: "!!s. inv client_map s = | 
| 406 | (%(x,y).(|giv = giv x, ask = ask x, rel = rel x, | |
| 21632 | 407 | clientState_d.dummy = y|)) s" | 
| 408 | apply (rule inj_client_map [THEN inv_f_eq]) | |
| 24147 | 409 | apply record_auto | 
| 21632 | 410 | done | 
| 411 | ||
| 412 | lemma surj_client_map [iff]: "surj client_map" | |
| 40702 | 413 | apply (simp add: surj_iff_all) | 
| 24147 | 414 | apply record_auto | 
| 21632 | 415 | done | 
| 416 | ||
| 417 | lemma bij_client_map [iff]: "bij client_map" | |
| 418 | apply (blast intro: bijI) | |
| 419 | done | |
| 420 | ||
| 421 | ||
| 21710 | 422 | text{*o-simprules for @{term client_map}*}
 | 
| 21632 | 423 | |
| 424 | lemma fst_o_client_map: "fst o client_map = non_dummy" | |
| 425 | apply (unfold client_map_def) | |
| 426 | apply (rule fst_o_funPair) | |
| 427 | done | |
| 428 | ||
| 39159 | 429 | ML {* bind_thms ("fst_o_client_map'", make_o_equivs @{thm fst_o_client_map}) *}
 | 
| 21632 | 430 | declare fst_o_client_map' [simp] | 
| 431 | ||
| 432 | lemma snd_o_client_map: "snd o client_map = clientState_d.dummy" | |
| 433 | apply (unfold client_map_def) | |
| 434 | apply (rule snd_o_funPair) | |
| 435 | done | |
| 436 | ||
| 39159 | 437 | ML {* bind_thms ("snd_o_client_map'", make_o_equivs @{thm snd_o_client_map}) *}
 | 
| 21632 | 438 | declare snd_o_client_map' [simp] | 
| 439 | ||
| 21710 | 440 | |
| 441 | subsection{*o-simprules for @{term sysOfAlloc} [MUST BE AUTOMATED]*}
 | |
| 21632 | 442 | |
| 443 | lemma client_o_sysOfAlloc: "client o sysOfAlloc = fst o allocState_d.dummy " | |
| 24147 | 444 | apply record_auto | 
| 21632 | 445 | done | 
| 446 | ||
| 39159 | 447 | ML {* bind_thms ("client_o_sysOfAlloc'", make_o_equivs @{thm client_o_sysOfAlloc}) *}
 | 
| 21632 | 448 | declare client_o_sysOfAlloc' [simp] | 
| 449 | ||
| 450 | lemma allocGiv_o_sysOfAlloc_eq: "allocGiv o sysOfAlloc = allocGiv" | |
| 24147 | 451 | apply record_auto | 
| 21632 | 452 | done | 
| 453 | ||
| 39159 | 454 | ML {* bind_thms ("allocGiv_o_sysOfAlloc_eq'", make_o_equivs @{thm allocGiv_o_sysOfAlloc_eq}) *}
 | 
| 21632 | 455 | declare allocGiv_o_sysOfAlloc_eq' [simp] | 
| 456 | ||
| 457 | lemma allocAsk_o_sysOfAlloc_eq: "allocAsk o sysOfAlloc = allocAsk" | |
| 24147 | 458 | apply record_auto | 
| 21632 | 459 | done | 
| 460 | ||
| 39159 | 461 | ML {* bind_thms ("allocAsk_o_sysOfAlloc_eq'", make_o_equivs @{thm allocAsk_o_sysOfAlloc_eq}) *}
 | 
| 21632 | 462 | declare allocAsk_o_sysOfAlloc_eq' [simp] | 
| 463 | ||
| 464 | lemma allocRel_o_sysOfAlloc_eq: "allocRel o sysOfAlloc = allocRel" | |
| 24147 | 465 | apply record_auto | 
| 21632 | 466 | done | 
| 467 | ||
| 39159 | 468 | ML {* bind_thms ("allocRel_o_sysOfAlloc_eq'", make_o_equivs @{thm allocRel_o_sysOfAlloc_eq}) *}
 | 
| 21632 | 469 | declare allocRel_o_sysOfAlloc_eq' [simp] | 
| 470 | ||
| 21710 | 471 | |
| 472 | subsection{* o-simprules for @{term sysOfClient} [MUST BE AUTOMATED]*}
 | |
| 21632 | 473 | |
| 474 | lemma client_o_sysOfClient: "client o sysOfClient = fst" | |
| 24147 | 475 | apply record_auto | 
| 21632 | 476 | done | 
| 477 | ||
| 39159 | 478 | ML {* bind_thms ("client_o_sysOfClient'", make_o_equivs @{thm client_o_sysOfClient}) *}
 | 
| 21632 | 479 | declare client_o_sysOfClient' [simp] | 
| 480 | ||
| 481 | lemma allocGiv_o_sysOfClient_eq: "allocGiv o sysOfClient = allocGiv o snd " | |
| 24147 | 482 | apply record_auto | 
| 21632 | 483 | done | 
| 484 | ||
| 39159 | 485 | ML {* bind_thms ("allocGiv_o_sysOfClient_eq'", make_o_equivs @{thm allocGiv_o_sysOfClient_eq}) *}
 | 
| 21632 | 486 | declare allocGiv_o_sysOfClient_eq' [simp] | 
| 487 | ||
| 488 | lemma allocAsk_o_sysOfClient_eq: "allocAsk o sysOfClient = allocAsk o snd " | |
| 24147 | 489 | apply record_auto | 
| 21632 | 490 | done | 
| 491 | ||
| 39159 | 492 | ML {* bind_thms ("allocAsk_o_sysOfClient_eq'", make_o_equivs @{thm allocAsk_o_sysOfClient_eq}) *}
 | 
| 21632 | 493 | declare allocAsk_o_sysOfClient_eq' [simp] | 
| 494 | ||
| 495 | lemma allocRel_o_sysOfClient_eq: "allocRel o sysOfClient = allocRel o snd " | |
| 24147 | 496 | apply record_auto | 
| 21632 | 497 | done | 
| 498 | ||
| 39159 | 499 | ML {* bind_thms ("allocRel_o_sysOfClient_eq'", make_o_equivs @{thm allocRel_o_sysOfClient_eq}) *}
 | 
| 21632 | 500 | declare allocRel_o_sysOfClient_eq' [simp] | 
| 501 | ||
| 502 | lemma allocGiv_o_inv_sysOfAlloc_eq: "allocGiv o inv sysOfAlloc = allocGiv" | |
| 503 | apply (simp add: o_def) | |
| 504 | done | |
| 505 | ||
| 39159 | 506 | ML {* bind_thms ("allocGiv_o_inv_sysOfAlloc_eq'", make_o_equivs @{thm allocGiv_o_inv_sysOfAlloc_eq}) *}
 | 
| 21632 | 507 | declare allocGiv_o_inv_sysOfAlloc_eq' [simp] | 
| 508 | ||
| 509 | lemma allocAsk_o_inv_sysOfAlloc_eq: "allocAsk o inv sysOfAlloc = allocAsk" | |
| 510 | apply (simp add: o_def) | |
| 511 | done | |
| 512 | ||
| 39159 | 513 | ML {* bind_thms ("allocAsk_o_inv_sysOfAlloc_eq'", make_o_equivs @{thm allocAsk_o_inv_sysOfAlloc_eq}) *}
 | 
| 21632 | 514 | declare allocAsk_o_inv_sysOfAlloc_eq' [simp] | 
| 515 | ||
| 516 | lemma allocRel_o_inv_sysOfAlloc_eq: "allocRel o inv sysOfAlloc = allocRel" | |
| 517 | apply (simp add: o_def) | |
| 518 | done | |
| 519 | ||
| 39159 | 520 | ML {* bind_thms ("allocRel_o_inv_sysOfAlloc_eq'", make_o_equivs @{thm allocRel_o_inv_sysOfAlloc_eq}) *}
 | 
| 21632 | 521 | declare allocRel_o_inv_sysOfAlloc_eq' [simp] | 
| 522 | ||
| 24147 | 523 | lemma rel_inv_client_map_drop_map: "(rel o inv client_map o drop_map i o inv sysOfClient) = | 
| 21632 | 524 | rel o sub i o client" | 
| 525 | apply (simp add: o_def drop_map_def) | |
| 526 | done | |
| 527 | ||
| 39159 | 528 | ML {* bind_thms ("rel_inv_client_map_drop_map'", make_o_equivs @{thm rel_inv_client_map_drop_map}) *}
 | 
| 21632 | 529 | declare rel_inv_client_map_drop_map [simp] | 
| 530 | ||
| 24147 | 531 | lemma ask_inv_client_map_drop_map: "(ask o inv client_map o drop_map i o inv sysOfClient) = | 
| 21632 | 532 | ask o sub i o client" | 
| 533 | apply (simp add: o_def drop_map_def) | |
| 534 | done | |
| 535 | ||
| 39159 | 536 | ML {* bind_thms ("ask_inv_client_map_drop_map'", make_o_equivs @{thm ask_inv_client_map_drop_map}) *}
 | 
| 21632 | 537 | declare ask_inv_client_map_drop_map [simp] | 
| 538 | ||
| 539 | ||
| 21710 | 540 | text{*Client : <unfolded specification> *}
 | 
| 21632 | 541 | lemmas client_spec_simps = | 
| 542 | client_spec_def client_increasing_def client_bounded_def | |
| 543 | client_progress_def client_allowed_acts_def client_preserves_def | |
| 544 | guarantees_Int_right | |
| 545 | ||
| 546 | ML {*
 | |
| 547 | val [Client_Increasing_ask, Client_Increasing_rel, | |
| 24147 | 548 | Client_Bounded, Client_Progress, Client_AllowedActs, | 
| 21632 | 549 | Client_preserves_giv, Client_preserves_dummy] = | 
| 24147 | 550 |         @{thm Client} |> simplify (@{simpset} addsimps @{thms client_spec_simps})
 | 
| 21632 | 551 | |> list_of_Int; | 
| 552 | ||
| 553 | bind_thm ("Client_Increasing_ask", Client_Increasing_ask);
 | |
| 554 | bind_thm ("Client_Increasing_rel", Client_Increasing_rel);
 | |
| 555 | bind_thm ("Client_Bounded", Client_Bounded);
 | |
| 556 | bind_thm ("Client_Progress", Client_Progress);
 | |
| 557 | bind_thm ("Client_AllowedActs", Client_AllowedActs);
 | |
| 558 | bind_thm ("Client_preserves_giv", Client_preserves_giv);
 | |
| 559 | bind_thm ("Client_preserves_dummy", Client_preserves_dummy);
 | |
| 560 | *} | |
| 561 | ||
| 562 | declare | |
| 563 | Client_Increasing_ask [iff] | |
| 564 | Client_Increasing_rel [iff] | |
| 565 | Client_Bounded [iff] | |
| 566 | Client_preserves_giv [iff] | |
| 567 | Client_preserves_dummy [iff] | |
| 568 | ||
| 569 | ||
| 21710 | 570 | text{*Network : <unfolded specification> *}
 | 
| 21632 | 571 | lemmas network_spec_simps = | 
| 572 | network_spec_def network_ask_def network_giv_def | |
| 573 | network_rel_def network_allowed_acts_def network_preserves_def | |
| 574 | ball_conj_distrib | |
| 575 | ||
| 576 | ML {*
 | |
| 577 | val [Network_Ask, Network_Giv, Network_Rel, Network_AllowedActs, | |
| 24147 | 578 | Network_preserves_allocGiv, Network_preserves_rel, | 
| 579 | Network_preserves_ask] = | |
| 580 |         @{thm Network} |> simplify (@{simpset} addsimps @{thms network_spec_simps})
 | |
| 21632 | 581 | |> list_of_Int; | 
| 582 | ||
| 583 | bind_thm ("Network_Ask", Network_Ask);
 | |
| 584 | bind_thm ("Network_Giv", Network_Giv);
 | |
| 585 | bind_thm ("Network_Rel", Network_Rel);
 | |
| 586 | bind_thm ("Network_AllowedActs", Network_AllowedActs);
 | |
| 587 | bind_thm ("Network_preserves_allocGiv", Network_preserves_allocGiv);
 | |
| 588 | bind_thm ("Network_preserves_rel", Network_preserves_rel);
 | |
| 589 | bind_thm ("Network_preserves_ask", Network_preserves_ask);
 | |
| 590 | *} | |
| 591 | ||
| 592 | declare Network_preserves_allocGiv [iff] | |
| 593 | ||
| 594 | declare | |
| 595 | Network_preserves_rel [simp] | |
| 596 | Network_preserves_ask [simp] | |
| 597 | ||
| 598 | declare | |
| 599 | Network_preserves_rel [simplified o_def, simp] | |
| 600 | Network_preserves_ask [simplified o_def, simp] | |
| 601 | ||
| 21710 | 602 | text{*Alloc : <unfolded specification> *}
 | 
| 21632 | 603 | lemmas alloc_spec_simps = | 
| 604 | alloc_spec_def alloc_increasing_def alloc_safety_def | |
| 605 | alloc_progress_def alloc_allowed_acts_def alloc_preserves_def | |
| 606 | ||
| 607 | ML {*
 | |
| 608 | val [Alloc_Increasing_0, Alloc_Safety, Alloc_Progress, Alloc_AllowedActs, | |
| 24147 | 609 | Alloc_preserves_allocRel, Alloc_preserves_allocAsk, | 
| 610 | Alloc_preserves_dummy] = | |
| 611 |         @{thm Alloc} |> simplify (@{simpset} addsimps @{thms alloc_spec_simps})
 | |
| 21632 | 612 | |> list_of_Int; | 
| 613 | ||
| 614 | bind_thm ("Alloc_Increasing_0", Alloc_Increasing_0);
 | |
| 615 | bind_thm ("Alloc_Safety", Alloc_Safety);
 | |
| 616 | bind_thm ("Alloc_Progress", Alloc_Progress);
 | |
| 617 | bind_thm ("Alloc_AllowedActs", Alloc_AllowedActs);
 | |
| 618 | bind_thm ("Alloc_preserves_allocRel", Alloc_preserves_allocRel);
 | |
| 619 | bind_thm ("Alloc_preserves_allocAsk", Alloc_preserves_allocAsk);
 | |
| 620 | bind_thm ("Alloc_preserves_dummy", Alloc_preserves_dummy);
 | |
| 621 | *} | |
| 622 | ||
| 21710 | 623 | text{*Strip off the INT in the guarantees postcondition*}
 | 
| 24147 | 624 | |
| 625 | lemmas Alloc_Increasing = Alloc_Increasing_0 [normalized] | |
| 21632 | 626 | |
| 627 | declare | |
| 628 | Alloc_preserves_allocRel [iff] | |
| 629 | Alloc_preserves_allocAsk [iff] | |
| 630 | Alloc_preserves_dummy [iff] | |
| 631 | ||
| 632 | ||
| 21710 | 633 | subsection{*Components Lemmas [MUST BE AUTOMATED]*}
 | 
| 21632 | 634 | |
| 24147 | 635 | lemma Network_component_System: "Network Join | 
| 636 | ((rename sysOfClient | |
| 637 | (plam x: (lessThan Nclients). rename client_map Client)) Join | |
| 638 | rename sysOfAlloc Alloc) | |
| 21632 | 639 | = System" | 
| 21710 | 640 | by (simp add: System_def Join_ac) | 
| 21632 | 641 | |
| 24147 | 642 | lemma Client_component_System: "(rename sysOfClient | 
| 643 | (plam x: (lessThan Nclients). rename client_map Client)) Join | |
| 21632 | 644 | (Network Join rename sysOfAlloc Alloc) = System" | 
| 21710 | 645 | by (simp add: System_def Join_ac) | 
| 21632 | 646 | |
| 24147 | 647 | lemma Alloc_component_System: "rename sysOfAlloc Alloc Join | 
| 648 | ((rename sysOfClient (plam x: (lessThan Nclients). rename client_map Client)) Join | |
| 21632 | 649 | Network) = System" | 
| 21710 | 650 | by (simp add: System_def Join_ac) | 
| 21632 | 651 | |
| 652 | declare | |
| 653 | Client_component_System [iff] | |
| 654 | Network_component_System [iff] | |
| 655 | Alloc_component_System [iff] | |
| 656 | ||
| 21710 | 657 | |
| 658 | text{** These preservation laws should be generated automatically **}
 | |
| 21632 | 659 | |
| 660 | lemma Client_Allowed [simp]: "Allowed Client = preserves rel Int preserves ask" | |
| 21710 | 661 | by (auto simp add: Allowed_def Client_AllowedActs safety_prop_Acts_iff) | 
| 21632 | 662 | |
| 24147 | 663 | lemma Network_Allowed [simp]: "Allowed Network = | 
| 664 | preserves allocRel Int | |
| 21632 | 665 | (INT i: lessThan Nclients. preserves(giv o sub i o client))" | 
| 21710 | 666 | by (auto simp add: Allowed_def Network_AllowedActs safety_prop_Acts_iff) | 
| 21632 | 667 | |
| 668 | lemma Alloc_Allowed [simp]: "Allowed Alloc = preserves allocGiv" | |
| 21710 | 669 | by (auto simp add: Allowed_def Alloc_AllowedActs safety_prop_Acts_iff) | 
| 21632 | 670 | |
| 21710 | 671 | text{*needed in @{text rename_client_map_tac}*}
 | 
| 21632 | 672 | lemma OK_lift_rename_Client [simp]: "OK I (%i. lift i (rename client_map Client))" | 
| 673 | apply (rule OK_lift_I) | |
| 674 | apply auto | |
| 675 | apply (drule_tac w1 = rel in subset_preserves_o [THEN [2] rev_subsetD]) | |
| 676 | apply (drule_tac [2] w1 = ask in subset_preserves_o [THEN [2] rev_subsetD]) | |
| 677 | apply (auto simp add: o_def split_def) | |
| 678 | done | |
| 679 | ||
| 21710 | 680 | lemma fst_lift_map_eq_fst [simp]: "fst (lift_map i x) i = fst x" | 
| 681 | apply (insert fst_o_lift_map [of i]) | |
| 24147 | 682 | apply (drule fun_cong [where x=x]) | 
| 40702 | 683 | apply (simp add: o_def) | 
| 21710 | 684 | done | 
| 685 | ||
| 686 | lemma fst_o_lift_map' [simp]: | |
| 687 | "(f \<circ> sub i \<circ> fst \<circ> lift_map i \<circ> g) = f o fst o g" | |
| 24147 | 688 | apply (subst fst_o_lift_map [symmetric]) | 
| 689 | apply (simp only: o_assoc) | |
| 21710 | 690 | done | 
| 691 | ||
| 21632 | 692 | |
| 693 | (*The proofs of rename_Client_Increasing, rename_Client_Bounded and | |
| 694 | rename_Client_Progress are similar. All require copying out the original | |
| 695 | Client property. A forward proof can be constructed as follows: | |
| 696 | ||
| 697 | Client_Increasing_ask RS | |
| 698 | (bij_client_map RS rename_rename_guarantees_eq RS iffD2) | |
| 699 | RS (lift_lift_guarantees_eq RS iffD2) | |
| 700 | RS guarantees_PLam_I | |
| 701 | RS (bij_sysOfClient RS rename_rename_guarantees_eq RS iffD2) | |
| 24147 | 702 | |> simplify (simpset() addsimps [lift_image_eq_rename, o_def, split_def, | 
| 40702 | 703 | surj_rename]) | 
| 21632 | 704 | |
| 705 | However, the "preserves" property remains to be discharged, and the unfolding | |
| 706 | of "o" and "sub" complicates subsequent reasoning. | |
| 707 | ||
| 708 | The following tactic works for all three proofs, though it certainly looks | |
| 709 | ad-hoc! | |
| 710 | *) | |
| 711 | ML | |
| 712 | {*
 | |
| 24147 | 713 | fun rename_client_map_tac ss = | 
| 21632 | 714 | EVERY [ | 
| 25995 
21b51f748daf
rename_client_map_tac: avoid ill-defined thm reference;
 wenzelm parents: 
24147diff
changeset | 715 |     simp_tac (ss addsimps [@{thm rename_guarantees_eq_rename_inv}]) 1,
 | 
| 24147 | 716 |     rtac @{thm guarantees_PLam_I} 1,
 | 
| 21632 | 717 | assume_tac 2, | 
| 24147 | 718 | (*preserves: routine reasoning*) | 
| 719 |     asm_simp_tac (ss addsimps [@{thm lift_preserves_sub}]) 2,
 | |
| 720 | (*the guarantee for "lift i (rename client_map Client)" *) | |
| 21632 | 721 | asm_simp_tac | 
| 24147 | 722 |         (ss addsimps [@{thm lift_guarantees_eq_lift_inv},
 | 
| 723 |                       @{thm rename_guarantees_eq_rename_inv},
 | |
| 40702 | 724 |                       @{thm bij_imp_bij_inv}, @{thm surj_rename},
 | 
| 24147 | 725 |                       @{thm inv_inv_eq}]) 1,
 | 
| 21632 | 726 | asm_simp_tac | 
| 24147 | 727 |         (@{simpset} addsimps [@{thm o_def}, @{thm non_dummy_def}, @{thm guarantees_Int_right}]) 1]
 | 
| 21632 | 728 | *} | 
| 729 | ||
| 24147 | 730 | method_setup rename_client_map = {*
 | 
| 30549 | 731 | Scan.succeed (fn ctxt => | 
| 32149 
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
 wenzelm parents: 
32139diff
changeset | 732 | SIMPLE_METHOD (rename_client_map_tac (simpset_of ctxt))) | 
| 42814 | 733 | *} | 
| 24147 | 734 | |
| 21710 | 735 | text{*Lifting @{text Client_Increasing} to @{term systemState}*}
 | 
| 24147 | 736 | lemma rename_Client_Increasing: "i : I | 
| 737 | ==> rename sysOfClient (plam x: I. rename client_map Client) : | |
| 738 | UNIV guarantees | |
| 739 | Increasing (ask o sub i o client) Int | |
| 21632 | 740 | Increasing (rel o sub i o client)" | 
| 24147 | 741 | by rename_client_map | 
| 21632 | 742 | |
| 24147 | 743 | lemma preserves_sub_fst_lift_map: "[| F : preserves w; i ~= j |] | 
| 21632 | 744 | ==> F : preserves (sub i o fst o lift_map j o funPair v w)" | 
| 745 | apply (auto simp add: lift_map_def split_def linorder_neq_iff o_def) | |
| 746 | apply (drule_tac [!] subset_preserves_o [THEN [2] rev_subsetD]) | |
| 747 | apply (auto simp add: o_def) | |
| 748 | done | |
| 749 | ||
| 24147 | 750 | lemma client_preserves_giv_oo_client_map: "[| i < Nclients; j < Nclients |] | 
| 21632 | 751 | ==> Client : preserves (giv o sub i o fst o lift_map j o client_map)" | 
| 46911 | 752 | apply (cases "i=j") | 
| 21710 | 753 | apply (simp, simp add: o_def non_dummy_def) | 
| 21632 | 754 | apply (drule Client_preserves_dummy [THEN preserves_sub_fst_lift_map]) | 
| 755 | apply (drule_tac [!] subset_preserves_o [THEN [2] rev_subsetD]) | |
| 756 | apply (simp add: o_def client_map_def) | |
| 757 | done | |
| 758 | ||
| 759 | lemma rename_sysOfClient_ok_Network: | |
| 24147 | 760 | "rename sysOfClient (plam x: lessThan Nclients. rename client_map Client) | 
| 21632 | 761 | ok Network" | 
| 21710 | 762 | by (auto simp add: ok_iff_Allowed client_preserves_giv_oo_client_map) | 
| 21632 | 763 | |
| 764 | lemma rename_sysOfClient_ok_Alloc: | |
| 24147 | 765 | "rename sysOfClient (plam x: lessThan Nclients. rename client_map Client) | 
| 21632 | 766 | ok rename sysOfAlloc Alloc" | 
| 21710 | 767 | by (simp add: ok_iff_Allowed) | 
| 21632 | 768 | |
| 769 | lemma rename_sysOfAlloc_ok_Network: "rename sysOfAlloc Alloc ok Network" | |
| 21710 | 770 | by (simp add: ok_iff_Allowed) | 
| 21632 | 771 | |
| 772 | declare | |
| 773 | rename_sysOfClient_ok_Network [iff] | |
| 774 | rename_sysOfClient_ok_Alloc [iff] | |
| 775 | rename_sysOfAlloc_ok_Network [iff] | |
| 776 | ||
| 24147 | 777 | text{*The "ok" laws, re-oriented.
 | 
| 21710 | 778 |   But not sure this works: theorem @{text ok_commute} is needed below*}
 | 
| 21632 | 779 | declare | 
| 780 | rename_sysOfClient_ok_Network [THEN ok_sym, iff] | |
| 781 | rename_sysOfClient_ok_Alloc [THEN ok_sym, iff] | |
| 782 | rename_sysOfAlloc_ok_Network [THEN ok_sym] | |
| 783 | ||
| 784 | lemma System_Increasing: "i < Nclients | |
| 24147 | 785 | ==> System : Increasing (ask o sub i o client) Int | 
| 21632 | 786 | Increasing (rel o sub i o client)" | 
| 787 | apply (rule component_guaranteesD [OF rename_Client_Increasing Client_component_System]) | |
| 788 | apply auto | |
| 789 | done | |
| 790 | ||
| 791 | lemmas rename_guarantees_sysOfAlloc_I = | |
| 45605 | 792 | bij_sysOfAlloc [THEN rename_rename_guarantees_eq, THEN iffD2] | 
| 21632 | 793 | |
| 794 | ||
| 795 | (*Lifting Alloc_Increasing up to the level of systemState*) | |
| 21710 | 796 | lemmas rename_Alloc_Increasing = | 
| 797 | Alloc_Increasing | |
| 24147 | 798 | [THEN rename_guarantees_sysOfAlloc_I, | 
| 40702 | 799 | simplified surj_rename o_def sub_apply | 
| 24147 | 800 | rename_image_Increasing bij_sysOfAlloc | 
| 40702 | 801 | allocGiv_o_inv_sysOfAlloc_eq'] | 
| 21632 | 802 | |
| 24147 | 803 | lemma System_Increasing_allocGiv: | 
| 21632 | 804 | "i < Nclients ==> System : Increasing (sub i o allocGiv)" | 
| 805 | apply (unfold System_def) | |
| 806 | apply (simp add: o_def) | |
| 807 | apply (rule rename_Alloc_Increasing [THEN guarantees_Join_I1, THEN guaranteesD]) | |
| 808 | apply auto | |
| 809 | done | |
| 21710 | 810 | |
| 21632 | 811 | |
| 812 | ML {*
 | |
| 39159 | 813 | bind_thms ("System_Increasing'", list_of_Int @{thm System_Increasing})
 | 
| 21632 | 814 | *} | 
| 815 | ||
| 816 | declare System_Increasing' [intro!] | |
| 817 | ||
| 21710 | 818 | text{* Follows consequences.
 | 
| 21632 | 819 | The "Always (INT ...) formulation expresses the general safety property | 
| 21710 | 820 |     and allows it to be combined using @{text Always_Int_rule} below. *}
 | 
| 21632 | 821 | |
| 24147 | 822 | lemma System_Follows_rel: | 
| 21632 | 823 | "i < Nclients ==> System : ((sub i o allocRel) Fols (rel o sub i o client))" | 
| 824 | apply (auto intro!: Network_Rel [THEN component_guaranteesD]) | |
| 24147 | 825 | apply (simp add: ok_commute [of Network]) | 
| 21710 | 826 | done | 
| 21632 | 827 | |
| 24147 | 828 | lemma System_Follows_ask: | 
| 21632 | 829 | "i < Nclients ==> System : ((sub i o allocAsk) Fols (ask o sub i o client))" | 
| 21710 | 830 | apply (auto intro!: Network_Ask [THEN component_guaranteesD]) | 
| 24147 | 831 | apply (simp add: ok_commute [of Network]) | 
| 21632 | 832 | done | 
| 833 | ||
| 24147 | 834 | lemma System_Follows_allocGiv: | 
| 21632 | 835 | "i < Nclients ==> System : (giv o sub i o client) Fols (sub i o allocGiv)" | 
| 836 | apply (auto intro!: Network_Giv [THEN component_guaranteesD] | |
| 837 | rename_Alloc_Increasing [THEN component_guaranteesD]) | |
| 21710 | 838 | apply (simp_all add: o_def non_dummy_def ok_commute [of Network]) | 
| 21632 | 839 | apply (auto intro!: rename_Alloc_Increasing [THEN component_guaranteesD]) | 
| 840 | done | |
| 21710 | 841 | |
| 21632 | 842 | |
| 24147 | 843 | lemma Always_giv_le_allocGiv: "System : Always (INT i: lessThan Nclients. | 
| 21710 | 844 |                        {s. (giv o sub i o client) s \<le> (sub i o allocGiv) s})"
 | 
| 21632 | 845 | apply auto | 
| 846 | apply (erule System_Follows_allocGiv [THEN Follows_Bounded]) | |
| 847 | done | |
| 21710 | 848 | |
| 21632 | 849 | |
| 24147 | 850 | lemma Always_allocAsk_le_ask: "System : Always (INT i: lessThan Nclients. | 
| 21710 | 851 |                        {s. (sub i o allocAsk) s \<le> (ask o sub i o client) s})"
 | 
| 21632 | 852 | apply auto | 
| 853 | apply (erule System_Follows_ask [THEN Follows_Bounded]) | |
| 854 | done | |
| 21710 | 855 | |
| 21632 | 856 | |
| 24147 | 857 | lemma Always_allocRel_le_rel: "System : Always (INT i: lessThan Nclients. | 
| 21710 | 858 |                        {s. (sub i o allocRel) s \<le> (rel o sub i o client) s})"
 | 
| 859 | by (auto intro!: Follows_Bounded System_Follows_rel) | |
| 860 | ||
| 21632 | 861 | |
| 21710 | 862 | subsection{*Proof of the safety property (1)*}
 | 
| 21632 | 863 | |
| 21710 | 864 | text{*safety (1), step 1 is @{text System_Follows_rel}*}
 | 
| 21632 | 865 | |
| 21710 | 866 | text{*safety (1), step 2*}
 | 
| 21632 | 867 | (* i < Nclients ==> System : Increasing (sub i o allocRel) *) | 
| 45605 | 868 | lemmas System_Increasing_allocRel = System_Follows_rel [THEN Follows_Increasing1] | 
| 21632 | 869 | |
| 870 | (*Lifting Alloc_safety up to the level of systemState. | |
| 21710 | 871 | Simplifying with o_def gets rid of the translations but it unfortunately | 
| 21632 | 872 | gets rid of the other "o"s too.*) | 
| 873 | ||
| 21710 | 874 | text{*safety (1), step 3*}
 | 
| 24147 | 875 | lemma System_sum_bounded: | 
| 21710 | 876 |     "System : Always {s. (\<Sum>i \<in> lessThan Nclients. (tokens o sub i o allocGiv) s)
 | 
| 877 | \<le> NbT + (\<Sum>i \<in> lessThan Nclients. (tokens o sub i o allocRel) s)}" | |
| 21632 | 878 | apply (simp add: o_apply) | 
| 24147 | 879 | apply (insert Alloc_Safety [THEN rename_guarantees_sysOfAlloc_I]) | 
| 40702 | 880 | apply (simp add: o_def) | 
| 24147 | 881 | apply (erule component_guaranteesD) | 
| 21710 | 882 | apply (auto simp add: System_Increasing_allocRel [simplified sub_apply o_def]) | 
| 21632 | 883 | done | 
| 884 | ||
| 21710 | 885 | text{* Follows reasoning*}
 | 
| 21632 | 886 | |
| 24147 | 887 | lemma Always_tokens_giv_le_allocGiv: "System : Always (INT i: lessThan Nclients. | 
| 888 |                           {s. (tokens o giv o sub i o client) s
 | |
| 21710 | 889 | \<le> (tokens o sub i o allocGiv) s})" | 
| 21632 | 890 | apply (rule Always_giv_le_allocGiv [THEN Always_weaken]) | 
| 891 | apply (auto intro: tokens_mono_prefix simp add: o_apply) | |
| 892 | done | |
| 893 | ||
| 24147 | 894 | lemma Always_tokens_allocRel_le_rel: "System : Always (INT i: lessThan Nclients. | 
| 895 |                           {s. (tokens o sub i o allocRel) s
 | |
| 21710 | 896 | \<le> (tokens o rel o sub i o client) s})" | 
| 21632 | 897 | apply (rule Always_allocRel_le_rel [THEN Always_weaken]) | 
| 898 | apply (auto intro: tokens_mono_prefix simp add: o_apply) | |
| 899 | done | |
| 900 | ||
| 21710 | 901 | text{*safety (1), step 4 (final result!) *}
 | 
| 902 | theorem System_safety: "System : system_safety" | |
| 21632 | 903 | apply (unfold system_safety_def) | 
| 39159 | 904 |   apply (tactic {* rtac (Always_Int_rule [@{thm System_sum_bounded},
 | 
| 905 |     @{thm Always_tokens_giv_le_allocGiv}, @{thm Always_tokens_allocRel_le_rel}] RS
 | |
| 906 |     @{thm Always_weaken}) 1 *})
 | |
| 21632 | 907 | apply auto | 
| 908 | apply (rule setsum_fun_mono [THEN order_trans]) | |
| 909 | apply (drule_tac [2] order_trans) | |
| 910 | apply (rule_tac [2] add_le_mono [OF order_refl setsum_fun_mono]) | |
| 911 | prefer 3 apply assumption | |
| 912 | apply auto | |
| 913 | done | |
| 914 | ||
| 21710 | 915 | subsection {* Proof of the progress property (2) *}
 | 
| 21632 | 916 | |
| 21710 | 917 | text{*progress (2), step 1 is @{text System_Follows_ask} and
 | 
| 918 |       @{text System_Follows_rel}*}
 | |
| 21632 | 919 | |
| 21710 | 920 | text{*progress (2), step 2; see also @{text System_Increasing_allocRel}*}
 | 
| 21632 | 921 | (* i < Nclients ==> System : Increasing (sub i o allocAsk) *) | 
| 45605 | 922 | lemmas System_Increasing_allocAsk = System_Follows_ask [THEN Follows_Increasing1] | 
| 21632 | 923 | |
| 21710 | 924 | text{*progress (2), step 3: lifting @{text Client_Bounded} to systemState*}
 | 
| 24147 | 925 | lemma rename_Client_Bounded: "i : I | 
| 926 | ==> rename sysOfClient (plam x: I. rename client_map Client) : | |
| 927 | UNIV guarantees | |
| 21710 | 928 |           Always {s. ALL elt : set ((ask o sub i o client) s). elt \<le> NbT}"
 | 
| 24147 | 929 | by rename_client_map | 
| 21710 | 930 | |
| 21632 | 931 | |
| 24147 | 932 | lemma System_Bounded_ask: "i < Nclients | 
| 933 | ==> System : Always | |
| 21710 | 934 |                     {s. ALL elt : set ((ask o sub i o client) s). elt \<le> NbT}"
 | 
| 21632 | 935 | apply (rule component_guaranteesD [OF rename_Client_Bounded Client_component_System]) | 
| 936 | apply auto | |
| 937 | done | |
| 938 | ||
| 939 | lemma Collect_all_imp_eq: "{x. ALL y. P y --> Q x y} = (INT y: {y. P y}. {x. Q x y})"
 | |
| 940 | apply blast | |
| 941 | done | |
| 942 | ||
| 21710 | 943 | text{*progress (2), step 4*}
 | 
| 24147 | 944 | lemma System_Bounded_allocAsk: "System : Always {s. ALL i<Nclients.
 | 
| 21710 | 945 | ALL elt : set ((sub i o allocAsk) s). elt \<le> NbT}" | 
| 21632 | 946 | apply (auto simp add: Collect_all_imp_eq) | 
| 39159 | 947 |   apply (tactic {* rtac (Always_Int_rule [@{thm Always_allocAsk_le_ask},
 | 
| 948 |     @{thm System_Bounded_ask}] RS @{thm Always_weaken}) 1 *})
 | |
| 21632 | 949 | apply (auto dest: set_mono) | 
| 950 | done | |
| 951 | ||
| 21710 | 952 | text{*progress (2), step 5 is @{text System_Increasing_allocGiv}*}
 | 
| 21632 | 953 | |
| 21710 | 954 | text{*progress (2), step 6*}
 | 
| 21632 | 955 | (* i < Nclients ==> System : Increasing (giv o sub i o client) *) | 
| 45605 | 956 | lemmas System_Increasing_giv = System_Follows_allocGiv [THEN Follows_Increasing1] | 
| 21632 | 957 | |
| 958 | ||
| 24147 | 959 | lemma rename_Client_Progress: "i: I | 
| 960 | ==> rename sysOfClient (plam x: I. rename client_map Client) | |
| 961 | : Increasing (giv o sub i o client) | |
| 962 | guarantees | |
| 963 |           (INT h. {s. h \<le> (giv o sub i o client) s &
 | |
| 964 | h pfixGe (ask o sub i o client) s} | |
| 21710 | 965 |                   LeadsTo {s. tokens h \<le> (tokens o rel o sub i o client) s})"
 | 
| 24147 | 966 | apply rename_client_map | 
| 21632 | 967 | apply (simp add: Client_Progress [simplified o_def]) | 
| 968 | done | |
| 969 | ||
| 970 | ||
| 21710 | 971 | text{*progress (2), step 7*}
 | 
| 24147 | 972 | lemma System_Client_Progress: | 
| 973 | "System : (INT i : (lessThan Nclients). | |
| 974 |             INT h. {s. h \<le> (giv o sub i o client) s &
 | |
| 975 | h pfixGe (ask o sub i o client) s} | |
| 21710 | 976 |                 LeadsTo {s. tokens h \<le> (tokens o rel o sub i o client) s})"
 | 
| 21632 | 977 | apply (rule INT_I) | 
| 978 | (*Couldn't have just used Auto_tac since the "INT h" must be kept*) | |
| 979 | apply (rule component_guaranteesD [OF rename_Client_Progress Client_component_System]) | |
| 980 | apply (auto simp add: System_Increasing_giv) | |
| 981 | done | |
| 982 | ||
| 983 | (*Concludes | |
| 24147 | 984 |  System : {s. k \<le> (sub i o allocGiv) s}
 | 
| 21632 | 985 | LeadsTo | 
| 21710 | 986 |           {s. (sub i o allocAsk) s \<le> (ask o sub i o client) s} Int
 | 
| 987 |           {s. k \<le> (giv o sub i o client) s} *)
 | |
| 21632 | 988 | |
| 21710 | 989 | lemmas System_lemma1 = | 
| 990 | Always_LeadsToD [OF System_Follows_ask [THEN Follows_Bounded] | |
| 991 | System_Follows_allocGiv [THEN Follows_LeadsTo]] | |
| 21632 | 992 | |
| 21710 | 993 | lemmas System_lemma2 = | 
| 994 | PSP_Stable [OF System_lemma1 | |
| 24147 | 995 | System_Follows_ask [THEN Follows_Increasing1, THEN IncreasingD]] | 
| 21710 | 996 | |
| 997 | ||
| 24147 | 998 | lemma System_lemma3: "i < Nclients | 
| 999 |       ==> System : {s. h \<le> (sub i o allocGiv) s &
 | |
| 1000 | h pfixGe (sub i o allocAsk) s} | |
| 1001 | LeadsTo | |
| 1002 |                    {s. h \<le> (giv o sub i o client) s &
 | |
| 21632 | 1003 | h pfixGe (ask o sub i o client) s}" | 
| 1004 | apply (rule single_LeadsTo_I) | |
| 45600 
1bbbac9a0cb0
'lemmas' / 'theorems' commands allow 'for' fixes and standardize the result before storing;
 wenzelm parents: 
44871diff
changeset | 1005 | apply (rule_tac k1 = h and x1 = "(sub i o allocAsk) s" | 
| 21710 | 1006 | in System_lemma2 [THEN LeadsTo_weaken]) | 
| 21632 | 1007 | apply auto | 
| 21710 | 1008 | apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] prefix_imp_pfixGe) | 
| 21632 | 1009 | done | 
| 1010 | ||
| 1011 | ||
| 21710 | 1012 | text{*progress (2), step 8: Client i's "release" action is visible system-wide*}
 | 
| 24147 | 1013 | lemma System_Alloc_Client_Progress: "i < Nclients | 
| 1014 |       ==> System : {s. h \<le> (sub i o allocGiv) s &
 | |
| 1015 | h pfixGe (sub i o allocAsk) s} | |
| 21710 | 1016 |                    LeadsTo {s. tokens h \<le> (tokens o sub i o allocRel) s}"
 | 
| 21632 | 1017 | apply (rule LeadsTo_Trans) | 
| 1018 | prefer 2 | |
| 1019 | apply (drule System_Follows_rel [THEN | |
| 1020 | mono_tokens [THEN mono_Follows_o, THEN [2] rev_subsetD], | |
| 1021 | THEN Follows_LeadsTo]) | |
| 1022 | apply (simp add: o_assoc) | |
| 1023 | apply (rule LeadsTo_Trans) | |
| 1024 | apply (cut_tac [2] System_Client_Progress) | |
| 1025 | prefer 2 | |
| 1026 | apply (blast intro: LeadsTo_Basis) | |
| 21710 | 1027 | apply (erule System_lemma3) | 
| 21632 | 1028 | done | 
| 1029 | ||
| 21710 | 1030 | text{*Lifting @{text Alloc_Progress} up to the level of systemState*}
 | 
| 21632 | 1031 | |
| 21710 | 1032 | text{*progress (2), step 9*}
 | 
| 24147 | 1033 | lemma System_Alloc_Progress: | 
| 1034 | "System : (INT i : (lessThan Nclients). | |
| 1035 |             INT h. {s. h \<le> (sub i o allocAsk) s}
 | |
| 21632 | 1036 |                    LeadsTo {s. h pfixLe (sub i o allocGiv) s})"
 | 
| 1037 | apply (simp only: o_apply sub_def) | |
| 24147 | 1038 | apply (insert Alloc_Progress [THEN rename_guarantees_sysOfAlloc_I]) | 
| 32139 | 1039 | apply (simp add: o_def del: INT_iff) | 
| 21710 | 1040 | apply (erule component_guaranteesD) | 
| 24147 | 1041 | apply (auto simp add: | 
| 21710 | 1042 | System_Increasing_allocRel [simplified sub_apply o_def] | 
| 1043 | System_Increasing_allocAsk [simplified sub_apply o_def] | |
| 1044 | System_Bounded_allocAsk [simplified sub_apply o_def] | |
| 1045 | System_Alloc_Client_Progress [simplified sub_apply o_def]) | |
| 21632 | 1046 | done | 
| 1047 | ||
| 21710 | 1048 | text{*progress (2), step 10 (final result!) *}
 | 
| 21632 | 1049 | lemma System_Progress: "System : system_progress" | 
| 1050 | apply (unfold system_progress_def) | |
| 1051 | apply (cut_tac System_Alloc_Progress) | |
| 1052 | apply (blast intro: LeadsTo_Trans | |
| 1053 | System_Follows_allocGiv [THEN Follows_LeadsTo_pfixLe] | |
| 1054 | System_Follows_ask [THEN Follows_LeadsTo]) | |
| 1055 | done | |
| 1056 | ||
| 1057 | ||
| 21710 | 1058 | theorem System_correct: "System : system_spec" | 
| 21632 | 1059 | apply (unfold system_spec_def) | 
| 1060 | apply (blast intro: System_safety System_Progress) | |
| 1061 | done | |
| 1062 | ||
| 1063 | ||
| 21710 | 1064 | text{* Some obsolete lemmas *}
 | 
| 21632 | 1065 | |
| 24147 | 1066 | lemma non_dummy_eq_o_funPair: "non_dummy = (% (g,a,r). (| giv = g, ask = a, rel = r |)) o | 
| 21632 | 1067 | (funPair giv (funPair ask rel))" | 
| 1068 | apply (rule ext) | |
| 1069 | apply (auto simp add: o_def non_dummy_def) | |
| 1070 | done | |
| 1071 | ||
| 24147 | 1072 | lemma preserves_non_dummy_eq: "(preserves non_dummy) = | 
| 21632 | 1073 | (preserves rel Int preserves ask Int preserves giv)" | 
| 1074 | apply (simp add: non_dummy_eq_o_funPair) | |
| 1075 | apply auto | |
| 1076 | apply (drule_tac w1 = rel in subset_preserves_o [THEN [2] rev_subsetD]) | |
| 1077 | apply (drule_tac [2] w1 = ask in subset_preserves_o [THEN [2] rev_subsetD]) | |
| 1078 | apply (drule_tac [3] w1 = giv in subset_preserves_o [THEN [2] rev_subsetD]) | |
| 1079 | apply (auto simp add: o_def) | |
| 1080 | done | |
| 1081 | ||
| 21710 | 1082 | text{*Could go to Extend.ML*}
 | 
| 21632 | 1083 | lemma bij_fst_inv_inv_eq: "bij f ==> fst (inv (%(x, u). inv f x) z) = f z" | 
| 1084 | apply (rule fst_inv_equalityI) | |
| 1085 | apply (rule_tac f = "%z. (f z, ?h z) " in surjI) | |
| 1086 | apply (simp add: bij_is_inj inv_f_f) | |
| 1087 | apply (simp add: bij_is_surj surj_f_inv_f) | |
| 1088 | done | |
| 11194 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 1089 | |
| 
ea13ff5a26d1
reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
 paulson parents: diff
changeset | 1090 | end |