Average Error: 30.4 → 16.6
Time: 4.0s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -3.9080173825937296 \cdot 10^{+86}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 5.192758660905024 \cdot 10^{+70}:\\ \;\;\;\;\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 < -3.9080173825937296e+86

    1. Initial program 47.3

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

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

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

    if -3.9080173825937296e+86 < re < 5.192758660905024e+70

    1. Initial program 20.5

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

    if 5.192758660905024e+70 < re

    1. Initial program 45.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -3.9080173825937296 \cdot 10^{+86}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 5.192758660905024 \cdot 10^{+70}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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