Average Error: 30.0 → 18.3
Time: 5.0s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.9133903609356435 \cdot 10^{+137}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le -1.4143330855213813 \cdot 10^{-180}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{if}\;re \le 1.5363993963951212 \cdot 10^{-139}:\\ \;\;\;\;im\\ \mathbf{if}\;re \le 4.594816212135136 \cdot 10^{+128}:\\ \;\;\;\;\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 4 regimes
  2. if re < -1.9133903609356435e+137

    1. Initial program 55.1

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

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

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

    if -1.9133903609356435e+137 < re < -1.4143330855213813e-180 or 1.5363993963951212e-139 < re < 4.594816212135136e+128

    1. Initial program 14.9

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

    if -1.4143330855213813e-180 < re < 1.5363993963951212e-139

    1. Initial program 30.2

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Taylor expanded around 0 35.3

      \[\leadsto \color{blue}{im}\]

    if 4.594816212135136e+128 < re

    1. Initial program 53.6

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

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

Runtime

Time bar (total: 5.0s)Debug logProfile

herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))