\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \le -1.3453816967374705 \cdot 10^{153}:\\
\;\;\;\;\log \left(\frac{1}{e}\right)\\
\mathbf{elif}\;y \le -1.2162082839611001 \cdot 10^{-151}:\\
\;\;\;\;\log \left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y}{\sqrt{x \cdot x + y \cdot y}}}}\right)\\
\mathbf{elif}\;y \le 6.95543461840908064 \cdot 10^{-213}:\\
\;\;\;\;\log e\\
\mathbf{elif}\;y \le 3.3722516347658366 \cdot 10^{-167}:\\
\;\;\;\;\log \left(\frac{1}{e}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\
\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 <= -1.3453816967374705e+153)) {
VAR = log((1.0 / ((double) M_E)));
} else {
double VAR_1;
if ((y <= -1.2162082839611001e-151)) {
VAR_1 = log((exp(((x * x) / ((x * x) + (y * y)))) / exp(((y / sqrt(((x * x) + (y * y)))) * (y / sqrt(((x * x) + (y * y))))))));
} else {
double VAR_2;
if ((y <= 6.95543461840908e-213)) {
VAR_2 = log(((double) M_E));
} else {
double VAR_3;
if ((y <= 3.3722516347658366e-167)) {
VAR_3 = log((1.0 / ((double) M_E)));
} else {
VAR_3 = ((((x - y) * (x + y)) / sqrt(((x * x) + (y * y)))) / sqrt(((x * x) + (y * y))));
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.2 |
|---|---|
| Target | 0.1 |
| Herbie | 6.1 |
if y < -1.3453816967374705e+153 or 6.95543461840908e-213 < y < 3.3722516347658366e-167Initial program 56.6
rmApplied add-sqr-sqrt56.6
Applied associate-/r*56.6
rmApplied add-log-exp56.6
Simplified56.6
Taylor expanded around 0 8.7
if -1.3453816967374705e+153 < y < -1.2162082839611001e-151Initial program 0.0
rmApplied add-sqr-sqrt0.0
Applied associate-/r*0.1
rmApplied add-log-exp0.1
Simplified0.0
rmApplied add-sqr-sqrt0.0
Applied times-frac0.0
if -1.2162082839611001e-151 < y < 6.95543461840908e-213Initial program 29.4
rmApplied add-sqr-sqrt29.4
Applied associate-/r*29.4
rmApplied add-log-exp29.4
Simplified29.4
Taylor expanded around inf 14.9
if 3.3722516347658366e-167 < y Initial program 0.8
rmApplied add-sqr-sqrt0.8
Applied associate-/r*0.9
Final simplification6.1
herbie shell --seed 2020075
(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))))