Average Error: 29.6 → 16.6
Time: 4.3s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -8.550740197694876 \cdot 10^{+148}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 2.1468628440656388 \cdot 10^{+142}:\\ \;\;\;\;\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 < -8.550740197694876e+148

    1. Initial program 57.9

      \[\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 -8.550740197694876e+148 < re < 2.1468628440656388e+142

    1. Initial program 19.6

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

    if 2.1468628440656388e+142 < re

    1. Initial program 56.1

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

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

Runtime

Time bar (total: 4.3s)Debug logProfile

herbie shell --seed '#(1071948828 1180510430 2986424009 997076509 406109801 420189285)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))