src/HOL/UNITY/Alloc.thy
author paulson
Thu, 26 Aug 1999 11:36:04 +0200
changeset 7361 477e1bdf230f
parent 7347 ad0ce67e4eb6
child 7537 875754b599df
permissions -rw-r--r--
changed "guar" back to "guarantees" (sorry)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/Alloc
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     2
    ID:         $Id$
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     4
    Copyright   1998  University of Cambridge
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     5
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     6
Specification of Chandy and Charpentier's Allocator
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     7
*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
     8
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
     9
Alloc = Follows + Extend + PPROD +
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    10
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    11
(*Duplicated from HOL/ex/NatSum.thy.
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    12
  Maybe type should be  [nat=>int, nat] => int**)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    13
consts sum     :: [nat=>nat, nat] => nat
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    14
primrec 
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    15
  "sum f 0 = 0"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    16
  "sum f (Suc n) = f(n) + sum f n"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    17
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    18
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    19
(*This function merely sums the elements of a list*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    20
consts tokens     :: nat list => nat
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    21
primrec 
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    22
  "tokens [] = 0"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    23
  "tokens (x#xs) = x + tokens xs"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    24
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    25
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    26
consts
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    27
  NbT      :: nat       (*Number of tokens in system*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    28
  Nclients :: nat       (*Number of clients*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    29
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    30
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    31
record clientState =
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    32
  giv :: nat list   (*client's INPUT history:  tokens GRANTED*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    33
  ask :: nat list   (*client's OUTPUT history: tokens REQUESTED*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    34
  rel :: nat list   (*client's OUTPUT history: tokens RELEASED*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    35
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    36
record allocState =
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    37
  allocGiv :: nat => nat list   (*allocator's local copy of "giv" for i*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    38
  allocAsk :: nat => nat list   (*allocator's local copy of "ask" for i*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    39
  allocRel :: nat => nat list   (*allocator's local copy of "rel" for i*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    40
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    41
record systemState = allocState +
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    42
  client :: nat => clientState  (*states of all clients*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    43
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    44
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    45
constdefs
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    46
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    47
(** Resource allocation system specification **)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    48
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    49
  (*spec (1)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    50
  system_safety :: systemState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    51
    "system_safety ==
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    52
     Always {s. sum (%i. (tokens o giv o sub i o client) s) Nclients
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    53
	        <= NbT + sum (%i. (tokens o rel o sub i o client) s) Nclients}"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    54
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    55
  (*spec (2)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    56
  system_progress :: systemState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    57
    "system_progress == INT i : lessThan Nclients.
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    58
			INT h. 
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    59
			  {s. h <= (ask o sub i o client)s} LeadsTo
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    60
			  {s. h pfixLe (giv o sub i o client) s}"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    61
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    62
  system_spec :: systemState program set
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    63
    "system_spec == system_safety Int system_progress"
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    64
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    65
(** Client specification (required) ***)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    66
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    67
  (*spec (3) PROBABLY REQUIRES A LOCALTO PRECONDITION*)
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    68
  client_increasing :: clientState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    69
    "client_increasing ==
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
    70
         UNIV guarantees Increasing ask Int Increasing rel"
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    71
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    72
  (*spec (4)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    73
  client_bounded :: clientState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    74
    "client_bounded ==
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
    75
         UNIV guarantees Always {s. ALL elt : set (ask s). elt <= NbT}"
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    76
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    77
  (*spec (5)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    78
  client_progress :: clientState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    79
    "client_progress ==
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    80
	 Increasing giv
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
    81
	 guarantees
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    82
	 (INT h. {s. h <= giv s & h pfixGe ask s}
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    83
		 LeadsTo
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    84
		 {s. tokens h <= (tokens o rel) s})"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    85
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    86
  client_spec :: clientState program set
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    87
    "client_spec == client_increasing Int client_bounded Int client_progress"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
    88
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    89
(** Allocator specification (required) ***)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    90
7347
ad0ce67e4eb6 another snapshot
paulson
parents: 7188
diff changeset
    91
  (*spec (6)  PROBABLY REQUIRES A LOCALTO PRECONDITION*)
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    92
  alloc_increasing :: allocState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    93
    "alloc_increasing ==
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    94
	 UNIV
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
    95
         guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    96
	 (INT i : lessThan Nclients. Increasing (sub i o allocAsk))"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    97
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    98
  (*spec (7)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
    99
  alloc_safety :: allocState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   100
    "alloc_safety ==
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   101
	 (INT i : lessThan Nclients. Increasing (sub i o allocRel))
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
   102
         guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   103
	 Always {s. sum (%i. (tokens o sub i o allocGiv) s) Nclients
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   104
	         <= NbT + sum (%i. (tokens o sub i o allocRel) s) Nclients}"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   105
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   106
  (*spec (8)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   107
  alloc_progress :: allocState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   108
    "alloc_progress ==
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   109
	 (INT i : lessThan Nclients. Increasing (sub i o allocAsk) Int
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   110
	                             Increasing (sub i o allocRel))
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   111
         Int
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   112
         Always {s. ALL i : lessThan Nclients.
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   113
		    ALL k : lessThan (length (allocAsk s i)).
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   114
		    allocAsk s i ! k <= NbT}
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   115
         Int
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   116
         (INT i : lessThan Nclients. 
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   117
	  INT h. {s. h <= (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s}
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   118
		  LeadsTo {s. tokens h <= (tokens o sub i o allocRel)s})
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
   119
         guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   120
	     (INT i : lessThan Nclients.
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   121
	      INT h. {s. h <= (sub i o allocAsk) s} LeadsTo
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   122
	             {s. h pfixLe (sub i o allocGiv) s})"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   123
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   124
  alloc_spec :: allocState program set
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   125
    "alloc_spec == alloc_increasing Int alloc_safety Int alloc_progress"
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   126
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   127
(** Network specification ***)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   128
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   129
  (*spec (9.1)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   130
  network_ask :: systemState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   131
    "network_ask == INT i : lessThan Nclients.
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   132
                    Increasing (ask o sub i o client)
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
   133
                    guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   134
                    ((sub i o allocAsk) Fols (ask o sub i o client))"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   135
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   136
  (*spec (9.2)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   137
  network_giv :: systemState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   138
    "network_giv == INT i : lessThan Nclients.
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   139
                    Increasing (sub i o allocGiv)
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
   140
                    guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   141
                    ((giv o sub i o client) Fols (sub i o allocGiv))"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   142
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   143
  (*spec (9.3)*)
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   144
  network_rel :: systemState program set
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   145
    "network_rel == INT i : lessThan Nclients.
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   146
                    Increasing (rel o sub i o client)
7361
477e1bdf230f changed "guar" back to "guarantees" (sorry)
paulson
parents: 7347
diff changeset
   147
                    guarantees
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   148
                    ((sub i o allocRel) Fols (rel o sub i o client))"
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   149
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   150
  network_spec :: systemState program set
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   151
    "network_spec == network_ask Int network_giv Int network_rel"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   152
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   153
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   154
(** State mappings **)
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   155
  sysOfAlloc :: "(allocState * (nat => clientState)) => systemState"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   156
    "sysOfAlloc == %(s,y). (| allocGiv = allocGiv s,
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   157
			      allocAsk = allocAsk s,
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   158
			      allocRel = allocRel s,
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   159
			      client   = y |)"
6841
5a557122bb62 renamed PPI to plam
paulson
parents: 6837
diff changeset
   160
(***    "sysOfAlloc == %(s,y). s(|client := y|)"  TYPE DOESN'T CHANGE***)
5a557122bb62 renamed PPI to plam
paulson
parents: 6837
diff changeset
   161
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   162
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   163
  sysOfClient :: "((nat => clientState) * allocState ) => systemState"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   164
    "sysOfClient == %(x,y). sysOfAlloc(y,x)"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   165
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   166
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   167
locale System =
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   168
  fixes 
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   169
    Alloc   :: allocState program
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   170
    Client  :: clientState program
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   171
    Network :: systemState program
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   172
    System  :: systemState program
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   173
  
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   174
  assumes
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   175
    Alloc   "Alloc   : alloc_spec"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   176
    Client  "Client  : client_spec"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   177
    Network "Network : network_spec"
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   178
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   179
  defines
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   180
    System_def
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   181
      "System == (extend sysOfAlloc Alloc)
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   182
                 Join
6841
5a557122bb62 renamed PPI to plam
paulson
parents: 6837
diff changeset
   183
                 (extend sysOfClient (plam x: lessThan Nclients. Client))
6827
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   184
                 Join
b69a2585ec0f guar; locale for the spec
paulson
parents: 6815
diff changeset
   185
                 Network"
6815
de4d358bf01e The Allocator example: specifications
paulson
parents:
diff changeset
   186
end