Average Error: 30.5 → 12.4
Time: 24.6s
Precision: 64
Ground Truth: 128
\[\sqrt{re \cdot re + im \cdot im}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;re \le -2.0506543985785498 \cdot 10^{+132}:\\
\;\;\;\;-re\\
\mathbf{if}\;re \le -9.729387694827135 \cdot 10^{-250}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re \le 1.1913008854416164 \cdot 10^{-287}:\\
\;\;\;\;im\\
\mathbf{if}\;re \le 2.4228660641686305 \cdot 10^{+144}:\\
\;\;\;\;\sqrt{re \cdot re + im \cdot im}\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}\]
Derivation
- Split input into 4 regimes.
-
if re < -2.0506543985785498e+132
Initial program 54.0
\[\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.0506543985785498e+132 < re < -9.729387694827135e-250 or 1.1913008854416164e-287 < re < 2.4228660641686305e+144
Initial program 18.7
\[\sqrt{re \cdot re + im \cdot im}\]
if -9.729387694827135e-250 < re < 1.1913008854416164e-287
Initial program 46.4
\[\sqrt{re \cdot re + im \cdot im}\]
Applied taylor 0
\[\leadsto im\]
Taylor expanded around 0 0
\[\leadsto \color{blue}{im}\]
if 2.4228660641686305e+144 < re
Initial program 57.3
\[\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 --seed '#(1184208345 2389244311 1807722534 1482994180 2388527835 2813794003)'
(FPCore (re im)
:name "math.abs on complex"
(sqrt (+ (* re re) (* im im))))