
(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 (/ (sin eps) (cos eps))))
(+
(/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
(/ (sin x) (* (cos x) (+ (/ (/ 1.0 (tan eps)) (tan x)) -1.0))))))
double code(double x, double eps) {
double t_0 = sin(eps) / cos(eps);
return (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + (sin(x) / (cos(x) * (((1.0 / tan(eps)) / tan(x)) + -1.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin(eps) / cos(eps)
code = (t_0 / (1.0d0 - (t_0 * (sin(x) / cos(x))))) + (sin(x) / (cos(x) * (((1.0d0 / tan(eps)) / tan(x)) + (-1.0d0))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) / Math.cos(eps);
return (t_0 / (1.0 - (t_0 * (Math.sin(x) / Math.cos(x))))) + (Math.sin(x) / (Math.cos(x) * (((1.0 / Math.tan(eps)) / Math.tan(x)) + -1.0)));
}
def code(x, eps): t_0 = math.sin(eps) / math.cos(eps) return (t_0 / (1.0 - (t_0 * (math.sin(x) / math.cos(x))))) + (math.sin(x) / (math.cos(x) * (((1.0 / math.tan(eps)) / math.tan(x)) + -1.0)))
function code(x, eps) t_0 = Float64(sin(eps) / cos(eps)) return Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + Float64(sin(x) / Float64(cos(x) * Float64(Float64(Float64(1.0 / tan(eps)) / tan(x)) + -1.0)))) end
function tmp = code(x, eps) t_0 = sin(eps) / cos(eps); tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + (sin(x) / (cos(x) * (((1.0 / tan(eps)) / tan(x)) + -1.0))); end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $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[Sin[x], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(N[(N[(1.0 / N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\sin x}{\cos x \cdot \left(\frac{\frac{1}{\tan \varepsilon}}{\tan x} + -1\right)}
\end{array}
\end{array}
Initial program 44.2%
tan-sum68.4%
div-inv68.4%
*-un-lft-identity68.4%
prod-diff68.4%
*-commutative68.4%
*-un-lft-identity68.4%
*-commutative68.4%
*-un-lft-identity68.4%
Applied egg-rr68.4%
Simplified68.4%
Taylor expanded in x around inf 68.2%
associate--l+81.7%
associate-/r*81.7%
times-frac81.7%
Simplified81.8%
Applied egg-rr79.3%
associate-/r/79.3%
rgt-mult-inverse81.8%
associate--r-99.5%
metadata-eval99.5%
+-lft-identity99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
clear-num99.5%
tan-quot99.5%
frac-times99.5%
*-un-lft-identity99.5%
Applied egg-rr99.5%
*-commutative99.5%
div-sub89.0%
sub-neg89.0%
*-commutative89.0%
associate-/r*89.0%
*-inverses99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (sin eps) (cos eps))))
(+
(/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
(/ (tan x) (+ (/ (/ 1.0 (tan eps)) (tan x)) -1.0)))))
double code(double x, double eps) {
double t_0 = sin(eps) / cos(eps);
return (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + (tan(x) / (((1.0 / tan(eps)) / tan(x)) + -1.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin(eps) / cos(eps)
code = (t_0 / (1.0d0 - (t_0 * (sin(x) / cos(x))))) + (tan(x) / (((1.0d0 / tan(eps)) / tan(x)) + (-1.0d0)))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) / Math.cos(eps);
return (t_0 / (1.0 - (t_0 * (Math.sin(x) / Math.cos(x))))) + (Math.tan(x) / (((1.0 / Math.tan(eps)) / Math.tan(x)) + -1.0));
}
def code(x, eps): t_0 = math.sin(eps) / math.cos(eps) return (t_0 / (1.0 - (t_0 * (math.sin(x) / math.cos(x))))) + (math.tan(x) / (((1.0 / math.tan(eps)) / math.tan(x)) + -1.0))
function code(x, eps) t_0 = Float64(sin(eps) / cos(eps)) return Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + Float64(tan(x) / Float64(Float64(Float64(1.0 / tan(eps)) / tan(x)) + -1.0))) end
function tmp = code(x, eps) t_0 = sin(eps) / cos(eps); tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + (tan(x) / (((1.0 / tan(eps)) / tan(x)) + -1.0)); end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $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[Tan[x], $MachinePrecision] / N[(N[(N[(1.0 / N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\tan x}{\frac{\frac{1}{\tan \varepsilon}}{\tan x} + -1}
\end{array}
\end{array}
Initial program 44.2%
tan-sum68.4%
div-inv68.4%
*-un-lft-identity68.4%
prod-diff68.4%
*-commutative68.4%
*-un-lft-identity68.4%
*-commutative68.4%
*-un-lft-identity68.4%
Applied egg-rr68.4%
Simplified68.4%
Taylor expanded in x around inf 68.2%
associate--l+81.7%
associate-/r*81.7%
times-frac81.7%
Simplified81.8%
Applied egg-rr79.3%
associate-/r/79.3%
rgt-mult-inverse81.8%
associate--r-99.5%
metadata-eval99.5%
+-lft-identity99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
expm1-log1p-u92.9%
expm1-udef75.2%
associate-*l/75.2%
*-commutative75.2%
associate-*l*75.2%
pow275.2%
Applied egg-rr75.2%
expm1-def92.9%
expm1-log1p99.5%
*-commutative99.5%
unpow299.5%
associate-*l*99.5%
associate-*l/99.5%
associate-/r/99.6%
div-sub89.0%
sub-neg89.0%
*-commutative89.0%
associate-/r*89.0%
*-inverses99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (* (tan eps) (tan x))) (t_1 (- 1.0 t_0))) (+ (/ (/ (sin eps) (cos eps)) t_1) (* (tan x) (/ t_0 t_1)))))
double code(double x, double eps) {
double t_0 = tan(eps) * tan(x);
double t_1 = 1.0 - t_0;
return ((sin(eps) / cos(eps)) / t_1) + (tan(x) * (t_0 / t_1));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
t_0 = tan(eps) * tan(x)
t_1 = 1.0d0 - t_0
code = ((sin(eps) / cos(eps)) / t_1) + (tan(x) * (t_0 / t_1))
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(eps) * Math.tan(x);
double t_1 = 1.0 - t_0;
return ((Math.sin(eps) / Math.cos(eps)) / t_1) + (Math.tan(x) * (t_0 / t_1));
}
def code(x, eps): t_0 = math.tan(eps) * math.tan(x) t_1 = 1.0 - t_0 return ((math.sin(eps) / math.cos(eps)) / t_1) + (math.tan(x) * (t_0 / t_1))
function code(x, eps) t_0 = Float64(tan(eps) * tan(x)) t_1 = Float64(1.0 - t_0) return Float64(Float64(Float64(sin(eps) / cos(eps)) / t_1) + Float64(tan(x) * Float64(t_0 / t_1))) end
function tmp = code(x, eps) t_0 = tan(eps) * tan(x); t_1 = 1.0 - t_0; tmp = ((sin(eps) / cos(eps)) / t_1) + (tan(x) * (t_0 / t_1)); end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, N[(N[(N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[Tan[x], $MachinePrecision] * N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \varepsilon \cdot \tan x\\
t_1 := 1 - t_0\\
\frac{\frac{\sin \varepsilon}{\cos \varepsilon}}{t_1} + \tan x \cdot \frac{t_0}{t_1}
\end{array}
\end{array}
Initial program 44.2%
tan-sum68.4%
div-inv68.4%
*-un-lft-identity68.4%
prod-diff68.4%
*-commutative68.4%
*-un-lft-identity68.4%
*-commutative68.4%
*-un-lft-identity68.4%
Applied egg-rr68.4%
Simplified68.4%
Taylor expanded in x around inf 68.2%
associate--l+81.7%
associate-/r*81.7%
times-frac81.7%
Simplified81.8%
Applied egg-rr79.3%
associate-/r/79.3%
rgt-mult-inverse81.8%
associate--r-99.5%
metadata-eval99.5%
+-lft-identity99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
tan-quot99.6%
associate-*l/99.5%
*-commutative99.5%
clear-num99.5%
clear-num99.5%
*-commutative99.5%
associate-*l/99.5%
tan-quot99.5%
Applied egg-rr99.5%
remove-double-div99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.6e-9) (not (<= eps 1.15e-16))) (- (/ (- (- (tan eps)) (tan x)) (fma (tan x) (tan eps) -1.0)) (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 <= -2.6e-9) || !(eps <= 1.15e-16)) {
tmp = ((-tan(eps) - tan(x)) / fma(tan(x), tan(eps), -1.0)) - tan(x);
} 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 <= -2.6e-9) || !(eps <= 1.15e-16)) tmp = Float64(Float64(Float64(Float64(-tan(eps)) - tan(x)) / fma(tan(x), tan(eps), -1.0)) - tan(x)); 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, -2.6e-9], N[Not[LessEqual[eps, 1.15e-16]], $MachinePrecision]], N[(N[(N[((-N[Tan[eps], $MachinePrecision]) - N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $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 -2.6 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{\left(-\tan \varepsilon\right) - \tan x}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -2.6000000000000001e-9 or 1.15e-16 < eps Initial program 55.3%
tan-sum99.2%
div-inv99.2%
*-un-lft-identity99.2%
prod-diff99.2%
*-commutative99.2%
*-un-lft-identity99.2%
*-commutative99.2%
*-un-lft-identity99.2%
Applied egg-rr99.2%
Simplified99.2%
frac-2neg99.2%
distribute-frac-neg99.2%
sub-neg99.2%
distribute-neg-in99.2%
metadata-eval99.2%
distribute-lft-neg-in99.2%
add-sqr-sqrt55.1%
sqrt-unprod79.6%
sqr-neg79.6%
sqrt-prod24.5%
add-sqr-sqrt57.9%
distribute-lft-neg-in57.9%
add-sqr-sqrt33.3%
Applied egg-rr99.2%
distribute-neg-frac99.2%
+-commutative99.2%
fma-def99.3%
Simplified99.3%
if -2.6000000000000001e-9 < eps < 1.15e-16Initial program 30.7%
Taylor expanded in eps around 0 99.7%
cancel-sign-sub-inv99.7%
metadata-eval99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.3e-9) (not (<= eps 1.15e-16))) (- (/ (+ (tan eps) (tan x)) (- 1.0 (* (tan eps) (tan x)))) (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 <= -3.3e-9) || !(eps <= 1.15e-16)) {
tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - 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 <= (-3.3d-9)) .or. (.not. (eps <= 1.15d-16))) then
tmp = ((tan(eps) + tan(x)) / (1.0d0 - (tan(eps) * tan(x)))) - 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 <= -3.3e-9) || !(eps <= 1.15e-16)) {
tmp = ((Math.tan(eps) + Math.tan(x)) / (1.0 - (Math.tan(eps) * Math.tan(x)))) - 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 <= -3.3e-9) or not (eps <= 1.15e-16): tmp = ((math.tan(eps) + math.tan(x)) / (1.0 - (math.tan(eps) * math.tan(x)))) - 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 <= -3.3e-9) || !(eps <= 1.15e-16)) tmp = Float64(Float64(Float64(tan(eps) + tan(x)) / Float64(1.0 - Float64(tan(eps) * tan(x)))) - 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 <= -3.3e-9) || ~((eps <= 1.15e-16))) tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - 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, -3.3e-9], N[Not[LessEqual[eps, 1.15e-16]], $MachinePrecision]], N[(N[(N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $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 -3.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \tan \varepsilon \cdot \tan x} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -3.30000000000000018e-9 or 1.15e-16 < eps Initial program 55.3%
tan-sum99.2%
div-inv99.2%
*-un-lft-identity99.2%
prod-diff99.2%
*-commutative99.2%
*-un-lft-identity99.2%
*-commutative99.2%
*-un-lft-identity99.2%
Applied egg-rr99.2%
Simplified99.2%
if -3.30000000000000018e-9 < eps < 1.15e-16Initial program 30.7%
Taylor expanded in eps around 0 99.7%
cancel-sign-sub-inv99.7%
metadata-eval99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.32e-5) (not (<= eps 1.15e-16))) (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.32e-5) || !(eps <= 1.15e-16)) {
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.32d-5)) .or. (.not. (eps <= 1.15d-16))) 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.32e-5) || !(eps <= 1.15e-16)) {
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.32e-5) or not (eps <= 1.15e-16): 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.32e-5) || !(eps <= 1.15e-16)) 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.32e-5) || ~((eps <= 1.15e-16))) 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.32e-5], N[Not[LessEqual[eps, 1.15e-16]], $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.32 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\tan \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -1.32000000000000007e-5 or 1.15e-16 < eps Initial program 55.7%
log1p-expm1-u54.3%
Applied egg-rr54.3%
Taylor expanded in x around 0 55.2%
expm1-def56.7%
Simplified56.7%
add-sqr-sqrt23.4%
sqrt-unprod25.9%
pow225.9%
tan-quot26.0%
Applied egg-rr26.0%
unpow226.0%
rem-sqrt-square26.0%
Simplified26.0%
Taylor expanded in eps around 0 26.0%
rem-square-sqrt23.5%
fabs-sqr23.5%
rem-square-sqrt58.1%
Simplified58.1%
if -1.32000000000000007e-5 < eps < 1.15e-16Initial program 30.8%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
Final simplification76.9%
(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 44.2%
log1p-expm1-u43.5%
Applied egg-rr43.5%
Taylor expanded in x around 0 33.0%
expm1-def58.4%
Simplified58.4%
add-sqr-sqrt27.0%
sqrt-unprod22.6%
pow222.6%
tan-quot22.7%
Applied egg-rr22.7%
unpow222.7%
rem-sqrt-square29.3%
Simplified29.3%
Taylor expanded in eps around 0 29.3%
rem-square-sqrt27.1%
fabs-sqr27.1%
rem-square-sqrt59.2%
Simplified59.2%
Final simplification59.2%
(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 44.2%
log1p-expm1-u43.5%
Applied egg-rr43.5%
Taylor expanded in x around 0 33.0%
expm1-def58.4%
Simplified58.4%
log1p-expm1-u59.1%
clear-num59.0%
clear-num58.9%
tan-quot59.1%
Applied egg-rr59.1%
Taylor expanded in eps around 0 31.0%
Final simplification31.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 44.2%
log1p-expm1-u43.5%
Applied egg-rr43.5%
Taylor expanded in x around 0 33.0%
expm1-def58.4%
Simplified58.4%
log1p-expm1-u59.1%
clear-num59.0%
clear-num58.9%
tan-quot59.1%
Applied egg-rr59.1%
Taylor expanded in eps around 0 30.9%
Final simplification30.9%
(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 2024021
(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)))