Average Error: 31.8 → 18.3
Time: 1.9s
Precision: binary64
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.05653654456576854 \cdot 10^{139}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.39501769279737873 \cdot 10^{-165}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le -2.5556997558112552 \cdot 10^{-228}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.98923595946216538 \cdot 10^{-268}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le -6.9728479796481374 \cdot 10^{-305}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.0407504367576015 \cdot 10^{92}:\\ \;\;\;\;\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 < -1.05653654456576854e139 or -8.39501769279737873e-165 < re < -2.5556997558112552e-228

    1. Initial program 52.3

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

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

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

    if -1.05653654456576854e139 < re < -8.39501769279737873e-165 or -2.5556997558112552e-228 < re < -8.98923595946216538e-268 or -6.9728479796481374e-305 < re < 1.0407504367576015e92

    1. Initial program 20.0

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

    if -8.98923595946216538e-268 < re < -6.9728479796481374e-305

    1. Initial program 31.3

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

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

    if 1.0407504367576015e92 < re

    1. Initial program 50.9

      \[\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 simplification18.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.05653654456576854 \cdot 10^{139}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.39501769279737873 \cdot 10^{-165}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le -2.5556997558112552 \cdot 10^{-228}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le -8.98923595946216538 \cdot 10^{-268}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{elif}\;re \le -6.9728479796481374 \cdot 10^{-305}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 1.0407504367576015 \cdot 10^{92}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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