(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (tan x))) (t_1 (+ (tan x) (tan eps))))
(if (<= eps -4e-9)
(fma t_1 (/ 1.0 (fma -1.0 (* (tan x) (tan eps)) 1.0)) t_0)
(if (<= eps 1.6e-51)
(fma eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0)) eps)
(- t_0 (/ t_1 (- (fma (tan eps) t_0 1.0))))))))double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
double code(double x, double eps) {
double t_0 = -tan(x);
double t_1 = tan(x) + tan(eps);
double tmp;
if (eps <= -4e-9) {
tmp = fma(t_1, (1.0 / fma(-1.0, (tan(x) * tan(eps)), 1.0)), t_0);
} else if (eps <= 1.6e-51) {
tmp = fma(eps, (pow(sin(x), 2.0) / pow(cos(x), 2.0)), eps);
} else {
tmp = t_0 - (t_1 / -fma(tan(eps), t_0, 1.0));
}
return tmp;
}
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function code(x, eps) t_0 = Float64(-tan(x)) t_1 = Float64(tan(x) + tan(eps)) tmp = 0.0 if (eps <= -4e-9) tmp = fma(t_1, Float64(1.0 / fma(-1.0, Float64(tan(x) * tan(eps)), 1.0)), t_0); elseif (eps <= 1.6e-51) tmp = fma(eps, Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)), eps); else tmp = Float64(t_0 - Float64(t_1 / Float64(-fma(tan(eps), t_0, 1.0)))); 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[Tan[x], $MachinePrecision])}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4e-9], N[(t$95$1 * N[(1.0 / N[(-1.0 * N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[eps, 1.6e-51], N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision], N[(t$95$0 - N[(t$95$1 / (-N[(N[Tan[eps], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := -\tan x\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \frac{1}{\mathsf{fma}\left(-1, \tan x \cdot \tan \varepsilon, 1\right)}, t_0\right)\\
\mathbf{elif}\;\varepsilon \leq 1.6 \cdot 10^{-51}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, \frac{{\sin x}^{2}}{{\cos x}^{2}}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \frac{t_1}{-\mathsf{fma}\left(\tan \varepsilon, t_0, 1\right)}\\
\end{array}




Bits error versus x




Bits error versus eps
| Original | 36.8 |
|---|---|
| Target | 15.4 |
| Herbie | 1.3 |
if eps < -4.00000000000000025e-9Initial program 29.9
Applied egg-rr0.5
Applied egg-rr0.5
if -4.00000000000000025e-9 < eps < 1.6e-51Initial program 45.5
Applied egg-rr45.4
Taylor expanded in eps around 0 0.3
Simplified0.3
if 1.6e-51 < eps Initial program 29.9
Applied egg-rr3.5
Applied egg-rr3.5
Final simplification1.3
herbie shell --seed 2022166
(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)))