Average Error: 30.7 → 17.0
Time: 3.1s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -3.3387975659405454 \cdot 10^{+25}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.81636618488538 \cdot 10^{+52}:\\ \;\;\;\;\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.3387975659405454e+25

    1. Initial program 40.8

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

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

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

    if -3.3387975659405454e+25 < re < 1.81636618488538e+52

    1. Initial program 21.7

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

    if 1.81636618488538e+52 < re

    1. Initial program 44.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -3.3387975659405454 \cdot 10^{+25}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.81636618488538 \cdot 10^{+52}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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