Average Error: 30.2 → 17.0
Time: 9.6s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -6.162267456736828 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 3.051366085636659 \cdot 10^{+151}:\\ \;\;\;\;\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 < -6.162267456736828e+153

    1. Initial program 59.3

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

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

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

    if -6.162267456736828e+153 < re < 3.051366085636659e+151

    1. Initial program 20.3

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

    if 3.051366085636659e+151 < re

    1. Initial program 58.6

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

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

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

Runtime

Time bar (total: 9.6s)Debug logProfile

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