In page 269 of the latest draft of Richard S. Sutton's RL book, he proves the policy gradient theorem for episodic MDPs. I'm trying to follow the proof, but I don't understand one of the steps. How does he go from:
$$ \sum_a \left[\nabla\pi(a|s)q_\pi(s,a)+\pi(a|s)\sum_{s'}p(s'|s,a)\sum_{a'}[\nabla\pi(a'|s')q_\pi(s',a')+\pi(a'|s')\sum_{s''}p(s''|s',a')\nabla v_\pi(s'')] \right] $$
to:
$$ \sum_{r\in \mathcal{S}}\sum_{k=0}^\infty Pr(s\rightarrow x,k,\pi)\sum_a \nabla \pi(a|x)q_\pi(x,a) ~?$$
He mentions that this is obtained after "repeated unrolling", where "unrolling" means (judging from the previous step in the proof) expanding $v_\pi(x)$ into its definition, dependent on $v_\pi(x')$.
Can anyone help me clarify this step?