-
Notifications
You must be signed in to change notification settings - Fork 1
/
InductionLoop.dfy
47 lines (40 loc) · 981 Bytes
/
InductionLoop.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
// RUN: /compile:0 /nologo /rlimit:1000000
function IsEven(a : int) : bool
requires a >= 0
{
if a == 0 then true
else if a == 1 then false
else IsEven(a - 2)
}
lemma {:induction x} EvenPlus(x: int, y: int)
requires x >= 0
requires y >= 0
requires IsEven(x)
requires IsEven(y)
ensures IsEven(x + y)
{ }
lemma {:induction y} EvenPlus2(x: int, y: int)
requires x >= 0
requires y >= 0
requires IsEven(x)
requires IsEven(y)
ensures IsEven(x + y)
{ }
// This one makes Z3 spin, as does leaving off the {:induction ...} annotation.
lemma {:induction false} EvenPlus3(x: int, y: int)
requires x >= 0
requires y >= 0
requires IsEven(x)
requires IsEven(y)
ensures IsEven(x + y)
{
EvenPlus4(x, y, x + y);
}
lemma EvenPlus4(x: int, y: int, z: int)
requires x >= 0
requires y >= 0
requires IsEven(x)
requires IsEven(y)
requires z == x + y
ensures IsEven(z)
{ }