Proofs: Depth-limited search
These are the human proofs of Depth-limited search, at full length.
Depth-limited search stops, and its answer of path, cutoff or failure is exact full
This proof shows: correctness, termination.
We use the pseudocode of the page with the check for cycles. Without the check, read "path" below as "path that may repeat states" and treat onpath as always empty; each step of the proof stays the same. Let be the tree of paths from that repeat no state. A call DLS is made for a node of that ends at , and has depth .
Invariant 1. When DLS is called for the path , the set onpath is exactly the set of states of , and each call leaves onpath as it found it.
Proof. At line L2 the path is and onpath by line L1. A call adds at line L9 before the recursive call for the path followed by , and removes it at line L11 after the call returns, and was not in onpath by the test of line L8. The call returns at lines L3, L5, L6, L12 or L14, and each recursive call that it made has already undone its own addition.
Theorem 1 (termination). If each state has finitely many successors, the search stops after at most calls, where is the largest number of successors.
Proof. Each call with makes at most calls with , and a call with makes none. By induction on , a call with budget makes at most calls in total, itself included. Each call does finitely many other steps.
Lemma 2 (meaning of a returned path). If DLS returns a list for the path , then starts at , follows SUCCESSORS, ends at a goal state, has at most actions, and followed by without its first state repeats no state.
Proof. By induction on . A list is returned at line L3, where and is a goal, or at line L12, where followed by the list of a call DLS for a successor of not on . By induction, is a path from to a goal with at most actions that avoids the states of followed by , apart from itself. So has at most actions and the claim holds.
Applied to the first call, Lemma 2 shows that a returned path goes from to a goal with at most actions and repeats no state.
Lemma 3 (completeness within the budget). Let DLS be called for the path . If some goal state can be reached from by a path of at most actions that avoids the states of other than , then the call returns a path.
Proof. By induction on . If is a goal, line L3 returns. Otherwise the path to a goal has at least one action, so , and its second state is a successor of that is not on . So line L8 tries , unless an earlier child already returned a path at line L12. By Invariant 1 the call DLS is made for followed by , and the rest of the path to the goal has at most actions and avoids that path. By induction it returns a path, and line L12 returns.
A path to a goal of at most actions can be shortened to one that repeats no state, by cutting out each cycle. So by Lemma 3 with and , the search returns a path when some goal is within actions of .
Lemma 4 (meaning of failure). If DLS for the path returns failure, then no path from that avoids the states of other than has more than actions, and none of them ends at a goal.
Proof. By induction on . For , failure comes from line L6: is not a goal and each successor of is on , so each path that avoids has 0 actions. For , failure comes from line L14 with cut false: is not a goal, no child returned a path, and no child returned cutoff, so each child not on returned failure. A path from that avoids and has at least one action starts with such an , and by induction its remainder has at most actions and does not end at a goal.
Theorem 5 (the answer is exact).
- The search returns a path if and only if some goal has a path of at most actions from , and the path is such a path.
- If it returns failure, no goal can be reached from .
- If it returns cutoff, no goal has a path of at most actions, and some path from that repeats no state has more than actions.
Proof. Part 1 is Lemma 2 and Lemma 3 for the first call. For part 2, Lemma 4 for the first call says that each path from that repeats no state has at most actions and does not end at a goal. Each reachable goal has a path that repeats no state, so no goal is reachable. For part 3, the first half is part 1. For the second half, follow the chain of calls that returned cutoff, from the first call down. A call returns cutoff at line L14 only if one of its children returned cutoff, and at line L5 only if and has a successor not on the path. So the chain ends at a call with , for a path of actions, which extends to a path of actions that repeats no state.