Average Error: 29.9 → 14.3
Time: 7.9s
Precision: 64
Internal precision: 128
\[\sqrt{re \cdot re + im \cdot im}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;im \le -1.1496000680102836 \cdot 10^{+163}:\\
\;\;\;\;-im\\
\mathbf{if}\;im \le 4.692828868299432 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{{im}^2 + re \cdot re}\\
\mathbf{else}:\\
\;\;\;\;im\\
\end{array}\]
Derivation
- Split input into 3 regimes.
-
if im < -1.1496000680102836e+163
Initial program 59.5
\[\sqrt{re \cdot re + im \cdot im}\]
Applied simplify 59.5
\[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]
Applied taylor 0
\[\leadsto -1 \cdot im\]
Taylor expanded around -inf 0
\[\leadsto \color{blue}{-1 \cdot im}\]
Applied simplify 0
\[\leadsto \color{blue}{-im}\]
if -1.1496000680102836e+163 < im < 4.692828868299432e+91
Initial program 20.4
\[\sqrt{re \cdot re + im \cdot im}\]
Applied simplify 20.4
\[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]
if 4.692828868299432e+91 < im
Initial program 47.2
\[\sqrt{re \cdot re + im \cdot im}\]
Applied simplify 47.2
\[\leadsto \color{blue}{\sqrt{{im}^2 + re \cdot re}}\]
Applied taylor 0
\[\leadsto im\]
Taylor expanded around inf 0
\[\leadsto \color{blue}{im}\]
- Recombined 3 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(3132427909 2405578827 4278482967 2215509689 1521496148 2758201993)'
(FPCore (re im)
:name "math.abs on complex"
(sqrt (+ (* re re) (* im im))))