Skip to content

How does the Dafny Programming Language compile-time check its constraints? #1898

Answered by MikaelMayer
lancejpollard asked this question in Q&A
Discussion options

You must be logged in to vote

Let me get started on this one, let's forget about mutable references, let's only consider a program like this, which is an unoptimized version of "maximum"

method Maximum(a: int, b: int) returns (m: int)
  ensures m >= a && m >= b;
  ensures m == a || m == b
{
  m := a;
  while (m < a || m < b)
    invariant m <= a || m <= b
  {
    m := m + 1;
  }
}

You can actually desugar this program for verification purpose into blocks that don't have loops, and into special commands that don't have a compilation equivalent like assume (but that's fine, it's no code to execute, only for Hoare logic)

method Maximum(a: int, b: int) return (m: int)
{
// Block 1, including the invariants of the loop
  //

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lancejpollard
Comment options

@lancejpollard
Comment options

@MikaelMayer
Comment options

Answer selected by lancejpollard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants