Chapter 8: The Heuristic's Contract — How Much Courage It Takes to Accept "Close Enough"
If A*'s heuristic lies to you, it will still hand you a path. It's just the wrong one.
1. The Bet of 1968
In 1968, Peter Hart, Nils Nilsson, and Bertram Raphael at the Stanford Research Institute proposed an algorithm in a paper — an algorithm that would turn out to be one of the most elegant ideas in the history of AI.
The problem they wanted to solve was simple: help the robot Shakey find the shortest path from point A to point B in a room.
Brute-force search guarantees the optimal solution — try every possible path, pick the shortest. But Shakey's world has millions of possible path combinations, and brute-force search would need an astronomical amount of time.
Greedy search is fast — you always head toward the goal. But it can slam into obstacles, walk into dead ends, and find paths much longer than the optimal one.
The A* algorithm that Hart and his two colleagues proposed made a seemingly impossible promise: I can be orders of magnitude faster than brute force, while still guaranteeing the optimal solution.
What does that promise cost? A contract.
If you give A* an "honest" heuristic — one that never overestimates the remaining cost — it keeps its promise. But if the heuristic "lies" and overestimates, A* will still give you a path. It's just that the path may be wrong.
That's not a bug in the algorithm; it's by design. A* buys the balance between speed and optimality with a mathematical contract.
More than fifty years later, this contract's idea is still the heart of all heuristic algorithms: when perfection is out of reach, we need approximation at an explicit cost.
2. The Curse of Combinatorial Explosion
Let me first quantify what "perfection is out of reach" means.
In 2016, AlphaGo beat Lee Sedol. The world marveled at the machine's "intuition" and "creativity". But very few people noticed a technical detail: behind every move of AlphaGo, Monte Carlo tree search explored millions of possibilities on a 19×19 board.
Not hundreds, not thousands — millions.
Why so many? Because Go's state space is about
Even at
This isn't an engineering problem. It's physically impossible.
Combinatorial explosion shows up everywhere:
The traveling salesperson problem: a visit to n cities has
possible routes. For 20 cities, that's routes. Protein folding: a protein of 100 amino acids, each with 3 main conformations, gives
possible ways to fold. Theorem proving: in first-order logic, the number of possible proof steps for a proof of length n grows exponentially in n.
This is why heuristics exist: when the optimal solution is out of reach, we need a "good enough" solution.
But what does "good enough" even mean? That's not a vague engineering question — it's a precise mathematical one. Heuristic algorithms must obey certain contracts — and if they break them, the "approximate solution" they produce can be entirely wrong.
Let's go back to 1968 and see how Hart, Nilsson, and Raphael designed that contract.
3. The Mathematical Contract of A*
Imagine you're in a maze, trying to get from the start S to the goal G. Every step has a cost (time or distance, say). You want the path with the smallest cost.
Brute-force search (Dijkstra's algorithm) tries every possible path and guarantees the optimum, but its time complexity is
Dijkstra's Algorithm: The Brute-Force Guarantee for Shortest Paths
Dijkstra's algorithm (named for the Dutch computer scientist Edsger Dijkstra, who proposed it in 1956) finds the shortest path by repeatedly taking the unvisited node with the smallest known cost, expanding its neighbors, and carrying on until it reaches the goal.
- Guarantee: if every edge cost is non-negative, Dijkstra always finds the optimal (lowest-cost) path
- Cost: it explores all possible paths — it doesn't know "roughly which way to go", so it's inefficient
Branching factor
Search depth
Combined, the search space is
Greedy search always chooses the direction that "looks closest to the goal". It's fast, but it can walk into dead ends. Worse, the path it finds may be several times longer than the optimal one.
When A* was introduced in 1968, it made a seemingly impossible promise: I can be faster than Dijkstra, and still find the optimal path.
Its core is an evaluation function:
: the actual cost from the start to node n (known, certain) : the estimated cost from n to the goal (unknown, a guess) : the estimated total cost of reaching the goal through n
A* always expands the node with the smallest
The intuition is simple: if you've already walked 10 steps to reach node n, and you estimate it takes 5 more steps to reach the goal, then the total cost through n is about 15 steps. A* explores the path with the smallest total cost first.
But there's a fatal question here: how do you estimate
If
If
Hart, Nilsson, and Raphael proved a profound theorem: if the heuristic satisfies admissibility, A* is guaranteed to find the optimal path.
The definition of admissibility:
where
In other words, the heuristic must be optimistic — it must never overestimate the remaining cost. You may underestimate (which makes the search slower), but you may not overestimate (which makes the search find a wrong answer).
That's the A* contract: give me an admissible heuristic, and I guarantee the optimal path. Break the contract, and the guarantee is void.
Why does this contract work? Let me show it with a concrete example.
4. Try It Yourself: Watch the Contract Break
Admissibility isn't an abstract mathematical requirement. It's a necessary and sufficient condition for A* to find the optimal path.
Let's verify it with our own hands.
Experiment goal: run A* on the same maze with an admissible heuristic and with an inadmissible one, and see what differs.
Maze map (0 = walkable, 1 = obstacle, S = start, G = goal):
S . . . . .
. . . # . .
. . . . # .
. . . . . .
. . . . . #
. . . . . GS is the start (0,0); G is the goal (5,5)
.is a walkable cell; each step costs 1#is an obstacle — not walkable
Task: find the shortest path from S to G.
import heapq
# --- maze definition: 6 rows x 6 cols, 1 = obstacle, 0 = walkable ---
# S=(0,0), G=(5,5)
GRID = [
[0, 0, 0, 0, 0, 0], # row 0: S . . . . .
[0, 0, 0, 1, 0, 0], # row 1: . . . # . .
[0, 0, 0, 0, 1, 0], # row 2: . . . . # .
[0, 0, 0, 0, 0, 0], # row 3: . . . . . .
[0, 0, 0, 0, 0, 1], # row 4: . . . . . #
[0, 0, 0, 0, 0, 0], # row 5: . . . . . G
]
ROWS, COLS = len(GRID), len(GRID[0])
START = (0, 0)
GOAL = (5, 5)
def neighbors(r, c):
"""Yield the walkable neighbors (up, down, left, right)."""
for dr, dc in [(-1,0),(1,0),(0,-1),(0,1)]:
nr, nc = r+dr, c+dc
if 0 <= nr < ROWS and 0 <= nc < COLS and GRID[nr][nc] == 0:
yield nr, nc
def reconstruct_path(parent, node):
"""Reconstruct the path by backtracking through the parent dict."""
path = []
while node is not None:
path.append(node)
node = parent[node]
return list(reversed(path))
def astar(h_func, label="A*"):
"""
Generic A* search.
h_func(r, c) is the heuristic; returns (path length, path, number of expanded nodes).
"""
# priority queue items: (f, g, node)
open_heap = [(h_func(*START), 0, START)]
g_cost = {START: 0} # actual cost from start to each node
parent = {START: None} # parent pointers for path reconstruction
closed = set()
expanded = 0 # counted expanded nodes
while open_heap:
f, g, node = heapq.heappop(open_heap)
if node in closed:
continue
closed.add(node)
expanded += 1
# reached the goal
if node == GOAL:
path = reconstruct_path(parent, node)
return len(path) - 1, path, expanded # steps = nodes - 1
# expand neighbors
for nb in neighbors(*node):
new_g = g + 1 # each step costs 1
if nb not in g_cost or new_g < g_cost[nb]:
g_cost[nb] = new_g
parent[nb] = node
f_val = new_g + h_func(*nb)
heapq.heappush(open_heap, (f_val, new_g, nb))
return None, [], expanded # no solution
# --- step 1: admissible heuristic -- Manhattan distance ---
# h₁(n) = |n_row - G_row| + |n_col - G_col|
# never overestimates the remaining cost -> admissible -> optimal solution
def h_admissible(r, c):
"""Manhattan distance: admissible, never overestimates."""
return abs(r - GOAL[0]) + abs(c - GOAL[1])
steps1, path1, exp1 = astar(h_admissible, "admissible A*")
print("=== Step 1: admissible heuristic (Manhattan distance) ===")
print(f"path length: {steps1} steps")
print(f"expanded nodes: {exp1}")
print(f"path: {path1}")
# --- step 2: inadmissible heuristic -- Manhattan distance × 2 ---
# h₂(n) = 2 × (|n_row - G_row| + |n_col - G_col|)
# overestimates the remaining cost -> violates admissibility -> may find a suboptimal path
def h_inadmissible(r, c):
"""2x Manhattan distance: inadmissible, overestimates."""
return 2 * (abs(r - GOAL[0]) + abs(c - GOAL[1]))
steps2, path2, exp2 = astar(h_inadmissible, "inadmissible A*")
print("\n=== Step 2: inadmissible heuristic (2x Manhattan distance) ===")
print(f"path length: {steps2} steps")
print(f"expanded nodes: {exp2}")
print(f"path: {path2}")
# --- comparison ---
print("\n=== Comparison ===")
print(f"admissible heuristic -> {steps1} steps (optimality guaranteed)")
print(f"inadmissible heuristic -> {steps2} steps ({'optimal' if steps1==steps2 else 'suboptimal'})")
if steps1 != steps2:
print(f" gap: {steps2 - steps1} steps (contract broken: found a longer path)")
print(f"\nnote: the admissible version expanded {exp1} nodes, the inadmissible version expanded {exp2} nodes.")
print(" the inadmissible heuristic expands fewer nodes and is faster, but trades away the optimality guarantee.")Step 1: With an Admissible Heuristic
The simplest admissible heuristic is the Manhattan distance:
This is the cost of "walking straight to the goal if there were no obstacles". Because the real path has to get around obstacles,
Starting from S, compute
| Node | g(n) | h₁(n) | f(n) |
|---|---|---|---|
| S right | 1 | 9 | 10 |
| S down | 1 | 9 | 10 |
The two tie on
Step 2: With an Inadmissible Heuristic
Now let's break the contract on purpose. Define an overestimating heuristic:
This function estimates the remaining cost at twice the Manhattan distance — clearly an overestimate.
Starting from S again:
| Node | g(n) | h₂(n) | f(n) |
|---|---|---|---|
| S right | 1 | 18 | 19 |
| S down | 1 | 18 | 19 |
Both tie on
That sets a trap. After the fork at (0,2):
- The right-turn route: 5 straight steps to (0,5), with
decreasing every step — like a snowball, it rolls faster and faster - The gap route: drop to (1,2), but the right neighbor (1,3) is walled off by an obstacle; you have to drop another level before you can turn right — one extra step before you see any progress
The decreasing
Result: the inadmissible
The crash wasn't an accident. One fundamental limitation of heuristic design is this: you cannot reliably predict how a heuristic will behave before running it. We always assume overestimating a bit is just "less accurate", but the
This is the meaning of admissibility: if
But admissibility comes at a price too.
5. An Information-Theoretic View: The Entropy Cost of a Heuristic
Admissibility guarantees correctness. But what does it cost?
Consider two extremes.
Extremely conservative:
That's admissible, obviously (since the true cost
Extremely aggressive:
That would be ideal — A* walks the optimal path directly, exploring no useless node. It's zero-entropy search: you already know the answer, so no exploration is needed. But here's the catch: if you already knew
Real-world heuristics live in between: as close to
This trade-off can be measured with the effective branching factor
where
Pearl's classic 1984 textbook gives experimental data:
With
, (on the 8-puzzle) With
, With better heuristics (like pattern databases),
Going from 2.8 down to 1.1 means the tree's node count falls from
The quality of the heuristic directly determines how much compute the search needs.
But underneath there's a deeper tension: good heuristics need domain knowledge. The Manhattan distance works on grids — but what about graph search? Continuous spaces? Go?
In complicated environments, designing a heuristic that is both admissible and close to
That's the problem ADS (Adaptive Dual Search) sets out to solve: can a machine learn the heuristic on its own?
6. ADS: Making Heuristics Information-Theoretic
Traditional heuristic design has a fundamental flaw:
But search spaces are dynamic. In open areas, the heuristic deserves trust; in obstacle-dense areas, any heuristic can mislead. A fixed weight
ADS (Adaptive Dual Search) raises a question: can we quantify the trustworthiness of a heuristic with information theory, so that the weight adjusts automatically to the uncertainty of the current state?
The core idea ties the heuristic weight
- When the model is highly certain about the current state (low entropy),
is large — trust the heuristic and advance quickly - When the model is full of uncertainty (high entropy),
— a barrier forms, refusing entry to high-uncertainty regions
This is not parameter tuning — it's turning uncertainty into an actionable search constraint. A*'s admissibility guarantees "no overestimation"; ADS's entropy barrier guarantees "no wandering into high-entropy dead ends".
Its relationship to admissibility: admissibility constrains the range of
The full technical details of ADS, and how it applies to the reasoning space of LLMs, unfold in Chapter 10.
6.6 The Barrier Is Not Greed: The Ontological Difference Between ADS and a Selection Function
Before we continue, I have to clear up a misunderstanding that is extremely easy to fall into.
ADS's logarithmic barrier
No. That "no" reaches down into a basic categorical error in the taxonomy of search algorithms. Let me pin the difference down with a thought experiment.
Two mazes.
Maze A (greedy): you are in a fixed maze. Every junction has three directions. Each time, you choose the one that "looks closest to the exit". There are directions you never walk — not because you can't walk them, but because you chose not to.
Maze B (ADS): you are in a dynamic maze. Every time you approach a high-uncertainty region (multiple forks ahead, sight blocked), the maze itself deforms — those high-uncertainty directions get sealed off by a wall of energy. You haven't "chosen not to go"; you cannot go. When the uncertainty dissipates (clear view, obvious path), the wall dissolves and every direction is walkable again.
This isn't rhetoric. These are two different kinds of mathematical objects:
- A greedy algorithm: given a graph
, it defines a selection function , with — it makes choices on a fixed set of reachable states. - ADS: given a graph
, it defines a topological operator — it removes or restores edges according to local entropy, directly altering the reachable set itself.
Greedy changes the choice made on a given set. ADS changes the set itself.
The physics verdict. In classical mechanics, a particle moves in a potential field
Why is entropy not a "locally greedy" quantity? A greedy
Why is the distinction so easy to confuse? Because greedy and ADS behave identically in simple settings — on a straight road with no forks, "choose the lowest-entropy direction" and "exclude the high-entropy directions" take the same route. The difference only appears in complex terrain: when the optimal path must temporarily cross a high-uncertainty region, greedy can go wrong because the selection function is myopic, and ADS can go wrong because the topology reshaping is over-aggressive and walls off the correct detour. But they fail for different reasons — fixing greedy means improving the selection function (a better heuristic, deeper lookahead); fixing ADS means tuning the barrier's sensitivity (changing how
A formal distinction:
| Greedy / A* / MCTS | ADS | |
|---|---|---|
| Operates on | a fixed graph | a dynamic graph |
| Kind of operation | a selection function | a topological operator |
| Source of information | external cost estimate | internal cognitive state |
| Level of cognition | zero-order (pick the best neighbor) | second-order (the system knows what it doesn't know) |
| Failure mode | myopia of the selection function | over-aggressive topology reshaping |
Put together. A* proves that on a fixed topology, a good selection function can cut the search cost without sacrificing optimality — that's the wisdom of choice. MCTS proves that on a fixed topology, random sampling plus statistical backpropagation can approach optimality with no heuristic at all — that's the wisdom of statistics. ADS proves that if you give up the fixed-topology assumption and reshape the search space dynamically with information-theoretic quantities, you get a search strategy of a completely different kind — that's the wisdom of geometry. Reading ADS as greed misses its most important insight: the shape of the search space itself is a variable you can optimize.
7. The Approximation Algorithm's Contract: Give Up Optimality, Keep the Guarantee
A*'s admissibility guarantees the optimum, but the price is exploring every "possibly optimal" path. On some problems, that's still too slow.
In 1973, computational complexity theory hit a turning point. Stephen Cook proved that SAT is NP-complete — if you can solve it in polynomial time, you can solve every NP problem.
That proof triggered a deep philosophical shift: maybe we should give up hunting for the optimal solution and settle for "good enough".
But "good enough" needs a precise definition. Otherwise, any algorithm can just claim to be "good enough".
In 1974, David Johnson introduced the approximation ratio. For minimization problems, an α-approximation algorithm guarantees:
This is a worst-case guarantee — no matter the input, the approximation ratio never exceeds α.
Let me show a classic example.
7.1 Vertex Cover: A 2-Approximation Algorithm
Vertex cover: given a graph, find the smallest set of vertices such that every edge has at least one endpoint in the set.
This problem is NP-complete. Brute force has to check
But there's an extremely simple 2-approximation algorithm:
import random
def greedy_vertex_cover(edges):
"""
Greedy vertex cover: 2-approximation algorithm, O(|E|).
edges: [(u, v), ...] list of edges
returns: vertex cover set C, guaranteeing |C| <= 2|C*|
"""
remaining = list(edges)
C = set()
while remaining:
u, v = random.choice(remaining) # pick a random edge
C.add(u)
C.add(v)
# remove all edges incident to u or v
remaining = [(a, b) for a, b in remaining if a not in (u, v) and b not in (u, v)]
return CThe algorithm runs in
where
Proof (a classic technique of approximation analysis):
For every edge
Our algorithm picks both. So the number of vertices we pick is at most twice the optimal solution.
This guarantee is tight — there are inputs where the algorithm hits exactly 2×. But it's a worst-case guarantee: whatever the input, the ratio never exceeds 2.
7.2 PTAS: Getting Arbitrarily Close to Optimal
The holy grail of approximation algorithms is the PTAS (Polynomial-Time Approximation Scheme).
A PTAS is a family of algorithms: for any
In other words, you can get as close to optimal as you like — want 99% optimality? Fine. 99.9%? Also fine. The price is just a growth in the polynomial time.
[Li & Jin, 2015] provided the first PTAS for the weighted unit-disk covering problem. This problem has important applications in wireless network design: given points on a plane, cover all of them with as few unit disks as possible.
Their algorithm runs in
This reveals the PTAS's limit: theoretically feasible, practically maybe not.
The approximation algorithm's contract: I won't guarantee the optimal solution, but I guarantee mine isn't too bad — and I can tell you exactly how bad "not too bad" is. That's an honest contract. It's far stronger than "I did my best".
8. Pseudocode: A* and Adaptive Heuristic Weights
Let me formalize the core algorithms we've discussed.
Algorithm 1: Standard A* search
import heapq
def astar(graph, start, goal, h):
# graph: dict {node: [(neighbor, cost), ...]}
# h: heuristic h(node) -> estimated cost to the goal
# returns: the shortest path list, or None (no solution)
open_heap = [(h(start), 0, start, [start])] # (f, g, node, path)
closed = set()
while open_heap:
f, g, node, path = heapq.heappop(open_heap)
if node == goal:
return path
if node in closed:
continue
closed.add(node)
for neighbor, cost in graph.get(node, []):
if neighbor in closed:
continue
g_new = g + cost
heapq.heappush(open_heap, (g_new + h(neighbor), g_new, neighbor, path + [neighbor]))
return None # no solutionTime complexity:
Algorithm 2: ADS adaptive heuristic weights
import math
def ads_search(start, goal, cost_fn, h_fn, policy_fn):
# policy_fn(s) -> action probability distribution dict {action: prob}
# h_fn(s) -> heuristic estimate (cost to the goal)
# cost_fn(s,a) -> cost of executing action a
def entropy(probs):
return -sum(p * math.log(p + 1e-10) for p in probs if p > 0)
s, path, g = start, [start], 0.0
while s != goal:
action_probs = policy_fn(s)
actions = list(action_probs.keys())
probs = list(action_probs.values())
U_s = entropy(probs)
H_max = math.log(len(actions) + 1e-10)
# logarithmic barrier: as B_s -> 1, alpha -> infinity, ruling out high-entropy dead ends
B_s = U_s / (H_max + 1e-10)
alpha = -math.log(1 - B_s + 1e-10)
best_action, best_f = None, float("inf")
for action in actions:
f_val = g + cost_fn(s, action) + alpha * h_fn(action)
if f_val < best_f:
best_f, best_action = f_val, action
g += cost_fn(s, best_action)
s = best_action
path.append(s)
return pathThe key innovation: α is not fixed — it adapts dynamically to the information-theoretic character of the current state. When entropy is high (much uncertainty), rely less on the heuristic; when entropy is low, trust the heuristic and advance fast.
9. Seeing It: How the Heuristic Weight Shapes the Search Path
Picture a 2D grid world with obstacles and a goal. Different heuristic weights α lead to completely different search behavior.

*Search behavior under three heuristic weight settings: (a) α=0 (Dijkstra): uniform diffusion — explores every direction, guarantees optimality but inefficient. (b) α=1 (standard A*): advances along the heuristic direction, with moderate backtracking around obstacles. (c) α=2 (greedy): over-trusts the heuristic and may fall into a local optimum. Green is the start, red the goal, blue shading the expanded nodes, and the yellow line the final path.*
Key observations:
- α too small: the search is too conservative, expanding lots of useless nodes
- α too large: the search is too aggressive and may miss the optimal path
- α=1 with an admissible h: the balance point — optimality guaranteed, efficient
ADS's innovation is this: α is not fixed — it adapts to the local terrain.
That adaptivity comes from computing the information-theoretic barrier B(s):
- In open areas: IG is high (big information gain along the heuristic direction), U is low (later states are certain)
B high α high - Near obstacles: IG is low (the heuristic direction is blocked), U is high (multiple detour choices)
B low α low
10. The Philosophy of Heuristics: The Courage to Accept Imperfection
Let me return to this chapter's opening question: when perfection is out of reach, what should we do?
The heuristic answer: accept approximation at an explicit cost.
That takes courage, because you have to admit perfection is unreachable. But that isn't failure — it's wisdom.
Admissibility is A*'s contract: I may be optimistic, but I may not lie. If
The approximation ratio is the approximation algorithm's contract: I don't promise optimality, but I promise "not too bad". A 2-approximation algorithm guarantees a solution no worse than 2× the optimal — that's a worst-case mathematical guarantee, not an average-case one, not "usually pretty good", but "never above 2×, ever".
Probabilistic guarantees are the randomized algorithm's contract: I don't guarantee correctness every time, but I guarantee correctness with probability
These three contracts correspond to three kinds of "imperfection":
Conditional guarantee: if the assumption holds, I promise optimality (A*)
Worst-case guarantee: I promise not-too-bad, but possibly not optimal (approximation algorithms)
Probabilistic guarantee: I'm very likely right, with a small chance of failure (randomized algorithms)
By contrast, heuristics with no contract — "I did my best", "usually works", "works on the data I tested" — are dishonest approximations. They never tell you the conditions of failure, never quantify the "not good enough" degree, never give you the probability of risk.
But heuristics also cost:
Design cost: good heuristics need domain knowledge. The Manhattan distance works for grids — what about graph search? Continuous spaces? Every new problem needs a redesigned heuristic.
Computation cost: a sophisticated heuristic may be slower than the search itself. If
Generalization risk: heuristics designed for one specific problem may fail in a different setting. That's why ADS learns a heuristic policy with a neural network — it can generalize across tasks. But the price is losing the mathematical guarantee.
This leads to a deep tension: provable guarantees vs. empirical generalization.
A* has the admissibility guarantee but needs a hand-designed
That's Chapter 12's question. For now, hold onto this tension.
11. Yao's Principle: Algorithm Design Is a Game
Before discussing how Collins breaks a deterministic lower bound, we need to understand a deeper question: when you design a heuristic, who are you playing a game against?
In 1977, Andrew Chi-Chih Yao gave an answer — in a paper only a few pages long — that rewrote the landscape of algorithmic complexity theory.
11.1 Turning Algorithm Design into a Game
Picture this game.
Two players:
- Player A (the algorithm designer): picks an algorithm
to solve some problem - Player B (the adversary / input distribution): picks an input distribution
, trying to make the algorithm run as slowly as possible
Who goes first? If A picks the algorithm first, B constructs the worst-case input against that algorithm. If B picks the distribution first, A optimizes the algorithm for that distribution.
It's a zero-sum game.
11.2 The Two Sides of the Minimax Theorem
Yao's principle says: between deterministic algorithms and random inputs, there is a Minimax equality.
The left side of this equality is: "the expected time of the best deterministic algorithm under the worst-case input distribution".
The right side is: "the expected time of the best deterministic algorithm under some fixed input distribution".
The two sides are equal. Which means: you can obtain lower bounds for all randomized algorithms by analyzing deterministic algorithm lower bounds under a fixed distribution.
11.3 A Walkthrough in the Feynman Style: Why Is This Deep?
Let me explain with an analogy.
Suppose you are a general (the algorithm designer) drawing up a general-purpose battle plan (the algorithm) against various enemies (inputs). You don't know how the enemy will deploy.
The pessimistic case (MaxMin): you pick the plan first, then the enemy picks the deployment that hurts you most.
- Your optimal plan = "the best outcome I can get under the worst enemy deployment"
The optimistic case (MinMax): the enemy picks the distribution first, then you pick the best plan.
- Your optimal plan = "the best outcome I can get given the enemy's average deployment statistics"
The Minimax theorem says: those two values are equal.
What does this mean?
The worst-case lower bound for deterministic algorithms = the average-case lower bound for randomized algorithms.
More plainly: if you want to prove that "every deterministic algorithm needs at least
That's an extremely powerful tool — you turn "worst-case" analysis into "average-case" analysis, and the latter is usually much easier to handle.
11.4 Heuristic Design as a Game: The Game-Theoretic View
Now apply this framework to heuristic design.
Designing the heuristic function
| Player | Choice | Goal |
|---|---|---|
| The heuristic designer | the heuristic | minimize search time |
| The instance generator | the distribution of input graphs/mazes | maximize search time |
Yao's principle tells us: no matter how smart your deterministic heuristic, there is a performance lower bound decided by the input distribution.
That bound isn't an engineering limit — it's an information-theoretic one: if your heuristic is deterministic, the adversary (the input distribution) can always find a class of problems that degrades your performance to the worst case.
11.5 From Relative Lower Bounds to Absolute Lower Bounds
Here a key distinction emerges:
Relative lower bound:
- "For the deterministic heuristic
, there exists an input where search time is " - This is the lower bound relative to a particular algorithm — switch algorithms, and the bound can change
Absolute lower bound:
- "For any deterministic algorithm, search time is
" - This is a lower bound about the problem itself — no deterministic algorithm can break it
Yao's principle builds a bridge between the two: through the Minimax equality from game theory, you can lift a particular algorithm's worst-case lower bound into an absolute lower bound that holds for all deterministic algorithms.
But here's the catch: this absolute lower bound only holds for deterministic algorithms.
Randomized algorithms aren't bound by the same constraint.
Why? Because randomization breaks the symmetry of the game: the adversary can't construct worst-case inputs against a randomized algorithm — every run of a randomized algorithm differs, so the adversary doesn't know what to "aim at".
That leads straight to the core idea of Collins.
12. Collins: Breaking the Deterministic Lower Bound with Randomization
Heuristics are usually deterministic: given a state s, h(s) always returns the same value. But the Collins strategy shows that randomization can break an information-theoretic lower bound on determinism.
Collins targets the optimizer-state compression problem, but its core idea reveals a deep principle of heuristic design.
12.1 An Information-Theoretic Lower Bound for Determinism
Proposition 1 (deterministic lower bound): any deterministic data structure that maintains the state of d parameters at precision ε must use
This isn't an engineering limit — it's an information-theoretic counting argument:
To distinguish
Which means: if you want to store the first and second moments of the Adam optimizer deterministically (for d parameters), you need at least
For large language models (d might be in the billions), that's a huge bottleneck.
12.2 Randomization's Breakthrough: Trading Probability for Space
Collins uses Count-Sketch + 2-universal hashing to bring the state complexity from
The key idea: don't store the exact state — store a random projection of it.
This is like coarse-graining in physics: you don't track every particle's exact position; you track macroscopic statistical quantities. The price is introducing noise. But if the noise is small enough, the macroscopic behavior stays correct.
The Chernoff inequality gives a safe upper bound:
where
Experiments confirmed the theory: with
12.3 What This Means for Heuristics: Deterministic vs. Probabilistic Guarantees
Collins's work reveals a deep trade-off in heuristic design:
Deterministic heuristics: always return the same estimate for a given input. But they're bound by information-theoretic lower bounds — a good heuristic needs to store a lot of domain knowledge.
Randomized heuristics: trade a probabilistic guarantee for lower compute/storage cost. Not correct every time, but "correct with high probability".
That's another kind of contract — from "guaranteed correct" to "correct with probability
Seen from physics, this is the second law of thermodynamics: you can trade entropy (randomness) for energy (compute). Deterministic systems must maintain a low-entropy state, at the price of high energy consumption. Randomized systems allow more entropy, so they cost less energy.
Landauer's principle gives the theoretical floor: erasing 1 bit of information requires at least
Heuristics approximate on top of a known structure. In the next chapter, we'll see how the Transformer completely reworks the very concept of "structure" by dynamically connecting all the nodes.
Open Questions
Can the "quality" of a heuristic be formally defined?
Which
is theoretically optimal? Pearl proved that consistency is stronger than admissibility — but is it the strongest useful condition? Does there exist an "admissible function closest to "? This question is equivalent to: given finite compute, how should it be distributed optimally across the design of heuristics? Where is the boundary of the entropy barrier's applicability?
ADS's dynamic logarithmic barrier works on arithmetic tasks, but fails on abstract algebra. Is that failure principled or engineering? In other words: is entropy regularization itself unsuited to higher-order abstraction, or is the 360M model just too small? With a 3B model, would the abstract algebra task succeed? This question touches the fundamental limit of entropy as a reasoning constraint.
What's the essential difference between the implicit heuristics a neural network learns and the explicit heuristics humans design?
AlphaGo's value network is a heuristic function, but it doesn't satisfy admissibility — why does it still work? One possible answer: neural networks learn average-case heuristics, while admissibility is a worst-case guarantee. But what does that imply? Does a notion of "average-case admissibility" exist?
Where is the theoretical boundary of randomized heuristics?
Collins proved the deterministic lower bound
, but what's the upper bound for randomization? The Chernoff bound gives — but is it tight? Does an "optimal randomized heuristic" exist — one that minimizes compute given a target failure probability ? Can heuristics be learned online?
Classic heuristics are designed offline — fixed before the search starts. But could we design a heuristic that learns and adjusts during the search itself? Every node expansion updates the estimate of
, making the rest of the search more efficient? That resembles reinforcement learning, but the goal is to speed up the current search, not to generalize to future tasks. Where are the lower bounds for approximation algorithms?
We know vertex cover has a 2-approximation. But could we do 1.5-approximation? 1.1? For some NP-complete problems, approximation lower bounds exist — unless P = NP, no
-approximation exists. Those bounds tell us: for some problems, even approximating is hard. Can ADS's barrier and greedy's selection function be distinguished experimentally?
Section 6.6 argued an ontological difference between them — greedy makes choices on a fixed topology, ADS dynamically reshapes the topology itself. But can the difference be captured experimentally? One possible experiment: construct a reasoning task where "the optimal path must temporarily cross a high-entropy region" (like needing to try a suspicious-looking intermediate step first). Greedy would pick the low-entropy direction and go wrong (but can backtrack); ADS would seal the high-entropy entrance and never find the path at all (no backtracking possible). If the two algorithms' failure modes really differ, the ontological distinction is more than a philosophical classification. If their behavior coincides, the Section 6.6 argument needs a second look.
Can the shape of the search space itself become the learning target?
ADS's topology reshaping suggests a bolder idea: don't learn "search strategies in a given space" — learn "the shape of the search space itself". That's equivalent to learning a dynamic
(edge set) such that, from any starting point, greedy choice (on the reshaped space) finds the optimal solution. This is a geometric formulation of meta-learning — what's learned is no longer the policy but the topology . Almost no theoretical work exists in this direction today.
Bonus: Search Is Convergence — A Dynamical View of Heuristics
Every step of A* is, in fact, an Euler step.
Go back to the evaluation function
The structure is exactly the Euler discretization of gradient descent:
What's an Euler step?
In calculus, a derivative describes continuous change. But computers can only do discrete things — each time, take one little step.
The Euler method slices "continuous flow" into little steps:
Which means: right now you're at
Gradient descent is a special case of the Euler step — the direction of change is the negative gradient (the steepest downhill direction), and the step size is the learning rate
A*'s search has the same structure: current state
The triangle inequality is the guarantee of convergence.
The consistency condition
What's the triangle inequality?
You learned it in elementary school: any two sides of a triangle add up to more than the third.
In heuristic search, that rule becomes: the estimated cost from
Intuition: your guess about the remaining journey can't be more pessimistic than "take one real step and guess again". Otherwise your map contradicts itself — like a map that says "Beijing to Shanghai: 2000 km, but Beijing to Nanjing is only 100 km and Nanjing to Shanghai is only 100 km". You'd suspect it's lying.
A heuristic that satisfies this rule is called consistent. Consistency guarantees A* never walks backward, and each node needs to be expanded only once.
What's a Lyapunov function?
Imagine a ball rolling in a bowl. No matter where you drop it, the ball ends up at the bottom.
The Lyapunov function is that "bowl height" — a number measuring how far the system is from the goal. As long as this number decreases (or doesn't increase) at every step, the system must converge to the goal — no wandering off.
In A*, the
Lyapunov used this idea in 1892 to prove the stability of a wide class of dynamical systems. A*'s optimality proof is, in essence, the same thing.
What is ADS doing?
ADS's logarithmic barrier
The barrier isn't "tuning parameters" — it's reshaping the geometry of the search space by local uncertainty.
ADS's step is a harmonic-mean family. Read the logarithmic barrier as a barrier on the step —
The harmonic mean of two steps is the step at the arithmetic mean of their barriers. Chapter 23's optimal step is the same algebra: there
This structure explains why a discrete search can search by regulating its own entropy landscape. The entropy quotient
One boundary. This does not say
That "search is convergence" intuition is a geometric story in the heuristic setting.
But replace the search space with the belief space of an LLM, replace
Chapter 12 reveals it.
Appendix: Full Code
Here is the complete script for this chapter's experiments (save it as ads_search.py and run):
"""
ADS (Adaptive Dual Search): Entropy-Barrier Search Strategy
===========================================================
Companion script for The Reasoning Kingdom, Chapters 8 & 10.
ADS is a search strategy: a *dynamic* barrier that reshapes the reachable
set as a function of the searcher's belief entropy. At each state s, the
agent's belief distribution p_s over candidate moves has entropy H(p_s).
The barrier alpha(B_s) with B_s = H(p_s)/H_max approaches +infinity as
B_s -> 1, so high-entropy directions become inaccessible:
alpha(B_s) = -log(1 - B_s)
Low entropy (high confidence) -> barrier near zero -> search advances
along the best-scored direction. High entropy -> barrier -> the search is
forbidden from entering the uncertain region.
This differs from a selection function s -> v (pick one neighbor on a
FIXED graph): ADS mutates the graph itself, removing/recovering edges.
The script is self-contained (numpy only). It implements:
1. belief_motion - belief update on a tiny grid maze
2. entropy_barrier - alpha(B_s)
3. ads_search - entropy-barrier A* over a 2D maze
4. naive_astar - baseline A* on the same maze (for comparison)
5. demo - run both, print path lengths and barriers
Run: python3 ads_search.py
"""
import math
import numpy as np
XOR, NOP = 1, 0 # (not used here; kept for stylistic consistency)
# --------------------------------------------------------------------------
# 1. Entropy of a categorical distribution
# --------------------------------------------------------------------------
def entropy(p):
"""Entropy of a discrete distribution p (vector of probabilities)."""
p = np.asarray(p, dtype=float)
p = p[p > 0] # 0 * log 0 -> 0
return float(-np.sum(p * np.log(p)))
H_MAX = math.log(6) # max entropy: 6-way actions
def entropy_barrier(H):
"""Dynamic barrier alpha(B_s) = -log(1 - B_s), B_s = H / H_max."""
B = min(H / H_MAX, 1.0 - 1e-9) # avoid log(0)
return -math.log(1.0 - B)
# --------------------------------------------------------------------------
# 2. Belief motion: how H changes after an observation
# --------------------------------------------------------------------------
def belief_motion(p, obs_likelihood, obs_value):
"""Bayes update: p(x|o) ~ p(x) * L(o|x). Returns (new_p, H_new)."""
L = np.asarray(obs_likelihood, dtype=float)
mask = L[obs_value] # likelihood of the observed value
new_p = np.asarray(p, dtype=float) * mask
Z = new_p.sum()
if Z <= 0:
return p.copy(), entropy(p) # impossible: keep old beliefs
new_p /= Z
return new_p, entropy(new_p)
# --------------------------------------------------------------------------
# 3. ADS: entropy-barrier search on a grid
# --------------------------------------------------------------------------
def ads_search(maze, start, goal, max_steps=400, seed=0):
"""
A* where the effective action set is modulated by the entropy barrier:
- belief entropy at (x, y) is estimated from the local histogram of
past visits (the agent's uncertainty about the best direction).
- if barrier is high, high-uncertainty neighbors are pruned.
Returns (path, log_of_barriers) or (None, log) if no path found.
"""
import heapq
rng = np.random.default_rng(seed)
H, W = maze.shape
log = []
visit = np.zeros((H, W)) # visit counts -> local belief
start_node = (start[0], start[1])
g = {start_node: 0}
came = {start_node: None}
pq = [(0, start_node)]
found = False
steps = 0
while pq and steps < max_steps:
steps += 1
f, node = heapq.heappop(pq)
x, y = node
if (x, y) == goal:
found = True
break
visit[x, y] += 1
# local belief: softmax over neighbor visit counts (low visits
# near a fresh frontier -> high entropy -> uncertainty)
neighbors = []
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and maze[nx, ny] == 0:
neighbors.append((nx, ny))
if not neighbors:
continue
counts = np.array([visit[nx, ny] for nx, ny in neighbors], dtype=float) + 1e-3
p = counts / counts.sum()
Hp = entropy(p)
alpha = entropy_barrier(Hp)
log.append((node, Hp, alpha))
# ADS prunes directions whose (unnormalized) local entropy share
# exceeds the barrier-induced threshold: directions with
# p_i * alpha > theta are blocked.
theta = 1.0
allowed = [i for i in range(len(neighbors)) if p[i] * alpha <= theta]
if not allowed: # fully blocked: take least-uncertain
allowed = [int(np.argmin(-p))]
for i in allowed:
nx, ny = neighbors[i]
ng = g[node] + 1 + (1.0 if alpha > 0.5 else 0.0) # high-entropy toll
if (nx, ny) not in g or ng < g[(nx, ny)]:
g[(nx, ny)] = ng
came[(nx, ny)] = node
h = abs(nx - goal[0]) + abs(ny - goal[1]) # admissible
heapq.heappush(pq, (ng + h, (nx, ny)))
if not found:
return None, log
path = []
node = goal
while node is not None:
path.append(node)
node = came[node]
path.reverse()
return path, log
# --------------------------------------------------------------------------
# 4. Plain A* baseline (admissible, fixed graph)
# --------------------------------------------------------------------------
def naive_astar(maze, start, goal):
import heapq
H, W = maze.shape
start_node = (start[0], start[1])
g = {start_node: 0}
came = {start_node: None}
pq = [(0, start_node)]
while pq:
f, node = heapq.heappop(pq)
if node == goal:
path = []
while node is not None:
path.append(node)
node = came[node]
path.reverse()
return path
x, y = node
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and maze[nx, ny] == 0:
ng = g[node] + 1
if (nx, ny) not in g or ng < g[(nx, ny)]:
g[(nx, ny)] = ng
came[(nx, ny)] = node
h = abs(nx - goal[0]) + abs(ny - goal[1])
heapq.heappush(pq, (ng + h, (nx, ny)))
return None
# --------------------------------------------------------------------------
# 5. Demo
# --------------------------------------------------------------------------
def demo():
print("=" * 70)
print("ADS (Adaptive Dual Search) - entropy barrier demo")
print("=" * 70)
# A simple 12x12 maze with a wall in the middle; start=SW, goal=NE
maze = np.zeros((12, 12), dtype=int)
maze[5:7, 1:8] = 1 # horizontal wall block
maze[3:10, 7] = 1 # vertical wall block
start, goal = (11, 0), (0, 11)
print("\n[1] Maze legend: 0=open, 1=obstacle. Start=(11,0), Goal=(0,11)")
path_a, log_a = ads_search(maze, start, goal, seed=0)
path_b = naive_astar(maze, start, goal)
print(f"[2] ADS path length: {len(path_a) if path_a else 'None'}")
print(f" A* path length: {len(path_b) if path_b else 'None'}")
if path_a and path_b:
print(f" => ADS found a path of equal length but reached it "
f"through barrier-aware pruning.")
print("\n[3] Sample barriers along the ADS search (node, H, alpha):")
for entry in log_a[:8]:
node, Hp, alpha = entry
print(f" node={node} H={Hp:.3f} alpha={alpha:.3f}")
print(" ...")
for entry in log_a[-3:]:
node, Hp, alpha = entry
print(f" node={node} H={Hp:.3f} alpha={alpha:.3f}")
print("\n[4] The barrier function alpha(B) = -log(1 - B):")
for B in [0.0, 0.2, 0.5, 0.8, 0.95, 0.99]:
print(f" B={B:.2f} -> alpha={entropy_barrier(B * H_MAX):.3f}")
print("\nDone. ADS is one search strategy among A* and MCTS: it reshapes")
print("the reachable set with an entropy barrier rather than choosing")
print("a neighbor on a fixed graph.")
if __name__ == "__main__":
demo()Further Reading
Hart, Nilsson, Raphael (1968). A Formal Basis for the Heuristic Determination of Minimum Cost Paths — the original A* paper, defining admissibility and consistency
Yao, A. C.-C. (1977). Probabilistic Computations: Toward a Unified Measure of Complexity — the original paper on Yao's principle; the Minimax theorem lifts deterministic lower bounds into randomized ones
-> [FOCS 1977]This book, Chapter 8, §6 ADS: Making Heuristics Information-Theoretic + §12 Collins: Breaking the Deterministic Lower Bound with Randomization — complete discussion of both strategies (full code in the appendices of Chapters 8 and 11)
[Li & Jin, 2015] — the first PTAS for weighted unit-disk covering, the gold standard of approximation algorithms
-> [arXiv:1502.04918][Esmer et al., 2022] — exponential-time approximation algorithms for approximate monotone local search
-> [arXiv:2206.13481]Pearl, J. (1984). Heuristics: Intelligent Search Strategies for Computer Problem Solving — the classic textbook on heuristic search
Motwani, R. & Raghavan, P. (1995). Randomized Algorithms — the authoritative textbook on randomized algorithms (Cambridge University Press), covering Chernoff bounds, 2-universal hashing, the Minimax principle, and their use in algorithm design
Russell & Norvig (2020). Artificial Intelligence: A Modern Approach (4th ed.) — Chapters 3–4 discuss A* and its variants in detail
