Average Error: 29.6 → 16.9
Time: 4.5s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;-re \le -1.1827201026453843 \cdot 10^{+156}:\\ \;\;\;\;re\\ \mathbf{if}\;-re \le 1.883820880057145 \cdot 10^{+121}:\\ \;\;\;\;\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.1827201026453843e+156

    1. Initial program 59.3

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

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

    if -1.1827201026453843e+156 < (- re) < 1.883820880057145e+121

    1. Initial program 20.0

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

    if 1.883820880057145e+121 < (- re)

    1. Initial program 52.1

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

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

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

Runtime

Time bar (total: 4.5s)Debug logProfile

herbie shell --seed '#(1070706311 3771791028 4128836681 4194990999 2341756049 504035650)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))