Average Error: 29.0 → 17.4
Time: 4.4s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.7700344314868762 \cdot 10^{+155}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -7.813752444459668 \cdot 10^{-138}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.2208784163710688 \cdot 10^{-215}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 2.742924009268354 \cdot 10^{+138}:\\ \;\;\;\;\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 < -1.7700344314868762e+155

    1. Initial program 59.4

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

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

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

    if -1.7700344314868762e+155 < re < -7.813752444459668e-138 or 1.2208784163710688e-215 < re < 2.742924009268354e+138

    1. Initial program 15.4

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

    if -7.813752444459668e-138 < re < 1.2208784163710688e-215

    1. Initial program 27.6

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

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

    if 2.742924009268354e+138 < re

    1. Initial program 55.5

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

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

Runtime

Time bar (total: 4.4s)Debug logProfile

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