Average Error: 30.0 → 17.1
Time: 7.1s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -6.648995720553239 \cdot 10^{+118}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -2.5285777980245434 \cdot 10^{-263}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.470576454035906 \cdot 10^{-297}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 1.6037040674348993 \cdot 10^{+99}:\\ \;\;\;\;\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 < -6.648995720553239e+118

    1. Initial program 51.1

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

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

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

    if -6.648995720553239e+118 < re < -2.5285777980245434e-263 or 1.470576454035906e-297 < re < 1.6037040674348993e+99

    1. Initial program 20.0

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

    if -2.5285777980245434e-263 < re < 1.470576454035906e-297

    1. Initial program 30.2

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

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

    if 1.6037040674348993e+99 < re

    1. Initial program 46.6

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

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

Runtime

Time bar (total: 7.1s)Debug logProfile

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