src/HOL/UNITY/AllocImpl.thy
changeset 10064 1a77667b21ef
parent 9403 aad13b59b8d9
equal deleted inserted replaced
10063:947ee8608b90 10064:1a77667b21ef
    56 (** Merge specification (the number of inputs is Nclients) ***)
    56 (** Merge specification (the number of inputs is Nclients) ***)
    57 
    57 
    58   (*spec (10)*)
    58   (*spec (10)*)
    59   merge_increasing :: ('a,'b) merge_d program set
    59   merge_increasing :: ('a,'b) merge_d program set
    60     "merge_increasing ==
    60     "merge_increasing ==
    61          UNIV guarantees[funPair merge.Out merge.iOut]
    61          UNIV guarantees (Increasing merge.Out) Int (Increasing merge.iOut)"
    62          (Increasing merge.Out) Int (Increasing merge.iOut)"
       
    63 
    62 
    64   (*spec (11)*)
    63   (*spec (11)*)
    65   merge_eqOut :: ('a,'b) merge_d program set
    64   merge_eqOut :: ('a,'b) merge_d program set
    66     "merge_eqOut ==
    65     "merge_eqOut ==
    67          UNIV guarantees[funPair merge.Out merge.iOut]
    66          UNIV guarantees
    68          Always {s. length (merge.Out s) = length (merge.iOut s)}"
    67          Always {s. length (merge.Out s) = length (merge.iOut s)}"
    69 
    68 
    70   (*spec (12)*)
    69   (*spec (12)*)
    71   merge_bounded :: ('a,'b) merge_d program set
    70   merge_bounded :: ('a,'b) merge_d program set
    72     "merge_bounded ==
    71     "merge_bounded ==
    73          UNIV guarantees[merge.iOut]
    72          UNIV guarantees
    74          Always {s. ALL elt : set (merge.iOut s). elt < Nclients}"
    73          Always {s. ALL elt : set (merge.iOut s). elt < Nclients}"
    75 
    74 
    76   (*spec (13)*)
    75   (*spec (13)*)
    77   merge_follows :: ('a,'b) merge_d program set
    76   merge_follows :: ('a,'b) merge_d program set
    78     "merge_follows ==
    77     "merge_follows ==
    79 	 (INT i : lessThan Nclients. Increasing (sub i o merge.In))
    78 	 (INT i : lessThan Nclients. Increasing (sub i o merge.In))
    80 	 guarantees[funPair merge.Out merge.iOut]
    79 	 guarantees
    81 	 (INT i : lessThan Nclients. 
    80 	 (INT i : lessThan Nclients. 
    82 	  (%s. sublist (merge.Out s) 
    81 	  (%s. sublist (merge.Out s) 
    83                        {k. k < size(merge.iOut s) & merge.iOut s! k = i})
    82                        {k. k < size(merge.iOut s) & merge.iOut s! k = i})
    84 	  Fols (sub i o merge.In))"
    83 	  Fols (sub i o merge.In))"
    85 
    84 
    86   (*spec: preserves part*)
    85   (*spec: preserves part*)
    87     merge_preserves :: ('a,'b) merge_d program set
    86   merge_preserves :: ('a,'b) merge_d program set
    88     "merge_preserves == preserves (funPair merge.In merge_d.dummy)"
    87     "merge_preserves == preserves merge.In Int preserves merge_d.dummy"
       
    88 
       
    89   (*environmental constraints*)
       
    90   merge_allowed_acts :: ('a,'b) merge_d program set
       
    91     "merge_allowed_acts ==
       
    92        {F. AllowedActs F =
       
    93 	    insert Id (UNION (preserves (funPair merge.Out merge.iOut)) Acts)}"
    89 
    94 
    90   merge_spec :: ('a,'b) merge_d program set
    95   merge_spec :: ('a,'b) merge_d program set
    91     "merge_spec == merge_increasing Int merge_eqOut Int merge_bounded Int
    96     "merge_spec == merge_increasing Int merge_eqOut Int merge_bounded Int
    92                    merge_follows Int merge_preserves"
    97                    merge_follows Int merge_allowed_acts Int merge_preserves"
    93 
    98 
    94 (** Distributor specification (the number of outputs is Nclients) ***)
    99 (** Distributor specification (the number of outputs is Nclients) ***)
    95 
   100 
    96   (*spec (14)*)
   101   (*spec (14)*)
    97   distr_follows :: ('a,'b) distr_d program set
   102   distr_follows :: ('a,'b) distr_d program set
    98     "distr_follows ==
   103     "distr_follows ==
    99 	 Increasing distr.In Int Increasing distr.iIn Int
   104 	 Increasing distr.In Int Increasing distr.iIn Int
   100 	 Always {s. ALL elt : set (distr.iIn s). elt < Nclients}
   105 	 Always {s. ALL elt : set (distr.iIn s). elt < Nclients}
   101 	 guarantees[distr.Out]
   106 	 guarantees
   102 	 (INT i : lessThan Nclients. 
   107 	 (INT i : lessThan Nclients. 
   103 	  (sub i o distr.Out) Fols
   108 	  (sub i o distr.Out) Fols
   104 	  (%s. sublist (distr.In s) 
   109 	  (%s. sublist (distr.In s) 
   105                        {k. k < size(distr.iIn s) & distr.iIn s ! k = i}))"
   110                        {k. k < size(distr.iIn s) & distr.iIn s ! k = i}))"
   106 
   111 
       
   112   distr_allowed_acts :: ('a,'b) distr_d program set
       
   113     "distr_allowed_acts ==
       
   114        {D. AllowedActs D = insert Id (UNION (preserves distr.Out) Acts)}"
       
   115 
       
   116   distr_spec :: ('a,'b) distr_d program set
       
   117     "distr_spec == distr_follows Int distr_allowed_acts"
   107 
   118 
   108 (** Single-client allocator specification (required) ***)
   119 (** Single-client allocator specification (required) ***)
   109 
   120 
   110   (*spec (18)*)
   121   (*spec (18)*)
   111   alloc_increasing :: 'a allocState_d program set
   122   alloc_increasing :: 'a allocState_d program set
   112     "alloc_increasing == UNIV guarantees[giv] Increasing giv"
   123     "alloc_increasing == UNIV  guarantees  Increasing giv"
   113 
   124 
   114   (*spec (19)*)
   125   (*spec (19)*)
   115   alloc_safety :: 'a allocState_d program set
   126   alloc_safety :: 'a allocState_d program set
   116     "alloc_safety ==
   127     "alloc_safety ==
   117 	 Increasing rel
   128 	 Increasing rel
   118          guarantees[giv] Always {s. tokens (giv s) <= NbT + tokens (rel s)}"
   129          guarantees  Always {s. tokens (giv s) <= NbT + tokens (rel s)}"
   119 
   130 
   120   (*spec (20)*)
   131   (*spec (20)*)
   121   alloc_progress :: 'a allocState_d program set
   132   alloc_progress :: 'a allocState_d program set
   122     "alloc_progress ==
   133     "alloc_progress ==
   123 	 Increasing ask Int Increasing rel Int
   134 	 Increasing ask Int Increasing rel Int
   124          Always {s. ALL elt : set (ask s). elt <= NbT}
   135          Always {s. ALL elt : set (ask s). elt <= NbT}
   125          Int
   136          Int
   126          (INT h. {s. h <= giv s & h pfixGe (ask s)}
   137          (INT h. {s. h <= giv s & h pfixGe (ask s)}
   127 		 LeadsTo
   138 		 LeadsTo
   128 	         {s. tokens h <= tokens (rel s)})
   139 	         {s. tokens h <= tokens (rel s)})
   129          guarantees[giv]
   140          guarantees  (INT h. {s. h <= ask s} LeadsTo {s. h pfixLe giv s})"
   130 	     (INT h. {s. h <= ask s} LeadsTo {s. h pfixLe giv s})"
       
   131 
   141 
   132   (*spec: preserves part*)
   142   (*spec: preserves part*)
   133     alloc_preserves :: 'a allocState_d program set
   143   alloc_preserves :: 'a allocState_d program set
   134     "alloc_preserves == preserves (funPair rel
   144     "alloc_preserves == preserves rel Int
   135 				   (funPair ask allocState_d.dummy))"
   145                         preserves ask Int
       
   146                         preserves allocState_d.dummy"
   136   
   147   
       
   148 
       
   149   (*environmental constraints*)
       
   150   alloc_allowed_acts :: 'a allocState_d program set
       
   151     "alloc_allowed_acts ==
       
   152        {F. AllowedActs F = insert Id (UNION (preserves giv) Acts)}"
       
   153 
   137   alloc_spec :: 'a allocState_d program set
   154   alloc_spec :: 'a allocState_d program set
   138     "alloc_spec == alloc_increasing Int alloc_safety Int alloc_progress Int
   155     "alloc_spec == alloc_increasing Int alloc_safety Int alloc_progress Int
   139                    alloc_preserves"
   156                    alloc_allowed_acts Int alloc_preserves"
       
   157 
       
   158 locale Merge =
       
   159   fixes 
       
   160     M   :: ('a,'b::order) merge_d program
       
   161   assumes
       
   162     Merge_spec  "M  : merge_spec"
       
   163 
       
   164 locale Distrib =
       
   165   fixes 
       
   166     D   :: ('a,'b::order) distr_d program
       
   167   assumes
       
   168     Distrib_spec  "D : distr_spec"
       
   169 
   140 
   170 
   141 (****
   171 (****
   142     (** Network specification ***)
   172 #  (** Network specification ***)
   143 
   173 
   144       (*spec (9.1)*)
   174 #    (*spec (9.1)*)
   145       network_ask :: 'a systemState program set
   175 #    network_ask :: 'a systemState program set
   146 	"network_ask == INT i : lessThan Nclients.
   176 #	"network_ask == INT i : lessThan Nclients.
   147 			    Increasing (ask o sub i o client)
   177 #			    Increasing (ask o sub i o client)
   148 			    guarantees[ask]
   178 #			    guarantees[ask]
   149 			    (ask  Fols (ask o sub i o client))"
   179 #			    (ask  Fols (ask o sub i o client))"
   150 
   180 
   151       (*spec (9.2)*)
   181 #    (*spec (9.2)*)
   152       network_giv :: 'a systemState program set
   182 #    network_giv :: 'a systemState program set
   153 	"network_giv == INT i : lessThan Nclients.
   183 #	"network_giv == INT i : lessThan Nclients.
   154 			    Increasing giv 
   184 #			    Increasing giv 
   155 			    guarantees[giv o sub i o client]
   185 #			    guarantees[giv o sub i o client]
   156 			    ((giv o sub i o client) Fols giv )"
   186 #			    ((giv o sub i o client) Fols giv )"
   157 
   187 
   158       (*spec (9.3)*)
   188 #    (*spec (9.3)*)
   159       network_rel :: 'a systemState program set
   189 #    network_rel :: 'a systemState program set
   160 	"network_rel == INT i : lessThan Nclients.
   190 #	"network_rel == INT i : lessThan Nclients.
   161 			    Increasing (rel o sub i o client)
   191 #			    Increasing (rel o sub i o client)
   162 			    guarantees[rel]
   192 #			    guarantees[rel]
   163 			    (rel  Fols (rel o sub i o client))"
   193 #			    (rel  Fols (rel o sub i o client))"
   164 
   194 
   165       (*spec: preserves part*)
   195 #    (*spec: preserves part*)
   166 	network_preserves :: 'a systemState program set
   196 #	network_preserves :: 'a systemState program set
   167 	"network_preserves == preserves giv  Int
   197 #	"network_preserves == preserves giv  Int
   168 			      (INT i : lessThan Nclients.
   198 #			      (INT i : lessThan Nclients.
   169 			       preserves (funPair rel ask o sub i o client))"
   199 #			       preserves (funPair rel ask o sub i o client))"
   170 
   200 
   171       network_spec :: 'a systemState program set
   201 #    network_spec :: 'a systemState program set
   172 	"network_spec == network_ask Int network_giv Int
   202 #	"network_spec == network_ask Int network_giv Int
   173 			 network_rel Int network_preserves"
   203 #			 network_rel Int network_preserves"
   174 
   204 
   175 
   205 
   176     (** State mappings **)
   206 #  (** State mappings **)
   177       sysOfAlloc :: "((nat => merge) * 'a) allocState_d => 'a systemState"
   207 #    sysOfAlloc :: "((nat => merge) * 'a) allocState_d => 'a systemState"
   178 	"sysOfAlloc == %s. let (cl,xtr) = allocState_d.dummy s
   208 #	"sysOfAlloc == %s. let (cl,xtr) = allocState_d.dummy s
   179 			   in (| giv = giv s,
   209 #			   in (| giv = giv s,
   180 				 ask = ask s,
   210 #				 ask = ask s,
   181 				 rel = rel s,
   211 #				 rel = rel s,
   182 				 client   = cl,
   212 #				 client   = cl,
   183 				 dummy    = xtr|)"
   213 #				 dummy    = xtr|)"
   184 
   214 
   185 
   215 
   186       sysOfClient :: "(nat => merge) * 'a allocState_d => 'a systemState"
   216 #    sysOfClient :: "(nat => merge) * 'a allocState_d => 'a systemState"
   187 	"sysOfClient == %(cl,al). (| giv = giv al,
   217 #	"sysOfClient == %(cl,al). (| giv = giv al,
   188 				     ask = ask al,
   218 #				     ask = ask al,
   189 				     rel = rel al,
   219 #				     rel = rel al,
   190 				     client   = cl,
   220 #				     client   = cl,
   191 				     systemState.dummy = allocState_d.dummy al|)"
   221 #				     systemState.dummy = allocState_d.dummy al|)"
   192 ****)
   222 ****)
   193 
   223 
   194 consts 
       
   195     Alloc  :: 'a allocState_d program
       
   196     Merge  :: ('a,'b) merge_d program
       
   197 
       
   198 (*    
       
   199     Network :: 'a systemState program
       
   200     System  :: 'a systemState program
       
   201   *)
       
   202   
       
   203 rules
       
   204     Alloc   "Alloc   : alloc_spec"
       
   205     Merge  "Merge  : merge_spec"
       
   206 
       
   207 (**    Network "Network : network_spec"**)
       
   208 
       
   209 
       
   210 
       
   211 end
   224 end