I like the typesetting of Root objects. For example:


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

  • $\begingroup$ By "typesetting" do you mean the 2D boxes (as shown in Bob's answer), or a Root[…] expression as shown in Akku14's answer? $\endgroup$
    – xzczd
    Dec 19, 2020 at 4:21
  • 1
    $\begingroup$ @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. $\endgroup$
    – user13892
    Dec 19, 2020 at 4:37
  • $\begingroup$ It would sometimes be nice to represent quadratic roots as Root objects to avoid numerical instability. $\endgroup$
    – John Doty
    Dec 19, 2020 at 17:54

3 Answers 3

expr = 3 - Sqrt[2];

Use ToNumberField to convert the expression to an AlgebraicNumber

expr2 = expr // ToNumberField

enter image description here

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] *)
  • $\begingroup$ Nice idea, but this does'nt answer the question " I like the typesetting of Root objects" $\endgroup$
    – Akku14
    Dec 19, 2020 at 3:58

You can discover the polynomial with MinimalPolynomial:

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

(*    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.

  • $\begingroup$ 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? $\endgroup$
    – user13892
    Dec 18, 2020 at 18:47
  • $\begingroup$ 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. $\endgroup$
    – Roman
    Dec 18, 2020 at 19:09
  • 2
    $\begingroup$ 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. $\endgroup$
    – Bob Hanlon
    Dec 18, 2020 at 20:46
  • $\begingroup$ @BobHanlon that looks like the perfect solution! Please write it as a solution so I can upvote it. $\endgroup$
    – Roman
    Dec 18, 2020 at 20:54

You can wrap HoldForm only around Root.


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]   *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.