ML Systems Lab Open interactive version →
Foundational 45 min read bellmanvalue functiondynamic programmingcontractiontabular

Bellman Equations

V(s), Q(s,a), optimality equations, contraction mapping, curse of dimensionality

Consider a 4×4 grid world with γ = 0.9. You want to know: what is the expected total reward — the value — of being at position (2,3) if you follow the optimal policy? To answer this, you need to know the value of neighboring positions, because your value here depends on where you can move next. But those values depend on their neighbors too. The circular dependency seems impossible to resolve — yet this is exactly what the Bellman equations do: they express the value of a state as a function of the values of its successors, turning a circular problem into a recursive one with a guaranteed fixed point.

The state value function under a policy π is V^π(s) = E_π[R_{t+1} + γ V^π(S_{t+1}) | S_t = s]. The value of a state equals immediate expected reward plus discounted expected value of the next state. This is the Bellman expectation equation — self-consistent, recursive, and for a fixed policy, linear enough to solve directly.

The optimal value function is V*(s) = max_a [R(s,a) + γ Σ_{s'} P(s'|s,a) V*(s')]. The value of the best possible policy equals the action that maximizes immediate reward plus discounted future value. The action-value function Q*(s, a) = R(s,a) + γ Σ_{s'} P(s'|s,a) max_{a'} Q*(s', a') is more practically useful: it tells you the value of taking action a in state s and then acting optimally, which means you can select actions directly via argmax_a Q*(s, a) without needing to model transitions.

Value iteration starts with an arbitrary value estimate and repeatedly applies the Bellman operator until convergence. Contraction mapping theory guarantees this converges to V* for finite MDPs. Policy iteration alternates between evaluating the current policy exactly and then improving it greedily. Both are guaranteed to find the optimal policy — but only in the tabular case.

NOT this: you need to know the transition model T(s, a, s') to use Bellman equations. Model-based RL uses the equations directly with a known or learned T. Model-free RL — Q-learning, TD learning — uses samples to estimate the Bellman updates without ever modeling T explicitly. The Bellman structure guides both approaches by telling you what quantity to estimate.

Key points

Takeaway

The Bellman equation turns the circular problem of value estimation into a recursive fixed point: the value of a state equals immediate reward plus discounted value of the best next state — and iterating this update is guaranteed to find the answer.

Recap

Check your understanding

Q1. Write the Bellman optimality equation for Q*(s,a) and explain what makes it "nonlinear," unlike the Bellman expectation equation.

Q2. In policy iteration, why is policy improvement guaranteed to produce a policy at least as good as the current one? What is the formal argument?

Q3. You are implementing Q-learning with a neural network and notice Q-values growing unboundedly during training. Which two fixes directly address the bootstrapping instability that causes this?

Q4. How many states does a simplified Atari game environment like Pong have, and why does this make tabular DP completely impractical?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →