| 1 |
-- FILE: /home/diacon/LANG/Cafe/prog/hss.mod |
| 2 |
-- CONTENTS: behavioural specification of a stack object featuring |
| 3 |
-- use of behavioural equations in specifications, |
| 4 |
-- definition of behavioural equivalence by parameterized relation |
| 5 |
-- and by use of a 2nd order function, and |
| 6 |
-- some tests for behavioural context condition in execution |
| 7 |
-- AUTHOR: Razvan Diaconescu |
| 8 |
-- DIFFICULTY: *** |
| 9 |
|
| 10 |
mod! BARE-NAT { |
| 11 |
|
| 12 |
[ NzNat Zero < Nat ] |
| 13 |
|
| 14 |
op 0 : -> Zero |
| 15 |
op s_ : Nat -> NzNat |
| 16 |
} |
| 17 |
|
| 18 |
-- history sensitive storage (i.e., stack) object |
| 19 |
mod* HSS(X :: TRIV) { |
| 20 |
|
| 21 |
*[ Hss ]* |
| 22 |
|
| 23 |
bop put : Elt Hss -> Hss |
| 24 |
bop rest_ : Hss -> Hss |
| 25 |
bop get_ : Hss -> Elt |
| 26 |
|
| 27 |
var S : Hss |
| 28 |
var E : Elt |
| 29 |
|
| 30 |
eq get put(E, S) = E . |
| 31 |
beq rest put(E, S) = S . |
| 32 |
} |
| 33 |
|
| 34 |
-- 2nd order rest |
| 35 |
mod HSS-PROOF { |
| 36 |
protecting(HSS + BARE-NAT) |
| 37 |
|
| 38 |
bop rest* : Hss Nat -> Hss |
| 39 |
|
| 40 |
vars S S1 S2 : Hss |
| 41 |
vars N N' : Nat |
| 42 |
var E : Elt |
| 43 |
|
| 44 |
eq [ p1 ] : rest*(S, s(N)) = rest*(rest S, N) . |
| 45 |
eq [ p2 ] : rest*(S, 0) = S . |
| 46 |
} |
| 47 |
|
| 48 |
-- behavioural equivalence for HSS |
| 49 |
mod HSS-BEQ { |
| 50 |
protecting(HSS-PROOF) |
| 51 |
|
| 52 |
op _R[_]_ : Hss Nat Hss -> Bool |
| 53 |
|
| 54 |
vars S1 S2 : Hss |
| 55 |
var N : Nat |
| 56 |
|
| 57 |
eq [ R ] : S1 R[N] S2 = get rest*(S1, N) == get rest*(S2, N) . |
| 58 |
} |
| 59 |
|
| 60 |
open HSS-BEQ . |
| 61 |
-- proof that _R_ is a hidden congruence |
| 62 |
ops m n : -> Nat . |
| 63 |
ops e e1 e2 : -> Elt . |
| 64 |
ops s s1 s2 : -> Hss . |
| 65 |
|
| 66 |
eq [ hyp ] : get rest*(s1, N) = get rest*(s2, N) . |
| 67 |
-- ----- |
| 68 |
--> get | |
| 69 |
-- ----- |
| 70 |
start get s1 == get s2 . |
| 71 |
apply -.p2 within term . |
| 72 |
apply .hyp within term . |
| 73 |
apply reduce at term . -- it should be true |
| 74 |
-- ------ |
| 75 |
--> put | |
| 76 |
-- ------ |
| 77 |
-- proof by case analysis on N |
| 78 |
-- N = 0 |
| 79 |
red put(e, s1) R[0] put(e, s2) . |
| 80 |
-- N = s(n) |
| 81 |
red put(e, s1) R[s(n)] put(e, s2) . |
| 82 |
-- ----- |
| 83 |
--> rest | |
| 84 |
-- ----- |
| 85 |
start (rest s1) R[n] (rest s2) . |
| 86 |
apply .R within term . |
| 87 |
apply -.p1 within term . |
| 88 |
apply .hyp within term . |
| 89 |
apply reduce at term . |
| 90 |
-- --------------------------------------------- |
| 91 |
--> proof of rest rest put(E1, (put(E2, S))) =b= S . |
| 92 |
-- --------------------------------------------- |
| 93 |
red (rest rest put(e1, (put(e2, s)))) R[n] s . |
| 94 |
|
| 95 |
-- --------------------------------------------- |
| 96 |
--> proof of rest*(put(E, S), s(N)) =b= rest*(S, N) . |
| 97 |
-- --------------------------------------------- |
| 98 |
red (rest*(put(e, s), s(m))) R[n] rest*(s, m) . |
| 99 |
close |
| 100 |
|
| 101 |
-- some tests for the use of behavioural context condition in *reduce* |
| 102 |
open HSS(NAT) . |
| 103 |
ops e e1 e2 : -> Nat . |
| 104 |
ops st st1 st2 : -> Hss . |
| 105 |
red rest(put(e, st)) == st . |
| 106 |
red put(get(rest(put(e1, put(e2, st1)))), st2) == put(e2, st2) . |
| 107 |
bred rest(put(e, st)) . |
| 108 |
bred rest(put(e, st)) =b= st . |
| 109 |
bred rest(put(e, st)) == st . |
| 110 |
red rest(put(e, st)) =b= st . |
| 111 |
red put(1 + 2, st) == put(3, st) . |
| 112 |
close |
| 113 |
|
| 114 |
-- HSS with coherent put method |
| 115 |
mod* HSS(X :: TRIV) { |
| 116 |
|
| 117 |
*[ Hss ]* |
| 118 |
|
| 119 |
op put : Elt Hss -> Hss -- coherent |
| 120 |
bop rest_ : Hss -> Hss |
| 121 |
bop get_ : Hss -> Elt |
| 122 |
|
| 123 |
var S : Hss |
| 124 |
var E : Elt |
| 125 |
|
| 126 |
eq get put(E, S) = E . |
| 127 |
beq rest put(E, S) = S . |
| 128 |
} |
| 129 |
|
| 130 |
mod HSS-PROOF { |
| 131 |
protecting(HSS + BARE-NAT) |
| 132 |
|
| 133 |
bop rest* : Hss Nat -> Hss |
| 134 |
|
| 135 |
vars S S1 S2 : Hss |
| 136 |
vars N N' : Nat |
| 137 |
var E : Elt |
| 138 |
|
| 139 |
eq [ p1 ] : rest*(S, s(N)) = rest*(rest S, N) . |
| 140 |
eq [ p2 ] : rest*(S, 0) = S . |
| 141 |
} |
| 142 |
|
| 143 |
-- proof for coherence of put |
| 144 |
open HSS-PROOF . |
| 145 |
ops s1 s2 : -> Hss . |
| 146 |
eq get rest*(s1, N) = get rest*(s2, N) . |
| 147 |
red get rest*(put(E, s1), 0) == get rest*(put(E, s2), 0) . |
| 148 |
red get rest*(put(E, s1), s(N)) == get rest*(put(E, s2), s(N)) . |
| 149 |
close |
| 150 |
|
| 151 |
mod* HSS+ { protecting (HSS) |
| 152 |
op put : Elt Hss -> Hss {coherent} |
| 153 |
} |
| 154 |
|
| 155 |
-- |
| 156 |
eof |
| 157 |
-- |
| 158 |
$Id: hss.mod,v 1.1.1.1 2003-06-19 08:30:10 sawada Exp $ |