
(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) (tan eps))) (t_1 (- (tan x))))
(if (<= eps -2.6e-9)
(fma t_0 (/ -1.0 (fma (tan x) (tan eps) -1.0)) t_1)
(if (<= eps 6.5e-9)
(fma eps (pow (tan x) 2.0) eps)
(fma t_0 (/ 1.0 (- 1.0 (* (tan x) (tan eps)))) t_1)))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double t_1 = -tan(x);
double tmp;
if (eps <= -2.6e-9) {
tmp = fma(t_0, (-1.0 / fma(tan(x), tan(eps), -1.0)), t_1);
} else if (eps <= 6.5e-9) {
tmp = fma(eps, pow(tan(x), 2.0), eps);
} else {
tmp = fma(t_0, (1.0 / (1.0 - (tan(x) * tan(eps)))), t_1);
}
return tmp;
}
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) t_1 = Float64(-tan(x)) tmp = 0.0 if (eps <= -2.6e-9) tmp = fma(t_0, Float64(-1.0 / fma(tan(x), tan(eps), -1.0)), t_1); elseif (eps <= 6.5e-9) tmp = fma(eps, (tan(x) ^ 2.0), eps); else tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(tan(x) * tan(eps)))), t_1); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Tan[x], $MachinePrecision])}, If[LessEqual[eps, -2.6e-9], N[(t$95$0 * N[(-1.0 / N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[eps, 6.5e-9], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := -\tan x\\
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{-1}{\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)}, t_1\right)\\
\mathbf{elif}\;\varepsilon \leq 6.5 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, t_1\right)\\
\end{array}
\end{array}
if eps < -2.6000000000000001e-9Initial program 54.2%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
/-rgt-identity99.4%
frac-2neg99.4%
Applied egg-rr99.4%
+-commutative99.4%
fma-def99.5%
Simplified99.5%
clear-num99.5%
div-inv99.5%
Applied egg-rr99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
if -2.6000000000000001e-9 < eps < 6.5000000000000003e-9Initial program 28.0%
tan-sum28.0%
div-inv28.0%
fma-neg28.0%
Applied egg-rr28.0%
fma-neg28.0%
associate-*r/28.0%
*-rgt-identity28.0%
Simplified28.0%
Taylor expanded in eps around 0 99.6%
sub-neg99.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
distribute-lft-in99.7%
*-rgt-identity99.7%
unpow299.7%
unpow299.7%
frac-times99.7%
tan-quot99.7%
tan-quot99.7%
pow299.7%
Applied egg-rr99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
if 6.5000000000000003e-9 < eps Initial program 45.9%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
(if (<= eps -4.2e-9)
(- (/ t_0 t_1) (tan x))
(if (<= eps 5.7e-9)
(fma eps (pow (tan x) 2.0) eps)
(fma 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 <= -4.2e-9) {
tmp = (t_0 / t_1) - tan(x);
} else if (eps <= 5.7e-9) {
tmp = fma(eps, pow(tan(x), 2.0), eps);
} else {
tmp = fma(t_0, (1.0 / t_1), -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 <= -4.2e-9) tmp = Float64(Float64(t_0 / t_1) - tan(x)); elseif (eps <= 5.7e-9) tmp = fma(eps, (tan(x) ^ 2.0), eps); else tmp = fma(t_0, Float64(1.0 / t_1), Float64(-tan(x))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.2e-9], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5.7e-9], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[(t$95$0 * N[(1.0 / t$95$1), $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 -4.2 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 5.7 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{t_1}, -\tan x\right)\\
\end{array}
\end{array}
if eps < -4.20000000000000039e-9Initial program 54.2%
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%
if -4.20000000000000039e-9 < eps < 5.6999999999999998e-9Initial program 28.0%
tan-sum28.0%
div-inv28.0%
fma-neg28.0%
Applied egg-rr28.0%
fma-neg28.0%
associate-*r/28.0%
*-rgt-identity28.0%
Simplified28.0%
Taylor expanded in eps around 0 99.6%
sub-neg99.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
distribute-lft-in99.7%
*-rgt-identity99.7%
unpow299.7%
unpow299.7%
frac-times99.7%
tan-quot99.7%
tan-quot99.7%
pow299.7%
Applied egg-rr99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
if 5.6999999999999998e-9 < eps Initial program 45.9%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.4e-9) (not (<= eps 3.55e-9))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (fma eps (pow (tan x) 2.0) eps)))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.4e-9) || !(eps <= 3.55e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = fma(eps, pow(tan(x), 2.0), eps);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -2.4e-9) || !(eps <= 3.55e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = fma(eps, (tan(x) ^ 2.0), eps); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -2.4e-9], N[Not[LessEqual[eps, 3.55e-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[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.4 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.55 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\end{array}
\end{array}
if eps < -2.4e-9 or 3.54999999999999994e-9 < eps Initial program 50.2%
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%
if -2.4e-9 < eps < 3.54999999999999994e-9Initial program 28.0%
tan-sum28.0%
div-inv28.0%
fma-neg28.0%
Applied egg-rr28.0%
fma-neg28.0%
associate-*r/28.0%
*-rgt-identity28.0%
Simplified28.0%
Taylor expanded in eps around 0 99.6%
sub-neg99.6%
mul-1-neg99.6%
remove-double-neg99.6%
Simplified99.6%
distribute-lft-in99.7%
*-rgt-identity99.7%
unpow299.7%
unpow299.7%
frac-times99.7%
tan-quot99.7%
tan-quot99.7%
pow299.7%
Applied egg-rr99.7%
+-commutative99.7%
fma-def99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0072)
(tan eps)
(if (<= eps 2.25e-5)
(fma eps (pow (tan x) 2.0) eps)
(- (+ (tan x) (tan eps)) (/ (sin x) (cos x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0072) {
tmp = tan(eps);
} else if (eps <= 2.25e-5) {
tmp = fma(eps, pow(tan(x), 2.0), eps);
} else {
tmp = (tan(x) + tan(eps)) - (sin(x) / cos(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0072) tmp = tan(eps); elseif (eps <= 2.25e-5) tmp = fma(eps, (tan(x) ^ 2.0), eps); else tmp = Float64(Float64(tan(x) + tan(eps)) - Float64(sin(x) / cos(x))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0072], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 2.25e-5], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0072:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 2.25 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\tan x + \tan \varepsilon\right) - \frac{\sin x}{\cos x}\\
\end{array}
\end{array}
if eps < -0.0071999999999999998Initial program 54.9%
Taylor expanded in x around 0 58.5%
tan-quot58.6%
expm1-log1p-u41.4%
expm1-udef41.1%
Applied egg-rr41.1%
expm1-def41.4%
expm1-log1p58.6%
Simplified58.6%
if -0.0071999999999999998 < eps < 2.25000000000000014e-5Initial program 27.8%
tan-sum28.5%
div-inv28.5%
fma-neg28.5%
Applied egg-rr28.5%
fma-neg28.5%
associate-*r/28.5%
*-rgt-identity28.5%
Simplified28.5%
Taylor expanded in eps around 0 99.1%
sub-neg99.1%
mul-1-neg99.1%
remove-double-neg99.1%
Simplified99.1%
distribute-lft-in99.1%
*-rgt-identity99.1%
unpow299.1%
unpow299.1%
frac-times99.1%
tan-quot99.2%
tan-quot99.2%
pow299.2%
Applied egg-rr99.2%
+-commutative99.2%
fma-def99.3%
Simplified99.3%
if 2.25000000000000014e-5 < eps Initial program 45.9%
tan-sum99.4%
div-inv99.4%
tan-quot99.4%
div-inv99.3%
prod-diff99.4%
Applied egg-rr99.4%
+-commutative99.4%
fma-udef99.3%
associate-+r+99.3%
Simplified99.4%
Taylor expanded in x around 0 48.9%
Final simplification76.8%
(FPCore (x eps)
:precision binary64
(if (<= eps -0.0072)
(tan eps)
(if (<= eps 6.3e-6)
(fma eps (pow (tan x) 2.0) eps)
(fma (+ (tan x) (tan eps)) 1.0 (- (tan x))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0072) {
tmp = tan(eps);
} else if (eps <= 6.3e-6) {
tmp = fma(eps, pow(tan(x), 2.0), eps);
} else {
tmp = fma((tan(x) + tan(eps)), 1.0, -tan(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0072) tmp = tan(eps); elseif (eps <= 6.3e-6) tmp = fma(eps, (tan(x) ^ 2.0), eps); else tmp = fma(Float64(tan(x) + tan(eps)), 1.0, Float64(-tan(x))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0072], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 6.3e-6], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] * 1.0 + (-N[Tan[x], $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0072:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 6.3 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\tan x + \tan \varepsilon, 1, -\tan x\right)\\
\end{array}
\end{array}
if eps < -0.0071999999999999998Initial program 54.9%
Taylor expanded in x around 0 58.5%
tan-quot58.6%
expm1-log1p-u41.4%
expm1-udef41.1%
Applied egg-rr41.1%
expm1-def41.4%
expm1-log1p58.6%
Simplified58.6%
if -0.0071999999999999998 < eps < 6.29999999999999982e-6Initial program 27.8%
tan-sum28.5%
div-inv28.5%
fma-neg28.5%
Applied egg-rr28.5%
fma-neg28.5%
associate-*r/28.5%
*-rgt-identity28.5%
Simplified28.5%
Taylor expanded in eps around 0 99.1%
sub-neg99.1%
mul-1-neg99.1%
remove-double-neg99.1%
Simplified99.1%
distribute-lft-in99.1%
*-rgt-identity99.1%
unpow299.1%
unpow299.1%
frac-times99.1%
tan-quot99.2%
tan-quot99.2%
pow299.2%
Applied egg-rr99.2%
+-commutative99.2%
fma-def99.3%
Simplified99.3%
if 6.29999999999999982e-6 < eps Initial program 45.9%
tan-sum99.4%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
/-rgt-identity99.4%
frac-2neg99.4%
Applied egg-rr99.4%
+-commutative99.4%
fma-def99.4%
Simplified99.4%
Taylor expanded in x around 0 48.9%
Final simplification76.8%
(FPCore (x eps) :precision binary64 (if (<= eps -0.0072) (tan eps) (if (<= eps 3.75e-6) (fma eps (pow (tan x) 2.0) eps) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0072) {
tmp = tan(eps);
} else if (eps <= 3.75e-6) {
tmp = fma(eps, pow(tan(x), 2.0), eps);
} else {
tmp = tan(eps);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.0072) tmp = tan(eps); elseif (eps <= 3.75e-6) tmp = fma(eps, (tan(x) ^ 2.0), eps); else tmp = tan(eps); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.0072], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 3.75e-6], N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + eps), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0072:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 3.75 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, {\tan x}^{2}, \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -0.0071999999999999998 or 3.7500000000000001e-6 < eps Initial program 50.6%
Taylor expanded in x around 0 53.7%
tan-quot53.9%
expm1-log1p-u41.7%
expm1-udef41.4%
Applied egg-rr41.4%
expm1-def41.7%
expm1-log1p53.9%
Simplified53.9%
if -0.0071999999999999998 < eps < 3.7500000000000001e-6Initial program 27.8%
tan-sum28.5%
div-inv28.5%
fma-neg28.5%
Applied egg-rr28.5%
fma-neg28.5%
associate-*r/28.5%
*-rgt-identity28.5%
Simplified28.5%
Taylor expanded in eps around 0 99.1%
sub-neg99.1%
mul-1-neg99.1%
remove-double-neg99.1%
Simplified99.1%
distribute-lft-in99.1%
*-rgt-identity99.1%
unpow299.1%
unpow299.1%
frac-times99.1%
tan-quot99.2%
tan-quot99.2%
pow299.2%
Applied egg-rr99.2%
+-commutative99.2%
fma-def99.3%
Simplified99.3%
Final simplification76.8%
(FPCore (x eps) :precision binary64 (if (<= eps -0.0072) (tan eps) (if (<= eps 1.48e-5) (* eps (+ (pow (tan x) 2.0) 1.0)) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.0072) {
tmp = tan(eps);
} else if (eps <= 1.48e-5) {
tmp = eps * (pow(tan(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 <= (-0.0072d0)) then
tmp = tan(eps)
else if (eps <= 1.48d-5) then
tmp = eps * ((tan(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 <= -0.0072) {
tmp = Math.tan(eps);
} else if (eps <= 1.48e-5) {
tmp = eps * (Math.pow(Math.tan(x), 2.0) + 1.0);
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -0.0072: tmp = math.tan(eps) elif eps <= 1.48e-5: tmp = eps * (math.pow(math.tan(x), 2.0) + 1.0) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -0.0072) tmp = tan(eps); elseif (eps <= 1.48e-5) tmp = Float64(eps * Float64((tan(x) ^ 2.0) + 1.0)); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -0.0072) tmp = tan(eps); elseif (eps <= 1.48e-5) tmp = eps * ((tan(x) ^ 2.0) + 1.0); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.0072], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 1.48e-5], N[(eps * N[(N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0072:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 1.48 \cdot 10^{-5}:\\
\;\;\;\;\varepsilon \cdot \left({\tan x}^{2} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -0.0071999999999999998 or 1.4800000000000001e-5 < eps Initial program 50.6%
Taylor expanded in x around 0 53.7%
tan-quot53.9%
expm1-log1p-u41.7%
expm1-udef41.4%
Applied egg-rr41.4%
expm1-def41.7%
expm1-log1p53.9%
Simplified53.9%
if -0.0071999999999999998 < eps < 1.4800000000000001e-5Initial program 27.8%
tan-sum28.5%
div-inv28.5%
fma-neg28.5%
Applied egg-rr28.5%
fma-neg28.5%
associate-*r/28.5%
*-rgt-identity28.5%
Simplified28.5%
Taylor expanded in eps around 0 99.1%
sub-neg99.1%
mul-1-neg99.1%
remove-double-neg99.1%
Simplified99.1%
unpow299.1%
unpow299.1%
frac-times99.2%
tan-quot99.2%
tan-quot99.2%
Applied egg-rr99.2%
unpow299.2%
Simplified99.2%
Final simplification76.8%
(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 39.1%
Taylor expanded in x around 0 57.1%
tan-quot57.2%
expm1-log1p-u51.1%
expm1-udef23.6%
Applied egg-rr23.6%
expm1-def51.1%
expm1-log1p57.2%
Simplified57.2%
Final simplification57.2%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 39.1%
add-cube-cbrt38.2%
pow338.3%
Applied egg-rr38.3%
Taylor expanded in eps around 0 4.3%
pow-base-14.3%
*-lft-identity4.3%
+-inverses4.3%
Simplified4.3%
Final simplification4.3%
(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 39.1%
Taylor expanded in x around 0 57.1%
Taylor expanded in eps around 0 31.9%
Final simplification31.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 2023293
(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)))