Average Error: 31.9 → 17.6
Time: 1.6s
Precision: binary64
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1169736649081899.75:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -5.434411537566742 \cdot 10^{-154}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le 3.29968623641821832 \cdot 10^{-306}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.0570666050233334 \cdot 10^{116}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\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 < -1169736649081899.75

    1. Initial program 42.3

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

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

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

    if -1169736649081899.75 < re < -5.434411537566742e-154 or 3.29968623641821832e-306 < re < 1.0570666050233334e116

    1. Initial program 19.4

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

    if -5.434411537566742e-154 < re < 3.29968623641821832e-306

    1. Initial program 30.6

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

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

    if 1.0570666050233334e116 < re

    1. Initial program 54.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1169736649081899.75:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -5.434411537566742 \cdot 10^{-154}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le 3.29968623641821832 \cdot 10^{-306}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.0570666050233334 \cdot 10^{116}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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