Average Error: 30.4 → 17.7
Time: 2.0s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.309584646013422 \cdot 10^{+120}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 4.8166825988976595 \cdot 10^{+82}:\\ \;\;\;\;\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.309584646013422e+120

    1. Initial program 51.6

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

      \[\leadsto \color{blue}{-1 \cdot re}\]
    3. Simplified9.6

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

    if -2.309584646013422e+120 < re < 4.8166825988976595e+82

    1. Initial program 21.2

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

    if 4.8166825988976595e+82 < re

    1. Initial program 46.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.309584646013422 \cdot 10^{+120}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 4.8166825988976595 \cdot 10^{+82}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

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