({{, (RefLink[RootApproximant, paclet:ref/RootApproximant])[x]
converts the number x to one of the "simplest" algebraic numbers that approximates it well.}, {, (RefLink[RootApproximant, paclet:ref/RootApproximant])[x,n]
finds an algebraic number of degree at most n that approximates x.}})

OpenersNotesSection(Spacer1)Details and Options

For degrees above 2, (RefLink[RootApproximant, paclet:ref/RootApproximant]) generates (RefLink[Root, paclet:ref/Root]) objects.

(RefLink[RootApproximant, paclet:ref/RootApproximant])[x] effectively tests the total number of bits in the description of x by successively higher-degree algebraic numbers, and returns the first case for which the number of bits is small.

Results from (RefLink[RootApproximant, paclet:ref/RootApproximant]) may not be unique.

(RefLink[MinimalPolynomial, paclet:ref/MinimalPolynomial]) yields the minimal polynomial for the result of (RefLink[RootApproximant, paclet:ref/RootApproximant]).

The option (RefLink[Method, paclet:ref/Method])->{"DegreeCost"->p} specifies an additional cost p to be used for each successively higher power in determining the "simplest" approximation.

OpenersPrimaryExamplesSection(Spacer1)Examples  (13)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Find a quadratic approximation to π:

RootApproximant[Pi,2]

N[%]

Find algebraic approximants of any order:

N[Sqrt[67]]

RootApproximant[%]

RootApproximant[3.1415926]

OpenersExampleSection1(Spacer1)Scope  (4)

There is no simple quadratic approximation to N[(Sqrt[2])+(Sqrt[3])]:

RootApproximant[N[Sqrt[2]+Sqrt[3]],2]

At degree 4, there is a simple answer, which turns out to be equal to (Sqrt[2])+(Sqrt[3]):

RootApproximant[N[Sqrt[2]+Sqrt[3]],4]

RootReduce[Sqrt[2]+Sqrt[3]]==%

Machine precision is not enough to recover the (RefLink[Root, paclet:ref/Root]) object equal to (Sqrt[2])+(Sqrt[3])+(Sqrt[5]):

RootApproximant[N[Sqrt[2]+Sqrt[3]+Sqrt[5]],8]

RootReduce[Sqrt[2]+Sqrt[3]+Sqrt[5]]==%

30 digits of precision suffice to recover the exact value here:

RootApproximant[N[Sqrt[2]+Sqrt[3]+Sqrt[5],30],8]

RootReduce[Sqrt[2]+Sqrt[3]+Sqrt[5]]==%

When given exact input, (RefLink[RootApproximant, paclet:ref/RootApproximant]) uses machine-precision approximations:

RootApproximant[E,3]

RootApproximant[N[E],3]

%%==%

(RefLink[RootApproximant, paclet:ref/RootApproximant]) works with complex numbers:

RootApproximant[N[Sqrt[2]+I],4]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)Method  (1)

Assigning additional cost to higher powers can be used to lower the degree of result:

RootApproximant[N[Pi,20],20,Method->{"DegreeCost"->#}]&/@{0,1,2,3}

MinimalPolynomial[#,x]&/@%

OpenersExampleSection3(Spacer1)Applications  (2)

Find successive algebraic approximations to π:

Table[RootApproximant[N[Pi,n]],{n,5}]

A complicated radical expression:

expr=(-1+(Sqrt[2])-(Sqrt[(1+2 (Sqrt[2])-s) (-1+s)])+s) (-1-(Sqrt[2])+(Sqrt[2]) s-(Sqrt[-1-2 (Sqrt[2])+2 (2+(Sqrt[2])-s) s]))-(-1-(Sqrt[2])+(Sqrt[2]) s+(Sqrt[-1-2 (Sqrt[2])+2 (2+(Sqrt[2])-s) s])) (-2-2 (Sqrt[2])+2 s+2 (Sqrt[1-(1/4) (((-1-(Sqrt[2])+(Sqrt[(1+2 (Sqrt[2])-s) (-1+s)])+s))^2)]));

Use (RefLink[FindRoot, paclet:ref/FindRoot]) to find the real root near 2.5:

x=s/.FindRoot[expr==0,{s,2.5},WorkingPrecision->100]//Chop

Use (RefLink[RootApproximant, paclet:ref/RootApproximant]) to find an algebraic number close to the root:

a=RootApproximant[x]

Check whether the result is a root of the original expression:

expr/.s->a//RootReduce

OpenersExampleSection4(Spacer1)Properties & Relations  (3)

(RefLink[RootApproximant, paclet:ref/RootApproximant]) gives a (RefLink[Root, paclet:ref/Root]) object close to a given algebraic number:

RootApproximant[Sqrt[2+Sqrt[3]]]

The (RefLink[Root, paclet:ref/Root]) object found may not be exactly equal to the input:

a=Sqrt[2+Sqrt[3+Sqrt[5+Sqrt[7]]]];
b=RootApproximant[a]

N[a-b,20]

Use (RefLink[RootReduce, paclet:ref/RootReduce]) to find exact (RefLink[Root, paclet:ref/Root]) object representations of algebraic numbers:

RootReduce[a]

Specifying a linear polynomial effectively finds a rational approximation to x:

RootApproximant[Pi,1]

(RefLink[Rationalize, paclet:ref/Rationalize]) also gives a rational approximation, but it need not be the same:

Rationalize[N[π],0]

Interestingly, the approximations can be found among continued fraction convergents:

FromContinuedFraction[ContinuedFraction[N[π],15]]

FromContinuedFraction[ContinuedFraction[π,15]]

Use (RefLink[LatticeReduce, paclet:ref/LatticeReduce]) to recognize linear combinations of more general functions:

v={1,ArcTan[1],ArcTan[1/5],ArcTan[1/239],1};

{a0,a1,a2,a3,a4}=Round[10^20 v];

b=LatticeReduce[{{1,0,0,0,-a0},{0,1,0,0,-a1},{0,0,1,0,-a2},{0,0,0,1,-a3}}]

The final relationship (π/4)==4(tan^(-1))((1/5))-(tan^(-1))((1/239)):

b[[1]].v

N[%]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

Recognizing an algebraic number may require using higher precision:

a=Sqrt[5+2 6^(1/3)];
b=RootApproximant[N[a],10]

The result is not equal to a:

RootReduce[a]==b

Providing the correct degree improves the chances of recognizing an algebraic number:

c=RootApproximant[N[a],6]

RootReduce[a]==c

A penalty may be used to lower the degree; here it does not help in recognizing the number:

RootApproximant[N[a],10,Method->{"DegreeCost"->#}]&/@{1,2,3}

N[%-a,20]

Using a higher-precision approximation allows the algebraic number to be recognized:

RootApproximant[N[a,25],10]

RootReduce[a]==%

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Rationalize, paclet:ref/Rationalize])  ▪  (RefLink[LatticeReduce, paclet:ref/LatticeReduce])  ▪  (RefLink[Root, paclet:ref/Root])  ▪  (RefLink[FindSequenceFunction, paclet:ref/FindSequenceFunction])  ▪  (RefLink[MinimalPolynomial, paclet:ref/MinimalPolynomial])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Algebraic Numbers, paclet:guide/AlgebraicNumbers])}, {▪(RefLinkPlain[Number Recognition, paclet:guide/NumberRecognition])}, {▪(RefLinkPlain[Algebraic Number Theory, paclet:guide/AlgebraicNumberTheory])}})}})