Average Error: 29.4 → 16.6
Time: 6.5s
Precision: 64
Internal Precision: 576
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -1.253143076728685 \cdot 10^{+147}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 1.441337001454865 \cdot 10^{+128}:\\ \;\;\;\;\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) < -1.253143076728685e+147

    1. Initial program 57.7

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

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

    if -1.253143076728685e+147 < (- re) < 1.441337001454865e+128

    1. Initial program 19.7

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

    if 1.441337001454865e+128 < (- re)

    1. Initial program 53.1

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

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

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

Runtime

Time bar (total: 6.5s)Debug logProfile

herbie shell --seed '#(1072967564 1937075727 894099792 790700740 1036514779 1027793188)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))