Average Error: 29.6 → 16.6
Time: 9.4s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.3450563247296257 \cdot 10^{+154}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 5.2137866734293315 \cdot 10^{+151}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if re < -1.3450563247296257e+154

    1. Initial program 59.4

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Initial simplification59.4

      \[\leadsto \sqrt{re \cdot re + im \cdot im}\]
    3. Using strategy rm
    4. Applied add-exp-log59.4

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

      \[\leadsto \color{blue}{e^{-\log \left(\frac{-1}{re}\right)}}\]
    6. Simplified7.0

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

    if -1.3450563247296257e+154 < re < 5.2137866734293315e+151

    1. Initial program 19.6

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Initial simplification19.6

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

    if 5.2137866734293315e+151 < re

    1. Initial program 58.5

      \[\sqrt{re \cdot re + im \cdot im}\]
    2. Initial simplification58.5

      \[\leadsto \sqrt{re \cdot re + im \cdot im}\]
    3. Taylor expanded around inf 8.2

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

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

Runtime

Time bar (total: 9.4s)Debug logProfile

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