src/CCL/ex/flag.thy
author paulson
Mon Dec 07 18:26:25 1998 +0100 (1998-12-07)
changeset 6019 0e55c2fb2ebb
parent 290 37d580c16af5
permissions -rw-r--r--
tidying
clasohm@0
     1
(*  Title: 	CCL/ex/flag.thy
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Martin Coen, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Dutch national flag program - except that the point of Dijkstra's example was to use 
clasohm@0
     7
arrays and this uses lists.
clasohm@0
     8
clasohm@0
     9
*)
clasohm@0
    10
clasohm@0
    11
Flag = List + 
clasohm@0
    12
clasohm@0
    13
consts
clasohm@0
    14
clasohm@0
    15
  Colour             :: "i set"
clasohm@0
    16
  red, white, blue   :: "i"
clasohm@0
    17
  ccase              :: "[i,i,i,i]=>i"
clasohm@0
    18
  flag               :: "i"
clasohm@0
    19
clasohm@0
    20
rules
clasohm@0
    21
clasohm@0
    22
  Colour_def  "Colour == Unit + Unit + Unit"
clasohm@0
    23
  red_def        "red == inl(one)"
clasohm@0
    24
  white_def    "white == inr(inl(one))"
clasohm@0
    25
  blue_def     "blue == inr(inr(one))"
clasohm@0
    26
clasohm@0
    27
  ccase_def   "ccase(c,r,w,b) == when(c,%x.r,%wb.when(wb,%x.w,%x.b))"
clasohm@0
    28
clasohm@0
    29
  flag_def    "flag == lam l.letrec \
clasohm@0
    30
\      flagx l be lcase(l,<[],<[],[]>>, \
clasohm@0
    31
\                       %h t. split(flagx(t),%lr p.split(p,%lw lb. \
clasohm@290
    32
\                            ccase(h, <red$lr,<lw,lb>>, \
clasohm@290
    33
\                                     <lr,<white$lw,lb>>, \
clasohm@290
    34
\                                     <lr,<lw,blue$lb>>)))) \
clasohm@0
    35
\      in flagx(l)"    
clasohm@0
    36
clasohm@0
    37
  Flag_def
clasohm@0
    38
     "Flag(l,x) == ALL lr:List(Colour).ALL lw:List(Colour).ALL lb:List(Colour). \
clasohm@0
    39
\                    x = <lr,<lw,lb>> --> \
clasohm@0
    40
\                  (ALL c:Colour.(c mem lr = true --> c=red) & \
clasohm@0
    41
\                                (c mem lw = true --> c=white) & \
clasohm@0
    42
\                                (c mem lb = true --> c=blue)) & \
clasohm@0
    43
\                  Perm(l,lr @ lw @ lb)"
clasohm@0
    44
clasohm@0
    45
end
clasohm@0
    46
clasohm@0
    47
clasohm@0
    48