Average Error: 29.8 → 16.9
Time: 7.3s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.200646663461323 \cdot 10^{+133}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 9.047662084790376 \cdot 10^{+147}:\\ \;\;\;\;\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 < -2.200646663461323e+133

    1. Initial program 54.4

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

      \[\leadsto \color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{\sqrt{re \cdot re + im \cdot im}}}\]
    4. Taylor expanded around -inf 8.5

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

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

    if -2.200646663461323e+133 < re < 9.047662084790376e+147

    1. Initial program 20.1

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

    if 9.047662084790376e+147 < re

    1. Initial program 57.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.200646663461323 \cdot 10^{+133}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 9.047662084790376 \cdot 10^{+147}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Reproduce

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