Average Error: 30.0 → 17.1
Time: 12.7s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.493407606701611 \cdot 10^{+134}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 9.983133137271844 \cdot 10^{+149}:\\ \;\;\;\;\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 < -2.493407606701611e+134

    1. Initial program 54.7

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

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

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

    if -2.493407606701611e+134 < re < 9.983133137271844e+149

    1. Initial program 20.3

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

    if 9.983133137271844e+149 < re

    1. Initial program 58.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.493407606701611 \cdot 10^{+134}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 9.983133137271844 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 12.7s)Debug logProfile

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