Step-by-step definite integration in 2D

Is possible to extend this answer in order to perform definite integrals in two dimensions step-by-step?

OK, In response to the comment, I did a try and I have by now the following:

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


I think that the former approach could work,but any suggestion for improvement is welcome.

• Perhaps you could try something on your own and report back when you run into trouble? Feb 3, 2017 at 22:02
• The problem is that I don't know how to get started in the right direction. Feb 3, 2017 at 22:04
• How can I post Mathematica code dysplaying properly? Feb 3, 2017 at 22:15
• I guess if you did it by hand you would treat one integration variable at a time wouldn't you? Feb 3, 2017 at 22:45
• But you'd probably have the gaussian integral as a special case. Another special case is where the integrals are separable. Feb 3, 2017 at 23:56

You can always just compute the integrals in a nested fashion.

Disclaimer: This will not always work! We need to ensure continuity of the inner integral to apply the fundamental theorem of calculus. See here for more details.

Here's a quick mock up of how to do this, calling Wolfram Alpha to get the steps each time:

IntegralSteps[expr_, {x_, a_, b_}, {y_, c_, d_}] :=
Module[{inner, outer, innersteps, outersteps},
inner = Integrate[expr, {x, a, b}];
outer = Integrate[inner, {y, c, d}];

innersteps = IntegralSteps[expr, {x, a, b}];
outersteps = IntegralSteps[inner, {y, c, d}];

Style["Compute the integral:", Gray],
HoldForm[Integrate[expr, {x, a, b}, {y, c, d}]],
Style["First, compute the inner integral:", Gray],
Row[{HoldForm[Integrate[expr, {x, a, b}]] == inner, PopupWindow[Button["Show steps"], innersteps]}, Spacer[10]],
Style["Substitute the result:", Gray],
HoldForm[Integrate[expr, {x, a, b}, {y, c, d}] == Integrate[#, {y, c, d}]]&[inner],
Style["Compute the next integral:", Gray],
Row[{HoldForm[Integrate[#, {y, c, d}]]&[inner] == outer, PopupWindow[Button["Show steps"], outersteps]}, Spacer[10]],
Style["Summarize:", Gray],
HoldForm[Integrate[expr, {x, a, b}, {y, c, d}]] == outer
},
Alignment -> Left,
Dividers -> {{}, {False,{False,Gray},False}},
Spacings -> {{}, {Automatic, {Automatic, 3}}}
] /. i_Integrate :> Style[i, ScriptLevel -> 0]
]

IntegralSteps[expr_, {x_, a_, b_}] :=
IntegralSteps[ToString[Unevaluated[Integrate[expr, {x, a, b}]], InputForm]]

IntegralSteps[str_String] :=
WolframAlpha[str,{{"Input",2},"Content"},PodStates->{"Input__Step-by-step solution"}]


One could extend this code to work for an $nD$ integral.

Here's a GIF of it in action:

IntegralSteps[x y, {x, 0, 1}, {y, 0, 1}]


• Unfortunately, I am using Mathematica 9 and by some reason the pop-up menu that display the steps is not working. Thanks a lot for answer. Feb 4, 2017 at 3:20
• @user3116936 Hmm, I just tried it in Mathematica 9 and it worked fine for me. Feb 4, 2017 at 15:40