Dafny array elements contained in other array asse

2019-07-23 04:55发布

The question is rather simple: why does the assertion bellow return "assertion violation".

method test()
{
  var a := new int[5];
  a[0] := 1;
  a[1] := 1;
  a[2] := 2;
  a[3] := 3;
  a[4] := 3;
  var b := new int[3];
  b[0] := 1;
  b[1] := 2;
  b[2] := 3;
  assert(forall i :: exists j :: ((0 <= i < 5) && (0 <= j < 3)) ==> (a[i] == b[j]));
}

标签: dafny
1条回答
ら.Afraid
2楼-- · 2019-07-23 05:23

Here's one way to fix it. Add the following assertions before your assertion.

assert b[0] == 1;
assert b[1] == 2;

It seems that under a quantifier can only remember the value of the most recent assignment to b, which explains why no extra assertion about b[2] is required.

查看更多
登录 后发表回答