Average Error: 31.0 → 17.5
Time: 2.9s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.4560431567635725 \cdot 10^{+67}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.830714642883144 \cdot 10^{-300}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4305437478917951 \cdot 10^{-254}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 3.2126680732389842 \cdot 10^{+31}:\\ \;\;\;\;\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 < -1.4560431567635725e+67

    1. Initial program 45.7

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

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

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

    if -1.4560431567635725e+67 < re < -8.830714642883144e-300 or 1.4305437478917951e-254 < re < 3.2126680732389842e+31

    1. Initial program 20.9

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

    if -8.830714642883144e-300 < re < 1.4305437478917951e-254

    1. Initial program 32.3

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

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

    if 3.2126680732389842e+31 < re

    1. Initial program 42.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.4560431567635725 \cdot 10^{+67}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.830714642883144 \cdot 10^{-300}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.4305437478917951 \cdot 10^{-254}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 3.2126680732389842 \cdot 10^{+31}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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