Average Error: 29.2 → 16.7
Time: 5.7s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.23631698702111 \cdot 10^{+102}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 7.294114996693451 \cdot 10^{+76}:\\ \;\;\;\;\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 < -1.23631698702111e+102

    1. Initial program 47.8

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

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

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

    if -1.23631698702111e+102 < re < 7.294114996693451e+76

    1. Initial program 19.6

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

    if 7.294114996693451e+76 < re

    1. Initial program 44.6

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Using strategy rm
    3. Applied add-exp-log46.0

      \[\leadsto \color{blue}{e^{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}}\]
    4. Taylor expanded around inf 12.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -1.23631698702111 \cdot 10^{+102}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 7.294114996693451 \cdot 10^{+76}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

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