Average Error: 29.3 → 16.5
Time: 7.5s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -6.933392427819694 \cdot 10^{+157}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 1.9695378729101803 \cdot 10^{+130}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{else}:\\ \;\;\;\;-re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 3 regimes
  2. if (- re) < -6.933392427819694e+157

    1. Initial program 59.4

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

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

    if -6.933392427819694e+157 < (- re) < 1.9695378729101803e+130

    1. Initial program 19.6

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

    if 1.9695378729101803e+130 < (- re)

    1. Initial program 54.2

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

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

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

Runtime

Time bar (total: 7.5s)Debug logProfile

herbie shell --seed '#(1070258749 1877548225 2229079127 1588002776 3179087814 1886870650)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))