Average Error: 29.5 → 17.6
Time: 10.9s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.668905519097261 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le -2.867986206546408 \cdot 10^{-140}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{elif}\;re \le 3.1673469423254626 \cdot 10^{-185}:\\ \;\;\;\;im\\ \mathbf{elif}\;re \le 1.3082844391144367 \cdot 10^{+150}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if re < -1.668905519097261e+153

    1. Initial program 59.0

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

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

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

    if -1.668905519097261e+153 < re < -2.867986206546408e-140 or 3.1673469423254626e-185 < re < 1.3082844391144367e+150

    1. Initial program 15.6

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

    if -2.867986206546408e-140 < re < 3.1673469423254626e-185

    1. Initial program 28.2

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around 0 33.9

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

    if 1.3082844391144367e+150 < re

    1. Initial program 58.0

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

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

Runtime

Time bar (total: 10.9s)Debug logProfile

herbie shell --seed 2018208 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))