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


Posted 2013-08-14T16:02:37.270

Reputation: 3 121

possible duplicate of Get a "step by step" evaluation in Mathematica

– Szabolcs – 2014-02-23T16:24:56.607

My question was about getting the intermediate steps (as in the link above), but also about obtaining the formatting of those steps as outlined in the OP. – JohnD – 2014-03-06T17:49:31.700

see for package called Rubi which shows step by step transformations.

– Nasser – 2013-08-14T16:09:29.697

@Nasser: Thanks, but Rubi seems to be more than I need. – JohnD – 2013-08-14T16:46:43.970

Ok, you can try David's presentations package. 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 – 2013-08-14T17:18:03.397

@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 – 2013-08-14T18:33:40.620

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 – 2013-08-14T19:09:13.017

It might be worth noting that Mathematica computes many interesting definite integrals using techniques that do not involve finding an anti-derivative, which is one reason that WA does not provide steps for definite integration. One simple example is Integrate[Sin[Sin[x]],{x,0,2 Pi}]. – Mark McClure – 2013-08-15T01:27:16.247



Here is a simple implementation:

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



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}]], " = ", 
     Subsuperscript[DisplayForm[If[Head[antiDerivative] === Plus,
        RowBox[{StyleBox["[", SpanMinSize -> 2], ToBoxes[
           antiDerivative, form], StyleBox["]", SpanMinSize -> 2]}],
           antiDerivative, form], 
          StyleBox["\[RightBracketingBar]", SpanMinSize -> 2]}]]], 
      xMin, xMax], " = ", 
     Subtract @@ (antiDerivative /. x -> {xMax, xMin})}]] // form

showDefiniteIntegral[Cos[x] - Tan[x], {x, a, b}, TraditionalForm]

large integrand


Posted 2013-08-14T16:02:37.270

Reputation: 93 191

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 – 2013-08-15T01:04:24.973

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 – 2013-08-15T01:08:52.770

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 – 2013-08-15T01:14:17.307

1OK, I added a modified version that should be able to make the right stylistic decisions. – Jens – 2013-08-15T01:31:29.810


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.

enter image description here

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 

enter image description here

enter image description here

enter image description here

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

enter image description here

enter image description here

enter image description here

enter image description here

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.

enter image description here

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.

enter image description here

David Park

Posted 2013-08-14T16:02:37.270

Reputation: 2 503


You can call WolframAlpha from within Mathematica.

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

enter image description here

Bob Hanlon

Posted 2013-08-14T16:02:37.270

Reputation: 95 281