\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 \le -811.998650832227:\\
\;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\
\mathbf{elif}\;x \le -6.093571820386453 \cdot 10^{-07}:\\
\;\;\;\;{e}^{\left(\frac{\mathsf{fma}\left(2, \log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right), \log 1.0\right)}{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\
\end{array}double f(double p, double x) {
double r10427983 = 0.5;
double r10427984 = 1.0;
double r10427985 = x;
double r10427986 = 4.0;
double r10427987 = p;
double r10427988 = r10427986 * r10427987;
double r10427989 = r10427988 * r10427987;
double r10427990 = r10427985 * r10427985;
double r10427991 = r10427989 + r10427990;
double r10427992 = sqrt(r10427991);
double r10427993 = r10427985 / r10427992;
double r10427994 = r10427984 + r10427993;
double r10427995 = r10427983 * r10427994;
double r10427996 = sqrt(r10427995);
return r10427996;
}
double f(double p, double x) {
double r10427997 = x;
double r10427998 = -811.998650832227;
bool r10427999 = r10427997 <= r10427998;
double r10428000 = exp(1.0);
double r10428001 = p;
double r10428002 = 2.0;
double r10428003 = r10428001 * r10428002;
double r10428004 = hypot(r10427997, r10428003);
double r10428005 = r10427997 / r10428004;
double r10428006 = 0.5;
double r10428007 = fma(r10428005, r10428006, r10428006);
double r10428008 = log(r10428007);
double r10428009 = r10428008 / r10428002;
double r10428010 = pow(r10428000, r10428009);
double r10428011 = -6.093571820386453e-07;
bool r10428012 = r10427997 <= r10428011;
double r10428013 = -1.0;
double r10428014 = r10428013 / r10427997;
double r10428015 = log(r10428014);
double r10428016 = r10428013 / r10428001;
double r10428017 = log(r10428016);
double r10428018 = r10428015 - r10428017;
double r10428019 = 1.0;
double r10428020 = log(r10428019);
double r10428021 = fma(r10428002, r10428018, r10428020);
double r10428022 = r10428021 / r10428002;
double r10428023 = pow(r10428000, r10428022);
double r10428024 = r10428012 ? r10428023 : r10428010;
double r10428025 = r10427999 ? r10428010 : r10428024;
return r10428025;
}




Bits error versus p




Bits error versus x
| Original | 13.3 |
|---|---|
| Target | 13.3 |
| Herbie | 13.6 |
if x < -811.998650832227 or -6.093571820386453e-07 < x Initial program 13.0
Simplified13.0
rmApplied add-exp-log13.0
rmApplied pow1/213.0
Applied log-pow13.0
Applied exp-prod13.0
Simplified13.0
rmApplied pow1/213.0
Applied pow-pow13.0
Simplified13.0
if -811.998650832227 < x < -6.093571820386453e-07Initial program 31.3
Simplified31.3
rmApplied add-exp-log31.3
rmApplied pow1/231.3
Applied log-pow31.3
Applied exp-prod31.3
Simplified31.3
rmApplied pow1/231.3
Applied pow-pow31.3
Simplified31.3
Taylor expanded around -inf 47.0
Simplified47.0
Final simplification13.6
herbie shell --seed 2019168 +o rules:numerics
(FPCore (p x)
:name "Given's Rotation SVD example"
:pre (< 1e-150 (fabs x) 1e+150)
:herbie-target
(sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x)))))
(sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))