Average Error: 30.6 → 17.0
Time: 3.7s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.610120343778248 \cdot 10^{+40}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 6.339057535698283 \cdot 10^{-246}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4621303669194703 \cdot 10^{-218}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5215402511937908 \cdot 10^{+94}:\\ \;\;\;\;\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.610120343778248e+40

    1. Initial program 42.3

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

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

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

    if -2.610120343778248e+40 < re < 6.339057535698283e-246 or 1.4621303669194703e-218 < re < 1.5215402511937908e+94

    1. Initial program 20.8

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

    if 6.339057535698283e-246 < re < 1.4621303669194703e-218

    1. Initial program 33.2

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

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

    if 1.5215402511937908e+94 < re

    1. Initial program 49.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.610120343778248 \cdot 10^{+40}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 6.339057535698283 \cdot 10^{-246}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4621303669194703 \cdot 10^{-218}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5215402511937908 \cdot 10^{+94}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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