(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)))
(t_2 (- 1.0 (* (tan x) (tan eps)))))
(if (<= eps -1.533186348669762e-8)
(- (/ t_1 t_2) (tan x))
(if (<= eps 6.831258178301332e-22)
(+
(/ (/ (sin eps) (cos eps)) t_2)
(/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0)))
(fma (/ 1.0 (fma (tan eps) t_0 1.0)) t_1 t_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 t_2 = 1.0 - (tan(x) * tan(eps));
double tmp;
if (eps <= -1.533186348669762e-8) {
tmp = (t_1 / t_2) - tan(x);
} else if (eps <= 6.831258178301332e-22) {
tmp = ((sin(eps) / cos(eps)) / t_2) + ((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0));
} else {
tmp = fma((1.0 / fma(tan(eps), t_0, 1.0)), t_1, t_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)) t_2 = Float64(1.0 - Float64(tan(x) * tan(eps))) tmp = 0.0 if (eps <= -1.533186348669762e-8) tmp = Float64(Float64(t_1 / t_2) - tan(x)); elseif (eps <= 6.831258178301332e-22) tmp = Float64(Float64(Float64(sin(eps) / cos(eps)) / t_2) + Float64(Float64(eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0))); else tmp = fma(Float64(1.0 / fma(tan(eps), t_0, 1.0)), t_1, t_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]}, Block[{t$95$2 = N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -1.533186348669762e-8], N[(N[(t$95$1 / t$95$2), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 6.831258178301332e-22], N[(N[(N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(eps * N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[Tan[eps], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision]]]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := -\tan x\\
t_1 := \tan x + \tan \varepsilon\\
t_2 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -1.533186348669762 \cdot 10^{-8}:\\
\;\;\;\;\frac{t_1}{t_2} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 6.831258178301332 \cdot 10^{-22}:\\
\;\;\;\;\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{t_2} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\mathsf{fma}\left(\tan \varepsilon, t_0, 1\right)}, t_1, t_0\right)\\
\end{array}
| Original | 37.0 |
|---|---|
| Target | 14.8 |
| Herbie | 0.6 |
if eps < -1.5331863486697621e-8Initial program 29.3
Applied egg-rr0.4
if -1.5331863486697621e-8 < eps < 6.831258178301332e-22Initial program 45.2
Applied egg-rr45.0
Taylor expanded in x around inf 45.0
Simplified26.3
Applied egg-rr26.3
Taylor expanded in eps around 0 0.3
if 6.831258178301332e-22 < eps Initial program 29.4
Applied egg-rr1.3
Applied egg-rr1.3
Final simplification0.6
herbie shell --seed 2022210
(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)))