Average Error: 29.3 → 16.8
Time: 5.4s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.6065764226727804 \cdot 10^{+128}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 1.0156873505019894 \cdot 10^{+154}:\\ \;\;\;\;\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 < -2.6065764226727804e+128

    1. Initial program 52.2

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

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

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

    if -2.6065764226727804e+128 < re < 1.0156873505019894e+154

    1. Initial program 19.9

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

    if 1.0156873505019894e+154 < re

    1. Initial program 59.4

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

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

Runtime

Time bar (total: 5.4s)Debug logProfile

herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))