Exists Statement #5563
-
Hello, The predicate is intended to check if a natural number exists within the range
Could anyone help me understand why Thank you for your time and assistance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Please provide a minimal failing example. Which version of Dafny are you using? Where do you use |
Beta Was this translation helpful? Give feedback.
-
I use Dafny 4.6.0. I think this predicate is always true. But the below lemma is failed.
|
Beta Was this translation helpful? Give feedback.
-
Now Here's the final result: predicate existsNat(length: nat)
{
if length == 0 then
true
else
var p := x => 0 <= x < length;
assert p(0);
exists a: nat | 0 <= a < length :: p(a)
}
lemma theoremExistsNat(length: nat)
ensures existsNat(length)
{
assert existsNat(length);
} Footnotes |
Beta Was this translation helpful? Give feedback.
0 <= a <length
. E.g. byassert 0 <= 0 < length;
Since the predicate is not trivial enough, this still fails to verify because the verifier can't "connect" this assertion with theexists
expression. The warning "Could not find a trigger for this quantifier." hints at this. So you also need tovar p := x => 0 <= x < length; assert p(0); exists a: nat :: p(a)
. Now the verifier is able to proof that such a value exists, but there is a new error:quantifiers in non-ghost contexts must be compilable, but Dafny's heuristics can't figure out how to produ…