Average Error: 28.8 → 16.2
Time: 3.4s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -5.714338805013559 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le -6.356570007940982 \cdot 10^{-159}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{elif}\;re \le -6.729283391911509 \cdot 10^{-169}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.3316012716097696 \cdot 10^{+137}:\\ \;\;\;\;\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 < -5.714338805013559e+153 or -6.356570007940982e-159 < re < -6.729283391911509e-169

    1. Initial program 56.8

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

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

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

    if -5.714338805013559e+153 < re < -6.356570007940982e-159 or -6.729283391911509e-169 < re < 1.3316012716097696e+137

    1. Initial program 18.5

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

    if 1.3316012716097696e+137 < re

    1. Initial program 54.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -5.714338805013559 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le -6.356570007940982 \cdot 10^{-159}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{elif}\;re \le -6.729283391911509 \cdot 10^{-169}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.3316012716097696 \cdot 10^{+137}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 3.4s)Debug logProfile

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