Slide 10.2: Applications of Hoare logic Slide 10.4: The weakest precondition wp Home |
a[1] … a[n]
could be specified as follows:
{n ≥ 1 and for all i, 1 ≤ i ≤ n, a[i] = A[i]} sort-program {sorted( a ) and permutation( a, A )}The assertions are as follows:
sorted(a)
means the elements of a
are sorted.
permutation( a, A )
means the elements of a
are the same, except for order, as the original elements of the array A
.
assert
allows programs to be terminated with an error message on assertion failure, which can be a useful debugging feature:
x
and y
.
When x ≥ y
, the program halts and an error message is printed.