# How can I make Table of Defer[Sqrt[3i] - k Sqrt[3j]]?

I am trying to make a Table of expressions Defer[Sqrt[3i] + 2 Sqrt[3j]], e.g

Defer[Sqrt[27 ] + 2 Sqrt[108]] == Sqrt[27 ] + 2 Sqrt[108]

With Table, I tried

TableForm@
Activate@
Table[Inactivate@Defer[Sqrt[3 i] + 2 Sqrt[3 j]] ==
Sqrt[3 i] + 2 Sqrt[3 j] , {i, 1, 20}, {j, 21, 40}]

How can I tell Mathematica Out put in the form

Sqrt[27] + 2 Sqrt[108] == 3 Sqrt[3] + 12 Sqrt[3] == 15 Sqrt[3]

func = Defer[Sqrt[#] + 2 Sqrt[#2]] == (Defer[# + #2] &)[Sqrt[#], 2 Sqrt[#2]] ==
Sqrt[#] + 2 Sqrt[#2] &;

Table[func[3 i, 3 j], {i, 20}, {j, 21, 40}] // TableForm

Just keep in mind that Defer is nothing but a function with HoldAll attribute that will disappear when being output in notebook (to be more precise, when it passes through MakeBoxes stage).

• How can I remove when 3 i and 3j get the same value? Commented Aug 6, 2023 at 14:41
• @minhthien_2016 The simplest solution I can think of at the moment is using Nothing e.g. Table[If[i == j, Nothing, func[3 i, 3 j]], {i, 20}, {j, 20}] Commented Aug 7, 2023 at 0:05
• @xzczd Can I format like this Sqrt[27] + 2 Sqrt[108] == Sqrt[3*3^2] + 2 Sqrt[3*6^2] = 3 Sqrt[3] + 12 Sqrt[3] == 15 Sqrt[3]? Commented Aug 7, 2023 at 1:07
• @Laurenso It's possible, but more advanced, because evaluation like 3×3^2 doesn't happen internally, so you need something more than evaluation control: trans = Sqrt[#] /. {a_. Sqrt[b_] :> Sequence[b, a], a_ :> Sequence[1, a]} &; template = Defer[Sqrt[# #2^2] + 2 Sqrt[#3 #4^2]] &; func2 = template[trans[#], trans[#2]] &; func2[27, 108] Commented Aug 7, 2023 at 2:24
t0 = Table[
Inactivate[Sqrt[3 i] + 2 Sqrt[3 j]], {i, 1, 20}, {j, 21, 40}] /.
Inactive[Sqrt] :> Sqrt;

t1 = Table[
Inactivate[Sqrt[3 i] + 2 Sqrt[3 j]], {i, 1, 20}, {j, 21, 40}] /.
Inactive[Times] :> Times;

t2 = Table[Sqrt[3 i] + 2 Sqrt[3 j], {i, 1, 20}, {j, 21, 40}];

(MapThread[List, {t0, t1, t2}, 2] //
Replace[#, {a_, b_, c_} :> a == b == c, 2] &) /.
Inactive[Sqrt][a_] :> Sqrt[ToString@a] // TableForm

A sample of the output looks like:

• A bit different from OP's desired output, I'm afraid. In t0, Plus and Sqrt should be Inactivated, I think. Commented Aug 6, 2023 at 12:05
• Thanks for spotting. I wanted to retain the i and j so it is a bit different.
– Syed
Commented Aug 6, 2023 at 14:53