Average Error: 29.8 → 16.5
Time: 11.7s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.1758068988055531 \cdot 10^{+154}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 2.2594509086233645 \cdot 10^{-290}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 5.74738689663849 \cdot 10^{-263}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 1.9780770217947757 \cdot 10^{+114}:\\ \;\;\;\;\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 < -1.1758068988055531e+154

    1. Initial program 59.4

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

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

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

    if -1.1758068988055531e+154 < re < 2.2594509086233645e-290 or 5.74738689663849e-263 < re < 1.9780770217947757e+114

    1. Initial program 19.6

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

    if 2.2594509086233645e-290 < re < 5.74738689663849e-263

    1. Initial program 27.8

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

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

    if 1.9780770217947757e+114 < re

    1. Initial program 51.3

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

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

Runtime

Time bar (total: 11.7s)Debug logProfile

herbie shell --seed '#(1072840222 1305617769 1692503039 1353360431 4178980589 1488672652)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))