Average Error: 29.4 → 16.9
Time: 8.9s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.1305014506405113 \cdot 10^{+155}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -7.98041185133908 \cdot 10^{-244}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.6142347607863959 \cdot 10^{-251}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 5.0082237284892 \cdot 10^{+151}:\\ \;\;\;\;\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.1305014506405113e+155

    1. Initial program 59.3

      \[\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}\]

    if -1.1305014506405113e+155 < re < -7.98041185133908e-244 or 1.6142347607863959e-251 < re < 5.0082237284892e+151

    1. Initial program 18.0

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

    if -7.98041185133908e-244 < re < 1.6142347607863959e-251

    1. Initial program 30.1

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

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

    if 5.0082237284892e+151 < re

    1. Initial program 58.5

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

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

Runtime

Time bar (total: 8.9s)Debug logProfile

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