State-Value and Action-Value Functions

Imagine a robot navigating a warehouse, choosing among many possible paths to a loading dock. Some paths look short but pass through congested aisles. Others look long but stay clear. To choose well, the robot needs a number for each situation. It needs a forecast of how much total reward it can expect from here onward. This is exactly the problem that state-value and action-value functions solve. They compress an uncertain, multi-step future into a single predictive quantity. That quantity attaches to a state, or to a state-action pair. These functions are the computational backbone of almost every Reinforcement Learning algorithm. Whether an agent is playing chess, trading stocks, or controlling a robot arm, it needs a way to compare situations. It must judge "how good is this situation" against "how good is that one." Without value functions, an agent would have to simulate every possible future exhaustively. It would need to do this before making a single decision. This strategy is computationally hopeless in any environment with more than a handful of states. Value functions let the agent cache long-range consequences into short, reusable numbers. The big picture is this: given a fixed policy — a rule for choosing actions — we can ask two closely related questions. First, "how good is it to be in state ss while following this policy?" That is the state-value function, written vπ(s)v_\pi(s). Second, "how good is it to take a specific action aa in state ss, and only then follow the policy?" That is the action-value function, written qπ(s,a)q_\pi(s,a). These two functions are not independent inventions. They are algebraically linked, and that link is a seed. From it, the Bellman Equations and eventually the Bellman Optimality Equation will grow. This article builds both functions from first principles. It starts from the definition of expected return. It shows precisely how vπv_\pi and qπq_\pi relate to each other. It gives working pseudocode for estimating them by simulation. It also works a full numerical trace on a small grid. This way, every number can be checked by hand.

Key takeaways
  • vπ(s)v_\pi(s) is the expected total discounted reward from state ss, given that the agent follows policy π\pi forever after.
  • qπ(s,a)q_\pi(s,a) is the expected total discounted reward from taking action aa in state ss, then following π\pi afterward.
  • vπ(s)v_\pi(s) is an action-probability-weighted average of qπ(s,a)q_\pi(s,a) over all actions the policy might take in ss.
  • qπ(s,a)q_\pi(s,a) can be written in terms of vπv_\pi evaluated at the next state, averaged over the environment's transition dynamics.
  • Both functions can be estimated empirically by Monte Carlo averaging of sampled returns, without knowing the environment's model.
  • These definitions are exactly the objects that the Bellman equations turn into solvable recursive equations.
The core insight

State-value and action-value functions are expectations of future discounted reward, and they determine each other exactly through the policy's action probabilities and the environment's transition probabilities.

The idea

A <span class="wiki-link-missing">Markov decision process</span> (MDP) consists of states s∈Ss \in \mathcal{S}, actions a∈Aa \in \mathcal{A}, a transition function giving p(s′,r∣s,a)p(s', r \mid s, a), and a discount factor γ∈[0,1]\gamma \in [0,1]. A policy π\pi is a mapping from states to probabilities over actions: π(a∣s)\pi(a \mid s) is the probability of choosing action aa while in state ss. Given a trajectory that starts at time tt, the return is the discounted sum of future rewards,

Gt=Rt+1+γRt+2+γ2Rt+3+⋯=∑k=0∞γkRt+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}.

The return is a random variable: it depends on the random sequence of states, actions, and rewards that unfold after time tt, which in turn depend on both the policy's randomness and the environment's randomness. The state-value function for policy π\pi is the expected return starting from state ss and following π\pi thereafter:

vπ(s)  =  Eπ ⁣[Gt∣St=s].v_\pi(s) \;=\; \mathbb{E}_\pi\!\left[ G_t \mid S_t = s \right].

The action-value function (also called the Q-function) is the expected return starting from state ss, taking action aa immediately, and then following π\pi:

qπ(s,a)  =  Eπ ⁣[Gt∣St=s,At=a].q_\pi(s,a) \;=\; \mathbb{E}_\pi\!\left[ G_t \mid S_t = s, A_t = a \right].

The subtlety that separates the two definitions is the fate of the first action. In vπ(s)v_\pi(s), the first action is chosen by the policy according to π(⋅∣s)\pi(\cdot \mid s). In qπ(s,a)q_\pi(s,a), the first action is pinned to aa regardless of what the policy would normally do, and only the actions afterward obey π\pi. This is why qπq_\pi is strictly more informative: it tells you the consequence of every possible first move, not just the moves the policy happens to favor. Because vπ(s)v_\pi(s) averages over the policy's own choice of first action, and qπ(s,a)q_\pi(s,a) is the value conditional on that first action, the two are related by a simple expectation:

vπ(s)=∑a∈A(s)π(a∣s) qπ(s,a)=EA∼π(⋅∣s)[qπ(s,A)].v_\pi(s) = \sum_{a \in \mathcal{A}(s)} \pi(a \mid s)\, q_\pi(s,a) = \mathbb{E}_{A \sim \pi(\cdot\mid s)}\big[q_\pi(s,A)\big].

This identity is not an approximation or a modeling choice — it follows directly from the law of total expectation applied to the random variable AtA_t, conditioned on St=sS_t = s. Symmetrically, qπq_\pi can be expressed using vπv_\pi evaluated one step into the future, by conditioning on the immediate reward and next state produced by the environment's dynamics p(s′,r∣s,a)p(s', r \mid s, a):

qπ(s,a)=∑s′,rp(s′,r∣s,a)[r+γ vπ(s′)]=E[Rt+1+γ vπ(St+1)∣St=s,At=a].q_\pi(s,a) = \sum_{s', r} p(s', r \mid s, a) \Big[ r + \gamma\, v_\pi(s') \Big] = \mathbb{E}\big[R_{t+1} + \gamma\, v_\pi(S_{t+1}) \mid S_t = s, A_t = a\big].

Together these two identities form a tight loop: vπv_\pi is built from qπq_\pi by averaging over the policy, and qπq_\pi is built from vπv_\pi by averaging over the environment's transition dynamics. Substituting one into the other produces the recursive self-referential equation known as the Bellman equation for vπv_\pi, which is the natural next object of study, along with its action-value counterpart and, eventually, the optimality equations that characterize the best possible policy.

How it works

Since vπv_\pi and qπq_\pi are defined as expectations over an infinite (or long) random trajectory, computing them exactly requires either (a) an explicit model of the environment's dynamics, solved analytically or by dynamic programming, or (b) empirical estimation by sampling many trajectories and averaging observed returns — the Monte Carlo approach. Because this article's prerequisite level assumes only the definitions of policies and value functions (not yet the Bellman machinery), the cleanest way to compute — rather than merely define — these quantities without a model is direct Monte Carlo estimation. This also builds the right intuition: vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) are just averages of empirical returns, and dynamic-programming methods later on will simply find faster ways to compute the same averages using the recursive identities above.

Step-by-step mechanism for Monte Carlo estimation of vπv_\pi and qπq_\pi: 1. Fix the policy π\pi to be evaluated. It does not change during this process — we are only measuring it, not improving it. 2. Generate an episode: starting from some state, repeatedly sample an action from π(⋅∣St)\pi(\cdot \mid S_t), let the environment produce Rt+1R_{t+1} and St+1S_{t+1}, and continue until a terminal state (or a fixed horizon). 3. For each time step tt visited in the episode, compute the realized return Gt=∑k≥0γkRt+k+1G_t = \sum_{k \geq 0} \gamma^k R_{t+k+1} by summing forward from that point to the end of the episode. 4. Attribute that sampled return GtG_t as one observation of vπ(St)v_\pi(S_t), and also as one observation of qπ(St,At)q_\pi(S_t, A_t) (since the true action taken at tt was AtA_t). 5. Maintain running averages, per state (for vπv_\pi) and per state-action pair (for qπq_\pi), across many episodes. 6. As the number of episodes grows, the law of large numbers guarantees these running averages converge to the true vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a). ``` function MONTE_CARLO_EVALUATE(policy π, environment env, num_episodes N, discount γ):

# Running sums and counts for state-value and action-value estimates V_sum = dictionary(default 0.0) # state -> cumulative return V_count = dictionary(default 0) # state -> number of visits Q_sum = dictionary(default 0.0) # (state, action) -> cumulative return Q_count = dictionary(default 0) # (state, action) -> number of visits for episode in 1..N: states, actions, rewards = [], [], [] s = env.reset() while not env.is_terminal(s): a = sample_action(π, s) # a ~ π(· | s) s_next, r = env.step(s, a) states.append(s) actions.append(a) rewards.append(r) s = s_next T = length(rewards) G = 0.0

# Walk backward through the episode to build returns cheaply:

# G_t = R_{t+1} + γ G_{t+1}, computed from the end of the episode. for t in (T-1) down to 0: G = rewards[t] + γ * G # this G is now G_t s_t, a_t = states[t], actions[t] V_sum[s_t] += G V_count[s_t] += 1 Q_sum[(s_t, a_t)] += G Q_count[(s_t, a_t)] += 1

# Final estimates: sample averages of observed returns v_hat = { s: V_sum[s] / V_count[s] for s in V_sum } q_hat = { (s,a): Q_sum[(s,a)] / Q_count[(s,a)] for (s,a) in Q_sum } return v_hat, q_hat ``` Two implementation notes matter for correctness. First, computing GtG_t by walking backward through the episode (as shown) costs O(1)O(1) work per time step via the recursion Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, rather than O(T)O(T) work per time step from a naive forward sum — this is a standard trick, not a shortcut that changes the answer. Second, if a state is visited multiple times within one episode, one may choose first-visit Monte Carlo (only the first occurrence contributes) or every-visit Monte Carlo (every occurrence contributes); both converge to vπv_\pi and qπq_\pi under mild conditions, though their variance and bias properties in finite samples differ slightly. The diagram below shows how vπv_\pi and qπq_\pi interlock in a single decision step: the state-value at ss is a π\pi-weighted blend over actions of the action-values, and each action-value is a probability-weighted blend over the environment's stochastic outcomes of "reward plus discounted next-state value."

Figure
Backup structure linking vπ(s)v_\pi(s) to qπ(s,a)q_\pi(s,a) and back to vπ(s′)v_\pi(s')
s v_π(s) q_π(s,a₁) q_π(s,a₂) q_π(s,a₃) π(a₁|s) π(a₂|s) π(a₃|s) s₁′, r₁ s₂′, r₂ s₃′, r₃ p(s₁′,r₁|s,a₂) p(s₂′,r₂|s,a₂) p(s₃′,r₃|s,a₂) s₁′ s₂′ s₃′ v_π(s₁′) v_π(s₂′) v_π(s₃′) v_π(s) = Σ_a π(a|s) q_π(s,a); q_π(s,a) = Σ_{s',r} p(s',r|s,a) [r + γ v_π(s')]

Complexity & correctness

Space complexity. Storing vπv_\pi requires O(∣S∣)O(|\mathcal{S}|) numbers, one per state. Storing qπq_\pi requires O(∣S∣⋅∣A∣)O(|\mathcal{S}| \cdot |\mathcal{A}|) numbers, one per state-action pair. This is the fundamental storage tradeoff: qπq_\pi is a strictly larger table but carries strictly more decision-relevant information, since it separates out the consequence of each candidate action instead of blending them under the current policy.

Time complexity of Monte Carlo estimation. For one episode of length TT, generating the trajectory costs O(T)O(T) environment interactions. Computing all returns GtG_t for t=0,…,T−1t = 0, \dots, T-1 via the backward recursion costs O(T)O(T) total (each GtG_t is O(1)O(1) given Gt+1G_{t+1}), not O(T2)O(T^2) as a naive forward summation would cost. Updating running averages for vπv_\pi and qπq_\pi costs O(1)O(1) per visited state or state-action pair. So one episode costs O(T)O(T) overall, and NN episodes cost O(N⋅Tavg)O(N \cdot T_{\text{avg}}), where TavgT_{\text{avg}} is the average episode length. This is efficient — linear in the total amount of simulated experience — but the statistical efficiency (how many episodes are needed for accurate estimates) is separate from this computational cost, and is governed by the variance of returns, discussed below.

Correctness of the Monte Carlo estimator. The estimator's correctness rests on the definition of vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) as expectations, combined with the law of large numbers. Fix a state ss. Every episode that visits ss at some time tt contributes an independent (or, for every-visit, weakly dependent) sample of the random variable Gt∣St=sG_t \mid S_t = s, whose expectation is vπ(s)v_\pi(s) by definition. As the number of such samples n→∞n \to \infty,

1n∑i=1nG(i)  →a.s.  E[G∣S=s]=vπ(s)\frac{1}{n}\sum_{i=1}^{n} G^{(i)} \;\xrightarrow{\text{a.s.}}\; \mathbb{E}[G \mid S=s] = v_\pi(s)

by the strong law of large numbers, provided the returns have finite variance (guaranteed when rewards are bounded and γ<1\gamma < 1, or when episodes terminate with probability 1 under γ=1\gamma = 1). The identical argument, replacing the conditioning event St=sS_t = s with the joint event (St,At)=(s,a)(S_t, A_t) = (s,a), establishes convergence of the running average to qπ(s,a)q_\pi(s,a).

Correctness of the vπ↔qπv_\pi \leftrightarrow q_\pi identities. These are not estimated quantities but exact algebraic consequences of the definitions, provable by the law of total expectation. For the first identity:

vπ(s)=Eπ[Gt∣St=s]=EAt∼π(⋅∣s)[ Eπ[Gt∣St=s,At] ]=∑aπ(a∣s) qπ(s,a),v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s] = \mathbb{E}_{A_t \sim \pi(\cdot|s)}\Big[\, \mathbb{E}_\pi[G_t \mid S_t = s, A_t] \,\Big] = \sum_a \pi(a|s)\, q_\pi(s,a),

where the middle step is exactly the tower property of conditional expectation, conditioning first on AtA_t and then averaging over its distribution π(⋅∣s)\pi(\cdot \mid s). For the second identity, split the return as Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, and condition on (St+1,Rt+1)(S_{t+1}, R_{t+1}):

qπ(s,a)=E[Rt+1+γGt+1∣St=s,At=a]=∑s′,rp(s′,r∣s,a)[r+γ Eπ[Gt+1∣St+1=s′]],q_\pi(s,a) = \mathbb{E}[R_{t+1} + \gamma G_{t+1} \mid S_t=s, A_t=a] = \sum_{s',r} p(s',r|s,a)\Big[r + \gamma\, \mathbb{E}_\pi[G_{t+1} \mid S_{t+1}=s']\Big],

and the inner expectation is exactly vπ(s′)v_\pi(s') by definition, using the Markov property to note that the future beyond St+1S_{t+1} depends only on St+1S_{t+1}, not on the earlier history. This step is the one place the Markov assumption is doing real work — without it, Eπ[Gt+1∣St+1=s′]\mathbb{E}_\pi[G_{t+1} \mid S_{t+1} = s'] could differ depending on how the process arrived at s′s'.

Honest tradeoffs. Monte Carlo estimation is unbiased and model-free, but it has two costs. First, it requires episodes to terminate (or a very long finite horizon), so it converges slowly in environments with long or highly variable episode lengths — the variance of GtG_t compounds over every step, since each reward Rt+k+1R_{t+k+1} is itself random. Second, it wastes information: an episode that visits a state only once contributes only one sample, ignoring the rich structure the Bellman identities exploit — namely that vπ(s′)v_\pi(s') for a nearby state can be reused to estimate vπ(s)v_\pi(s) without waiting for whole episodes to finish. This inefficiency is precisely the gap that dynamic-programming and bootstrapping methods, built directly on the Bellman equations, are designed to close.

Worked example

Consider a tiny two-state MDP: states {A,B}\{A, B\}, with BB terminal (reward-then-done). From AA, two actions are available: stay (loop back to AA) and go (move to terminal BB). Rewards: staying yields reward 22 and looping back to AA; going yields reward 55 and terminates at BB. Discount factor γ=0.5\gamma = 0.5. The policy π\pi chooses stay with probability 0.30.3 and go with probability 0.70.7 in state AA.

Exact computation using the identities (ground truth). First compute qπ(A,go)q_\pi(A, \text{go}). Taking "go" yields reward 55 and transitions to terminal state BB, where vπ(B)=0v_\pi(B) = 0 since no further reward is possible:

qπ(A,go)=5+γ⋅vπ(B)=5+0.5⋅0=5.q_\pi(A,\text{go}) = 5 + \gamma \cdot v_\pi(B) = 5 + 0.5 \cdot 0 = 5.

Next compute qπ(A,stay)q_\pi(A, \text{stay}). Taking "stay" yields reward 22 and transitions back to AA, so it depends on vπ(A)v_\pi(A) itself:

qπ(A,stay)=2+γ⋅vπ(A)=2+0.5 vπ(A).q_\pi(A,\text{stay}) = 2 + \gamma \cdot v_\pi(A) = 2 + 0.5\, v_\pi(A).

Now use the other identity to write vπ(A)v_\pi(A) in terms of both qq-values:

vπ(A)=π(stay∣A) qπ(A,stay)+π(go∣A) qπ(A,go)v_\pi(A) = \pi(\text{stay}|A)\, q_\pi(A,\text{stay}) + \pi(\text{go}|A)\, q_\pi(A,\text{go})
vπ(A)=0.3 (2+0.5 vπ(A))+0.7 (5).v_\pi(A) = 0.3\,(2 + 0.5\, v_\pi(A)) + 0.7\,(5).

This is a single linear equation in vπ(A)v_\pi(A):

vπ(A)=0.6+0.15 vπ(A)+3.5=4.1+0.15 vπ(A)v_\pi(A) = 0.6 + 0.15\, v_\pi(A) + 3.5 = 4.1 + 0.15\, v_\pi(A)
0.85 vπ(A)=4.1⟹vπ(A)=4.8235 (to 4 d.p.).0.85\, v_\pi(A) = 4.1 \quad\Longrightarrow\quad v_\pi(A) = 4.8235 \text{ (to 4 d.p.)}.

Substituting back gives qπ(A,stay)=2+0.5⋅4.8235=4.4118q_\pi(A,\text{stay}) = 2 + 0.5 \cdot 4.8235 = 4.4118, and we already have qπ(A,go)=5q_\pi(A,\text{go}) = 5. Sanity check with the identity:

vπ(A)=0.3⋅4.4118+0.7⋅5=1.3235+3.5=4.8235.✓v_\pi(A) = 0.3 \cdot 4.4118 + 0.7 \cdot 5 = 1.3235 + 3.5 = 4.8235. \checkmark
QuantityValue
qπ(A,stay)q_\pi(A,\text{stay})4.41184.4118
qπ(A,go)q_\pi(A,\text{go})5.00005.0000
vπ(A)v_\pi(A)4.82354.8235
vπ(B)v_\pi(B)0.00000.0000

Monte Carlo estimate, for comparison. Simulate 4 short episodes starting at AA under π\pi (stay 0.3 / go 0.7), truncated once terminal BB is reached:

EpisodeAction sequenceRewardsReturn G0G_0 from AA
1go555
2stay, go2, 52+0.5(5)=4.52 + 0.5(5) = 4.5
3go555
4stay, stay, go2, 2, 52+0.5(2+0.5(5))=2+0.5(4.5)=4.252 + 0.5(2 + 0.5(5)) = 2 + 0.5(4.5) = 4.25

Averaging these four sampled returns for state AA: v^π(A)=(5+4.5+5+4.25)/4=4.6875\hat v_\pi(A) = (5 + 4.5 + 5 + 4.25)/4 = 4.6875. This is close to the exact value 4.82354.8235, and with only 4 episodes some estimation error is expected — the gap would shrink toward zero as more episodes are averaged, exactly as the law of large numbers predicts. Note episode 1 and 3 also contribute directly to the running average for qπ(A,go)q_\pi(A,\text{go}) (both sampled a return of 55 starting with action "go"), while episodes 2 and 4 contribute to qπ(A,stay)q_\pi(A,\text{stay}).

Common pitfalls & traps

PitfallWhy it happensFix
Confusing vπ(s)v_\pi(s) with max⁡aqπ(s,a)\max_a q_\pi(s,a)vπ(s)v_\pi(s) averages over the policy's action distribution, not the best actionRemember vπ(s)=∑aπ(a∣s)qπ(s,a)v_\pi(s) = \sum_a \pi(a|s) q_\pi(s,a); only for an optimal greedy policy does this equal the max
Forgetting the discount factor when computing returnsOff-by-one errors treating γ0\gamma^0 or γ1\gamma^1 as the weight on the first rewardReturn is Gt=Rt+1+γRt+2+⋯G_t = R_{t+1} + \gamma R_{t+2} + \cdots; the first reward after time tt has weight γ0=1\gamma^0=1
Assuming qπ(s,a)q_\pi(s,a) ignores the policy entirelyThe first action is fixed at aa, but every subsequent action still follows π\piqπq_\pi pins only the first action; it is not the value of always taking aa forever
Using forward summation for returns in Monte Carlo codeNaively re-summing from each tt to the episode end costs O(T2)O(T^2)Use the backward recursion Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, costing O(T)O(T) total
Treating vπ(s′)v_\pi(s') in the qπq_\pi identity as depending on historyForgetting the Markov propertyThe identity qπ(s,a)=E[R+γvπ(S′)]q_\pi(s,a)=\mathbb{E}[R+\gamma v_\pi(S')] is valid only because future return depends solely on St+1S_{t+1}, not on how the process arrived there
Averaging returns across different policiesValue functions are policy-specific: vπ≠vπ′v_\pi \ne v_{\pi'} in generalAlways fix and label the policy being evaluated; re-evaluate from scratch after any policy change

Pioneers & history

The state-value and action-value functions arose from the marriage of two independent lines of work: Richard Bellman's theory of dynamic programming for sequential decision problems under uncertainty, and the later formalization of trial-and-error learning as an approximation to that theory.

Origins · 1 minRichard E. Bellman and how this was discovered
RE
Richard E. Bellman
1920–1984 · RAND Corporation, dynamic programming and the theory of Markov decision processes

Bellman formulated the principle of optimality and the recursive equations that bear his name while working on multistage decision processes at RAND in the 1950s. His formulation of value as an expected future return, defined recursively in terms of immediate reward plus discounted future value, is the direct mathematical ancestor of vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) as used in reinforcement learning today.

History
1957
Bellman publishes Dynamic Programming, introducing value functions and the principle of optimality for sequential decision processes.
1960
Ronald Howard develops policy iteration for Markov decision processes, an early algorithm exploiting the vπv_\pi–qπq_\pi relationship.
1988
Sutton introduces Temporal-Difference learning, showing value functions can be updated from single-step experience rather than full-episode Monte Carlo returns.
1989
Watkins formalizes Q-learning, placing the action-value function qπq_\pi and its optimal counterpart at the center of a practical, model-free control algorithm.
1998
Sutton and Barto's Reinforcement Learning: An Introduction consolidates vπv_\pi and qπq_\pi as the standard notation and pedagogical foundation for the field.

Where this matters

Every reinforcement learning algorithm that improves a policy needs some way to judge how good the current policy is, and vπv_\pi and qπq_\pi are exactly that judgment mechanism. Policy iteration and value iteration, the classical dynamic-programming algorithms for solving MDPs, alternate between evaluating vπv_\pi (or qπq_\pi) and improving the policy based on those values — this is the direct ancestor of modern actor-critic methods. Q-learning and Deep Q-Networks (DQN), used in landmark results such as Atari-playing agents, learn an approximation of the optimal action-value function directly, using a neural network to represent q(s,a)q(s,a) over enormous state spaces such as raw pixel frames. Actor-critic methods, including A3C, PPO, and modern robotics controllers, maintain an explicit "critic" network estimating vπ(s)v_\pi(s) to reduce the variance of policy-gradient updates. In recommendation systems, qπ(s,a)q_\pi(s,a)-style estimates are used to score candidate recommendations against a user's simulated future engagement. In finance and operations research, dynamic-programming solutions to inventory and portfolio problems rest on value functions defined exactly as they are here, decades before "reinforcement learning" was a common term. Any system that must trade off immediate reward against long-term consequence — game-playing agents, autonomous vehicles, dialogue systems — ultimately relies on some computational stand-in for vπv_\pi or qπq_\pi.

:::quiz[Why does the identity qπ(s,a)=∑s′,rp(s′,r∣s,a)[r+γvπ(s′)]q_\pi(s,a) = \sum_{s',r} p(s',r|s,a)[r + \gamma v_\pi(s')] rely on the Markov property?]

  • It doesn't; the identity holds for any stochastic process
  • Because it assumes Eπ[Gt+1∣St+1=s′]\mathbb{E}_\pi[G_{t+1} \mid S_{t+1}=s'] depends only on s′s', not on the path taken to reach it ✓
  • Because Markov chains never terminate
  • Because the discount factor must be state-dependent

Ask the tutor: How does substituting the qπq_\pi-to-vπv_\pi identity into the vπv_\pi-to-qπq_\pi identity produce the full Bellman equation for vπv_\pi?

Are vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) the same thing, just written differently?

No — they answer different questions and carry different amounts of information. vπ(s)v_\pi(s) tells you the expected return if you let the policy choose the very first action too, so it is a single blended number per state. qπ(s,a)q_\pi(s,a) tells you the expected return for each specific candidate first action, holding it fixed, and only lets the policy resume afterward. Because of this, qπq_\pi contains strictly more information: knowing qπ(s,a)q_\pi(s,a) for every action lets you recover vπ(s)v_\pi(s) exactly via the weighted average vπ(s)=∑aπ(a∣s)qπ(s,a)v_\pi(s) = \sum_a \pi(a|s) q_\pi(s,a), but knowing only vπ(s)v_\pi(s) does not let you recover the individual qπ(s,a)q_\pi(s,a) values, since the averaging step discards per-action detail. This is why algorithms that need to choose actions, like Q-learning, prefer to learn qπq_\pi or its optimal counterpart directly.

Why do we need the policy π\pi at all — can't we just define "the" value of a state?

"The" value of a state is not well-defined without specifying a policy, because different policies produce different expected returns from the same state. A cautious policy that avoids risky shortcuts and a reckless policy that takes them will generally assign very different expected returns to the same starting state, even though the environment's dynamics are identical. This is why value functions are always written with a policy subscript, vπv_\pi or qπq_\pi, and why comparing two policies means comparing their entire value functions, state by state. Only when we ask for the best possible value, over all policies simultaneously, do we get a policy-independent object — the optimal value functions v∗v_* and q∗q_* — which is the subject the Bellman optimality equation addresses.

Does the Monte Carlo estimator described here require knowing the environment's transition probabilities p(s′,r∣s,a)p(s',r|s,a)?

No, and this is one of its most attractive properties. Monte Carlo estimation only requires the ability to sample from the environment — to actually take actions and observe the resulting rewards and next states — not to know or compute with the underlying probability distribution p(s′,r∣s,a)p(s',r|s,a) in closed form. This makes it a model-free method, in contrast to dynamic-programming approaches that require an explicit, known model to compute the same expectations analytically. The tradeoff is statistical efficiency: Monte Carlo needs many sampled episodes to average away randomness, whereas a known model lets you compute exact expectations in one pass, using exactly the recursive identities derived in this article.

What happens to vπv_\pi and qπq_\pi if the discount factor γ\gamma equals 1?

With γ=1\gamma = 1, the return GtG_t becomes an undiscounted sum of all future rewards, which is only guaranteed to be finite if episodes terminate with probability 1 (an "episodic" task) or if rewards eventually become exactly zero. In infinite-horizon tasks without guaranteed termination, an undiscounted sum of nonzero rewards can diverge to infinity, making vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) undefined or infinite. This is precisely why most continuing (non-episodic) tasks use γ<1\gamma < 1: it guarantees the geometric-series-like sum converges whenever rewards are bounded, since ∑kγkRmax⁡\sum_k \gamma^k R_{\max} is a convergent geometric series for γ<1\gamma < 1. Episodic tasks with guaranteed termination can safely use γ=1\gamma = 1, since the sum is automatically finite.

Can qπ(s,a)q_\pi(s,a) be negative, or larger than vπ(s)v_\pi(s) for every action?

Both are possible and neither indicates an error. qπ(s,a)q_\pi(s,a) can be negative whenever the expected discounted future rewards following action aa are net negative, which is perfectly normal in environments with penalty or cost signals. It is also entirely possible for qπ(s,a)>vπ(s)q_\pi(s,a) > v_\pi(s) for every action aa that the policy assigns positive probability to — this simply means the policy is choosing suboptimally at ss, favoring some mixture of actions whose weighted average vπ(s)v_\pi(s) falls short of what any single action alone would achieve. This exact gap, between what the policy currently does and what greedily following the largest qπ(s,a)q_\pi(s,a) would achieve, is the quantity that policy improvement algorithms are built to close.

How does this relate to the Bellman equations mentioned as "leading to" this topic?

The two identities derived here — vπ(s)=∑aπ(a∣s)qπ(s,a)v_\pi(s) = \sum_a \pi(a|s) q_\pi(s,a) and qπ(s,a)=∑s′,rp(s′,r∣s,a)[r+γvπ(s′)]q_\pi(s,a) = \sum_{s',r} p(s',r|s,a)[r+\gamma v_\pi(s')] — are the two halves of a puzzle. Substituting the second identity into the first produces a single equation expressing vπ(s)v_\pi(s) entirely in terms of vπv_\pi evaluated at other states, one step into the future. That self-referential equation is exactly the Bellman equation for vπv_\pi, and an analogous substitution in the other direction produces the Bellman equation for qπq_\pi. Rather than being estimated only by simulation, as in this article's Monte Carlo pseudocode, these recursive equations can be solved directly — by linear algebra for small problems, or by dynamic-programming iteration for larger ones — which is the natural next step in the theory.

Why does the article emphasize that returns are random variables, not fixed numbers?

Because misunderstanding this point is one of the most common sources of confusion for newcomers to the field. A single played-out trajectory produces one concrete numerical return, but vπ(s)v_\pi(s) and qπ(s,a)q_\pi(s,a) are defined as expectations over the entire distribution of possible trajectories, not as the return of any one particular trajectory. This distinction matters practically: in a stochastic environment, or with a stochastic policy, two agents starting in the exact same state ss and following the exact same policy π\pi can experience wildly different realized returns, yet both are legitimate samples of the same underlying random variable whose mean defines vπ(s)v_\pi(s). Monte Carlo estimation works precisely because averaging many such samples converges to that mean, per the law of large numbers.

Before this

Where this leads