How to Hold/Defer only one (only given) level?

Is it possible to Hold/Defer some of outer expressions, having evaluates inner ones?

For example, I want to prepare a table of expression values, like this

Table[Defer[Sin[x]^2 + Cos[x]^2] == Sin[x]^2 + Cos[x]^2, {x, 0, 1, 0.1}] // TableForm

Currently this displays left hand sides as

Sin[x]^2 + Cos[x]^2

but can I have x-s evaluated/substituted?

UPDATE

Or just simpler example.

Suppose I write

x = 12
Defer[Sin[x]^2 + Cos[x]^2] == Sin[x]^2 + Cos[x]^2

which gives

12
Sin[x]^2 + Cos[x]^2 == 1.

but can I have

12
Sin^2 + Cos^2 == 1.
• Are you working on V10? – Kuba Nov 25 '14 at 8:06
• No, I have V9. What advantages V10 has? – Suzan Cioc Nov 25 '14 at 12:28
• @SuzanCioc v10 has a set of functions exactly for this. Please check Inactive. – Silvia Nov 25 '14 at 12:37
• Incredible. Why did they wait 9 versions? – Suzan Cioc Nov 25 '14 at 12:50

Your can use Replace* inside Hold or Deffer like this:

x = 12;
test = Defer[Sin[x]^2 + Cos[x]^2] == Sin[x]^2 + Cos[x]^2

Sin[x]^2 + Cos[x]^2 == 1.

Block[{x}, test /. x -> y] /. y -> x

Sin[12.]^2 + Cos[12.]^2 == 1.

Just idea, no doubt better approach can be found.

• It seems to be even a bit more simple than that: Defer[Sin[x]^2 + Cos[x]^2] == Sin[x]^2 + Cos[x]^2 /.x -> 12// Simplify yields what you need. – Alexei Boulbitch Nov 25 '14 at 8:41
• I assume that x has a value, so 12->12. – user18792 Nov 25 '14 at 9:18
• In my code x has no value. I do not see your point. – Alexei Boulbitch Nov 25 '14 at 9:26
• Not my point. It is put in the formulation of the task: x=12; – user18792 Nov 25 '14 at 9:34
• Nice, but Alexei's solution in its present form doesn't work in a table, i.e. Table[Defer[Sin[x]^2 + Cos[x]^2] == Sin[x]^2 + Cos[x]^2 /. x -> 12 // Simplify, {x, 0, 1, 0.1}] // TableForm – Chris Degnen Nov 25 '14 at 9:41

Mapping Hold or HoldForm over all the elements effectively freezes the expression for easier manipulation. (This method was used in R. Maeder's Programming in Mathematica, page 137.)

x = 12.;
Replace[Map[HoldForm, Defer[Sin[x]^2 + Cos[x]^2], Infinity] ,
HoldForm[x] -> HoldForm] == Sin[x]^2 + Cos[x]^2

Sin^2+Cos^2==1.

And in a table:

Table[
ReplaceAll[Map[HoldForm, Defer[Sin[x]^2 + Cos[x]^2], Infinity] ,
HoldForm[x] -> HoldForm[Evaluate[x]]] == Sin[x]^2 + Cos[x]^2,
{x, 0, 1, 0.1}] // TableForm

Simpler method

Table[With[{y = x}, Defer[Sin[y]^2 + Cos[y]^2] == Sin[x]^2 + Cos[x]^2],
{x, 0, 1, 0.1}] // TableForm

You could also use Activate/Inactivate:

TableForm @ Activate @ Table[
Inactivate @ Defer[Sin[x]^2+Cos[x]^2] == Sin[x]^2+Cos[x]^2,
{x, 0, 1, 0.1}
] //TeXForm

$\begin{array}{c} \sin ^2(0.)+\cos ^2(0.)=1. \\ \sin ^2(0.1)+\cos ^2(0.1)=1. \\ \sin ^2(0.2)+\cos ^2(0.2)=1. \\ \sin ^2(0.3)+\cos ^2(0.3)=1. \\ \sin ^2(0.4)+\cos ^2(0.4)=1. \\ \sin ^2(0.5)+\cos ^2(0.5)=1. \\ \sin ^2(0.6)+\cos ^2(0.6)=1. \\ \sin ^2(0.7)+\cos ^2(0.7)=1. \\ \sin ^2(0.8)+\cos ^2(0.8)=1. \\ \sin ^2(0.9)+\cos ^2(0.9)=1. \\ \sin ^2(1.)+\cos ^2(1.)=1. \\ \end{array}$