src/HOL/UNITY/Token.thy
author oheimb
Mon, 27 Apr 1998 19:29:19 +0200
changeset 4836 fc5773ae2790
parent 4776 1f9362e769c1
child 5232 e5a7cdd07ea5
permissions -rw-r--r--
added option_map_eq_Some via AddIffs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4776
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     1
(*  Title:      HOL/UNITY/Token
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
The Token Ring.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     7
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     8
From Misra, "A Logic for Concurrent Programming" (1994), sections 5.2 and 13.2.
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
     9
*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    10
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    11
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    12
Token = WFair +
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    13
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    14
(*process states*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    15
datatype pstate = Hungry | Eating | Thinking | Pnum nat
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    16
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    17
types state = nat => pstate
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    18
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    19
consts
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    20
  N :: nat	(*number of nodes in the ring*)
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    21
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    22
constdefs
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    23
  nodeOrder :: "nat => (nat*nat)set"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    24
    "nodeOrder j == (inv_image less_than (%i. ((j+N)-i) mod N))  Int
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    25
                    (lessThan N Times lessThan N)"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    26
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    27
  next      :: nat => nat
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    28
    "next i == (Suc i) mod N"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    29
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    30
  WellTyped :: state set
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    31
    "WellTyped == {s. ALL i j. s (Suc i) ~= Pnum j}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    32
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    33
  Token :: state => nat
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    34
    "Token s == case s 0 of 
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    35
                    Hungry => 0
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    36
                  | Eating => 0
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    37
                  | Thinking => 0
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    38
                  | Pnum i => i"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    39
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    40
  HasTok :: nat => state set
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    41
    "HasTok i == Token -`` {i}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    42
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    43
  H :: nat => state set
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    44
    "H i == {s. s (Suc i) = Hungry}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    45
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    46
  E :: nat => state set
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    47
    "E i == {s. s (Suc i) = Eating}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    48
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    49
  T :: nat => state set
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    50
    "T i == {s. s (Suc i) = Thinking}"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    51
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    52
rules
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    53
  N_positive "0<N"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    54
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    55
  stable_WT  "stable Acts WellTyped"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    56
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    57
  skip "id: Acts"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    58
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    59
  TR2  "constrains Acts (T i) (T i Un H i)"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    60
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    61
  TR3  "constrains Acts (H i) (H i Un E i)"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    62
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    63
  TR4  "constrains Acts (H i - HasTok i) (H i)"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    64
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    65
  TR5  "constrains Acts (HasTok i) (HasTok i Un Compl(E i))"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    66
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    67
  TR6  "leadsTo Acts (H i Int HasTok i) (E i)"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    68
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    69
  TR7  "leadsTo Acts (HasTok i) (HasTok (next i))"
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    70
1f9362e769c1 New UNITY theory
paulson
parents:
diff changeset
    71
end