Average Error: 28.9 → 16.2
Time: 6.7s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.8902639993092405 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 4.2147853830585397 \cdot 10^{+124}:\\ \;\;\;\;\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 < -4.8902639993092405e+153

    1. Initial program 59.2

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

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

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

    if -4.8902639993092405e+153 < re < 4.2147853830585397e+124

    1. Initial program 19.1

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

    if 4.2147853830585397e+124 < re

    1. Initial program 51.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -4.8902639993092405 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 4.2147853830585397 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 6.7s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes28.916.27.221.758.5%
herbie shell --seed 2018296 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))