Debian Codegraph @

doc/examples/ASIP/zz.mod

raw
1 -- ZZ : builtin Integer with some extensions .
2 --
3 -- From J.A.Goguen and G. Malcolm "Algebraic semantics of
4 -- imperative program", MIT Press.
5 -- * program codes are converted from OBJ to CafeOBJ
6 --
7
8 #|------------------------------
9 ZZ extends CafeoBJ's built-in representation of the integers with an
10 equality predicate, _is_, and with some equations that are useful for
11 manipulating inequalities. In paricular, these equations are useful
12 as lemmas in the correctness proof given in the book. For example,
13 proving that a property is an invariant of a loop often involves showing
14 that `if 0 <= s[['X]] then 0 <= s[['X]] + 1' for some store s.
15 The equation in ZZ allow this implication to be automatically verified
16 by an CafeOBJ reduction, but they are not strong enough to allow all
17 properties of integers to be proved by reduction. For instance, they do
18 not allow the automatic verification of the implication: `if 0 <= s[['X]]
19 then 0 <= s[['X]] + 2'. If this property is needed for a correctnes proof
20 of some program, then an appropriate equation will beed to be added as a
21 lemma for the proof. In fact, there is not set of equations that can allow
22 the automatic verification of all properties of integer expressions which
23 contain indeterminate values such as `s[['X]]'; in other words, first order
24 arithmetic is "undecidable".
25 --------------------------|#
26
27 module ZZ {
28 imports {
29 protecting (INT)
30 }
31 signature {
32 #|
33 The predicate _is_ is intended to represent equality on integers.
34 The reason for introducing a new equality predicate rather then
35 using CafeOBJ's builtin equality _==_ is that we want to use
36 integer expressions which indeterminate values in program
37 correctness proofs (cf. Section 2.1.1 of Chapter2).
38 |#
39 op _is_ : Int Int -> Bool
40 }
41 axioms {
42 vars I J K L : Int
43 -- -----------------------
44 eq I is I = true .
45 eq (I + J) is (K + J) = I is K .
46 eq (I - J) is (K - J) = I is K .
47 cq I is J = false if (I < J) or (J < I) .
48 eq I + - I = 0 .
49 eq I + - J = - I + - J .
50 eq -(I + J) = - I + - J .
51 eq 0 * I = 0 .
52 eq - I * J = -(I * J) .
53 eq I - J = I + - J .
54 eq I * (J + K) = (I * J) + (I * K) .
55 cq I * J = I + (I * (J - 1)) if 0 < J .
56 eq (I + J) * K = (I * K) + (J * K) .
57
58 eq not(I <= J) = J < I .
59 eq not(I < J) = J <= I .
60 eq I + 1 <= J = I < J .
61 eq I < J + 1 = I <= J .
62 eq I <= J + -1 = I < J .
63 eq I <= J + - K = I + K <= J .
64 eq I < J + - K = I + K < J .
65 eq I + -1 < J = I <= J .
66 eq I <= I = true .
67 eq I < I = false .
68 cq I < I + J = true if 0 < J .
69 eq I + -1 < I = true .
70 cq I + J < I = true if J < 0 .
71 cq I <= J = true if I < J .
72 cq I <= J + 1 = true if I <= J .
73 cq I <= J + K = true if (I <= J) and (I <= K) .
74 cq I + J <= K + L = true if (I <= K) and (J <= L) .
75 }
76 }
77
78
79 eof