Average Error: 31.1 → 18.0
Time: 3.3s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.0335816615218086 \cdot 10^{+28}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.1537126034956638 \cdot 10^{-166}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.1554937198802627 \cdot 10^{-236}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 2.28335840082869 \cdot 10^{+113}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 4 regimes
  2. if re < -2.0335816615218086e+28

    1. Initial program 42.0

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Taylor expanded around -inf 11.6

      \[\leadsto \log \color{blue}{\left(-1 \cdot re\right)}\]
    3. Simplified11.6

      \[\leadsto \log \color{blue}{\left(-re\right)}\]

    if -2.0335816615218086e+28 < re < -2.1537126034956638e-166 or 2.1554937198802627e-236 < re < 2.28335840082869e+113

    1. Initial program 18.0

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]

    if -2.1537126034956638e-166 < re < 2.1554937198802627e-236

    1. Initial program 30.8

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Taylor expanded around 0 35.4

      \[\leadsto \log \color{blue}{im}\]

    if 2.28335840082869e+113 < re

    1. Initial program 52.3

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Taylor expanded around inf 8.1

      \[\leadsto \log \color{blue}{re}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification18.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.0335816615218086 \cdot 10^{+28}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -2.1537126034956638 \cdot 10^{-166}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 2.1554937198802627 \cdot 10^{-236}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 2.28335840082869 \cdot 10^{+113}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

herbie shell --seed 2019068 
(FPCore (re im)
  :name "math.log/1 on complex, real part"
  (log (sqrt (+ (* re re) (* im im)))))