# Evaluating value functions in RL

I'm working my way through the book Reinforcement Learning by Richar S. Sutton and Andrew G. Barto and I am stuck on the following question.

The value of a state depends on the the values of the actions possible in that state and on how likely each action is to be taken under the current policy. We can think of this in terms of a small backup diagram rooted at the state and considering each possible action:

Give the equation corresponding to this intuition and diagram for the value at the root node $v_{\pi }(s)$ , in terms of the value at the expected leaf node, $q_{\pi }(s_{t},a_{t})$ , given $s_{t} = s$ . This expectation depends on the policy, $\pi$ . Then give a second equation in which the expected value is written out explicitly in terms of $\pi(s,a)$ such that no expected value notation appears in the equation.

I should mention that...

$v_{\pi }(s) = \sum_{a}\pi (s,a)\sum_{s'}P_{ss'}^{a}[R_{ss'}^{a} + \gamma v_{\pi }(s')]$ ...

Where...

$\pi(s,a)$ = Probability of taking action a from state s

$P_{ss'}^{a}$ = Given any state s and a, the probability of each next state s'

$R_{ss'}^{a}$ = Expected reward given any state s, next state s, and action a

How can I re-evaluate this value function in the way that is asked?

In a discrete probability space, the expectation of a random variable (RV) is a sum over all possible values multiplied by their individual probabilities. Here, your RV is $$q_\pi(s,a)$$, with $$s$$ being fixed. Therefore you need to take the expecation with respect to the actions only:
$$v_{\pi}(s) \stackrel{\text{1. task}}{=} \mathbb{E}_{a\sim \pi(s, a)}[q_{\pi}(s, a)] \stackrel{\text{2. task}}{=} \sum_\limits{a}\pi(s, a) q_{\pi}(s, a)$$.
$$\pi(s, a)$$ represents the "individual probabilities".