Average Error: 29.7 → 16.7
Time: 5.0s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -3.355213242625688 \cdot 10^{+128}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 1.9547410587721634 \cdot 10^{+94}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \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.355213242625688e+128

    1. Initial program 53.1

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

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

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

    if -3.355213242625688e+128 < re < 1.9547410587721634e+94

    1. Initial program 20.0

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

    if 1.9547410587721634e+94 < re

    1. Initial program 47.2

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

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

Runtime

Time bar (total: 5.0s)Debug logProfile

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