Debian Codegraph @

doc/examples/counter.mod

raw
1 -- FILE: /home/diacon/LANG/Cafe/prog/counter.mod
2 -- CONTENTS: behavioural specification of a counter object featuring
3 -- a comparison between coinduction and context induction proofs,
4 -- behavioural rewriting specification, and
5 -- proof of a behavioural transition property
6 -- AUTHOR: Razvan Diaconescu
7 -- corrected by [email protected]
8 -- DIFFICULTY: ***
9
10 -- non-deterministic naturals in RWL
11 mod! NNAT {
12 extending(NAT)
13 op _|_ : Nat Nat -> Nat
14
15 vars M N : Nat
16
17 trans M | N => M .
18 trans M | N => N .
19 }
20
21 -- generic data
22 mod* DATA {
23 [ Data ]
24 op _+_ : Data Data -> Data
25 }
26
27 -- generic counter object
28 mod* COUNTER(X :: DATA) {
29 *[ Counter ]*
30
31 bop add : Data Counter -> Counter -- method
32 bop read_ : Counter -> Data -- attribute
33
34 eq read add(N:Data, C:Counter) = read(C) + N .
35 }
36
37 -- proof of add(m,(add(n,counter))) =b= add(n,(add(m,counter))) .
38 open COUNTER(NAT) .
39 ops m n : -> Nat .
40 op counter : -> Counter .
41 --> PROOF BY CONTEXT INDUCTION
42 --> Base case: length of context is 1
43 red read add(m,(add(n,counter))) == read add(n,(add(m,counter))) .
44 --> Induction hypothesis: length of context read(c(z)) is n
45 op c : Counter -> Counter .
46 eq read c(add(m,(add(n,counter)))) = read c(add(n,(add(m,counter)))) .
47 --> Induction step:
48 op q : -> Nat .
49 red read add(q,c(add(m,(add(n,counter))))) ==
50 read add(q,c(add(n,(add(m,counter))))) .
51 --> PROOF BY COINDUCTION
52 red add(m,add(n,counter)) =*= add(n,add(m,counter)) .
53 close
54
55 -- proof of beh transition add(m | n,counter) => add(m,counter)
56 -- for a non-deterministic counter (in a HOSRWL specification)
57 open COUNTER(NNAT{sort Data -> Nat}) .
58 ops m n : -> Nat .
59 op counter : -> Counter .
60 --> PROOF BY CONTEXT INDUCTION
61 --> Base case: length of context is 1
62 **> want to perform only transitions:
63 ** set exec normalize off <- now this is obsolete switch.
64 ** but this example rely on this setting.
65 evq (setq *cexec-normalize* nil)
66
67 red read add(m | n,counter) ==> read add(m,counter) .
68 --> Induction hypothesis: length of context read(c(z)) is n
69 op c : Counter -> Counter .
70 eq read c(add(m | n,counter)) ==> read c(add(m,counter)) = true .
71 --> Induction step:
72 op q : -> Nat .
73 red read add(q,c(add(m | n,counter))) ==> read add(q,c(add(m,counter))) .
74 --> PROOF BY CO-INDUCTION
75 red read add(m | n,counter) ==> read add(m,counter) .
76 close
77 ** recover internal switch
78 evq (setq *cexec-normalize* t)
79 --
80 eof
81 --
82 $Id: counter.mod,v 1.1.1.1 2003-06-19 08:30:10 sawada Exp $