Average Error: 29.2 → 16.5
Time: 1.7s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.0372103667772526 \cdot 10^{+152}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.637785624538399 \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 < -4.0372103667772526e+152

    1. Initial program 58.9

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

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

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

    if -4.0372103667772526e+152 < re < 1.637785624538399e+151

    1. Initial program 19.3

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

    if 1.637785624538399e+151 < re

    1. Initial program 58.4

      \[\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.5

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

Runtime

Time bar (total: 1.7s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes29.216.57.621.658.8%
herbie shell --seed 2018290 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))