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