Average Error: 30.8 → 10.5
Time: 14.1s
Precision: 64
Ground Truth: 128
\[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.1110224014220058 \cdot 10^{+125}:\\ \;\;\;\;\log \left(-re\right)\\ \mathbf{if}\;re \le -1.219585437824595 \cdot 10^{-174}:\\ \;\;\;\;\log \left(\sqrt{re \cdot re + im \cdot im}\right)\\ \mathbf{if}\;re \le 1.1913008854416164 \cdot 10^{-287}:\\ \;\;\;\;\log im\\ \mathbf{if}\;re \le 3.2338231936094466 \cdot 10^{+51}:\\ \;\;\;\;\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.1110224014220058e+125

    1. Initial program 54.3

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log \left(-1 \cdot re\right)\]
    3. Taylor expanded around -inf 0

      \[\leadsto \log \color{blue}{\left(-1 \cdot re\right)}\]
    4. Applied simplify 0

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

    if -1.1110224014220058e+125 < re < -1.219585437824595e-174 or 1.1913008854416164e-287 < re < 3.2338231936094466e+51

    1. Initial program 18.9

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

    if -1.219585437824595e-174 < re < 1.1913008854416164e-287

    1. Initial program 29.1

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log im\]
    3. Taylor expanded around 0 0

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

    if 3.2338231936094466e+51 < re

    1. Initial program 45.0

      \[\log \left(\sqrt{re \cdot re + im \cdot im}\right)\]
    2. Applied taylor 0

      \[\leadsto \log re\]
    3. Taylor expanded around inf 0

      \[\leadsto \log \color{blue}{re}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Total time: 14.1s Debug log

Please include this information when filing a bug report:

herbie --seed '#(3077355129 3040876750 603735522 1810249925 4069650757 1436287769)'
(FPCore (re im)
  :name "math.log/1 on complex, real part"
  (log (sqrt (+ (* re re) (* im im)))))