Average Error: 30.6 → 16.9
Time: 2.8s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.219198831026942 \cdot 10^{+122}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -1.3987143113439338 \cdot 10^{-265}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 9.615181704877145 \cdot 10^{-268}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5569157992329785 \cdot 10^{+79}:\\ \;\;\;\;\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.219198831026942e+122

    1. Initial program 54.2

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

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

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

    if -1.219198831026942e+122 < re < -1.3987143113439338e-265 or 9.615181704877145e-268 < re < 1.5569157992329785e+79

    1. Initial program 19.9

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

    if -1.3987143113439338e-265 < re < 9.615181704877145e-268

    1. Initial program 30.9

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

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

    if 1.5569157992329785e+79 < re

    1. Initial program 46.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.219198831026942 \cdot 10^{+122}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -1.3987143113439338 \cdot 10^{-265}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 9.615181704877145 \cdot 10^{-268}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.5569157992329785 \cdot 10^{+79}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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