Average Error: 29.2 → 16.8
Time: 30.7s
Precision: 64
Internal Precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
\[\begin{array}{l} \mathbf{if}\;re \le -1.1308471751629867 \cdot 10^{+78}:\\ \;\;\;\;-re\\ \mathbf{if}\;re \le 1.108679184051191 \cdot 10^{+152}:\\ \;\;\;\;\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 < -1.1308471751629867e+78

    1. Initial program 44.5

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

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

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

    if -1.1308471751629867e+78 < re < 1.108679184051191e+152

    1. Initial program 20.0

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

    if 1.108679184051191e+152 < re

    1. Initial program 58.2

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

      \[\leadsto \color{blue}{re}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 30.7s)Debug logProfile

herbie shell --seed '#(1063027428 1192549564 1443466578 604016274 3637110559 1698629644)' 
(FPCore (re im)
  :name "math.abs on complex"
  (sqrt (+ (* re re) (* im im))))