Dafny断言既不真实也不虚假

时间:2016-07-06 06:39:25

标签: dafny

Dafny谓词既不是真也不是假?

此:

predicate sorted(s: seq<int>)
{
  forall j, k :: 0 <= j < k < |s| ==> s[j] <= s[k]
}

lemma SortedTest()
{
  assert  sorted([1, 3, 2]);
  assert !sorted([1, 3, 2]);
}

产生双断言违规行为:

Dafny program verifier version 1.9.7.30401, Copyright (c) 2003-2016, Microsoft.
Sort.dfy(8,10): Error: assertion violation
Sort.dfy(3,2): Related location
Sort.dfy(3,43): Related location
Execution trace:
    (0,0): anon0
Sort.dfy(9,9): Error: assertion violation
Execution trace:
    (0,0): anon0

Dafny program verifier finished with 2 verified, 2 errors

1 个答案:

答案 0 :(得分:3)

Dafny并不是说断言是假的,而是说它不能证明他们持有。如果你给它一些帮助,那么它将证明那是真的:

predicate sorted(s: seq<int>)
{
  forall j, k :: 0 <= j < k < |s| ==> s[j] <= s[k]
}

lemma SortedTest()
{
  var a := [1, 3, 2];
  assert a[0] == 1 && a[1] == 3 && a[2] == 2;
  assert  sorted(a);
  assert !sorted(a);
}