24
$\begingroup$

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):

Integrate[
 ((I E^(I t) + 2 I E^(I x)) PolyLog[2, 1 - E^(I (t - x))])/(E^(I (t + 2 x))), 
 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.

$\endgroup$
3
  • 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, 2021 at 17:51
  • $\begingroup$ Excellent example! Post it as an answer! (Perhaps make a new minimal example, to keep things interesting.) $\endgroup$ May 1, 2021 at 17:55
  • 1
    $\begingroup$ Crossposted here. $\endgroup$ May 3, 2021 at 1:46

5 Answers 5

14
$\begingroup$

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]

and

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.

$\endgroup$
2
  • $\begingroup$ Excellent... just what I'm seeking. And so elegant! Thanks. (+1). $\endgroup$ May 2, 2021 at 16:26
  • 4
    $\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, 2021 at 21:49
12
$\begingroup$

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.

Clear["Global`*"]

$Version

(* "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 *)
$\endgroup$
1
  • $\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, 2021 at 23:32
10
$\begingroup$

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...

Edit:

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.

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

Assuming that as stated in the subject line, the question is about "symbolic math" in general and not just integration:

To find a closed-form representation of a recursive function definition, a typical approach is to generate a sequence from the recursion and then use FindSequenceFunction on the sequence.

f[1] = a*x + b;

f[n_Integer?Positive] := f[n] =
  Integrate[c*x^k*f[n - 1], x] // Simplify

seq = f /@ Range[6]

(* {b + a x, c x^(1 + k) (b/(1 + k) + (a x)/(2 + k)), 
 1/2 c^2 x^(2 + 2 k) (b/(1 + k)^2 + (2 a x)/(6 + 7 k + 2 k^2)), 
 1/6 c^3 x^(3 + 3 k) (b/(1 + k)^3 + (6 a x)/(24 + 46 k + 29 k^2 + 6 k^3)), 
 1/24 c^4 x^(
  4 + 4 k) (b/(1 + k)^4 + (24 a x)/((5 + 4 k) (24 + 46 k + 29 k^2 + 6 k^3))), 
 1/120 c^5 x^(
  5 + 5 k) (b/(1 + k)^5 + (
    120 a x)/((5 + 4 k) (6 + 5 k) (24 + 46 k + 29 k^2 + 6 k^3)))} *)

However, with more complicated functions such as this, FindSequenceFunction returns unevaluated.

FindSequenceFunction[seq, n] // Short[#, 3] &

enter image description here

To workaround this, use FindSequenceFunction on the separate parts of the sequence

(f2[n_, x_] = Total[FindSequenceFunction[#, n] & /@
     Transpose[List @@@ (seq // Expand)]] // FunctionExpand // FullSimplify)//TraditionalForm

enter image description here

Verifying the equivalence of f (recursive) and f2 (closed-form) for positive integer values of n

And @@ (Table[f[n] == f2[n, x] // FullSimplify, {n, 1, 30}])

(* True *)

However, note that the closed-form definition,f2, is not limited to positive integer values of n.

f2[3.2, 1.7] /. {a -> 0.25, b -> 1.5, c -> 1.75, k -> 0.5}

(* 5.61395 *)
$\endgroup$
3
$\begingroup$

I think the place I have run into this most is with Fourier transforms. For example, if we try to calculate the Fourier transform of Sin[t] directly from the definition

Integrate[Sin[t] Exp[I w t], {t, -Infinity, Infinity}]

we get a message that the integral does not converge on {-Infinity, Infinity}. But we can take this transform easily using the built-in function

FourierTransform[Sin[t], t, w]

which gives the answer as a sum of two delta functions (as we may have been taught in school).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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