src/HOL/UNITY/Mutex.thy
author paulson
Tue, 05 May 1998 17:28:22 +0200
changeset 4896 4727272f3db6
parent 4776 1f9362e769c1
child 5071 548f398d770b
permissions -rw-r--r--
New syntax for function update; moved to main HOL directory
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/Mutex.thy
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     2
    ID:         $Id$
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     4
    Copyright   1998  University of Cambridge
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     5
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     6
Based on "A Family of 2-Process Mutual Exclusion Algorithms" by J Misra
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
Mutex = Update + UNITY + Traces + SubstAx +
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    11
(*WE NEED A GENERAL TREATMENT OF NUMBERS!!*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    12
syntax
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
  "3"       :: nat                ("3")
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
  "4"       :: nat                ("4")
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
translations
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
   "3"  == "Suc 2"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    18
   "4"  == "Suc 3"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
(*program variables*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
datatype pvar = PP | MM | NN | UU | VV
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
(*No booleans; instead True=1 and False=0*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
types state = pvar => nat
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
constdefs
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
  cmd0 :: "[pvar,pvar] => (state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    29
    "cmd0 u m == {(s,s'). s' = s[u:=1][m:=1] & s m = 0}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    30
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    31
  cmd1u :: "(state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    32
    "cmd1u == {(s,s'). s' = s[PP:= s VV][MM:=2] & s MM = 1}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
  cmd1v :: "(state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    35
    "cmd1v == {(s,s'). s' = s[PP:= 1 - s UU][NN:=2] & s NN = 1}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
  (*Put pv=0 for u's program and pv=1 for v's program*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
  cmd2 :: "[nat,pvar] => (state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    39
    "cmd2 pv m == {(s,s'). s' = s[m:=3] & s PP = pv & s m = 2}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
  cmd3 :: "[pvar,pvar] => (state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    42
    "cmd3 u m == {(s,s'). s' = s[u:=0][m:=4] & s m = 3}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
  (*Put pv=1 for u's program and pv=0 for v's program*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
  cmd4 :: "[nat,pvar] => (state*state) set"
4896
4727272f3db6 New syntax for function update; moved to main HOL directory
paulson
parents: 4776
diff changeset
    46
    "cmd4 pv m == {(s,s'). s' = s[PP:=pv][m:=0] & s m = 4}"
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
  mutex :: "(state*state) set set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
    "mutex == {id,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
	       cmd0 UU MM, cmd0 VV NN,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
	       cmd1u, cmd1v,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
	       cmd2 0 MM, cmd2 1 NN,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
	       cmd3 UU MM, cmd3 VV NN,
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
	       cmd4 1 MM, cmd4 0 NN}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    55
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
  MInit :: "state set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
    "MInit == {s. s PP < 2 & s UU = 0 & s VV = 0 & s MM = 0 & s NN = 0}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
  boolVars :: "state set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
    "boolVars == {s. s PP<2 & s UU < 2 & s VV < 2}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
  (*Put pv=0 for u's program and pv=1 for v's program*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
  invariant :: "[nat,pvar,pvar] => state set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
    "invariant pv u m == {s. ((s u=1) = (1 <= s m & s m <= 3)) &
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    65
			     (s m = 3 --> s PP = pv)}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
  bad_invariant :: "[nat,pvar,pvar] => state set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
    "bad_invariant pv u m == {s. ((s u=1) = (1 <= s m & s m <= 3)) &
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
			         (3 <= s m & s m <= 4 --> s PP = pv)}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    72
  
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    73
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    74
end