TITLE: A problem about parametric integral
QUESTION [6 upvotes]: How to solve the following integral.
$I(\theta) = \int_0^{\pi}\ln(1+\theta \cos x)dx$ where $|\theta|<1$

REPLY [4 votes]: Note that the integrand always changes sign at $x=\frac\pi2$ for $\theta\ne0$.
In fact, this is an even, nonpositive function,
since $\cos(\pi-x)=-\cos x$ and since, for $r=\theta\cos x$,
$|r|<1$ and $\ln(1+r)+$ $\ln(1-r)=$ $\ln(1-r^2)<0$ $\implies$
$$
\eqalign{
\int_0^\pi~\ln\big(1+\theta\,\cos\,x\big)\;dx         &=
\int_0^\frac\pi2~\ln\big(1+\theta\cos x\big)\;dx   +
\int_\frac\pi2^\pi~\ln\big(1+\theta\cos x\big)\;dx \\ &=
\int_0^\frac\pi2~\ln\big(1-\theta^2\cos^2 x\big)\;dx
\le 0
\,,
}
$$
with equality iff $\theta=0$.
Out of perverse curiosity, let us define, slightly more generally
(substituting $a$ for 1, $b$ for $\theta$ and $\theta$ for $x$)
$$
I(a,b)=\int_0^\pi\ln\big(a+b\cos\theta\big)\;d\theta.
$$
Then
$$
\frac{\partial I}{\partial b}
=\int_0^\pi \frac{\cos\theta\,d\theta}{a+b\cos\theta}
=\frac{\pi}{b}-\frac{a}b\int_0^\pi\frac{d\theta}{a+b\cos\theta}
\qquad
\text{since}
\qquad
   \frac{b\cos\theta}{a+b\cos\theta}
=1-\frac{a          }{a+b\cos\theta}
.
$$
But (thanks to Ragib Zaman):
$$
\eqalign{\frac\pi{a} - \frac{b}{a} \, \frac{\partial I}{\partial b}
  & = \int_0^\pi \frac{d\theta}{a+b\cos{\theta}}
\\& = \int_0^\pi \frac{d\theta}
      {a\left(\sin^2\frac\theta2+\cos^2\frac\theta2\right)
      +b\left(\cos^2\frac\theta2-\sin^2\frac\theta2\right)}
\\& = \int_0^\pi \frac{d\theta}
      {(a-b)\sin^2\frac\theta2+(a+b)\cos^2\frac\theta2}
\\& = \int_0^\pi \frac{\sec^2\frac\theta2\;d\theta}
      {(a+b)+(a-b)\tan^2\frac\theta2}
\\& = 2\int_0^\infty \frac{dt}{(a+b)+(a-b)t^2}
\\& = 2\int_0^\infty \frac{dt}{(\sqrt{a+b})^2+(\sqrt{a-b})^2t^2}
\\& = \frac{2}{{\sqrt{a^2-b^2}}}~
      \left.\tan^{-1}
        \left(
          \frac{\sqrt{a-b}}{\sqrt{a+b}}~t
        \right)
      \right|_{0}^{\infty} \\& = \frac{\pi}{\sqrt{a^2-b^2}}
}
$$
so that
$$
\frac{\partial I}{\partial b} =
\frac\pi{b} \left( 1-\frac{a}{\sqrt{a^2-b^2}} \right)
$$
or
$$
I(a,b)
= \pi \int \frac{db}{b}
- \pi a \int \frac{db}{b \sqrt{a^2-b^2}}
\,.
$$
For $a>|b|>0$, we can use the substitution
$b=a\sin\phi,~db=a\cos\phi\,d\phi$ to continue thus:
$$
\eqalign{
I(a,b)&=\pi\ln|b| - \pi a \int \frac{d\phi}{\sin\phi}
\\    &=\pi\ln|b| - \pi a \int \csc\phi ~d\phi
\\    &=\pi\ln|b| + \pi a ~\ln\, \big| \csc\phi + \cot\phi \big| + c
\\    &=\pi\ln|b| + \pi a ~\ln\, \left| \frac{1+\cos\phi}{\sin\phi} \right| + c
\\    &=\pi\ln|b| + \pi a ~\ln\, \left|
                                \frac{a}{b} +\sqrt{\left(
                                \frac{a}{b}       \right)^2-1}
                               \right| + c
\,.
}
$$
Using $I(a,0)=\pi\,\ln a$,
we find that $c$ depends on a limit
which exists and is $\ln2$ iff $a=1$,
$$
\frac{\pi\ln a-c}{a}
=\lim_{b\rightarrow0}\,\ln
\left|
  \frac{
     \frac{a}{b} +\sqrt{\left(
     \frac{a}{b}       \right)^2-1}
  }{|b|^{-1/a}}
\right|
=\lim_{b\rightarrow0}\,\ln
\left|
  b^{1/a-1}
  \left(
     a+\sqrt{a^2-b^2}
  \right)
\right|
$$
in which case $c=-\pi\ln2$.
So for our original problem,
$$
\int_0^\pi~\ln\big(1+\theta\,\cos\,x\big)\;dx=I(1,\theta)
= \pi \ln\frac{1+\sqrt{1-\theta^2}}{2}
\,.
$$
As already noted, this exists and
is nonpositive for $|\theta|<1$.
On the other hand we see from the RHS above
that the integral is bounded below by
$-\pi\ln2\approx-2.17758609030360$.
Here is a plot of the solution using sage,
with the factor of $\pi$ removed (in blue),
and a comparable function (in red)
from an earlier erroneous draft:
var('t')
#assume(t != 0)
G = plot(log( (1 + sqrt(1-t^2)) / 2 ), (t, -1, 1), color='blue')
G+= text('log((1 + sqrt(1-t^2)) / 2)', (-.6,-.65), color='blue')
G+= plot(      1 - arcsin(t)/t       , (t, -1, 1), color='red')
G+= text(     '1 - arcsin(t)/t'      , (.85,-.06), color='red')
G#.show(aspect_ratio=1)


In particular, the graph has a minimum
of $-\ln2\approx-0.693147180559945$
at $\theta=\pm1$.
To check the endpoint, I computed an approximate numerical integral, which agrees with the above (the tuple gives the integral and error estimates):
numerical_integral(2*log(sin(x)), 0, pi/2)


$\left(-2.17758608788, 1.09713268507 \times 10^{-06}\right)$