Chapter 6 introduces temporal-difference prediction and control, combining Monte Carlo sampling with dynamic-programming-style bootstrapping.
Exercise 6.1
Let be the drift term between and .
Then,
Unrolling the equation further, we get:
Exercise 6.2
In this scenario, where you move to a new building and parking lot but still join the highway at the same place, only the first part of the journey is unknown. The rest of the route is unchanged.
Monte Carlo must wait until many full trips finish to adjust the estimate for the new office.
TD, however, can immediately update the estimate for the new office by bootstrapping from the already accurate highway predictions. Because only the new office segment needs to be learned, TD adapts more quickly and is better in this case.
Exercise 6.3
The first episode went left: .
For , the TD error is:
Similarly, for , the TD error is:
For , the TD error is:
Therefore, after the first episode, only the estimate for state is updated by the following amount:
The new estimate for state is:
Exercise 6.4
As we can see from the plots, increasing for Monte Carlo makes the estimates more volatile, because MC’s updates rely on full returns with high variance. This forces MC to use a small to remain stable, which slows learning.
TD, by contrast, bootstraps from existing estimates, giving it lower variance and allowing larger values without instability.
Exploring a wider range of values would not overturn the conclusion: TD(0) would still consistently achieve lower RMS error than MC.
Each algorithm’s best constant is already close to what’s shown (≈0.1 for TD, ≈0.02–0.04 for MC). A slightly different might improve results marginally, but there is no single fixed that would make MC significantly better than TD.
To outperform what’s shown, one would need a decreasing step-size schedule rather than just changing . This is because early episodes benefit from larger , while later episodes benefit from smaller .
Exercise 6.5
Since all states are initialized to , the center state is exactly correct at the start. However, because TD bootstraps from its neighbors, is pushed away from . At the same time, the other states are pulled towards their true values, causing the RMS error to decrease initially. But once is pulled away from , the RMS error goes up again. This problem is exacerbated with high values of because the updates are more aggressive.
This issue is not inherent to TD itself but is largely due to the choice of initial values. With different initializations, the problem could be avoided.
Exercise 6.6
1) Using Bellman Equations
Let the terminal on the left have value and the one on the right value . For the five non-terminal states, the Bellman equations for the Markov Reward Process are:
We get a linear system of equations with 5 equations and 5 unknowns that can be solved using linear algebra.
2) Using Hitting Probability
We can calculate the probability of hitting the right terminal before hitting the left terminal from each state.
This can simply be calculated by looking at the difference in path lengths from the current state to the right terminal and the left terminal.
For example, for state , the path length to the left terminal is 2 and the path length to the right terminal is 4. Therefore, the probability of hitting the right terminal before hitting the left terminal is .
Which method did the book likely use?
Most likely the hitting-probability method, because it is exact, simple, and yields the clean fractions without solving a system or running simulations.
Exercise 6.7
When data comes from behavior policy , the only mismatch with at time is the distribution of the action . The action determines both the immediate reward and the next state. So we correct it with a one-step ratio:
and multiply the TD target by this ratio:
Exercise 6.8
Hence,
Exercise 6.9
With 4 actions, the optimal path length is 16. Adding diagonal moves (8 actions) reduces it to 7, and including a “no-op” action (9 actions) also yields 7.



The learning curve shows that the 9-action agent starts slower but eventually matches the efficiency of the 8-action agent, both clearly outperforming the 4-action case.

Learning curves as the windy gridworld action set expands.
Exercise 6.10
Under stochastic wind, optimal paths become longer: 21 steps with 8 actions and 18 with 9 actions.


Convergence is similar across both, but the 9-action agent improves late in training and finds shorter paths than the 8-action agent.

Learning curves under stochastic wind.
Exercise 6.11
In Q-learning, the agent may follow an -greedy policy (or any exploratory policy) to generate actions (this is the behavior policy ).
The update, however, uses as the target (greedy policy ).
Since the behavior policy and the target policy are different, Q-learning is an off-policy algorithm.
Exercise 6.12
If the action selection is greedy, the update rules for SARSA are reduced to:
which is exactly the same as the update rule for Q-learning.
However, the algorithms are not operationally identical because in SARSA, the next action is chosen before the update, based on the old -values. That action is then carried forward into the next step.
Whereas in Q-learning, the next action is chosen after the update, based on the updated -values.
So, while the update equations coincide under greedy policies, the sequence of state–action pairs the agent actually follows can differ, since SARSA commits to the old greedy action and Q-learning commits to the new one.
Exercise 6.13
For Double Expected SARSA, we have two action-value functions and , and randomly choose which one to update at each step (same as Double Q-learning).
With probability:
else
where is the -greedy policy for such that:
and is the -greedy policy for .
Note that for the update of , we use the expected value of under the -greedy policy for . The converse is true for the update of .
Exercise 6.14
In the Car Rental problem, the next state after moving cars is known. For example, if Jack has 5 cars at location 1 and 2 at location 2, and he moves 1 car from location 1 to location 2, the resulting state is .
Similarly, if he starts with 6 cars at location 1 and 1 at location 2 and moves 2 cars, the resulting state is also .
In the standard formulation, these two state–action pairs are evaluated separately, even though they lead to the same outcome.
By instead working with afterstates, we can collapse both cases into a single representation. This reduces the number of states that need to be evaluated, which in turn will speed up convergence.