\sin \left(x + \varepsilon\right) - \sin x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -2.754166658325086627164164643222221684482 \cdot 10^{-5} \lor \neg \left(\varepsilon \le 5.156835808069300787421688310116496545277 \cdot 10^{-9}\right):\\
\;\;\;\;\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right) - \sin x\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sin \left(\frac{\varepsilon}{2}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)\right)\right)\\
\end{array}double f(double x, double eps) {
double r95388 = x;
double r95389 = eps;
double r95390 = r95388 + r95389;
double r95391 = sin(r95390);
double r95392 = sin(r95388);
double r95393 = r95391 - r95392;
return r95393;
}
double f(double x, double eps) {
double r95394 = eps;
double r95395 = -2.7541666583250866e-05;
bool r95396 = r95394 <= r95395;
double r95397 = 5.156835808069301e-09;
bool r95398 = r95394 <= r95397;
double r95399 = !r95398;
bool r95400 = r95396 || r95399;
double r95401 = x;
double r95402 = sin(r95401);
double r95403 = cos(r95394);
double r95404 = r95402 * r95403;
double r95405 = cos(r95401);
double r95406 = sin(r95394);
double r95407 = r95405 * r95406;
double r95408 = r95404 + r95407;
double r95409 = r95408 - r95402;
double r95410 = 2.0;
double r95411 = r95394 / r95410;
double r95412 = sin(r95411);
double r95413 = r95401 + r95394;
double r95414 = r95413 + r95401;
double r95415 = r95414 / r95410;
double r95416 = cos(r95415);
double r95417 = log1p(r95416);
double r95418 = expm1(r95417);
double r95419 = r95412 * r95418;
double r95420 = r95410 * r95419;
double r95421 = r95400 ? r95409 : r95420;
return r95421;
}




Bits error versus x




Bits error versus eps
Results
| Original | 36.8 |
|---|---|
| Target | 14.8 |
| Herbie | 0.5 |
if eps < -2.7541666583250866e-05 or 5.156835808069301e-09 < eps Initial program 29.0
rmApplied sin-sum0.5
if -2.7541666583250866e-05 < eps < 5.156835808069301e-09Initial program 45.0
rmApplied diff-sin45.0
Simplified0.4
rmApplied expm1-log1p-u0.4
Final simplification0.5
herbie shell --seed 2019235 +o rules:numerics
(FPCore (x eps)
:name "2sin (example 3.3)"
:precision binary64
:herbie-target
(* 2 (* (cos (+ x (/ eps 2))) (sin (/ eps 2))))
(- (sin (+ x eps)) (sin x)))