2

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
4

1 回答 1

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);
}
于 2016-08-08T14:44:35.890 回答