| 1 |
-- ----------------------------------------------------- |
| 2 |
-- FILE: /home/diacon/LANG/Cafe/prog/path.mod |
| 3 |
-- CONTENTS: specification of a path data type featuring |
| 4 |
-- partial functions |
| 5 |
-- AUTHOR: Razvan Diaconescu (with inspiration from a Maude example) |
| 6 |
-- modfied by [email protected] for adapting to SRA implementation, i.e., |
| 7 |
-- sort membership predicate is `_:is_' not `_:_'. |
| 8 |
-- |
| 9 |
-- DIFFICULTY: ** |
| 10 |
|
| 11 |
-- a graph data type |
| 12 |
mod* GRAPH { |
| 13 |
[ Node Edge ] |
| 14 |
|
| 15 |
ops (s_) (t_) : Edge -> Node |
| 16 |
} |
| 17 |
|
| 18 |
-- the path data type |
| 19 |
mod! PATH (X :: GRAPH) { |
| 20 |
[ Edge < Path ] |
| 21 |
|
| 22 |
op _;_ : ?Path ?Path -> ?Path {assoc} |
| 23 |
ops (s_) (t_) : Path -> Node |
| 24 |
|
| 25 |
var E : Edge |
| 26 |
var P : Path |
| 27 |
var ?P : ?Path |
| 28 |
|
| 29 |
eq (E ; ?P) :is Path = (?P :is Path) and (s ?P) == (t E) . |
| 30 |
ceq s(E ; ?P) = s(E) if (E ; ?P) :is Path . |
| 31 |
ceq t(E ; ?P) = t(?P) if (E ; ?P) :is Path . |
| 32 |
} |
| 33 |
|
| 34 |
-- a example of GRAPH |
| 35 |
mod! GRAPH1 { |
| 36 |
[ Node Edge ] |
| 37 |
|
| 38 |
ops (s_) (t_) : Edge -> Node |
| 39 |
|
| 40 |
ops n1 n2 n3 : -> Node |
| 41 |
ops e1 e2 e3 : -> Edge |
| 42 |
eq s e1 = n1 . |
| 43 |
eq t e1 = n2 . |
| 44 |
eq s e2 = n2 . |
| 45 |
eq t e2 = n3 . |
| 46 |
eq s e3 = n3 . |
| 47 |
eq t e3 = n1 . |
| 48 |
} |
| 49 |
|
| 50 |
-- testing by some example reductions |
| 51 |
set mel sort on |
| 52 |
select PATH(GRAPH1) |
| 53 |
red s (e1 ; e3) . -- should be error |
| 54 |
red s (e1 ; e2) . -- should be n1 |
| 55 |
red t (e2 ; e3) . -- should be n1 |
| 56 |
red s (e1 ; e2 ; e3) . -- should be n1 |
| 57 |
red e1 ; e2 . -- should be e1 ; e2 : Path |
| 58 |
red (e1 ; e2) ; e3 == e1 ; (e2 ; e3) . -- should be true |
| 59 |
-- |
| 60 |
eof |
| 61 |
-- |
| 62 |
$Id: path.mod,v 1.2 2007-01-27 23:18:38 sawada Exp $ |