Average Error: 29.8 → 16.7
Time: 17.5s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.6083849651937358 \cdot 10^{+118}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 2.008790645499284 \cdot 10^{+119}:\\ \;\;\;\;\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 3 regimes
  2. if re < -2.6083849651937358e+118

    1. Initial program 51.7

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

      \[\leadsto \color{blue}{-1 \cdot re}\]
    3. Applied simplify9.5

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

    if -2.6083849651937358e+118 < re < 2.008790645499284e+119

    1. Initial program 19.9

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

    if 2.008790645499284e+119 < re

    1. Initial program 51.0

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

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

Runtime

Time bar (total: 17.5s)Debug logProfile

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