src/HOL/UNITY/Lift.thy
author paulson
Thu Aug 06 15:47:26 1998 +0200 (1998-08-06)
changeset 5277 e4297d03e5d2
child 5320 79b326bceafb
permissions -rw-r--r--
A higher-level treatment of LeadsTo, minimizing use of "reachable"
paulson@5277
     1
(*  Title:      HOL/UNITY/Lift.thy
paulson@5277
     2
    ID:         $Id$
paulson@5277
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5277
     4
    Copyright   1998  University of Cambridge
paulson@5277
     5
paulson@5277
     6
The Lift-Control Example
paulson@5277
     7
*)
paulson@5277
     8
paulson@5277
     9
Lift = SubstAx +
paulson@5277
    10
paulson@5277
    11
record state =
paulson@5277
    12
  floor :: nat		(*current position of the lift*)
paulson@5277
    13
  open  :: bool		(*whether the door is open at floor*)
paulson@5277
    14
  stop  :: bool		(*whether the lift is stopped at floor*)
paulson@5277
    15
  req   :: nat set	(*for each floor, whether the lift is requested*)
paulson@5277
    16
  up    :: bool		(*current direction of movement*)
paulson@5277
    17
  move  :: bool		(*whether moving takes precedence over opening*)
paulson@5277
    18
paulson@5277
    19
consts
paulson@5277
    20
  min, max :: nat	(*least and greatest floors*)
paulson@5277
    21
paulson@5277
    22
rules
paulson@5277
    23
  min_le_max  "min <= max"
paulson@5277
    24
  
paulson@5277
    25
paulson@5277
    26
constdefs
paulson@5277
    27
  
paulson@5277
    28
  (** Abbreviations: the "always" part **)
paulson@5277
    29
  
paulson@5277
    30
  above :: "state set"
paulson@5277
    31
    "above == {s. EX i. floor s < i & i <= max & i : req s}"
paulson@5277
    32
paulson@5277
    33
  below :: "state set"
paulson@5277
    34
    "below == {s. EX i. min <= i & i < floor s & i : req s}"
paulson@5277
    35
paulson@5277
    36
  queueing :: "state set"
paulson@5277
    37
    "queueing == above Un below"
paulson@5277
    38
paulson@5277
    39
  goingup :: "state set"
paulson@5277
    40
    "goingup == above Int ({s. up s} Un Compl below)"
paulson@5277
    41
paulson@5277
    42
  goingdown :: "state set"
paulson@5277
    43
    "goingdown == below Int ({s. ~ up s} Un Compl above)"
paulson@5277
    44
paulson@5277
    45
  ready :: "state set"
paulson@5277
    46
    "ready == {s. stop s & ~ open s & move s}"
paulson@5277
    47
paulson@5277
    48
paulson@5277
    49
  (** The program **)
paulson@5277
    50
  
paulson@5277
    51
  request_act :: "(state*state) set"
paulson@5277
    52
    "request_act == {(s,s'). s' = s (|stop:=True, move:=False|)
paulson@5277
    53
		                  & ~ stop s & floor s : req s}"
paulson@5277
    54
paulson@5277
    55
  open_act :: "(state*state) set"
paulson@5277
    56
    "open_act ==
paulson@5277
    57
         {(s,s'). s' = s (|open :=True,
paulson@5277
    58
			   req  := req s - {floor s},
paulson@5277
    59
			   move := True|)
paulson@5277
    60
		       & stop s & ~ open s & floor s : req s
paulson@5277
    61
	               & ~(move s & s: queueing)}"
paulson@5277
    62
paulson@5277
    63
  close_act :: "(state*state) set"
paulson@5277
    64
    "close_act == {(s,s'). s' = s (|open := False|) & open s}"
paulson@5277
    65
paulson@5277
    66
  req_up_act :: "(state*state) set"
paulson@5277
    67
    "req_up_act ==
paulson@5277
    68
         {(s,s'). s' = s (|stop  :=False,
paulson@5277
    69
			   floor := Suc (floor s),
paulson@5277
    70
			   up    := True|)
paulson@5277
    71
		       & s : (ready Int goingup)}"
paulson@5277
    72
paulson@5277
    73
  req_down_act :: "(state*state) set"
paulson@5277
    74
    "req_down_act ==
paulson@5277
    75
         {(s,s'). s' = s (|stop  :=False,
paulson@5277
    76
			   floor := floor s - 1,
paulson@5277
    77
			   up    := False|)
paulson@5277
    78
		       & s : (ready Int goingdown)}"
paulson@5277
    79
paulson@5277
    80
  move_up :: "(state*state) set"
paulson@5277
    81
    "move_up ==
paulson@5277
    82
         {(s,s'). s' = s (|floor := Suc (floor s)|)
paulson@5277
    83
		       & ~ stop s & up s & floor s ~: req s}"
paulson@5277
    84
paulson@5277
    85
  move_down :: "(state*state) set"
paulson@5277
    86
    "move_down ==
paulson@5277
    87
         {(s,s'). s' = s (|floor := floor s - 1|)
paulson@5277
    88
		       & ~ stop s & ~ up s & floor s ~: req s}"
paulson@5277
    89
paulson@5277
    90
  Lprg :: state program
paulson@5277
    91
    "Lprg == (|Init = {s. floor s = min & ~ up s & move s & stop s &
paulson@5277
    92
		          ~ open s & req s = {}},
paulson@5277
    93
	       Acts = {id, request_act, open_act, close_act,
paulson@5277
    94
		       req_up_act, req_down_act, move_up, move_down}|)"
paulson@5277
    95
paulson@5277
    96
paulson@5277
    97
  (** Invariants **)
paulson@5277
    98
paulson@5277
    99
  bounded :: state set
paulson@5277
   100
    "bounded == {s. min <= floor s & floor s <= max}"
paulson@5277
   101
paulson@5277
   102
  (** ???
paulson@5277
   103
		    (~ stop s & up s --> floor s < max) &
paulson@5277
   104
		    (~ stop s & ~ up s --> min < floor s)}"
paulson@5277
   105
  **)
paulson@5277
   106
paulson@5277
   107
  open_stop :: state set
paulson@5277
   108
    "open_stop == {s. open s --> stop s}"
paulson@5277
   109
  
paulson@5277
   110
  open_move :: state set
paulson@5277
   111
    "open_move == {s. open s --> move s}"
paulson@5277
   112
  
paulson@5277
   113
  stop_floor :: state set
paulson@5277
   114
    "stop_floor == {s. open s & ~ move s --> floor s : req s}"
paulson@5277
   115
  
paulson@5277
   116
  moving_up :: state set
paulson@5277
   117
    "moving_up == {s. ~ stop s & up s -->
paulson@5277
   118
                   (EX f. floor s <= f & f <= max & f : req s)}"
paulson@5277
   119
  
paulson@5277
   120
  moving_down :: state set
paulson@5277
   121
    "moving_down == {s. ~ stop s & ~ up s -->
paulson@5277
   122
                     (EX f. min <= f & f <= floor s & f : req s)}"
paulson@5277
   123
  
paulson@5277
   124
  valid :: "state set"
paulson@5277
   125
    "valid == bounded Int open_stop Int open_move"
paulson@5277
   126
paulson@5277
   127
end