| Alternative 1 | |
|---|---|
| Error | 16.3 |
| Cost | 19776 |
\[\left(\left(\cos \varepsilon - 1\right) \cdot x + \sin \varepsilon\right) \cdot \cos x
\]
(FPCore (x eps) :precision binary64 (- (sin (+ x eps)) (sin x)))
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (sin eps) (sin x)))) (if (<= eps -8e-8) t_0 (if (<= eps 7e-6) (* (cos x) eps) t_0))))
double code(double x, double eps) {
return sin((x + eps)) - sin(x);
}
double code(double x, double eps) {
double t_0 = sin(eps) - sin(x);
double tmp;
if (eps <= -8e-8) {
tmp = t_0;
} else if (eps <= 7e-6) {
tmp = cos(x) * eps;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((x + eps)) - sin(x)
end function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin(eps) - sin(x)
if (eps <= (-8d-8)) then
tmp = t_0
else if (eps <= 7d-6) then
tmp = cos(x) * eps
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
return Math.sin((x + eps)) - Math.sin(x);
}
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) - Math.sin(x);
double tmp;
if (eps <= -8e-8) {
tmp = t_0;
} else if (eps <= 7e-6) {
tmp = Math.cos(x) * eps;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): return math.sin((x + eps)) - math.sin(x)
def code(x, eps): t_0 = math.sin(eps) - math.sin(x) tmp = 0 if eps <= -8e-8: tmp = t_0 elif eps <= 7e-6: tmp = math.cos(x) * eps else: tmp = t_0 return tmp
function code(x, eps) return Float64(sin(Float64(x + eps)) - sin(x)) end
function code(x, eps) t_0 = Float64(sin(eps) - sin(x)) tmp = 0.0 if (eps <= -8e-8) tmp = t_0; elseif (eps <= 7e-6) tmp = Float64(cos(x) * eps); else tmp = t_0; end return tmp end
function tmp = code(x, eps) tmp = sin((x + eps)) - sin(x); end
function tmp_2 = code(x, eps) t_0 = sin(eps) - sin(x); tmp = 0.0; if (eps <= -8e-8) tmp = t_0; elseif (eps <= 7e-6) tmp = cos(x) * eps; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := N[(N[Sin[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] - N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -8e-8], t$95$0, If[LessEqual[eps, 7e-6], N[(N[Cos[x], $MachinePrecision] * eps), $MachinePrecision], t$95$0]]]
\sin \left(x + \varepsilon\right) - \sin x
\begin{array}{l}
t_0 := \sin \varepsilon - \sin x\\
\mathbf{if}\;\varepsilon \leq -8 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq 7 \cdot 10^{-6}:\\
\;\;\;\;\cos x \cdot \varepsilon\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 37.2 |
|---|---|
| Target | 15.2 |
| Herbie | 14.8 |
if eps < -8.0000000000000002e-8 or 6.99999999999999989e-6 < eps Initial program 30.1
Taylor expanded in x around 0 28.6
if -8.0000000000000002e-8 < eps < 6.99999999999999989e-6Initial program 44.5
Taylor expanded in eps around 0 0.4
Final simplification14.8
| Alternative 1 | |
|---|---|
| Error | 16.3 |
| Cost | 19776 |
| Alternative 2 | |
|---|---|
| Error | 15.3 |
| Cost | 6856 |
| Alternative 3 | |
|---|---|
| Error | 29.0 |
| Cost | 6464 |
| Alternative 4 | |
|---|---|
| Error | 45.4 |
| Cost | 64 |
herbie shell --seed 2023088
(FPCore (x eps)
:name "2sin (example 3.3)"
:precision binary64
:herbie-target
(* 2.0 (* (cos (+ x (/ eps 2.0))) (sin (/ eps 2.0))))
(- (sin (+ x eps)) (sin x)))