Average Error: 30.9 → 17.5
Time: 2.9s
Precision: 64
Internal Precision: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.366350354694201 \cdot 10^{+18}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 2.3360666207130245 \cdot 10^{+103}:\\ \;\;\;\;\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 < -2.366350354694201e+18

    1. Initial program 39.8

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

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

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

    if -2.366350354694201e+18 < re < 2.3360666207130245e+103

    1. Initial program 22.3

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

    if 2.3360666207130245e+103 < re

    1. Initial program 49.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.366350354694201 \cdot 10^{+18}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{elif}\;re \le 2.3360666207130245 \cdot 10^{+103}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\ \mathbf{else}:\\ \;\;\;\;\log re\\ \end{array}\]

Reproduce

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