\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{if}\;t_0 \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - 4 \cdot {\left(\frac{x}{y}\right)}^{4}}{-1 - 2 \cdot {\left(\frac{x}{y}\right)}^{2}}\\
\end{array}
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
(if (<= t_0 1.0)
t_0
(/
(- 1.0 (* 4.0 (pow (/ x y) 4.0)))
(- -1.0 (* 2.0 (pow (/ x y) 2.0)))))))double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
double code(double x, double y) {
double t_0 = ((x - y) * (x + y)) / ((x * x) + (y * y));
double tmp;
if (t_0 <= 1.0) {
tmp = t_0;
} else {
tmp = (1.0 - (4.0 * pow((x / y), 4.0))) / (-1.0 - (2.0 * pow((x / y), 2.0)));
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.0 |
|---|---|
| Target | 0.0 |
| Herbie | 4.6 |
if (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) < 1Initial program 0.0
if 1 < (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y))) Initial program 64.0
Taylor expanded around 0 29.9
Simplified29.9
rmApplied add-sqr-sqrt_binary6429.9
Simplified29.9
Simplified14.5
rmApplied flip-+_binary6414.6
Simplified14.6
Simplified14.6
Final simplification4.6
herbie shell --seed 2021205
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (< 0.0 x 1.0) (< y 1.0))
:herbie-target
(if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))