How does Mathematica calculate integrals?
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:
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.