\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\begin{array}{l}
\mathbf{if}\;y \le -3.847434879443193393633321330852372755378 \cdot 10^{151}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \le -1.694063246808970668811003130641552295003 \cdot 10^{-162}:\\
\;\;\;\;e^{\mathsf{log1p}\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)} - 1\\
\mathbf{elif}\;y \le 6.451959238219760281097758056287369172736 \cdot 10^{-208}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(1\right)\right)\\
\mathbf{elif}\;y \le 1.336866892806927934140174920733392856435 \cdot 10^{-166}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;e^{\mathsf{log1p}\left(\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\right)} - 1\\
\end{array}double f(double x, double y) {
double r97489 = x;
double r97490 = y;
double r97491 = r97489 - r97490;
double r97492 = r97489 + r97490;
double r97493 = r97491 * r97492;
double r97494 = r97489 * r97489;
double r97495 = r97490 * r97490;
double r97496 = r97494 + r97495;
double r97497 = r97493 / r97496;
return r97497;
}
double f(double x, double y) {
double r97498 = y;
double r97499 = -3.8474348794431934e+151;
bool r97500 = r97498 <= r97499;
double r97501 = -1.0;
double r97502 = -1.6940632468089707e-162;
bool r97503 = r97498 <= r97502;
double r97504 = x;
double r97505 = r97504 - r97498;
double r97506 = r97504 + r97498;
double r97507 = r97505 * r97506;
double r97508 = r97504 * r97504;
double r97509 = r97498 * r97498;
double r97510 = r97508 + r97509;
double r97511 = r97507 / r97510;
double r97512 = log1p(r97511);
double r97513 = exp(r97512);
double r97514 = 1.0;
double r97515 = r97513 - r97514;
double r97516 = 6.45195923821976e-208;
bool r97517 = r97498 <= r97516;
double r97518 = expm1(r97514);
double r97519 = log1p(r97518);
double r97520 = 1.336866892806928e-166;
bool r97521 = r97498 <= r97520;
double r97522 = r97521 ? r97501 : r97515;
double r97523 = r97517 ? r97519 : r97522;
double r97524 = r97503 ? r97515 : r97523;
double r97525 = r97500 ? r97501 : r97524;
return r97525;
}




Bits error versus x




Bits error versus y
Results
| Original | 19.6 |
|---|---|
| Target | 0.0 |
| Herbie | 5.5 |
if y < -3.8474348794431934e+151 or 6.45195923821976e-208 < y < 1.336866892806928e-166Initial program 55.7
Taylor expanded around 0 8.5
if -3.8474348794431934e+151 < y < -1.6940632468089707e-162 or 1.336866892806928e-166 < y Initial program 0.3
rmApplied log1p-expm1-u0.3
rmApplied expm1-log1p-u0.3
Simplified0.3
rmApplied expm1-udef0.3
if -1.6940632468089707e-162 < y < 6.45195923821976e-208Initial program 28.7
rmApplied log1p-expm1-u28.7
Taylor expanded around inf 13.4
Final simplification5.5
herbie shell --seed 2019353 +o rules:numerics
(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))))