Skip to content
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

Function and such that operator interaction #6076

Open
rdivyanshu opened this issue Jan 24, 2025 · 0 comments
Open

Function and such that operator interaction #6076

rdivyanshu opened this issue Jan 24, 2025 · 0 comments
Labels
part: documentation Dafny's reference manual, tutorial, and other materials

Comments

@rdivyanshu
Copy link

rdivyanshu commented Jan 24, 2025

What change in documentation do you suggest?

These two seems to be at odd with each other

  • See Section 7.3 for a description of the function specification. A Dafny function is a pure mathematical function.

  • This form has one or more left-hand-sides, a :| symbol and then a boolean expression on the right. The effect is to assign values to the left-hand-sides that satisfy the RHS condition. .... . The given boolean expression need not constrain the LHS values uniquely: the choice of satisfying values is non-deterministic.

ghost function Any<E(!new)>(data: set<E>): E
  requires |data| != 0
{
    var key :| key in data; key
}

ghost function PredicateAny<E(!new)>(data: set<E>): bool
  requires |data| != 0
{
    var k1 :| k1 in data;
    var k2 :| k2 in data;
    k1 == k2
}

ghost function PredicateAny2<E(!new)>(data: set<E>): bool
  requires |data| != 0
{
    var k1 := Any(data); var k2 := Any(data); k1 == k2
}
  
lemma Test(s: set<int>)
  requires |s| != 0
{
    var r1 := PredicateAny(s);
    var r2 := PredicateAny2(s);
    assert r1;
    assert r2;
}

In code above assert r2 verifies but assert r1 doesn't. It seems that function referential transparency (being pure) is not followed for :| operator. Functions somehow remembers which choice it took.

@rdivyanshu rdivyanshu added the part: documentation Dafny's reference manual, tutorial, and other materials label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part: documentation Dafny's reference manual, tutorial, and other materials
Projects
None yet
Development

No branches or pull requests

1 participant