\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \leq 1:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y) :precision binary64 (if (<= (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) 1.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) -1.0))
double code(double x, double y) {
return (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y)))));
}
double code(double x, double y) {
double VAR;
if (((((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y))))) <= 1.0)) {
VAR = (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y)))));
} else {
VAR = -1.0;
}
return VAR;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.4 |
|---|---|
| Target | 0.1 |
| Herbie | 4.9 |
if (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) < 1Initial program 0.0
if 1 < (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) Initial program 64.0
Taylor expanded around 0 15.3
Final simplification4.9
herbie shell --seed 2020198
(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))))