Macalinao StudioLearnAll enriched lessons ↗
College path · 7 sectionsSwitch to high school ↗

College / LONGER LESSON tree

Tree-of-thought search: keep better options alive

Represent partial states, expand and rank alternatives, trace beam pruning, and distinguish heuristic search from verified success.

Preparation: arithmetic, lists and the test-time compute lesson.

Plan 25–40 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Turn one path into a set of possibilities

College path. Represent partial states, expand and rank alternatives, trace beam pruning, and distinguish heuristic search from verified success. Preparation: arithmetic, lists and the test-time compute lesson. Move between Signal Room, Workbench and Field Notes without losing your section. Pause before each worked solution.

A single generated solution commits to one sequence of intermediate decisions. Tree-of-thought search organizes several partial solutions as states, proposes continuations, evaluates them and decides which to explore. The “thought” is a chosen unit of progress, not a literal inspection of a model’s mind. It might be an equation, a paragraph or a planning step. The original framework uses language models within this search process. Our experiment replaces model calls with simple arithmetic actions so you can inspect exactly why a branch survives or disappears.

The search state includes the original problem and the partial solution. Thought generation and state evaluation are separate functions, while the traversal algorithm controls exploration. Breadth-first and depth-first strategies have different memory and backtracking behavior. Our implementation is a bounded breadth-first beam search over a numeric state, not a reproduction of the paper’s model prompts or benchmark results.

Worked example. Start at one. At each step you may add two or multiply by two. The goal is to reach ten within three actions. The first action creates states three and two. Instead of choosing immediately, a search procedure can keep both as possibilities.

State → candidate steps → evaluation → retained frontier

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. What additional component does a search system need beyond a generator of candidate steps?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

It needs a policy for evaluating, retaining and exploring states, plus a way to recognize a valid final solution. Generation alone does not decide which paths deserve the remaining budget.

Section 02 / 07

Choose a state representation that preserves the problem

A search state must contain enough information to determine valid next steps and whether the goal is satisfied. In our arithmetic task, the current number and the path that produced it are sufficient because the same two actions are always available. In other tasks, remaining resources, previous commitments or constraints may matter. If you discard that information, two apparently similar states may not be interchangeable. Keep an explicit path so a claimed result can be replayed from the start rather than trusted because a score is high.

The numeric state is Markov for this toy transition system: future reachability depends on its value and remaining depth, not the preceding route. We deduplicate equal values within a depth layer, retaining one valid path. This is not safe for tasks where path-dependent constraints differ. A search tree can become a directed graph when equivalent states merge; the representation determines whether merging preserves correctness.

Worked example. The value four can be reached from two by adding two or multiplying by two. At the same depth, either route leaves the same future numeric possibilities in this task. Retaining one path avoids duplicate work while preserving reachability from that state.

Merge states only when their future legal continuations are equivalent

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Would equal current totals always justify merging two states in a shopping-plan problem?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. The plans may have bought different items or used different coupons. Future options can depend on that history. A sufficient state must retain every constraint relevant to later decisions.

Section 03 / 07

A heuristic is a prediction, not the goal test

Our heuristic prefers states with smaller absolute distance from the target. This is easy to calculate and often feels sensible, but it does not predict how many legal actions are needed. Multiplication can make a temporarily less-close state more useful. The goal test is different: the current number must equal the target exactly, and every recorded action must be valid. Keep these roles separate. A high heuristic score can justify exploration; it cannot certify success. The experiment shows both the ranked frontier and the final verified result.

Absolute numeric distance is not asserted to be an admissible estimate of remaining action cost. Our beam search has no A-star optimality guarantee. At equal distance, lower numeric value wins the deterministic tie, followed by generation order for duplicate paths. Explicit tie rules make the trace reproducible. The search inspects exact goals among generated children before pruning the next frontier.

Worked example. From state three, the two next values are five and six. Six is closer to ten, but five reaches ten with one multiplication. From six, one more action gives eight or twelve, neither of which is ten. The closer-looking state can therefore lose the only solution within the depth cap.

Heuristic h(x)=|target−x|; goal test: x=target

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why should distance-to-target not be described as a proof that one branch is better?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

It is a heuristic estimate under this action system. Future legal transitions matter. A branch can look worse numerically and still contain a valid short solution.

Section 04 / 07

Watch a narrow beam discard the useful path

Beam width limits how many states survive each depth. Width one behaves like a greedy choice among that layer’s candidates. For our default problem, it keeps three after the first step and six after the second, discarding five. It then fails to reach ten within the third step. Width two keeps both five and six at the second layer and finds the goal from five. The difference is visible in the trace. More breadth can protect a promising alternative, but it also increases the work required to generate and evaluate states.

Pruning is irreversible in this implementation: discarded states are not kept in a backtracking stack. Increasing width changes the retained frontier, but finite-width heuristic search is not generally complete. The default example demonstrates a particular gain, not a theorem that every beam-width increase monotonically improves every search algorithm’s result. Record the actual expanded states and success at the stated depth.

Worked example. With width one and depth three, the retained values progress from one to three to six, then a non-goal frontier. With width two, the second frontier contains six and five. Expanding five generates seven and ten, and the goal is found.

Frontier_next = best B distinct generated states under the heuristic

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Which state was wrongly discarded by the narrow beam in the default example?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Five. It is slightly farther from ten than six is, but doubling five reaches the goal within the remaining action. The heuristic failed to capture that transition.

Section 05 / 07

Count the work as well as the solution

Every expanded state produces two candidate actions in this fixture. We count expansions and generated candidates separately from retained states. At a layer with beam width B, at most B states are expanded, but duplicate merging and early goal detection can reduce future work. A complete binary tree grows rapidly with depth if nothing is pruned. These counts help explain why real language-model search can be expensive: proposing and evaluating a state may each require model calls, long contexts or tools. Our arithmetic operation counts are not measured model latency.

A full two-branch tree through depth D contains one plus two through two to the D nodes. A beam bounded by B expands at most B times D states, with a tighter root-layer bound when B exceeds one. Our implementation generates the entire current layer before checking for a goal, so counts are deterministic under that convention. Different early-exit policies produce different counts and should not be compared without disclosure.

Worked example. A complete binary tree through depth three has one plus two plus four plus eight, or 15 nodes including the root. The beam retains only a small frontier at each layer. Compare expansion counts in the Workbench while changing width and depth rather than assuming the same cost for every successful run.

Full binary tree nodes through D = 2^(D+1)−1

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Why are generated candidates and retained states different quantities?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

The search can generate several children, merge duplicate states and discard low-ranked candidates. Retention measures what remains available for the next layer; generation measures work already spent.

Section 06 / 07

Backtracking and verification solve different problems

A depth-first strategy can follow one branch and return to earlier alternatives when it fails. That is backtracking. Our beam demonstration does not backtrack; it retains a bounded set of states and permanently prunes the rest. Neither strategy removes the need for verification. Replaying a found action sequence confirms that it obeys the rules and reaches the target. For open-ended language tasks, verification may be less exact, and a search can exploit errors in its evaluator. Better traversal cannot compensate for every flaw in the problem representation or checker.

Completeness depends on the state space, traversal, pruning rule and budget. Exhaustive finite search can establish absence within a bound; a failed narrow beam cannot. In the fixture, a separate exhaustive reachability computation is used in testing, not exposed to the heuristic. This prevents the demonstrator from secretly using a perfect future oracle to rank states while claiming to illustrate heuristic uncertainty.

Worked example. The valid path one, three, five, ten corresponds to add two, add two, multiply by two. Replaying these actions verifies the solution. If a width-one run fails at depth three, that says only that this run failed; the verified path proves the problem itself was solvable.

Search failure under pruning ≠ proof of impossibility

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. Does failure of a pruned search prove that no solution exists within the depth limit?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

No. It may have discarded a useful state. Only an appropriate exhaustive or otherwise complete method can support that stronger claim for the defined search space and bound.

Section 07 / 07

Connect language proposals to a trustworthy search system

In a language-model application, define the thought unit, state format, proposal procedure, evaluator and stopping rule before measuring success. Check that candidate steps preserve constraints. Compare with simpler baselines at matched budgets. Search is valuable when keeping alternatives and checking them improves the final result enough to justify the cost. It is not a new Transformer layer or a guarantee of deliberate human-like thought. The next lesson examines process reward models, which can provide learned scores for intermediate steps but also introduce their own errors.

Evaluate generator coverage, evaluator ranking, pruning losses and final verification separately. A failed run may lack a useful proposal, discard it, or select an invalid result. Logging the frontier and decisions helps diagnose which component failed. Account for both generation and evaluation calls, and report held-out success with uncertainty. Our deterministic trace demonstrates algorithm behavior only; it provides no language-model performance claim.

Worked example. For a planning assistant, test whether each partial plan respects time and resource constraints, whether the final plan is feasible, and how many proposals were evaluated. A fluent intermediate plan with an impossible schedule should not survive merely because it receives a high learned score.

Search quality depends on proposals, evaluation, traversal, budget and verification

The displayed notation records the process described in the example. Keep its assumptions and units attached to the result.

Try it yourself. What should a search log retain so a failure can be diagnosed?

Pause the narration and explain your reasoning before continuing to the worked solution.

Reveal worked solution

Retain states, proposed actions, evaluator scores, pruning decisions, budget use and the final checker result. These distinguish a missing candidate from a bad ranking or an inadequate verifier.

Final checkpoint. What does failure of a pruned search establish? Option 1: No solution exists. Option 2: That bounded search run did not find a solution. Option 3: The heuristic is admissible.

Pause and choose an answer before continuing.

Reveal worked solution

Option 2 is correct. Pruning can discard a valid route, so failure is not an impossibility proof.

LONGER RETRIEVAL, TOOL AND AGENT LESSONS

Find evidence, use tools and coordinate work

Worked examples, local narration and connected experiments at your level.

Continue the learning path

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

Reset this college path?

This removes only this path’s notes, progress and experiments from this browser.