method BinarySearch(arr: array<int>, target: int) returns (index: int)
ensures -1 <= index < arr.Length
ensures index == -1 ==> not_found(arr, target)
ensures index != -1 ==> found(arr, target, index)
var low, high := 0 , arr.Length-1;
invariant 0 <= low <= high + 1
invariant low-1 <= high < arr.Length
invariant forall i :: 0 <= i <= low && high <= i < arr.Length ==> arr[i] != target
var mid := (low + high) / 2;
else if arr[mid] < target
predicate sorted(a: array<int>)
forall j, k :: 0 <= j < k < a.Length ==> a[j] <= a[k]
predicate distinct(arr: array<int>)
forall i, j :: 0 <= i < arr.Length && 0 <= j < arr.Length ==> arr[i] != arr[j]
predicate not_found(arr: array<int>, target: int)
(forall j :: 0 <= j < arr.Length ==> arr[j] != target)
predicate found(arr: array<int>, target: int, index: int)
requires -1 <= index < arr.Length;
if index == -1 then false
else if arr[index] == target then true