Average Error: 29.3 → 16.6
Time: 7.5s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.5112664263065406 \cdot 10^{+155}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.215821452578765 \cdot 10^{+126}:\\ \;\;\;\;\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 < -2.5112664263065406e+155

    1. Initial program 59.5

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

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

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

    if -2.5112664263065406e+155 < re < 1.215821452578765e+126

    1. Initial program 19.8

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

    if 1.215821452578765e+126 < re

    1. Initial program 52.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.5112664263065406 \cdot 10^{+155}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.215821452578765 \cdot 10^{+126}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 7.5s)Debug logProfile

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