Average Error: 42.8 → 0.0
Time: 22.5s
Precision: 64
Internal precision: 128
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
⬇
\[\begin{array}{l}
\mathbf{if}\;re \le 3.280266654840657 \cdot 10^{-252}:\\
\;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re + im} \cdot \sqrt{re - im} + re\right)}\\
\end{array}\]
Derivation
- Split input into 2 regimes.
-
if re < 3.280266654840657e-252
Initial program 49.1
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
Applied taylor 0
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(-1 \cdot re + re\right)}\]
Taylor expanded around -inf 0
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{-1 \cdot re} + re\right)}\]
if 3.280266654840657e-252 < re
Initial program 28.9
\[0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - im \cdot im} + re\right)}\]
- Using strategy
rm
Applied square-unmult 28.9
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{re \cdot re - \color{blue}{{im}^2}} + re\right)}\]
Applied square-unmult 28.9
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{{re}^2} - {im}^2} + re\right)}\]
Applied difference-of-squares 28.8
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\sqrt{\color{blue}{\left(re + im\right) \cdot \left(re - im\right)}} + re\right)}\]
Applied sqrt-prod 0.2
\[\leadsto 0.5 \cdot \sqrt{2.0 \cdot \left(\color{blue}{\sqrt{re + im} \cdot \sqrt{re - im}} + re\right)}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie --seed '#(1052631102 1549666840 214851374 4124938917 336414485 3340135247)'
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
(* 0.5 (sqrt (* 2.0 (+ (sqrt (- (* re re) (* im im))) re)))))