Exercises — Agent, environment, state, action, reward
This page is a graded workout. Every problem builds on the parent note Agent, environment, state, action, reward. Start at L1, don't peek at the solution until you've tried. Each solution is collapsible — click to reveal.
Before we begin, one reminder of the two symbols we lean on hardest:
Recall What is the
return and the discount factor ? The return is the total future reward the agent collects starting at time : . The discount factor is a number that shrinks rewards the further they are in the future — think of it as "how much a reward one step from now is worth compared to right now." means "I only care about this instant"; means "I weigh the far future almost as much as now."
Level 1 — Recognition
Can you name the parts of the loop and read a definition?
Exercise 1.1
For a self-driving car learning to stay in its lane, label each item as agent, environment, state, action, or reward: (a) the steering angle chosen each moment; (b) the road, other cars, and weather; (c) the car's position and speed on the road; (d) the driving software; (e) a each second the car stays centred, if it crosses a line.
Recall Solution
(a) action — the only thing the agent directly picks. (b) environment — everything outside the agent that reacts. (c) state — the complete description of the situation at that moment. (d) agent — the learner/decision-maker (the "brain"). (e) reward — the scalar feedback signal encoding the goal.
Exercise 1.2
A trajectory is written . In the ordering the parent note uses, which comes first after the agent is in state : the reward or the next state ? What produces each?
Recall Solution
In state the agent first chooses action (from its policy). The environment then does two things: it emits reward and transitions to . In the written trajectory appears before , but both are produced by the environment in response to the same action . The agent controls only ; state and reward "emerge" from it.
Level 2 — Application
Plug numbers into the return formula and the loop.
Exercise 2.1
An episode gives the rewards then ends. Using no discounting (finite-horizon sum), what is ? What is ?
Recall Solution
Finite-horizon return is a plain sum from time onward. Notice : the return depends on where you start counting.
Exercise 2.2
Same rewards , now with discount . Compute .
Recall Solution
Each future reward is multiplied by where is how many steps ahead it is.
Exercise 2.3
An agent receives the same reward at every step forever (infinite horizon), with . What is ?
Recall Solution
This is a constant reward, so . The geometric series sums to for . Even an infinite stream of rewards gives a finite return — that is exactly why discounting is used. See Bellman Equations for where this geometric collapse reappears.
Level 3 — Analysis
Reason about the grid world and about why the formula behaves as it does.
Exercise 3.1
In the 5×5 grid world (parent Example 1: goal, per step, hitting a wall), an agent takes 4 steps: step, step, wall-bump, then reaches goal. So . With , compute .

Recall Solution
Apply with : Compute each term: , . The wall bump at costs the most ( after discount); the goal reward, though large, is shrunk to by being 3 steps away. Net positive, so this path was still worthwhile.
Exercise 3.2
Rewards are bounded by . Give the tightest guaranteed upper bound on when . Interpret the size of the number.
Recall Solution
From the parent's convergence argument, . Interpretation: with this close to 1 the agent is extremely far-sighted — its return can be up to 100× the single-step maximum. Learning is harder here because a value estimate must sum the effect of ~100 future steps.
Exercise 3.3
Suppose the task designer sets the per-step reward to (only at the goal). Explain, using the return, why the agent has no reason to reach the goal quickly.
Recall Solution
With per step, the only nonzero term in is the discounted goal reward , where is the number of steps taken. If (no discount), then for any — reaching the goal in 5 steps or 500 steps gives the identical return . So the agent is indifferent to speed and may wander forever. Subtlety: if , then shrinks with larger , so discounting alone gives a mild "hurry up" pressure. The explicit step penalty in the parent is a stronger, -independent way to force efficiency. This is a design choice about shaping the goal — see Policy and Value Functions.
Level 4 — Synthesis
Combine the recursion, the Markov property, and multiple components.
Exercise 4.1
Prove the recursive (bootstrapping) identity starting only from the definition .
Recall Solution
Peel off the term: Factor out of the remaining sum and re-index with : Therefore . This one line is the seed of the Bellman Equations.
Exercise 4.2
An agent gets for the first two steps () then forever after (), with . Compute two ways: (a) directly by splitting the sum, (b) using the recursion to check.
Recall Solution
(a) Direct. Split into the two special terms plus the constant tail: First two: . The tail is a geometric series starting at : So .
(b) Recursion check. First find . From step 1 onward the rewards are Then . ✓ Same answer.
Exercise 4.3
The Markov property says . A poker-playing agent that only sees its own two cards claims its problem is Markov in what it observes. Is it? Justify.
Recall Solution
No. The true environment state includes the opponents' hidden cards and the deck order; the agent's observation (its two cards) is not a complete description. The future — who wins the pot — depends on information the agent cannot see, so knowing only the observation does not make the future conditionally independent of the past. This is a partially observable problem, a Partial Observability (POMDP), not a plain Markov Decision Process (MDP). The fix in practice is to fold history (past actions/bets) into an augmented "agent state" to recover an approximately-Markov signal.
Level 5 — Mastery
Design and reason about edge cases end-to-end.
Exercise 5.1
You want a two-armed slot machine agent (a Multi-Armed Bandits problem). Arm A pays with probability , arm B pays with probability . There is only one step per episode (). Write the expected return for always-A and always-B, and state which policy is optimal. Then explain why is irrelevant here.
Recall Solution
With a single step, the return equals the single reward: . Its expectation is the payout probability. Optimal policy: always pull arm A (expected ). Why doesn't matter: with there is exactly one reward and no future terms, so no reward ever gets multiplied by for . Discounting only bites when there is a future. The bandit's real difficulty is instead not knowing the / in advance — that's Exploration vs Exploitation.
Exercise 5.2
Degenerate case. Set . Show that maximizing the return collapses to maximizing the immediate reward, and state what kind of agent this produces.
Recall Solution
Plug into . Every term with has a factor ; the term has . So Maximizing return now means maximizing only the immediate reward — a greedy / myopic agent that ignores all consequences. This is the opposite extreme from Exercise 3.2's far-sighted agent. Real tasks pick between these poles to trade off short vs long-term payoff.
Exercise 5.3
Full synthesis. In the temperature-control task (parent Example 2), the reward is with . At one step C and the agent used heater power . (a) Compute . (b) Explain why both terms being negative still lets the agent "maximize" reward. (c) Is action space here discrete or continuous, and why does that matter for whether you'd use tabular methods?
Recall Solution
(a) Deviation term: . Energy term: . (b) All rewards are , so "maximizing" means pushing the reward toward zero — i.e. getting the temperature as close to as possible while using as little heater power as possible. The best achievable per-step reward is (perfect temperature, zero power), which is never quite reached, so the agent keeps improving. (c) The action is continuous. A continuous action space has infinitely many actions, so you cannot store one value per (state, action) pair in a table — tabular/lookup methods break. You need function approximation (see Model-Free vs Model-Based RL) or a policy that outputs a real number directly.
Recall Quick self-audit checklist
Ordering in a trajectory ::: ; only is the agent's. Return exponent rule ::: where = steps ahead of the start time . Convergence bound ::: . Recursion ::: . vs ::: myopic (immediate reward) vs far-sighted. Observation state when ::: information is hidden (POMDP).