# Is there a way to print simple roots as Root objects?

I like the typesetting of Root objects. For example:

3-Sqrt[2]+Sqrt[3]//RootReduce


But can I get the same root object with its typesetting for simple roots like follows?

3-Sqrt[2]//RootReduce

• By "typesetting" do you mean the 2D boxes (as shown in Bob's answer), or a Root[…] expression as shown in Akku14's answer? Dec 19 '20 at 4:21
• @xzczd 2D boxes as shown in Bob's answer for now. Since I want to quickly see the numerical value of the roots that are appearing in my code but still keep them as exact quantities. But if there is a way to get the Root expression to print like that without automatically turning into explicit roots that is even better. Dec 19 '20 at 4:37
• It would sometimes be nice to represent quadratic roots as Root objects to avoid numerical instability. Dec 19 '20 at 17:54

expr = 3 - Sqrt[2];


Use ToNumberField to convert the expression to an AlgebraicNumber

expr2 = expr // ToNumberField


The short form display of the AlgebraicNumber is similar to that of Root

RootReduce will convert the expression back to the radical representation.

expr2 // RootReduce

(* 3 - Sqrt[2] *)

• Nice idea, but this does'nt answer the question " I like the typesetting of Root objects" Dec 19 '20 at 3:58

You can discover the polynomial with MinimalPolynomial:

p = MinimalPolynomial[3 - Sqrt[2]]
(*    7 - 6 #1 + #1^2 &    *)

p[x]
(*    7 - 6 x + x^2    *)

Root[p, 1]
(*    3 - Sqrt[2]    *)


From the documentation of Root:

For linear and quadratic polynomials f[x], Root[f,k] is automatically reduced to explicit rational or radical form.

• Is there a way to prevent it from reducing to explicit form? I want the nice typesetting. Also is there a way to know in advance which root number of the MinimalPolynomial the root is? Dec 18 '20 at 18:47
• Is there a way to prevent it from reducing to explicit form? No, according to the quoted documentation. Is there a way to know in advance which root number? You may have to look at both roots and see which one fits. Dec 18 '20 at 19:09
• 3-Sqrt[2] // ToNumberField will provide an AlgebraicNumber with short form display similar to Root. RootReduce will convert the AlgebraicNumber back to the radical representation. Dec 18 '20 at 20:46
• @BobHanlon that looks like the perfect solution! Please write it as a solution so I can upvote it. Dec 18 '20 at 20:54

You can wrap HoldForm only around Root.

Edit

p = MinimalPolynomial[ro = 3 - Sqrt[2]];

a = Select[Range[10], Root[p, #] == ro &][[1]] // Quiet;

hf = HoldForm[Root][p, a]

(*   Root(#1^2-6 #1+7&,1)   *)

hf // ReleaseHold

(*   3 - Sqrt[2]   *)