blob: 13db1bfc9bc41b997d28f02c467a28f67967616b (
plain)
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
|
// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
abstract module Specification {
function method Pick(s: set<int>): int
requires s != {}
ensures Pick(s) in s
}
module Attempt_Arbitrary refines Specification {
function method Pick...
{
var x :| x in s; // error: cannot prove this is deterministic
x
}
}
module Attempt_Smallest refines Specification {
function method Pick...
{
ASmallestToPick(s);
var x :| x in s && forall y :: y in s ==> x <= y;
x
}
lemma ASmallestToPick(s: set<int>)
requires s != {}
ensures exists x :: x in s && forall y :: y in s ==> x <= y
{
var z :| z in s;
if s != {z} {
var s' := s - {z};
assert forall y :: y in s ==> y in s' || y == z;
ASmallestToPick(s');
}
}
}
module AnotherTest {
function method PickFromSingleton<U>(s: set<U>): U
requires exists y :: s == {y}
{
var x :| x in s; x
}
function method PickFromPair<U(==)>(a: U, b: U): U
requires a != b
{
var x :| x in {a,b} && x != a; x
}
}
|