Average Error: 29.4 → 16.6
Time: 5.7s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -7.598569655957909 \cdot 10^{+137}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 1.0768358594289975 \cdot 10^{+167}:\\ \;\;\;\;\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 3 regimes
  2. if re < -7.598569655957909e+137

    1. Initial program 54.1

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around -inf 8.3

      \[\leadsto \color{blue}{-1 \cdot re}\]
    3. Applied simplify8.3

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

    if -7.598569655957909e+137 < re < 1.0768358594289975e+167

    1. Initial program 19.6

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

    if 1.0768358594289975e+167 < re

    1. Initial program 59.2

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around inf 8.0

      \[\leadsto \color{blue}{re}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 5.7s)Debug logProfile

herbie shell --seed '#(1071852389 864846987 1238109217 3425890003 4124793586 650694553)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))