Average Error: 29.4 → 16.3
Time: 5.6s
Precision: 64
Internal Precision: 320
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -4.0320563656945774 \cdot 10^{+153}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 4.772473411917852 \cdot 10^{+133}:\\ \;\;\;\;\sqrt{re \cdot re + im \cdot im}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array}\]

Error

Bits error versus re

Bits error versus im

Derivation

  1. Split input into 3 regimes
  2. if re < -4.0320563656945774e+153

    1. Initial program 59.3

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

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

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

    if -4.0320563656945774e+153 < re < 4.772473411917852e+133

    1. Initial program 19.4

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

    if 4.772473411917852e+133 < re

    1. Initial program 53.9

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

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

Runtime

Time bar (total: 5.6s)Debug logProfile

herbie shell --seed '#(1071246582 2318319007 2683472949 3810440501 3233274817 2724848749)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))