| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 39104 |
\[\frac{\sin \varepsilon}{\cos x \cdot \left(\cos x \cdot \cos \varepsilon - \sin \varepsilon \cdot \sin x\right)}
\]
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -4.8e-7)
(- (- (tan x)) (/ t_0 (fma (tan x) (tan eps) -1.0)))
(if (<= eps 3.4e-7)
(/ (sin (- eps)) (* (cos x) (- (* eps (sin x)) (cos x))))
(- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))))))double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double tmp;
if (eps <= -4.8e-7) {
tmp = -tan(x) - (t_0 / fma(tan(x), tan(eps), -1.0));
} else if (eps <= 3.4e-7) {
tmp = sin(-eps) / (cos(x) * ((eps * sin(x)) - cos(x)));
} else {
tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
}
return tmp;
}
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) tmp = 0.0 if (eps <= -4.8e-7) tmp = Float64(Float64(-tan(x)) - Float64(t_0 / fma(tan(x), tan(eps), -1.0))); elseif (eps <= 3.4e-7) tmp = Float64(sin(Float64(-eps)) / Float64(cos(x) * Float64(Float64(eps * sin(x)) - cos(x)))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); end return tmp end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.8e-7], N[((-N[Tan[x], $MachinePrecision]) - N[(t$95$0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.4e-7], N[(N[Sin[(-eps)], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -4.8 \cdot 10^{-7}:\\
\;\;\;\;\left(-\tan x\right) - \frac{t_0}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\mathbf{elif}\;\varepsilon \leq 3.4 \cdot 10^{-7}:\\
\;\;\;\;\frac{\sin \left(-\varepsilon\right)}{\cos x \cdot \left(\varepsilon \cdot \sin x - \cos x\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\end{array}
| Original | 37.4 |
|---|---|
| Target | 15.6 |
| Herbie | 0.4 |
if eps < -4.79999999999999957e-7Initial program 31.1
Applied egg-rr0.5
Applied egg-rr0.5
Simplified0.4
if -4.79999999999999957e-7 < eps < 3.39999999999999974e-7Initial program 44.8
Applied egg-rr44.8
Applied egg-rr44.8
Simplified0.5
Taylor expanded in eps around 0 0.3
Simplified0.3
Applied egg-rr59.6
Simplified0.3
if 3.39999999999999974e-7 < eps Initial program 29.8
Applied egg-rr0.4
Simplified0.4
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 39104 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 33220 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 33092 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 32969 |
| Alternative 5 | |
|---|---|
| Error | 0.4 |
| Cost | 32968 |
| Alternative 6 | |
|---|---|
| Error | 14.9 |
| Cost | 26176 |
| Alternative 7 | |
|---|---|
| Error | 15.2 |
| Cost | 19904 |
| Alternative 8 | |
|---|---|
| Error | 15.1 |
| Cost | 19784 |
| Alternative 9 | |
|---|---|
| Error | 15.6 |
| Cost | 19648 |
| Alternative 10 | |
|---|---|
| Error | 15.0 |
| Cost | 13321 |
| Alternative 11 | |
|---|---|
| Error | 27.3 |
| Cost | 12992 |
| Alternative 12 | |
|---|---|
| Error | 39.0 |
| Cost | 6720 |
| Alternative 13 | |
|---|---|
| Error | 61.7 |
| Cost | 128 |
herbie shell --seed 2022343
(FPCore (x eps)
:name "2tan (problem 3.3.2)"
:precision binary64
:herbie-target
(/ (sin eps) (* (cos x) (cos (+ x eps))))
(- (tan (+ x eps)) (tan x)))