\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\begin{array}{l}
\mathbf{if}\;x \leq -5.541137639902676 \cdot 10^{+37}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \frac{p}{\frac{x \cdot x}{p}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + x \cdot \frac{1}{\sqrt{x \cdot x + p \cdot \left(p \cdot 4\right)}}\right)}\\
\end{array}(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
(FPCore (p x) :precision binary64 (if (<= x -5.541137639902676e+37) (sqrt (* 0.5 (* 2.0 (/ p (/ (* x x) p))))) (sqrt (* 0.5 (+ 1.0 (* x (/ 1.0 (sqrt (+ (* x x) (* p (* p 4.0)))))))))))
double code(double p, double x) {
return sqrt(0.5 * (1.0 + (x / sqrt(((4.0 * p) * p) + (x * x)))));
}
double code(double p, double x) {
double tmp;
if (x <= -5.541137639902676e+37) {
tmp = sqrt(0.5 * (2.0 * (p / ((x * x) / p))));
} else {
tmp = sqrt(0.5 * (1.0 + (x * (1.0 / sqrt((x * x) + (p * (p * 4.0)))))));
}
return tmp;
}










Bits error versus p










Bits error versus x
Results
| Original | 13.2 |
|---|---|
| Target | 13.2 |
| Herbie | 14.6 |
| Alternative 1 | |
|---|---|
| Error | 14.5 |
| Cost | 14081 |
| Alternative 2 | |
|---|---|
| Error | 15.3 |
| Cost | 7681 |
| Alternative 3 | |
|---|---|
| Error | 20.1 |
| Cost | 7297 |
| Alternative 4 | |
|---|---|
| Error | 19.9 |
| Cost | 6792 |
| Alternative 5 | |
|---|---|
| Error | 39.5 |
| Cost | 385 |
| Alternative 6 | |
|---|---|
| Error | 40.6 |
| Cost | 64 |

if x < -5.54113763990267597e37Initial program 29.4
Taylor expanded around -inf 37.5
Simplified36.9
Simplified36.9
if -5.54113763990267597e37 < x Initial program 9.4
rmApplied div-inv_binary64_31449.4
Simplified9.4
Simplified9.4
Final simplification14.6
herbie shell --seed 2021044
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (< 1e-150 (fabs x) 1e+150)
:herbie-target
(sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))
(sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))