Average Error: 29.1 → 16.9
Time: 3.6s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.3347851480310733 \cdot 10^{+122}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -9.803953207443715 \cdot 10^{-265}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 4.198217036248412 \cdot 10^{-200}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 7.303299105932718 \cdot 10^{+148}:\\ \;\;\;\;\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 4 regimes
  2. if re < -2.3347851480310733e+122

    1. Initial program 51.9

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

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

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

    if -2.3347851480310733e+122 < re < -9.803953207443715e-265 or 4.198217036248412e-200 < re < 7.303299105932718e+148

    1. Initial program 17.6

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

    if -9.803953207443715e-265 < re < 4.198217036248412e-200

    1. Initial program 28.9

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around 0 31.9

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

    if 7.303299105932718e+148 < re

    1. Initial program 58.1

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

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

Runtime

Time bar (total: 3.6s)Debug logProfile

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