Average Error: 29.0 → 16.4
Time: 3.2s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.3417656043460147 \cdot 10^{+154}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 7.931296847150586 \cdot 10^{+153}:\\ \;\;\;\;\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 < -1.3417656043460147e+154

    1. Initial program 59.4

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

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

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

    if -1.3417656043460147e+154 < re < 7.931296847150586e+153

    1. Initial program 19.3

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

    if 7.931296847150586e+153 < re

    1. Initial program 59.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.3417656043460147 \cdot 10^{+154}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 7.931296847150586 \cdot 10^{+153}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 3.2s)Debug logProfile

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