Average Error: 29.4 → 16.8
Time: 9.8s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.333951939884602 \cdot 10^{+154}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -1.1350134350066445 \cdot 10^{-200}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.0354870292778926 \cdot 10^{-272}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 4.236891465196376 \cdot 10^{+104}:\\ \;\;\;\;\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.333951939884602e+154

    1. Initial program 59.4

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

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

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

    if -1.333951939884602e+154 < re < -1.1350134350066445e-200 or 1.0354870292778926e-272 < re < 4.236891465196376e+104

    1. Initial program 18.0

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

    if -1.1350134350066445e-200 < re < 1.0354870292778926e-272

    1. Initial program 29.0

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

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

    if 4.236891465196376e+104 < re

    1. Initial program 47.6

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

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

Runtime

Time bar (total: 9.8s)Debug logProfile

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