Average Error: 29.4 → 16.8
Time: 8.1s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -4.2798662729248727 \cdot 10^{+145}:\\ \;\;\;\;re\\ \mathbf{elif}\;-re \le 4.950119475502134 \cdot 10^{+131}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \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 3 regimes
  2. if (- re) < -4.2798662729248727e+145

    1. Initial program 56.5

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

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

    if -4.2798662729248727e+145 < (- re) < 4.950119475502134e+131

    1. Initial program 19.8

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

    if 4.950119475502134e+131 < (- re)

    1. Initial program 53.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-re \le -4.2798662729248727 \cdot 10^{+145}:\\ \;\;\;\;re\\ \mathbf{elif}\;-re \le 4.950119475502134 \cdot 10^{+131}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;-re\\ \end{array}\]

Runtime

Time bar (total: 8.1s)Debug logProfile

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