In the diagram, $\alpha$ and $\beta$ are independent uniformly random real numbers in $\left(0,\frac{\pi}{2}\right)$.

enter image description here

What is $\mathbb{E}(h)$?

Superimposing a cartesian coordinate system, the equations of the lines are $y=(\tan\alpha)x$ and $y=(-\tan\beta)(x-1)$, so the $y$-coordinate of their intersection is $\frac{(\tan\alpha)(\tan\beta)}{\tan\alpha+\tan\beta}$. So we have

$$\mathbb{E}(h)=\frac{4}{\pi^2}\int_0^{\pi/2}\int_0^{\pi/2}\frac{(\tan\alpha)(\tan\beta)}{\tan\alpha+\tan\beta} d\alpha d\beta$$

Desmos says $I=\int_0^{\pi/2}\int_0^{\pi/2}\frac{(\tan\alpha)(\tan\beta)}{\tan\alpha+\tan\beta} d\alpha d\beta$ is $(0.9999999913...)(\frac{\pi}{2})$. Is that a computer error, and the result is exactly $\frac{\pi}{2}$? I don't know how to evaluate the integral. Wolfram evaluates the inside integral but doesn't evaluate both integrals.

If Desmos is not very reliable, then maybe my earlier weird conjecture is actually true.

(This question was inspired by a question about random points in a square.)

Edit: In the comments, @G.Gare notes that Mathematica says the integral $I$ is exactly $\pi/2$. Can we prove it? Maybe an intuitive geometrical argument?

Edit2: I seek to generalize this result here.

  • 2
    $\begingroup$ Mathematica says it's $\pi/2$, but the indefinite integral is a mess $\endgroup$
    – G. Gare
    Nov 22, 2023 at 11:58
  • 1
    $\begingroup$ It's not giving a result for this one $\endgroup$
    – G. Gare
    Nov 22, 2023 at 12:06
  • 2
    $\begingroup$ With $(u,v)=\left(\frac{1-\tan x}{1+\tan x}, \frac{1-\tan y}{1+\tan y}\right)$ we get another integral identity for $\pi$,$$\int_{-1}^1\int_{-1}^1\frac{1-u}{1+u^2}\,\frac{1-v}{1+v^2}\,\frac{du\,dv}{1-uv}=\pi$$Mathematica can compute this exactly, even over each quadrant. $\endgroup$
    – user170231
    Nov 22, 2023 at 18:55
  • 2
    $\begingroup$ I’m surprised nobody cited this video by Grant Sanderson: youtube.com/watch?v=851U557j6HE&t=0s or the related problem. It seems it is not your case, but sometimes what looks like a computer error in approximating integrals is actually true! $\endgroup$ Nov 22, 2023 at 22:37
  • 3
    $\begingroup$ You wrote "Desmos is not very reliable" but I think you meant "Desmos is extremely reliable and has an impressive precision of $10^{-8}$ on this integral" ;-) $\endgroup$
    – Stef
    Nov 24, 2023 at 9:31

6 Answers 6


$$I=\int_0^{\pi/2}\int_0^{\pi/2}\frac{(\tan\alpha)(\tan\beta)}{\tan\alpha+\tan\beta} d\alpha d\beta\overset{\binom{\alpha=\arctan x}{\beta=\arctan y}}{=}\int_0^\infty\int_0^\infty\frac{xy}{(1+x^2)(1+y^2)(x+y)}dxdy$$ $$=\int_0^\infty\int_0^\infty\left(\frac1{1+x^2}-\frac1{1+y^2}\right)\frac{xy}{x+y}\frac{dxdy}{y^2-x^2}$$ $$=2\int_0^\infty\int_0^\infty\frac1{1+x^2}\frac{xy}{x+y}\frac{dxdy}{y^2-x^2}\overset{x=ty}{=}2\int_0^\infty dy\int_0^\infty\frac{t\,dt}{(1+t^2y^2)(1-t)(1+t)^2}$$ $$=2\int_0^\infty\frac{t\,dt}{(1-t)(1+t)^2}\int_0^\infty\frac{dy}{1+t^2y^2}$$ $$=\pi\int_0^\infty\frac{dt}{(1-t)(1+t)^2}\overset{x=\frac1t}{=}-\pi\int_0^\infty\frac{x\,dx}{(1-x)(1+x)^2}$$ $$\Rightarrow\,\,2I=\pi\int_0^\infty\frac{dx}{(1+x)^2}\,\,\Rightarrow\,\,I=\frac\pi2$$

  • 1
    $\begingroup$ Can you comment on the singularity at $t=1$? I see you have sort of canceled it out in the penultimate step but how can you justify carrying it around? $\endgroup$
    – Ron Gordon
    Nov 22, 2023 at 13:34
  • 2
    $\begingroup$ @Ron Gordon, thank you for your question. Regarding the singularity: we are allowed to write the integral as $$\int_0^\infty\int_0^\infty\left(\frac1{1+x^2}-\frac1{1+y^2}\right)\frac{xy}{x+y}\frac{dxdy}{y^2-x^2}$$ $$=\int_0^\infty\int_0^\infty\frac1{1+x^2}\frac{xy}{x+y}\frac{dxdy}{y^2-x^2}-\int_0^\infty\int_0^\infty\frac1{1+y^2}\frac{xy}{x+y}\frac{dxdy}{y^2-x^2}$$ where every integral exists separately and is evaluated in the principal value sense. The last integral can be evaluated directly (also in the principal value sense) and gives $$\int_0^\infty\frac{dt}{(1-t)(1+t)^2}=\frac12$$ $\endgroup$
    – Svyatoslav
    Nov 22, 2023 at 15:08

A variant of Svyatoslav's solution, using polar coordinates $(x, y) = (r \cos \phi, r \sin\phi)$:

$$ \begin{align} I &=\int_0^{\pi/2}\int_0^{\pi/2}\frac{\tan\alpha \tan\beta}{\tan\alpha+\tan\beta} d\alpha d\beta \\ &=\int_0^\infty\int_0^\infty\frac{xy}{(x+y)(1+x^2)(1+y^2)}dxdy \\ &= \int_0^{\pi/2} \frac{\cos\phi \sin\phi}{\cos \phi + \sin\phi}\left( \int_0^\infty \frac{r^2}{(1+r^2 \cos^2\phi)(1+r^2\sin^2\phi)} \, dr \right) d\phi \, . \end{align} $$ For $ 0 < \phi < \pi/2$ the inner integral is $$ \begin{align} &\frac{1}{ \sin^2 \phi-\cos^2\phi } \int_0^\infty \left( \frac{1}{1+r^2 \cos^2 \phi)} - \frac{1}{1+r^2 \sin^2\phi}\right) dr \\ &\qquad = \frac{1}{ \sin^2 \phi-\cos^2\phi } \left[ \frac{\arctan(r \cos\phi)}{\cos \phi} - \frac{\arctan(r \sin\phi)}{\sin\phi}\right]_{r=0}^{r=\infty} \\ &\qquad = \frac{1}{\cos \phi \sin\phi (\cos\phi + \sin\phi)} \frac{\pi}{2} \, . \end{align} $$ It follows that $$ I = \frac{\pi}{2} \int_0^{\pi/2} \frac{1}{(\cos\phi + \sin\phi)^2} d\phi = \frac{\pi}{2} \left[ \frac{\sin \phi}{\cos\phi+\sin\phi}\right]_{\phi=0}^{\phi=\pi/2}= \frac{\pi}{2} \, . $$


Long comment

Related result: The expected length of one of the sides of the triangle (not the base) is

$$\frac{4}{\pi^2}\int_0^{\pi/2}\int_0^{\pi/2}\frac{\sin \beta}{\sin (\alpha+\beta)}d\alpha d{\beta}$$

$$=\frac{4}{\pi^2}\int_0^{\pi/2}\left[(\sin \beta)\log\left(\tan\left({\frac{\alpha+\beta}{2}}\right)\right)\right]_0^{\pi/2}d\beta$$

$$=\frac{4}{\pi^2}\int_0^{\pi/2}(\sin \beta)\log\left(\frac{\tan\left({\frac{\frac{\pi}{2}+\beta}{2}}\right)}{\tan\left({\frac{\beta}{2}}\right)}\right)d\beta$$

$$=\frac{4}{\pi^2}\left[\beta-\log\left(\frac{\sin b}{2}\right)-(\cos\beta)\log \left(\frac{\cos\left(\frac{\beta}{2}\right)\left(\cot\left(\frac{\beta}{2}\right)+1\right)}{\cos\left(\frac{\beta}{2}\right)-\sin\left(\frac{\beta}{2}\right)}\right)\right]_0^{\pi/2}$$

$$=\frac{2\pi+\log 16}{\pi^2}$$

(with help from Wolfram)


The first antiderivative is quite simple.

After solving the inner integral, we are left with:

$$\int \sin (b) \left(\frac{1}{2} \pi \cos (b)+\sin (b) \,\log (\tan (b))\right)\,db$$ Now, there is a quite nasty antiderivative.

Using the bounds, the first term is $\frac \pi 4$.

So, for the total, $$I=\frac \pi 4+ \frac{1}{16} (4+i \pi ) \pi-i\frac{ \pi ^2}{16}=\frac \pi 2$$


$$I=\int \frac{\tan (a) \tan (b)}{\tan (a)+\tan (b)}\, da$$ $$I=\sin (b) (a \cos (b)-\sin (b) \log (\sin (a+b)))$$ Using the bounds, the integral written at the top.

$$J=\int \sin ^2(b) \log (\tan (b))\,db$$ $$J=\frac{1}{2} i \text{Li}_2\left(e^{2 i b}\right)-\frac{1}{8} i \text{Li}_2\left(e^{4 i b}\right)+\frac{b}{2}+b \tanh ^{-1}\left(e^{2 i b}\right)+$$ $$\frac{1}{2} b \log (\tan (b))-\frac{1}{4} \sin (2 b) \log (\tan (b))$$

Now, use the bounds.

  • 1
    $\begingroup$ "The required antiderivatives are quite simple....A nasty antiderivative." Is it simple, or is it nasty? It can't be both, can it? $\endgroup$ Nov 23, 2023 at 5:30
  • 1
    $\begingroup$ @GerryMyerson. Thnaks for pointing ! The first one is simple. $\endgroup$ Nov 23, 2023 at 5:47

$$\frac{\tan(\alpha)\tan(\beta)}{\tan(\alpha)+ \tan(\beta)}= -\cot(\alpha+ \beta) +\frac{1}{\tan(\alpha)+ \tan(\beta)}$$

$$\displaystyle I:=\int _0^{\frac{\pi}2}\int _0^{\frac{\pi}2}\frac{\tan(\alpha)\tan(\beta)}{\tan(\alpha)+ \tan(\beta)} d \alpha d \beta=\int _0^{\frac{\pi}2}\int _0^{\frac{\pi}2}-\cot(\alpha+ \beta) +\frac{1}{\tan(\alpha)+ \tan(\beta)} d \alpha d \beta$$


for $\displaystyle \int \frac{1}{\tan x+ c}dx$ let $\tan x = t $ then $$\int \frac{1}{\tan x+ c}dx= \int \frac{1}{(t^2+1)(t+c)}dt$$ $$=\frac{c}{c^2+1}\int\frac{1}{1+t^2} dt -\frac{1}{2(c^2+1)}\int \frac{2t}{t^2+1}dt + \frac{1}{c^2+1}\int\frac{1}{c+t} dt $$ $$\frac{c}{c^2+1} \arctan(t) - \frac{1}{2(c^2+1)}\ln|t^2+1| +\frac{1}{c^2+1} \ln|t+c|$$ $$=\frac{c}{c^2+1} x +\frac{1}{(c^2+1)}\ln|\cos(x)| +\frac{1}{c^2+1} \ln|\tan(x)+c|$$ $\\[3pt]$ $$I=\int _0^{\frac{\pi}2} \biggr|-\ln|\sin(\alpha + \beta)| + \frac{\tan(\beta)}{\sec^2(\beta)} \alpha +\frac{1}{(\sec^2(\beta))}\ln|\cos(\alpha)| +\frac{1}{\sec^2(\beta)} \ln|\tan(\alpha)+\tan(\beta)|\biggr|_0 ^{\frac{\pi}{2}} d\beta$$ $$=\int _0^{\frac{\pi}2} \ln|\tan(x)| +\frac{\pi}{4}\sin(2\beta )+ \cos^2(\beta )(-\ln(\tan(\beta))) d\beta$$

first we can see that $\displaystyle \int _0 ^ \frac{\pi}{2}\ln(\tan(\alpha)) d\alpha= \int _{0}^ \frac{\pi}{2} \ln ( \cot \alpha)du =0 $ because $\displaystyle \int _0 ^ \frac{\pi}{2}\ln(\tan(\alpha)) d\alpha =-\int _0 ^ \frac{\pi}{2}\ln(\tan(\alpha)) d\alpha$ by king's rule

and $\displaystyle \int_0^{\frac{\pi}{2}} \sin(2\beta) d \beta =-\frac{\cos(2\beta)}{2} \biggr|_0^{\frac{\pi}{2}} = 1$ so that means $$I = \frac{\pi}{4} - \int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\tan(\beta)) d\beta$$

$$J:=\int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\tan(\beta)) d\beta=\int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\sin(\beta)) d\beta-\int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\cos(\beta)) d\beta $$

$$=\int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\sin(\beta)) d\beta+\int _0^{\frac{\pi}{2}}\ln(\cos(\beta)) (1-\cos^2(\beta)) d\beta -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$

since $\displaystyle \int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\sin(\beta)) d\beta=\int _0^{\frac{\pi}{2}}\ln(\cos(\beta)) (\sin^2(\beta)) d\beta$ by king's rule so

$$J = 2\int _0^{\frac{\pi}{2}}\cos^2(\beta)\ln(\sin(\beta)) d\beta-\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$

let $\displaystyle y= \sin(\beta)$

$$=2\int _0^{1}\ln(y)\sqrt{1-y^2}dy -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$ here I will use integration by parts and integrate $\sqrt{1-y^2} $ $$J=y \ln(y)\sqrt{1-y^2} +\arcsin(y)\ln(y)\biggr|_0^1 -\int_0^1 \sqrt{1-y^2} dy - \int_0^1 \frac{\arcsin{y}}{y} dy -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$

since $\displaystyle \lim\limits_{y \to 0}y \ln (y) =0$(why ? use L'Hôpital's rule) and $\lim\limits_{y \to 0}\arcsin{y} \ln (y) =0$(why ? substitute $\sin(t) = x$ and use L'Hôpital's rule )

and since $\displaystyle \int _0 ^1 \sqrt{1-y^2} dy = \frac{\pi}{4}$

$$J= -\frac{\pi}{4 } + \int_0^1 \frac{\arcsin{y}}{y} dy -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$ $$-\frac{\pi}{4 } -\int _0^{\frac{\pi}{2}} \beta \cot(\beta) d\beta -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$ $$=-\frac{\pi}{4 } - \beta \ln(\sin ( \beta))\biggr|_{0}^{\frac{\pi}{2}} +\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta -\int _0^{\frac{\pi}{2}} \ln(\cos(\beta)) d\beta $$

$$= -\frac{\pi}{4 }$$

so $$\color{red}{I = \frac{\pi}{4} -J =\frac{\pi }{2}}$$


Expanding on an earlier comment: let $(u,v)=\left(\dfrac{1-\tan \alpha}{1+\tan \alpha}, \dfrac{1-\tan \beta}{1+\tan \beta}\right)$, i.e. $(\alpha,\beta) = \left(\dfrac\pi4-\arctan u,\dfrac\pi4-\arctan v\right)$, to rewrite the integral as

$$\begin{align*} I &= \int_0^{\tfrac\pi2} \int_0^{\tfrac\pi2} \frac{\tan \alpha \tan \beta}{\tan \alpha + \tan\beta} \, d\alpha\,d\beta \\ &= \frac12 \int_{-1}^1 \int_{-1}^1 \frac{\frac{1-u}{1+u} \cdot \frac{1-v}{1+v}}{\frac{1-u}{1+u} + \frac{1-v}{1+v}} \, \frac{du}{1+u^2} \, \frac{dv}{1+v^2} \\ &= \frac12 \underbrace{\int_{-1}^1 \int_{-1}^1 \frac{1-u}{1+u^2} \, \frac{1-v}{1+v^2} \, \frac{du\,dv}{1-uv}}_{=\pi} \end{align*}$$

The inner integral is elementary:

$$\begin{align*} & \int_{-1}^1 \frac{1-u}{1+u^2} \, \frac{du}{1-uv} \\ &= \frac{1+v}{1+v^2} \int_{-1}^1 \frac{du}{1+u^2} + \frac{1-v}{1+v^2} \int_{-1}^1 \frac{u}{1+u^2} \, du - \frac{v(1-v)}{1+v^2} \int_{-1}^1 \frac{du}{1-uv} \\ &= \frac\pi2 \frac{1+v}{1+v^2} - 2 \frac{1-v}{1+v^2} \operatorname{artanh}v \end{align*}$$

and we're left with

$$\begin{align*} & \frac\pi2 \int_{-1}^1 \frac{1-v^2}{\left(1+v^2\right)^2} \, dv - 2 \int_{-1}^1 \frac{(1-v)^2}{\left(1+v^2\right)^2} \operatorname{artanh} v \, dv \\ &= \frac\pi2 + \underbrace{\int_{-1}^1 \frac{(1-v)^2}{\left(1+v^2\right)^2} \log \frac{1-v}{1+v} \, dv}_{=:J} \end{align*}$$

Showing $J=\dfrac\pi2$ can be done by enforcing $v\mapsto\dfrac{1-v}{1+v}$, folding up the subsequent integral at $v=1$ and expanding into partial fractions, exploiting power series, and integrating by parts:

$$\begin{align*} J &= 2 \int_0^\infty \frac{\left(1-\frac{1-v}{1+v}\right)^2}{\left(1+\frac{(1-v)^2}{(1+v)^2}\right)^2} \log v \, \frac{dv}{(1+v)^2} \\ &= 2 \int_0^\infty \frac{v^2}{\left(1+v^2\right)^2} \log v \, dv \\ &= 2 \int_0^1 \left(\frac1{1+v^2} - \frac2{\left(1+v^2\right)^2}\right) \log v \, dv \\ &= 2 \sum_{n\ge0} (-1)^{n+1} (2n+1) \int_0^1 v^{2n} \log v \, dv \\ &= 2 \sum_{n\ge0} \frac{(-1)^n}{2n+1} = 2\arctan 1 = \frac\pi2 \end{align*}$$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .