Skip to main content
© 2026 ePowerAI — instrumented learning, no login required.
CoursesContact
ePOWERAI
CoursesContact
Returns, Value, and the Bellman Equation
Reinforcement Learning
01Reinforcement Learning: Agents, Rewards, and MDPs
02Bandits: Exploration, Exploitation, and Regret
03Returns, Value, and the Bellman Equation
04Bandits: UCB1 and Thompson Sampling
05Week 1: Reinforcement Learning Problem Formulation
06Week 2: Multi-Armed Bandits
07Week 3: Dynamic Programming for Finite MDPs
08Week 4: Monte Carlo and Temporal-Difference Learning
09Week 5: Function Approximation in Reinforcement Learning
10Week 6: Deep Q-Learning and Variants
11Week 7: Policy Gradient and Actor–Critic Methods
12Week 8: Modern Deep Reinforcement Learning Algorithms
13Week 9: Exploration, Partial Observability, and Multi-Agent Reinforcement Learning
14Week 10: Model-Based Reinforcement Learning and Planning
15Week 11: Offline Reinforcement Learning
16Week 12: Reinforcement Learning from Human Feedback
17Week 13: Direct Preference Optimization and GRPO
18Week 14: Agentic Systems and Course Capstone
· Reinforcement Learning· Guided Path · Beginner11 min read

Returns, Value, and the Bellman Equation

Returns, Value, and the Bellman Equation

Learning Outcomes

By the end of this step you will:

  • Compute a discounted return for a short sequence of rewards, by hand and in code
  • Explain why future rewards are discounted and what the discount factor controls
  • Say what a value function is in plain language, and distinguish state value from action value
  • Read the Bellman equation as "reward now plus discounted value later"
  • Explain why a discount below 1 is what makes the recursion settle
Prerequisites
  • The previous step, Agents, Rewards, and MDPs: states, actions, rewards, policies, and the MDP tuple.
  • Expectation, Variance, and Covariance for the idea of an expected value.

Everything else is built in this step. Every cell runs in the page.

An agent does not receive one reward — it receives a stream of them, wrapped around a sequence of choices. To compare two policies we need to collapse that stream into a single number. That number is the return, and the equation that computes it recursively is the Bellman equation.

From one reward to a running total#

Suppose an agent has just received reward rt+1r_{t+1}rt+1​, then rt+2r_{t+2}rt+2​, and so on. Its goal is not to maximise the next reward; it is to maximise the whole stream. So we define the return from time ttt:

Gt=rt+1+γrt+2+γ2rt+3+⋯=∑k=0∞γk rt+k+1.G_t = r_{t+1} + \gamma r_{t+2} + \gamma^2 r_{t+3} + \cdots = \sum_{k=0}^{\infty} \gamma^k\, r_{t+k+1}.Gt​=rt+1​+γrt+2​+γ2rt+3​+⋯=k=0∑∞​γkrt+k+1​.

Read it aloud: each reward further into the future is worth less, and the discount factor γ\gammaγ says how much less. The reward received immediately is counted at full value; the one after that is multiplied by γ\gammaγ; the one after that by γ2\gamma^2γ2; and so on.

The discount factor is a number between 0 and 1. Two extremes show what it means:

  • With γ\gammaγ close to 0, only the very next reward matters. The agent is short-sighted.
  • With γ\gammaγ close to 1, rewards far in the future count almost as much as immediate ones. The agent is patient.
Everything is a random variable

GtG_tGt​ is not a fixed number, because the future is uncertain: the policy may choose a different action, and the world may answer differently. So we usually ask for its average — its expected value. That average is what a value function measures, and it is the subject of the next section.

Three jobs of the discount factor#

Discounting is often taught as "the agent prefers rewards sooner", but it is doing more work than that.

1. It keeps the total finite. If an agent earns +1+1+1 at every step of a task that never ends, the undiscounted sum is 1+1+1+⋯1 + 1 + 1 + \cdots1+1+1+⋯, which grows without bound. Multiplying the kkk-th term by γk\gamma^kγk makes the sum of a geometric series with ratio γ\gammaγ, so it converges to a finite number. Without that, there is no single number to maximise.

2. It encodes time preference. Discounting is how we express that a reward now is worth more than the same reward later — the same idea as interest rates in finance. A smaller γ\gammaγ makes the agent care less about a distant payoff.

3. It sets the planning horizon. The weights γk\gamma^kγk shrink geometrically, so only a certain number of steps ahead carry real weight. Because 1+γ+γ2+⋯=11−γ1 + \gamma + \gamma^2 + \cdots = \frac{1}{1-\gamma}1+γ+γ2+⋯=1−γ1​, the effective horizon is about 11−γ\frac{1}{1-\gamma}1−γ1​ steps. At γ=0.9\gamma = 0.9γ=0.9 that is ten steps; at γ=0.99\gamma = 0.99γ=0.99 it is a hundred. This is a practical dial: how far ahead should the agent plan?

Why not just set gamma to 1?

For tasks that genuinely end — a game, a single episode of a robot — setting γ=1\gamma = 1γ=1 is fine, because the sum stops at the end. For tasks that keep going, it is not. The total reward may literally be infinite, and more subtly, the iterative method we use to solve for value stops converging: the fixed point that makes the mathematics work requires a discount below 1. This is not a stylistic preference; the convergence guarantee depends on it, as the last section shows.

The return, written out#

Two worked numbers make the formula concrete. Take γ=0.9\gamma = 0.9γ=0.9 and suppose the agent receives +1+1+1 at each of five steps:

1+0.9+0.81+0.729+0.6561=4.0951.1 + 0.9 + 0.81 + 0.729 + 0.6561 = 4.0951.1+0.9+0.81+0.729+0.6561=4.0951.

The five rewards add up to 5, but their discounted total is about 4.10. Now let the rewards continue forever. The sum becomes the geometric series 1+γ+γ2+⋯1 + \gamma + \gamma^2 + \cdots1+γ+γ2+⋯, which equals

11−γ=10.1=10.\frac{1}{1-\gamma} = \frac{1}{0.1} = 10.1−γ1​=0.11​=10.

An infinite number of rewards adds up to a finite 10 because each one is discounted more than the last. That closed form is worth remembering: it appears again and again whenever a state keeps earning the same reward forever.

Value: the expected return#

The return is a property of one trajectory. Policies are judged on average, so we take the expected return and call it value.

The state-value function of a policy π\piπ answers "how good is it to be here, if I keep following π\piπ?":

Vπ(s)=Eπ ⁣[ Gt  |  st=s ].V^{\pi}(s) = \mathbb{E}_{\pi}\!\left[\,G_t \;\middle|\; s_t = s\,\right].Vπ(s)=Eπ​[Gt​∣st​=s].

The action-value function answers "how good is it to be here and take this action first?":

Qπ(s,a)=Eπ ⁣[ Gt  |  st=s,  at=a ].Q^{\pi}(s, a) = \mathbb{E}_{\pi}\!\left[\,G_t \;\middle|\; s_t = s,\; a_t = a\,\right].Qπ(s,a)=Eπ​[Gt​∣st​=s,at​=a].

The difference is worth saying in plain words:

  • Vπ(s)V^{\pi}(s)Vπ(s) — how good is this situation?
  • Qπ(s,a)Q^{\pi}(s, a)Qπ(s,a) — how good is this situation, if I start with action aaa?

The action value is more informative, because it directly compares the actions available. The state value is a weighted average of them, where the weights are the policy's action probabilities:

Vπ(s)=∑aπ(a∣s) Qπ(s,a).V^{\pi}(s) = \sum_a \pi(a \mid s)\, Q^{\pi}(s, a).Vπ(s)=a∑​π(a∣s)Qπ(s,a).

If we could compute Q∗Q^{*}Q∗ — the action values of the best policy — the problem would be solved: in each state, pick the action with the largest Q∗Q^{*}Q∗. Everything in reinforcement learning is a way of estimating these numbers without knowing the future.

The Bellman idea: reward now, value later#

Here is the step that turns an infinite problem into a computable one. Write the return as its first term plus the rest:

Gt=rt+1+γ Gt+1.G_t = r_{t+1} + \gamma\, G_{t+1}.Gt​=rt+1​+γGt+1​.

Then take expectations. The value of a state equals the reward you get now plus the discounted value of where you land:

“

The value of now is the reward now, plus the discounted value of next.

That sentence is the Bellman equation, and it holds exactly. For a fixed policy, averaging over both the policy's action choice and the world's randomness gives the Bellman expectation equation:

Vπ(s)=∑aπ(a∣s)[R(s,a)+γ∑s′P(s′∣s,a) Vπ(s′)].V^{\pi}(s) = \sum_a \pi(a \mid s) \left[ R(s, a) + \gamma \sum_{s'} P(s' \mid s, a)\, V^{\pi}(s') \right].Vπ(s)=a∑​π(a∣s)[R(s,a)+γs′∑​P(s′∣s,a)Vπ(s′)].

The outer sum averages over the action the policy might take; the inner sum averages over the state the world might deliver. The equation is recursive: VπV^{\pi}Vπ appears on both sides. Notice there are no infinite sums left — every term refers only to the value of a next state.

For the best possible policy, each state simply takes the best action instead of averaging:

V∗(s)=max⁡a[R(s,a)+γ∑s′P(s′∣s,a) V∗(s′)].V^{*}(s) = \max_a \left[ R(s, a) + \gamma \sum_{s'} P(s' \mid s, a)\, V^{*}(s') \right].V∗(s)=amax​[R(s,a)+γs′∑​P(s′∣s,a)V∗(s′)].

This is the Bellman optimality equation. The change looks small — a max⁡\maxmax where an average used to be — but it is the difference between evaluating a policy and finding the best one. The max⁡\maxmax also makes the equation non-linear, which is why optimality is solved by iteration rather than a single linear solve.

Intuition: why one equation is enough

The Bellman equation replaces "add up every reward until the end of time" with "one step of reward, plus the value of wherever you land". Because the landing spot has a value too, using the equation again expands it one more step, and again, and again — until you have the whole future. The recursion is the infinite sum, written in a form a computer can iterate.

Why the recursion settles#

The Bellman right-hand side defines an update: take a guess at VVV, apply the equation, get a better guess, repeat. Why does that not wander forever?

Because multiplying by γ\gammaγ shrinks differences. If two guesses are far apart, one sweep of the Bellman update pulls them closer by a factor of γ\gammaγ at worst. Squeeze a distance by a factor below 1 and the guesses must converge to a single fixed point — one set of values that reproduces itself under the equation. This is the contraction property, and it is the mathematical guarantee that iterative methods like value iteration terminate at the right answer.

The guarantee is exactly why γ\gammaγ must be below 1 for continuing tasks. At γ=1\gamma = 1γ=1 the shrinking factor is 1 — nothing is squeezed, there may be no unique fixed point, and the iteration can cycle. Discounting is not just about patience; it is what makes the problem well-posed.

Browser lab: returns and the Bellman fixed point#

The cell computes a discounted return directly, then finds the same answer by iterating the Bellman equation.

python · runs in browser
import numpy as np

gamma = 0.9

# 1. The discounted return, computed the long way.
rewards = np.array([1.0, 1.0, 1.0, 1.0, 1.0])
discounts = gamma ** np.arange(len(rewards))
G = np.sum(discounts * rewards)
print(f"5 rewards of +1, discounted at {gamma}: {G:.4f}")

# 2. The same idea for a state that earns +1 forever. Bellman says V = 1 + gamma * V.
V = 0.0
for _ in range(200):
    V = 1.0 + gamma * V
print(f"Bellman fixed point: {V:.4f}  (closed form 1/(1-gamma) = {1 / (1 - gamma):.4f})")

# 3. Watch a guess walk up to the fixed point instead of jumping to it.
V = 0.0
snapshots = []
for sweep in range(20):
    V = 1.0 + gamma * V
    if sweep in (0, 1, 2, 4, 9, 19):
        snapshots.append(f"after {sweep + 1:>2} sweeps: V = {V:.4f}")
print("Approaching the fixed point:")
for line in snapshots:
    print("  " + line)

print("Notice: each sweep shrinks the remaining gap by gamma, so the guesses converge geometrically.")

What to look for.

  • The five-step return (about 4.10) is smaller than the infinite-state value (10.0) — the infinite value keeps earning after the fifth step.
  • Every sweep multiplies the remaining gap by γ=0.9\gamma = 0.9γ=0.9. The starting error is 10, so after ten sweeps it is about 3.5, and after twenty it is about 1.2. That is the contraction at work, and it is why a discount below 1 matters.

Try it. Change gamma to 0.99 and re-run. The closed form jumps to 100, but 200 sweeps are no longer enough to get there — the printed value lands near 86.6, and convergence is visibly slower. A larger effective horizon costs more iterations. Then try gamma = 1.0 with the loop in part 2 and watch V grow without settling.

Key takeaways#

  • The return Gt=∑kγkrt+k+1G_t = \sum_k \gamma^k r_{t+k+1}Gt​=∑k​γkrt+k+1​ collapses a reward stream into one number by discounting the future geometrically.
  • The discount factor does three jobs: keeps the total finite, encodes time preference, and sets an effective planning horizon of about 11−γ\frac{1}{1-\gamma}1−γ1​ steps.
  • Value functions are expected returns. Vπ(s)V^{\pi}(s)Vπ(s) is "how good is this state", Qπ(s,a)Q^{\pi}(s,a)Qπ(s,a) is "how good is this state plus this action".
  • The Bellman equation is the recursion V=reward now+γ⋅V(next)V = \text{reward now} + \gamma \cdot V(\text{next})V=reward now+γ⋅V(next). The expectation version evaluates a policy; the max version describes the best one.
  • With γ\gammaγ below 1 the Bellman update shrinks the error by γ\gammaγ each sweep, so iteration converges to a unique fixed point. At γ=1\gamma = 1γ=1 that guarantee disappears.

Knowledge Check#

Check the arithmetic and the idea behind the recursion.

Exercise · Fill in the blank

With discount factor gamma = 0.5, a reward of 1 received two steps from now is counted as ___.

Exercise · Multiple choice

The Bellman equation expresses a state's value in terms of:

Every future reward, summed without bound
The reward received now plus the discounted value of the next state
Only the reward of the best possible trajectory
The policy's parameters and a learning rate
Question 1 of 3

Why is the discount factor kept below 1 for a task that never ends?

Because rewards are always negative
To keep the total reward finite and to guarantee the value iteration converges
Because the policy must be deterministic
Because the state space is too small

Next step#

Value functions tell an agent how good its current choices are. The next step is about the other half of learning: how an agent gathers the evidence it needs, what it costs to try an uncertain option, and how to measure the reward it gave up along the way.

Next: Exploration, Exploitation, and Regret

← Previous
Bandits: Exploration, Exploitation, and Regret
Next →
Bandits: UCB1 and Thompson Sampling
On this page
  • From one reward to a running total
  • Three jobs of the discount factor
  • The return, written out
  • Value: the expected return
  • The Bellman idea: reward now, value later
  • Why the recursion settles
  • Browser lab: returns and the Bellman fixed point
  • Key takeaways
  • Knowledge Check
  • Next step