Finding an integral formula for intertwined recursive sequences I saw on Wikipedia that the arithmetic-geometric mean of two numbers is given by
$$\operatorname{agm}(x,y)=\frac{\pi}{2}\Bigg[\int_0^{\pi/2}\frac{d\theta}{\sqrt{x^2\cos^2\theta+y^2\sin^2\theta}}\Bigg]^{-1}$$
and I understand the proof of this little gem... however, how does one go about deriving something like this without knowing what to prove beforehand? For example, if I wanted to find an integral formula for the "geometric-harmonic mean" defined as
$$\operatorname{ghm}(x,y)=\lim_{n\to\infty} g_n=\lim_{n\to\infty} h_n$$
where
$$g_0=x$$
$$h_0=y$$
$$g_{n+1}=\sqrt{g_nh_n}$$
$$h_{n+1}=\frac{2}{\frac{1}{g_n}+\frac{1}{h_n}}$$
Then how would I go about finding an analogous integral formula?

For any $a,b>0$, let $HG(a,b)=HG\left(\frac{2ab}{a+b},\sqrt{ab}\right)$ and for any $x>1$ let $f(x)=HG(1,x)$.
We have:
$$f(x) = HG(1,x) = HG\left(\frac{2x}{1+x},\sqrt{x}\right) = \frac{2x}{1+x}\,HG\left(1,\frac{1+x}{2\sqrt{x}}\right)\\= \frac{2x}{1+x}\,f\left(\frac{1+x}{2\sqrt{x}}\right)\tag{A} $$
and we may notice that the map $g:x\mapsto\frac{1+x}{2\sqrt{x}}$ sends the interval $(1,+\infty)$ into itself.
In particular the given problem is equivalent to finding an invariant measure $\mu$ such that
$$\forall x>1,\qquad \mu((1,x)) = \frac{2x}{1+x}\,\mu\left(\left(1,\frac{1+x}{2\sqrt{x}}\right)\right)$$
Additionally, the sequence $x,g(x),g(g(x)),g(g(g(x))),\ldots$ converges really fast to $1$ for any $x>1$.
In particular
$$ f(x) = \frac{4x}{(1+\sqrt{x})^2}\;f(g(g(x))) \tag{B}$$
leads to $f(x)\approx \frac{4x}{(1+\sqrt{x})^2}$ and 
$$ HG(a,b) = a\cdot f\left(\tfrac{b}{a}\right) \approx \frac{4ab}{\left(\sqrt{a}+\sqrt{b}\right)^2}=H\left(\sqrt{a},\sqrt{b}\right)^2\tag{C}$$
where $H$ stands for the usual harmonic mean. We may also notice that
$$ h(x)=\text{AGM}(1,x)=\text{AGM}\left(\sqrt{x},\frac{1+x}{2}\right) = \sqrt{x}\,h\left(\frac{1+x}{2\sqrt{x}}\right) $$
hence
$$ \frac{f}{h}(x) = \frac{1}{g(x)}\cdot \frac{f}{h}(g(x))\tag{D} $$
and the problem of finding a closed form for $\text{HG}$ boils down to the problem of finding a closed form for the infinite product
$$ g(x)\cdot g(g(x))\cdot g(g(g(x)))\cdot\ldots $$
On the other hand:
$$ h(x) = \sqrt{x} h(g(x)) = \sqrt{x}\sqrt{g(x)} h(g(g(x))) = \ldots = \sqrt{x}\sqrt{g(x)g(g(x))\cdot\ldots} $$
hence $f(x)=\frac{x}{h(x)}$ and
$$\boxed{ HG(a,b) = \frac{ab}{\text{AGM}(a,b)} = \color{red}{\frac{2}{\pi}\int_{0}^{+\infty}\frac{dx}{\sqrt{\left(1+\frac{x^2}{a^2}\right)\left(1+\frac{x^2}{b^2}\right)}}}.}\tag{E}$$
Further proof of $(E)$: it is enough to check that $\frac{ab}{\text{AGM}(a,b)}$ is invariant with respect to the replacements $b\to\sqrt{ab}, a\to\frac{2ab}{a+b}$.
$$\begin{eqnarray*}\frac{\sqrt{ab}\frac{2ab}{a+b}}{\text{AGM}\left(\sqrt{ab},\frac{2ab}{a+b}\right)}&=&\frac{2ab\sqrt{ab}}{\text{AGM}\left((a+b)\sqrt{ab},2ab\right)}\\&=&\frac{2ab}{\text{AGM}\left(a+b,2\sqrt{ab}\right)}\\&=&\frac{ab}{\text{AGM}\left(\frac{a+b}{2},\sqrt{ab}\right)}=\frac{ab}{\text{AGM}(a,b)}\;\large\checkmark\end{eqnarray*} $$
