3
$\begingroup$

How come

N[ Log[ Cos[1]^2 + Sin[1]^2 ] ]

evaluates to 0. without any trouble, while

N[ Log[ Cos[1]^2 + Sin[1]^2 ], 1 ]

returns 0.*10^-67 but gives the warning message N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating Log[Cos[1]^2+Sin[1]^2] ?

It's not that I'm asking for more digits. As a matter of fact: it gives this warning independent of the amount of digits I ask.

$\endgroup$
2
  • $\begingroup$ I added some more details. $\endgroup$
    – Szabolcs
    Jul 1, 2021 at 11:06
  • $\begingroup$ Use N[Log[Cos[1]^2 + Sin[1]^2] // Simplify, 1] $\endgroup$
    – Bob Hanlon
    Jul 1, 2021 at 14:02

1 Answer 1

6
$\begingroup$

This is because N[expr] uses machine precision, without any guarantees on the number of correct digits in the result. It simply uses machine numbers (approximately 15 decimal digits) during the intermediate steps of the computation.

N[expr, n] is different. It does not just use n-digit numbers during computation. Instead, it tries to ensure that the result is correct to n digits, which typically requires more than n digits during the calculation. This warning means that the system was unable to ensure that the result is correct to as many digits as you requested, even after using 50 extra digits (the current limit) in intermediate calculations.

The failure likely has to do with the fact that the true result is zero, yet the error estimate ("number of correct digits") is relative, which is not applicable to zero. The system can't seem to decide if the result is just very small or truly zero.

Roughly speaking, in Mathematica "precision" refers to relative error and "accuracy" to absolute error. Computing absolute error is no problem with zero. We can make the error go away by requesting no n significant digits (precision) but n digits after to the right of the decimal point (accuracy). See N for the syntax.

N[Log[Cos[1]^2 + Sin[1]^2], {Infinity, 10}]
(* 0.*10^-10 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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