6
$\begingroup$

One can use mathematica to get $$ \int_{-\infty}^{\infty}\frac{\sin^2x}{x^2+1}\ dx=\frac{\pi \sinh 1}{e}. $$ Here are my questions:

  • [Edited:] Is there a way that I can see the intermediate steps Mathematica uses? (Of course one can calculate this integral by hand using complex analysis. But I guess Mathematica would not do it in that way.)
  • More general, is there a way to see what underlying algorithm Mathematica uses to calculate integrals?
$\endgroup$
2
  • $\begingroup$ Though this question also asks how to see the intermediate steps, so not entirely a duplicate. $\endgroup$
    – Mark Adler
    Apr 6, 2016 at 22:30
  • 1
    $\begingroup$ In that case, this answer applies. $\endgroup$ Apr 7, 2016 at 11:42

2 Answers 2

8
$\begingroup$

Rules. Lots of rules. See the implementation notes in the documentation. I don't know of a way to show Mathematica's intermediate steps, but you can load the Rubi symbolic integration package, which will in fact show how it does an integral with ShowSteps=True;. Also it seems to work better than Mathematica's integrator.

Int[Sin[x]^2/(x^2 + 1), x]

Rule 6313: If PositiveIntegerQ[n],

  \[Integral]u/(a+b x^n) \[DifferentialD]x \[LongRightArrow] \[Integral]RationalFunctionExpand[u/(a+b x^n),x]\[DifferentialD]x

Int[(I Sin[x]^2)/(2 (I - x)) + (I Sin[x]^2)/(2 (I + x)), x]

Rule: 

  Int[a u+b v+\[CenterEllipsis],x] \[LongRightArrow] a \[Integral]u \[DifferentialD]x+b \[Integral]v \[DifferentialD]x+\[CenterEllipsis]

Dist[I/2, Int[Sin[x]^2/(I - x), x], x] + 
 Dist[I/2, Int[Sin[x]^2/(I + x), x], x]

Rule 4154: If IntegerQ[n]&&n>1&&(!RationalQ[m]||-1<=m<1),

  \[Integral](c+d x)^m Sin[a+b x]^n\[DifferentialD]x \[LongRightArrow] \[Integral]ExpandTrigReduce[(c+d x)^m,Sin[a+b x]^n,x]\[DifferentialD]x

Rule 4154: If IntegerQ[n]&&n>1&&(!RationalQ[m]||-1<=m<1),

  \[Integral](c+d x)^m Sin[a+b x]^n\[DifferentialD]x \[LongRightArrow] \[Integral]ExpandTrigReduce[(c+d x)^m,Sin[a+b x]^n,x]\[DifferentialD]x

Dist[I/2, Int[1/(2 (I - x)) - Cos[2 x]/(2 (I - x)), x], x] + 
 Dist[I/2, Int[1/(2 (I + x)) - Cos[2 x]/(2 (I + x)), x], x]

Rule: 

  Int[a u+b v+\[CenterEllipsis],x] \[LongRightArrow] a \[Integral]u \[DifferentialD]x+b \[Integral]v \[DifferentialD]x+\[CenterEllipsis]

Rule: 

  Int[a u+b v+\[CenterEllipsis],x] \[LongRightArrow] a \[Integral]u \[DifferentialD]x+b \[Integral]v \[DifferentialD]x+\[CenterEllipsis]

-(1/4) I Log[I - x] + 1/4 I Log[I + x] - 
 Dist[I/4, Int[Cos[2 x]/(I - x), x], x] - 
 Dist[I/4, Int[Cos[2 x]/(I + x), x], x]

Rule 4139: If NonzeroQ[b c-a d],

  \[Integral]Cos[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Dist[Cos[(b c-a d)/d],\[Integral]Cos[(b c)/d+b x]/(c+d x) \[DifferentialD]x,x]+Dist[Sin[(b c-a d)/d],\[Integral]Sin[(b c)/d+b x]/(c+d x) \[DifferentialD]x,x]

Rule 4139: If NonzeroQ[b c-a d],

  \[Integral]Cos[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Dist[Cos[(b c-a d)/d],\[Integral]Cos[(b c)/d+b x]/(c+d x) \[DifferentialD]x,x]+Dist[Sin[(b c-a d)/d],\[Integral]Sin[(b c)/d+b x]/(c+d x) \[DifferentialD]x,x]

-(1/4) I Log[I - x] + 1/4 I Log[I + x] - 
 Dist[1/4 I Cosh[2], Int[Cosh[2 - 2 I x]/(I + x), x], x] - 
 Dist[1/4 I Cosh[2], Int[Cosh[2 + 2 I x]/(I - x), x], x] + 
 Dist[1/4 I Sinh[2], Int[Sinh[2 - 2 I x]/(I + x), x], x] + 
 Dist[1/4 I Sinh[2], Int[Sinh[2 + 2 I x]/(I - x), x], x]

Rule 5090: If ZeroQ[b c-a d],

  \[Integral]Cosh[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Simp[CoshIntegral[(b c)/d+b x]/d,x]

Rule 5090: If ZeroQ[b c-a d],

  \[Integral]Cosh[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Simp[CoshIntegral[(b c)/d+b x]/d,x]

Rule 5089: If ZeroQ[b c-a d],

  \[Integral]Sinh[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Simp[SinhIntegral[(b c)/d+b x]/d,x]

Rule 5089: If ZeroQ[b c-a d],

  \[Integral]Sinh[a+b x]/(c+d x) \[DifferentialD]x \[LongRightArrow] Simp[SinhIntegral[(b c)/d+b x]/d,x]

-(1/4) I Cosh[2] CoshIntegral[2 - 2 I x] + 
 1/4 I Cosh[2] CoshIntegral[2 + 2 I x] - 1/4 I Log[I - x] + 
 1/4 I Log[I + x] + 1/4 I Sinh[2] SinhIntegral[2 - 2 I x] - 
 1/4 I Sinh[2] SinhIntegral[2 + 2 I x]

f[x_] = %;

Limit[f[x], x -> \[Infinity]] - Limit[f[x], x -> -\[Infinity]]

((-1 + E^2) \[Pi])/(2 E^2)

Update:

Daniel Lichtbau and Searke noted that there is a "Step-by-step solution" button when you use Wolfram Alpha from Mathematica (input starts with an equals sign). Here is the output for the indefinite integral above:

Wolfram Alpha output

$\endgroup$
1
  • 1
    $\begingroup$ Integrate and Rubi don't work the same way. But yes, rubi is useful $\endgroup$
    – Searke
    Apr 5, 2016 at 21:57
3
$\begingroup$

How does Integrate work?

https://en.wikipedia.org/wiki/Risch_algorithm

There are more details you can find online, but it's not useful for most people. Integrate internally does a lot of things that most people wouldn't understand.

If you want to learn more about integration, you should use Wolfram|Alpha. It can show you the steps a human would take to solve these problems.

The real answer to the question depends on why you want to know how it works.

$\endgroup$
7
  • $\begingroup$ I mean the answer to your question can get quite complicated if you want it to: dl.acm.org/… $\endgroup$
    – Searke
    Apr 5, 2016 at 22:02
  • $\begingroup$ Or when the Risch algorithm can't be applied, "For other indefinite integrals, heuristic simplification followed by pattern matching is used." $\endgroup$
    – Mark Adler
    Apr 5, 2016 at 22:03
  • $\begingroup$ Please see this question where people have already talked about this in more detail: mathematica.stackexchange.com/questions/6811/… $\endgroup$
    – Searke
    Apr 5, 2016 at 22:05
  • $\begingroup$ @Searke: Thank you for your answer and helpful comments. I have tried Wolfram|Alpha with int sin^2x/(x^2+1) {x, -infty,+infty}. But I don't see how it shows the human ways. Would you elaborate? $\endgroup$
    – user664
    Apr 5, 2016 at 22:13
  • 4
    $\begingroup$ @DanielLichtblau You can also get "Show Steps" if you query Wolfram|Alpha inside Mathematica with the "double equal sign" $\endgroup$
    – Searke
    Apr 6, 2016 at 15:38