Average Error: 30.4 → 17.3
Time: 18.8s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.522363531271217 \cdot 10^{+151}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 3.1316917744172105 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 3 regimes
  2. if re < -4.522363531271217e+151

    1. Initial program 58.7

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube59.5

      \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im}\right) \cdot \sqrt{re \cdot re + im \cdot im}}}\]
    4. Taylor expanded around -inf 7.0

      \[\leadsto \color{blue}{-1 \cdot re}\]
    5. Simplified7.0

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

    if -4.522363531271217e+151 < re < 3.1316917744172105e+146

    1. Initial program 20.6

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

    if 3.1316917744172105e+146 < re

    1. Initial program 57.1

      \[\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. Final simplification17.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -4.522363531271217 \cdot 10^{+151}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 3.1316917744172105 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

herbie shell --seed 2019088 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))