Average Error: 30.3 → 17.1
Time: 11.8s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.5339282929029025 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.0845514057732897 \cdot 10^{+144}:\\ \;\;\;\;\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 < -1.5339282929029025e+153

    1. Initial program 59.2

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

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

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

    if -1.5339282929029025e+153 < re < 1.0845514057732897e+144

    1. Initial program 20.4

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

    if 1.0845514057732897e+144 < re

    1. Initial program 57.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.5339282929029025 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.0845514057732897 \cdot 10^{+144}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 11.8s)Debug logProfile

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