Average Error: 30.0 → 16.8
Time: 19.1s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.863416131836119 \cdot 10^{+102}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 3.778966780440601 \cdot 10^{+153}:\\ \;\;\;\;\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.863416131836119e+102

    1. Initial program 48.2

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

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

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

    if -1.863416131836119e+102 < re < 3.778966780440601e+153

    1. Initial program 20.2

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

    if 3.778966780440601e+153 < re

    1. Initial program 59.0

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

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

Runtime

Time bar (total: 19.1s)Debug logProfile

herbie shell --seed '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))