
(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 10 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
(let* ((t_0 (- (tan x)))
(t_1 (fma -1.0 (tan x) (tan x)))
(t_2 (/ (sin x) (cos x)))
(t_3 (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))
(t_4 (+ (tan x) (tan eps)))
(t_5 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(if (<= eps -4.8e-5)
(+ (fma t_4 (/ 1.0 (- 1.0 (log (pow (exp (tan eps)) (tan x))))) t_0) t_1)
(if (<= eps 5.2e-11)
(+
t_1
(+
(* eps (+ 1.0 t_5))
(+
(* (pow eps 2.0) (+ t_2 t_3))
(*
(pow eps 3.0)
(+
0.3333333333333333
(+
t_5
(/ (* (sin x) (- t_3 (* t_2 -0.3333333333333333))) (cos x))))))))
(- t_0 (/ t_4 (fma (tan x) (tan eps) -1.0)))))))
double code(double x, double eps) {
double t_0 = -tan(x);
double t_1 = fma(-1.0, tan(x), tan(x));
double t_2 = sin(x) / cos(x);
double t_3 = pow(sin(x), 3.0) / pow(cos(x), 3.0);
double t_4 = tan(x) + tan(eps);
double t_5 = pow(sin(x), 2.0) / pow(cos(x), 2.0);
double tmp;
if (eps <= -4.8e-5) {
tmp = fma(t_4, (1.0 / (1.0 - log(pow(exp(tan(eps)), tan(x))))), t_0) + t_1;
} else if (eps <= 5.2e-11) {
tmp = t_1 + ((eps * (1.0 + t_5)) + ((pow(eps, 2.0) * (t_2 + t_3)) + (pow(eps, 3.0) * (0.3333333333333333 + (t_5 + ((sin(x) * (t_3 - (t_2 * -0.3333333333333333))) / cos(x)))))));
} else {
tmp = t_0 - (t_4 / fma(tan(x), tan(eps), -1.0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-tan(x)) t_1 = fma(-1.0, tan(x), tan(x)) t_2 = Float64(sin(x) / cos(x)) t_3 = Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0)) t_4 = Float64(tan(x) + tan(eps)) t_5 = Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) tmp = 0.0 if (eps <= -4.8e-5) tmp = Float64(fma(t_4, Float64(1.0 / Float64(1.0 - log((exp(tan(eps)) ^ tan(x))))), t_0) + t_1); elseif (eps <= 5.2e-11) tmp = Float64(t_1 + Float64(Float64(eps * Float64(1.0 + t_5)) + Float64(Float64((eps ^ 2.0) * Float64(t_2 + t_3)) + Float64((eps ^ 3.0) * Float64(0.3333333333333333 + Float64(t_5 + Float64(Float64(sin(x) * Float64(t_3 - Float64(t_2 * -0.3333333333333333))) / cos(x)))))))); else tmp = Float64(t_0 - Float64(t_4 / fma(tan(x), tan(eps), -1.0))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = (-N[Tan[x], $MachinePrecision])}, Block[{t$95$1 = N[(-1.0 * N[Tan[x], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.8e-5], N[(N[(t$95$4 * N[(1.0 / N[(1.0 - N[Log[N[Power[N[Exp[N[Tan[eps], $MachinePrecision]], $MachinePrecision], N[Tan[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[eps, 5.2e-11], N[(t$95$1 + N[(N[(eps * N[(1.0 + t$95$5), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[eps, 2.0], $MachinePrecision] * N[(t$95$2 + t$95$3), $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 3.0], $MachinePrecision] * N[(0.3333333333333333 + N[(t$95$5 + N[(N[(N[Sin[x], $MachinePrecision] * N[(t$95$3 - N[(t$95$2 * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(t$95$4 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\tan x\\
t_1 := \mathsf{fma}\left(-1, \tan x, \tan x\right)\\
t_2 := \frac{\sin x}{\cos x}\\
t_3 := \frac{{\sin x}^{3}}{{\cos x}^{3}}\\
t_4 := \tan x + \tan \varepsilon\\
t_5 := \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{if}\;\varepsilon \leq -4.8 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(t_4, \frac{1}{1 - \log \left({\left(e^{\tan \varepsilon}\right)}^{\tan x}\right)}, t_0\right) + t_1\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;t_1 + \left(\varepsilon \cdot \left(1 + t_5\right) + \left({\varepsilon}^{2} \cdot \left(t_2 + t_3\right) + {\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_5 + \frac{\sin x \cdot \left(t_3 - t_2 \cdot -0.3333333333333333\right)}{\cos x}\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \frac{t_4}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -4.8000000000000001e-5Initial program 51.4%
tan-sum99.3%
div-inv99.3%
*-un-lft-identity99.3%
*-commutative99.3%
prod-diff99.3%
*-un-lft-identity99.3%
metadata-eval99.3%
*-un-lft-identity99.3%
Applied egg-rr99.3%
add-log-exp99.4%
*-commutative99.4%
exp-prod99.5%
Applied egg-rr99.5%
if -4.8000000000000001e-5 < eps < 5.2000000000000001e-11Initial program 28.9%
tan-sum29.5%
div-inv29.5%
*-un-lft-identity29.5%
*-commutative29.5%
prod-diff29.5%
*-un-lft-identity29.5%
metadata-eval29.5%
*-un-lft-identity29.5%
Applied egg-rr29.5%
Taylor expanded in eps around 0 99.8%
if 5.2000000000000001e-11 < eps Initial program 52.2%
log1p-expm1-u50.6%
Applied egg-rr50.6%
log1p-expm1-u52.2%
tan-sum99.4%
frac-2neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt53.7%
sqrt-unprod78.2%
sqr-neg78.2%
sqrt-unprod24.4%
add-sqr-sqrt54.8%
distribute-lft-neg-in54.8%
add-sqr-sqrt30.4%
sqrt-unprod76.0%
sqr-neg76.0%
sqrt-unprod45.5%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
neg-sub099.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (tan x))) (t_1 (+ (tan x) (tan eps))))
(if (<= eps -5.1e-9)
(+
(fma t_1 (/ 1.0 (- 1.0 (log (pow (exp (tan eps)) (tan x))))) t_0)
(fma -1.0 (tan x) (tan x)))
(if (<= eps 5.2e-11)
(* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(- t_0 (/ t_1 (fma (tan x) (tan eps) -1.0)))))))
double code(double x, double eps) {
double t_0 = -tan(x);
double t_1 = tan(x) + tan(eps);
double tmp;
if (eps <= -5.1e-9) {
tmp = fma(t_1, (1.0 / (1.0 - log(pow(exp(tan(eps)), tan(x))))), t_0) + fma(-1.0, tan(x), tan(x));
} else if (eps <= 5.2e-11) {
tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = t_0 - (t_1 / fma(tan(x), tan(eps), -1.0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-tan(x)) t_1 = Float64(tan(x) + tan(eps)) tmp = 0.0 if (eps <= -5.1e-9) tmp = Float64(fma(t_1, Float64(1.0 / Float64(1.0 - log((exp(tan(eps)) ^ tan(x))))), t_0) + fma(-1.0, tan(x), tan(x))); elseif (eps <= 5.2e-11) tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = Float64(t_0 - Float64(t_1 / fma(tan(x), tan(eps), -1.0))); end return tmp end
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, -5.1e-9], N[(N[(t$95$1 * N[(1.0 / N[(1.0 - N[Log[N[Power[N[Exp[N[Tan[eps], $MachinePrecision]], $MachinePrecision], N[Tan[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] + N[(-1.0 * N[Tan[x], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.2e-11], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(t$95$1 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\tan x\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -5.1 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_1, \frac{1}{1 - \log \left({\left(e^{\tan \varepsilon}\right)}^{\tan x}\right)}, t_0\right) + \mathsf{fma}\left(-1, \tan x, \tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 - \frac{t_1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -5.10000000000000017e-9Initial program 51.5%
tan-sum98.9%
div-inv98.9%
*-un-lft-identity98.9%
*-commutative98.9%
prod-diff98.9%
*-un-lft-identity98.9%
metadata-eval98.9%
*-un-lft-identity98.9%
Applied egg-rr98.9%
add-log-exp99.0%
*-commutative99.0%
exp-prod99.1%
Applied egg-rr99.1%
if -5.10000000000000017e-9 < eps < 5.2000000000000001e-11Initial program 28.5%
Taylor expanded in eps around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
Simplified99.8%
if 5.2000000000000001e-11 < eps Initial program 52.2%
log1p-expm1-u50.6%
Applied egg-rr50.6%
log1p-expm1-u52.2%
tan-sum99.4%
frac-2neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt53.7%
sqrt-unprod78.2%
sqr-neg78.2%
sqrt-unprod24.4%
add-sqr-sqrt54.8%
distribute-lft-neg-in54.8%
add-sqr-sqrt30.4%
sqrt-unprod76.0%
sqr-neg76.0%
sqrt-unprod45.5%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
neg-sub099.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.5e-9) (not (<= eps 5.2e-11))) (- (- (tan x)) (/ (+ (tan x) (tan eps)) (fma (tan x) (tan eps) -1.0))) (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.5e-9) || !(eps <= 5.2e-11)) {
tmp = -tan(x) - ((tan(x) + tan(eps)) / fma(tan(x), tan(eps), -1.0));
} else {
tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -4.5e-9) || !(eps <= 5.2e-11)) tmp = Float64(Float64(-tan(x)) - Float64(Float64(tan(x) + tan(eps)) / fma(tan(x), tan(eps), -1.0))); else tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -4.5e-9], N[Not[LessEqual[eps, 5.2e-11]], $MachinePrecision]], N[((-N[Tan[x], $MachinePrecision]) - N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(eps * N[(1.0 + 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.5 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.2 \cdot 10^{-11}\right):\\
\;\;\;\;\left(-\tan x\right) - \frac{\tan x + \tan \varepsilon}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -4.49999999999999976e-9 or 5.2000000000000001e-11 < eps Initial program 51.9%
log1p-expm1-u50.3%
Applied egg-rr50.3%
log1p-expm1-u51.9%
tan-sum99.1%
frac-2neg99.1%
sub-neg99.1%
distribute-neg-in99.1%
metadata-eval99.1%
distribute-lft-neg-in99.1%
add-sqr-sqrt54.0%
sqrt-unprod79.4%
sqr-neg79.4%
sqrt-unprod25.4%
add-sqr-sqrt54.8%
distribute-lft-neg-in54.8%
add-sqr-sqrt29.4%
sqrt-unprod74.5%
sqr-neg74.5%
sqrt-unprod45.0%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
neg-sub099.1%
+-commutative99.1%
associate--r+99.1%
neg-sub099.1%
+-commutative99.1%
fma-def99.3%
Simplified99.3%
if -4.49999999999999976e-9 < eps < 5.2000000000000001e-11Initial program 28.5%
Taylor expanded in eps around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -6.2e-9)
(- (* t_0 (/ -1.0 (fma (tan eps) (tan x) -1.0))) (tan x))
(if (<= eps 5.2e-11)
(* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(- (- (tan x)) (/ t_0 (fma (tan x) (tan eps) -1.0)))))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double tmp;
if (eps <= -6.2e-9) {
tmp = (t_0 * (-1.0 / fma(tan(eps), tan(x), -1.0))) - tan(x);
} else if (eps <= 5.2e-11) {
tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = -tan(x) - (t_0 / fma(tan(x), tan(eps), -1.0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) tmp = 0.0 if (eps <= -6.2e-9) tmp = Float64(Float64(t_0 * Float64(-1.0 / fma(tan(eps), tan(x), -1.0))) - tan(x)); elseif (eps <= 5.2e-11) tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = Float64(Float64(-tan(x)) - Float64(t_0 / fma(tan(x), tan(eps), -1.0))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -6.2e-9], N[(N[(t$95$0 * N[(-1.0 / N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.2e-11], N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[Tan[x], $MachinePrecision]) - N[(t$95$0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -6.2 \cdot 10^{-9}:\\
\;\;\;\;t_0 \cdot \frac{-1}{\mathsf{fma}\left(\tan \varepsilon, \tan x, -1\right)} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-\tan x\right) - \frac{t_0}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -6.2000000000000001e-9Initial program 51.5%
log1p-expm1-u50.0%
Applied egg-rr50.0%
log1p-expm1-u51.5%
tan-sum98.9%
div-inv98.9%
flip-+98.7%
frac-2neg98.7%
metadata-eval98.7%
frac-times98.7%
pow298.7%
pow298.7%
sub-neg98.7%
distribute-neg-in98.7%
metadata-eval98.7%
distribute-lft-neg-in98.7%
Applied egg-rr98.7%
*-commutative98.7%
*-commutative98.7%
times-frac98.7%
+-commutative98.7%
*-commutative98.7%
fma-def98.8%
unpow298.8%
unpow298.8%
flip-+99.0%
+-commutative99.0%
Applied egg-rr99.0%
if -6.2000000000000001e-9 < eps < 5.2000000000000001e-11Initial program 28.5%
Taylor expanded in eps around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
Simplified99.8%
if 5.2000000000000001e-11 < eps Initial program 52.2%
log1p-expm1-u50.6%
Applied egg-rr50.6%
log1p-expm1-u52.2%
tan-sum99.4%
frac-2neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt53.7%
sqrt-unprod78.2%
sqr-neg78.2%
sqrt-unprod24.4%
add-sqr-sqrt54.8%
distribute-lft-neg-in54.8%
add-sqr-sqrt30.4%
sqrt-unprod76.0%
sqr-neg76.0%
sqrt-unprod45.5%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
neg-sub099.4%
+-commutative99.4%
associate--r+99.4%
neg-sub099.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
(if (<= eps -2.6e-9)
(- (/ t_0 t_1) (tan x))
(if (<= eps 5.2e-11)
(* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(- (* t_0 (/ 1.0 t_1)) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double t_1 = 1.0 - (tan(x) * tan(eps));
double tmp;
if (eps <= -2.6e-9) {
tmp = (t_0 / t_1) - tan(x);
} else if (eps <= 5.2e-11) {
tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = (t_0 * (1.0 / t_1)) - tan(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = tan(x) + tan(eps)
t_1 = 1.0d0 - (tan(x) * tan(eps))
if (eps <= (-2.6d-9)) then
tmp = (t_0 / t_1) - tan(x)
else if (eps <= 5.2d-11) then
tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
else
tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(x) + Math.tan(eps);
double t_1 = 1.0 - (Math.tan(x) * Math.tan(eps));
double tmp;
if (eps <= -2.6e-9) {
tmp = (t_0 / t_1) - Math.tan(x);
} else if (eps <= 5.2e-11) {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
} else {
tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
}
return tmp;
}
def code(x, eps): t_0 = math.tan(x) + math.tan(eps) t_1 = 1.0 - (math.tan(x) * math.tan(eps)) tmp = 0 if eps <= -2.6e-9: tmp = (t_0 / t_1) - math.tan(x) elif eps <= 5.2e-11: tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) else: tmp = (t_0 * (1.0 / t_1)) - math.tan(x) return tmp
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) t_1 = Float64(1.0 - Float64(tan(x) * tan(eps))) tmp = 0.0 if (eps <= -2.6e-9) tmp = Float64(Float64(t_0 / t_1) - tan(x)); elseif (eps <= 5.2e-11) tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(x) + tan(eps); t_1 = 1.0 - (tan(x) * tan(eps)); tmp = 0.0; if (eps <= -2.6e-9) tmp = (t_0 / t_1) - tan(x); elseif (eps <= 5.2e-11) tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); else tmp = (t_0 * (1.0 / t_1)) - tan(x); end tmp_2 = 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[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2.6e-9], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.2e-11], N[(eps * N[(1.0 + 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 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\
\end{array}
\end{array}
if eps < -2.6000000000000001e-9Initial program 51.5%
tan-sum98.9%
div-inv98.9%
*-un-lft-identity98.9%
prod-diff98.9%
*-commutative98.9%
*-un-lft-identity98.9%
*-commutative98.9%
*-un-lft-identity98.9%
Applied egg-rr98.9%
+-commutative98.9%
fma-udef98.9%
associate-+r+98.9%
unsub-neg98.9%
Simplified98.9%
if -2.6000000000000001e-9 < eps < 5.2000000000000001e-11Initial program 28.5%
Taylor expanded in eps around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
Simplified99.8%
if 5.2000000000000001e-11 < eps Initial program 52.2%
tan-sum99.4%
div-inv99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.3e-9) (not (<= eps 5.2e-11))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.3e-9) || !(eps <= 5.2e-11)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = eps * (1.0 + (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 <= (-4.3d-9)) .or. (.not. (eps <= 5.2d-11))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = eps * (1.0d0 + ((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 <= -4.3e-9) || !(eps <= 5.2e-11)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -4.3e-9) or not (eps <= 5.2e-11): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = eps * (1.0 + (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 <= -4.3e-9) || !(eps <= 5.2e-11)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -4.3e-9) || ~((eps <= 5.2e-11))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.3e-9], N[Not[LessEqual[eps, 5.2e-11]], $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[(1.0 + 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.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.2 \cdot 10^{-11}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -4.29999999999999963e-9 or 5.2000000000000001e-11 < eps Initial program 51.9%
tan-sum99.1%
div-inv99.1%
*-un-lft-identity99.1%
prod-diff99.2%
*-commutative99.2%
*-un-lft-identity99.2%
*-commutative99.2%
*-un-lft-identity99.2%
Applied egg-rr99.2%
+-commutative99.2%
fma-udef99.1%
associate-+r+99.1%
unsub-neg99.1%
Simplified99.1%
if -4.29999999999999963e-9 < eps < 5.2000000000000001e-11Initial program 28.5%
Taylor expanded in eps around 0 99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.6e-5) (not (<= eps 5.2e-11))) (tan eps) (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.6e-5) || !(eps <= 5.2e-11)) {
tmp = tan(eps);
} else {
tmp = eps * (1.0 + (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 <= (-1.6d-5)) .or. (.not. (eps <= 5.2d-11))) then
tmp = tan(eps)
else
tmp = eps * (1.0d0 + ((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 <= -1.6e-5) || !(eps <= 5.2e-11)) {
tmp = Math.tan(eps);
} else {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.6e-5) or not (eps <= 5.2e-11): tmp = math.tan(eps) else: tmp = eps * (1.0 + (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 <= -1.6e-5) || !(eps <= 5.2e-11)) tmp = tan(eps); else tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.6e-5) || ~((eps <= 5.2e-11))) tmp = tan(eps); else tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.6e-5], N[Not[LessEqual[eps, 5.2e-11]], $MachinePrecision]], N[Tan[eps], $MachinePrecision], N[(eps * N[(1.0 + 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 -1.6 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 5.2 \cdot 10^{-11}\right):\\
\;\;\;\;\tan \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -1.59999999999999993e-5 or 5.2000000000000001e-11 < eps Initial program 51.9%
Taylor expanded in x around 0 54.4%
tan-quot54.6%
expm1-log1p-u41.5%
expm1-udef40.2%
Applied egg-rr40.2%
expm1-def41.5%
expm1-log1p54.6%
Simplified54.6%
if -1.59999999999999993e-5 < eps < 5.2000000000000001e-11Initial program 28.9%
Taylor expanded in eps around 0 99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
*-lft-identity99.3%
Simplified99.3%
Final simplification75.5%
(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 41.1%
Taylor expanded in x around 0 57.6%
tan-quot57.7%
expm1-log1p-u50.7%
expm1-udef24.5%
Applied egg-rr24.5%
expm1-def50.7%
expm1-log1p57.7%
Simplified57.7%
Final simplification57.7%
(FPCore (x eps) :precision binary64 (/ 1.0 (+ (* eps -0.3333333333333333) (/ 1.0 eps))))
double code(double x, double eps) {
return 1.0 / ((eps * -0.3333333333333333) + (1.0 / eps));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0 / ((eps * (-0.3333333333333333d0)) + (1.0d0 / eps))
end function
public static double code(double x, double eps) {
return 1.0 / ((eps * -0.3333333333333333) + (1.0 / eps));
}
def code(x, eps): return 1.0 / ((eps * -0.3333333333333333) + (1.0 / eps))
function code(x, eps) return Float64(1.0 / Float64(Float64(eps * -0.3333333333333333) + Float64(1.0 / eps))) end
function tmp = code(x, eps) tmp = 1.0 / ((eps * -0.3333333333333333) + (1.0 / eps)); end
code[x_, eps_] := N[(1.0 / N[(N[(eps * -0.3333333333333333), $MachinePrecision] + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\varepsilon \cdot -0.3333333333333333 + \frac{1}{\varepsilon}}
\end{array}
Initial program 41.1%
Taylor expanded in x around 0 57.6%
tan-quot57.7%
add-sqr-sqrt29.3%
pow229.3%
Applied egg-rr29.3%
unpow229.3%
add-sqr-sqrt57.7%
tan-quot57.6%
clear-num57.5%
clear-num57.5%
tan-quot57.6%
Applied egg-rr57.6%
Taylor expanded in eps around 0 32.1%
Final simplification32.1%
(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 41.1%
Taylor expanded in x around 0 57.6%
Taylor expanded in eps around 0 31.3%
Final simplification31.3%
(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 2024024
(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)))