Average Error: 30.8 → 16.8
Time: 3.8s
Precision: 64
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -6.35141706346629 \cdot 10^{+142}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 8.020319511765941 \cdot 10^{-261}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 7.607752075086984 \cdot 10^{-180}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 9.271000483643551 \cdot 10^{+124}:\\ \;\;\;\;\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 < -6.35141706346629e+142

    1. Initial program 59.3

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

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

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

    if -6.35141706346629e+142 < re < 8.020319511765941e-261 or 7.607752075086984e-180 < re < 9.271000483643551e+124

    1. Initial program 19.2

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

    if 8.020319511765941e-261 < re < 7.607752075086984e-180

    1. Initial program 29.8

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

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

    if 9.271000483643551e+124 < re

    1. Initial program 54.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -6.35141706346629 \cdot 10^{+142}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 8.020319511765941 \cdot 10^{-261}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 7.607752075086984 \cdot 10^{-180}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 9.271000483643551 \cdot 10^{+124}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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