Average Error: 29.6 → 16.3
Time: 11.6s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.831381958200308 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 2.0352296470876165 \cdot 10^{+91}:\\ \;\;\;\;\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.831381958200308e+153

    1. Initial program 59.1

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

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

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

    if -1.831381958200308e+153 < re < 2.0352296470876165e+91

    1. Initial program 19.7

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

    if 2.0352296470876165e+91 < re

    1. Initial program 46.8

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

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

Runtime

Time bar (total: 11.6s)Debug logProfile

herbie shell --seed '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))