-
Notifications
You must be signed in to change notification settings - Fork 1
/
EvenPredicate.dfy
61 lines (55 loc) · 1.12 KB
/
EvenPredicate.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
// RUN: /compile:0 /nologo
function IsEven(a : int) : bool
requires a >= 0
{
if a == 0 then true
else if a == 1 then false
else IsEven(a - 2)
}
lemma EvenSquare(a : int)
requires a >= 0
ensures IsEven(a) ==> IsEven(a * a)
{
if a >= 2 && IsEven(a) {
EvenSquare(a - 2);
assert a * a == (a - 2) * (a - 2) + 4 * a - 4;
EvenDouble(2 * a - 2);
EvenPlus((a - 2) * (a - 2), 4 * a - 4);
}
}
lemma EvenDouble(a: int)
requires a >= 0
ensures IsEven(a + a)
{
if a >= 2 {
EvenDouble(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)
{
if x >= 2 {
EvenPlus(x - 2, y);
}
}
/*
lemma {:induction x} EvenTimes(x: int, y: int)
requires x >= 0
requires y >= 0
requires IsEven(x)
requires IsEven(y)
ensures IsEven(x * y)
{
if x >= 2 {
calc {
IsEven(x * y);
IsEven((x - 2) * y + 2 * y); { Check1(y); EvenPlus((x - 2) * y, 2 * y); }
true;
}
}
}
*/