| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 72008 |
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0)))
(t_1 (+ (tan x) (tan eps))))
(if (<= eps -5.4e-5)
(- (/ t_1 (- 1.0 (/ (tan eps) (/ 1.0 (tan x))))) (tan x))
(if (<= eps 5e-5)
(fma
eps
(+ 1.0 t_0)
(+
(*
(pow eps 3.0)
(+
(+ t_0 0.3333333333333333)
(+
(/ (pow (sin x) 4.0) (pow (cos x) 4.0))
(* t_0 0.3333333333333333))))
(*
(* eps eps)
(+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0))))))
(- (/ t_1 (- 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 = pow(sin(x), 2.0) / pow(cos(x), 2.0);
double t_1 = tan(x) + tan(eps);
double tmp;
if (eps <= -5.4e-5) {
tmp = (t_1 / (1.0 - (tan(eps) / (1.0 / tan(x))))) - tan(x);
} else if (eps <= 5e-5) {
tmp = fma(eps, (1.0 + t_0), ((pow(eps, 3.0) * ((t_0 + 0.3333333333333333) + ((pow(sin(x), 4.0) / pow(cos(x), 4.0)) + (t_0 * 0.3333333333333333)))) + ((eps * eps) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.0))))));
} else {
tmp = (t_1 / (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((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) t_1 = Float64(tan(x) + tan(eps)) tmp = 0.0 if (eps <= -5.4e-5) tmp = Float64(Float64(t_1 / Float64(1.0 - Float64(tan(eps) / Float64(1.0 / tan(x))))) - tan(x)); elseif (eps <= 5e-5) tmp = fma(eps, Float64(1.0 + t_0), Float64(Float64((eps ^ 3.0) * Float64(Float64(t_0 + 0.3333333333333333) + Float64(Float64((sin(x) ^ 4.0) / (cos(x) ^ 4.0)) + Float64(t_0 * 0.3333333333333333)))) + Float64(Float64(eps * eps) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)))))); else tmp = Float64(Float64(t_1 / 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[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -5.4e-5], N[(N[(t$95$1 / N[(1.0 - N[(N[Tan[eps], $MachinePrecision] / N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5e-5], N[(eps * N[(1.0 + t$95$0), $MachinePrecision] + N[(N[(N[Power[eps, 3.0], $MachinePrecision] * N[(N[(t$95$0 + 0.3333333333333333), $MachinePrecision] + N[(N[(N[Power[N[Sin[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $MachinePrecision] * N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / 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 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -5.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{t_1}{1 - \frac{\tan \varepsilon}{\frac{1}{\tan x}}} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, 1 + t_0, {\varepsilon}^{3} \cdot \left(\left(t_0 + 0.3333333333333333\right) + \left(\frac{{\sin x}^{4}}{{\cos x}^{4}} + t_0 \cdot 0.3333333333333333\right)\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\end{array}
| Original | 42.2% |
|---|---|
| Target | 76.8% |
| Herbie | 99.5% |
if eps < -5.3999999999999998e-5Initial program 51.9%
Applied egg-rr99.4%
[Start]51.9 | \[ \tan \left(x + \varepsilon\right) - \tan x
\] |
|---|---|
tan-sum [=>]99.4 | \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
div-inv [=>]99.4 | \[ \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
Simplified99.4%
[Start]99.4 | \[ \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
|---|---|
associate-*r/ [=>]99.4 | \[ \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
*-rgt-identity [=>]99.4 | \[ \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
Applied egg-rr99.4%
[Start]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
|---|---|
*-commutative [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\tan \varepsilon \cdot \tan x}} - \tan x
\] |
tan-quot [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \tan \varepsilon \cdot \color{blue}{\frac{\sin x}{\cos x}}} - \tan x
\] |
associate-*r/ [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\tan \varepsilon \cdot \sin x}{\cos x}}} - \tan x
\] |
associate-/l* [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\frac{\tan \varepsilon}{\frac{\cos x}{\sin x}}}} - \tan x
\] |
*-un-lft-identity [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon}{\frac{\color{blue}{1 \cdot \cos x}}{\sin x}}} - \tan x
\] |
associate-/l* [=>]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon}{\color{blue}{\frac{1}{\frac{\sin x}{\cos x}}}}} - \tan x
\] |
tan-quot [<=]99.4 | \[ \frac{\tan x + \tan \varepsilon}{1 - \frac{\tan \varepsilon}{\frac{1}{\color{blue}{\tan x}}}} - \tan x
\] |
if -5.3999999999999998e-5 < eps < 5.00000000000000024e-5Initial program 30.5%
Applied egg-rr31.5%
[Start]30.5 | \[ \tan \left(x + \varepsilon\right) - \tan x
\] |
|---|---|
tan-sum [=>]31.5 | \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
div-inv [=>]31.5 | \[ \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
Simplified31.5%
[Start]31.5 | \[ \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
|---|---|
associate-*r/ [=>]31.5 | \[ \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
*-rgt-identity [=>]31.5 | \[ \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
Applied egg-rr31.5%
[Start]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
|---|---|
expm1-log1p-u [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)\right)}} - \tan x
\] |
expm1-udef [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan x \cdot \tan \varepsilon\right)} - 1\right)}} - \tan x
\] |
log1p-udef [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(e^{\color{blue}{\log \left(1 + \tan x \cdot \tan \varepsilon\right)}} - 1\right)} - \tan x
\] |
add-exp-log [<=]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(1 + \tan x \cdot \tan \varepsilon\right)} - 1\right)} - \tan x
\] |
Applied egg-rr31.5%
[Start]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(\left(1 + \tan x \cdot \tan \varepsilon\right) - 1\right)} - \tan x
\] |
|---|---|
sub-neg [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \color{blue}{\left(\left(1 + \tan x \cdot \tan \varepsilon\right) + \left(-1\right)\right)}} - \tan x
\] |
+-commutative [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\left(\tan x \cdot \tan \varepsilon + 1\right)} + \left(-1\right)\right)} - \tan x
\] |
fma-def [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(\color{blue}{\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right)} + \left(-1\right)\right)} - \tan x
\] |
metadata-eval [=>]31.5 | \[ \frac{\tan x + \tan \varepsilon}{1 - \left(\mathsf{fma}\left(\tan x, \tan \varepsilon, 1\right) + \color{blue}{-1}\right)} - \tan x
\] |
Taylor expanded in eps around 0 99.6%
Simplified99.6%
[Start]99.6 | \[ \varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(-1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)
\] |
|---|---|
fma-def [=>]99.6 | \[ \color{blue}{\mathsf{fma}\left(\varepsilon, 1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}, -1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)}
\] |
sub-neg [=>]99.6 | \[ \mathsf{fma}\left(\varepsilon, \color{blue}{1 + \left(--1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}, -1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)
\] |
mul-1-neg [=>]99.6 | \[ \mathsf{fma}\left(\varepsilon, 1 + \left(-\color{blue}{\left(-\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}\right), -1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)
\] |
remove-double-neg [=>]99.6 | \[ \mathsf{fma}\left(\varepsilon, 1 + \color{blue}{\frac{{\sin x}^{2}}{{\cos x}^{2}}}, -1 \cdot \left({\varepsilon}^{2} \cdot \left(-1 \cdot \frac{{\sin x}^{3}}{{\cos x}^{3}} + -1 \cdot \frac{\sin x}{\cos x}\right)\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 - \left(-1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}} + \left(-1 \cdot \frac{{\sin x}^{4}}{{\cos x}^{4}} + -0.3333333333333333 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)\right)\right)
\] |
if 5.00000000000000024e-5 < eps Initial program 56.0%
Applied egg-rr99.4%
[Start]56.0 | \[ \tan \left(x + \varepsilon\right) - \tan x
\] |
|---|---|
tan-sum [=>]99.4 | \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
div-inv [=>]99.4 | \[ \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
Simplified99.4%
[Start]99.4 | \[ \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
|---|---|
associate-*r/ [=>]99.4 | \[ \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot 1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
*-rgt-identity [=>]99.4 | \[ \frac{\color{blue}{\tan x + \tan \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 72008 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 65736 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 32969 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 32968 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 26953 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.2% |
| Cost | 26697 |
| Alternative 7 | |
|---|---|
| Accuracy | 77.8% |
| Cost | 26440 |
| Alternative 8 | |
|---|---|
| Accuracy | 77.8% |
| Cost | 19976 |
| Alternative 9 | |
|---|---|
| Accuracy | 77.8% |
| Cost | 19976 |
| Alternative 10 | |
|---|---|
| Accuracy | 58.4% |
| Cost | 6464 |
| Alternative 11 | |
|---|---|
| Accuracy | 31.5% |
| Cost | 64 |
herbie shell --seed 2023130
(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)))