# Can I have Mathematica show intermediate forms before final evaluation?

If I have

x = 2


and I want to evaluate

y = x^2


I would like to the output to show

y = (2)^2


before evaluating to 4.

• Define y[x_] := x^2 // HoldForm and then use y to get 2^2 and y // ReleaseHold to get 4. – Boson Mar 21 '14 at 17:25
• Take a look at Defer too. – Kuba Mar 21 '14 at 17:48

I would recommend to look into new functions that are already available on Raspberry Pi and you have something to look forward to in a general future release: Activate, Inactive and Inactivate.

They are a very powerful way to transform the code and expressions in the way you need. For example.

f[x_] := Inactive[Power][x, 2]

y == f


y == 2^2

y == Activate@f


y == 4

You can make a lot of things including identity tables:

Table[f[k] == Activate[f[k]], {k, 0, 3}] // Column // TraditionalForm Table[Inactive[Sin][k \[Pi]/6] == Sin[k \[Pi]/6], {k, 0, 3}] // Column // TraditionalForm But in your specific case you of course could simply do something like:

Table[Superscript[k, 2] == k^2, {k, 0, 3}] // Column // TraditionalForm • I'm happy it seems to work as I've imagined it works :) Can't wait to test it. – Kuba Mar 21 '14 at 20:33

As Boson suggested, HoldForm and ReleaseHold can be pressed into service to accomplish what you ask. Here is how you can use them.

ySq[x_] := Module[{y}, Row[{"y = ", y = HoldForm[x^2], " = ", ReleaseHold[y]}]]
Column[ySq /@ Range]

y = 1^2 = 1
y = 2^2 = 4
y = 3^2 = 9
y = 4^2 = 16
y = 5^2 = 25


ySq can serve as a model for defining other functions that can produce similar expository output.