Average Error: 29.9 → 17.0
Time: 3.4s
Precision: 64
Internal Precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.3473069568466345 \cdot 10^{+139}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.3325633016550788 \cdot 10^{+132}:\\ \;\;\;\;\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.3473069568466345e+139

    1. Initial program 55.6

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

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

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

    if -4.3473069568466345e+139 < re < 1.3325633016550788e+132

    1. Initial program 20.3

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

    if 1.3325633016550788e+132 < re

    1. Initial program 54.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -4.3473069568466345 \cdot 10^{+139}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 1.3325633016550788 \cdot 10^{+132}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 3.4s)Debug logProfile

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