Average Error: 30.3 → 17.2
Time: 3.3s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.4571744152834948 \cdot 10^{+127}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.6130609402823183 \cdot 10^{-296}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.3378356563173365 \cdot 10^{-270}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 9.88552434217187 \cdot 10^{+29}:\\ \;\;\;\;\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.4571744152834948e+127

    1. Initial program 54.8

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

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

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

    if -1.4571744152834948e+127 < re < 1.6130609402823183e-296 or 1.3378356563173365e-270 < re < 9.88552434217187e+29

    1. Initial program 20.6

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

    if 1.6130609402823183e-296 < re < 1.3378356563173365e-270

    1. Initial program 35.0

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

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

    if 9.88552434217187e+29 < re

    1. Initial program 41.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.4571744152834948 \cdot 10^{+127}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 1.6130609402823183 \cdot 10^{-296}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{elif}\;re \le 1.3378356563173365 \cdot 10^{-270}:\\ \;\;\;\;\log im\\ \mathbf{elif}\;re \le 9.88552434217187 \cdot 10^{+29}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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