Average Error: 29.7 → 17.2
Time: 32.7s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -9.736498105849951 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -3.4341346056066796 \cdot 10^{-191}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le -3.2662809389580054 \cdot 10^{-249}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 3.76876908226489 \cdot 10^{+122}:\\ \;\;\;\;\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 4 regimes
  2. if re < -9.736498105849951e+153

    1. Initial program 59.3

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

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

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

    if -9.736498105849951e+153 < re < -3.4341346056066796e-191 or -3.2662809389580054e-249 < re < 3.76876908226489e+122

    1. Initial program 19.3

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

    if -3.4341346056066796e-191 < re < -3.2662809389580054e-249

    1. Initial program 30.7

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

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

    if 3.76876908226489e+122 < re

    1. Initial program 51.5

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

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

Runtime

Time bar (total: 32.7s)Debug logProfile

herbie shell --seed '#(1070864556 424010669 783715395 1203517814 4070606583 4107618214)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))