Debian Codegraph @

doc/examples/nnat-hsa.mod

raw
1 -- FILE: /home/diacon/LANG/Cafe/prog/nnat-hsa.mod
2 -- CONTENTS: behavioural specification of non-deterministic natural numbers
3 -- featuring use of coherent operations for non-determinism
4 -- handling in behavioural specification
5 -- AUTHOR: Razvan Diaconescu
6 -- DIFFICULTY: ***
7
8 -- non-deterministic naturals
9 mod* NNAT-HSA {
10 protecting(NAT)
11
12 *[ NNat ]*
13
14 op [_] : Nat -> NNat
15 op _|_ : NNat NNat -> NNat {r-assoc} -- coherent
16 bop _->_ : NNat Nat -> Bool
17
18 vars S1 S2 : NNat
19 vars M N : Nat
20
21 eq [M] -> N = M == N .
22 eq S1 | S2 -> N = S1 -> N or S2 -> N .
23 }
24
25 select NNAT-HSA
26 --> some tests
27 red ( [1] | [2] | [3] ) -> 2 .
28 red ( [1] | [2] | [3] ) -> 4 .
29
30 --> the behavioural equivalence is =*=
31 -- (already automatically proved by the system)
32 --> s =*= s' == (forall n:Nat) s -> n iff s' -> n
33
34 --> proof of coherence of _|_
35 open NNAT-HSA .
36 ops s1 s1' s2 s2' : -> NNat .
37 op n : -> Nat .
38 -- hypothesis: s1 =*= s1' and s2 =*= s2'
39 var N : Nat
40 eq s1 -> N = s1' -> N .
41 eq s2 -> N = s2' -> N .
42 red (s1 | s2) -> n == (s1' | s2') -> n .
43 close
44
45 mod* NNAT-HSA+
46 {
47 protecting (NNAT-HSA)
48 op _|_ : NNat NNat -> NNat {coherent}
49 }
50
51 -- proof of some behavioural properties of the non-deterministic constructor
52 open NNAT-HSA+ .
53 ops s1 s2 s3 : -> NNat .
54 op n : -> Nat .
55 --> proof of commutativity
56 red (s1 | s2) -> n == (s2 | s1) -> n .
57 --> proof of associativity
58 red ((s1 | s2) | s3) -> n == (s1 | (s2 | s3)) -> n .
59 --> proof of idempotence
60 --> by lemma on idempotence on or
61 eq B:Bool or B = B .
62 red (s1 | s1) -> n == s1 -> n .
63 close
64
65 -- adding the _<=_ predicate to the non-deterministic naturals
66 -- first a simpler version
67 mod* NNAT-HSA<= {
68 protecting(NNAT-HSA+)
69
70 bop _<=_ : NNat Nat -> Bool
71
72 vars M N : Nat
73 vars S1 S2 : NNat
74
75 eq [M] <= N = M <= N .
76 eq S1 | S2 <= N = S1 <= N and S2 <= N .
77 }
78
79 select NNAT-HSA<=
80
81 red ([1] | ([2] | [3])) <= 3 .
82 red ([1] | ([2] | [3])) <= 1 .
83
84 -- the fully general version of _<=_
85 mod* NNAT-HSA<=< {
86 protecting(NNAT-HSA)
87
88 op _<=_ : NNat NNat -> Bool
89
90 vars M N : Nat
91 vars S1 S2 S : NNat
92
93 eq [M] <= [N] = M <= N .
94 eq S1 | S2 <= S = (S1 <= S) and (S2 <= S) .
95 eq S <= S1 | S2 = (S <= S1) and (S <= S2) .
96 }
97
98 select NNAT-HSA<=<
99
100 red ([1] | ([2] | [3])) <= ([4] | ([4] | [5])) .
101 red ([1] | ([2] | [3])) <= ([4] | ([4] | [2])) .
102
103 --
104 eof
105 --
106 $Id: nnat-hsa.mod,v 1.1.1.1 2003-06-19 08:30:10 sawada Exp $