Average Error: 29.6 → 17.5
Time: 5.7s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.37114684777626 \cdot 10^{+141}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 4.822601499727239 \cdot 10^{-295}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 4.1762824341776603 \cdot 10^{-163}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 1.1982953378316015 \cdot 10^{+140}:\\ \;\;\;\;\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 < -4.37114684777626e+141

    1. Initial program 55.8

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

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

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

    if -4.37114684777626e+141 < re < 4.822601499727239e-295 or 4.1762824341776603e-163 < re < 1.1982953378316015e+140

    1. Initial program 18.4

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

    if 4.822601499727239e-295 < re < 4.1762824341776603e-163

    1. Initial program 28.6

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

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

    if 1.1982953378316015e+140 < re

    1. Initial program 55.0

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

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

Runtime

Time bar (total: 5.7s)Debug logProfile

herbie shell --seed '#(1070960995 739739648 2531964651 3069671617 351857262 3877178482)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))