Average Error: 30.8 → 12.8
Time: 4.5s
Precision: 64
Internal precision: 384
\[\sqrt{re \cdot re + im \cdot im}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;re \le -2.674059323268242 \cdot 10^{+128}:\\
\;\;\;\;-re\\
\mathbf{if}\;re \le -2.321564696919607 \cdot 10^{-245}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re \le -2.837848394186995 \cdot 10^{-306}:\\
\;\;\;\;im\\
\mathbf{if}\;re \le 2.540188601643307 \cdot 10^{+151}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}\]
Derivation
- Split input into 4 regimes.
-
if re < -2.674059323268242e+128
Initial program 53.9
\[\sqrt{re \cdot re + im \cdot im}\]
Applied taylor 0
\[\leadsto -1 \cdot re\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot re}\]
Applied simplify 0
\[\leadsto \color{blue}{-re}\]
if -2.674059323268242e+128 < re < -2.321564696919607e-245 or -2.837848394186995e-306 < re < 2.540188601643307e+151
Initial program 19.1
\[\sqrt{re \cdot re + im \cdot im}\]
if -2.321564696919607e-245 < re < -2.837848394186995e-306
Initial program 45.8
\[\sqrt{re \cdot re + im \cdot im}\]
Applied taylor 0
\[\leadsto im\]
Taylor expanded around 0 0
\[\leadsto \color{blue}{im}\]
if 2.540188601643307e+151 < re
Initial program 59.1
\[\sqrt{re \cdot re + im \cdot im}\]
Applied taylor 0
\[\leadsto re\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{re}\]
- Recombined 4 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (re im)
:name "math.abs on complex"
(sqrt (+ (* re re) (* im im))))