# Step-by-step definite integration

I am interested in obtaining the intermediate steps for rather straightforward symbolic definite integrations (e.g., from an elementary calculus text).

As an example, for $\int_0^1 x\,dx$ I'd like output along the lines of

$$\int_0^1 x\,dx={x^2\over 2}\Bigg|_0^1={1\over 2}$$

I have reviewed the responses to this question dealing with WolframAlpha-like step-by-step output as well as this one and this one.

The answer in the first link above is in the spirit of what I'm after (especially the last answer given by FDSg), but it focuses on differentiation. However, when I try this on even elementary definite integrals like $\int_0^1 x\,dx$ it simply returns the answer without the steps. Perhaps I am overlooking something. I do not intend to duplicate that question and this distinction is key to that.

In short, I'd be happy if ShowSteps (applied to Integrate[x,{x,0,1}]) would simply show the output in the displayed equation above (the emphasis being that I don't need to see how the indefinite integral is computed, just what it is, and then completing the evaluation between limits).

• see mathematica.stackexchange.com/questions/29362/… for package called Rubi which shows step by step transformations. – Nasser Aug 14 '13 at 16:09
• @Nasser: Thanks, but Rubi seems to be more than I need. – JohnD Aug 14 '13 at 16:46
• Ok, you can try David's presentations package. forums.wolfram.com/mathgroup/archive/2008/Nov/msg00503.html he Presentations package has a subsection called Student's Integral that allows the step by step evaluation of definite or indefinite integrals. I have not used it. But David posts here, so you can either ask him or check his web site. – Nasser Aug 14 '13 at 17:18
• @Nasser: Simple follow up, but do you know how to process the output of Integrate[x,x] to include the vertical bar, subscripted lower limit, and superscripted upper limit as in the middle part of the displayed equation above? – JohnD Aug 14 '13 at 18:33
• I tried, but could not find a way. Mathematica will immediately do the full evaluation. Even if you write Integrate[x, {x, a, b}] it will generate -(a^2/2) + b^2/2 so I do not think there is a way to do this using Mathematica directly. – Nasser Aug 14 '13 at 19:09

Here is a simple implementation:

showDefiniteIntegral[integrand_, {x_, xMin_, xMax_},
form_: StandardForm] :=
Module[{antiDerivative = Integrate[integrand, x]},
Row[{HoldForm[Integrate[integrand, {x, xMin, xMax}]], " = ",
Subsuperscript[
DisplayForm[
RowBox[{ToBoxes[antiDerivative, form],
StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]], xMin,
xMax], " = ",
Subtract @@ (antiDerivative /. x -> {xMax, xMin})}]] // form Edit

With the option SpanMinSize, I make sure that the limits bar is always large enough to stand out as a delimiter, e.g. in this situation where the antiderivative is just one character high:

showDefiniteIntegral[Sin[x], {x, 0, 1}] The optional argument form is either StandardForm (default) or TraditionalForm:

showDefiniteIntegral[Tan[x], {x, a, b}, TraditionalForm] Edit in response to the comment

Here is a version that replaces the vertical bar by a square bracket when the antiderivative has more than one term (combined with Plus, which also is the head when the terms are subtracted):

showDefiniteIntegral[integrand_, {x_, xMin_, xMax_},
form_: StandardForm] :=
Module[{a, replaceA = "", antiDerivative = Integrate[integrand, x]},
Row[{HoldForm[Integrate[integrand, {x, xMin, xMax}]], " = ",
RowBox[{StyleBox["[", SpanMinSize -> 2], ToBoxes[
antiDerivative, form], StyleBox["]", SpanMinSize -> 2]}],
RowBox[{ToBoxes[
antiDerivative, form],
StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]]],
xMin, xMax], " = ",
Subtract @@ (antiDerivative /. x -> {xMax, xMin})}]] // form

showDefiniteIntegral[Cos[x] - Tan[x], {x, a, b}, TraditionalForm] • In order to switch between a vertical bar and surrounding square brackets based on Length[antiDerivative], I modified as follows (too many characters to paste the whole new def, sorry): If[Length[antiDerivative] > 1, Row[{HoldForm[Integrate[integrand, {x, xMin, xMax}]], " = ", Subsuperscript[ DisplayForm[RowBox[{"[", ToBoxes[antiDerivative, form], "]"}]], xMin, xMax], " = ", Subtract @@ (antiDerivative /. x -> {xMax, xMin})}] but to no avail. Suggestion? – JohnD Aug 15 '13 at 1:04
• Ah yes, good idea. I'll think about it... Length may not be good - you just want to bracket operations with low precedence (like + or -), right? – Jens Aug 15 '13 at 1:08
• Yes, that is what I am after. (I wasn't sure if Length counted terms or not...) I was having trouble both getting the [ ] to show up---and even when they did, for their heights to scale vertically like SpanMinSize did for |. – JohnD Aug 15 '13 at 1:14
• OK, I added a modified version that should be able to make the right stylistic decisions. – Jens Aug 15 '13 at 1:31

The Presentations Application, which I sell, has a Student's Integral section that allows basic step by step single variable integral operations to be developed and displayed. One can operate on the integrands including using change of variables, integration by parts and trigonometric substitution. One can also do breakout of sums and constants. The actual integration can be performed by a BasicIntegralTable, or by turning it over to Mathematica. When using tables it's possible to display intermediate limits expressions.

<< Presentations


The following is the BasicIntegralTable, common in most basic calculus texts. It is also possible to construct one's own integral tables. Such tables might also be useful for advanced users. You might have an integral that takes a long time to evaluate and whose result also needs to be transformed to a more convenient form. This could be put into a table, in which case it would evaluate to the desired form rapidly in subsequent work.

Here is your pretty basic example. The integrate command formats like Integrate but does not evaluate.

step1 = integrate[x, {x, 0, 1}]
step2 = step1 // UseIntegralTable[BasicIntegralTable]
step3 = step2 // EvaluateLimitsBracket   Here is another example using integration by parts.

step1 = integrate[x Cos[x], x]
step2 = step1 // IntegrateByParts[x, x]
step3 = step2 + C // UseIntegralTable[BasicIntegralTable] // Framed    Finally, here is a more extended example: Find the volume of the solid generated by revolving the region bounded by the x-axis and the curve y(x) == x sin(x) for 0 <= x<= [Pi] revolved about the y-axis. And here is the integration display done in a two column format. (Presentations has a formatting command for this but it's a construction that has to be built-up and not a general notebook command.) In the notebook, the right hand side has Tooltips that show the Mathematica command used to display the result. You can call WolframAlpha from within Mathematica.

WolframAlpha["integrate x from 0 to 1", {{"Input", 2}, "Content"},
PodStates -> {"Input__Step-by-step solution"}]
` 