问题
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