Average Error: 29.6 → 16.7
Time: 2.8s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -7.335090534885366 \cdot 10^{+149}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 2.937250069907319 \cdot 10^{-180} \lor \neg \left(re \le 6.821929949278014 \cdot 10^{-164}\right) \land re \le 2.0210968109194186 \cdot 10^{+118}:\\ \;\;\;\;\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 < -7.335090534885366e+149

    1. Initial program 58.6

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

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

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

    if -7.335090534885366e+149 < re < 2.937250069907319e-180 or 6.821929949278014e-164 < re < 2.0210968109194186e+118

    1. Initial program 19.5

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

    if 2.937250069907319e-180 < re < 6.821929949278014e-164 or 2.0210968109194186e+118 < re

    1. Initial program 48.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -7.335090534885366 \cdot 10^{+149}:\\ \;\;\;\;-re\\ \mathbf{elif}\;re \le 2.937250069907319 \cdot 10^{-180} \lor \neg \left(re \le 6.821929949278014 \cdot 10^{-164}\right) \land re \le 2.0210968109194186 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{im \cdot im + re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Runtime

Time bar (total: 2.8s)Debug logProfile

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