Average Error: 29.1 → 16.8
Time: 13.2s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.0818560398189068 \cdot 10^{+132}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 8.513202966218162 \cdot 10^{+129}:\\ \;\;\;\;\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.0818560398189068e+132

    1. Initial program 53.2

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

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

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

    if -1.0818560398189068e+132 < re < 8.513202966218162e+129

    1. Initial program 19.8

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

    if 8.513202966218162e+129 < re

    1. Initial program 53.7

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

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

Runtime

Time bar (total: 13.2s)Debug logProfile

herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))