【发布时间】:2017-02-12 20:32:28
【问题描述】:
我从 BVD 得到以下结果,我不明白。
让我感到困惑的是,第二个不变量似乎在生成反例时被忽略了。如果两个不变量是 I0 和 I1 并且保护是 G,那么肯定验证条件是 I0 && I1 && !G ==> qy > x 反例应满足对此的否定。我误会了什么?
为了方便任何需要的人,将代码复制在下面。
function TwoToThe( i : int ) : int
decreases i
requires i >= 0
{
if i==0 then 1 else 2*TwoToThe( i-1 )
}
method interestingBVD(x : int, y : int)
requires y > 0
requires x >= 0
{
var q := 1 ;
var qy := y ; // Tracks q*y
ghost var i := 0 ;
// Double q until q*y exceeds x
while( qy < x ) // Off by one error.
invariant qy == q*y
invariant q == TwoToThe(i)
decreases 2*x-qy ;
{
q, qy, i := 2*q, 2*qy, i + 1 ;
}
// In the BVD we get actual numbers!!
assert q*y == qy > x && q == TwoToThe(i) ;
}
【问题讨论】:
标签: dafny