\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \le -2.2208938072286916 \cdot 10^{-30}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \le -7.3739560176803406 \cdot 10^{-160}:\\
\;\;\;\;e^{e^{\log \left(\log \left(x - y\right) + \left(-2 \cdot \log \left(\sqrt[3]{x \cdot x + y \cdot y}\right)\right)\right)}} \cdot \frac{x + y}{\sqrt[3]{x \cdot x + y \cdot y}}\\
\mathbf{elif}\;y \le -4.89796425683335106 \cdot 10^{-179}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \le 7.00176504920879174 \cdot 10^{-156}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}double code(double x, double y) {
return (((x - y) * (x + y)) / ((x * x) + (y * y)));
}
double code(double x, double y) {
double VAR;
if ((y <= -2.2208938072286916e-30)) {
VAR = -1.0;
} else {
double VAR_1;
if ((y <= -7.37395601768034e-160)) {
VAR_1 = (exp(exp(log((log((x - y)) + -(2.0 * log(cbrt(((x * x) + (y * y))))))))) * ((x + y) / cbrt(((x * x) + (y * y)))));
} else {
double VAR_2;
if ((y <= -4.897964256833351e-179)) {
VAR_2 = -1.0;
} else {
double VAR_3;
if ((y <= 7.001765049208792e-156)) {
VAR_3 = 1.0;
} else {
VAR_3 = -1.0;
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.4 |
|---|---|
| Target | 0.1 |
| Herbie | 8.9 |
if y < -2.2208938072286916e-30 or -7.37395601768034e-160 < y < -4.897964256833351e-179 or 7.001765049208792e-156 < y Initial program 20.0
Taylor expanded around 0 6.2
if -2.2208938072286916e-30 < y < -7.37395601768034e-160Initial program 0.0
rmApplied add-cube-cbrt1.3
Applied times-frac1.5
rmApplied add-exp-log4.4
Applied add-exp-log5.3
Applied prod-exp5.3
Applied add-exp-log5.5
Applied div-exp5.5
Simplified5.5
rmApplied add-exp-log5.8
if -4.897964256833351e-179 < y < 7.001765049208792e-156Initial program 30.2
Taylor expanded around inf 15.4
Final simplification8.9
herbie shell --seed 2020102
(FPCore (x y)
:name "Kahan p9 Example"
:precision binary64
:pre (and (< 0.0 x 1) (< y 1))
:herbie-target
(if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))