Average Error: 29.8 → 16.6
Time: 16.6s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -4.2396704393719017 \cdot 10^{+148}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 2.9577354133548924 \cdot 10^{+138}:\\ \;\;\;\;\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) < -4.2396704393719017e+148

    1. Initial program 57.5

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

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

    if -4.2396704393719017e+148 < (- re) < 2.9577354133548924e+138

    1. Initial program 20.0

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

    if 2.9577354133548924e+138 < (- re)

    1. Initial program 55.4

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

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

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

Runtime

Time bar (total: 16.6s)Debug logProfile

herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))