-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxormod.pvs
More file actions
75 lines (70 loc) · 1.71 KB
/
xormod.pvs
File metadata and controls
75 lines (70 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
xormod: THEORY
BEGIN
l,n,m: VAR nat
a,b,c: VAR nbit
xor_bit(b,c): nbit =
TABLE b, c
%+---+---++
|[ 0 | 1 ]|
%---+---+---++
| 0 | 0 | 1 ||
%---+---+---++
| 1 | 1 | 0 ||
%---+---+---++
ENDTABLE
xor_bit_comm: LEMMA
xor_bit(b,c) = xor_bit(c,b)
xor_bit_assoc: LEMMA
xor_bit(a,xor_bit(b,c)) = xor_bit(xor_bit(a,b),c)
xor_bit_cancel: LEMMA
xor_bit(b,b) = 0
xor_bit_zero0: LEMMA
xor_bit(b,0) = b
xor_bit_zero1: LEMMA
xor_bit(0,c) = c
xor_nat(n,m): RECURSIVE nat =
IF n = 0 THEN m
ELSIF m = 0 THEN n
ELSE LET n2 = ndiv(n,2), m2 = ndiv(m,2),
n0 = rem(2)(n), m0 = rem(2)(m)
IN xor_bit(n0,m0) + 2 * xor_nat(n2,m2)
ENDIF
MEASURE n+m
xor_nat_comm: LEMMA
xor_nat(n,m) = xor_nat(m,n)
xor_nat_assoc: LEMMA
xor_nat(l,xor_nat(n,m)) = xor_nat(xor_nat(l,n),m)
xor_nat_cancel: LEMMA
xor_nat(n,n) = 0
xor_nat_zero0: LEMMA
xor_nat(n,0) = n
xor_nat_zero1: LEMMA
xor_nat(0,m) = m
xor_nat_one_even: LEMMA
even?(n) IMPLIES xor_nat(n,1) = n+1
xor_nat_one_odd: LEMMA
odd?(n) IMPLIES xor_nat(n,1) = n-1
xor_nat_succ_even: LEMMA
even?(n) IMPLIES xor_nat(n,n+1) = 1
% xor_nat_succ_odd: LEMMA
% odd?(n) IMPLIES xor_nat(n,n+1) = ??
xor_iter(n): RECURSIVE nat =
IF n = 0 THEN 0
ELSE xor_nat(xor_iter(n-1),n)
ENDIF
MEASURE n
xor_iter_prop: LEMMA
LET m = rem(4)(n), x = xor_iter(n)
IN
TABLE
%-------+---------++
| m = 0 | x = n ||
%-------+---------++
| m = 1 | x = 1 ||
%-------+---------++
| m = 2 | x = n+1 ||
%-------+---------++
| m = 3 | x = 0 ||
%-------+---------++
ENDTABLE
END xormod