-
Notifications
You must be signed in to change notification settings - Fork 1
/
NativeIntExponential.dfy
151 lines (135 loc) · 2.72 KB
/
NativeIntExponential.dfy
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// RUN: /compile:0
newtype {:nativeType "uint"} u32 =
x: int | 0 <= x < 0x100000000
function pow2(n: nat): int
{
if n == 0 then 1 else 2 * pow2(n - 1)
}
lemma {:fuel pow2,31,32} {:induction false} pow2Bounds(n: nat)
requires n < 32
ensures 0 <= pow2(n) < 0x100000000
{
}
function pow2u32(n: u32): u32
requires n < 32
{
pow2Bounds(n as nat);
pow2(n as nat) as u32
}
/*lemma pow2Monotone(a: nat, b: nat)
requires a < b
ensures pow2(a) < pow2(b)
{}
lemma pow2unroll2(n: nat)
requires n >= 2
ensures pow2(n) == 4 * pow2(n - 2)
{}
lemma pow2unroll4(n: nat)
requires n >= 4
ensures pow2(n) == 0x10 * pow2(n - 4)
{
pow2unroll2(n);
pow2unroll2(n-2);
}
lemma pow2unroll8(n: nat)
requires n >= 8
ensures pow2(n) == 0x100 * pow2(n - 8)
{
pow2unroll4(n);
pow2unroll4(n-4);
}
lemma pow2unroll16(n: nat)
requires n >= 16
ensures pow2(n) == 0x10000 * pow2(n - 16)
{
pow2unroll8(n);
pow2unroll8(n-8);
}
lemma pow2Bounds(n: nat)
requires n < 32
ensures 0 <= pow2(n) < 0x100000000
{
var k := n;
if k >= 16 {
pow2unroll16(k);
k := k - 16;
}
if k >= 8 {
pow2unroll8(k);
k := k - 8;
}
if k >= 4 {
pow2unroll4(k);
k := k - 4;
}
if k >= 2 {
pow2unroll2(k);
k := k - 2;
}
}
lemma pow2Bounds'(n: nat)
requires n < 32
ensures 0 <= pow2(n) < 0x100000000
{
if n == 0 {
} else if n == 1 {
} else if n == 2 {
} else if n == 3 {
} else if n == 4 {
} else if n == 5 {
} else if n == 6 {
} else if n == 7 {
} else if n == 8 {
} else if n == 9 {
} else if n == 10 {
} else if n == 11 {
} else if n == 12 {
} else if n == 13 {
} else if n == 14 {
} else if n == 15 {
} else if n == 16 {
} else if n == 17 {
} else if n == 18 {
} else if n == 19 {
} else if n == 20 {
} else if n == 21 {
} else if n == 22 {
} else if n == 23 {
} else if n == 24 {
} else if n == 25 {
} else if n == 26 {
} else if n == 27 {
} else if n == 28 {
} else if n == 29 {
} else if n == 30 {
} else if n == 31 {
}
}
lemma pow2Bounds''(n: nat)
requires n < 32
ensures 0 <= pow2(n) < 0x100000000
{
if n == 2 {
} else if n == 4 {
} else if n == 6 {
} else if n == 8 {
} else if n == 10 {
} else if n == 12 {
} else if n == 14 {
} else if n == 16 {
} else if n == 18 {
} else if n == 20 {
} else if n == 22 {
} else if n == 24 {
} else if n == 26 {
} else if n == 28 {
} else if n == 30 {
}
}
lemma pow2Bounds'''(n: nat)
requires n < 32
ensures 0 <= pow2(n) < 0x100000000
{
pow2Monotone(n, 32);
}
*/