Average Error: 31.5 → 17.5
Time: 3.9s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -6.361970019444908 \cdot 10^{+117}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 7.593356150167312 \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 3 regimes
  2. if re < -6.361970019444908e+117

    1. Initial program 53.2

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

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

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

    if -6.361970019444908e+117 < re < 7.593356150167312e+113

    1. Initial program 21.6

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

    if 7.593356150167312e+113 < re

    1. Initial program 52.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -6.361970019444908 \cdot 10^{+117}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 7.593356150167312 \cdot 10^{+113}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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