
(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 9 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) (tan eps))))
(if (<= eps -4.1e-7)
(- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))
(if (<= eps 3.3e-7)
(+
(+ 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)))))
(- (- (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 <= -4.1e-7) {
tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 3.3e-7) {
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))));
} 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 <= -4.1e-7) tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); elseif (eps <= 3.3e-7) 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))))); 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, -4.1e-7], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.3e-7], 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], 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 -4.1 \cdot 10^{-7}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 3.3 \cdot 10^{-7}:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\left(-\tan x\right) - \frac{t_0}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -4.0999999999999999e-7Initial program 52.7%
tan-sum99.7%
div-inv99.7%
fma-neg99.6%
Applied egg-rr99.6%
fma-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
if -4.0999999999999999e-7 < eps < 3.3000000000000002e-7Initial program 35.2%
tan-sum36.0%
div-inv36.0%
fma-neg36.0%
Applied egg-rr36.0%
fma-neg36.0%
associate-*r/36.0%
*-rgt-identity36.0%
Simplified36.0%
Taylor expanded in eps around 0 99.5%
+-commutative99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.6%
if 3.3000000000000002e-7 < eps Initial program 58.1%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
frac-2neg99.4%
distribute-frac-neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt47.6%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod33.5%
add-sqr-sqrt59.8%
distribute-lft-neg-in59.8%
add-sqr-sqrt26.2%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod51.7%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
distribute-neg-frac99.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -12500.0)
(- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))
(if (<= eps 9e-9)
(+
(/
(sin eps)
(* (cos eps) (- 1.0 (* (/ (sin eps) (cos eps)) (/ (sin x) (cos x))))))
(/ eps (/ (pow (cos x) 2.0) (pow (sin 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 <= -12500.0) {
tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 9e-9) {
tmp = (sin(eps) / (cos(eps) * (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x)))))) + (eps / (pow(cos(x), 2.0) / pow(sin(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 <= -12500.0) tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); elseif (eps <= 9e-9) tmp = Float64(Float64(sin(eps) / Float64(cos(eps) * Float64(1.0 - Float64(Float64(sin(eps) / cos(eps)) * Float64(sin(x) / cos(x)))))) + Float64(eps / Float64((cos(x) ^ 2.0) / (sin(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, -12500.0], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 9e-9], N[(N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $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], 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 -12500:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 9 \cdot 10^{-9}:\\
\;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}\right)} + \frac{\varepsilon}{\frac{{\cos x}^{2}}{{\sin x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;\left(-\tan x\right) - \frac{t_0}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -12500Initial program 52.0%
tan-sum99.7%
div-inv99.7%
fma-neg99.6%
Applied egg-rr99.6%
fma-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
if -12500 < eps < 8.99999999999999953e-9Initial program 35.7%
tan-sum36.5%
div-inv36.5%
fma-neg36.5%
Applied egg-rr36.5%
fma-neg36.5%
associate-*r/36.5%
*-rgt-identity36.5%
Simplified36.5%
Taylor expanded in x around inf 36.5%
associate--l+58.6%
times-frac58.6%
associate-/r*58.6%
times-frac58.6%
Simplified58.6%
Taylor expanded in eps around 0 99.4%
associate-/l*99.4%
Simplified99.4%
if 8.99999999999999953e-9 < eps Initial program 58.1%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
frac-2neg99.4%
distribute-frac-neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt47.6%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod33.5%
add-sqr-sqrt59.8%
distribute-lft-neg-in59.8%
add-sqr-sqrt26.2%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod51.7%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
distribute-neg-frac99.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -12500.0)
(- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))
(if (<= eps 5.2e-9)
(+
(/
(sin eps)
(* (cos eps) (- 1.0 (* (/ (sin eps) (cos eps)) (/ (sin x) (cos x))))))
(/ (* eps (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 <= -12500.0) {
tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 5.2e-9) {
tmp = (sin(eps) / (cos(eps) * (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x)))))) + ((eps * 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 <= -12500.0) tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); elseif (eps <= 5.2e-9) tmp = Float64(Float64(sin(eps) / Float64(cos(eps) * Float64(1.0 - Float64(Float64(sin(eps) / cos(eps)) * Float64(sin(x) / cos(x)))))) + Float64(Float64(eps * (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, -12500.0], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.2e-9], N[(N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $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], 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 -12500:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-9}:\\
\;\;\;\;\frac{\sin \varepsilon}{\cos \varepsilon \cdot \left(1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}\right)} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\left(-\tan x\right) - \frac{t_0}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}\\
\end{array}
\end{array}
if eps < -12500Initial program 52.0%
tan-sum99.7%
div-inv99.7%
fma-neg99.6%
Applied egg-rr99.6%
fma-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
if -12500 < eps < 5.2000000000000002e-9Initial program 35.7%
tan-sum36.5%
div-inv36.5%
fma-neg36.5%
Applied egg-rr36.5%
fma-neg36.5%
associate-*r/36.5%
*-rgt-identity36.5%
Simplified36.5%
Taylor expanded in x around inf 36.5%
associate--l+58.6%
times-frac58.6%
associate-/r*58.6%
times-frac58.6%
Simplified58.6%
Taylor expanded in eps around 0 99.4%
if 5.2000000000000002e-9 < eps Initial program 58.1%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
frac-2neg99.4%
distribute-frac-neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt47.6%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod33.5%
add-sqr-sqrt59.8%
distribute-lft-neg-in59.8%
add-sqr-sqrt26.2%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod51.7%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
distribute-neg-frac99.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))))
(if (<= eps -7e-9)
(- (/ t_0 (- 1.0 (* (tan x) (tan eps)))) (tan x))
(if (<= eps 4.2e-9)
(+ eps (* eps (/ (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 <= -7e-9) {
tmp = (t_0 / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else if (eps <= 4.2e-9) {
tmp = eps + (eps * (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 <= -7e-9) tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); elseif (eps <= 4.2e-9) tmp = Float64(eps + Float64(eps * 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, -7e-9], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.2e-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[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 -7 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 4.2 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\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.9999999999999998e-9Initial program 52.7%
tan-sum99.7%
div-inv99.7%
fma-neg99.6%
Applied egg-rr99.6%
fma-neg99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
if -6.9999999999999998e-9 < eps < 4.20000000000000039e-9Initial program 35.2%
Taylor expanded in eps around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
distribute-lft-in99.3%
*-rgt-identity99.3%
Simplified99.3%
if 4.20000000000000039e-9 < eps Initial program 58.1%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
frac-2neg99.4%
distribute-frac-neg99.4%
sub-neg99.4%
distribute-neg-in99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
add-sqr-sqrt47.6%
sqrt-unprod81.2%
sqr-neg81.2%
sqrt-unprod33.5%
add-sqr-sqrt59.8%
distribute-lft-neg-in59.8%
add-sqr-sqrt26.2%
sqrt-unprod78.0%
sqr-neg78.0%
sqrt-unprod51.7%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
distribute-neg-frac99.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.7e-9) (not (<= eps 3e-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.7e-9) || !(eps <= 3e-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.7d-9)) .or. (.not. (eps <= 3d-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.7e-9) || !(eps <= 3e-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.7e-9) or not (eps <= 3e-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.7e-9) || !(eps <= 3e-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.7e-9) || ~((eps <= 3e-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.7e-9], N[Not[LessEqual[eps, 3e-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.7 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3 \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.7e-9 or 2.99999999999999998e-9 < eps Initial program 55.6%
tan-sum99.6%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
fma-neg99.5%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
if -3.7e-9 < eps < 2.99999999999999998e-9Initial program 35.2%
Taylor expanded in eps around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
distribute-lft-in99.3%
*-rgt-identity99.3%
Simplified99.3%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -1.9e-6)
(tan eps)
(if (<= eps 3e-6)
(* eps (+ (/ (pow (sin x) 2.0) (pow (cos x) 2.0)) 1.0))
(tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.9e-6) {
tmp = tan(eps);
} else if (eps <= 3e-6) {
tmp = eps * ((pow(sin(x), 2.0) / pow(cos(x), 2.0)) + 1.0);
} else {
tmp = tan(eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-1.9d-6)) then
tmp = tan(eps)
else if (eps <= 3d-6) then
tmp = eps * (((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)) + 1.0d0)
else
tmp = tan(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -1.9e-6) {
tmp = Math.tan(eps);
} else if (eps <= 3e-6) {
tmp = eps * ((Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)) + 1.0);
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.9e-6: tmp = math.tan(eps) elif eps <= 3e-6: tmp = eps * ((math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)) + 1.0) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.9e-6) tmp = tan(eps); elseif (eps <= 3e-6) tmp = Float64(eps * Float64(Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0)); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.9e-6) tmp = tan(eps); elseif (eps <= 3e-6) tmp = eps * (((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.9e-6], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 3e-6], 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], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.9 \cdot 10^{-6}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 3 \cdot 10^{-6}:\\
\;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -1.9e-6 or 3.0000000000000001e-6 < eps Initial program 55.6%
Taylor expanded in x around 0 58.0%
tan-quot58.2%
expm1-log1p-u42.0%
expm1-udef41.6%
Applied egg-rr41.6%
expm1-def42.0%
expm1-log1p58.2%
Simplified58.2%
if -1.9e-6 < eps < 3.0000000000000001e-6Initial program 35.2%
tan-sum36.0%
div-inv36.0%
fma-neg36.0%
Applied egg-rr36.0%
Taylor expanded in eps around 0 99.2%
Final simplification77.3%
(FPCore (x eps)
:precision binary64
(if (<= eps -5.9e-6)
(tan eps)
(if (<= eps 1e-5)
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -5.9e-6) {
tmp = tan(eps);
} else if (eps <= 1e-5) {
tmp = eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = tan(eps);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-5.9d-6)) then
tmp = tan(eps)
else if (eps <= 1d-5) then
tmp = eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
else
tmp = tan(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -5.9e-6) {
tmp = Math.tan(eps);
} else if (eps <= 1e-5) {
tmp = eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -5.9e-6: tmp = math.tan(eps) elif eps <= 1e-5: tmp = eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -5.9e-6) tmp = tan(eps); elseif (eps <= 1e-5) tmp = Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -5.9e-6) tmp = tan(eps); elseif (eps <= 1e-5) tmp = eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -5.9e-6], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 1e-5], 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[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.9 \cdot 10^{-6}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 10^{-5}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -5.90000000000000026e-6 or 1.00000000000000008e-5 < eps Initial program 55.6%
Taylor expanded in x around 0 58.0%
tan-quot58.2%
expm1-log1p-u42.0%
expm1-udef41.6%
Applied egg-rr41.6%
expm1-def42.0%
expm1-log1p58.2%
Simplified58.2%
if -5.90000000000000026e-6 < eps < 1.00000000000000008e-5Initial program 35.2%
Taylor expanded in eps around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
distribute-lft-in99.3%
*-rgt-identity99.3%
Simplified99.3%
Final simplification77.3%
(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 46.1%
Taylor expanded in x around 0 58.0%
tan-quot58.0%
expm1-log1p-u49.4%
expm1-udef25.4%
Applied egg-rr25.4%
expm1-def49.4%
expm1-log1p58.0%
Simplified58.0%
Final simplification58.0%
(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 46.1%
Taylor expanded in x around 0 58.0%
Taylor expanded in eps around 0 28.7%
Final simplification28.7%
(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 2023280
(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)))