Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was exploring the problem presented by another question, when I ran into some behavior of Mathematica's arbitrary precision arithmetic engine that perplexes me.

Here is what I was doing

poly = 64 x^7 - 112 x^5 - 8 x^4 + 56 x^3 + 8 x^2 - 7 x - 1;
solns = Solve[poly == 0, x, Reals]

{{x -> -(1/2)}, {x -> 1},
{x -> Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 1]},
{x -> Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 2]},
{x -> Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 3]},
{x -> Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 4]},
{x -> Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5]}}

root[n_] := Cos[2 n Pi/11];
poly == 0 /. x -> root[1]

True

N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] == root[1], 20]

True

N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] - root[1], 20]

N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating -Cos[(2 [Pi])/11]+Root[1+6 #1-12 #1^2-32 #1^3+16 #1^4+32 #1^5&,5,0].

0.*10^-70

PossibleZeroQ[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] -  root[1]]

PossibleZeroQ::ztest1: "Unable to decide whether numeric quantity -Cos[(2\[Pi])/11]+Root[1+6\ #1-12\ #1^2-32\ #1^3+16\ #1^4+32\ #1^5&,5,0] is equal to zero. Assuming it is."

True

It would appear that Mathematica can compare the values of Root[1+6 #1+..+32 #1^5&,5] and root[1] more easily than it can determine their difference. I realize differences lose precision very rapidly, but I still find this perplexing.

Finally I tried raising the value of $MaxExtraPrecision, but still no joy.

Block[{$MaxExtraPrecision = 10000}, 
  N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] - root[1], 20]]  

N::meprec: "Internal precision limit $MaxExtraPrecision = 10000.` reached while evaluating -Cos[(2\[Pi])/11]+Root[1+6\ #1-12\ #1^2-32\ #1^3+16\ #1^4+32\ #1^5&,5,0]"

0.*10^-10020

Larger values of $MaxExtraPrecision only made the computation take longer before it failed.

Could there be something wrong with the algorithm used to compute a difference to high precision in the case where the two terms are essentially the identical?

Edit

From the first answer posted, I realize I should ask my question more carefully. I am not sure how Mathematica estimates the precision of very small numbers, which can be a tricky business. Perhaps, that's my problem. For a difference that is expected to be zero or very close, should I be asking for evaluation in terms of accuracy rather than precision?

I note that

N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] - root[1], {∞, 1000}]  

returns 0.*10^-1001 with no error message. For this return value, I get

Accuracy[0.*10^-1001]

1000.

Precision[0.*10^-1001]

0.

This is consistent with the behavior that bothers me, but why is the precision zero?

WRI defines precision and accuracy as follows:

Precision[x]: the total number of significant decimal digits in x

Accuracy[x]: the number of significant decimal digits to the right of the decimal point in x

In my mind, these definitions are not consistent with the accuracy and precision values shown above. The definitions imply that accuracy will always be less than precision.

share|improve this question
    
It may be of interest that MMA can recognize the equivalence of Root[1] and Root[1 + 6 #1 - ... &, 5]: applying MinimalPolynomial to both of these yields the same expression. Equivalently, applying Root[MinimalPolynomial[#], 1]& to their difference--rather than N--produces $0$ (and you can just as easily check that this is the only root). –  whuber Jan 5 '13 at 18:10
add comment

1 Answer

up vote 8 down vote accepted

The exact equality comparison returns unevaluated.

Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] == root[1]

(* Out[900]= 
Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] == 
 Cos[(2 \[Pi])/11] *)

The numerical values agree to all significant digits.

N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5], 20]

(* Out[902]= 0.84125353283118116886 *)

N[root[1], 20]

(* Out[903]= 0.84125353283118116886 *)

This should explain why the numerical comparison gave True.

As for the max precision stuff, notice that you cannot get any precision in the difference since they are in fact equal. This not being something mathematica detects, it keeps ramping precision in an effort to get some actual digits.

You might instead tell N to give 20 digits of Accuracy (in the Mathematica meaning of that term). Then it will give up once it has attained 20 correct digits to the right of the decimal point.

N[Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] - 
  root[1], {Infinity, 20}]

(* Out[906]= 0.*10^-20 *)

Also note that you can convert root[1] to the algebraic form using RootReduce.

RootReduce[root[1]]

(* Out[919]= Root[1 + 6 #1 - 12 #1^2 - 32 #1^3 + 16 #1^4 + 32 #1^5 &, 5] *)

All that said, I'm not sure if I have addressed your question. I gather you think something incorrect is happening. But I'm not clear on what that perceived something is, and moreover I'm confident nothing inappropriate is in fact taking place in the computations you show.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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