达夫尼:帮助适当的不变,减少陈述

时间:2016-01-23 09:50:27

标签: functional-programming dafny

任何人都可以帮我解决这里的错误。 验证此程序时出现以下错误。

我尝试了各种各样的方法,但它从未经过验证。请帮忙。

method Main() {
     var a:int := 0;
     var b:int := -1;
     var c:int := 0;
     var i:int := 100;
     while (a!=b)
     invariant 0<=c<i
     decreases i-c
     {
         b := a;
       c := c+1;
         if (c < i) {
           a := a+1;
         }
     }
    print "Eureka";
}

.............

stdin.dfy(7,19): Error BP5005: This loop invariant might not be maintained by the loop.
Execution trace:
    (0,0): anon0
    stdin.dfy(6,6): anon12_LoopHead
    (0,0): anon12_LoopBody
    stdin.dfy(6,6): anon13_Else
    stdin.dfy(6,6): anon15_Else
    (0,0): anon16_Else
    (0,0): anon10

Dafny program verifier finished with 1 verified, 1 error

1 个答案:

答案 0 :(得分:0)

添加&#34;不变c == i ==&gt; b == a;&#34;固定它。由于dafny无法在c,i和b之间建立链接,a。

method Main() {
     var a:int := 0;
     var b:int := -1;
     var c:int := 0;
     var i:int := 100;
     while (a!=b)
     invariant 0<=c<=i
     invariant c == i ==> b == a;
     decreases i-c
     {
         b := a;
         c := c+1;
         if (c < i) {
           a := a+1;
         }
     }
    print "Eureka";
}