6
$\begingroup$

I was trying to do understand how N works in Mathematica, but I couldn't understand the followings:

Table[N[Log[DedekindEta[(I b*1/1000)/(2 π)]]], {b, 1, 5}]
Table[N[Log[DedekindEta[(I b*1/1000)/(2 π)]], 10], {b, 1, 5}]
Table[N[Log[DedekindEta[(I b*1/1000)/(2 π)]]], {b, 1, 5, 0.5}]
Table[N[Log[DedekindEta[(I b*1/1000)/(2 π)]], 10], {b, 1, 5, 0.5}]
N[Log[DedekindEta[(I 1*1/1000)/(2 π)]], 10]

The results of above codes are

{Indeterminate, Indeterminate, -544.488, -407.554, -325.419}
{-1640.561251, -818.4407908, -544.4878456, -407.5538477, -325.4187162}
{Indeterminate, Indeterminate, Indeterminate, -654.059, -544.488,-466.235, -407.554, -361.92, -325.419}
{Indeterminate, Indeterminate, Indeterminate, -654.059, -544.488,-466.235, -407.554, -361.92, -325.419}
-1640.561251

First, I can't see why Indeterminate shows up even when the actual results are not that big or small. (Sometimes the precision can be helpful as you see in the 1st and 2nd lines, but not always as you see in the 3rd and 4th lines.)

Second, I can't understand why the first component of the fourth code doesn't give me -1640.561251 as the fifth code does. For me it looks like there is no difference at all.

In summary, I would really appreciate if you let me know how to avoid Indeterminate when using N in general!

$\endgroup$
1

3 Answers 3

5
$\begingroup$

The probable reason is underflow or internal machine rounding error. First evaluate to arbitrary precision:

Table[N@N[Log[DedekindEta[(I b*1/1000)/(2 π)]], $MachinePrecision], {b, 1, 5}]
(* {-1640.56, -818.441, -544.488, -407.554, -325.419}  *)

Note that for the iterator {b, 1, 5, 0.5}, the values of b are machine-precision numbers:

Table[b, {b, 1, 5, 0.5}]
(*  {1., 1.5, 2., 2.5, 3., 3.5, 4., 4.5, 5.}  *)

The corresponding values of Log@DedekindEta evaluate to Indeterminate before N has a chance to work on the values:

Table[N[Log[DedekindEta[(I b*1/1000)/(2 π)]], 32], {b, 1, 5, 0.5}]
(*
  {Indeterminate, Indeterminate, Indeterminate, -654.059, -544.488, 
   -466.235, -407.554, -361.92, -325.419}
*)
$\endgroup$
1
  • $\begingroup$ Thanks a lot! Considering your answer, I replaced 0.5 with 1/2 to avoid machine-precision numbers then it worked! $\endgroup$
    – StudyHard
    Commented Jun 12, 2017 at 22:01
8
$\begingroup$

There are many good discussions of precision and N. But, I couldn't find the following succinctly stated in other answers:

  1. Expressions that mix machine precision numbers and arbitrary precision numbers always evaluate to a machine number. You can think of machine precision numbers as being the lowest possible precision one can use.

  2. Expressions evaluated using machine precision numbers have no error tracking. The result will not give any indication of which digits in the result are accurate, and it is entirely possible that none of the digits are accurate.

  3. Expressions evaluated using only arbitrary precision numbers and exact numbers (i.e., no machine precision numbers) will have their numerical errors tracked during the evaluation process, and the result will be given with a conservative estimate of the precision achieved accounting for those numerical errors.

  4. If one uses N[expr, prec], where prec is a number (not the variable MachinePrecision), then Mathematica will attempt to return a result with precision prec. If the numerical error tracking process decides that the error has gotten too big to achieve the desired precision goal, than it will increase the working precision in order to achieve the desired precision goal. The amount of extra precision that Mathematica will use is limited by the variable $MaxExtraPrecision.

Now, @MichaelE2 has already explained the main issues, but let me repeat them below:

  1. For your first table you use N[exact], and so only machine precision is used, and a naive machine precision computation of your expression encounters underflow, and so you get Indeterminate in these cases.

  2. For your second table, you use N[exact, 10], and so Mathematica works extra hard by using an increased working precision so that it can return a result with a correct precision of 10.

  3. For you third and fourth tables, your table iterator actually evaluates to a machine precision number, and so what is evaluated is N[machineNumber] and N[machineNumber, 10]. Since the number is already a machine number, N doesn't do anything.

  4. For your last evaluation, you again use N[exact, 10] and so Mathematica returns a result correct to 10 digits.

$\endgroup$
1
  • $\begingroup$ Thanks for your detailed explanation on each line! $\endgroup$
    – StudyHard
    Commented Jun 12, 2017 at 22:02
2
$\begingroup$
DedekindEta[(I 1/1000)/(2 π)]] 

(*

0

*)

and then N@Log[%] gives Indeterminate.

(Version 10.4.)

$\endgroup$
2
  • $\begingroup$ I get Log[0] is -Infinity, when evaluated directly. -- Oops, wait, Log[0.] evaluates to Indeterminate. $\endgroup$
    – Michael E2
    Commented Jun 12, 2017 at 20:54
  • $\begingroup$ What version are you using? On V11.1.1 (Mac), DedekindEta[(I 1/1000)/(2 \[Pi])] does not evaluate to zero. $\endgroup$
    – Michael E2
    Commented Jun 12, 2017 at 20:58

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.