Average Error: 30.5 → 12.4
Time: 24.6s
Precision: 64
Ground Truth: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.0506543985785498 \cdot 10^{+132}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -9.729387694827135 \cdot 10^{-250}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.1913008854416164 \cdot 10^{-287}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 2.4228660641686305 \cdot 10^{+144}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 4 regimes.
  2. if re < -2.0506543985785498e+132

    1. Initial program 54.0

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied taylor 0

      \[\leadsto -1 \cdot re\]
    3. Taylor expanded around -inf 0

      \[\leadsto \color{blue}{-1 \cdot re}\]
    4. Applied simplify 0

      \[\leadsto \color{blue}{-re}\]

    if -2.0506543985785498e+132 < re < -9.729387694827135e-250 or 1.1913008854416164e-287 < re < 2.4228660641686305e+144

    1. Initial program 18.7

      \[\sqrt{re \cdot re + im \cdot im}\]

    if -9.729387694827135e-250 < re < 1.1913008854416164e-287

    1. Initial program 46.4

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied taylor 0

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

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

    if 2.4228660641686305e+144 < re

    1. Initial program 57.3

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Applied taylor 0

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

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

Runtime

Total time: 24.6s Debug log

Please include this information when filing a bug report:

herbie --seed '#(1184208345 2389244311 1807722534 1482994180 2388527835 2813794003)'
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))