% Cleo bench — shared template for derivation documents.
% Replace <<TITLE>>, <<QID>>, <<N>> and the body. Keep the preamble as-is unless
% a document genuinely needs another package.
\documentclass[11pt]{article}
\usepackage[a4paper,margin=2.7cm]{geometry}
\usepackage{amsmath,amssymb,amsthm,mathtools}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=blue!50!black,urlcolor=blue!50!black]{hyperref}
\allowdisplaybreaks

\newtheorem{lemma}{Lemma}
\newtheorem{proposition}{Proposition}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}

\title{Cleo Bench Problem 4\\[1ex]\large Evaluate $\int_0^{\pi/2}\frac{x^2\log^2{(\sin{x})}}{\sin^2x}dx$}
\author{Derivation by Claude (Fable 5), closed-book\thanks{Problem originally
posed on Mathematics Stack Exchange
(\href{https://math.stackexchange.com/q/1142705}{question 1142705}, CC BY-SA),
famously answered by user Cleo. This derivation was produced independently,
offline, without access to the published answer, as part of the Cleo benchmark.}}
\date{July 2026}

\begin{document}
\maketitle

\section*{Problem}

Evaluate in closed form
$$I \;=\; \int_0^{\pi/2}\frac{x^2\log^2(\sin x)}{\sin^2 x}\,dx .$$

(The original post supplies the companion value
$\displaystyle\int_0^{\pi/2}\frac{x^2\log(\sin x)}{\sin^2x}\,dx=\pi\ln 2-\frac{\pi}{2}\ln^2 2-\frac{\pi^3}{12}$;
we re-derive this from scratch along the way rather than assuming it.)

\section*{Result}

$$\boxed{\;I \;=\; \frac{\pi\,\zeta(3)}{8}\;+\;\frac{\pi^{3}\ln 2}{6}\;+\;\frac{\pi\ln^{3}2}{3}\;+\;2\pi\ln 2\;-\;\pi\ln^{2}2\;-\;\frac{\pi^{3}}{6}\;}$$

equivalently $I=\dfrac{\pi\zeta(3)}{8}+\dfrac{\pi^{3}}{6}\bigl(\ln 2-1\bigr)+\dfrac{\pi\ln^{3}2}{3}-\pi\ln^{2}2+2\pi\ln 2$. Numerically,

$$I = 2.08084652714326246266849090286004549406212100731588547858680778590266\ldots$$

\section*{Derivation}

Throughout, $\log=\ln$ is the natural logarithm. All integrands below are continuous on $(0,\pi/2]$; the only issue is the endpoint $x=0$, where $x/\sin x\to 1$, so the integrand of $I$ behaves like $\log^2 x$, which is absolutely integrable. Hence $I$ converges (absolutely; the integrand is $\ge 0$).

\subsection*{Step 1. Integration by parts}

On $[\varepsilon,\pi/2]$ integrate by parts with
$$\begin{gathered}
u=x^{2}\log^{2}(\sin x),\qquad dv=\frac{dx}{\sin^{2}x},\qquad v=-\cot x,\\
du=\Bigl(2x\log^{2}\sin x+2x^{2}\cot x\,\log\sin x\Bigr)dx .
\end{gathered}$$
The boundary term is $\bigl[-x^{2}\log^{2}(\sin x)\cot x\bigr]_{\varepsilon}^{\pi/2}$. At $x=\pi/2$ it vanishes because $\cot(\pi/2)=0$ (and $\log\sin(\pi/2)=0$); as $\varepsilon\to0^{+}$,
$$\varepsilon^{2}\log^{2}(\sin\varepsilon)\,\cot\varepsilon\;\sim\;\varepsilon\,\log^{2}\varepsilon\;\longrightarrow\;0 .$$
The two integrals produced converge absolutely (near $0$: $x\cot x\log^{2}\sin x\sim\log^{2}x$ and $x^{2}\cot^{2}x\log\sin x\sim\log x$), so letting $\varepsilon\to0^{+}$,
$$I \;=\; 2\underbrace{\int_0^{\pi/2}x\cot x\,\log^{2}(\sin x)\,dx}_{=:K}\;+\;2\int_0^{\pi/2}x^{2}\cot^{2}x\,\log(\sin x)\,dx .$$
Using $\cot^{2}x=\csc^{2}x-1$ and the (separate, absolute) convergence of both pieces,
$$\int_0^{\pi/2}x^{2}\cot^{2}x\log\sin x\,dx \;=\; \underbrace{\int_0^{\pi/2}\frac{x^{2}\log\sin x}{\sin^{2}x}\,dx}_{=:J}\;-\;\underbrace{\int_0^{\pi/2}x^{2}\log\sin x\,dx}_{=:M},$$
so that
\begin{equation}I \;=\; 2K+2J-2M. \tag{1}\end{equation}

We now compute $K$, $J$, $M$ exactly.

\subsection*{Step 2. A master formula: differentiating the Wallis integral}

For $\Re s>-1$ define
$$W(s):=\int_0^{\pi/2}\sin^{s}x\,dx .$$
Substituting $t=\sin^{2}x$ (so $dx=\tfrac12 t^{-1/2}(1-t)^{-1/2}dt$) gives a Beta integral:
\begin{equation}W(s)=\frac12\int_0^{1}t^{\frac{s-1}{2}}(1-t)^{-\frac12}\,dt=\frac12 B\!\Bigl(\frac{s+1}{2},\frac12\Bigr)
=\frac{\sqrt{\pi}\;\Gamma\!\bigl(\frac{s+1}{2}\bigr)}{2\,\Gamma\!\bigl(\frac{s}{2}+1\bigr)} . \tag{2}\end{equation}

Next, for $s\in(-1,\infty)$ set
$$F(s):=\int_0^{\pi/2}x\cot x\,\sin^{s}x\,dx
=\int_0^{\pi/2}x\cos x\,\sin^{s-1}x\,dx ,$$
which converges absolutely (the integrand is $\sim x^{s}$ at $0$). Since $\frac{d}{dx}\sin^{s}x=s\cos x\sin^{s-1}x$, integration by parts on $[\varepsilon,\pi/2]$ gives
$$s\int_\varepsilon^{\pi/2}x\cos x\,\sin^{s-1}x\,dx=\Bigl[x\sin^{s}x\Bigr]_\varepsilon^{\pi/2}-\int_\varepsilon^{\pi/2}\sin^{s}x\,dx .$$
As $\varepsilon\to0^{+}$ the boundary term $\varepsilon\sin^{s}\varepsilon\sim\varepsilon^{1+s}\to0$ (as $s>-1$), and all integrals converge, so
\begin{equation}s\,F(s)\;=\;\frac{\pi}{2}-W(s),\qquad s\in(-1,\infty) \tag{3}\end{equation}
(at $s=0$ both sides vanish, by $W(0)=\pi/2$).

\textbf{Smoothness of $F$ and differentiation under the integral.} Fix $0<\sigma<\tfrac12$. For $|s|\le\sigma$ and $m\in\{0,1,2,3\}$,
$$\Bigl|x\cot x\,\sin^{s}x\,\log^{m}\sin x\Bigr|\;\le\;\sin^{-\sigma}x\;\bigl|\log\sin x\bigr|^{m},$$
because $0<\sin x\le 1$ makes $s\mapsto\sin^{s}x$ bounded by $\sin^{-\sigma}x$ for $s\ge-\sigma$, and $x\cot x\le 1$ on $(0,\pi/2)$ (since $\tan x\ge x$). By concavity $\sin x\ge\frac{2}{\pi}x$ on $[0,\pi/2]$, so the dominating function is $\le C\,x^{-\sigma}\bigl(|\log x|+c\bigr)^{m}$ near $0$, which is integrable. Hence, by the standard theorem on differentiation under the integral sign (mean value theorem + dominated convergence, applied repeatedly), $F\in C^{3}\bigl((-\sigma,\sigma)\bigr)$ with
\begin{equation}F^{(m)}(0)=\int_0^{\pi/2}x\cot x\,\log^{m}(\sin x)\,dx,\qquad m=0,1,2. \tag{4}\end{equation}

\textbf{Matching Taylor coefficients.} $W$ is real-analytic in a neighbourhood of $s=0$ (by (2): both Gamma arguments are near $\tfrac12$ and $1$, away from poles), and $W(0)=\pi/2$; hence
$$G(s):=\frac{\pi/2-W(s)}{s}$$
extends to a real-analytic function near $0$. By (3), $F=G$ on a punctured neighbourhood of $0$, and both are continuous at $0$, so $F\equiv G$ near $0$; consequently
\begin{equation}F(0)=G(0),\qquad F'(0)=G'(0),\qquad F''(0)=G''(0), \tag{5}\end{equation}
i.e. the integrals (4) are read off from the Taylor expansion of $W$ at $s=0$.

\subsection*{Step 3. Gamma-function input}

We use the Weierstrass product $\dfrac{1}{\Gamma(z)}=z e^{\gamma z}\prod_{n\ge1}\bigl(1+\tfrac zn\bigr)e^{-z/n}$, whose logarithmic derivative gives
$$\psi(z)=\frac{\Gamma'(z)}{\Gamma(z)}=-\gamma+\sum_{n\ge0}\Bigl(\frac{1}{n+1}-\frac{1}{n+z}\Bigr),
\qquad
\psi^{(m)}(z)=(-1)^{m+1}m!\sum_{n\ge0}\frac{1}{(n+z)^{m+1}}\;(m\ge1),$$
the series for $\psi^{(m)}$ obtained by termwise differentiation (uniform convergence on compacta avoiding the poles). Therefore:

\begin{itemize}
\item $\psi(1)=-\gamma$.
\item $\psi(1/2)$: the partial sum $\sum_{n=0}^{N-1}\bigl(\frac{1}{n+1}-\frac{2}{2n+1}\bigr)=H_N-(2H_{2N}-H_N)=2H_N-2H_{2N}\to-2\ln2$ (by $H_N=\ln N+\gamma+o(1)$), so $\psi(1/2)=-\gamma-2\ln 2$.
\item $\psi'(1)=\zeta(2)=\frac{\pi^{2}}{6}$, and $\psi'(1/2)=\sum_{n\ge0}\frac{1}{(n+\frac12)^{2}}=4\sum_{n\ge0}\frac{1}{(2n+1)^{2}}=4\bigl(1-\tfrac14\bigr)\zeta(2)=\frac{\pi^{2}}{2}$.
\item $\psi''(1)=-2\zeta(3)$, and $\psi''(1/2)=-2\sum_{n\ge0}\frac{1}{(n+\frac12)^{3}}=-16\bigl(1-\tfrac18\bigr)\zeta(3)=-14\zeta(3)$.
\end{itemize}

(Here $\zeta(2)=\pi^2/6$ is Euler's classical evaluation; the odd-index sums use $\sum_{\text{odd }m}m^{-p}=(1-2^{-p})\zeta(p)$.)

Write $W(s)=\frac{\pi}{2}e^{u(s)}$ with
$$u(s)=\ln\Gamma\Bigl(\frac{s+1}{2}\Bigr)-\ln\Gamma\Bigl(\frac{s}{2}+1\Bigr)-\frac12\ln\pi,\qquad u(0)=0 .$$
Then
$$\begin{aligned}
&u'(0)=\tfrac12\bigl[\psi(\tfrac12)-\psi(1)\bigr]=-\ln 2,\qquad
u''(0)=\tfrac14\bigl[\psi'(\tfrac12)-\psi'(1)\bigr]=\frac{\pi^{2}}{12},\\
&u'''(0)=\tfrac18\bigl[\psi''(\tfrac12)-\psi''(1)\bigr]=-\frac{3\zeta(3)}{2}.
\end{aligned}$$
Exponentiating the cubic Taylor polynomial ($e^{u}=1+u+\frac{u^{2}}{2}+\frac{u^{3}}{6}+\cdots$):
\begin{equation}W(s)=\frac{\pi}{2}\Bigl[1-\ln 2\;s+\Bigl(\frac{\pi^{2}}{24}+\frac{\ln^{2}2}{2}\Bigr)s^{2}
-\Bigl(\frac{\zeta(3)}{4}+\frac{\pi^{2}\ln 2}{24}+\frac{\ln^{3}2}{6}\Bigr)s^{3}+O(s^{4})\Bigr], \tag{6}\end{equation}
where the $s^3$-coefficient is $\frac{1}{6}\bigl(u'''(0)+3u'(0)u''(0)+u'(0)^{3}\bigr)$.

\subsection*{Step 4. The three moments of $x\cot x$}

From (6),
$$G(s)=\frac{\pi/2-W(s)}{s}
=\frac{\pi}{2}\Bigl[\ln 2-\Bigl(\frac{\pi^{2}}{24}+\frac{\ln^{2}2}{2}\Bigr)s
+\Bigl(\frac{\zeta(3)}{4}+\frac{\pi^{2}\ln 2}{24}+\frac{\ln^{3}2}{6}\Bigr)s^{2}+O(s^{3})\Bigr],$$
so by (4)--(5):
\begin{equation}\int_0^{\pi/2}x\cot x\,dx=\frac{\pi\ln 2}{2}, \tag{7}\end{equation}
\begin{equation}\int_0^{\pi/2}x\cot x\,\log\sin x\,dx=-\frac{\pi^{3}}{48}-\frac{\pi\ln^{2}2}{4}, \tag{8}\end{equation}
\begin{equation}K=\int_0^{\pi/2}x\cot x\,\log^{2}\sin x\,dx
=2!\cdot\frac{\pi}{2}\Bigl(\frac{\zeta(3)}{4}+\frac{\pi^{2}\ln 2}{24}+\frac{\ln^{3}2}{6}\Bigr)
=\frac{\pi\zeta(3)}{4}+\frac{\pi^{3}\ln 2}{24}+\frac{\pi\ln^{3}2}{6}. \tag{9}\end{equation}

\subsection*{Step 5. The elementary companions, and the hinted integral $J$}

Integrating by parts exactly as in Step 1 (boundary terms vanish by the same estimates):

\begin{itemize}
\item With $u=x^{2}$: $\displaystyle\int_0^{\pi/2}\frac{x^{2}}{\sin^{2}x}\,dx
=\Bigl[-x^{2}\cot x\Bigr]_0^{\pi/2}+2\int_0^{\pi/2}x\cot x\,dx
\overset{(7)}{=}\pi\ln 2$, hence
\begin{equation}\int_0^{\pi/2}x^{2}\cot^{2}x\,dx=\pi\ln 2-\int_0^{\pi/2}x^{2}dx=\pi\ln 2-\frac{\pi^{3}}{24}. \tag{10}\end{equation}

\item With $u=x^{2}\log\sin x$ (boundary term $\sim x\log x\to0$ at $0$):
\begin{equation}\begin{aligned}
J=\int_0^{\pi/2}\frac{x^{2}\log\sin x}{\sin^{2}x}\,dx
&=2\int_0^{\pi/2}x\cot x\log\sin x\,dx+\int_0^{\pi/2}x^{2}\cot^{2}x\,dx\\
&\overset{(8),(10)}{=}\pi\ln 2-\frac{\pi\ln^{2}2}{2}-\frac{\pi^{3}}{12}.
\end{aligned}\tag{11}\end{equation}
\end{itemize}

This reproduces the value quoted in the problem statement, confirming the machinery.

\subsection*{Step 6. $M=\displaystyle\int_0^{\pi/2}x^{2}\log\sin x\,dx$ via the Fourier series of $\log(2\sin x)$}

For $0<x<\pi$,
$$1-e^{2ix}=-2i\sin x\,e^{ix}=2\sin x\;e^{i(x-\pi/2)},$$
and since $2\sin x>0$, $x-\frac{\pi}{2}\in(-\frac{\pi}{2},\frac{\pi}{2})$, the principal logarithm satisfies
$$\operatorname{Log}\bigl(1-e^{2ix}\bigr)=\log(2\sin x)+i\Bigl(x-\frac{\pi}{2}\Bigr).$$
The series $-\sum_{k\ge1}z^{k}/k$ converges for $|z|=1$, $z\ne1$ (Dirichlet's test, as the partial sums of $\sum z^{k}$ are bounded), and by Abel's theorem its value is $\lim_{r\to1^{-}}\bigl(-\operatorname{Log}(1-rz)\bigr)=-\operatorname{Log}(1-z)$; the limit uses continuity of $\operatorname{Log}$ on the right half-plane, where $1-rz$ stays for $0\le r\le1$ because $\Re z<1$. Taking real parts at $z=e^{2ix}$:
\begin{equation}\log(2\sin x)=-\sum_{k=1}^{\infty}\frac{\cos 2kx}{k}\qquad\text{pointwise on }(0,\pi). \tag{12}\end{equation}

\textbf{Termwise integration against $x^{2}$.} On $(0,\pi)$ the system $\{\cos 2kx\}_{k\ge1}$ is orthogonal with $\|\cos 2kx\|_{L^{2}}^{2}=\pi/2$; since $\sum k^{-2}<\infty$, the partial sums $S_N(x)=\sum_{k\le N}\frac{\cos2kx}{k}$ form a Cauchy sequence in $L^{2}(0,\pi)$ and converge to some $f\in L^{2}$. A subsequence converges a.e. to $f$; by (12) the full sequence converges pointwise to $-\log(2\sin x)$, so $f=-\log(2\sin x)$ a.e. With $\phi=x^{2}\chi_{(0,\pi/2)}\in L^{2}(0,\pi)$, Cauchy--Schwarz gives
$$\int_0^{\pi/2}x^{2}S_N(x)\,dx\;\longrightarrow\;-\int_0^{\pi/2}x^{2}\log(2\sin x)\,dx .$$
The cosine moments are elementary: differentiating $\frac{x^{2}\sin 2kx}{2k}+\frac{x\cos 2kx}{2k^{2}}-\frac{\sin 2kx}{4k^{3}}$ returns $x^{2}\cos 2kx$, and evaluating between $0$ and $\pi/2$ (where $\sin k\pi=0$, $\cos k\pi=(-1)^{k}$),
$$\int_0^{\pi/2}x^{2}\cos 2kx\,dx=\frac{(-1)^{k}\pi}{4k^{2}} .$$
Hence
$$\int_0^{\pi/2}x^{2}S_N\,dx=\frac{\pi}{4}\sum_{k\le N}\frac{(-1)^{k}}{k^{3}}\;\longrightarrow\;
-\frac{\pi}{4}\eta(3)=-\frac{\pi}{4}\cdot\frac{3}{4}\zeta(3)=-\frac{3\pi\zeta(3)}{16},$$
using $\eta(3)=\sum_{k\ge1}(-1)^{k-1}k^{-3}=(1-2^{-2})\zeta(3)$ (split even/odd indices). Therefore
\begin{equation}\int_0^{\pi/2}x^{2}\log(2\sin x)\,dx=\frac{3\pi\zeta(3)}{16},
\qquad
M=\frac{3\pi\zeta(3)}{16}-\ln 2\cdot\frac{\pi^{3}}{24}. \tag{13}\end{equation}

\subsection*{Step 7. Assembly}

Insert (9), (11), (13) into (1):
$$\begin{aligned}
I&=2K+2J-2M\\[2pt]
&=\Bigl(\frac{\pi\zeta(3)}{2}+\frac{\pi^{3}\ln 2}{12}+\frac{\pi\ln^{3}2}{3}\Bigr)
+\Bigl(2\pi\ln 2-\pi\ln^{2}2-\frac{\pi^{3}}{6}\Bigr)
-\Bigl(\frac{3\pi\zeta(3)}{8}-\frac{\pi^{3}\ln 2}{12}\Bigr)\\[4pt]
&=\;\frac{\pi\zeta(3)}{8}\;+\;\frac{\pi^{3}\ln 2}{6}\;+\;\frac{\pi\ln^{3}2}{3}\;+\;2\pi\ln 2\;-\;\pi\ln^{2}2\;-\;\frac{\pi^{3}}{6}.
\end{aligned}$$

$$\int_0^{\pi/2}\frac{x^{2}\log^{2}(\sin x)}{\sin^{2}x}\,dx
=\frac{\pi\zeta(3)}{8}+\frac{\pi^{3}\ln 2}{6}+\frac{\pi\ln^{3}2}{3}+2\pi\ln 2-\pi\ln^{2}2-\frac{\pi^{3}}{6}.$$

\section*{Numerical verification}

All computations with mpmath (scripts \texttt{check\_main.py}, \texttt{check\_digits.py}, \texttt{check\_gl.py} in the work directory
{\footnotesize\ttfamily /tmp/\allowbreak claude-\allowbreak 1000/\allowbreak -home-\allowbreak riv-\allowbreak Code-\allowbreak cleo-\allowbreak bench/\allowbreak 817bd907-\allowbreak 85a0-\allowbreak 4bc2-\allowbreak a728-\allowbreak b3544bb304b6/\allowbreak scratchpad/\allowbreak cleo/\allowbreak work/\allowbreak q1142705-\allowbreak evaluate-\allowbreak int-\allowbreak 0-\allowbreak pi-\allowbreak 2-\allowbreak frac-\allowbreak x-\allowbreak 2-\allowbreak log-\allowbreak 2-\allowbreak sin-\allowbreak x-\allowbreak sin-\allowbreak 2x/}).

\begin{itemize}
\item \textbf{Main integral, tanh--sinh quadrature, \texttt{mp.dps = 90},} split points $\{0,10^{-3},10^{-1},\pi/4,\pi/2\}$:
  \begin{itemize}
  \item direct integral:\\ {\footnotesize$2.08084652714326246266849090286004549406212100731588547858680778590265996293\ldots$}
  \item closed form:\\ {\footnotesize$2.08084652714326246266849090286004549406212100731588547858680778590265996293\ldots$}
  \item $|\,\text{difference}\,| = 4.9\times10^{-91}$ --- agreement to \textbf{90 significant digits} (full working precision).
  \end{itemize}
\item \textbf{Independent method:} Gauss--Legendre quadrature at \texttt{mp.dps = 60} on $[10^{-40},\pi/2]$ with geometric split points $10^{-40},10^{-39},\dots,10^{-1},\pi/4,\pi/2$, plus the analytic tail $\int_0^{\varepsilon}\log^{2}x\,dx=\varepsilon(\log^{2}\varepsilon-2\log\varepsilon+2)$ for $\varepsilon=10^{-40}$ (the neglected correction is $O(\varepsilon^{3}\log^{2}\varepsilon)\approx10^{-117}$): difference from the closed form $=0.0$ at 60-digit precision.
\item \textbf{Every intermediate identity was also checked numerically at 60 digits} (differences $0$ or $\lesssim10^{-61}$):
  $K$ from (9); (8); (7); $J$ from (11); $M$ from (13); $\int_0^{\pi/2}x^{2}\csc^{2}x\,dx=\pi\ln2$; and the master identity (3) at the off-center points $s=0.3$ (agreement $\sim10^{-61}$) and $s=-0.4$ (agreement $\sim10^{-39}$, limited only by quadrature near the $x^{s}$ endpoint singularity).
\end{itemize}

\section*{Notes}

\begin{itemize}
\item The derivation is complete and self-contained up to the following classical facts used without proof: the Beta--Gamma identity $B(a,b)=\Gamma(a)\Gamma(b)/\Gamma(a+b)$; the Weierstrass product for $\Gamma$ (equivalently, the partial-fraction series for $\psi$ and its derivatives); Euler's $\zeta(2)=\pi^{2}/6$; Abel's theorem on power series; and completeness of $L^{2}$ together with the fact that $L^{2}$-convergence yields an a.e.-convergent subsequence. All interchanges of limit and integral are justified in the text (dominated convergence with explicit dominating functions in Step 2; $L^{2}$/Cauchy--Schwarz in Step 6), and every improper integral and boundary term is handled by explicit asymptotics.
\item The identity (3) plus the expansion (6) is the engine of the solution: it delivers all moments $\int_0^{\pi/2}x\cot x\log^{m}\sin x\,dx$ at once, and in particular re-derives the value of $J$ quoted in the problem statement --- an internal consistency check on the method, independently confirmed numerically.
\item No caveats or gaps remain; the closed form is verified to 90 significant digits by two different quadrature schemes.
\end{itemize}

\end{document}
