
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps): return math.tan((x + eps)) - math.tan(x)
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function tmp = code(x, eps) tmp = tan((x + eps)) - tan(x); end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps): return math.tan((x + eps)) - math.tan(x)
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function tmp = code(x, eps) tmp = tan((x + eps)) - tan(x); end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}
(FPCore (x eps)
:precision binary64
(if (or (<= eps -8.4e-7) (not (<= eps 3.1e-7)))
(fma
(+ (tan x) (tan eps))
(/ -1.0 (fma (tan x) (tan eps) -1.0))
(- (tan x)))
(+
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(*
(* eps eps)
(+ (/ (pow (sin x) 3.0) (pow (cos x) 3.0)) (/ (sin x) (cos x)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -8.4e-7) || !(eps <= 3.1e-7)) {
tmp = fma((tan(x) + tan(eps)), (-1.0 / fma(tan(x), tan(eps), -1.0)), -tan(x));
} else {
tmp = (eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)))) + ((eps * eps) * ((pow(sin(x), 3.0) / pow(cos(x), 3.0)) + (sin(x) / cos(x))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -8.4e-7) || !(eps <= 3.1e-7)) tmp = fma(Float64(tan(x) + tan(eps)), Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), Float64(-tan(x))); else tmp = Float64(Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + Float64(Float64(eps * eps) * Float64(Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)) + Float64(sin(x) / cos(x))))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -8.4e-7], N[Not[LessEqual[eps, 3.1e-7]], $MachinePrecision]], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], N[(N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $MachinePrecision] * N[(N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.4 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 3.1 \cdot 10^{-7}\right):\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{{\sin x}^{3}}{{\cos x}^{3}} + \frac{\sin x}{\cos x}\right)\\
\end{array}
\end{array}
if eps < -8.4e-7 or 3.1e-7 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
frac-2neg99.5%
metadata-eval99.5%
div-inv99.5%
sub-neg99.5%
distribute-neg-in99.5%
metadata-eval99.5%
distribute-lft-neg-in99.5%
add-sqr-sqrt42.1%
sqrt-unprod80.1%
sqr-neg80.1%
sqrt-unprod38.0%
add-sqr-sqrt60.1%
distribute-lft-neg-in60.1%
add-sqr-sqrt22.0%
sqrt-unprod79.5%
sqr-neg79.5%
sqrt-unprod57.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
if -8.4e-7 < eps < 3.1e-7Initial program 29.2%
tan-sum29.6%
clear-num29.3%
Applied egg-rr29.3%
Taylor expanded in eps around 0 99.7%
mul-1-neg99.7%
unsub-neg99.7%
cancel-sign-sub-inv99.7%
metadata-eval99.7%
*-lft-identity99.7%
distribute-lft-in99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (sin eps) (cos eps))))
(if (or (<= eps -8e-9) (not (<= eps 6.3e-9)))
(fma
(+ (tan x) (tan eps))
(/ -1.0 (fma (tan x) (tan eps) -1.0))
(- (tan x)))
(+
(/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
(/ eps (/ (pow (cos x) 2.0) (pow (sin x) 2.0)))))))
double code(double x, double eps) {
double t_0 = sin(eps) / cos(eps);
double tmp;
if ((eps <= -8e-9) || !(eps <= 6.3e-9)) {
tmp = fma((tan(x) + tan(eps)), (-1.0 / fma(tan(x), tan(eps), -1.0)), -tan(x));
} else {
tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + (eps / (pow(cos(x), 2.0) / pow(sin(x), 2.0)));
}
return tmp;
}
function code(x, eps) t_0 = Float64(sin(eps) / cos(eps)) tmp = 0.0 if ((eps <= -8e-9) || !(eps <= 6.3e-9)) tmp = fma(Float64(tan(x) + tan(eps)), Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), Float64(-tan(x))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + Float64(eps / Float64((cos(x) ^ 2.0) / (sin(x) ^ 2.0)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -8e-9], N[Not[LessEqual[eps, 6.3e-9]], $MachinePrecision]], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eps / N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -8 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 6.3 \cdot 10^{-9}\right):\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}\\
\end{array}
\end{array}
if eps < -8.0000000000000005e-9 or 6.3000000000000002e-9 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
frac-2neg99.5%
metadata-eval99.5%
div-inv99.5%
sub-neg99.5%
distribute-neg-in99.5%
metadata-eval99.5%
distribute-lft-neg-in99.5%
add-sqr-sqrt42.1%
sqrt-unprod80.1%
sqr-neg80.1%
sqrt-unprod38.0%
add-sqr-sqrt60.1%
distribute-lft-neg-in60.1%
add-sqr-sqrt22.0%
sqrt-unprod79.5%
sqr-neg79.5%
sqrt-unprod57.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
if -8.0000000000000005e-9 < eps < 6.3000000000000002e-9Initial program 29.2%
tan-sum29.6%
div-inv29.6%
fma-neg29.6%
Applied egg-rr29.6%
Taylor expanded in x around inf 29.6%
associate--l+61.0%
sub-neg61.0%
*-commutative61.0%
sub-neg61.0%
Simplified61.0%
Taylor expanded in eps around 0 99.5%
associate-/l*99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (sin eps) (cos eps))))
(if (or (<= eps -6.8e-9) (not (<= eps 3.8e-9)))
(fma
(+ (tan x) (tan eps))
(/ -1.0 (fma (tan x) (tan eps) -1.0))
(- (tan x)))
(+
(/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
(/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double t_0 = sin(eps) / cos(eps);
double tmp;
if ((eps <= -6.8e-9) || !(eps <= 3.8e-9)) {
tmp = fma((tan(x) + tan(eps)), (-1.0 / fma(tan(x), tan(eps), -1.0)), -tan(x));
} else {
tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + ((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(sin(eps) / cos(eps)) tmp = 0.0 if ((eps <= -6.8e-9) || !(eps <= 3.8e-9)) tmp = fma(Float64(tan(x) + tan(eps)), Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), Float64(-tan(x))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + Float64(Float64(eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -6.8e-9], N[Not[LessEqual[eps, 3.8e-9]], $MachinePrecision]], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -6.8 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.8 \cdot 10^{-9}\right):\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -6.7999999999999997e-9 or 3.80000000000000011e-9 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
frac-2neg99.5%
metadata-eval99.5%
div-inv99.5%
sub-neg99.5%
distribute-neg-in99.5%
metadata-eval99.5%
distribute-lft-neg-in99.5%
add-sqr-sqrt42.1%
sqrt-unprod80.1%
sqr-neg80.1%
sqrt-unprod38.0%
add-sqr-sqrt60.1%
distribute-lft-neg-in60.1%
add-sqr-sqrt22.0%
sqrt-unprod79.5%
sqr-neg79.5%
sqrt-unprod57.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
if -6.7999999999999997e-9 < eps < 3.80000000000000011e-9Initial program 29.2%
tan-sum29.6%
div-inv29.6%
fma-neg29.6%
Applied egg-rr29.6%
Taylor expanded in x around inf 29.6%
associate--l+61.0%
sub-neg61.0%
*-commutative61.0%
sub-neg61.0%
Simplified61.0%
Taylor expanded in eps around 0 99.5%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -5.5e-9) (not (<= eps 2.8e-9)))
(fma
(+ (tan x) (tan eps))
(/ -1.0 (fma (tan x) (tan eps) -1.0))
(- (tan x)))
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.5e-9) || !(eps <= 2.8e-9)) {
tmp = fma((tan(x) + tan(eps)), (-1.0 / fma(tan(x), tan(eps), -1.0)), -tan(x));
} else {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -5.5e-9) || !(eps <= 2.8e-9)) tmp = fma(Float64(tan(x) + tan(eps)), Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), Float64(-tan(x))); else tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -5.5e-9], N[Not[LessEqual[eps, 2.8e-9]], $MachinePrecision]], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.5 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 2.8 \cdot 10^{-9}\right):\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, -\tan x\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -5.4999999999999996e-9 or 2.79999999999999984e-9 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
frac-2neg99.5%
metadata-eval99.5%
div-inv99.5%
sub-neg99.5%
distribute-neg-in99.5%
metadata-eval99.5%
distribute-lft-neg-in99.5%
add-sqr-sqrt42.1%
sqrt-unprod80.1%
sqr-neg80.1%
sqrt-unprod38.0%
add-sqr-sqrt60.1%
distribute-lft-neg-in60.1%
add-sqr-sqrt22.0%
sqrt-unprod79.5%
sqr-neg79.5%
sqrt-unprod57.4%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
associate-*r/99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.6%
Simplified99.6%
if -5.4999999999999996e-9 < eps < 2.79999999999999984e-9Initial program 29.2%
Taylor expanded in eps around 0 99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
*-lft-identity99.4%
distribute-lft-in99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps)))
(t_1 (/ 1.0 (- 1.0 (* (tan x) (tan eps))))))
(if (<= eps -3.6e-9)
(fma t_0 t_1 (- (tan x)))
(if (<= eps 3.55e-9)
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(- (* t_0 t_1) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double t_1 = 1.0 / (1.0 - (tan(x) * tan(eps)));
double tmp;
if (eps <= -3.6e-9) {
tmp = fma(t_0, t_1, -tan(x));
} else if (eps <= 3.55e-9) {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = (t_0 * t_1) - tan(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) t_1 = Float64(1.0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) tmp = 0.0 if (eps <= -3.6e-9) tmp = fma(t_0, t_1, Float64(-tan(x))); elseif (eps <= 3.55e-9) tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = Float64(Float64(t_0 * t_1) - tan(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.6e-9], N[(t$95$0 * t$95$1 + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 3.55e-9], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \frac{1}{1 - \tan x \cdot \tan \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_1, -\tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 3.55 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot t_1 - \tan x\\
\end{array}
\end{array}
if eps < -3.6e-9Initial program 66.7%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
if -3.6e-9 < eps < 3.54999999999999994e-9Initial program 29.2%
Taylor expanded in eps around 0 99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
*-lft-identity99.4%
distribute-lft-in99.5%
*-rgt-identity99.5%
Simplified99.5%
if 3.54999999999999994e-9 < eps Initial program 48.4%
tan-sum99.5%
div-inv99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4e-9) (not (<= eps 4.2e-9))) (- (* (+ (tan x) (tan eps)) (/ 1.0 (- 1.0 (* (tan x) (tan eps))))) (tan x)) (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4e-9) || !(eps <= 4.2e-9)) {
tmp = ((tan(x) + tan(eps)) * (1.0 / (1.0 - (tan(x) * tan(eps))))) - tan(x);
} else {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-4d-9)) .or. (.not. (eps <= 4.2d-9))) then
tmp = ((tan(x) + tan(eps)) * (1.0d0 / (1.0d0 - (tan(x) * tan(eps))))) - tan(x)
else
tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -4e-9) || !(eps <= 4.2e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) * (1.0 / (1.0 - (Math.tan(x) * Math.tan(eps))))) - Math.tan(x);
} else {
tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4e-9) or not (eps <= 4.2e-9): tmp = ((math.tan(x) + math.tan(eps)) * (1.0 / (1.0 - (math.tan(x) * math.tan(eps))))) - math.tan(x) else: tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -4e-9) || !(eps <= 4.2e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) * Float64(1.0 / Float64(1.0 - Float64(tan(x) * tan(eps))))) - tan(x)); else tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4e-9) || ~((eps <= 4.2e-9))) tmp = ((tan(x) + tan(eps)) * (1.0 / (1.0 - (tan(x) * tan(eps))))) - tan(x); else tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4e-9], N[Not[LessEqual[eps, 4.2e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 4.2 \cdot 10^{-9}\right):\\
\;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -4.00000000000000025e-9 or 4.20000000000000039e-9 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
Applied egg-rr99.5%
if -4.00000000000000025e-9 < eps < 4.20000000000000039e-9Initial program 29.2%
Taylor expanded in eps around 0 99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
*-lft-identity99.4%
distribute-lft-in99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.3e-9) (not (<= eps 1.82e-9))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.3e-9) || !(eps <= 1.82e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-3.3d-9)) .or. (.not. (eps <= 1.82d-9))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.3e-9) || !(eps <= 1.82e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.3e-9) or not (eps <= 1.82e-9): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.3e-9) || !(eps <= 1.82e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.3e-9) || ~((eps <= 1.82e-9))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.3e-9], N[Not[LessEqual[eps, 1.82e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.82 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -3.30000000000000018e-9 or 1.8199999999999999e-9 < eps Initial program 57.4%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if -3.30000000000000018e-9 < eps < 1.8199999999999999e-9Initial program 29.2%
Taylor expanded in eps around 0 99.4%
cancel-sign-sub-inv99.4%
metadata-eval99.4%
*-lft-identity99.4%
distribute-lft-in99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -8.2e-5) (not (<= eps 0.0016))) (- (/ 1.0 (/ (cos eps) (sin eps))) (tan x)) (* eps (+ (/ (pow (sin x) 2.0) (pow (cos x) 2.0)) 1.0))))
double code(double x, double eps) {
double tmp;
if ((eps <= -8.2e-5) || !(eps <= 0.0016)) {
tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x);
} else {
tmp = eps * ((pow(sin(x), 2.0) / pow(cos(x), 2.0)) + 1.0);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-8.2d-5)) .or. (.not. (eps <= 0.0016d0))) then
tmp = (1.0d0 / (cos(eps) / sin(eps))) - tan(x)
else
tmp = eps * (((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)) + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -8.2e-5) || !(eps <= 0.0016)) {
tmp = (1.0 / (Math.cos(eps) / Math.sin(eps))) - Math.tan(x);
} else {
tmp = eps * ((Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)) + 1.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -8.2e-5) or not (eps <= 0.0016): tmp = (1.0 / (math.cos(eps) / math.sin(eps))) - math.tan(x) else: tmp = eps * ((math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)) + 1.0) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -8.2e-5) || !(eps <= 0.0016)) tmp = Float64(Float64(1.0 / Float64(cos(eps) / sin(eps))) - tan(x)); else tmp = Float64(eps * Float64(Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -8.2e-5) || ~((eps <= 0.0016))) tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x); else tmp = eps * (((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -8.2e-5], N[Not[LessEqual[eps, 0.0016]], $MachinePrecision]], N[(N[(1.0 / N[(N[Cos[eps], $MachinePrecision] / N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps * N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.2 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 0.0016\right):\\
\;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\
\end{array}
\end{array}
if eps < -8.20000000000000009e-5 or 0.00160000000000000008 < eps Initial program 58.3%
tan-sum99.7%
clear-num99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 60.7%
if -8.20000000000000009e-5 < eps < 0.00160000000000000008Initial program 28.8%
tan-sum30.5%
div-inv30.5%
fma-neg30.6%
Applied egg-rr30.6%
Taylor expanded in eps around 0 98.4%
Final simplification80.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000265) (not (<= eps 0.0016))) (- (/ 1.0 (/ (cos eps) (sin eps))) (tan x)) (+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000265) || !(eps <= 0.0016)) {
tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x);
} else {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000265d0)) .or. (.not. (eps <= 0.0016d0))) then
tmp = (1.0d0 / (cos(eps) / sin(eps))) - tan(x)
else
tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000265) || !(eps <= 0.0016)) {
tmp = (1.0 / (Math.cos(eps) / Math.sin(eps))) - Math.tan(x);
} else {
tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000265) or not (eps <= 0.0016): tmp = (1.0 / (math.cos(eps) / math.sin(eps))) - math.tan(x) else: tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000265) || !(eps <= 0.0016)) tmp = Float64(Float64(1.0 / Float64(cos(eps) / sin(eps))) - tan(x)); else tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000265) || ~((eps <= 0.0016))) tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x); else tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000265], N[Not[LessEqual[eps, 0.0016]], $MachinePrecision]], N[(N[(1.0 / N[(N[Cos[eps], $MachinePrecision] / N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000265 \lor \neg \left(\varepsilon \leq 0.0016\right):\\
\;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -2.6499999999999999e-4 or 0.00160000000000000008 < eps Initial program 58.3%
tan-sum99.7%
clear-num99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 60.7%
if -2.6499999999999999e-4 < eps < 0.00160000000000000008Initial program 28.8%
Taylor expanded in eps around 0 98.4%
cancel-sign-sub-inv98.4%
metadata-eval98.4%
*-lft-identity98.4%
distribute-lft-in98.5%
*-rgt-identity98.5%
Simplified98.5%
Final simplification80.6%
(FPCore (x eps) :precision binary64 (tan eps))
double code(double x, double eps) {
return tan(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan(eps)
end function
public static double code(double x, double eps) {
return Math.tan(eps);
}
def code(x, eps): return math.tan(eps)
function code(x, eps) return tan(eps) end
function tmp = code(x, eps) tmp = tan(eps); end
code[x_, eps_] := N[Tan[eps], $MachinePrecision]
\begin{array}{l}
\\
\tan \varepsilon
\end{array}
Initial program 42.7%
Taylor expanded in x around 0 60.0%
tan-quot60.2%
expm1-log1p-u51.4%
expm1-udef22.9%
Applied egg-rr22.9%
expm1-def51.4%
expm1-log1p60.2%
Simplified60.2%
Final simplification60.2%
(FPCore (x eps) :precision binary64 eps)
double code(double x, double eps) {
return eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps
end function
public static double code(double x, double eps) {
return eps;
}
def code(x, eps): return eps
function code(x, eps) return eps end
function tmp = code(x, eps) tmp = eps; end
code[x_, eps_] := eps
\begin{array}{l}
\\
\varepsilon
\end{array}
Initial program 42.7%
Taylor expanded in x around 0 60.0%
Taylor expanded in eps around 0 33.2%
Final simplification33.2%
(FPCore (x eps) :precision binary64 (/ (sin eps) (* (cos x) (cos (+ x eps)))))
double code(double x, double eps) {
return sin(eps) / (cos(x) * cos((x + eps)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin(eps) / (cos(x) * cos((x + eps)))
end function
public static double code(double x, double eps) {
return Math.sin(eps) / (Math.cos(x) * Math.cos((x + eps)));
}
def code(x, eps): return math.sin(eps) / (math.cos(x) * math.cos((x + eps)))
function code(x, eps) return Float64(sin(eps) / Float64(cos(x) * cos(Float64(x + eps)))) end
function tmp = code(x, eps) tmp = sin(eps) / (cos(x) * cos((x + eps))); end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}
\end{array}
herbie shell --seed 2023278
(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)))