src/HOL/UNITY/Comp/AllocImpl.thy
author huffman
Sun, 09 May 2010 09:39:01 -0700
changeset 36775 ba2a7096dd2b
parent 35416 d8d7d1b785af
child 36866 426d5781bb25
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
     1
(*  Title:      HOL/UNITY/Comp/AllocImpl.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
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
     6
header{*Implementation of a multiple-client allocator from a single-client allocator*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
     7
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 15074
diff changeset
     8
theory AllocImpl imports AllocBase Follows PPROD begin
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
     9
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    10
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    11
(** State definitions.  OUTPUT variables are locals **)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    12
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    13
(*Type variable 'b is the type of items being merged*)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    14
record 'b merge =
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
    15
  In   :: "nat => 'b list"  (*merge's INPUT histories: streams to merge*)
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
    16
  Out  :: "'b list"         (*merge's OUTPUT history: merged items*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    17
  iOut :: "nat list"        (*merge's OUTPUT history: origins of merged items*)
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,'b) merge_d =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    20
  "'b merge" +
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    21
  dummy :: 'a       (*dummy field for new variables*)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    22
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 32960
diff changeset
    23
definition non_dummy :: "('a,'b) merge_d => 'b merge" where
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    24
    "non_dummy s == (|In = In s, Out = Out s, iOut = iOut s|)"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    25
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    26
record 'b distr =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    27
  In  :: "'b list"          (*items to distribute*)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    28
  iIn :: "nat list"         (*destinations of items to distribute*)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    29
  Out :: "nat => 'b list"   (*distributed items*)
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    30
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    31
record ('a,'b) distr_d =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    32
  "'b distr" +
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    33
  dummy :: 'a       (*dummy field for new variables*)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    34
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    35
record allocState =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    36
  giv :: "nat list"   (*OUTPUT history: source of tokens*)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    37
  ask :: "nat list"   (*INPUT: tokens requested from allocator*)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    38
  rel :: "nat list"   (*INPUT: tokens released to allocator*)
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 +
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    42
  dummy    :: 'a                (*dummy field for new variables*)
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 +
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    46
  mergeRel :: "nat merge"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    47
  mergeAsk :: "nat merge"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    48
  distr    :: "nat distr"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    49
  dummy    :: 'a                  (*dummy field for new variables*)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    50
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    51
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    52
constdefs
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    53
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    54
(** Merge specification (the number of inputs is Nclients) ***)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    55
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    56
  (*spec (10)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    57
  merge_increasing :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    58
    "merge_increasing ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    59
         UNIV guarantees (Increasing merge.Out) Int (Increasing merge.iOut)"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    60
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    61
  (*spec (11)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    62
  merge_eqOut :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    63
    "merge_eqOut ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    64
         UNIV guarantees
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    65
         Always {s. length (merge.Out s) = length (merge.iOut s)}"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    66
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    67
  (*spec (12)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    68
  merge_bounded :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    69
    "merge_bounded ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    70
         UNIV guarantees
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    71
         Always {s. \<forall>elt \<in> set (merge.iOut s). elt < Nclients}"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    72
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    73
  (*spec (13)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    74
  merge_follows :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    75
    "merge_follows ==
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    76
         (\<Inter>i \<in> lessThan Nclients. Increasing (sub i o merge.In))
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    77
         guarantees
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    78
         (\<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    79
          (%s. sublist (merge.Out s)
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    80
                       {k. k < size(merge.iOut s) & merge.iOut s! k = i})
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    81
          Fols (sub i o merge.In))"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    82
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    83
  (*spec: preserves part*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    84
  merge_preserves :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    85
    "merge_preserves == preserves merge.In Int preserves merge_d.dummy"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    86
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    87
  (*environmental constraints*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    88
  merge_allowed_acts :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    89
    "merge_allowed_acts ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    90
       {F. AllowedActs F =
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
    91
            insert Id (UNION (preserves (funPair merge.Out merge.iOut)) Acts)}"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    92
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
    93
  merge_spec :: "('a,'b) merge_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    94
    "merge_spec == merge_increasing Int merge_eqOut Int merge_bounded Int
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    95
                   merge_follows Int merge_allowed_acts Int merge_preserves"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    96
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    97
(** Distributor specification (the number of outputs is Nclients) ***)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    98
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
    99
  (*spec (14)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   100
  distr_follows :: "('a,'b) distr_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   101
    "distr_follows ==
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   102
         Increasing distr.In Int Increasing distr.iIn Int
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   103
         Always {s. \<forall>elt \<in> set (distr.iIn s). elt < Nclients}
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   104
         guarantees
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   105
         (\<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   106
          (sub i o distr.Out) Fols
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   107
          (%s. sublist (distr.In s)
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   108
                       {k. k < size(distr.iIn s) & distr.iIn s ! k = i}))"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   109
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   110
  distr_allowed_acts :: "('a,'b) distr_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   111
    "distr_allowed_acts ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   112
       {D. AllowedActs D = insert Id (UNION (preserves distr.Out) Acts)}"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   113
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   114
  distr_spec :: "('a,'b) distr_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   115
    "distr_spec == distr_follows Int distr_allowed_acts"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   116
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   117
(** Single-client allocator specification (required) ***)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   118
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   119
  (*spec (18)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   120
  alloc_increasing :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   121
    "alloc_increasing == UNIV  guarantees  Increasing giv"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   122
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   123
  (*spec (19)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   124
  alloc_safety :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   125
    "alloc_safety ==
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   126
         Increasing rel
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   127
         guarantees  Always {s. tokens (giv s) \<le> NbT + tokens (rel s)}"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   128
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   129
  (*spec (20)*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   130
  alloc_progress :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   131
    "alloc_progress ==
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   132
         Increasing ask Int Increasing rel Int
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   133
         Always {s. \<forall>elt \<in> set (ask s). elt \<le> NbT}
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   134
         Int
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   135
         (\<Inter>h. {s. h \<le> giv s & h pfixGe (ask s)}
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   136
                 LeadsTo
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   137
                 {s. tokens h \<le> tokens (rel s)})
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   138
         guarantees  (\<Inter>h. {s. h \<le> ask s} LeadsTo {s. h pfixLe giv s})"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   139
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   140
  (*spec: preserves part*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   141
  alloc_preserves :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   142
    "alloc_preserves == preserves rel Int
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   143
                        preserves ask Int
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   144
                        preserves allocState_d.dummy"
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   145
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   146
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   147
  (*environmental constraints*)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   148
  alloc_allowed_acts :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   149
    "alloc_allowed_acts ==
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   150
       {F. AllowedActs F = insert Id (UNION (preserves giv) Acts)}"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   151
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   152
  alloc_spec :: "'a allocState_d program set"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   153
    "alloc_spec == alloc_increasing Int alloc_safety Int alloc_progress Int
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   154
                   alloc_allowed_acts Int alloc_preserves"
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   155
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   156
locale Merge =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   157
  fixes M :: "('a,'b::order) merge_d program"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   158
  assumes
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   159
    Merge_spec:  "M  \<in> merge_spec"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   160
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   161
locale Distrib =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   162
  fixes D :: "('a,'b::order) distr_d program"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   163
  assumes
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   164
    Distrib_spec:  "D \<in> distr_spec"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   165
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   166
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   167
(****
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   168
#  {** Network specification ***}
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   169
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   170
#    {*spec (9.1)*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   171
#    network_ask :: "'a systemState program set
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   172
#       "network_ask == \<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   173
#                           Increasing (ask o sub i o client)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   174
#                           guarantees[ask]
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   175
#                           (ask  Fols (ask o sub i o client))"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   176
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   177
#    {*spec (9.2)*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   178
#    network_giv :: "'a systemState program set
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   179
#       "network_giv == \<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   180
#                           Increasing giv
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   181
#                           guarantees[giv o sub i o client]
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   182
#                           ((giv o sub i o client) Fols giv)"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   183
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   184
#    {*spec (9.3)*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   185
#    network_rel :: "'a systemState program set
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   186
#       "network_rel == \<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   187
#                           Increasing (rel o sub i o client)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   188
#                           guarantees[rel]
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   189
#                           (rel  Fols (rel o sub i o client))"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   190
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   191
#    {*spec: preserves part*}
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   192
#       network_preserves :: "'a systemState program set
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   193
#       "network_preserves == preserves giv  Int
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   194
#                             (\<Inter>i \<in> lessThan Nclients.
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   195
#                              preserves (funPair rel ask o sub i o client))"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   196
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   197
#    network_spec :: "'a systemState program set
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   198
#       "network_spec == network_ask Int network_giv Int
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   199
#                        network_rel Int network_preserves"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   200
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   201
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   202
#  {** State mappings **}
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   203
#    sysOfAlloc :: "((nat => merge) * 'a) allocState_d => 'a systemState"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   204
#       "sysOfAlloc == %s. let (cl,xtr) = allocState_d.dummy s
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   205
#                          in (| giv = giv s,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   206
#                                ask = ask s,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   207
#                                rel = rel s,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   208
#                                client   = cl,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   209
#                                dummy    = xtr|)"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   210
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   211
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   212
#    sysOfClient :: "(nat => merge) * 'a allocState_d => 'a systemState"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   213
#       "sysOfClient == %(cl,al). (| giv = giv al,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   214
#                                    ask = ask al,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   215
#                                    rel = rel al,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   216
#                                    client   = cl,
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 16417
diff changeset
   217
#                                    systemState.dummy = allocState_d.dummy al|)"
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   218
****)
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   219
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   220
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   221
declare subset_preserves_o [THEN subsetD, intro]
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   222
declare funPair_o_distrib [simp]
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   223
declare Always_INT_distrib [simp]
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   224
declare o_apply [simp del]
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   225
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   226
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   227
subsection{*Theorems for Merge*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   228
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   229
lemma (in Merge) Merge_Allowed:
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   230
     "Allowed M = (preserves merge.Out) Int (preserves merge.iOut)"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   231
apply (cut_tac Merge_spec)
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   232
apply (auto simp add: merge_spec_def merge_allowed_acts_def Allowed_def
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   233
                      safety_prop_Acts_iff)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   234
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   235
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   236
lemma (in Merge) M_ok_iff [iff]:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   237
     "M ok G = (G \<in> preserves merge.Out & G \<in> preserves merge.iOut &
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   238
                     M \<in> Allowed G)"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   239
by (auto simp add: Merge_Allowed ok_iff_Allowed)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   240
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   241
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   242
lemma (in Merge) Merge_Always_Out_eq_iOut:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   243
     "[| G \<in> preserves merge.Out; G \<in> preserves merge.iOut; M \<in> Allowed G |]
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   244
      ==> M Join G \<in> Always {s. length (merge.Out s) = length (merge.iOut s)}"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   245
apply (cut_tac Merge_spec)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   246
apply (force dest: guaranteesD simp add: merge_spec_def merge_eqOut_def)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   247
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   248
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   249
lemma (in Merge) Merge_Bounded:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   250
     "[| G \<in> preserves merge.iOut; G \<in> preserves merge.Out; M \<in> Allowed G |]
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   251
      ==> M Join G \<in> Always {s. \<forall>elt \<in> set (merge.iOut s). elt < Nclients}"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   252
apply (cut_tac Merge_spec)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   253
apply (force dest: guaranteesD simp add: merge_spec_def merge_bounded_def)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   254
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   255
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   256
lemma (in Merge) Merge_Bag_Follows_lemma:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   257
     "[| G \<in> preserves merge.iOut; G \<in> preserves merge.Out; M \<in> Allowed G |]
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   258
  ==> M Join G \<in> Always
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   259
          {s. (\<Sum>i \<in> lessThan Nclients. bag_of (sublist (merge.Out s)
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   260
                                  {k. k < length (iOut s) & iOut s ! k = i})) =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   261
              (bag_of o merge.Out) s}"
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   262
apply (rule Always_Compl_Un_eq [THEN iffD1])
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   263
apply (blast intro: Always_Int_I [OF Merge_Always_Out_eq_iOut Merge_Bounded])
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   264
apply (rule UNIV_AlwaysI, clarify)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   265
apply (subst bag_of_sublist_UN_disjoint [symmetric])
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   266
  apply (simp)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   267
 apply blast
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   268
apply (simp add: set_conv_nth)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   269
apply (subgoal_tac
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   270
       "(\<Union>i \<in> lessThan Nclients. {k. k < length (iOut x) & iOut x ! k = i}) =
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   271
       lessThan (length (iOut x))")
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   272
 apply (simp (no_asm_simp) add: o_def)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   273
apply blast
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   274
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   275
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   276
lemma (in Merge) Merge_Bag_Follows:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   277
     "M \<in> (\<Inter>i \<in> lessThan Nclients. Increasing (sub i o merge.In))
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   278
          guarantees
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   279
             (bag_of o merge.Out) Fols
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   280
             (%s. \<Sum>i \<in> lessThan Nclients. (bag_of o sub i o merge.In) s)"
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   281
apply (rule Merge_Bag_Follows_lemma [THEN Always_Follows1, THEN guaranteesI], auto)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   282
apply (rule Follows_setsum)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   283
apply (cut_tac Merge_spec)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   284
apply (auto simp add: merge_spec_def merge_follows_def o_def)
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   285
apply (drule guaranteesD)
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   286
  prefer 3
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   287
  apply (best intro: mono_bag_of [THEN mono_Follows_apply, THEN subsetD], auto)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   288
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   289
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   290
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   291
subsection{*Theorems for Distributor*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   292
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   293
lemma (in Distrib) Distr_Increasing_Out:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   294
     "D \<in> Increasing distr.In Int Increasing distr.iIn Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   295
          Always {s. \<forall>elt \<in> set (distr.iIn s). elt < Nclients}
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   296
          guarantees
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   297
          (\<Inter>i \<in> lessThan Nclients. Increasing (sub i o distr.Out))"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   298
apply (cut_tac Distrib_spec)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   299
apply (simp add: distr_spec_def distr_follows_def)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   300
apply clarify
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   301
apply (blast intro: guaranteesI Follows_Increasing1 dest: guaranteesD)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   302
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   303
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   304
lemma (in Distrib) Distr_Bag_Follows_lemma:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   305
     "[| G \<in> preserves distr.Out;
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   306
         D Join G \<in> Always {s. \<forall>elt \<in> set (distr.iIn s). elt < Nclients} |]
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   307
  ==> D Join G \<in> Always
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   308
          {s. (\<Sum>i \<in> lessThan Nclients. bag_of (sublist (distr.In s)
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   309
                                  {k. k < length (iIn s) & iIn s ! k = i})) =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   310
              bag_of (sublist (distr.In s) (lessThan (length (iIn s))))}"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   311
apply (erule Always_Compl_Un_eq [THEN iffD1])
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   312
apply (rule UNIV_AlwaysI, clarify)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   313
apply (subst bag_of_sublist_UN_disjoint [symmetric])
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   314
  apply (simp (no_asm))
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   315
 apply blast
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   316
apply (simp add: set_conv_nth)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   317
apply (subgoal_tac
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   318
       "(\<Union>i \<in> lessThan Nclients. {k. k < length (iIn x) & iIn x ! k = i}) =
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   319
        lessThan (length (iIn x))")
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   320
 apply (simp (no_asm_simp))
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   321
apply blast
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   322
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   323
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   324
lemma (in Distrib) D_ok_iff [iff]:
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   325
     "D ok G = (G \<in> preserves distr.Out & D \<in> Allowed G)"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   326
apply (cut_tac Distrib_spec)
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   327
apply (auto simp add: distr_spec_def distr_allowed_acts_def Allowed_def
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   328
                      safety_prop_Acts_iff ok_iff_Allowed)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   329
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   330
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   331
lemma (in Distrib) Distr_Bag_Follows:
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   332
 "D \<in> Increasing distr.In Int Increasing distr.iIn Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   333
      Always {s. \<forall>elt \<in> set (distr.iIn s). elt < Nclients}
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   334
      guarantees
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   335
       (\<Inter>i \<in> lessThan Nclients.
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   336
        (%s. \<Sum>i \<in> lessThan Nclients. (bag_of o sub i o distr.Out) s)
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   337
        Fols
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   338
        (%s. bag_of (sublist (distr.In s) (lessThan (length(distr.iIn s))))))"
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   339
apply (rule guaranteesI, clarify)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   340
apply (rule Distr_Bag_Follows_lemma [THEN Always_Follows2], auto)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   341
apply (rule Follows_setsum)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   342
apply (cut_tac Distrib_spec)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   343
apply (auto simp add: distr_spec_def distr_follows_def o_def)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   344
apply (drule guaranteesD)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   345
  prefer 3
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   346
  apply (best intro: mono_bag_of [THEN mono_Follows_apply, THEN subsetD], auto)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   347
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   348
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   349
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   350
subsection{*Theorems for Allocator*}
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   351
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   352
lemma alloc_refinement_lemma:
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   353
     "!!f::nat=>nat. (\<Inter>i \<in> lessThan n. {s. f i \<le> g i s})
15074
277b3a4da341 Modified \<Sum> syntax a little.
nipkow
parents: 14114
diff changeset
   354
      \<subseteq> {s. (SUM x: lessThan n. f x) \<le> (SUM x: lessThan n. g x s)}"
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   355
apply (induct_tac "n")
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   356
apply (auto simp add: lessThan_Suc)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   357
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   358
14114
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   359
lemma alloc_refinement:
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   360
"(\<Inter>i \<in> lessThan Nclients. Increasing (sub i o allocAsk) Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   361
                           Increasing (sub i o allocRel))
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   362
  Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   363
  Always {s. \<forall>i. i<Nclients -->
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   364
              (\<forall>elt \<in> set ((sub i o allocAsk) s). elt \<le> NbT)}
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   365
  Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   366
  (\<Inter>i \<in> lessThan Nclients.
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   367
   \<Inter>h. {s. h \<le> (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s}
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   368
        LeadsTo {s. tokens h \<le> (tokens o sub i o allocRel)s})
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   369
  \<subseteq>
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   370
 (\<Inter>i \<in> lessThan Nclients. Increasing (sub i o allocAsk) Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   371
                           Increasing (sub i o allocRel))
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   372
  Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   373
  Always {s. \<forall>i. i<Nclients -->
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   374
              (\<forall>elt \<in> set ((sub i o allocAsk) s). elt \<le> NbT)}
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   375
  Int
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   376
  (\<Inter>hf. (\<Inter>i \<in> lessThan Nclients.
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   377
         {s. hf i \<le> (sub i o allocGiv)s & hf i pfixGe (sub i o allocAsk)s})
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   378
  LeadsTo {s. (\<Sum>i \<in> lessThan Nclients. tokens (hf i)) \<le>
e97ca1034caa tidying
paulson
parents: 14089
diff changeset
   379
              (\<Sum>i \<in> lessThan Nclients. (tokens o sub i o allocRel)s)})"
14089
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   380
apply (auto simp add: ball_conj_distrib)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   381
apply (rename_tac F hf)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   382
apply (rule LeadsTo_weaken_R [OF Finite_stable_completion alloc_refinement_lemma], blast, blast)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   383
apply (subgoal_tac "F \<in> Increasing (tokens o (sub i o allocRel))")
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   384
 apply (simp add: Increasing_def o_assoc)
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   385
apply (blast intro: mono_tokens [THEN mono_Increasing_o, THEN subsetD])
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   386
done
7b34f58b1b81 converted UNITY/Comp/{AllocImpl,Client} to Isar scripts
paulson
parents: 11194
diff changeset
   387
11194
ea13ff5a26d1 reorganization of HOL/UNITY, moving examples to subdirectories Simple and Comp
paulson
parents:
diff changeset
   388
end