\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \leq -1.3574780207067694 \cdot 10^{+154}:\\
\;\;\;\;-1 + e^{\log 2 + \log \left(\frac{x}{y} \cdot \frac{x}{y}\right)}\\
\mathbf{elif}\;y \leq -1.5543412890393429 \cdot 10^{-162}:\\
\;\;\;\;\sqrt[3]{\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y} \cdot \left(\frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y} \cdot \frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\right)}\\
\mathbf{elif}\;y \leq 6.230209348455822 \cdot 10^{-173}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot y - x \cdot x}{-\left(x \cdot x + y \cdot y\right)}\\
\end{array}(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
:precision binary64
(if (<= y -1.3574780207067694e+154)
(+ -1.0 (exp (+ (log 2.0) (log (* (/ x y) (/ x y))))))
(if (<= y -1.5543412890393429e-162)
(cbrt
(*
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y)))
(*
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y)))
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y))))))
(if (<= y 6.230209348455822e-173)
1.0
(/ (- (* y y) (* x x)) (- (+ (* x x) (* y y))))))))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 <= -1.3574780207067694e+154) {
tmp = -1.0 + exp(log(2.0) + log((x / y) * (x / y)));
} else if (y <= -1.5543412890393429e-162) {
tmp = cbrt((((x - y) * (y + x)) / ((x * x) + (y * y))) * ((((x - y) * (y + x)) / ((x * x) + (y * y))) * (((x - y) * (y + x)) / ((x * x) + (y * y)))));
} else if (y <= 6.230209348455822e-173) {
tmp = 1.0;
} else {
tmp = ((y * y) - (x * x)) / -((x * x) + (y * y));
}
return tmp;
}




Bits error versus x




Bits error versus y
Results
| Original | 20.3 |
|---|---|
| Target | 0.1 |
| Herbie | 4.8 |
if y < -1.3574780207067694e154Initial program 64.0
Taylor expanded around 0 0
Simplified0
rmApplied add-sqr-sqrt_binary64_28280
Simplified0
Simplified0
rmApplied add-exp-log_binary64_28440
Applied add-exp-log_binary64_28440
Applied prod-exp_binary64_28550
if -1.3574780207067694e154 < y < -1.5543412890393429e-162Initial program 0.1
rmApplied add-cbrt-cube_binary64_28420.1
if -1.5543412890393429e-162 < y < 6.2302093484558222e-173Initial program 30.5
rmApplied frac-2neg_binary64_281730.5
Simplified30.5
Taylor expanded around 0 14.5
if 6.2302093484558222e-173 < y Initial program 2.1
rmApplied frac-2neg_binary64_28172.1
Simplified2.1
Final simplification4.8
herbie shell --seed 2021098
(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))))