Bellman equation derivation
Bellman equation for .
We want to show for all states .
The core idea of the proof is to use the law of total probability to go from marginal to conditional probabilities, and then invoke the Markov assumption.
The law of total probability states that if is an event, and are events that partition the sample space, then .
For fixed event with non-zero probability, the mapping is another valid probability measure. In other words, define by for all events . Now the law of total probability for states that . We also have
So the law of total probability states that .
Now we see how the law of total probability interacts with conditional expectation. Let be a random variable. Then
Here the event is playing the role of in the statement of the conditional law of total probability.
This is the basic trick of the proof; we keep conditioning on different things (actions, next states, rewards) and using the law of total probability.
By definition, . Now rewrite and use the linearity of expectation to get . From here, we can work separately with and for a while.
Using the law of total probability while conditioning over actions, we have
Using the convention that , this becomes
Now we can reorder the sums to get
Again, using the law of total probability (in its conjunction form) while conditioning this time over states, we have
Reordering the sums, this becomes
Sutton and Barto abbreviate as (strictly speaking, we should track the timestep parameter , but we will omit this detail here). We can also combine the nested sums into a single sum that iterates over pairs . So we obtain
This completes the part for . In other words, we have shown that
Now we do a similar series of steps for . Conditioning over actions,
Rearranging sums, this is
Conditioning over states and rewards, we have
Now write as . Since we have . Thus, substituting this expression and rearranging sums, we have
This is basically what we want, except we want to say that .