
(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 11 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 (pow (sin x) 2.0))
(t_1 (pow (cos x) 2.0))
(t_2 (/ t_0 t_1))
(t_3 (+ 1.0 t_2)))
(if (or (<= eps -2.8e-5) (not (<= eps 2.2e-6)))
(- (/ (+ (tan x) (tan eps)) (- (fma (tan x) (tan eps) -1.0))) (tan x))
(+
(* eps t_3)
(+
(*
(pow eps 3.0)
(+
0.3333333333333333
(+ (* t_2 0.3333333333333333) (/ (* t_0 t_3) t_1))))
(/ (* (pow eps 2.0) (* (sin x) t_3)) (cos x)))))))
double code(double x, double eps) {
double t_0 = pow(sin(x), 2.0);
double t_1 = pow(cos(x), 2.0);
double t_2 = t_0 / t_1;
double t_3 = 1.0 + t_2;
double tmp;
if ((eps <= -2.8e-5) || !(eps <= 2.2e-6)) {
tmp = ((tan(x) + tan(eps)) / -fma(tan(x), tan(eps), -1.0)) - tan(x);
} else {
tmp = (eps * t_3) + ((pow(eps, 3.0) * (0.3333333333333333 + ((t_2 * 0.3333333333333333) + ((t_0 * t_3) / t_1)))) + ((pow(eps, 2.0) * (sin(x) * t_3)) / cos(x)));
}
return tmp;
}
function code(x, eps) t_0 = sin(x) ^ 2.0 t_1 = cos(x) ^ 2.0 t_2 = Float64(t_0 / t_1) t_3 = Float64(1.0 + t_2) tmp = 0.0 if ((eps <= -2.8e-5) || !(eps <= 2.2e-6)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(-fma(tan(x), tan(eps), -1.0))) - tan(x)); else tmp = Float64(Float64(eps * t_3) + Float64(Float64((eps ^ 3.0) * Float64(0.3333333333333333 + Float64(Float64(t_2 * 0.3333333333333333) + Float64(Float64(t_0 * t_3) / t_1)))) + Float64(Float64((eps ^ 2.0) * Float64(sin(x) * t_3)) / cos(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 + t$95$2), $MachinePrecision]}, If[Or[LessEqual[eps, -2.8e-5], N[Not[LessEqual[eps, 2.2e-6]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / (-N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(N[(eps * t$95$3), $MachinePrecision] + N[(N[(N[Power[eps, 3.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[(t$95$2 * 0.3333333333333333), $MachinePrecision] + N[(N[(t$95$0 * t$95$3), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin x}^{2}\\
t_1 := {\cos x}^{2}\\
t_2 := \frac{t_0}{t_1}\\
t_3 := 1 + t_2\\
\mathbf{if}\;\varepsilon \leq -2.8 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 2.2 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot t_3 + \left({\varepsilon}^{3} \cdot \left(0.3333333333333333 + \left(t_2 \cdot 0.3333333333333333 + \frac{t_0 \cdot t_3}{t_1}\right)\right) + \frac{{\varepsilon}^{2} \cdot \left(\sin x \cdot t_3\right)}{\cos x}\right)\\
\end{array}
\end{array}
if eps < -2.79999999999999996e-5 or 2.2000000000000001e-6 < eps Initial program 57.2%
tan-sum99.4%
div-inv99.4%
*-un-lft-identity99.4%
prod-diff99.3%
*-commutative99.3%
*-un-lft-identity99.3%
*-commutative99.3%
*-un-lft-identity99.3%
Applied egg-rr99.3%
+-commutative99.3%
fma-udef99.4%
associate-+r+99.4%
unsub-neg99.4%
Simplified99.4%
expm1-log1p-u85.4%
expm1-udef85.3%
log1p-udef85.4%
add-exp-log99.4%
Applied egg-rr99.4%
associate--l+99.4%
fma-neg99.4%
metadata-eval99.4%
Simplified99.4%
sub-neg99.4%
associate--r+99.5%
metadata-eval99.5%
sub0-neg99.5%
Applied egg-rr99.5%
sub-neg99.5%
Simplified99.5%
if -2.79999999999999996e-5 < eps < 2.2000000000000001e-6Initial program 28.0%
tan-sum28.8%
div-inv28.8%
*-un-lft-identity28.8%
prod-diff28.8%
*-commutative28.8%
*-un-lft-identity28.8%
*-commutative28.8%
*-un-lft-identity28.8%
Applied egg-rr28.8%
+-commutative28.8%
fma-udef28.8%
associate-+r+28.8%
unsub-neg28.8%
Simplified28.8%
expm1-log1p-u28.8%
expm1-udef28.8%
log1p-udef28.8%
add-exp-log28.8%
Applied egg-rr28.8%
associate--l+28.8%
fma-neg28.8%
metadata-eval28.8%
Simplified28.8%
Taylor expanded in eps around 0 99.7%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -2.6e-7) (not (<= eps 3.7e-7)))
(- (/ (+ (tan x) (tan eps)) (- (fma (tan x) (tan eps) -1.0))) (tan x))
(+
(* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(*
(pow eps 2.0)
(+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.6e-7) || !(eps <= 3.7e-7)) {
tmp = ((tan(x) + tan(eps)) / -fma(tan(x), tan(eps), -1.0)) - tan(x);
} else {
tmp = (eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)))) + (pow(eps, 2.0) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.0))));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -2.6e-7) || !(eps <= 3.7e-7)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(-fma(tan(x), tan(eps), -1.0))) - tan(x)); else tmp = Float64(Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + Float64((eps ^ 2.0) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0))))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -2.6e-7], N[Not[LessEqual[eps, 3.7e-7]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / (-N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(N[(eps * N[(1.0 + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.6 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 3.7 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{-\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) + {\varepsilon}^{2} \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\\
\end{array}
\end{array}
if eps < -2.59999999999999999e-7 or 3.70000000000000004e-7 < eps Initial program 57.2%
tan-sum99.4%
div-inv99.4%
*-un-lft-identity99.4%
prod-diff99.3%
*-commutative99.3%
*-un-lft-identity99.3%
*-commutative99.3%
*-un-lft-identity99.3%
Applied egg-rr99.3%
+-commutative99.3%
fma-udef99.4%
associate-+r+99.4%
unsub-neg99.4%
Simplified99.4%
expm1-log1p-u85.4%
expm1-udef85.3%
log1p-udef85.4%
add-exp-log99.4%
Applied egg-rr99.4%
associate--l+99.4%
fma-neg99.4%
metadata-eval99.4%
Simplified99.4%
sub-neg99.4%
associate--r+99.5%
metadata-eval99.5%
sub0-neg99.5%
Applied egg-rr99.5%
sub-neg99.5%
Simplified99.5%
if -2.59999999999999999e-7 < eps < 3.70000000000000004e-7Initial program 28.0%
tan-sum28.8%
div-inv28.8%
*-un-lft-identity28.8%
prod-diff28.8%
*-commutative28.8%
*-un-lft-identity28.8%
*-commutative28.8%
*-un-lft-identity28.8%
Applied egg-rr28.8%
+-commutative28.8%
fma-udef28.8%
associate-+r+28.8%
unsub-neg28.8%
Simplified28.8%
Taylor expanded in eps around 0 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.9e-9) (not (<= eps 8e-24))) (- (/ (+ (tan x) (tan eps)) (- (fma (tan x) (tan eps) -1.0))) (tan x)) (+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.9e-9) || !(eps <= 8e-24)) {
tmp = ((tan(x) + tan(eps)) / -fma(tan(x), tan(eps), -1.0)) - tan(x);
} else {
tmp = eps + (eps * pow(tan(x), 2.0));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -2.9e-9) || !(eps <= 8e-24)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(-fma(tan(x), tan(eps), -1.0))) - tan(x)); else tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -2.9e-9], N[Not[LessEqual[eps, 8e-24]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / (-N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + -1.0), $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 -2.9 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{-\mathsf{fma}\left(\tan x, \tan \varepsilon, -1\right)} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\end{array}
\end{array}
if eps < -2.89999999999999991e-9 or 7.99999999999999939e-24 < eps Initial program 57.4%
tan-sum99.1%
div-inv99.1%
*-un-lft-identity99.1%
prod-diff99.0%
*-commutative99.0%
*-un-lft-identity99.0%
*-commutative99.0%
*-un-lft-identity99.0%
Applied egg-rr99.0%
+-commutative99.0%
fma-udef99.1%
associate-+r+99.1%
unsub-neg99.1%
Simplified99.1%
expm1-log1p-u85.5%
expm1-udef85.4%
log1p-udef85.4%
add-exp-log99.1%
Applied egg-rr99.1%
associate--l+99.1%
fma-neg99.2%
metadata-eval99.2%
Simplified99.2%
sub-neg99.2%
associate--r+99.2%
metadata-eval99.2%
sub0-neg99.2%
Applied egg-rr99.2%
sub-neg99.2%
Simplified99.2%
if -2.89999999999999991e-9 < eps < 7.99999999999999939e-24Initial program 27.1%
Taylor expanded in eps around 0 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-lft-identity99.5%
Simplified99.5%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
unpow299.6%
unpow299.6%
frac-times99.6%
tan-quot99.6%
tan-quot99.6%
pow299.6%
Applied egg-rr99.6%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))) (t_1 (* (tan x) (tan eps))))
(if (<= eps -4e-9)
(- (/ t_0 (- 1.0 t_1)) (tan x))
(if (<= eps 8e-24)
(+ eps (* eps (pow (tan x) 2.0)))
(- (* t_0 (/ 1.0 (+ 1.0 (+ 1.0 (- -1.0 t_1))))) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double t_1 = tan(x) * tan(eps);
double tmp;
if (eps <= -4e-9) {
tmp = (t_0 / (1.0 - t_1)) - tan(x);
} else if (eps <= 8e-24) {
tmp = eps + (eps * pow(tan(x), 2.0));
} else {
tmp = (t_0 * (1.0 / (1.0 + (1.0 + (-1.0 - t_1))))) - tan(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = tan(x) + tan(eps)
t_1 = tan(x) * tan(eps)
if (eps <= (-4d-9)) then
tmp = (t_0 / (1.0d0 - t_1)) - tan(x)
else if (eps <= 8d-24) then
tmp = eps + (eps * (tan(x) ** 2.0d0))
else
tmp = (t_0 * (1.0d0 / (1.0d0 + (1.0d0 + ((-1.0d0) - t_1))))) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(x) + Math.tan(eps);
double t_1 = Math.tan(x) * Math.tan(eps);
double tmp;
if (eps <= -4e-9) {
tmp = (t_0 / (1.0 - t_1)) - Math.tan(x);
} else if (eps <= 8e-24) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = (t_0 * (1.0 / (1.0 + (1.0 + (-1.0 - t_1))))) - Math.tan(x);
}
return tmp;
}
def code(x, eps): t_0 = math.tan(x) + math.tan(eps) t_1 = math.tan(x) * math.tan(eps) tmp = 0 if eps <= -4e-9: tmp = (t_0 / (1.0 - t_1)) - math.tan(x) elif eps <= 8e-24: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = (t_0 * (1.0 / (1.0 + (1.0 + (-1.0 - t_1))))) - math.tan(x) return tmp
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) t_1 = Float64(tan(x) * tan(eps)) tmp = 0.0 if (eps <= -4e-9) tmp = Float64(Float64(t_0 / Float64(1.0 - t_1)) - tan(x)); elseif (eps <= 8e-24) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = Float64(Float64(t_0 * Float64(1.0 / Float64(1.0 + Float64(1.0 + Float64(-1.0 - t_1))))) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(x) + tan(eps); t_1 = tan(x) * tan(eps); tmp = 0.0; if (eps <= -4e-9) tmp = (t_0 / (1.0 - t_1)) - tan(x); elseif (eps <= 8e-24) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = (t_0 * (1.0 / (1.0 + (1.0 + (-1.0 - t_1))))) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4e-9], N[(N[(t$95$0 / N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 8e-24], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(1.0 / N[(1.0 + N[(1.0 + N[(-1.0 - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{1 - t_1} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-24}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{1}{1 + \left(1 + \left(-1 - t_1\right)\right)} - \tan x\\
\end{array}
\end{array}
if eps < -4.00000000000000025e-9Initial program 63.8%
tan-sum99.6%
div-inv99.6%
*-un-lft-identity99.6%
prod-diff99.6%
*-commutative99.6%
*-un-lft-identity99.6%
*-commutative99.6%
*-un-lft-identity99.6%
Applied egg-rr99.6%
+-commutative99.6%
fma-udef99.6%
associate-+r+99.6%
unsub-neg99.6%
Simplified99.6%
if -4.00000000000000025e-9 < eps < 7.99999999999999939e-24Initial program 27.1%
Taylor expanded in eps around 0 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-lft-identity99.5%
Simplified99.5%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
unpow299.6%
unpow299.6%
frac-times99.6%
tan-quot99.6%
tan-quot99.6%
pow299.6%
Applied egg-rr99.6%
if 7.99999999999999939e-24 < eps Initial program 49.7%
expm1-log1p-u42.4%
Applied egg-rr42.4%
expm1-log1p-u49.7%
tan-sum98.5%
clear-num98.3%
associate-/r/98.6%
Applied egg-rr98.6%
expm1-log1p-u86.1%
expm1-udef86.0%
log1p-udef86.1%
add-exp-log98.5%
Applied egg-rr98.6%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (tan x) (tan eps))) (t_1 (- 1.0 (* (tan x) (tan eps)))))
(if (<= eps -3.6e-9)
(- (/ t_0 t_1) (tan x))
(if (<= eps 8e-24)
(+ eps (* eps (pow (tan x) 2.0)))
(- (* t_0 (/ 1.0 t_1)) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(x) + tan(eps);
double t_1 = 1.0 - (tan(x) * tan(eps));
double tmp;
if (eps <= -3.6e-9) {
tmp = (t_0 / t_1) - tan(x);
} else if (eps <= 8e-24) {
tmp = eps + (eps * pow(tan(x), 2.0));
} else {
tmp = (t_0 * (1.0 / t_1)) - tan(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = tan(x) + tan(eps)
t_1 = 1.0d0 - (tan(x) * tan(eps))
if (eps <= (-3.6d-9)) then
tmp = (t_0 / t_1) - tan(x)
else if (eps <= 8d-24) then
tmp = eps + (eps * (tan(x) ** 2.0d0))
else
tmp = (t_0 * (1.0d0 / t_1)) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(x) + Math.tan(eps);
double t_1 = 1.0 - (Math.tan(x) * Math.tan(eps));
double tmp;
if (eps <= -3.6e-9) {
tmp = (t_0 / t_1) - Math.tan(x);
} else if (eps <= 8e-24) {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
} else {
tmp = (t_0 * (1.0 / t_1)) - Math.tan(x);
}
return tmp;
}
def code(x, eps): t_0 = math.tan(x) + math.tan(eps) t_1 = 1.0 - (math.tan(x) * math.tan(eps)) tmp = 0 if eps <= -3.6e-9: tmp = (t_0 / t_1) - math.tan(x) elif eps <= 8e-24: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) else: tmp = (t_0 * (1.0 / t_1)) - math.tan(x) return tmp
function code(x, eps) t_0 = Float64(tan(x) + tan(eps)) t_1 = Float64(1.0 - Float64(tan(x) * tan(eps))) tmp = 0.0 if (eps <= -3.6e-9) tmp = Float64(Float64(t_0 / t_1) - tan(x)); elseif (eps <= 8e-24) tmp = Float64(eps + Float64(eps * (tan(x) ^ 2.0))); else tmp = Float64(Float64(t_0 * Float64(1.0 / t_1)) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(x) + tan(eps); t_1 = 1.0 - (tan(x) * tan(eps)); tmp = 0.0; if (eps <= -3.6e-9) tmp = (t_0 / t_1) - tan(x); elseif (eps <= 8e-24) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = (t_0 * (1.0 / t_1)) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.6e-9], N[(N[(t$95$0 / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 8e-24], N[(eps + N[(eps * N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x + \tan \varepsilon\\
t_1 := 1 - \tan x \cdot \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{t_1} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{-24}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{1}{t_1} - \tan x\\
\end{array}
\end{array}
if eps < -3.6e-9Initial program 63.8%
tan-sum99.6%
div-inv99.6%
*-un-lft-identity99.6%
prod-diff99.6%
*-commutative99.6%
*-un-lft-identity99.6%
*-commutative99.6%
*-un-lft-identity99.6%
Applied egg-rr99.6%
+-commutative99.6%
fma-udef99.6%
associate-+r+99.6%
unsub-neg99.6%
Simplified99.6%
if -3.6e-9 < eps < 7.99999999999999939e-24Initial program 27.1%
Taylor expanded in eps around 0 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-lft-identity99.5%
Simplified99.5%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
unpow299.6%
unpow299.6%
frac-times99.6%
tan-quot99.6%
tan-quot99.6%
pow299.6%
Applied egg-rr99.6%
if 7.99999999999999939e-24 < eps Initial program 49.7%
tan-sum98.5%
div-inv98.6%
Applied egg-rr98.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.1e-9) (not (<= eps 8e-24))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.1e-9) || !(eps <= 8e-24)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - 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.1d-9)) .or. (.not. (eps <= 8d-24))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - 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.1e-9) || !(eps <= 8e-24)) {
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.tan(x), 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.1e-9) or not (eps <= 8e-24): 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.tan(x), 2.0)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.1e-9) || !(eps <= 8e-24)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - 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.1e-9) || ~((eps <= 8e-24))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = eps + (eps * (tan(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.1e-9], N[Not[LessEqual[eps, 8e-24]], $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[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.1 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 8 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\end{array}
\end{array}
if eps < -3.10000000000000005e-9 or 7.99999999999999939e-24 < eps Initial program 57.4%
tan-sum99.1%
div-inv99.1%
*-un-lft-identity99.1%
prod-diff99.0%
*-commutative99.0%
*-un-lft-identity99.0%
*-commutative99.0%
*-un-lft-identity99.0%
Applied egg-rr99.0%
+-commutative99.0%
fma-udef99.1%
associate-+r+99.1%
unsub-neg99.1%
Simplified99.1%
if -3.10000000000000005e-9 < eps < 7.99999999999999939e-24Initial program 27.1%
Taylor expanded in eps around 0 99.5%
cancel-sign-sub-inv99.5%
metadata-eval99.5%
*-lft-identity99.5%
Simplified99.5%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
unpow299.6%
unpow299.6%
frac-times99.6%
tan-quot99.6%
tan-quot99.6%
pow299.6%
Applied egg-rr99.6%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= eps -0.00185) (- (/ 1.0 (/ (cos eps) (sin eps))) (tan x)) (if (<= eps 1.4e-6) (+ eps (* eps (pow (tan x) 2.0))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00185) {
tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x);
} else if (eps <= 1.4e-6) {
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 <= (-0.00185d0)) then
tmp = (1.0d0 / (cos(eps) / sin(eps))) - tan(x)
else if (eps <= 1.4d-6) 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 <= -0.00185) {
tmp = (1.0 / (Math.cos(eps) / Math.sin(eps))) - Math.tan(x);
} else if (eps <= 1.4e-6) {
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 <= -0.00185: tmp = (1.0 / (math.cos(eps) / math.sin(eps))) - math.tan(x) elif eps <= 1.4e-6: 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 <= -0.00185) tmp = Float64(Float64(1.0 / Float64(cos(eps) / sin(eps))) - tan(x)); elseif (eps <= 1.4e-6) 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 <= -0.00185) tmp = (1.0 / (cos(eps) / sin(eps))) - tan(x); elseif (eps <= 1.4e-6) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -0.00185], N[(N[(1.0 / N[(N[Cos[eps], $MachinePrecision] / N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.4e-6], 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 -0.00185:\\
\;\;\;\;\frac{1}{\frac{\cos \varepsilon}{\sin \varepsilon}} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 1.4 \cdot 10^{-6}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -0.0018500000000000001Initial program 64.7%
tan-sum99.8%
clear-num99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 67.2%
if -0.0018500000000000001 < eps < 1.39999999999999994e-6Initial program 27.9%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
distribute-rgt-in98.8%
*-un-lft-identity98.8%
unpow298.8%
unpow298.8%
frac-times98.8%
tan-quot98.8%
tan-quot98.8%
pow298.8%
Applied egg-rr98.8%
if 1.39999999999999994e-6 < eps Initial program 48.7%
Taylor expanded in x around 0 50.5%
tan-quot50.7%
expm1-log1p-u42.0%
expm1-udef41.1%
Applied egg-rr41.1%
expm1-def42.0%
expm1-log1p50.7%
Simplified50.7%
Final simplification80.6%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0018) (not (<= eps 1.2e-6))) (tan eps) (* eps (+ 1.0 (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0018) || !(eps <= 1.2e-6)) {
tmp = tan(eps);
} else {
tmp = eps * (1.0 + 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 <= (-0.0018d0)) .or. (.not. (eps <= 1.2d-6))) then
tmp = tan(eps)
else
tmp = eps * (1.0d0 + (tan(x) ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0018) || !(eps <= 1.2e-6)) {
tmp = Math.tan(eps);
} else {
tmp = eps * (1.0 + Math.pow(Math.tan(x), 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0018) or not (eps <= 1.2e-6): tmp = math.tan(eps) else: tmp = eps * (1.0 + math.pow(math.tan(x), 2.0)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0018) || !(eps <= 1.2e-6)) tmp = tan(eps); else tmp = Float64(eps * Float64(1.0 + (tan(x) ^ 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0018) || ~((eps <= 1.2e-6))) tmp = tan(eps); else tmp = eps * (1.0 + (tan(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0018], N[Not[LessEqual[eps, 1.2e-6]], $MachinePrecision]], N[Tan[eps], $MachinePrecision], N[(eps * N[(1.0 + N[Power[N[Tan[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0018 \lor \neg \left(\varepsilon \leq 1.2 \cdot 10^{-6}\right):\\
\;\;\;\;\tan \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + {\tan x}^{2}\right)\\
\end{array}
\end{array}
if eps < -0.0018 or 1.1999999999999999e-6 < eps Initial program 57.6%
Taylor expanded in x around 0 59.7%
tan-quot59.9%
expm1-log1p-u48.5%
expm1-udef48.0%
Applied egg-rr48.0%
expm1-def48.5%
expm1-log1p59.9%
Simplified59.9%
if -0.0018 < eps < 1.1999999999999999e-6Initial program 27.9%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
unpow298.7%
unpow298.7%
frac-times98.6%
tan-quot98.7%
tan-quot98.7%
Applied egg-rr98.7%
unpow298.7%
Simplified98.7%
Final simplification80.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0018) (not (<= eps 1.5e-6))) (tan eps) (+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0018) || !(eps <= 1.5e-6)) {
tmp = tan(eps);
} 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 <= (-0.0018d0)) .or. (.not. (eps <= 1.5d-6))) then
tmp = tan(eps)
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 <= -0.0018) || !(eps <= 1.5e-6)) {
tmp = Math.tan(eps);
} else {
tmp = eps + (eps * Math.pow(Math.tan(x), 2.0));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0018) or not (eps <= 1.5e-6): tmp = math.tan(eps) else: tmp = eps + (eps * math.pow(math.tan(x), 2.0)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0018) || !(eps <= 1.5e-6)) tmp = tan(eps); 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 <= -0.0018) || ~((eps <= 1.5e-6))) tmp = tan(eps); else tmp = eps + (eps * (tan(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0018], N[Not[LessEqual[eps, 1.5e-6]], $MachinePrecision]], N[Tan[eps], $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 -0.0018 \lor \neg \left(\varepsilon \leq 1.5 \cdot 10^{-6}\right):\\
\;\;\;\;\tan \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\end{array}
\end{array}
if eps < -0.0018 or 1.5e-6 < eps Initial program 57.6%
Taylor expanded in x around 0 59.7%
tan-quot59.9%
expm1-log1p-u48.5%
expm1-udef48.0%
Applied egg-rr48.0%
expm1-def48.5%
expm1-log1p59.9%
Simplified59.9%
if -0.0018 < eps < 1.5e-6Initial program 27.9%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
distribute-rgt-in98.8%
*-un-lft-identity98.8%
unpow298.8%
unpow298.8%
frac-times98.8%
tan-quot98.8%
tan-quot98.8%
pow298.8%
Applied egg-rr98.8%
Final simplification80.6%
(FPCore (x eps) :precision binary64 (tan eps))
double code(double x, double eps) {
return tan(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan(eps)
end function
public static double code(double x, double eps) {
return Math.tan(eps);
}
def code(x, eps): return math.tan(eps)
function code(x, eps) return tan(eps) end
function tmp = code(x, eps) tmp = tan(eps); end
code[x_, eps_] := N[Tan[eps], $MachinePrecision]
\begin{array}{l}
\\
\tan \varepsilon
\end{array}
Initial program 41.8%
Taylor expanded in x around 0 58.8%
tan-quot58.9%
expm1-log1p-u53.5%
expm1-udef25.8%
Applied egg-rr25.8%
expm1-def53.5%
expm1-log1p58.9%
Simplified58.9%
Final simplification58.9%
(FPCore (x eps) :precision binary64 eps)
double code(double x, double eps) {
return eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps
end function
public static double code(double x, double eps) {
return eps;
}
def code(x, eps): return eps
function code(x, eps) return eps end
function tmp = code(x, eps) tmp = eps; end
code[x_, eps_] := eps
\begin{array}{l}
\\
\varepsilon
\end{array}
Initial program 41.8%
Taylor expanded in x around 0 58.8%
Taylor expanded in eps around 0 32.6%
Final simplification32.6%
(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 2023332
(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)))