Average Error: 29.8 → 17.8
Time: 11.4s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.3332909757075433 \cdot 10^{+147}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -8.30732108697294 \cdot 10^{-301}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.5101400909533284 \cdot 10^{-255}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 1.2288226746954848 \cdot 10^{+174}:\\ \;\;\;\;\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.3332909757075433e+147

    1. Initial program 57.6

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

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

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

    if -1.3332909757075433e+147 < re < -8.30732108697294e-301 or 1.5101400909533284e-255 < re < 1.2288226746954848e+174

    1. Initial program 20.2

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

    if -8.30732108697294e-301 < re < 1.5101400909533284e-255

    1. Initial program 31.0

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

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

    if 1.2288226746954848e+174 < re

    1. Initial program 59.2

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

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

Runtime

Time bar (total: 11.4s)Debug logProfile

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