我正在与 Dafny 合作,试图了解规范(特别是修改和确保多集)如何影响验证。
我有一个方法do_nothing
,用于修改数组 a,但确保其元素的多集保持不变。该方法的主体为空。
method do_nothing(a: array<int>)
modifies a
ensures multiset(a[..]) == multiset(old(a[..]))
{
// nothing is done
}
method test()
{
var a := new int[6] [2, -3, 4, 1, 1, 7];
assert a[..] == [2, -3, 4, 1, 1, 7]; // Verifies
assert a[0] !=0 ; // Verifies
do_nothing(a);
assert a[0] != 0; // <-- Verification Error: This assertion cannot be proved
}
我的期望:
a
由于其中根本没有 0 ,并且 dafny 同意do_nothing
确保multiset(a[..]) == multiset(old(a[..]))
。因此,断言 a[0] != 0 应该成立并验证成功。
问题:
Dafny 无法验证最终断言 assert a[0] != 0;