Average Error: 29.4 → 17.1
Time: 4.6s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -1.2321885464066262 \cdot 10^{+159}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 1.9209669004775234 \cdot 10^{+132}:\\ \;\;\;\;\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) < -1.2321885464066262e+159

    1. Initial program 59.3

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

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

    if -1.2321885464066262e+159 < (- re) < 1.9209669004775234e+132

    1. Initial program 20.0

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

    if 1.9209669004775234e+132 < (- re)

    1. Initial program 53.8

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

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

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

Runtime

Time bar (total: 4.6s)Debug logProfile

herbie shell --seed '#(1071119240 1686926585 3481876196 78132896 2080707795 3185793749)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))