Proofs: Chronological backtracking
These are the human proofs of Chronological backtracking, at full length.
Chronological backtracking returns the first solution, or failure when there is none full
This proof shows: correctness, termination.
We use the pseudocode of the page. For , let be the set of consistent assignments of with for each . Order the tuples of lexicographically, using the given order of each domain. A solution is an element of .
Prefix closure. If and , then . Proof. A constraint whose variables are all among has all its variables among , so it is satisfied by , and it reads only the values .
Check of line L3. If , then line L3 accepts if and only if . Proof. A constraint on variables among either does not involve , and then it is satisfied because is consistent, or it involves , and then line L3 checks it.
Lemma. Let with . Then BT terminates. It returns the lexicographically first element of that extends , if one exists, and failure otherwise. If it returns failure, then on return again assigns exactly with the same values.
Proof. By induction on .
Base, . Line L1 returns , which is in and is the only element of that extends itself.
Step, . Assume the lemma for . Let be the values of in order. We show by induction on that before the iteration for , the assignment is and no element of extends for any . This holds for . In the iteration for :
- If line L3 rejects , then by the check lemma. By prefix closure, no element of extends . The assignment is not changed.
- If line L3 accepts , then , line L4 makes the assignment , and line L5 calls BT with . By the induction hypothesis the call terminates. If it returns a solution, that solution is the first element of that extends , and line L6 returns it. If it returns failure, no element of extends , the assignment is again, and line L7 restores .
Each element of that extends has some value for . The extensions with come before those with in lexicographic order when . So when line L6 returns a solution for , there is no extension with an earlier value, and the returned solution is the first extension of . If the loop ends, no value gives an extension, so no element of extends , and line L8 returns failure with the assignment equal to . The loop has iterations, each of which terminates, so the call terminates.
Theorem. BT terminates. It returns the lexicographically first solution if a solution exists, and failure otherwise.
Proof. The empty assignment is in , and each element of extends it. Apply the lemma with .
All solutions. In the version that outputs at line L1 and never returns at line L6, the same induction, with "returns the first extension" replaced by "outputs every element of that extends , once each, in lexicographic order", shows that the search outputs all solutions, once each, in lexicographic order.