\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \leq -3.034508079287107 \cdot 10^{+152}:\\
\;\;\;\;-1 + 2 \cdot \frac{x \cdot x}{y \cdot y}\\
\mathbf{elif}\;y \leq -1.7556393841525514 \cdot 10^{-177}:\\
\;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\\
\mathbf{elif}\;y \leq -3.6861139043320025 \cdot 10^{-201}:\\
\;\;\;\;-1 + 2 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\
\mathbf{elif}\;y \leq 5.0918618588880355 \cdot 10^{-197}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.82726859401974 \cdot 10^{-168}:\\
\;\;\;\;-1 + 2 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(y + x\right)}}\\
\end{array}(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
:precision binary64
(if (<= y -3.034508079287107e+152)
(+ -1.0 (* 2.0 (/ (* x x) (* y y))))
(if (<= y -1.7556393841525514e-177)
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y)))
(if (<= y -3.6861139043320025e-201)
(+ -1.0 (* 2.0 (* (/ x y) (/ x y))))
(if (<= y 5.0918618588880355e-197)
1.0
(if (<= y 4.82726859401974e-168)
(+ -1.0 (* 2.0 (* (/ x y) (/ x y))))
(/ 1.0 (/ (+ (* x x) (* y y)) (* (- x y) (+ y x))))))))))double code(double x, double y) {
return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
double code(double x, double y) {
double tmp;
if (y <= -3.034508079287107e+152) {
tmp = -1.0 + (2.0 * ((x * x) / (y * y)));
} else if (y <= -1.7556393841525514e-177) {
tmp = ((x - y) * (y + x)) / ((x * x) + (y * y));
} else if (y <= -3.6861139043320025e-201) {
tmp = -1.0 + (2.0 * ((x / y) * (x / y)));
} else if (y <= 5.0918618588880355e-197) {
tmp = 1.0;
} else if (y <= 4.82726859401974e-168) {
tmp = -1.0 + (2.0 * ((x / y) * (x / y)));
} else {
tmp = 1.0 / (((x * x) + (y * y)) / ((x - y) * (y + x)));
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.4 |
|---|---|
| Target | 0.0 |
| Herbie | 5.5 |
if y < -3.034508079287107e152Initial program 63.2
Taylor expanded around 0 0
Simplified0
if -3.034508079287107e152 < y < -1.75563938415255139e-177Initial program 1.3
if -1.75563938415255139e-177 < y < -3.686113904332003e-201 or 5.0918618588880355e-197 < y < 4.8272685940197399e-168Initial program 31.2
Taylor expanded around 0 64.0
Simplified64.0
rmApplied times-frac_binary6436.4
if -3.686113904332003e-201 < y < 5.0918618588880355e-197Initial program 29.8
Taylor expanded around inf 11.2
if 4.8272685940197399e-168 < y Initial program 1.3
rmApplied clear-num_binary641.3
Final simplification5.5
herbie shell --seed 2021173
(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))))