| 1 |
-- FILE: /home/diacon/LANG/Cafe/prog/atm.mod |
| 2 |
-- CONTENTS: CASE study of an ATM (automated teller machine) system featuring |
| 3 |
-- concurrent object composition |
| 4 |
-- behavioural verification |
| 5 |
-- automatic generation of case analysis by meta-level encoding |
| 6 |
-- AUTHORS: Shuusaku Iida & Razvan Diaconescu |
| 7 |
-- DIFFICULTY: **** |
| 8 |
|
| 9 |
-- set tram path brute . <-- obsolete. now, we don't have tram. |
| 10 |
|
| 11 |
-- we trust system's =*= proof |
| 12 |
set accept =*= proof on |
| 13 |
|
| 14 |
-- control-oriented definition of Boolean connectives |
| 15 |
-- improves the efficiency of execution by 20% |
| 16 |
-- (now this is already in built-in BOOL. [email protected]) |
| 17 |
|
| 18 |
" |
| 19 |
module! BOOL+ |
| 20 |
{ |
| 21 |
protecting(BOOL) |
| 22 |
op _and-also_ : Bool Bool -> Bool { r-assoc strategy: (1 0 2 0) prec: 55 } |
| 23 |
op _or-else_ : Bool Bool -> Bool { r-assoc strategy: (1 0 2 0) prec: 59 } |
| 24 |
var X : Bool |
| 25 |
eq true and-also X = X . |
| 26 |
eq X and-also true = X . |
| 27 |
eq false and-also X = false . |
| 28 |
eq X and-also false = false . |
| 29 |
eq true or-else X = true . |
| 30 |
eq X or-else true = true . |
| 31 |
eq false or-else X = X . |
| 32 |
eq X or-else false = X . |
| 33 |
} |
| 34 |
" |
| 35 |
|
| 36 |
-- ------------------------------------------------------------- |
| 37 |
-- Values of SWITCH |
| 38 |
-- ------------------------------------------------------------- |
| 39 |
mod! ON-OFF { |
| 40 |
[ Value ] |
| 41 |
|
| 42 |
ops on off : -> Value |
| 43 |
} |
| 44 |
|
| 45 |
-- ------------------------------------------------------------- |
| 46 |
-- SWITCH |
| 47 |
-- ------------------------------------------------------------- |
| 48 |
mod* SWITCH { |
| 49 |
protecting (ON-OFF) |
| 50 |
|
| 51 |
*[ Switch ]* |
| 52 |
|
| 53 |
op init-sw : -> Switch -- initial state |
| 54 |
-- switch on |
| 55 |
bop on_ : Switch -> Switch -- method |
| 56 |
-- switch off |
| 57 |
bop off_ : Switch -> Switch -- method |
| 58 |
-- observe the state of the switch |
| 59 |
bop status_ : Switch -> Value -- attribute |
| 60 |
|
| 61 |
var S : Switch |
| 62 |
|
| 63 |
eq status(init-sw) = off . |
| 64 |
eq status(on(S)) = on . |
| 65 |
eq status(off(S)) = off . |
| 66 |
} |
| 67 |
|
| 68 |
-- ------------------------------------------------------------- |
| 69 |
-- User identification |
| 70 |
-- ------------------------------------------------------------- |
| 71 |
mod! USER-ID { |
| 72 |
protecting (NAT) |
| 73 |
[ Nat < UId ] |
| 74 |
|
| 75 |
op unidentified-user : -> UId |
| 76 |
} |
| 77 |
|
| 78 |
-- ------------------------------------------------------------- |
| 79 |
-- Counter |
| 80 |
-- ------------------------------------------------------------- |
| 81 |
mod* COUNTER { |
| 82 |
protecting(USER-ID + INT) |
| 83 |
|
| 84 |
*[ Counter ]* |
| 85 |
|
| 86 |
-- initialize counter with user ID |
| 87 |
op init-counter : UId -> Counter -- initial state |
| 88 |
-- add a value to the counter |
| 89 |
bop add : Int Counter -> Counter -- method |
| 90 |
-- read the value of the counter |
| 91 |
bop read_ : Counter -> Int -- attribute |
| 92 |
|
| 93 |
var I : Int |
| 94 |
var C : Counter |
| 95 |
var U : UId |
| 96 |
|
| 97 |
eq read(init-counter(U)) = 0 . |
| 98 |
eq read(add(I, C)) = I + read(C) . |
| 99 |
} |
| 100 |
|
| 101 |
-- ------------------------------------------------------------- |
| 102 |
-- Counter with error |
| 103 |
-- ------------------------------------------------------------- |
| 104 |
mod* COUNTER* { |
| 105 |
protecting (COUNTER) |
| 106 |
|
| 107 |
op counter-not-exist : -> Counter -- error value |
| 108 |
} |
| 109 |
|
| 110 |
-- ------------------------------------------------------------- |
| 111 |
-- Account sytem |
| 112 |
-- ------------------------------------------------------------- |
| 113 |
mod* ACCOUNT-SYSTEM { |
| 114 |
protecting (COUNTER* *{ hsort Counter -> Account, |
| 115 |
op init-counter -> init-account, |
| 116 |
op counter-not-exist -> no-account }) |
| 117 |
|
| 118 |
*[ AccountSys ]* |
| 119 |
|
| 120 |
op init-account-sys : -> AccountSys -- initial state |
| 121 |
-- add a user account with user ID |
| 122 |
bop add : UId Nat AccountSys -> AccountSys -- method |
| 123 |
-- delete a user account |
| 124 |
bop del : UId AccountSys -> AccountSys -- method |
| 125 |
-- deposit operation |
| 126 |
bop deposit : UId Nat AccountSys -> AccountSys -- method |
| 127 |
-- withdraw operation |
| 128 |
bop withdraw : UId Nat AccountSys -> AccountSys -- method |
| 129 |
-- calculate the balance of an user account |
| 130 |
bop balance : UId AccountSys -> Nat -- attribute |
| 131 |
-- get the state of a counter from the state of an account |
| 132 |
bop account : UId AccountSys -> Account {memo} -- projection |
| 133 |
|
| 134 |
vars U U' : UId |
| 135 |
var A : AccountSys |
| 136 |
var N : Nat |
| 137 |
|
| 138 |
eq account(U, init-account-sys) = no-account . |
| 139 |
ceq account(U, add(U', N, A)) = add(N, init-account(U)) |
| 140 |
if U == U' . |
| 141 |
ceq account(U, add(U', N, A)) = account(U, A) |
| 142 |
if U =/= U' . |
| 143 |
ceq account(U, del(U', A)) = no-account |
| 144 |
if U == U' . |
| 145 |
ceq account(U, del(U', A)) = account(U, A) |
| 146 |
if U =/= U' . |
| 147 |
ceq account(U, deposit(U', N, A)) = add(N, account(U, A)) |
| 148 |
if U == U' . |
| 149 |
ceq account(U, deposit(U', N, A)) = account(U, A) |
| 150 |
if U =/= U' . |
| 151 |
ceq account(U, withdraw(U', N, A)) = add(-(N), account(U, A)) |
| 152 |
if U == U' . |
| 153 |
ceq account(U, withdraw(U', N, A)) = account(U, A) |
| 154 |
if U =/= U' . |
| 155 |
|
| 156 |
eq balance(U, A) = read(account(U, A)) . |
| 157 |
} |
| 158 |
|
| 159 |
-- ------------------------------------------------------------- |
| 160 |
-- Trivial module with an element (undefined) |
| 161 |
-- ------------------------------------------------------------- |
| 162 |
mod* TRIV+ { |
| 163 |
[ Elt ] |
| 164 |
|
| 165 |
op undefined : -> Elt |
| 166 |
} |
| 167 |
|
| 168 |
-- ------------------------------------------------------------- |
| 169 |
-- Cell |
| 170 |
-- ------------------------------------------------------------- |
| 171 |
mod* CELL(X :: TRIV+) { |
| 172 |
*[ Cell ]* |
| 173 |
|
| 174 |
op init-cell : -> Cell -- initial state |
| 175 |
-- put the element to the cell |
| 176 |
bop put : Elt Cell -> Cell -- method |
| 177 |
-- get the element from the cell |
| 178 |
bop get : Cell -> Elt -- attribute |
| 179 |
|
| 180 |
var E : Elt |
| 181 |
var C : Cell |
| 182 |
|
| 183 |
eq get(init-cell) = undefined . |
| 184 |
eq get(put(E, C)) = E . |
| 185 |
} |
| 186 |
|
| 187 |
-- ------------------------------------------------------------- |
| 188 |
-- ATM identifier |
| 189 |
-- ------------------------------------------------------------- |
| 190 |
mod! ATM-ID { |
| 191 |
-- protecting(NAT *{ sort Nat -> AId }) |
| 192 |
protecting(NAT) |
| 193 |
|
| 194 |
[ Nat < AId ] |
| 195 |
} |
| 196 |
|
| 197 |
-- ------------------------------------------------------------- |
| 198 |
-- Button |
| 199 |
-- ------------------------------------------------------------- |
| 200 |
mod* BUTTON { |
| 201 |
protecting(SWITCH *{ hsort Switch -> Button, |
| 202 |
sort Value -> Operation, |
| 203 |
op init-sw -> init-button, |
| 204 |
op on -> deposit, |
| 205 |
op off -> withdraw }) |
| 206 |
} |
| 207 |
|
| 208 |
-- ------------------------------------------------------------- |
| 209 |
-- Cell for card information |
| 210 |
-- ------------------------------------------------------------- |
| 211 |
mod* CARD { |
| 212 |
protecting(CELL(X <= view to USER-ID |
| 213 |
{ sort Elt -> UId, |
| 214 |
op undefined -> unidentified-user }) |
| 215 |
*{ hsort Cell -> Card, |
| 216 |
op init-cell -> init-card }) |
| 217 |
} |
| 218 |
|
| 219 |
-- ------------------------------------------------------------- |
| 220 |
-- Cell for input |
| 221 |
-- ------------------------------------------------------------- |
| 222 |
mod* INPUT { |
| 223 |
protecting(CELL(X <= view to NAT |
| 224 |
{ sort Elt -> Nat, |
| 225 |
op undefined -> 0 }) |
| 226 |
*{ hsort Cell -> Input, |
| 227 |
op init-cell -> init-input }) |
| 228 |
} |
| 229 |
|
| 230 |
-- ------------------------------------------------------------- |
| 231 |
-- Cell for ouput |
| 232 |
-- ------------------------------------------------------------- |
| 233 |
mod* OUTPUT { |
| 234 |
protecting(CELL(X <= view to NAT |
| 235 |
{ sort Elt -> Nat, |
| 236 |
op undefined -> 0 }) |
| 237 |
*{ hsort Cell -> Output, |
| 238 |
op init-cell -> init-output }) |
| 239 |
} |
| 240 |
|
| 241 |
-- ------------------------------------------------------------- |
| 242 |
-- Cell for request |
| 243 |
-- ------------------------------------------------------------- |
| 244 |
mod* REQUEST { |
| 245 |
protecting(CELL(X <= view to NAT |
| 246 |
{ sort Elt -> Nat, |
| 247 |
op undefined -> 0 }) |
| 248 |
*{ hsort Cell -> Request, |
| 249 |
op init-cell -> init-request }) |
| 250 |
} |
| 251 |
|
| 252 |
-- ------------------------------------------------------------- |
| 253 |
-- ATM client |
| 254 |
-- ------------------------------------------------------------- |
| 255 |
mod* ATM-CLIENT { |
| 256 |
-- importing data and the composing objects |
| 257 |
protecting(ATM-ID + BUTTON + CARD + INPUT + OUTPUT + REQUEST) |
| 258 |
|
| 259 |
*[ Atm ]* |
| 260 |
|
| 261 |
op init-atm : AId -> Atm -- initial state |
| 262 |
op no-atm : -> Atm -- error |
| 263 |
op invalid-operation : -> Atm -- error |
| 264 |
-- push the deposit button |
| 265 |
bop deposit : Atm -> Atm -- method |
| 266 |
-- push the withdraw button |
| 267 |
bop withdraw : Atm -> Atm -- method |
| 268 |
-- input the request for withdraw |
| 269 |
bop request : Nat Atm -> Atm -- method |
| 270 |
-- put money |
| 271 |
bop put-money : Nat Atm -> Atm -- method |
| 272 |
-- take money |
| 273 |
bop take-money : Atm -> Atm -- mothod |
| 274 |
-- set money for output (system operation) |
| 275 |
bop set-money : Nat Atm -> Atm -- method |
| 276 |
-- put the bank card |
| 277 |
bop put-card : UId Atm -> Atm -- method |
| 278 |
-- clear all the informations kept in the atm |
| 279 |
bop clear : Atm -> Atm -- method |
| 280 |
-- get the user ID |
| 281 |
bop user-id : Atm -> UId -- attribute |
| 282 |
-- get the money that user input |
| 283 |
bop get-input : Atm -> Nat -- attribute |
| 284 |
-- get the outputed money |
| 285 |
bop get-output : Atm -> Nat -- attribute |
| 286 |
-- get the request |
| 287 |
bop get-request : Atm -> Nat -- attribute |
| 288 |
-- get the state of the button |
| 289 |
bop button-status : Atm -> Operation -- attribute |
| 290 |
|
| 291 |
bop button : Atm -> Button {memo} -- projection |
| 292 |
bop card : Atm -> Card {memo} -- projection |
| 293 |
bop request : Atm -> Request {memo} -- projection |
| 294 |
bop input : Atm -> Input {memo} -- projection |
| 295 |
bop output : Atm -> Output {memo} -- projection |
| 296 |
|
| 297 |
var ATM : Atm |
| 298 |
var N : Nat |
| 299 |
var U : UId |
| 300 |
var A : AId |
| 301 |
|
| 302 |
eq button(init-atm(A)) = init-button . |
| 303 |
eq button(invalid-operation) = init-button . |
| 304 |
eq button(deposit(ATM)) = on(button(ATM)) . |
| 305 |
eq button(withdraw(ATM)) = off(button(ATM)) . |
| 306 |
eq button(request(N, ATM)) = button(ATM) . |
| 307 |
eq button(put-money(N, ATM)) = button(ATM) . |
| 308 |
eq button(take-money(ATM)) = button(ATM) . |
| 309 |
eq button(set-money(N, ATM)) = button(ATM) . |
| 310 |
eq button(put-card(U, ATM)) = button(ATM) . |
| 311 |
eq button(clear(ATM)) = init-button . |
| 312 |
|
| 313 |
eq card(init-atm(A)) = init-card . |
| 314 |
eq card(invalid-operation) = init-card . |
| 315 |
eq card(deposit(ATM)) = card(ATM) . |
| 316 |
eq card(withdraw(ATM)) = card(ATM) . |
| 317 |
eq card(request(N, ATM)) = card(ATM) . |
| 318 |
eq card(put-money(N, ATM)) = card(ATM) . |
| 319 |
eq card(take-money(ATM)) = card(ATM) . |
| 320 |
eq card(set-money(N, ATM)) = card(ATM) . |
| 321 |
eq card(put-card(U, ATM)) = put(U, card(ATM)) . |
| 322 |
eq card(clear(ATM)) = init-card . |
| 323 |
|
| 324 |
eq request(init-atm(A)) = init-request . |
| 325 |
eq request(invalid-operation) = init-request . |
| 326 |
eq request(deposit(ATM)) = request(ATM) . |
| 327 |
eq request(withdraw(ATM)) = request(ATM) . |
| 328 |
eq request(request(N, ATM)) = put(N, request(ATM)) . |
| 329 |
eq request(put-money(N, ATM)) = request(ATM) . |
| 330 |
eq request(take-money(ATM)) = request(ATM) . |
| 331 |
eq request(set-money(N, ATM)) = request(ATM) . |
| 332 |
eq request(put-card(U, ATM)) = request(ATM) . |
| 333 |
eq request(clear(ATM)) = init-request . |
| 334 |
|
| 335 |
eq input(init-atm(A)) = init-input . |
| 336 |
eq input(invalid-operation) = init-input . |
| 337 |
eq input(deposit(ATM)) = input(ATM) . |
| 338 |
eq input(withdraw(ATM)) = input(ATM) . |
| 339 |
eq input(request(N, ATM)) = input(ATM) . |
| 340 |
eq input(put-money(N, ATM)) = put(N, input(ATM)) . |
| 341 |
eq input(take-money(ATM)) = input(ATM) . |
| 342 |
eq input(set-money(N, ATM)) = input(ATM) . |
| 343 |
eq input(put-card(U, ATM)) = input(ATM) . |
| 344 |
eq input(clear(ATM)) = init-input . |
| 345 |
|
| 346 |
eq output(init-atm(A)) = init-output . |
| 347 |
eq output(invalid-operation) = init-output . |
| 348 |
eq output(deposit(ATM)) = output(ATM) . |
| 349 |
eq output(withdraw(ATM)) = output(ATM) . |
| 350 |
eq output(request(N, ATM)) = output(ATM) . |
| 351 |
eq output(put-money(N, ATM)) = output(ATM) . |
| 352 |
eq output(take-money(ATM)) = init-output . |
| 353 |
eq output(set-money(N, ATM)) = put(N, output(ATM)) . |
| 354 |
eq output(put-card(U, ATM)) = output(ATM) . |
| 355 |
eq output(clear(ATM)) = output(ATM) . |
| 356 |
|
| 357 |
eq user-id(ATM) = get(card(ATM)) . |
| 358 |
eq get-input(ATM) = get(input(ATM)) . |
| 359 |
eq get-output(ATM) = get(output(ATM)) . |
| 360 |
eq get-request(ATM) = get(request(ATM)) . |
| 361 |
eq button-status(ATM) = status(button(ATM)) . |
| 362 |
} |
| 363 |
|
| 364 |
-- ------------------------------------------------------------- |
| 365 |
-- ATM system |
| 366 |
-- ------------------------------------------------------------- |
| 367 |
mod* ATM-SYSTEM { |
| 368 |
-- protecting(BOOL+) |
| 369 |
protecting(ACCOUNT-SYSTEM + ATM-CLIENT) |
| 370 |
|
| 371 |
*[ System ]* |
| 372 |
|
| 373 |
op init-sys : -> System -- initial state |
| 374 |
-- add an atm to the system |
| 375 |
bop add-atm : AId System -> System -- method |
| 376 |
-- delete an atm from the system |
| 377 |
bop del-atm : AId System -> System -- method |
| 378 |
-- add an user account |
| 379 |
bop add-user : UId Nat System -> System -- method |
| 380 |
-- delete an user account |
| 381 |
bop del-user : UId System -> System -- method |
| 382 |
-- put the bank card |
| 383 |
bop put-card : AId UId System -> System -- method |
| 384 |
-- request for withdraw |
| 385 |
bop request : AId Nat System -> System -- method |
| 386 |
-- put money |
| 387 |
bop put-money : AId Nat System -> System -- method |
| 388 |
-- take money |
| 389 |
bop take-money : AId System -> System -- method |
| 390 |
-- deposit operation |
| 391 |
bop deposit : AId System -> System -- method |
| 392 |
-- withdraw operation |
| 393 |
bop withdraw : AId System -> System -- method |
| 394 |
-- push the ok button on atm to complete the operation |
| 395 |
bop ok : AId System -> System -- method |
| 396 |
-- cancel the operation of ATM |
| 397 |
bop cancel : AId System -> System -- method |
| 398 |
-- get the balance of specified user |
| 399 |
bop balance : UId System -> Nat -- attribute |
| 400 |
-- projection operator for AccountSys |
| 401 |
bop account-sys : System -> AccountSys {memo} -- projection |
| 402 |
-- projection operator for Atm |
| 403 |
bop atm : AId System -> Atm {memo} -- projection |
| 404 |
|
| 405 |
var S : System |
| 406 |
vars A A' : AId |
| 407 |
var U : UId |
| 408 |
var N : Nat |
| 409 |
|
| 410 |
eq balance(U, S) = balance(U, account-sys(S)) . |
| 411 |
|
| 412 |
eq account-sys(init-sys) = init-account-sys . |
| 413 |
eq account-sys(add-atm(A, S)) = account-sys(S) . |
| 414 |
eq account-sys(del-atm(A, S)) = account-sys(S) . |
| 415 |
eq account-sys(add-user(U, N, S)) = add(U, N, account-sys(S)) . |
| 416 |
eq account-sys(del-user(U, S)) = del(U, account-sys(S)) . |
| 417 |
eq account-sys(put-card(A, U, S)) = account-sys(S) . |
| 418 |
eq account-sys(request(A, N, S)) = account-sys(S) . |
| 419 |
eq account-sys(put-money(A, N, S)) = account-sys(S) . |
| 420 |
eq account-sys(take-money(A, S)) = account-sys(S) . |
| 421 |
eq account-sys(deposit(A, S)) = account-sys(S) . |
| 422 |
eq account-sys(withdraw(A, S)) = account-sys(S) . |
| 423 |
ceq account-sys(ok(A, S)) = |
| 424 |
deposit(user-id(atm(A, S)), get-input(atm(A, S)), account-sys(S)) |
| 425 |
if (button-status(atm(A, S)) == deposit) and-also |
| 426 |
(user-id(atm(A, S)) =/= unidentified-user) and-also |
| 427 |
(get-input(atm(A, S)) =/= 0) . |
| 428 |
ceq account-sys(ok(A, S)) = |
| 429 |
withdraw(user-id(atm(A, S)), get-request(atm(A, S)), account-sys(S)) |
| 430 |
if (button-status(atm(A, S)) == withdraw) and-also |
| 431 |
(user-id(atm(A, S)) =/= unidentified-user) and-also |
| 432 |
(get-request(atm(A, S)) =/= 0) and-also |
| 433 |
(get-request(atm(A, S)) <= |
| 434 |
balance(user-id(atm(A, S)), account-sys(S))) . |
| 435 |
ceq account-sys(ok(A, S)) = account-sys(S) |
| 436 |
if user-id(atm(A, S)) == unidentified-user or |
| 437 |
(button-status(atm(A, S)) == deposit and-also |
| 438 |
get-input(atm(A, S)) == 0) or |
| 439 |
(button-status(atm(A, S)) == withdraw and-also |
| 440 |
(get-request(atm(A, S)) == 0 or |
| 441 |
get-request(atm(A, S)) > |
| 442 |
balance(user-id(atm(A, S)), account-sys(S)))) . |
| 443 |
eq account-sys(cancel(A, S)) = account-sys(S) . |
| 444 |
|
| 445 |
eq atm(A, init-sys) = no-atm . |
| 446 |
ceq atm(A, add-atm(A', S)) = init-atm(A) |
| 447 |
if A == A' . |
| 448 |
ceq atm(A, add-atm(A', S)) = atm(A, S) |
| 449 |
if A =/= A' . |
| 450 |
ceq atm(A, del-atm(A', S)) = no-atm |
| 451 |
if A == A . |
| 452 |
ceq atm(A, del-atm(A', S)) = atm(A, S) |
| 453 |
if A =/= A . |
| 454 |
eq atm(A, add-user(U, N, S)) = atm(A, S) . |
| 455 |
eq atm(A, del-user(U, S)) = atm(A, S) . |
| 456 |
ceq atm(A, put-card(A', U, S)) = put-card(U, atm(A, S)) |
| 457 |
if A == A' . |
| 458 |
ceq atm(A, put-card(A', U, S)) = atm(A, S) |
| 459 |
if A =/= A' . |
| 460 |
ceq atm(A, request(A', N, S)) = request(N, atm(A, S)) |
| 461 |
if A == A' . |
| 462 |
ceq atm(A, request(A', N, S)) = atm(A, S) |
| 463 |
if A =/= A' . |
| 464 |
ceq atm(A, put-money(A', N, S)) = put-money(N, atm(A, S)) |
| 465 |
if A == A' . |
| 466 |
ceq atm(A, put-money(A', N, S)) = atm(A, S) |
| 467 |
if A =/= A' . |
| 468 |
ceq atm(A, take-money(A', S)) = take-money(atm(A, S)) |
| 469 |
if A == A' . |
| 470 |
ceq atm(A, take-money(A', S)) = atm(A, S) |
| 471 |
if A =/= A' . |
| 472 |
ceq atm(A, deposit(A', S)) = deposit(atm(A, S)) |
| 473 |
if A == A' . |
| 474 |
ceq atm(A, deposit(A', S)) = atm(A, S) |
| 475 |
if A =/= A' . |
| 476 |
ceq atm(A, withdraw(A', S)) = withdraw(atm(A, S)) |
| 477 |
if A == A' . |
| 478 |
ceq atm(A, withdraw(A', S)) = atm(A, S) |
| 479 |
if A =/= A' . |
| 480 |
ceq atm(A, ok(A', S)) = clear(atm(A, S)) |
| 481 |
if (A == A') and-also |
| 482 |
(user-id(atm(A, S)) =/= unidentified-user) and-also |
| 483 |
(button-status(atm(A, S)) == deposit) . |
| 484 |
ceq atm(A, ok(A', S)) = set-money(get-request(atm(A, S)), clear(atm(A, S))) |
| 485 |
if A == A' and-also |
| 486 |
(user-id(atm(A, S)) =/= unidentified-user) and-also |
| 487 |
(button-status(atm(A, S)) == withdraw) and-also |
| 488 |
(get-request(atm(A, S)) <= |
| 489 |
balance(user-id(atm(A, S)), account-sys(S))) . |
| 490 |
ceq atm(A, ok(A', S)) = invalid-operation |
| 491 |
if A == A' and-also |
| 492 |
((user-id(atm(A, S)) == unidentified-user) or |
| 493 |
((button-status(atm(A, S)) == withdraw) and-also |
| 494 |
(get-request(atm(A, S)) > |
| 495 |
balance(user-id(atm(A, S)), account-sys(S))))) . |
| 496 |
ceq atm(A, ok(A', S)) = atm(A, S) |
| 497 |
if A =/= A' . |
| 498 |
ceq atm(A, cancel(A', S)) = init-atm(A) |
| 499 |
if A == A' . |
| 500 |
ceq atm(A, cancel(A', S)) = atm(A, S) |
| 501 |
if A =/= A' . |
| 502 |
} |
| 503 |
|
| 504 |
-- ------------------------------------------------------------- |
| 505 |
-- The toplevel of ATM system |
| 506 |
-- ------------------------------------------------------------- |
| 507 |
mod* ATM-SYSTEM-TOPLEVEL { |
| 508 |
protecting(ATM-SYSTEM) |
| 509 |
|
| 510 |
*[ TopLevel ]* |
| 511 |
|
| 512 |
op init-tl : -> TopLevel -- initial state |
| 513 |
-- add a new atm |
| 514 |
bop add-atm : AId TopLevel -> TopLevel -- method |
| 515 |
-- delete an atm |
| 516 |
bop del-atm : AId TopLevel -> TopLevel -- method |
| 517 |
-- create an user account with initial balance |
| 518 |
bop add-user : UId Nat TopLevel -> TopLevel -- method |
| 519 |
-- delete an user account |
| 520 |
bop del-user : UId TopLevel -> TopLevel -- method |
| 521 |
-- user "UId" goes to an ATM "AId" and deposit "Nat" |
| 522 |
bop deposit : UId AId Nat TopLevel -> TopLevel -- method |
| 523 |
-- user "UId" goes to an ATM "AId" and withdraw "Nat" |
| 524 |
bop withdraw : UId AId Nat TopLevel -> TopLevel -- method |
| 525 |
-- get a balance for the user |
| 526 |
bop balance : UId TopLevel -> Nat {memo} -- attribute |
| 527 |
-- projection operator for System |
| 528 |
bop system : TopLevel -> System {memo} -- projection |
| 529 |
|
| 530 |
var U : UId |
| 531 |
var A : AId |
| 532 |
var N : Nat |
| 533 |
var TL : TopLevel |
| 534 |
|
| 535 |
eq balance(U, TL) = balance(U, account-sys(system(TL))) . |
| 536 |
|
| 537 |
eq system(init-tl) = init-sys . |
| 538 |
eq system(add-atm(A, TL)) = add-atm(A, system(TL)) . |
| 539 |
eq system(del-atm(A, TL)) = del-atm(A, system(TL)) . |
| 540 |
eq system(add-user(U, N, TL)) = add-user(U, N, system(TL)) . |
| 541 |
eq system(del-user(U, TL)) = del-user(U, system(TL)) . |
| 542 |
eq system(deposit(U, A, N, TL)) = |
| 543 |
ok(A, put-money(A, N, deposit(A, put-card(A, U, system(TL))))) . |
| 544 |
eq system(withdraw(U, A, N, TL)) = |
| 545 |
take-money(A, ok(A, request(A, N, withdraw(A, |
| 546 |
put-card(A, U, system(TL)))))) . |
| 547 |
} |
| 548 |
|
| 549 |
-- ------------------------------------------------------------- |
| 550 |
-- test for ATM-SYSTEM-TOPLEVEL |
| 551 |
-- ------------------------------------------------------------- |
| 552 |
open ATM-SYSTEM-TOPLEVEL . |
| 553 |
|
| 554 |
op tl : -> TopLevel . |
| 555 |
ops u1 u2 : -> UId . |
| 556 |
ops ai1 ai2 : -> AId . |
| 557 |
|
| 558 |
red balance(u1, deposit(u1, ai2, 20, add-user(u1, 100, tl))) . |
| 559 |
red balance(u1, withdraw(u1, ai1, 20, withdraw(u2, ai2, 30, |
| 560 |
add-user(u1, 100, add-user(u2, 100, tl))))) . |
| 561 |
close |
| 562 |
|
| 563 |
-- ------------------------------------------------------------- |
| 564 |
-- module for behavioural equivalences |
| 565 |
-- ------------------------------------------------------------- |
| 566 |
mod COINDUCTION-REL { |
| 567 |
protecting(ATM-SYSTEM-TOPLEVEL) |
| 568 |
|
| 569 |
-- behavioural equivalence for AccountSys |
| 570 |
op _R[_]_ : AccountSys UId AccountSys -> Bool {coherent} |
| 571 |
|
| 572 |
vars AS1 AS2 : AccountSys |
| 573 |
var U : UId |
| 574 |
|
| 575 |
eq AS1 R[U] AS2 = account(U, AS1) =*= account(U, AS2) . |
| 576 |
|
| 577 |
-- behavioural equivalence for Atm |
| 578 |
op _R_ : Atm Atm -> Bool {coherent} |
| 579 |
|
| 580 |
vars A1 A2 : Atm |
| 581 |
|
| 582 |
eq A1 R A2 = button(A1) =*= button(A2) and |
| 583 |
card(A1) =*= card(A2) and |
| 584 |
request(A1) =*= request(A2) and |
| 585 |
input(A1) =*= input(A2) and |
| 586 |
output(A1) =*= output(A2) . |
| 587 |
|
| 588 |
-- behavioural equivalence for System |
| 589 |
op _R[_,_]_ : System UId AId System -> Bool {coherent} |
| 590 |
|
| 591 |
vars S1 S2 : System |
| 592 |
var A : AId |
| 593 |
|
| 594 |
eq S1 R[U, A] S2 = account-sys(S1) R[U] account-sys(S2) and |
| 595 |
atm(A, S1) R atm(A, S2) . |
| 596 |
|
| 597 |
-- behavioural equivalence for TopLevel |
| 598 |
op _R[_,_]_ : TopLevel UId AId TopLevel -> Bool {coherent} |
| 599 |
|
| 600 |
vars T1 T2 : TopLevel |
| 601 |
|
| 602 |
eq T1 R[U, A] T2 = system(T1) R[U, A] system(T2) . |
| 603 |
} |
| 604 |
|
| 605 |
mod PROOF { |
| 606 |
-- organize the proof of the behavioural property |
| 607 |
protecting(COINDUCTION-REL) |
| 608 |
|
| 609 |
ops a a1 a2 : -> AId |
| 610 |
op tl : -> TopLevel |
| 611 |
ops u u1 u2 : -> UId |
| 612 |
ops n1 n2 n01 n02 m1 m1' m2 m2' m : -> Nat |
| 613 |
|
| 614 |
-- atomic cases |
| 615 |
eq n1 =/= 0 = true . |
| 616 |
eq n2 =/= 0 = true . |
| 617 |
eq n01 == 0 = true . |
| 618 |
eq n02 == 0 = true . |
| 619 |
eq n1 <= m1 = true . |
| 620 |
eq n01 <= m1 = true . |
| 621 |
eq n1 > m1' = true . |
| 622 |
eq n2 <= m2 = true . |
| 623 |
eq n02 <= m2 = true . |
| 624 |
eq n2 > m2' = true . |
| 625 |
|
| 626 |
op state-of-system : Nat Nat -> TopLevel |
| 627 |
ops w1w2 w2w1 : AId AId Nat Nat Nat Nat -> TopLevel |
| 628 |
-- the meta-level encoding generating the proof term containing all cases |
| 629 |
op TERM : UId AId AId AId Nat Nat Nat Nat -> Bool |
| 630 |
op TERM1 : UId AId AId AId Nat Nat -> Bool |
| 631 |
op TERM2 : UId AId AId AId -> Bool |
| 632 |
op TERM' : AId AId AId -> Bool |
| 633 |
op RESULT : -> Bool |
| 634 |
|
| 635 |
vars A A1 A2 : AId |
| 636 |
var U : UId |
| 637 |
vars N1 N2 M1 M2 : Nat |
| 638 |
|
| 639 |
-- basic assumptions |
| 640 |
eq state-of-system(M1, M2) = add-user(u, m, |
| 641 |
add-user(u1, M1, |
| 642 |
add-user(u2, M2, |
| 643 |
add-atm(a, |
| 644 |
add-atm(a1, |
| 645 |
add-atm(a2, tl)))))) . |
| 646 |
|
| 647 |
eq w1w2(A1, A2, N1, N2, M1, M2) = |
| 648 |
withdraw(u1, A1, N1, |
| 649 |
withdraw(u2, A2, N2, state-of-system(M1, M2))) . |
| 650 |
|
| 651 |
eq w2w1(A1, A2, N1, N2, M1, M2) = |
| 652 |
withdraw(u2, A2, N2, |
| 653 |
withdraw(u1, A1, N1, state-of-system(M1, M2))) . |
| 654 |
|
| 655 |
-- the parameterized proof term |
| 656 |
eq TERM(U, A, A1, A2, N1, N2, M1, M2) = |
| 657 |
w1w2(A1,A2,N1,N2,M1,M2) R[U, A] w2w1(A1,A2,N1,N2,M1,M2) . |
| 658 |
|
| 659 |
eq TERM1(U, A, A1, A2, N2, M2) = |
| 660 |
TERM(U, A, A1, A2, n1, N2, m1, M2) and |
| 661 |
TERM(U, A, A1, A2, n1, N2, m1', M2) and |
| 662 |
TERM(U, A, A1, A2, n01, N2, m1, M2) . |
| 663 |
|
| 664 |
eq TERM2 (U, A, A1, A2) = |
| 665 |
TERM1(U, A, A1, A2, n2, m2) and |
| 666 |
TERM1(U, A, A1, A2, n2, m2') and |
| 667 |
TERM1(U, A, A1, A2, n02, m2) . |
| 668 |
|
| 669 |
eq TERM'(A, A1, A2) = TERM2(u, A, A1, A2) and |
| 670 |
TERM2(u1, A, A1, A2) and |
| 671 |
TERM2(u2, A, A1, A2) . |
| 672 |
eq RESULT = TERM'(a, a1, a2) and |
| 673 |
TERM'(a, a1, a1) and |
| 674 |
TERM'(a, a, a) and |
| 675 |
TERM'(a1, a1, a2) . |
| 676 |
} |
| 677 |
|
| 678 |
select PROOF |
| 679 |
-- tram red RESULT . |
| 680 |
red RESULT . |
| 681 |
|
| 682 |
eof |
| 683 |
-- |
| 684 |
$Id: atm.mod,v 1.2 2010-07-30 00:47:51 sawada Exp $ |