Dafny array elements contained in other array assertion

烈酒焚心 提交于 2019-12-24 07:33:06

问题


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]));
}

回答1:


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.



来源:https://stackoverflow.com/questions/49723710/dafny-array-elements-contained-in-other-array-assertion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!