Mathematica sometimes fails to compute symbolic solutions when posed in the direct or obvious code, but succeeds when the same fundamental problem is posed in a slightly different way, or when assumptions are made explicit, or other tricks and hacks.

Example (v. 11.3):

 ((I E^(I t) + 2 I E^(I x)) PolyLog[2, 1 - E^(I (t - x))])/(E^(I (t + 2 x))), 

fails to integrate, but if it is split into the two component integrals in the natural way, it succeeds. (The two component answers can be added and then FullSimplifyed.)

As a result, there must be cases where users have given up in frustration when the proper hack or trick would have solved their problem.

As a service to the community (and for my own use), I'd like to collect in one place examples of such tricks and hacks that have yielded symbolic solutions when the direct or "obvious" approach failed.

(I'm not interested in numerical hacks... as these are of a fundamentally different sort.)

Some of the tricks I've come across include:

  • expressing constraints in novel ways
  • Expanding a complex function into a sum of simpler functions and integrating them individually
  • solving a "simpler" integral symbolically and then taking the limit of some variable to the desired value
  • forcing a "smart" change of variables
  • breaking an integral into component parts (as above)

Again, I'd like to limit consideration to symbolic computational mathematics, so I expect most answers will involve Integrate, D, Solve, DSolve, Simplify, and such. As a mild request, I think we would all best profit from minimal problems that require a particular hack.

Mathematica's symbolic manipulation is an extraordinary tool, but like all complex tools, its power and applicability is enhanced with the user knows how best to use it... and that sometimes includes non-obvious heuristics and hacks.

  • 2
    $\begingroup$ The workaround that you described can be done by Simplify[Integrate[#, x] & /@ Expand[f[x]]] Mapping Integrate over Plus will take care of doing multiple integrals and summing the results. $\endgroup$
    – Bob Hanlon
    May 1 at 17:51
  • $\begingroup$ Excellent example! Post it as an answer! (Perhaps make a new minimal example, to keep things interesting.) $\endgroup$ May 1 at 17:55
  • 1
    $\begingroup$ Crossposted here. $\endgroup$ May 3 at 1:46

If Integrate returns unevaluated, expand the integrand (into a sum of simpler functions) and map Integrate onto the expanded expression. If the term-by-term integrations are successful, the evaluated expression will be the original integral.



(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

f[x_, t_] := ((I E^(I t) + 2 I E^(I x)) PolyLog[2, 
      1 - E^(I (t - x))])/(E^(I (t + 2 x)));

Direct integration returns unevaluated

Integrate[f[x, t], x]

enter image description here

Integrating the expanded expression term-by-term

int[x_, t_] = Simplify[Integrate[#, x] & /@ Expand[f[x, t]]]

(* 1/8 E^(-2 I (t + x)) (E^(2 I t) + 20 E^(I (t + x)) - 
   2 E^(2 I t) Log[E^(I (t - x))] - 20 E^(I (t + x)) Log[E^(I (t - x))] - 
   10 E^(2 I x) Log[E^(I (t - x))]^2 - 
   20 E^(2 I x) Log[E^(I (t - x))] Log[1 - E^(I (-t + x))] + 
   20 E^(2 I x) PolyLog[2, E^(I (-t + x))] - 
   4 E^(I t) (E^(I t) + 4 E^(I x)) PolyLog[2, 1 - E^(I (t - x))]) *)

Verifying that this result is a valid antiderivative of the original integrand

D[int[x, t], x] == f[x, t] // Simplify

(* True *)
  • $\begingroup$ Good start (+1). Let's hope for lots of more examples... including from differential equations and other domains. (I'd love to see another class of function where the illustrated problem occurs too.) $\endgroup$ May 1 at 23:32

To calculate

Integrate[ArcTan[a*Sqrt[1 - k^2*Sin[z]^2]]/Sqrt[1 - k^2*Sin[z]^2], {z, 0,Pi/2}]

do differentiation under the integral with respect to the parameter a

D[ArcTan[a*Sqrt[1 - k^2*Sin[z]^2]]/Sqrt[1 - k^2*Sin[z]^2], a]

and integrate over z :

Integrate[1/(1 + a^2 - a^2*k^2*Sin[z]^2), z]
(* ArcTanh[(Sqrt[-1 + a^2*(-1 + k^2)]*Tan[z])/Sqrt[1 + a^2]]/
(Sqrt[1 + a^2]*Sqrt[-1 + a^2*(-1 + k^2)])*)

Take the minus out of the square roots to get :

ArcTan[(Sqrt[1 + a^2*(1 - k^2)]*Tan[z])/Sqrt[1 + a^2]]/
(Sqrt[1 + a^2]*Sqrt[1 + a^2*(1 - k^2)])

Insertion of the limits z = Pi/2 and z = 0 gives

Pi/(2*(Sqrt[1 + a^2]*Sqrt[1 + a^2*(1 - k^2)]))

which may then be integrated to reverse the initial differentiation :

Integrate[Pi/(2*(Sqrt[1 + a^2]*Sqrt[1 + a^2*(1 - k^2)])), a]
(* (Pi*EllipticF[ArcSin[a*Sqrt[-1 + k^2]], 1/(1 - k^2)])/(2*
Sqrt[-1 + k^2]) *)

To shape this into a nicer form take again the minus out of the square roots to get :

(Pi*EllipticF[I*ArcSinh[a*Sqrt[1 - k^2]], 1/(1 - k^2)])/(I*2*Sqrt[1 - k^2])

With two subsequent transformations for EllipticF like (https://dlmf.nist.gov 19.7.7 and 19.7.5)

EllipticF[I zz, kk^2] -> I EllipticF[ArcTan[Sinh[zz]], 1 - kk^2]


EllipticF[zz, -kk] -> EllipticF[ArcTan[Sqrt[1 + kk]*Tan[zz]], kk/(1 + kk)]/Sqrt[1 + kk]

we obtain the beautiful result of the original integral

Pi/2*EllipticF[ArcTan[a], k^2]

This procedure helped me calculating many integrals.

  • $\begingroup$ Excellent... just what I'm seeking. And so elegant! Thanks. (+1). $\endgroup$ May 2 at 16:26
  • 2
    $\begingroup$ Since differentiating under the integral sign is often but not always valid, one should always find a way to check such answers. $\endgroup$ May 2 at 21:49

A way to get sometimes unexpected results :

The following integral is ' easy'

Integrate[Log[1 - x]/(1 - x), x]
(* (-(1/2))*Log[1 - x]^2 *)

Now write explicitly the geometric series

Sum[x^k, {k, 0, Infinity}]
(* 1/(1 - x) *)

inside the integral

(-(1/2))*Log[1 - x]^2 = Integrate[Log[1 - x]/(1 - x), x] = 
Integrate[Sum[x^k, {k, 0, Infinity}] Log[1 - x], x],

exchange integral and sum

Sum[Integrate[x^k Log[1 - x], x], {k, 0, Infinity}]

and let Mathematica do the the integral

Sum[(x^(1 + k)*(x*Hypergeometric2F1[1, 2 + k, 3 + k, x] + (2 + k)*Log[1 - x]))/
 ((1 + k)*(2 + k)), {k, 0, Infinity}]

The Hypergeometric can be simplified

Sum[(Beta[x, 2 + k, 0] + x^(1 + k)*Log[1 - x])/(1 + k), {k, 0, Infinity}] = 
Sum[Beta[x, 2 + k, 0]/(1 + k), {k, 0, Infinity}] + 
Log[1 - x])*Sum[(x^k)/k, {k, 1, Infinity}] = 
Sum[Beta[x, 2 + k, 0]/(1 + k), {k, 0, Infinity}] - Log[1 - x]^2

So finally

Sum[Beta[x, k + 1 , 0]/k, {k, 1, Infinity}] = (1/2)*Log[1 - x]^2

A nice closed form...


Another example for this technique is

Integrate[E^(-a*x^n)/(1 - b*E^(-c*x^n)), {x, 0, Infinity}]

Mathematica cannot calculate this integral. Replace the 'geometric factor' with

Sum[b^k* E^(-c*k*x^n), {k, 0, Infinity}]

and exchange integral and sum

Sum[(b^k*Gamma[1 + 1/n])/(a + c*k)^n^(-1), {k, 0, Infinity}]
(* (Gamma[(1 + n)/n]*HurwitzLerchPhi[b, 1/n, a/c])/c^n^(-1) *)

valid for b < 1.

  • $\begingroup$ Interesting... but can you show an "unsolvable" problem that becomes solvable using this technique? $\endgroup$ May 2 at 18:44
  • $\begingroup$ Mathematica does not solve Sum[Beta[x, k + 1 , 0]/k, {k, 1, Infinity}] $\endgroup$
    – Andreas
    May 2 at 18:52
  • $\begingroup$ Ah... that wasn't clear to me. So thanks! (+1) $\endgroup$ May 2 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.