Let $f(x)$ be a positive continuous pdf with support over $[a,b]$ and let $F(x)$ be its corresponding cdf. Let $p: [a,b] \to [0,1]$. I am trying to figure out the following chain of equalities:
$$ \int_a^b \int_a^x p(y) f(x) dy dx = \int_a^b \int_y^b f(x) p(y) dx dy = \int_a^b (1-F(y)) p(y) dy $$
I think I see the second equality (since $F(x) = \int_a^x f(x) dx)$) but I am struggling to see the logic behind the change of order of integration in the first equation. It looks to me that we are integrating over the region of $[a,b]\times[a,b]$ where $x \geq a$, but I get stuck there.
Any pointers would be appreciated, thanks!
The last expression in the chain is not correct; it depends on $x$ while the others do not. It is correct if you replace $F(x)$ by $F(y)$, and then it is just that $\int_y^b f(x) dx = F(b)-F(y)=1-F(y)$.
The first equality is from describing the triangular region with inequalities. To begin with you have $a \leq x \leq b,a \leq y \leq x$, that is, the part of the square $[a,b] \times [a,b]$ below the line $y=x$. This can be instead described as the part of the square $[a,b] \times [a,b]$ to the right of the line $y=x$ which is where the bound $x \geq y$ in the second formula comes from.