class ArraySet { private static Object[] a; public static int size; /*: public static ghost specvar init :: bool; public static specvar content :: objset; vardefs "content == {n. EX j. n = a.[j] & 0 <= j & j < size}"; invariant "init --> a ~= null & 0 < a..Array.length & 0 <= size & size <= a..Array.length"; */ public static void initialize() /*: modifies init, content ensures "init & content = {}"; */ { a = new /*: hidden */ Object[100]; size = 0; //: init := "True"; } public static boolean contains(Object x) /*: requires "init & x ~= null" ensures "result = (x : content)"; */ { /*: private static ghost specvar content_i :: objset; private specvar bounds :: bool; private vardefs "bounds == 0 <= i & i <= size"; private specvar a_i :: obj; private vardefs "a_i == a.[i]"; */ int i = 0; //: content_i := "{}"; while /*: inv "0 <= i & i <= size & (content_i = {n. EX j. n = a.[j] & 0 <= j & j < i }) & (x ~: content_i)" */ (i < size) { if (a[i] == x) { return true; } else { //: content_i := "content_i Un {a.[i]}"; i = i + 1; } } return false; } public static void driver() { int i = 0; int n = 10; boolean b0; boolean b1; Object j; initialize(); while (i < n) { j = new Object (); add(j); i = i + 1; } Object k = new Object (); b0 = containsVC(j); b1 = containsVC(k); //: assert "b0"; //: assert "~b1"; } }