Explain what a lexicographic ranking function is and why it is more powerful than a single numeric ranking function.
Think about your answer, then reveal below.
Model answer: A lexicographic ranking function is a tuple (f1, f2, ..., fk) that decreases in lexicographic order: f1 strictly decreases, OR f1 stays the same and f2 strictly decreases, OR f1 and f2 stay the same and f3 strictly decreases, etc. This is more powerful because it handles nested loops and programs where no single expression decreases on every iteration. For example, a nested loop might keep the outer counter fixed while the inner counter decreases, then decrease the outer counter and reset the inner one — a single ranking function cannot capture this, but the pair (outer, inner) with lexicographic ordering does.
Lexicographic ranking functions correspond to the mathematical fact that the lexicographic product of well-founded orderings is well-founded. This extends to programs with multiple phases: the first component tracks one measure, the second tracks another, and so on. Most automated termination tools search for lexicographic linear ranking functions as their primary strategy, because linear arithmetic is decidable and lexicographic orderings handle the majority of real loop patterns.