-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The value of a let-such-that expression must be uniquely determined #18
Comments
Hmmm, yeah that is in the model indeed. |
So, this is strange. This code fails to compile: function f(items: set<nat>) : (r:nat)
requires |items| > 0 {
var item :| item in items;
item
} Whilst on the other hand, this code does indeed compile: method m(items: set<nat>) returns (r:nat)
requires |items| > 0 {
var item :| item in items;
return item;
} Not sure what's going on here. |
I've raised an issue for this now: dafny-lang/dafny#4564 |
@DavePearce , maybe this is just a feature of how functions should behave, considering the differences below, functions are transparent, so looping inside functions should be a non-transparent behaviour.
So this is one case [I found this example] that make the function works: function f(s: set<int>) : (z:int)
requires s != {} {
has_minimum(s);
var z :| z in s && forall y :: y in s ==> z <= y;
z
}
lemma has_minimum(s: set<int>)
requires s != {}
ensures exists z :: z in s && forall y :: y in s ==> z <= y {
var z :| z in s;
if s == {z} {
// the mimimum of a singleton set is its only element
} else if forall y :: y in s ==> z <= y {
// we happened to pick the minimum of s
} else {
// s-{z} is a smaller, nonempty set and it has a minimum
var s' := s - {z};
has_minimum(s');
var z' :| z' in s' && forall y :: y in s' ==> z' <= y;
// the minimum of s' is the same as the miminum of s
forall y | y in s
ensures z' <= y {
if
case y in s' =>
assert z' <= y; // because z' in minimum in s'
case y == z =>
var k :| k in s && k < z; // because z is not minimum in s
assert k in s'; // because k != z
}
}
} Maybe the sum should be implemented only in terms of method instead of function ? |
Hey @henry-hz, So, Rustan has responded to this on stackoverflow (see comments). He said this:
Its not clear to me whether he is going to offer an alternative mechanism for iterating sets.
I understand why you are suggesting this, but it is not a good idea unfortunately. This because There are only a few suggestions I can think of:
I guess another option might be to use |
The problem here is that I don't see how you can convert from |
Actually, in the case of
This works because its only used as a specification element. So that is fine! I should add that, as a general solution, I don't really like it because I always want to be able to run my code. But for this particular case, it seems fine. I hope that the Dafny team provide an alternative in the future. |
…-expression-must-be-uniquely-determined Fix #18
@DavePearce thanks for the solution and sharing the steps to reach it! |
Thanks for merging the #14 @DavePearce
but we still have this error I couldn't fix.
The text was updated successfully, but these errors were encountered: