Average Error: 29.5 → 17.3
Time: 12.0s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -3.957078144730544 \cdot 10^{+152}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 2.633327089023278 \cdot 10^{+176}:\\ \;\;\;\;\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 < -3.957078144730544e+152

    1. Initial program 59.2

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

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

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

    if -3.957078144730544e+152 < re < 2.633327089023278e+176

    1. Initial program 20.5

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

    if 2.633327089023278e+176 < re

    1. Initial program 59.2

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

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

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

Runtime

Time bar (total: 12.0s)Debug logProfile

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