Average Error: 29.1 → 16.3
Time: 6.4s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.1714237678920416 \cdot 10^{+102}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 1.1669831942553872 \cdot 10^{+150}:\\ \;\;\;\;\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.1714237678920416e+102

    1. Initial program 47.9

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

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

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

    if -2.1714237678920416e+102 < re < 1.1669831942553872e+150

    1. Initial program 19.6

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

    if 1.1669831942553872e+150 < re

    1. Initial program 57.6

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

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

Runtime

Time bar (total: 6.4s)Debug logProfile

herbie shell --seed '#(1070227846 1561819246 480764335 4016816270 2602869839 2117310382)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))