Latest update

# Integration gives ComplexInfinity when it shouldn't

2018-03-13 17:02:00

A simple example of my problem is that

Assuming[k ∈ Reals, Integrate[Exp[l]/((1 + Exp[l])*Exp[k*l]), l]] /. {k -> 2}

gives ComplexInfinity while

Integrate[Exp[l]/((1 + Exp[l])*Exp[2*l]), l]

gives the correct answer. I would like to get the correct answer in the first case as well. Any suggestions?

I'm using Mathematica 6 on a Windows XP PC.

Failed attempts to bypass the problem

Defining Riemann integration as a separate function using Sum and Limit

Using Assumptions in preamble, putting Assuming[] around Integrate, using Integrate[f,x,Assumptions->{x,params}\in Reals]

Using FunctionInterpolation on the function to be integrated before applying the (definite) integral

Expanding the function to be integrated with Series before integrating

Have to hand it to Mathematica, at least it is consistent.

The reason this happens, is because Hypergeometric2F1[1, 1 - k, 2 - k, -E^z] is infinity at $k=2$

Assuming[Element[k, Integers] And k > 0,Integrate[Ex

• The reason this happens, is because Hypergeometric2F1[1, 1 - k, 2 - k, -E^z] is infinity at $k=2$

Assuming[Element[k, Integers] And k > 0,Integrate[Exp[z]/((1 + Exp[z])*Exp[k*z]), z]]

Hypergeometric2F1[1, 1 - k, 2 - k, -E^z] /. k -> 2

When you wrote

Integrate[Exp[z]/((1 + Exp[z])*Exp[2*z]), z]

Then M went through a different path, since now $k=2$ and it did not need to use Hypergeometric2F1 for the result.

May be relevant, in the help, it says under possible issues for Hypergeometric2F1 see the assumptions on variables used. When they are assumed to be positive integers vs. default complex numbers.

I thought by using assumptions that $k$ is positive integer then this might not make Integrate use Hypergeometric2F1 and go through the same path it did for $k=2$, but for some reason, it still uses this function. May be I did not use the assumptions for Integrate correctly. Just want to add that this is a little strange, but sometimes I feel sorry for Integrate, as I read i

2018-03-13 17:24:24
• The difference in the integrands is fundamentally important. The presence of $k$ makes a difference, apparently, in the way the integration algorithm arrives at an antiderivative.

(For instance, if the ratio of the exponents in Exp[k l] and Exp[l], i.e., k l / l = k, is rational, then the antiderivative can be expressed in terms of elementary functions; otherwise it seems not.)

A way that seems it might be convenient rests on recognizing the nature of the problem. Define a function to separate out the cases when k is a rational number or not:

myIntegral[k : _Integer | _Rational] :=

myIntegral[k] = Integrate[Exp[l]/((1 + Exp[l])*Exp[k*l]), l];

myIntegral[k_?NumericQ] :=

Integrate[Exp[l]/((1 + Exp[l])*Exp[k*l]), l];

Then, if you want, you can wrap both in a piecewise expression:

integral = Piecewise[{

{myIntegral[k], k \[Element] Rationals},

{Integrate[ Exp[l]/((1 + Exp[l])*Exp[k*l]), l], True}}]

integral /. k -> 2

(* -E^-l + Log[1 + E^-l] *)

There may be other ways

2018-03-13 17:32:19
• As it turns out, making the substitution $u=\exp l$, manually integrating by parts, applying the Pfaff transformation to the resulting hypergeometric function, and then undoing the substitutions, will get you a usable form:

Simplify[(u^(1 - k)/(1 - k) 1/(1 + u) +

Integrate[u^(1 - k)/(1 - k) 1/(1 + u)^2, u] /.

Hypergeometric2F1[a_, b_, c_, z_] :>

(1 - z)^(c - a - b) Hypergeometric2F1[c - a, c - b, c, z]) /.

u -> Exp[l], k ∈ Integers]

(E^(l - k l) ((1 + E^l) (1 + k) Hypergeometric2F1[1, 1, 1 + k, 1/(1 + E^l)] -

k ((1 + E^l) (1 + k) + Hypergeometric2F1[1, 2, 2 + k, 1/(1 + E^l)])))/

((1 + E^l)^2 k (-1 + k^2))

which now works for $k>1$:

sander[k_, l_] :=

(E^(l - k l) ((1 + E^l) (1 + k) Hypergeometric2F1[1, 1, 1 + k, 1/(1 + E^l)] -

k ((1 + E^l) (1 + k) + Hypergeometric2F1[1, 2, 2 + k, 1/(1 + E^l)])))/

((1 + E^l)^2 k (-1 + k^2))

And @@ Table[FullSimplify[Integrate[Exp[l]/((1 + Exp[l])*Exp[k*l]), l] == sander[k, l],

2018-03-13 17:57:00
• Your function appears to have singularities at integer values:

DiscretePlot[Integrate[Exp[l]/((1 + Exp[l])*Exp[k*l]), l] /. l -> 1,

{k, 1, 5, 0.01}] // Quiet

Are you sure of your expected result?

2018-03-13 18:33:25