I'm trying to prove the correctness of the Selection sort, in which I should use only the mathematical predicate logic to prove program correctness, I'm finding it difficult to write the English statements given below as Predicates and proceed through the proof of correctness following Inference rules,
void sort(int [] a, int n) {
for (int i=0; i<n-1; i++) {
int best = i;
for (int j=i; j<n; j++) {
if (a[j] < a[best]) {
best = j;
}
}
swap a[i] and a[best];
}
}
The statements I have to write in Predicates are,
a[0...i-1]
is sortedall entries in
a[i..n-1]
are larger than or equal to the entries ina[0..i-1]
.