Average Error: 29.5 → 16.6
Time: 2.3s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -8.854994527365762 \cdot 10^{+143}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.0667669692279988 \cdot 10^{+89}:\\ \;\;\;\;\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 < -8.854994527365762e+143

    1. Initial program 56.8

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

      \[\leadsto \color{blue}{-1 \cdot re}\]
    3. Simplified7.8

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

    if -8.854994527365762e+143 < re < 1.0667669692279988e+89

    1. Initial program 19.9

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

    if 1.0667669692279988e+89 < re

    1. Initial program 45.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -8.854994527365762 \cdot 10^{+143}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.0667669692279988 \cdot 10^{+89}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 2.3s)Debug logProfile

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