| 1 |
-- FILE: /home/diacon/LANG/Cafe/prog/tel.mod |
| 2 |
-- CONTENTS: behavioural specification of a telephone system featuring |
| 3 |
-- dynamic object composition (without synchronization) |
| 4 |
-- AUTHOR: Razvan Diaconescu |
| 5 |
-- DIFFICULTY: *** |
| 6 |
|
| 7 |
-- we trust system's proof of congruency of =*= |
| 8 |
set accept =*= proof on |
| 9 |
|
| 10 |
-- -------------------------------------------------------------- |
| 11 |
-- telephone number |
| 12 |
-- -------------------------------------------------------------- |
| 13 |
mod! NUMBER { |
| 14 |
protecting(NAT * { sort Nat -> Number }) |
| 15 |
|
| 16 |
[ Number < Number* ] |
| 17 |
|
| 18 |
op no-tel : -> Number* -- for errors |
| 19 |
} |
| 20 |
|
| 21 |
-- -------------------------------------------------------------- |
| 22 |
-- duration of calls (unit) |
| 23 |
-- -------------------------------------------------------------- |
| 24 |
mod! UNIT { |
| 25 |
protecting(NAT * { sort Nat -> Unit }) |
| 26 |
|
| 27 |
op no-tel : -> Unit -- for errors |
| 28 |
eq no-tel = 0 . |
| 29 |
} |
| 30 |
|
| 31 |
-- -------------------------------------------------------------- |
| 32 |
-- telephone (client) |
| 33 |
-- -------------------------------------------------------------- |
| 34 |
mod* TELEPHONE { |
| 35 |
protecting(NUMBER + UNIT) |
| 36 |
|
| 37 |
*[ Tel ]* |
| 38 |
|
| 39 |
op no-tel : -> Tel -- for errors |
| 40 |
op init-tel : Number -> Tel -- initial state |
| 41 |
bop call : Unit Tel -> Tel -- method |
| 42 |
bop clear : Tel -> Tel -- method |
| 43 |
bop unit : Tel -> Unit -- attribute |
| 44 |
bop number : Tel -> Number* -- attribute |
| 45 |
|
| 46 |
var NUM : Number |
| 47 |
var U : Unit |
| 48 |
var T : Tel |
| 49 |
|
| 50 |
eq unit(init-tel(NUM)) = 0 . |
| 51 |
eq unit(call(U, T)) = U + unit(T) . |
| 52 |
eq unit(no-tel) = no-tel . |
| 53 |
eq unit(clear(T)) = 0 . |
| 54 |
|
| 55 |
eq number(init-tel(NUM)) = NUM . |
| 56 |
eq number(call(U, T)) = number(T) . |
| 57 |
eq number(no-tel) = no-tel . |
| 58 |
eq number(clear(T)) = number(T) . |
| 59 |
} |
| 60 |
|
| 61 |
-- -------------------------------------------------------------- |
| 62 |
-- telephone system (server) |
| 63 |
-- -------------------------------------------------------------- |
| 64 |
mod* TELEPHONE-SYSTEM { |
| 65 |
protecting(TELEPHONE) |
| 66 |
|
| 67 |
*[ TelSys ]* |
| 68 |
|
| 69 |
op init-sys : -> TelSys -- initial state |
| 70 |
bop tel : Number TelSys -> Tel -- attribute |
| 71 |
bop add-tel : Number TelSys -> TelSys -- method |
| 72 |
bop del-tel : Number TelSys -> TelSys -- method |
| 73 |
bop call : Number Unit TelSys -> TelSys -- method |
| 74 |
bop pay : Number TelSys -> TelSys -- method |
| 75 |
|
| 76 |
vars NUM NUM' : Number |
| 77 |
var U : Unit |
| 78 |
var TS : TelSys |
| 79 |
|
| 80 |
eq tel(NUM, init-sys) = no-tel . |
| 81 |
ceq tel(NUM, add-tel(NUM', TS)) = init-tel(NUM) if NUM == NUM' . |
| 82 |
ceq tel(NUM, add-tel(NUM', TS)) = tel(NUM, TS) if NUM =/= NUM' . |
| 83 |
ceq tel(NUM, del-tel(NUM', TS)) = no-tel if NUM == NUM' . |
| 84 |
ceq tel(NUM, del-tel(NUM', TS)) = tel(NUM, TS) if NUM =/= NUM' . |
| 85 |
ceq tel(NUM, call(NUM', U, TS)) = call(U, tel(NUM, TS)) if NUM == NUM' . |
| 86 |
ceq tel(NUM, call(NUM', U, TS)) = tel(NUM, TS) if NUM =/= NUM' . |
| 87 |
ceq tel(NUM, pay(NUM', TS)) = tel(NUM, TS) if NUM =/= NUM' . |
| 88 |
ceq tel(NUM, pay(NUM', TS)) = clear(tel(NUM, TS)) if NUM == NUM' . |
| 89 |
} |
| 90 |
|
| 91 |
--> define the coinduction relation on TelSys by |
| 92 |
mod COINDUCTION-REL { |
| 93 |
protecting(TELEPHONE-SYSTEM) |
| 94 |
|
| 95 |
op _R[_]_ : TelSys Number TelSys -> Bool {coherent} |
| 96 |
|
| 97 |
vars T1 T2 : TelSys |
| 98 |
var N : Number |
| 99 |
|
| 100 |
eq T1 R[N] T2 = tel(N, T1) =*= tel(N, T2) . |
| 101 |
} |
| 102 |
|
| 103 |
-- --------------------------------------------------------------------- |
| 104 |
-- proof of true concurrency of phone calls |
| 105 |
-- call(n1, u1, call(n2, u2, telsys)) R call(n2, u2, call(n1, u1, telsys)) |
| 106 |
-- --------------------------------------------------------------------- |
| 107 |
open COINDUCTION-REL . |
| 108 |
op telsys : -> TelSys . |
| 109 |
ops n n1 n2 : -> Number . |
| 110 |
ops u1 u2 : -> Unit . |
| 111 |
-- n =/= n1, n =/= n2 |
| 112 |
red call(n1, u1, call(n2, u2, telsys)) R[n] |
| 113 |
call(n2, u2, call(n1, u1, telsys)) . |
| 114 |
-- n = n1 or n = n2 |
| 115 |
red call(n1, u1, call(n2, u2, telsys)) R[n1] |
| 116 |
call(n2, u2, call(n1, u1, telsys)) . |
| 117 |
close |
| 118 |
-- |
| 119 |
eof |
| 120 |
-- |
| 121 |
$Id: tel.mod,v 1.2 2010-07-30 04:20:09 sawada Exp $ |