My question pertains to the inconsistency that may arise in indefinite integrals vs definite integrals in Mathematica due to the indefinite integral being discontinuous as explained here.
I want to evaluate the following integral and obtain the result as a function of n and m, the latter is absolutely crucial to me :
$ g(n,x) = \sqrt{\frac{2}{(n+2)^2 - 1}} \left\{ (n+2) \cos[(n+2) \pi x] - \cot(\pi x) \sin[ (n+2) \pi x] \right\}$ and $x_{nm}(n,m) = \int_0^1 dx\ g(n,x)\ x\ g(m,x)$.
Naively, integrating this results in a non-converging integral. So, I tried to do an indefinite integral and take the limits and then subtract to get the result. This gives me inconsistent result when n=m and when |n-m| is even. In both cases I get indeterminate result whereas if I go with definite integral (while specifying the value of n and m) then in the former I get finite result and in the latter I get 0. Except this the method works absolutely fine.
I realize that this comes from the discontinuity in the anti-derivative obtained using Integrate and I have read the blog post linked above but can't make it work for me. Can someone please help me resolve the inconsistency?
All Mathematica Code pertaining to this is below :-
g[n_, x_] :=
Sqrt[2/((n + 2)^2 -
1)] ((n + 2)*Cos[\[Pi]*(n + 2)*x] -
Cot[\[Pi]*x]*Sin[(n + 2)*\[Pi]*x]);
Integrate[ g[n, x] * g[m, x] *x, {x, 0, 1},
Assumptions -> {n \[Element] Integers, m \[Element] Integers}] (* Indeterminate *)
Integrate[ g[n, x] * g[m, x] *x, x,
Assumptions -> {n \[Element] Integers, m \[Element] Integers}]
(* Output-
2 Sqrt[1/(3 + 4 m + m^2)] Sqrt[1/(
3 + 4 n +
n^2)] (-(1/(
2 (m - n) (4 + m + n) \[Pi]))((
2 (2 + m) (3 + 4 m + m^2) (2 +
n) Cos[(2 + m) \[Pi] x] Cos[(2 + n) \[Pi] x])/((-m + n) (4 +
m + n) \[Pi]) - (1/(
2 \[Pi]))(-((
E^(I (m - n) \[Pi] x) (m^2 - m (-1 + 4 n + n^2) -
3 (2 + 4 n + n^2)) Hypergeometric2F1[1, (m - n)/2,
1/2 (2 + m - n), E^(2 I \[Pi] x)])/(m - n)) - (
E^(I (2 + m - n) \[Pi] x) (6 + m^2 + 4 n + n^2 +
m (7 + 4 n + n^2)) Hypergeometric2F1[1, 1/2 (2 + m - n),
1/2 (4 + m - n), E^(2 I \[Pi] x)])/(2 + m - n) + (
1/((2 + m + n) (4 + m + n)))
E^(-2 I (3 + m +
n) \[Pi] x) (-E^(
I (2 + m + n) \[Pi] x) (12 + m^3 + 14 n + 6 n^2 + n^3 +
m^2 (9 + 5 n + n^2) +
m (20 + 19 n + 7 n^2 + n^3)) Hypergeometric2F1[
1, -2 - m/2 - n/2, -1 - m/2 - n/2, E^(2 I \[Pi] x)] -
E^(I (4 + m + n) \[Pi] x) (m^3 - m^2 (-5 + 3 n + n^2) -
3 (8 + 18 n + 8 n^2 + n^3) -
m (2 + 27 n + 11 n^2 + n^3)) Hypergeometric2F1[
1, -1 - m/2 - n/2, -(m/2) - n/2, E^(2 I \[Pi] x)])) - (
1/(2 \[Pi]))((
E^(-I (m - n) \[Pi] x) (6 + m^2 + 4 n + n^2 +
m (7 + 4 n + n^2)) Hypergeometric2F1[1, 1/2 (-m + n),
1/2 (2 - m + n), E^(2 I \[Pi] x)])/(m - n) + (
E^(-I (-2 + m - n) \[Pi] x) (m^2 - m (-1 + 4 n + n^2) -
3 (2 + 4 n + n^2)) Hypergeometric2F1[1, 1/2 (2 - m + n),
1/2 (4 - m + n), E^(2 I \[Pi] x)])/(-2 + m - n) + (
1/((4 + m + n) (6 + m + n)))(E^(
I (4 + m + n) \[Pi] x) (m^3 - m^2 (-7 + 3 n + n^2) -
m n (35 + 13 n + n^2) -
3 (12 + 26 n + 10 n^2 + n^3)) Hypergeometric2F1[1,
1/2 (4 + m + n), 1/2 (6 + m + n), E^(2 I \[Pi] x)] +
E^(I (6 + m + n) \[Pi] x) (24 + m^3 + 22 n + 8 n^2 + n^3 +
m^2 (11 + 5 n + n^2) +
m (34 + 27 n + 9 n^2 + n^3)) Hypergeometric2F1[1,
1/2 (6 + m + n), 1/2 (8 + m + n), E^(2 I \[Pi] x)])) + (
2 (3 + 4 m + m^2) (2 +
n)^2 Sin[(2 + m) \[Pi] x] Sin[(2 + n) \[Pi] x])/((-m +
n) (4 + m + n) \[Pi])) + (1/(2 (m - n) (4 + m + n) \[Pi]))
x (2 (3 + 4 m + m^2) (2 +
n) Cos[(2 + n) \[Pi] x] Sin[(2 + m) \[Pi] x] -
2 ((2 + m) (3 + 4 n + n^2) Cos[(2 + m) \[Pi] x] + (4 m + m^2 -
n (4 + n)) Cot[\[Pi] x] Sin[(2 + m) \[Pi] x]) Sin[(2 +
n) \[Pi] x]))
*)
(* Taking limits, subtracting and using a FullSimplify gives the following *)
(1/(2 \[Pi]^2))(-1 + (-1)^(m + n)) Sqrt[1/(3 + 4 m + m^2)] Sqrt[1/(
3 + 4 n +
n^2)] ((4 (2 + m) (2 + n) (6 + m (4 + m) + n (4 + n)))/((m -
n)^2 (4 + m + n)^2) + HarmonicNumber[1/2 (-2 + m - n)] -
HarmonicNumber[-3 - m/2 - n/2] + HarmonicNumber[1/2 (-2 - m + n)] -
HarmonicNumber[1/2 (2 + m + n)])
(* Trying for m->n limit and checking the result : *)
Limit[1/(2 \[Pi]^2) (-1 + (-1)^(m + n)) Sqrt[1/(3 + 4 m + m^2)] Sqrt[
1/(3 + 4 n +
n^2)] ((4 (2 + m) (2 + n) (6 + m (4 + m) + n (4 + n)))/((m -
n)^2 (4 + m + n)^2) + HarmonicNumber[1/2 (-2 + m - n)] -
HarmonicNumber[-3 - m/2 - n/2] +
HarmonicNumber[1/2 (-2 - m + n)] -
HarmonicNumber[1/2 (2 + m + n)]), m -> n]
(* Output : DirectedInfinity[Sign[-1 + (-1)^(2 n)]/Sqrt[1/
Sign[3 + 4 n + n^2]]] Sqrt[1/Sign[3 + 4 n + n^2]] *)
With[{n = 2, m = 2}, Integrate[ g[n, x] * g[m, x] *x, {x, 0, 1}]]
(* Output : 1/2 *)
Please help me get rid of the inconsistency.
Edit :
I had asked a related question here. I could make things work using Assumptions as explained in the comments there and then got stuck at the above-mentioned inconsistency.