Skip to content
24 changes: 24 additions & 0 deletions proofs/max_min_properties.dfy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this proof stub directly passes and trivially proves the test case. I think the test case needs to include more things so that the proof would actually require code in the body of the function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think i have fixed this now.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
lemma {:induction false} MaxMin_Bounds(a: int, b: int)
ensures Max(a, b) >= a
ensures Max(a, b) >= b
ensures Min(a, b) <= a
ensures Min(a, b) <= b
ensures Max(a, b) == a || Max(a, b) == b
ensures Min(a, b) == a || Min(a, b) == b
{
}

lemma {:induction false} MaxMin_Symmetry(a: int, b: int)
ensures Max(a, b) == Max(b, a)
ensures Min(a, b) == Min(b, a)
ensures Max(a, a) == a
ensures Min(a, a) == a
{
}

lemma {:induction false} MaxMin_Relation(a: int, b: int)
ensures a <= b ==> Max(a, b) == b && Min(a, b) == a
ensures b <= a ==> Max(a, b) == a && Min(a, b) == b
{
}

59 changes: 59 additions & 0 deletions testcases/max_min_properties.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function {:induction false} Max(a: int, b: int): int
{
if a >= b then a else b
}

function {:induction false} Min(a: int, b: int): int
{
if a <= b then a else b
}

// Test 1: bounds + “returns one of the arguments”.
method {:induction false} Test_MaxMin_Bounds(a: int, b: int)
{
assert
Max(a, b) >= a &&
Max(a, b) >= b &&
Min(a, b) <= a &&
Min(a, b) <= b &&
(Max(a, b) == a || Max(a, b) == b) &&
(Min(a, b) == a || Min(a, b) == b)
by
{
MaxMin_Bounds(a, b);
}
}

// Test 2: commutativity + idempotence.
method {:induction false} Test_MaxMin_Symmetry(a: int, b: int)
{
assert
Max(a, b) == Max(b, a) &&
Min(a, b) == Min(b, a) &&
Max(a, a) == a &&
Min(a, a) == a
by
{
MaxMin_Symmetry(a, b);
}
}

// Test 3: case-wise behavior (ordering).
method {:induction false} Test_MaxMin_Relation(a: int, b: int)
{
if a <= b {
assert Max(a, b) == b && Min(a, b) == a
by
{
MaxMin_Relation(a, b);
}
} else {
assert Max(a, b) == a && Min(a, b) == b
by
{
MaxMin_Relation(a, b);
}
}
}