Average Error: 29.7 → 16.4
Time: 9.9s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -8.117609398389217 \cdot 10^{+121}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 1.1756753883027842 \cdot 10^{+114}:\\ \;\;\;\;\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) < -8.117609398389217e+121

    1. Initial program 51.7

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

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

    if -8.117609398389217e+121 < (- re) < 1.1756753883027842e+114

    1. Initial program 19.7

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

    if 1.1756753883027842e+114 < (- re)

    1. Initial program 51.0

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

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

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

Runtime

Time bar (total: 9.9s)Debug logProfile

herbie shell --seed '#(1070386091 2509006183 1430610344 1025408621 36622005 1425925650)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))