\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 -1.2651948696730856 \cdot 10^{-107}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{1 - \frac{x \cdot x}{x \cdot x + p \cdot \left(p \cdot 4\right)}}{1 - \frac{x}{\sqrt{x \cdot x + p \cdot \left(p \cdot 4\right)}}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{\frac{x}{\left|\sqrt[3]{x \cdot x + p \cdot \left(p \cdot 4\right)}\right|}}{\sqrt{\sqrt[3]{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 -1.2651948696730856e-107)
(sqrt
(*
0.5
(/
(- 1.0 (/ (* x x) (+ (* x x) (* p (* p 4.0)))))
(- 1.0 (/ x (sqrt (+ (* x x) (* p (* p 4.0)))))))))
(sqrt
(*
0.5
(+
1.0
(/
(/ x (fabs (cbrt (+ (* x x) (* p (* p 4.0))))))
(sqrt (cbrt (+ (* 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 <= -1.2651948696730856e-107) {
tmp = sqrt(0.5 * ((1.0 - ((x * x) / ((x * x) + (p * (p * 4.0))))) / (1.0 - (x / sqrt((x * x) + (p * (p * 4.0)))))));
} else {
tmp = sqrt(0.5 * (1.0 + ((x / fabs(cbrt((x * x) + (p * (p * 4.0))))) / sqrt(cbrt((x * x) + (p * (p * 4.0)))))));
}
return tmp;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.0 |
|---|---|
| Target | 13.0 |
| Herbie | 13.1 |
if x < -1.26519486967308557e-107Initial program 27.5
rmApplied flip-+_binary6427.5
Simplified27.5
Simplified27.5
if -1.26519486967308557e-107 < x Initial program 2.1
rmApplied add-cube-cbrt_binary642.2
Applied sqrt-prod_binary642.2
Applied associate-/r*_binary642.2
Simplified2.2
Final simplification13.1
herbie shell --seed 2020224
(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))))))))