5.1.4 · D4Reinforcement Learning Foundations

Exercises — State-value and action-value functions

2,364 words11 min readBack to topic

This page is a self-test. Each problem is graded by cognitive level:

  • L1 Recognition — can you read the notation and pick the right definition?
  • L2 Application — can you plug numbers into one formula?
  • L3 Analysis — can you chain formulas or compare cases?
  • L4 Synthesis — can you build a small system and solve it?
  • L5 Mastery — can you reason about edge cases and limits?

Every solution hides inside a collapsible [!recall]- callout. Try first, then reveal. All the tools you need were built in the parent note State-value and action-value functions; here we only use them.

Here is the discount factor: a knob that says how much a reward one step in the future is worth compared to a reward right now. means "the future counts fully"; means "I only care about the very next reward".


L1 — Recognition

Exercise 1.1

You are handed the number . In one sentence, what real-world quantity does the measure? And which of or lets you compare two different actions in the same state?

Recall Solution

WHAT the 7 means: if the agent is in state , commits to action right now, and thereafter behaves according to policy , then the average total discounted reward it will collect from this moment onward is .

Which one compares actions: . It carries an action slot , so you can hold fixed and vary : compare vs . has no action slot — it has already averaged the actions away, so it cannot separate them.

Exercise 1.2

True or false: " can be larger than the best available at ." Justify.

Recall Solution

False. Because is a weighted average of the -values (the weights are probabilities that sum to 1). An average can never exceed the largest thing you are averaging. So with equality only if the policy puts all its probability on the best action.


L2 — Application

Exercise 2.1

A state has three actions with known Q-values , , . The policy picks them with probabilities . Compute .

Recall Solution

Apply the averaging formula : Sanity check: sits between the smallest Q () and the largest () — exactly as an average must.

Exercise 2.2

Action in state is deterministic: it always lands in and pays reward . You know and . Compute .

Recall Solution

With a deterministic transition, the environment-sum collapses to a single term (probability ):

Exercise 2.3

Same idea, but the action is stochastic. Action from :

  • : land in , reward
  • : land in , reward

Given , , . Compute .

Recall Solution

Weight each branch by its probability: WHY: "reward now + discounted value of where you land" is computed inside each outcome, then averaged. Do not average the states first and the rewards separately — average the whole bracket.


L3 — Analysis

Exercise 3.1 — chaining and

State has two actions, each deterministic:

  • , reward
  • , reward

Policy: . Values , , . Compute , , and then two ways to confirm they agree.

Recall Solution

Step 1 — the two Q's (environment-average, here deterministic so one term each): Step 2 — via the averaging formula : Step 3 — via the full Bellman equation : Both routes give — as they must, since the Bellman- equation is literally the averaging formula with each expanded.

Exercise 3.2 — which action does policy improvement prefer?

Using the 's from 3.1, if you were allowed to make the policy greedy at (put all probability on the best action), which action wins, and what would become?

Recall Solution

Compare the action-values: , so greedy picks . The new greedy policy has , so Going greedy cannot decrease the value — this one step is the seed of the policy-improvement theorem in 5.1.05-Optimal-policiesand-optimal-value-functions.


L4 — Synthesis

Exercise 4.1 — a 1-D corridor, solve it end to end

A corridor of cells . The agent only ever moves right (policy is deterministic, one action). Each move pays ; reaching goal is terminal with . Discount .

Figure — State-value and action-value functions

Compute , , by backing up from the goal.

Recall Solution

Work right-to-left — you can only evaluate a state once you know the value of where it leads. From (one step to ): From (one step to ): From (one step to ): Pattern: the farther from the goal, the more negative — each cell "inherits" its neighbour's discounted pain plus its own step cost. This backward sweep is exactly 5.2.01-Dynamic-programming-policy-evaluation on a chain.

Exercise 4.2 — closed form for an infinite corridor

Suppose the corridor never ends: every step pays forever, . What is for any state? Use the geometric-series shortcut.

Recall Solution

The return is . WHY a geometric series: each further step's cost is the previous one multiplied by the constant ratio , and the classic sum applies whenever . Consistency check with Bellman: guess constant, then


L5 — Mastery

Exercise 5.1 — the limit

In the finite 3-step corridor of 4.1, what happens to as ? Contrast this with the infinite corridor of 4.2 as .

Recall Solution

Finite corridor (3 steps from to ): the return is just the sum of three discounted 's, As this tends to : a finite answer, because there are only finitely many rewards. (Check with : , matching 4.1.) Infinite corridor: . As , , so . The lesson: discounting is what keeps an endless stream of rewards from summing to infinity. With a guaranteed-terminating task, you can afford ; with a non-terminating one you generally need for the value to even exist.

Exercise 5.2 — degenerate case

Take the stochastic action of Exercise 2.3 but set . Recompute and explain in words what turns the agent into.

Recall Solution

With the future-value term vanishes in every branch: What means: the agent becomes myopic — it only values the immediate reward and is completely blind to consequences. reduces to the expected next reward alone. This is the extreme opposite of the far-sighted agent.

Exercise 5.3 — self-consistency of a proposed value function

Someone claims that for a two-state loop (from you always go to with reward ; from you always go to with reward ; , single action each), the values are and . Set up and solve the coupled Bellman equations, then verify they are self-consistent.

Figure — State-value and action-value functions
Recall Solution

Set up the two equations (each state deterministic, one term each): Substitute the first into the second: Then Verify self-consistency by plugging back: Both hold, so the value function is the unique fixed point of the Bellman operator on this loop — the same fixed point that iterative methods like 5.3.01-Monte-Carlo-prediction and 5.4.01-Temporal-difference-learning converge to from samples.


Recall One-line self-quiz (reveal to check)

Why can never exceed ? ::: Because is a probability-weighted average of the -values, and an average never exceeds its maximum term. What single quantity should you compare to choose between actions? ::: — it already folds reward, discount, and next-state value into one number. What role does play for a non-terminating task? ::: It makes the infinite discounted reward sum converge to a finite value.