# Evaluation of an integral using Mathematica or otherwise

I need to find a closed form (in terms of known functions) using Mathematica or otherwise of $$\Re\left(\int_{\frac{1}{2}}^{1}\frac{\tan^{-1}\left(\frac {1-x}{\sqrt{-i-x^2}}\right)}{\sqrt{-i-x^2}}\ dx\right)$$ where $$i=\sqrt{-1}$$ is the imaginary unit and $$\Re$$ denotes the real part. I tried a code on Wolfram cloud as Re[Integrate[ArcTan[(1-x)/(-x^2-I)^(1/2)]/(-x^2-I)^(1/2), {x, 1/2, 1}]] but did not get any result.

We also have a similar integral having a closed form $$\int\frac{\tan^{-1}\left(\frac {x}{\sqrt{-i-x^2}}\right)}{\sqrt{-i-x^2}}\ dx=\frac{1}{2}\left[\tan^{-1}\left(\frac {x}{\sqrt{-i-x^2}}\right)\right]^2 +C$$ Any help will be highly appreciated. Thank you!

• Why are you expecting a closed form to exist? Aug 11, 2023 at 21:02
• The sub x == Sqrt[I] Sinh[u] works... Aug 13, 2023 at 0:23
• @MichaelE2 Thanks. But $x\in\mathbb{R}$, and in your substitution $x\in\mathbb{C}$
– Max
Aug 13, 2023 at 5:44
• @Max why $x\in\mathbb C$? Michael didn't claim that $u\in\mathbb R$... Aug 13, 2023 at 14:13

Your expression is just a number. You can get its value to any desired precision using NIntegrate

int50 = Re[
NIntegrate[ArcTan[(1 - x)/(-x^2 - I)^(1/2)]/(-x^2 - I)^(1/2), {x, 1/2, 1},
WorkingPrecision -> 50]]

(* -0.041203512171872067789770454057244867140767910178258 *)


You can convert this value to an approximate Root expression using RootApproximant

inta = int50 // RootApproximant

(* Root[-8 - 194 # + 9 #^2 + 120 #^3 - 134 #^4 - 166 #^5 - 27 #^6 - 33 #^7 +
133 #^8 - 141 #^9 - 331 #^10 + 147 #^11 - 232 #^12 - 337 #^13 + 294 #^14 -
69 #^15 + 4 #^16& , 1, 0] *)


The error from the approximation is

int50 - inta

(* 2.4*10^-50 *)


For lower levels of precision the Root expression can be converted to a radical representation with ToRadicals

inta16 = int50 // N[#, 16] & // RootApproximant // ToRadicals

(* -(641/1548) - (401911 7^(2/3) (1 - I Sqrt[3]))/(
3096 (-334247855 + 1548 I Sqrt[143024447823])^(
1/3)) - ((1 + I Sqrt[3]) (7 (-334247855 + 1548 I Sqrt[143024447823]))^(
1/3))/3096 *)


This representation differs from the high precision result by

int50 - FullSimplify[inta16]

(* -2.055101683907310203909684997075172161*10^-15 *)


Note that the FullSimplify converted the radical representation back to a Root expression. This avoids any imaginary artifacts resulting from numeric evaluation of the radical representation. For example,

int50 - inta16

(* -2.055101683907310203909684997075172161*10^-15 + 0.*10^-68 I *)

• $(+1)$. But I am sorry, I need a closed form not a numerical value.
– Max
Aug 12, 2023 at 4:35

The numerical result is

 NIntegrate[ ArcTan[(1 - x)/(-x^2 - I)^(1/2)]/(-x^2 - I)^(1/2), {x, 1/2, 1}]

-0.0412035 + 0.105342 I

TraditionalForm[ Re[Integrate[ ArcTan[(1 - x)/(-x^2 - I)^(1/2)]/(-x^2 - I)^(1/2), {x, 1/2, 1}]]]


$$\Re\left(\int_{\frac{1}{2}}^1 \frac{\tan ^{-1}\left(\frac{1-x}{\sqrt{-x^2-i}}\right)}{\sqrt{-x^2-i}} \, dx\right)$$

We use the outer algebraic form as differential $$dy$$

$$\int \frac{dx}{\sqrt(x^2+ i)} = \int dy$$

  (\[Integrate[ 1 /Sqrt[x^2 + I] == y) /.
{ a_  Log[b_] + d_ Log[c_] :>  a Log[(b/c)] /; a + d == 0 } //
FullSimplify

2 y + Log[1 + 2 I x (-x + Sqrt[I + x^2])] == 0



solving for x and replacing in the argument by y

$$\text{PowerExpand}\left[\text{FullSimplify}\left[\tan ^{-1}\left(\frac{1-x}{\sqrt{-x^2-i}}\right)\text{/.}\, \left\{x\to \frac{1}{2} \sqrt[4]{-1} \sqrt{e^{-2 y}+e^{2 y}-2}\right\}\right]\right]$$

$$\tan ^{-1}\left(\sqrt[4]{-1} \left(1-\sqrt[4]{-1} \sinh (y)\right) \text{sech}(y)\right)$$

The indefinite integral is with resubstitution

   res = I Integrate[ArcTan[(-1)^(1/4) Sech[y] (1 - (-1)^(1/4) Sinh[y])],y] /.
{y :> -1/2 Log[1 + 2 I x (-x + Sqrt[I + x^2])]}

I (-(1/2) ArcTan[ Sech[1/2 Log[1 + 2 I x (-x + Sqrt[I + x^2])]] ((-1)^(1/4) +
I Sinh[1/2 Log[1 + 2 I x (-x + Sqrt[I + x^2])]])] Log[1 + 2 I x (-x + Sqrt[I + x^2])] +
1/8 (-2 \[Pi] ArcTanh[(1 + Sqrt[2]) Cot[ 1/4 (\[Pi] - I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]] -
4 \[Pi] ArcTanh[  Sqrt[2] + I Tanh[1/4 Log[1 + 2 I x (-x + Sqrt[I + x^2])]]] +
4 ArcTanh[(-1 + Sqrt[2]) Tan[  1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]] (\[Pi] +
I Log[1 + 2 I x (-x + Sqrt[I + x^2])]) +
1/2 I Log[ 1 + 2 I x (-x + Sqrt[I + x^2])]^2 - (\[Pi] -
8 I ArcTanh[(1 + Sqrt[2]) Cot[ 1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]]) Log[((1/2 +
I/2) ((-1 - I) + Sqrt[2]) (1 +
I Cot[1/4 (\[Pi] - I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]))/
(-1 +  Sqrt[2] +  Cot[1/4 (\[Pi] -   I Log[1 + 2 I x (-x + Sqrt[I + x^2])])])] -
(\[Pi] +   8 I ArcTanh[(1 + Sqrt[2]) Cot[  1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]]) Log[-(((1/
2 + I/2) ((-1 + I) + Sqrt[2]) (I +  Cot[1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]))/(-1 +
Sqrt[2] +
Cot[1/4 (\[Pi] -
I Log[1 +  2 I x (-x + Sqrt[I + x^2])])]))] +
(\[Pi] -      8 I ArcTanh[(1 + Sqrt[2]) Cot[ 1/4 (\[Pi] - I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]] +   8 I ArcTanh[(-1 + Sqrt[2]) Tan[            1/4 (\[Pi] -  I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]]) Log[(-1)^(
1/4)/(2^(3/4) (1 + 2 I x (-x + Sqrt[I + x^2]))^(1/4)
Sqrt[-1 -
I Sqrt[2]
Sinh[1/2 Log[
1 + 2 I x (-x + Sqrt[I + x^2])]]])] + (\[Pi] +
8 I ArcTanh[(1 + Sqrt[2]) Cot[
1/4 (\[Pi] - I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]] -
8 I ArcTanh[(-1 + Sqrt[2]) Tan[
1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]]) Log[((1/2 -
I/2) (1 + 2 I x (-x + Sqrt[I + x^2]))^(1/4))/(
2^(1/4) Sqrt[-1 -
I Sqrt[2]
Sinh[1/2 Log[1 + 2 I x (-x + Sqrt[I + x^2])]]])] +
4 I (PolyLog[
2, -(((1 + I) (-1 + Sqrt[2] -
Cot[1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]))/(
Sqrt[2] (-1 + Sqrt[2] +
Cot[1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])])))] -
PolyLog[2, -(((1 - I) (-1 + Sqrt[2] -

Cot[1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])]))/(
Sqrt[2] (-1 + Sqrt[2] +
Cot[1/4 (\[Pi] -
I Log[1 + 2 I x (-x + Sqrt[I + x^2])])])))])))


No guarantee for failure free copy and paste here!

Result:

   Subtract @@ (res /. {{x -> 1}, {x -> 1/2}} // N)

0.0412035 + 0.105342 I


There will be a wrong sign somewhere in the simplifications, I suspect.

What may be the reason to produce such an algebraic monster just to get a number?

• $(+1)$ Elegant answer. I did not understand that how did you write: "We use the outer algebraic form as differential $dy$ ([Integrate[ x /Sqrt[x^2 + I] == y) /. { a_ Log[b_] + d_ Log[c_] :> a Log[(b/c)] /; a + d == 0 } // FullSimplify 2 y + Log[1 + 2 I x (-x + Sqrt[I + x^2])] == 0 ?
– Max
Aug 12, 2023 at 18:30
• Also why do we have the real part in the final answer with opposite sign as the initial answer but the imaginary part of final answer as same as the initial one?
– Max
Aug 12, 2023 at 18:37
• I changed the sign under the square root and put an I in front, maybe its not quite correct. There was a typo with an x instead of an dx in the substitution that has to be discarded in Integrate; corrected. Aug 12, 2023 at 18:49
• Thank you for the edit. You wrote $$\int \frac{dx}{\sqrt(x^2+ i)} = \int dy$$ Can we not do this with a sign as in our question $$\int \frac{dx}{\sqrt(-x^2- i)} = \int dy$$? Will this give us the sign we want in the final answer?
– Max
Aug 12, 2023 at 18:51
• You are right. In complex numbers we do not have $\sqrt{zw}=\sqrt{z} \sqrt{w}$
– Max
Aug 12, 2023 at 18:53

This is just a simplification of Roland's method using IntegrateChangeVariables that produces more compact results

First define the integrand:

integrand[x_]=ArcTan[(1 - x)/Sqrt[-I - x^2]]/Sqrt[-I - x^2];


I tried for a long time to find a good substitution, but it looks like Roland's suggestion works perfectly. Using $$y\to \log \left(\sqrt{-2 i x^2-2 \sqrt{-x^2 \left(x^2+i\right)}+1}\right)$$ seems to work pretty well using IntegrateChangeVariables:

ySub = Log[Sqrt[-2 I x^2 - 2 Sqrt[-x^2 (x^2 + I)] + 1]];
IntegrateChangeVariables[Inactive[Integrate][integrand[x], x], y,
y == ySub] // FullSimplify // PowerExpand;

indef = Activate[%] // FullSimplify


1/4 (-y (y - 4 ArcCoth[((1 + I) Cosh[y])/(Sqrt[2] + (1 + I) Sinh[y])] + 2 Log[1 + (-1)^(1/4) E^y] - 2 Log[1 + (-1)^(3/4) E^y]) - 2 PolyLog[2, -(-1)^(1/4) E^y] + 2 PolyLog[2, -(-1)^(3/4) E^y])

And plug in the integration bounds, and ComplexExpand the real part of the definite integral:

lowerBound = ySub /. x -> (1/2);
upperBound = ySub /. x -> 1;
def = (indef /. y -> upperBound) - (indef /. y -> lowerBound) //
FullSimplify;
rePart =
ComplexExpand[Re[def], TargetFunctions -> {Re, Im}] // FullSimplify //


1/64 (4 ArcTan[Sqrt[2 (1 + Sqrt[2])]]^2 + 12 ArcTan[1/2 Sqrt[1/2 (1 + Sqrt[17])]]^2 - Log[5 + 4 Sqrt[2] - 2 Sqrt[2 (7 + 5 Sqrt[2])]]^2 - 3 Log[1/4 (5 + Sqrt[17] - 2 Sqrt[13/2 + (5 Sqrt[17])/2])]^2 + 4 Log[Abs[((1 - 2 I) - 2 Sqrt[-1 - I])^(-((I \[Pi])/2) + Log[(-8 + 7 I) + 4 Sqrt[1 - 7 I]]) (1/ 2 ((2 - I) - Sqrt[-1 - 4 I]))^ Log[-(15/16) + I/2] (1 - Sqrt[1/17 - (4 I)/17])^ Log[1/2 ((-17 - 8 I) + Sqrt[221 + 272 I])]]] + 32 Re[PolyLog[2, I + Sqrt[-1 - I]] - PolyLog[2, 1/2 (I + Sqrt[-1 - 4 I])] - PolyLog[2, 1 - Sqrt[1 + I]] + PolyLog[2, 1/2 (1 - Sqrt[1 + 4 I])]])

Comparing to NIntegrate result:

nRePart =
Re[NIntegrate[integrand[x], {x, 1/2, 1}, WorkingPrecision -> 100]];
rePart - nRePart


0.*10^-102

• The result is an analytic expression, not a closed-form expression. There is no advantage over the numeric result. Aug 13, 2023 at 5:09
• $(+1)$ Thanks for the elegant answer. So we use the substitution $y\to \log \left(\sqrt{-2 i x^2-2 \sqrt{-x^2 \left(x^2+i\right)}+1}\right)$ but then $$\sqrt{-2 i x^2-2 \sqrt{-x^2 \left(x^2+i\right)}+1}=e^{y}$$ Then do we have $x\in\mathbb{R}$? Because in the question the limits of integration of $x$ are real number between $1/2$ and $1$. I am afraid that by using the above substitution $x\in\mathbb{C}$.
– Max
Aug 13, 2023 at 6:01

A better course of analysis with permanent control is this way

      ArcTan[(1 - x)/Sqrt[-x^2 - I]]  1/Sqrt[-x^2 - I] //TrigToExp


$$\frac{i \log \left(1-\frac{i (1-x)}{\sqrt{-x^2-i}}\right)}{2 \sqrt{-x^2-i}}-\frac{i \log \left(1+\frac{i (1-x)}{\sqrt{-x^2-i}}\right)}{2 \sqrt{-x^2-i}}$$

The signs and I's can be eliminated carefully

     Plot[{
ReIm[ Log[-1 + x + Sqrt[I + x^2]]/(2 Sqrt[I + x^2]) -
Log[1 - x + Sqrt[I + x^2]]/(2 Sqrt[I + x^2])],
ReIm[ ArcTan[(1 - x)/Sqrt[-x^2 - I]]  1/Sqrt[-x^2 - I]]},
{x, 1/2,  1},
PlotStyle -> {{Thickness[0.02], Red}, {Thickness[0.005], Black}}]


The first integrand yields

      f1 = 1/2 \[Integral]Log[-1 + x + Sqrt[I + x^2]]/Sqrt[
I + x^2] \[DifferentialD]x


$$\frac{1}{2} \left(\text{Li}_2\left(-x-\sqrt{x^2+i}+1\right)+\log \left(\sqrt{x^2+i}+x-1\right) \log \left(x+\sqrt{x^2+i}\right)\right)$$

The second seems to fail

    1/2 \[Integral]Log[1 - x + Sqrt[I + x^2]]/Sqrt[ I + x^2] \[DifferentialD]x


$$\frac{1}{2} \int \frac{\log \left(\sqrt{x^2+i}-x+1\right)}{\sqrt{x^2+i}} \, dx$$

but can be done trivially by

$$\text{f2}=\frac{1}{2} \int \frac{\log \left(\sqrt{x^2+i}+x+1\right)}{\sqrt{x^2+i}} \, dx\text{/.}\, \{x\to -x\}$$

$$-\frac{1}{2} \text{Li}_2\left(x-\sqrt{x^2+i}\right)$$

   f[x_] = f1 + f2

D[f[x], x] // FullSimplify


$$\frac{\log \left(\sqrt{x^2+i}+x-1\right)-\log \left(\sqrt{x^2+i}-x+1\right)}{2 \sqrt{x^2+i}}$$

  Plot[Evaluate[ReIm[f[x] - f[1/2]]], {x, 1/2, 1}]


Compare to

   g = NDSolveValue[
{h'[x] == ArcTan[(1 - x)/Sqrt[-x^2 - I]]  1/Sqrt[-x^2 - I],h[1/2] == 0},
h, {x, 1/2, 1}]

Plot[ReIm[{  g[x]}], {x, 1/2, 1}]