## Why does Log[Abs[#]] return a complex number?

0

For a nonzero number $$x$$, $$\log|x|$$ should be a real number. Why does the following NestList contain non-real numbers when no numbers involved are close to zero? Is it a bug?

In[1] := N /@ NestList[Log[Abs[#]] &, 2, 70]

Out[1] = {2., 0.693147, -0.366513, -1.00372, 0.0037146, -5.59549, 1.72196, \
0.543463, -0.609793, -0.494635, -0.703935, -0.35107, -1.04677, \
0.0457093, -3.08545, 1.1267, 0.119292, -2.12618, 0.754329, -0.281927, \
-1.26611, 0.235946, -1.44415, 0.367522, -1.00097, 0.000970967, \
-6.93722, 1.9369, 0.661089, -0.413867, -0.882212, -0.125323, \
-2.07686, 0.730856, -0.313538, -1.15983, 0.148277, -1.90867, \
0.646408, -0.436324, -0.829369, -0.18709, -1.67617, 0.516509, \
-0.660662, -0.414512, -0.880653, -0.127092, -2.06285, 0.724087, \
-0.322844, -1.13058, 0.122735, -2.09773, 0.740854, -0.299951, \
-1.20414, 0.185762, -1.68329, 0.52075, -0.652485, -0.426968, \
-0.851047, -0.161288, -1.82456 + 3.14159 I, 1.29006 - 1.04463 I,
0.5068 + 2.46093 I, 0.921308 - 1.7739 I, 0.692586 - 1.09177 I,
0.256904 + 2.1361 I, 0.766164 - 1.69049 I}


The following inputs also return the same result.

N /@ NestList[Log[ComplexExpand[Abs[#]]] &, 2, 70]
N /@ NestList[ComplexExpand[Log[Abs[#]]] &, 2, 70]
N /@ NestList[ComplexExpand[Re[Log[Abs[#]]]] &, 2, 70]
N /@ NestList[Log[Max[#, 0] + Max[-#, 0]] &, 2, 70]
N /@ NestList[Log[Sqrt[#^2]] &, 2, 70]


5Precision is lost. Try N[NestList[Log[Abs[#]] &, 2, 70], 20]. – user64494 – 2020-10-16T15:03:49.380

2Note also that Abs is evaluated on the exact input, but Log is not evaluated until you apply N[]. See for instance Last@NestList[Log[Abs[#]] &, 2, 70]. This is why the Abs[] does not correct a negative Log resulting from accumulated round-off error in your code. – Michael E2 – 2020-10-16T16:09:29.733

@michael-e2 Thanks. NestList[N[Log[Abs[#]]] &, 2, 70] works. – Yizhen Chen – 2020-10-17T16:15:38.637

Yes, it "works" in that it does not produce complex numbers, but there is significant round-off error after 30 or so iterations. After 60 or so iterations, none of the digits are correct. If you want accurate results, use @user64494's code. – Michael E2 – 2020-10-17T16:55:14.940