
(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 eps) (- 1.0 (* (/ (sin eps) (cos eps)) (/ (sin x) (cos x))))))
(t_1 (* (tan eps) (tan x)))
(t_2 (- 1.0 t_1)))
(if (<= eps -2.9e-9)
(+ t_0 (- (/ (tan x) t_2) (tan x)))
(if (<= eps 4.2e-9)
(+ eps (* eps (pow (tan x) 2.0)))
(+
t_0
(/
(+ (/ (sin x) (tan x)) (* (cos x) (+ t_1 -1.0)))
(/ (* (cos x) t_2) (tan x))))))))
double code(double x, double eps) {
double t_0 = tan(eps) / (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x))));
double t_1 = tan(eps) * tan(x);
double t_2 = 1.0 - t_1;
double tmp;
if (eps <= -2.9e-9) {
tmp = t_0 + ((tan(x) / t_2) - tan(x));
} else if (eps <= 4.2e-9) {
tmp = eps + (eps * pow(tan(x), 2.0));
} else {
tmp = t_0 + (((sin(x) / tan(x)) + (cos(x) * (t_1 + -1.0))) / ((cos(x) * t_2) / 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) :: t_2
real(8) :: tmp
t_0 = tan(eps) / (1.0d0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x))))
t_1 = tan(eps) * tan(x)
t_2 = 1.0d0 - t_1
if (eps <= (-2.9d-9)) then
tmp = t_0 + ((tan(x) / t_2) - tan(x))
else if (eps <= 4.2d-9) then
tmp = eps + (eps * (tan(x) ** 2.0d0))
else
tmp = t_0 + (((sin(x) / tan(x)) + (cos(x) * (t_1 + (-1.0d0)))) / ((cos(x) * t_2) / tan(x)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(eps) / (1.0 - ((Math.sin(eps) / Math.cos(eps)) * (Math.sin(x) / Math.cos(x))));
double t_1 = Math.tan(eps) * Math.tan(x);
double t_2 = 1.0 - t_1;
double tmp;
if (eps <= -2.9e-9) {
tmp = t_0 + ((Math.tan(x) / t_2) - Math.tan(x));
} else if (eps <= 4.2e-9) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = t_0 + (((Math.sin(x) / Math.tan(x)) + (Math.cos(x) * (t_1 + -1.0))) / ((Math.cos(x) * t_2) / Math.tan(x)));
}
return tmp;
}
def code(x, eps): t_0 = math.tan(eps) / (1.0 - ((math.sin(eps) / math.cos(eps)) * (math.sin(x) / math.cos(x)))) t_1 = math.tan(eps) * math.tan(x) t_2 = 1.0 - t_1 tmp = 0 if eps <= -2.9e-9: tmp = t_0 + ((math.tan(x) / t_2) - math.tan(x)) elif eps <= 4.2e-9: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = t_0 + (((math.sin(x) / math.tan(x)) + (math.cos(x) * (t_1 + -1.0))) / ((math.cos(x) * t_2) / math.tan(x))) return tmp
function code(x, eps) t_0 = Float64(tan(eps) / Float64(1.0 - Float64(Float64(sin(eps) / cos(eps)) * Float64(sin(x) / cos(x))))) t_1 = Float64(tan(eps) * tan(x)) t_2 = Float64(1.0 - t_1) tmp = 0.0 if (eps <= -2.9e-9) tmp = Float64(t_0 + Float64(Float64(tan(x) / t_2) - tan(x))); elseif (eps <= 4.2e-9) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = Float64(t_0 + Float64(Float64(Float64(sin(x) / tan(x)) + Float64(cos(x) * Float64(t_1 + -1.0))) / Float64(Float64(cos(x) * t_2) / tan(x)))); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(eps) / (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x)))); t_1 = tan(eps) * tan(x); t_2 = 1.0 - t_1; tmp = 0.0; if (eps <= -2.9e-9) tmp = t_0 + ((tan(x) / t_2) - tan(x)); elseif (eps <= 4.2e-9) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = t_0 + (((sin(x) / tan(x)) + (cos(x) * (t_1 + -1.0))) / ((cos(x) * t_2) / tan(x))); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[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]}, Block[{t$95$1 = N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 - t$95$1), $MachinePrecision]}, If[LessEqual[eps, -2.9e-9], N[(t$95$0 + N[(N[(N[Tan[x], $MachinePrecision] / t$95$2), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.2e-9], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(N[(N[(N[Sin[x], $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[x], $MachinePrecision] * N[(t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[x], $MachinePrecision] * t$95$2), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\tan \varepsilon}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}}\\
t_1 := \tan \varepsilon \cdot \tan x\\
t_2 := 1 - t_1\\
\mathbf{if}\;\varepsilon \leq -2.9 \cdot 10^{-9}:\\
\;\;\;\;t_0 + \left(\frac{\tan x}{t_2} - \tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 4.2 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \frac{\frac{\sin x}{\tan x} + \cos x \cdot \left(t_1 + -1\right)}{\frac{\cos x \cdot t_2}{\tan x}}\\
\end{array}
\end{array}
if eps < -2.89999999999999991e-9Initial program 59.4%
tan-sum99.4%
div-inv99.3%
fma-neg99.3%
Applied egg-rr99.3%
fma-neg99.3%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
Taylor expanded in x around inf 98.9%
associate--l+99.0%
Simplified99.0%
tan-quot99.3%
expm1-log1p-u74.4%
expm1-udef73.6%
Applied egg-rr73.6%
expm1-def74.4%
expm1-log1p99.3%
Simplified99.3%
tan-quot99.3%
sub-neg99.3%
tan-quot99.3%
tan-quot99.4%
tan-quot99.4%
Applied egg-rr99.4%
sub-neg99.4%
*-commutative99.4%
Simplified99.4%
if -2.89999999999999991e-9 < eps < 4.20000000000000039e-9Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 4.20000000000000039e-9 < eps Initial program 58.5%
tan-sum99.5%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in x around inf 99.3%
associate--l+99.3%
Simplified99.3%
tan-quot99.5%
expm1-log1p-u78.7%
expm1-udef78.2%
Applied egg-rr78.2%
expm1-def78.7%
expm1-log1p99.5%
Simplified99.5%
associate-/l/99.4%
clear-num99.4%
frac-sub99.5%
Applied egg-rr99.6%
associate-*r/99.6%
*-rgt-identity99.6%
*-rgt-identity99.6%
*-commutative99.6%
*-commutative99.6%
associate-*r/99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- 1.0 (* (tan eps) (tan x)))))
(if (<= eps -4e-9)
(+
(/ (tan eps) (- 1.0 (* (/ (sin eps) (cos eps)) (/ (sin x) (cos x)))))
(- (/ (tan x) t_0) (tan x)))
(if (<= eps 2.1e-9)
(+ eps (* eps (pow (tan x) 2.0)))
(- (/ (+ (tan eps) (tan x)) t_0) (tan x))))))
double code(double x, double eps) {
double t_0 = 1.0 - (tan(eps) * tan(x));
double tmp;
if (eps <= -4e-9) {
tmp = (tan(eps) / (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x))))) + ((tan(x) / t_0) - tan(x));
} else if (eps <= 2.1e-9) {
tmp = eps + (eps * pow(tan(x), 2.0));
} else {
tmp = ((tan(eps) + tan(x)) / t_0) - 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) :: tmp
t_0 = 1.0d0 - (tan(eps) * tan(x))
if (eps <= (-4d-9)) then
tmp = (tan(eps) / (1.0d0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x))))) + ((tan(x) / t_0) - tan(x))
else if (eps <= 2.1d-9) then
tmp = eps + (eps * (tan(x) ** 2.0d0))
else
tmp = ((tan(eps) + tan(x)) / t_0) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = 1.0 - (Math.tan(eps) * Math.tan(x));
double tmp;
if (eps <= -4e-9) {
tmp = (Math.tan(eps) / (1.0 - ((Math.sin(eps) / Math.cos(eps)) * (Math.sin(x) / Math.cos(x))))) + ((Math.tan(x) / t_0) - Math.tan(x));
} else if (eps <= 2.1e-9) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = ((Math.tan(eps) + Math.tan(x)) / t_0) - Math.tan(x);
}
return tmp;
}
def code(x, eps): t_0 = 1.0 - (math.tan(eps) * math.tan(x)) tmp = 0 if eps <= -4e-9: tmp = (math.tan(eps) / (1.0 - ((math.sin(eps) / math.cos(eps)) * (math.sin(x) / math.cos(x))))) + ((math.tan(x) / t_0) - math.tan(x)) elif eps <= 2.1e-9: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = ((math.tan(eps) + math.tan(x)) / t_0) - math.tan(x) return tmp
function code(x, eps) t_0 = Float64(1.0 - Float64(tan(eps) * tan(x))) tmp = 0.0 if (eps <= -4e-9) tmp = Float64(Float64(tan(eps) / Float64(1.0 - Float64(Float64(sin(eps) / cos(eps)) * Float64(sin(x) / cos(x))))) + Float64(Float64(tan(x) / t_0) - tan(x))); elseif (eps <= 2.1e-9) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = Float64(Float64(Float64(tan(eps) + tan(x)) / t_0) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = 1.0 - (tan(eps) * tan(x)); tmp = 0.0; if (eps <= -4e-9) tmp = (tan(eps) / (1.0 - ((sin(eps) / cos(eps)) * (sin(x) / cos(x))))) + ((tan(x) / t_0) - tan(x)); elseif (eps <= 2.1e-9) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = ((tan(eps) + tan(x)) / t_0) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 - N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4e-9], N[(N[(N[Tan[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] + N[(N[(N[Tan[x], $MachinePrecision] / t$95$0), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.1e-9], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \tan \varepsilon \cdot \tan x\\
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-9}:\\
\;\;\;\;\frac{\tan \varepsilon}{1 - \frac{\sin \varepsilon}{\cos \varepsilon} \cdot \frac{\sin x}{\cos x}} + \left(\frac{\tan x}{t_0} - \tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{t_0} - \tan x\\
\end{array}
\end{array}
if eps < -4.00000000000000025e-9Initial program 59.4%
tan-sum99.4%
div-inv99.3%
fma-neg99.3%
Applied egg-rr99.3%
fma-neg99.3%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
Taylor expanded in x around inf 98.9%
associate--l+99.0%
Simplified99.0%
tan-quot99.3%
expm1-log1p-u74.4%
expm1-udef73.6%
Applied egg-rr73.6%
expm1-def74.4%
expm1-log1p99.3%
Simplified99.3%
tan-quot99.3%
sub-neg99.3%
tan-quot99.3%
tan-quot99.4%
tan-quot99.4%
Applied egg-rr99.4%
sub-neg99.4%
*-commutative99.4%
Simplified99.4%
if -4.00000000000000025e-9 < eps < 2.10000000000000019e-9Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 2.10000000000000019e-9 < eps Initial program 58.5%
tan-sum99.5%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan eps) (tan x))))
(if (<= eps -2.6e-9)
(- (/ t_0 (+ 1.0 (- -1.0 (fma (tan x) (tan eps) -1.0)))) (tan x))
(if (<= eps 3.1e-9)
(+ eps (* eps (pow (tan x) 2.0)))
(- (/ t_0 (- 1.0 (* (tan eps) (tan x)))) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(eps) + tan(x);
double tmp;
if (eps <= -2.6e-9) {
tmp = (t_0 / (1.0 + (-1.0 - fma(tan(x), tan(eps), -1.0)))) - tan(x);
} else if (eps <= 3.1e-9) {
tmp = eps + (eps * pow(tan(x), 2.0));
} else {
tmp = (t_0 / (1.0 - (tan(eps) * tan(x)))) - tan(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(tan(eps) + tan(x)) tmp = 0.0 if (eps <= -2.6e-9) tmp = Float64(Float64(t_0 / Float64(1.0 + Float64(-1.0 - fma(tan(x), tan(eps), -1.0)))) - tan(x)); elseif (eps <= 3.1e-9) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(eps) * tan(x)))) - tan(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -2.6e-9], N[(N[(t$95$0 / N[(1.0 + N[(-1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.1e-9], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \varepsilon + \tan x\\
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{1 + \left(-1 - \mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)\right)} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 3.1 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan \varepsilon \cdot \tan x} - \tan x\\
\end{array}
\end{array}
if eps < -2.6000000000000001e-9Initial program 59.4%
tan-sum99.4%
div-inv99.3%
fma-neg99.3%
Applied egg-rr99.3%
fma-neg99.3%
associate-*r/99.4%
*-rgt-identity99.4%
Simplified99.4%
expm1-log1p-u91.5%
expm1-udef91.5%
log1p-udef91.5%
add-exp-log99.3%
Applied egg-rr99.3%
associate--l+99.4%
fma-neg99.4%
metadata-eval99.4%
Simplified99.4%
if -2.6000000000000001e-9 < eps < 3.10000000000000005e-9Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 3.10000000000000005e-9 < eps Initial program 58.5%
tan-sum99.5%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.3e-9) (not (<= eps 3.5e-9))) (- (/ (+ (tan eps) (tan x)) (- 1.0 (* (tan eps) (tan x)))) (tan x)) (+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.3e-9) || !(eps <= 3.5e-9)) {
tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - tan(x);
} else {
tmp = eps + (eps * pow(tan(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 <= 3.5d-9))) then
tmp = ((tan(eps) + tan(x)) / (1.0d0 - (tan(eps) * tan(x)))) - tan(x)
else
tmp = eps + (eps * (tan(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 <= 3.5e-9)) {
tmp = ((Math.tan(eps) + Math.tan(x)) / (1.0 - (Math.tan(eps) * Math.tan(x)))) - Math.tan(x);
} else {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.3e-9) or not (eps <= 3.5e-9): tmp = ((math.tan(eps) + math.tan(x)) / (1.0 - (math.tan(eps) * math.tan(x)))) - math.tan(x) else: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.3e-9) || !(eps <= 3.5e-9)) tmp = Float64(Float64(Float64(tan(eps) + tan(x)) / Float64(1.0 - Float64(tan(eps) * tan(x)))) - tan(x)); else tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.3e-9) || ~((eps <= 3.5e-9))) tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - tan(x); else tmp = eps + (eps * (tan(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.3e-9], N[Not[LessEqual[eps, 3.5e-9]], $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[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.5 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \tan \varepsilon \cdot \tan x} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\end{array}
\end{array}
if eps < -3.30000000000000018e-9 or 3.4999999999999999e-9 < eps Initial program 58.9%
tan-sum99.5%
div-inv99.3%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.3%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if -3.30000000000000018e-9 < eps < 3.4999999999999999e-9Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (if (<= eps -2.4e-5) (- (/ 1.0 (/ (cos eps) (sin eps))) (tan x)) (if (<= eps 0.00039) (+ eps (* eps (pow (tan x) 2.0))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.4e-5) {
tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x);
} else if (eps <= 0.00039) {
tmp = eps + (eps * pow(tan(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 <= (-2.4d-5)) then
tmp = (1.0d0 / (cos(eps) / sin(eps))) - tan(x)
else if (eps <= 0.00039d0) then
tmp = eps + (eps * (tan(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 <= -2.4e-5) {
tmp = (1.0 / (Math.cos(eps) / Math.sin(eps))) - Math.tan(x);
} else if (eps <= 0.00039) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -2.4e-5: tmp = (1.0 / (math.cos(eps) / math.sin(eps))) - math.tan(x) elif eps <= 0.00039: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -2.4e-5) tmp = Float64(Float64(1.0 / Float64(cos(eps) / sin(eps))) - tan(x)); elseif (eps <= 0.00039) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -2.4e-5) tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x); elseif (eps <= 0.00039) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -2.4e-5], N[(N[(1.0 / N[(N[Cos[eps], $MachinePrecision] / N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.00039], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 0.00039:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -2.4000000000000001e-5Initial program 59.4%
tan-sum99.4%
clear-num99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 62.1%
if -2.4000000000000001e-5 < eps < 3.89999999999999993e-4Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 3.89999999999999993e-4 < eps Initial program 58.5%
Taylor expanded in x around 0 59.9%
tan-quot99.5%
expm1-log1p-u78.7%
expm1-udef78.2%
Applied egg-rr48.8%
expm1-def78.7%
expm1-log1p99.5%
Simplified60.1%
Final simplification79.0%
(FPCore (x eps) :precision binary64 (if (<= eps -8.5e-7) (tan eps) (if (<= eps 2.1e-5) (+ eps (* eps (pow (tan x) 2.0))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -8.5e-7) {
tmp = tan(eps);
} else if (eps <= 2.1e-5) {
tmp = eps + (eps * pow(tan(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 <= (-8.5d-7)) then
tmp = tan(eps)
else if (eps <= 2.1d-5) then
tmp = eps + (eps * (tan(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 <= -8.5e-7) {
tmp = Math.tan(eps);
} else if (eps <= 2.1e-5) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -8.5e-7: tmp = math.tan(eps) elif eps <= 2.1e-5: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -8.5e-7) tmp = tan(eps); elseif (eps <= 2.1e-5) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -8.5e-7) tmp = tan(eps); elseif (eps <= 2.1e-5) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -8.5e-7], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 2.1e-5], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -8.5 \cdot 10^{-7}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -8.50000000000000014e-7 or 2.09999999999999988e-5 < eps Initial program 58.9%
Taylor expanded in x around 0 60.6%
tan-quot99.4%
expm1-log1p-u76.7%
expm1-udef76.1%
Applied egg-rr48.7%
expm1-def76.7%
expm1-log1p99.4%
Simplified60.8%
if -8.50000000000000014e-7 < eps < 2.09999999999999988e-5Initial program 30.1%
Taylor expanded in eps around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u99.6%
expm1-udef55.1%
unpow255.1%
unpow255.1%
frac-times55.1%
tan-quot55.1%
tan-quot55.1%
pow255.1%
Applied egg-rr55.1%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
Final simplification78.9%
(FPCore (x eps) :precision binary64 (sin eps))
double code(double x, double eps) {
return sin(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin(eps)
end function
public static double code(double x, double eps) {
return Math.sin(eps);
}
def code(x, eps): return math.sin(eps)
function code(x, eps) return sin(eps) end
function tmp = code(x, eps) tmp = sin(eps); end
code[x_, eps_] := N[Sin[eps], $MachinePrecision]
\begin{array}{l}
\\
\sin \varepsilon
\end{array}
Initial program 45.5%
Taylor expanded in x around 0 58.1%
add-sqr-sqrt31.3%
sqrt-unprod27.2%
pow227.2%
Applied egg-rr27.2%
unpow227.2%
rem-sqrt-square33.3%
Simplified33.3%
Taylor expanded in eps around 0 22.3%
rem-square-sqrt18.2%
fabs-sqr18.2%
rem-square-sqrt31.5%
Simplified31.5%
Final simplification31.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 45.5%
Taylor expanded in x around 0 58.1%
tan-quot78.8%
expm1-log1p-u66.7%
expm1-udef43.7%
Applied egg-rr29.1%
expm1-def66.7%
expm1-log1p78.8%
Simplified58.2%
Final simplification58.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 45.5%
Taylor expanded in x around 0 58.1%
Taylor expanded in eps around 0 27.9%
Final simplification27.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 2023242
(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)))