Average Error: 29.7 → 17.0
Time: 15.7s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.599620135686042 \cdot 10^{+159}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -2.051872051815594 \cdot 10^{-231}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le -2.3038745133907206 \cdot 10^{-266}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 2.5529807015333076 \cdot 10^{+146}:\\ \;\;\;\;\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.599620135686042e+159

    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 -4.599620135686042e+159 < re < -2.051872051815594e-231 or -2.3038745133907206e-266 < re < 2.5529807015333076e+146

    1. Initial program 19.7

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

    if -2.051872051815594e-231 < re < -2.3038745133907206e-266

    1. Initial program 29.9

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

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

    if 2.5529807015333076e+146 < re

    1. Initial program 57.3

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

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

Runtime

Time bar (total: 15.7s)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))