Skip to content

Timeout in verification of lemmaCal invovling real numbers #5768

@OlivierTOMATO

Description

@OlivierTOMATO

Dafny version

4.6.0

Code to produce this issue

ghost function Pick<T>(s: set<T>): T
    requires |s| > 0
{
    var x :| x in s;
    x
}

ghost function cal(s: set<real>): real
requires |s| > 0
{
    var x := Pick(s);
    if |s| == 1 then x
    else cal(s-{x}) * |s| as real
}

lemma lemmaCal(s: set<real>)
requires |s| > 1
ensures cal(s) == cal(s-{Pick(s)}) * |s| as real // Comment: A time out
{
 //  assert cal(s) == cal(s-{Pick(s)}) * |s| as real;
}

ghost function cal2(s: set<real>): real
requires |s| > 0
{
    var x := Pick(s);
    if |s| == 1 then x
    else cal2(s-{x}) + |s| as real
}

lemma lemmaCal2(s: set<real>)
requires |s| > 1
ensures cal2(s) == cal2(s-{Pick(s)}) + |s| as real
{
}

Command to run and resulting output

dafny --verification-time-limit 5 code.dfy

What happened?

I am working on a simple example involving the following functions:

  • Pick: Randomly selects a value from a set of real numbers.
  • cal: Multiplies all the values in a set and returns a real number.
  • cal2: Adds all the values in a set and returns a real number.

I have two lemmas:

  • lemmaCal: A lemma that asserts certain properties related to the above functions when the size of the set is greater than 1.
  • lemmaCal2: A similar lemma that also asserts properties when the set size is greater than 1.

Problem

  1. lemmaCal2 successfully passes the verification, but lemmaCal runs into a timeout during verification.
  2. If I add an assertion for the postcondition directly in lemmaCal and remove the postcondition, the verification passes.
  3. If I change the real numbers to integers or replace the set with a sequence (seq), the verification also passes.

Ultimately, I am looking for a way to ensure that lemmaCal() can be verified without timing out. Any insights or suggestions would be greatly appreciated!

What type of operating system are you experiencing the problem on?

Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugCrashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions