The Mathematics of Machine Intelligence

Chapter 17

Considering a Future

Score a plan inside a model, price a look, and see what a search cannot weigh.

6 guided illustrations. Move a slider or choose a value, watch the mathematics change, and check your prediction. Each illustration includes its full calculation.

01 / 06

How does the value of a place come from what happens next?

From Chapter 17, A map can be scored after the goal changes

A place pays 1 now and leads to a place worth 5 later. What is it worth when later rewards count for less?

The value of a place looks one step ahead. It averages, over where the rule might take you, the reward you collect on the way plus the discounted value of arriving. A discount near zero makes only the next reward count, and a discount near one makes the far future count almost fully.

Predict first: With future value 5, predict the discount at which the later reward contributes exactly as much as the immediate reward of 1.

00.99
A stacked bar of immediate and discounted future value for one place, and curves of value against the discount.
A place is worth its immediate reward plus a discounted share of what lies beyond it, and when there is future value to count, a higher discount lets it count for more.
Discount (gamma): 0.9 · Future value of the next place: 5 · Chance of reaching that place: 1.0

The only reachable place pays 1 now and is worth 5 later; with discount 0.9 it adds 4.5, so the value is 5.5. Raising the discount makes the future count for more.

Value of the starting place
5.5
Immediate part
1
Discounted future part
4.5
Why it matters

A planner that holds a model of how places lead to one another can score any place by this equation once it is given a goal and a rule, without a new trip.

In brains and behavior

Tolman read the rats' sudden drop in errors as a cognitive map. The chapter says calling a map a transition model is a modern reading, not Tolman's, and the rat is not shown to hold this table.

In machines

An agent that stores a transition model and plans with it is called model-based. The equation is a specification of how such an agent scores a place under a fixed rule.

Show the calculation

V = 1 x (1 + 0.9 x 5) + 0 x (0 + 0.9 x 0) = 5.5.

The equations and symbols

V(s)=∑s′T(s′∣s)[r(s,s′)+γV(s′)] V(s)=\sum_{s'}T(s'\mid s)\,\bigl[r(s,s')+\gamma V(s')\bigr]

s, s'
the current place and a possible next place
T(s' | s)
the chance of going to s' from s under the fixed rule
r(s, s')
the immediate reward for that step
V(s')
the future value of the next place
gamma
the discount, at least 0 and below 1; later rewards count for less
Where the conclusion applies

One fixed rule for choosing actions, known chances, a discount at least 0 and below 1, and a next-place value that is given. The equation evaluates the fixed movement rule; finding the best rule needs a comparison of actions. A rat's remembered route is not shown to be encoded in this table.

Check your understanding: A place pays 1 now and leads with certainty to a place worth 10. With discount 0.5, what is its value?
1 + 0.5 x 10 = 6.

Book source: Chapter 17, A map can be scored after the goal changes. Illustration C17-D01. Formula. Book equation and its worked example: one possible next place, immediate reward 1, future value 5, discount 0.9, giving 5.5. The other discounts, future values and the 0.6 chance of reaching the place are this companion's variations.

02 / 06

Which towns does A star explore, and when does it reach D through C?

From Chapter 17, A town map and a score for every open road

Which towns does a search explore on a four-town map, and what route does it return?

The search always explores the place with the lowest score, cost so far plus a guess of what is left. A guess that never runs too high means a place's score is a floor on any route through it, so once the goal has the lowest score no unexplored place can beat it. When the road from B to D is long enough and a road from C to D exists, the route through C becomes the cheaper one and the search turns to it. With no road from C to D, a long B to D road still ends with the route through B, though C may be explored and set aside.

Predict first: With the road from B to D at 6 miles and no road from C, predict which town is explored first and whether C is ever explored.

512
A map of towns A to D with road lengths and scores, and curves of the cost of the route found against the B to D road length.
The guess lets the search skip towns that cannot beat the route already found, and the first goal it takes from the list is a cheapest route.
Length of the B to D road (miles; the chapter uses 6): 6 · Road from C to D (the chapter has none): 0

A star returns A to B to D at 10 miles after exploring 2 places (A, B). Using cost so far alone, with no guess, explores 3 (A, C, B).

Route found
A to B to D
Cost (miles)
10
Places A star explored
A, B
Places explored by cost so far alone
A, C, B
Why it matters

Planning means running a model forward to see where actions lead, and every road leads to more roads. A good guess prunes the roads that cannot win without losing the best route.

In brains and behavior

A star is engineering proved on paper, built for machines. The chapter does not offer it as a model of how people or rats search.

In machines

A star is a specification with a proof: with a guess that never runs high, the route it returns is a cheapest one. Its authors note that exploring the fewest places might not minimize the total resources used.

Show the calculation

Score = miles so far + straight-line guess. B: 4 + 5 = 9. C: 3 + 9 = 12. Through B the route to D costs 4 + 6 = 10; there is no road from C to D in this map.

The equations and symbols

f(n)=g(n)+h(n) f(n)=g(n)+h(n)

n
a place on the map
g(n)
the cost of the best path found so far from the start to n, in miles
h(n)
a guess at the cost from n to the goal; it must never exceed the true cost left and must equal zero at the goal
f(n)
the score: cost so far plus the guess
Where the conclusion applies

A finite map with nonnegative road costs, guesses that never exceed the true cost left and equal zero at the goal, and a search that may reopen a place when it finds a cheaper way there. When two places tie on score (for example D and C at 12 when the B to D road is 8 miles), the code takes the one it found first, so the list of explored places can differ under another tie rule. A star was built for machines and is not a model of how people search.

Check your understanding: With the B to D road at 12 miles and a 9 mile road from C to D, which route does A star return, and what does it cost?
Through B the route would cost 4 + 12 = 16, through C it costs 3 + 9 = 12. After exploring B (score 9), C (score 12) has the lowest score and its road to D gives 12, so the route is A, C, D at 12 miles.

Book source: Chapter 17, A town map and a score for every open road. Illustration C17-D02. Formula. Hart, Nilsson and Raphael (1968) as the chapter describes them, with the chapter's four-town map: A to B 4 miles, A to C 3 miles, B to D 6 miles, straight-line guesses 5 from B and 9 from C. The chapter gives no road from C to D; the optional C to D road and the other B to D lengths are this companion's variations, kept at least as long as the straight-line guesses so that those guesses never run too high. The chapter gives no guess for A, which is the start; the companion sets it to 0 and never uses it.

03 / 06

What goes wrong if a search will not reopen a place?

From Chapter 17, A town map and a score for every open road

A place is closed at one cost and a cheaper way to it turns up later. Does the search still return a cheapest route?

At first the search reaches A at cost 3 and B at cost 1. With the guess at B at 3, A scores 3, below B's score of 1 + 3 = 4, so A is explored first and closed. With the guess at B at 1 or less, B scores 2 or less, below A's 3, so B goes first and A is never closed too soon. When B is explored, it offers A a cheaper cost of 2. A search that may reopen A takes it, and G is then reached at 4. One that cannot reopen keeps cost 3 for A and reaches G at 5.

Predict first: With the guess at B set to 3 and a search that never reopens a closed place, predict whether the route cost it returns is 4 or more.

03
A four-place directed graph with costs and guesses and the route kept, and a grid of route cost returned for each guess and reopening choice.
A guess that never runs high is not enough on its own: when a guess is not consistent with the roads, a search must be allowed to revisit a place whose cost was lowered.
Guess of the cost left from B: 3 · Search may reopen a place: 0

With the guess at B set to 3 and reopening not allowed, the search returns a route costing 5; the cheapest is 4. A place that was closed early had a cheaper way found later and was never revisited.

Cost returned
5
True cheapest cost
4
Places explored
S, A, B
Search may reopen places
no
Why it matters

A guarantee has conditions. A planner that drops one of them, here by never reopening, can return a route that is worse than the best without any sign that it has.

In machines

This is a specification checked by tracing a small graph. Straight-line distance never needs reopening, so the chapter's town map is not affected.

Show the calculation

Roads S to A 3, S to B 1, B to A 1, A to G 2. Cheapest route S, B, A, G costs 1 + 1 + 2 = 4. A scores 3 + 0 = 3 on first reach, below B's 1 + 3 = 4; if A is closed first at cost 3 and never reopened, G is reached at 3 + 2 = 5.

The equations and symbols

g(G)=f(G)≤f(n)≤C*≤g(G) g(G)=f(G)\le f(n)\le C^{*}\le g(G)

G
the goal the search selects
n
an open place on an optimal route
C*
the cost of a cheapest route
f, g
score and cost so far; the chain holds when guesses never run high and cheaper ways to a place are reopened
Where the conclusion applies

A finite directed graph with nonnegative costs and guesses that never exceed the true cost left. The guess at S is not consistent with the roads, which is why the chapter's reopening condition matters. Straight-line distance never needs reopening; this made-up guess is not a straight-line distance.

Check your understanding: With the guess at B set to 1 and no reopening, which of A and B is explored first, and what does the search return?
B scores 1 + 1 = 2 and A scores 3, so B is explored first and gives A the cost 2 before A is closed. Reopening never comes up, and the search returns 4.

Book source: Chapter 17, A town map and a score for every open road. Illustration C17-D03. Constructed example. The constructed numeric check in the book's Derivation 16: roads S to A 3, S to B 1, B to A 1 and A to G 2, with guesses 4, 0, 3 and 0 at S, A, B and G. Reopening finds cost 4, and permanently closing gives 5. The other guesses at B are this companion's variations, kept at or below the true cost left (3).

04 / 06

Can a table of expected visits be re-scored when only the goal moves?

From Chapter 17, Four rats and place cells that pictured the path ahead

A walker steps right through three rooms and stops in room 3. If the reward moves from room 3 to room 2, what changes in the table and what changes in the values?

From room 1 the walker visits room 1 now, room 2 one step later and room 3 two steps later, and later visits count for less by the discount each step. Those weights depend only on the rule. Multiplying them by the rewards gives the value. Move the reward and only that multiplication changes.

Predict first: Predict the value of room 1 when the 8 sits in room 3, and then when it moves to room 2, at a discount of one half.

13
A grid of discounted visits between three rooms, and bars of each room's value for a reward of 8 in the chosen room.
A table of expected future visits, kept apart from the rewards, lets a new goal be scored at once, for the rule the table was built under.
Room holding the reward of 8: 3 · Discount (gamma): 0.5

With discount 0.5, the walker from room 1 expects visits worth 1, 0.5, 0.25 in rooms 1, 2 and 3. A reward of 8 in room 3 makes room 1 worth 2. Moving the reward changes the values without changing the table, and the walker still follows the old rule.

Value of room 1
2
Value of room 2
4
Value of room 3
8
Visit weights from room 1
1, 0.5, 0.25
Why it matters

Latent learning raises the question of how a layout could be kept so a new goal can be scored without new trips. This is one answer, with its limits: it assumes the rule stays fixed.

In brains and behavior

Dayan noted that filling in the table by exploring before reward 'can be viewed as a form of latent learning'. He did not call the table a map, and the rats are not shown to hold one.

In machines

A learner can store the table, keep it apart from rewards and re-score it when a reward moves, as long as it keeps following the same rule.

Show the calculation

Value of room 1 = (visits from room 1) times (rewards) = 1 x 0 + 0.5 x 0 + 0.25 x 8 = 2.

The equations and symbols

V(s)=∑jM(s,j)r(j),M=(I−γP)−1 V(s)=\sum_{j} M(s,j)\,r(j),\qquad M=(I-\gamma P)^{-1}

M(s, j)
the discounted visits to room j to expect when starting in room s under the fixed rule
P
the chance of stepping from one room to the next under the fixed rule (always right)
r(j)
the reward in room j (8 in one room, none elsewhere)
gamma
the discount; later visits count for less
Where the conclusion applies

A fixed movement rule (always step right, stop in room 3) and a discount below 1. The table depends on the rule and is not 'a veridical map of the world', in Dayan's words. Re-scoring a fixed rule is not the same as finding a new best route.

Check your understanding: At discount 0.5, the reward of 8 is in room 1. What is the value of room 1, and does the table change?
8 x 1 = 8, because room 1 visits itself with weight 1. The table is the same: 1, 0.5 and 0.25 from room 1.

Book source: Chapter 17, Four rats and place cells that pictured the path ahead. Illustration C17-D04. Constructed example. Dayan's successor idea (1993) as the chapter describes it, with the chapter's three-room corridor: discount one half, visits 1, one half and one quarter from room 1, reward 8, giving values 2 (reward in room 3) and 4 (reward in room 2). The other discounts and reward rooms are this companion's variations; none of it is data.

05 / 06

Why can a first look be worth nothing while two looks pay?

From Chapter 17, A first look worth nothing, two looks worth 0.055

A player can pass for a sure 0.75 or answer a coin-flip question. Hints are right 7 times in 10. What is each look worth?

One hint makes the player 70 percent sure, which is still below the sure 0.75, so the player passes and the hint changed nothing. Two hints agree on 58 of 100 questions, and then the favored answer is right on 49 of those 58. The player answers then and passes when the hints split, for 80.5 points per 100 questions against 75.

Predict first: At hint accuracy 0.7, predict the value of the first look, then of the second. Does a planner that prices only the next look take either?

05
Expected points against number of looks with the sure 0.75 line, and gain over passing against looks for three hint accuracies.
A look can be worth nothing by itself and a lot together with another, so pricing only the next look can stop a planner too early.
Looks taken: 2 · Chance each hint is right: 0.7

After 2 looks with hints right 0.7 of the time, the player expects 0.805 points per question against 0.75 for passing, a gain of 0.055. The last look added 0.055.

Expected points per question
0.805
Gain over always passing
0.055
Added by the last look
0.055
Price per look at which looking just pays
0.0275
Why it matters

Whether to keep searching depends on what later looks make possible. A planner that stops when the next look is worthless can miss that two looks together change the choice.

In brains and behavior

No study here measures how often one-step pricing misleads real systems, and the quiz is a made-up illustration.

In machines

A builder chooses the search depth. At depth one the first look shows no gain; at depth two it shows a gross gain of 0.055 per question.

Show the calculation

Value of 2 looks = sum over hint counts of (chance of the count) x (larger of 0.75 and the chance the favored answer is right) = 0.805. Gain = 0.805 - 0.75 = 0.055. Break-even price per look = 0.055/2 = 0.0275.

The equations and symbols

Value(k)=∑mP(m)max⁡{0.75,P(favored answer right∣m)},Gain(k)=Value(k)−0.75 \mathrm{Value}(k)=\sum_{m}P(m)\max\{0.75,\ P(\text{favored answer right}\mid m)\},\qquad \text{Gain}(k)=\mathrm{Value}(k)-0.75

k
the number of looks (hints) taken
m
how many of the k hints point at the true answer
P(m)
the chance of that count, with answers equally likely and hints independent given the answer
0.75
the sure points from passing; answering pays 1 if right and 0 if wrong
Where the conclusion applies

Independent hints given the correct answer, equally likely answers, a known pass payoff and a player who updates by Bayes' rule. If every look costs the same amount, looking pays only when that price is below the gain per look. No study here measures how often one-step pricing misleads real systems.

Check your understanding: At hint accuracy 0.8, is one look worth anything, and what is the value of two looks?
One look makes the player 80 percent sure, above 0.75, so answering pays 0.8 and the gain is 0.05. Two looks: agree on 0.68, right with chance 0.64/0.68, split on 0.32; value 0.64 + 0.32 x 0.75 = 0.88, a gain of 0.13.

Book source: Chapter 17, A first look worth nothing, two looks worth 0.055. Illustration C17-D05. Constructed example. The chapter's made-up quiz: pass pays 0.75, answering pays 1 or 0, equally likely answers, hints right 7 times in 10 and independent given the answer. One look is worth 0 and two are worth 0.055 (80.5 points per 100 questions). The other hint accuracies and the numbers of looks are this companion's variations. The chapter says the numbers are not findings.

06 / 06

How many looks does it take to find a move a toy search rates as rare?

From Chapter 17, Move 79, and a value estimate that dived on move 87

In a toy search that tries moves in proportion to a starting weight, how many looks does a move with weight one in ten thousand need before it is ever tried?

Each look is one draw. The chance that a given move is never drawn in n looks is (1 - w)^n, which shrinks only slowly when w is tiny. So a move with weight 0.0001 needs thousands of looks before it is probably tried, and a search with a smaller budget will probably never weigh it.

Predict first: For a move with weight one in ten thousand, predict whether 1,000 looks give a better or worse than even chance of ever trying it.

100100000
Chance a rare move is tried against number of looks, and looks needed for an even chance and for 95 percent against the move's weight.
In this toy, a move given a very small weight can go unexamined for a long time, and a search that never examines it cannot weigh what it would bring.
Starting weight of the move: 0.0001 · Looks (simulated lines of play): 1000

In this toy, a move with starting weight 0.0001 is tried at least once in 1,000 looks with chance 0.0952; an even chance takes about 6,932 looks. The weights are the companion's toy values: 0.0001 only borrows the reported one-in-ten-thousand human-move estimate, and this is not AlphaGo's search.

Chance the move is tried
0.0952
Looks for an even chance
6,932
Looks for 95 percent
29,956
Why it matters

A planner can only weigh the futures its model holds. If the model rates a move as nearly impossible, the omission travels through the search however carefully it is steered.

In brains and behavior

No brain data are involved. The chapter says the evidence on Seoul does not show the cause of the mistake.

In machines

In the 2016 match, the program met a move it had put at about one in ten thousand for a human, and by Hassabis's account its own win estimate fell only at about move 87 (from about 70 percent at move 79). The toy shows why a rare move can stay unexamined; it does not explain this game.

Show the calculation

Chance = 1 - (1 - w)^n = 1 - (1 - 0.0001)^1000 = 0.0952. The chance of never trying it is (1 - w)^n = 0.905. Looks for chance c: n = ln(1 - c)/ln(1 - w).

The equations and symbols

P(tried at least once)=1−(1−w)n,nc=⌈ln⁡(1−c)ln⁡(1−w)⌉ P(\text{tried at least once})=1-(1-w)^{n},\qquad n_{c}=\left\lceil\frac{\ln(1-c)}{\ln(1-w)}\right\rceil

w
the toy's starting weight for a move (0.0001 borrows the reported one-in-ten-thousand estimate; it is not a weight read from AlphaGo)
n
the number of independent looks
c
the chance wanted that the move is tried at least once
n_c
the least number of looks that gives chance c
Where the conclusion applies

Each look draws one move independently with chance equal to its weight. A real tree search also uses the results of earlier looks and a value estimate, and the accounts cited do not establish why the program erred at move 79 or what its policy network and search did. The one in ten thousand reported for move 78 is AlphaGo's estimate of how likely a human was to play it; the chapter does not say it was a sampling weight in the search. This toy only borrows the number as an example of a rare starting weight. This is one game and one move; it shows what a search can miss, not how often it does.

Check your understanding: A move has weight 0.01. How many looks give at least a 95 percent chance of trying it at least once?
n = ln(0.05)/ln(0.99) = 298.07, so 299 looks.

Book source: Chapter 17, Move 79, and a value estimate that dived on move 87. Illustration C17-D06. Model. The reported figure is Hassabis's statement, as Wired reports it, that by AlphaGo's own estimate there was about one chance in ten thousand that a human would play move 78. No source read says how the program reached that number. The calculation is a toy this companion built: independent draws in proportion to a starting weight. It is not AlphaGo's search, whose Seoul version may differ from the 2015 version in the Nature paper.

Mathematical illustrations use the book's formulas with disclosed small examples. Each interactive choice shows a result computed from the same calculations as the chapter notebook. A simulation is not a measurement, and for a brain the mathematics is a model: a picture illustrates a result, and the assumptions determine its scope. Review copy, brain-computer partnership revision of 1 november 2026.