| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 65472 |
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (tan x))))
(if (<= eps -3.3e-9)
(fma
(+ (/ (sin x) (cos x)) (tan eps))
(/ 1.0 (- 1.0 (* (tan eps) (tan x))))
t_0)
(if (<= eps 7e-19)
(* eps (+ 1.0 (* (sin x) (* (sin x) (pow (cos x) -2.0)))))
(fma
(+ (tan eps) (tan x))
(/ 1.0 (- 1.0 (* (sin x) (/ (tan eps) (cos x)))))
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 tmp;
if (eps <= -3.3e-9) {
tmp = fma(((sin(x) / cos(x)) + tan(eps)), (1.0 / (1.0 - (tan(eps) * tan(x)))), t_0);
} else if (eps <= 7e-19) {
tmp = eps * (1.0 + (sin(x) * (sin(x) * pow(cos(x), -2.0))));
} else {
tmp = fma((tan(eps) + tan(x)), (1.0 / (1.0 - (sin(x) * (tan(eps) / cos(x))))), 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)) tmp = 0.0 if (eps <= -3.3e-9) tmp = fma(Float64(Float64(sin(x) / cos(x)) + tan(eps)), Float64(1.0 / Float64(1.0 - Float64(tan(eps) * tan(x)))), t_0); elseif (eps <= 7e-19) tmp = Float64(eps * Float64(1.0 + Float64(sin(x) * Float64(sin(x) * (cos(x) ^ -2.0))))); else tmp = fma(Float64(tan(eps) + tan(x)), Float64(1.0 / Float64(1.0 - Float64(sin(x) * Float64(tan(eps) / cos(x))))), 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])}, If[LessEqual[eps, -3.3e-9], N[(N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 - N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[eps, 7e-19], N[(eps * N[(1.0 + N[(N[Sin[x], $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] * N[Power[N[Cos[x], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 - N[(N[Sin[x], $MachinePrecision] * N[(N[Tan[eps], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]]]]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
t_0 := -\tan x\\
\mathbf{if}\;\varepsilon \leq -3.3 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin x}{\cos x} + \tan \varepsilon, \frac{1}{1 - \tan \varepsilon \cdot \tan x}, t_0\right)\\
\mathbf{elif}\;\varepsilon \leq 7 \cdot 10^{-19}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \sin x \cdot \left(\sin x \cdot {\cos x}^{-2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\tan \varepsilon + \tan x, \frac{1}{1 - \sin x \cdot \frac{\tan \varepsilon}{\cos x}}, t_0\right)\\
\end{array}
| Original | 41.6% |
|---|---|
| Target | 75.8% |
| Herbie | 99.0% |
if eps < -3.30000000000000018e-9Initial program 61.7%
Applied egg-rr99.6%
[Start]61.7 | \[ \tan \left(x + \varepsilon\right) - \tan x
\] |
|---|---|
tan-sum [=>]99.5 | \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
div-inv [=>]99.6 | \[ \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
fma-neg [=>]99.6 | \[ \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)}
\] |
Applied egg-rr99.5%
[Start]99.6 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
|---|---|
tan-quot [=>]99.6 | \[ \mathsf{fma}\left(\color{blue}{\frac{\sin x}{\cos x}} + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
div-inv [=>]99.6 | \[ \mathsf{fma}\left(\color{blue}{\sin x \cdot \frac{1}{\cos x}} + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
fma-def [=>]99.5 | \[ \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\sin x, \frac{1}{\cos x}, \tan \varepsilon\right)}, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
Simplified99.6%
[Start]99.5 | \[ \mathsf{fma}\left(\mathsf{fma}\left(\sin x, \frac{1}{\cos x}, \tan \varepsilon\right), \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
|---|---|
fma-udef [=>]99.6 | \[ \mathsf{fma}\left(\color{blue}{\sin x \cdot \frac{1}{\cos x} + \tan \varepsilon}, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
associate-*r/ [=>]99.6 | \[ \mathsf{fma}\left(\color{blue}{\frac{\sin x \cdot 1}{\cos x}} + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
*-rgt-identity [=>]99.6 | \[ \mathsf{fma}\left(\frac{\color{blue}{\sin x}}{\cos x} + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
if -3.30000000000000018e-9 < eps < 7.00000000000000031e-19Initial program 32.5%
Taylor expanded in eps around 0 99.7%
Simplified99.7%
[Start]99.7 | \[ \varepsilon \cdot \left(1 - -1 \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)
\] |
|---|---|
mul-1-neg [=>]99.7 | \[ \varepsilon \cdot \left(1 - \color{blue}{\left(-\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)}\right)
\] |
Applied egg-rr99.8%
[Start]99.7 | \[ \varepsilon \cdot \left(1 - \left(-\frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\right)
\] |
|---|---|
div-inv [=>]99.7 | \[ \varepsilon \cdot \left(1 - \left(-\color{blue}{{\sin x}^{2} \cdot \frac{1}{{\cos x}^{2}}}\right)\right)
\] |
unpow2 [=>]99.7 | \[ \varepsilon \cdot \left(1 - \left(-\color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{{\cos x}^{2}}\right)\right)
\] |
associate-*l* [=>]99.8 | \[ \varepsilon \cdot \left(1 - \left(-\color{blue}{\sin x \cdot \left(\sin x \cdot \frac{1}{{\cos x}^{2}}\right)}\right)\right)
\] |
pow-flip [=>]99.8 | \[ \varepsilon \cdot \left(1 - \left(-\sin x \cdot \left(\sin x \cdot \color{blue}{{\cos x}^{\left(-2\right)}}\right)\right)\right)
\] |
metadata-eval [=>]99.8 | \[ \varepsilon \cdot \left(1 - \left(-\sin x \cdot \left(\sin x \cdot {\cos x}^{\color{blue}{-2}}\right)\right)\right)
\] |
if 7.00000000000000031e-19 < eps Initial program 51.0%
Applied egg-rr99.5%
[Start]51.0 | \[ \tan \left(x + \varepsilon\right) - \tan x
\] |
|---|---|
tan-sum [=>]99.5 | \[ \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
div-inv [=>]99.5 | \[ \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x
\] |
fma-neg [=>]99.5 | \[ \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)}
\] |
Applied egg-rr99.5%
[Start]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)
\] |
|---|---|
*-commutative [=>]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\tan \varepsilon \cdot \tan x}}, -\tan x\right)
\] |
tan-quot [=>]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan \varepsilon \cdot \color{blue}{\frac{\sin x}{\cos x}}}, -\tan x\right)
\] |
associate-*r/ [=>]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\frac{\tan \varepsilon \cdot \sin x}{\cos x}}}, -\tan x\right)
\] |
Simplified99.6%
[Start]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \frac{\tan \varepsilon \cdot \sin x}{\cos x}}, -\tan x\right)
\] |
|---|---|
associate-/l* [=>]99.5 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\frac{\tan \varepsilon}{\frac{\cos x}{\sin x}}}}, -\tan x\right)
\] |
associate-/r/ [=>]99.6 | \[ \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\frac{\tan \varepsilon}{\cos x} \cdot \sin x}}, -\tan x\right)
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 65472 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 45960 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 39428 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 39300 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 32969 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 32968 |
| Alternative 7 | |
|---|---|
| Accuracy | 76.8% |
| Cost | 26505 |
| Alternative 8 | |
|---|---|
| Accuracy | 76.9% |
| Cost | 26249 |
| Alternative 9 | |
|---|---|
| Accuracy | 76.8% |
| Cost | 13449 |
| Alternative 10 | |
|---|---|
| Accuracy | 57.7% |
| Cost | 12992 |
| Alternative 11 | |
|---|---|
| Accuracy | 56.4% |
| Cost | 7497 |
| Alternative 12 | |
|---|---|
| Accuracy | 54.4% |
| Cost | 6985 |
| Alternative 13 | |
|---|---|
| Accuracy | 31.3% |
| Cost | 64 |
herbie shell --seed 2023159
(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)))