Average Error: 29.4 → 16.5
Time: 16.1s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.7207788925678074 \cdot 10^{+137}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 4.992503783611275 \cdot 10^{+127}:\\ \;\;\;\;\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.7207788925678074e+137

    1. Initial program 55.5

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

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

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

    if -2.7207788925678074e+137 < re < 4.992503783611275e+127

    1. Initial program 19.5

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

    if 4.992503783611275e+127 < re

    1. Initial program 53.5

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

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

Runtime

Time bar (total: 16.1s)Debug logProfile

herbie shell --seed '#(1063185673 2139736501 2393378123 1907444849 1070993796 1007244912)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))