{- Dijkstra's Dutch National Flag program. Nite: post-condition is weak in that it does not impose that the program does not change the array in any other way than permutating it. -} prog ducthFlag (a::& Int[]) b,i,r:: Int ; tmp :: Int pre 0 < #a /\ allRWB a do { b:=0; i:=0; r := #a ; inv allRWB a /\ (!k :- k range from r to #a -: isRed (a[k])) /\ (!k :- k range from b to i -: isWhite (a[k])) /\ (!k :- k range from 0 to b -: isBlue (a[k])) /\ (b range from 0 to (i+1)) /\ i <= r /\ r <= #a metric r-i while i Bool ; cntRed :: Int[] -> Int ; cntWhite :: Int[] -> Int ; cntBlue :: Int[] -> Int ; isRed :: Int -> Bool ; isWhite :: Int -> Bool ; isBlue :: Int -> Bool ; dutchSorted :: Int[] -> Bool