Average Error: 30.2 → 18.0
Time: 3.4s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -6.92029815203542 \cdot 10^{+145}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -6.947967300568486 \cdot 10^{-177}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le -2.4458756963213023 \cdot 10^{-235}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.0074545562893787 \cdot 10^{-220}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.639720186575044 \cdot 10^{-191}:\\ \;\;\;\;\log re\\ \mathbf{elif}\;re \le 2.045862224123966 \cdot 10^{+89}:\\ \;\;\;\;\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.92029815203542e+145 or -6.947967300568486e-177 < re < -2.4458756963213023e-235

    1. Initial program 51.0

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

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

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

    if -6.92029815203542e+145 < re < -6.947967300568486e-177 or -2.4458756963213023e-235 < re < 1.0074545562893787e-220 or 1.639720186575044e-191 < re < 2.045862224123966e+89

    1. Initial program 19.3

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

    if 1.0074545562893787e-220 < re < 1.639720186575044e-191 or 2.045862224123966e+89 < re

    1. Initial program 45.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -6.92029815203542 \cdot 10^{+145}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -6.947967300568486 \cdot 10^{-177}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le -2.4458756963213023 \cdot 10^{-235}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.0074545562893787 \cdot 10^{-220}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.639720186575044 \cdot 10^{-191}:\\ \;\;\;\;\log re\\ \mathbf{elif}\;re \le 2.045862224123966 \cdot 10^{+89}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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