
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps): return math.tan((x + eps)) - math.tan(x)
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function tmp = code(x, eps) tmp = tan((x + eps)) - tan(x); end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (tan (+ x eps)) (tan x)))
double code(double x, double eps) {
return tan((x + eps)) - tan(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan((x + eps)) - tan(x)
end function
public static double code(double x, double eps) {
return Math.tan((x + eps)) - Math.tan(x);
}
def code(x, eps): return math.tan((x + eps)) - math.tan(x)
function code(x, eps) return Float64(tan(Float64(x + eps)) - tan(x)) end
function tmp = code(x, eps) tmp = tan((x + eps)) - tan(x); end
code[x_, eps_] := N[(N[Tan[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(x + \varepsilon\right) - \tan x
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (tan x) (tan eps))) (t_1 (+ (tan x) (tan eps))))
(if (<= eps -4.4e-7)
(-
(/
(* t_1 (+ (fma (tan x) (tan eps) (pow t_0 2.0)) 1.0))
(- 1.0 (pow t_0 3.0)))
(tan x))
(if (<= eps 2.9e-7)
(+
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(*
(* eps eps)
(+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))))
(- (/ t_1 (- 1.0 t_0)) (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 <= -4.4e-7) {
tmp = ((t_1 * (fma(tan(x), tan(eps), pow(t_0, 2.0)) + 1.0)) / (1.0 - pow(t_0, 3.0))) - tan(x);
} else if (eps <= 2.9e-7) {
tmp = (eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)))) + ((eps * eps) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.0))));
} else {
tmp = (t_1 / (1.0 - t_0)) - 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 <= -4.4e-7) tmp = Float64(Float64(Float64(t_1 * Float64(fma(tan(x), tan(eps), (t_0 ^ 2.0)) + 1.0)) / Float64(1.0 - (t_0 ^ 3.0))) - tan(x)); elseif (eps <= 2.9e-7) tmp = Float64(Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + Float64(Float64(eps * eps) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0))))); else tmp = Float64(Float64(t_1 / Float64(1.0 - t_0)) - 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[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -4.4e-7], N[(N[(N[(t$95$1 * N[(N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 2.9e-7], N[(N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $MachinePrecision] * N[(N[(N[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], N[(N[(t$95$1 / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan x \cdot \tan \varepsilon\\
t_1 := \tan x + \tan \varepsilon\\
\mathbf{if}\;\varepsilon \leq -4.4 \cdot 10^{-7}:\\
\;\;\;\;\frac{t_1 \cdot \left(\mathsf{fma}\left(\tan x, \tan \varepsilon, {t_0}^{2}\right) + 1\right)}{1 - {t_0}^{3}} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 2.9 \cdot 10^{-7}:\\
\;\;\;\;\left(\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{1 - t_0} - \tan x\\
\end{array}
\end{array}
if eps < -4.4000000000000002e-7Initial program 57.2%
tan-sum99.5%
div-inv99.5%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
flip3--99.4%
associate-/r/99.3%
metadata-eval99.3%
metadata-eval99.3%
*-un-lft-identity99.3%
+-commutative99.3%
pow299.3%
Applied egg-rr99.3%
associate-*l/99.5%
fma-def99.5%
Simplified99.5%
if -4.4000000000000002e-7 < eps < 2.8999999999999998e-7Initial program 30.3%
tan-sum31.6%
div-inv31.6%
fma-neg31.6%
Applied egg-rr31.6%
fma-neg31.6%
associate-*r/31.6%
*-rgt-identity31.6%
Simplified31.6%
*-commutative31.6%
tan-quot31.6%
associate-*r/31.6%
Applied egg-rr31.6%
Taylor expanded in eps around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
if 2.8999999999999998e-7 < eps Initial program 53.1%
tan-sum99.6%
div-inv99.4%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.4%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -3.6e-7) (not (<= eps 3.8e-7)))
(- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
(+
(* eps (+ (/ (pow (sin x) 2.0) (pow (cos x) 2.0)) 1.0))
(*
(* eps eps)
(+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.6e-7) || !(eps <= 3.8e-7)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = (eps * ((pow(sin(x), 2.0) / pow(cos(x), 2.0)) + 1.0)) + ((eps * eps) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.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.6d-7)) .or. (.not. (eps <= 3.8d-7))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = (eps * (((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)) + 1.0d0)) + ((eps * eps) * ((sin(x) / cos(x)) + ((sin(x) ** 3.0d0) / (cos(x) ** 3.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.6e-7) || !(eps <= 3.8e-7)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = (eps * ((Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)) + 1.0)) + ((eps * eps) * ((Math.sin(x) / Math.cos(x)) + (Math.pow(Math.sin(x), 3.0) / Math.pow(Math.cos(x), 3.0))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.6e-7) or not (eps <= 3.8e-7): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = (eps * ((math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)) + 1.0)) + ((eps * eps) * ((math.sin(x) / math.cos(x)) + (math.pow(math.sin(x), 3.0) / math.pow(math.cos(x), 3.0)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.6e-7) || !(eps <= 3.8e-7)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(Float64(eps * Float64(Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0)) + Float64(Float64(eps * eps) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.6e-7) || ~((eps <= 3.8e-7))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = (eps * (((sin(x) ^ 2.0) / (cos(x) ^ 2.0)) + 1.0)) + ((eps * eps) * ((sin(x) / cos(x)) + ((sin(x) ^ 3.0) / (cos(x) ^ 3.0)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.6e-7], N[Not[LessEqual[eps, 3.8e-7]], $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[(N[(eps * N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $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 -3.6 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 3.8 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(\frac{{\sin x}^{2}}{{\cos x}^{2}} + 1\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\\
\end{array}
\end{array}
if eps < -3.59999999999999994e-7 or 3.80000000000000015e-7 < eps Initial program 55.2%
tan-sum99.5%
div-inv99.5%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if -3.59999999999999994e-7 < eps < 3.80000000000000015e-7Initial program 30.3%
tan-sum31.6%
div-inv31.6%
fma-neg31.6%
Applied egg-rr31.6%
fma-neg31.6%
associate-*r/31.6%
*-rgt-identity31.6%
Simplified31.6%
Taylor expanded in eps around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
sub-neg99.6%
mul-1-neg99.6%
remove-double-neg99.6%
mul-1-neg99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -3.1e-7) (not (<= eps 3.8e-7)))
(- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
(+
(+ eps (* eps (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(*
(* eps eps)
(+ (/ (sin x) (cos x)) (/ (pow (sin x) 3.0) (pow (cos x) 3.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.1e-7) || !(eps <= 3.8e-7)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = (eps + (eps * (pow(sin(x), 2.0) / pow(cos(x), 2.0)))) + ((eps * eps) * ((sin(x) / cos(x)) + (pow(sin(x), 3.0) / pow(cos(x), 3.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-7)) .or. (.not. (eps <= 3.8d-7))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = (eps + (eps * ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))) + ((eps * eps) * ((sin(x) / cos(x)) + ((sin(x) ** 3.0d0) / (cos(x) ** 3.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.1e-7) || !(eps <= 3.8e-7)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = (eps + (eps * (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)))) + ((eps * eps) * ((Math.sin(x) / Math.cos(x)) + (Math.pow(Math.sin(x), 3.0) / Math.pow(Math.cos(x), 3.0))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.1e-7) or not (eps <= 3.8e-7): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = (eps + (eps * (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))) + ((eps * eps) * ((math.sin(x) / math.cos(x)) + (math.pow(math.sin(x), 3.0) / math.pow(math.cos(x), 3.0)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.1e-7) || !(eps <= 3.8e-7)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(Float64(eps + Float64(eps * Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + Float64(Float64(eps * eps) * Float64(Float64(sin(x) / cos(x)) + Float64((sin(x) ^ 3.0) / (cos(x) ^ 3.0))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.1e-7) || ~((eps <= 3.8e-7))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = (eps + (eps * ((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) + ((eps * eps) * ((sin(x) / cos(x)) + ((sin(x) ^ 3.0) / (cos(x) ^ 3.0)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.1e-7], N[Not[LessEqual[eps, 3.8e-7]], $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[(N[(eps + N[(eps * N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * eps), $MachinePrecision] * N[(N[(N[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 -3.1 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 3.8 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon + \varepsilon \cdot \frac{{\sin x}^{2}}{{\cos x}^{2}}\right) + \left(\varepsilon \cdot \varepsilon\right) \cdot \left(\frac{\sin x}{\cos x} + \frac{{\sin x}^{3}}{{\cos x}^{3}}\right)\\
\end{array}
\end{array}
if eps < -3.1e-7 or 3.80000000000000015e-7 < eps Initial program 55.2%
tan-sum99.5%
div-inv99.5%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if -3.1e-7 < eps < 3.80000000000000015e-7Initial program 30.3%
tan-sum31.6%
div-inv31.6%
fma-neg31.6%
Applied egg-rr31.6%
fma-neg31.6%
associate-*r/31.6%
*-rgt-identity31.6%
Simplified31.6%
*-commutative31.6%
tan-quot31.6%
associate-*r/31.6%
Applied egg-rr31.6%
Taylor expanded in eps around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (sin eps) (cos eps))))
(if (or (<= eps -135000000.0) (not (<= eps 5.2e-9)))
(- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x))
(+
(/ t_0 (- 1.0 (* (/ (sin x) (cos x)) t_0)))
(/ (* eps (pow (sin x) 2.0)) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double t_0 = sin(eps) / cos(eps);
double tmp;
if ((eps <= -135000000.0) || !(eps <= 5.2e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = (t_0 / (1.0 - ((sin(x) / cos(x)) * t_0))) + ((eps * pow(sin(x), 2.0)) / pow(cos(x), 2.0));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = sin(eps) / cos(eps)
if ((eps <= (-135000000.0d0)) .or. (.not. (eps <= 5.2d-9))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = (t_0 / (1.0d0 - ((sin(x) / cos(x)) * t_0))) + ((eps * (sin(x) ** 2.0d0)) / (cos(x) ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) / Math.cos(eps);
double tmp;
if ((eps <= -135000000.0) || !(eps <= 5.2e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = (t_0 / (1.0 - ((Math.sin(x) / Math.cos(x)) * t_0))) + ((eps * Math.pow(Math.sin(x), 2.0)) / Math.pow(Math.cos(x), 2.0));
}
return tmp;
}
def code(x, eps): t_0 = math.sin(eps) / math.cos(eps) tmp = 0 if (eps <= -135000000.0) or not (eps <= 5.2e-9): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = (t_0 / (1.0 - ((math.sin(x) / math.cos(x)) * t_0))) + ((eps * math.pow(math.sin(x), 2.0)) / math.pow(math.cos(x), 2.0)) return tmp
function code(x, eps) t_0 = Float64(sin(eps) / cos(eps)) tmp = 0.0 if ((eps <= -135000000.0) || !(eps <= 5.2e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(Float64(sin(x) / cos(x)) * t_0))) + Float64(Float64(eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0))); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin(eps) / cos(eps); tmp = 0.0; if ((eps <= -135000000.0) || ~((eps <= 5.2e-9))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = (t_0 / (1.0 - ((sin(x) / cos(x)) * t_0))) + ((eps * (sin(x) ^ 2.0)) / (cos(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -135000000.0], N[Not[LessEqual[eps, 5.2e-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[(N[(t$95$0 / N[(1.0 - N[(N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps * N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
\mathbf{if}\;\varepsilon \leq -135000000 \lor \neg \left(\varepsilon \leq 5.2 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \frac{\sin x}{\cos x} \cdot t_0} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -1.35e8 or 5.2000000000000002e-9 < eps Initial program 54.8%
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%
if -1.35e8 < eps < 5.2000000000000002e-9Initial program 30.8%
tan-sum32.2%
div-inv32.2%
fma-neg32.2%
Applied egg-rr32.2%
fma-neg32.2%
associate-*r/32.2%
*-rgt-identity32.2%
Simplified32.2%
Taylor expanded in x around inf 32.2%
associate--l+54.5%
Simplified54.5%
Taylor expanded in eps around 0 99.1%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.5e-9) (not (<= eps 4.5e-9))) (- (/ (+ (tan x) (tan eps)) (- 1.0 (* (tan x) (tan eps)))) (tan x)) (+ eps (* eps (sqrt (pow (tan x) 4.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.5e-9) || !(eps <= 4.5e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x);
} else {
tmp = eps + (eps * sqrt(pow(tan(x), 4.0)));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-2.5d-9)) .or. (.not. (eps <= 4.5d-9))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - (tan(x) * tan(eps)))) - tan(x)
else
tmp = eps + (eps * sqrt((tan(x) ** 4.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -2.5e-9) || !(eps <= 4.5e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - (Math.tan(x) * Math.tan(eps)))) - Math.tan(x);
} else {
tmp = eps + (eps * Math.sqrt(Math.pow(Math.tan(x), 4.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -2.5e-9) or not (eps <= 4.5e-9): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - (math.tan(x) * math.tan(eps)))) - math.tan(x) else: tmp = eps + (eps * math.sqrt(math.pow(math.tan(x), 4.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -2.5e-9) || !(eps <= 4.5e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(tan(x) * tan(eps)))) - tan(x)); else tmp = Float64(eps + Float64(eps * sqrt((tan(x) ^ 4.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -2.5e-9) || ~((eps <= 4.5e-9))) tmp = ((tan(x) + tan(eps)) / (1.0 - (tan(x) * tan(eps)))) - tan(x); else tmp = eps + (eps * sqrt((tan(x) ^ 4.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -2.5e-9], N[Not[LessEqual[eps, 4.5e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(eps * N[Sqrt[N[Power[N[Tan[x], $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.5 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 4.5 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{4}}\\
\end{array}
\end{array}
if eps < -2.5000000000000001e-9 or 4.49999999999999976e-9 < eps Initial program 55.2%
tan-sum99.5%
div-inv99.5%
fma-neg99.4%
Applied egg-rr99.4%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
if -2.5000000000000001e-9 < eps < 4.49999999999999976e-9Initial program 30.3%
Taylor expanded in eps around 0 98.9%
cancel-sign-sub-inv98.9%
metadata-eval98.9%
*-lft-identity98.9%
distribute-lft-in98.9%
*-rgt-identity98.9%
Simplified98.9%
add-sqr-sqrt98.9%
sqrt-unprod98.9%
pow298.9%
unpow298.9%
unpow298.9%
frac-times98.9%
pow298.9%
tan-quot99.0%
Applied egg-rr99.0%
unpow299.0%
pow-sqr99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (<= eps -3.6e-5) (tan eps) (if (<= eps 0.00074) (+ eps (* eps (sqrt (pow (tan x) 4.0)))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -3.6e-5) {
tmp = tan(eps);
} else if (eps <= 0.00074) {
tmp = eps + (eps * sqrt(pow(tan(x), 4.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 <= (-3.6d-5)) then
tmp = tan(eps)
else if (eps <= 0.00074d0) then
tmp = eps + (eps * sqrt((tan(x) ** 4.0d0)))
else
tmp = tan(eps)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -3.6e-5) {
tmp = Math.tan(eps);
} else if (eps <= 0.00074) {
tmp = eps + (eps * Math.sqrt(Math.pow(Math.tan(x), 4.0)));
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -3.6e-5: tmp = math.tan(eps) elif eps <= 0.00074: tmp = eps + (eps * math.sqrt(math.pow(math.tan(x), 4.0))) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -3.6e-5) tmp = tan(eps); elseif (eps <= 0.00074) tmp = Float64(eps + Float64(eps * sqrt((tan(x) ^ 4.0)))); else tmp = tan(eps); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -3.6e-5) tmp = tan(eps); elseif (eps <= 0.00074) tmp = eps + (eps * sqrt((tan(x) ^ 4.0))); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -3.6e-5], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 0.00074], N[(eps + N[(eps * N[Sqrt[N[Power[N[Tan[x], $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-5}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 0.00074:\\
\;\;\;\;\varepsilon + \varepsilon \cdot \sqrt{{\tan x}^{4}}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -3.60000000000000009e-5 or 7.3999999999999999e-4 < eps Initial program 55.6%
Taylor expanded in x around 0 59.7%
tan-quot59.9%
expm1-log1p-u47.4%
expm1-udef47.1%
Applied egg-rr47.1%
expm1-def47.4%
expm1-log1p59.9%
Simplified59.9%
if -3.60000000000000009e-5 < eps < 7.3999999999999999e-4Initial program 30.1%
Taylor expanded in eps around 0 98.4%
cancel-sign-sub-inv98.4%
metadata-eval98.4%
*-lft-identity98.4%
distribute-lft-in98.4%
*-rgt-identity98.4%
Simplified98.4%
add-sqr-sqrt98.4%
sqrt-unprod98.4%
pow298.4%
unpow298.4%
unpow298.4%
frac-times98.4%
pow298.4%
tan-quot98.5%
Applied egg-rr98.5%
unpow298.5%
pow-sqr98.6%
metadata-eval98.6%
Simplified98.6%
Final simplification79.2%
(FPCore (x eps) :precision binary64 (if (<= eps -2.8e-6) (tan eps) (if (<= eps 0.00074) (+ eps (* eps (pow (tan x) 2.0))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.8e-6) {
tmp = tan(eps);
} else if (eps <= 0.00074) {
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.8d-6)) then
tmp = tan(eps)
else if (eps <= 0.00074d0) 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.8e-6) {
tmp = Math.tan(eps);
} else if (eps <= 0.00074) {
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.8e-6: tmp = math.tan(eps) elif eps <= 0.00074: 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.8e-6) tmp = tan(eps); elseif (eps <= 0.00074) 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.8e-6) tmp = tan(eps); elseif (eps <= 0.00074) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -2.8e-6], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 0.00074], 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.8 \cdot 10^{-6}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 0.00074:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -2.79999999999999987e-6 or 7.3999999999999999e-4 < eps Initial program 55.6%
Taylor expanded in x around 0 59.7%
tan-quot59.9%
expm1-log1p-u47.4%
expm1-udef47.1%
Applied egg-rr47.1%
expm1-def47.4%
expm1-log1p59.9%
Simplified59.9%
if -2.79999999999999987e-6 < eps < 7.3999999999999999e-4Initial program 30.1%
Taylor expanded in eps around 0 98.4%
cancel-sign-sub-inv98.4%
metadata-eval98.4%
*-lft-identity98.4%
distribute-lft-in98.4%
*-rgt-identity98.4%
Simplified98.4%
expm1-log1p-u98.4%
expm1-udef54.0%
unpow254.0%
unpow254.0%
frac-times54.0%
pow254.0%
tan-quot54.0%
Applied egg-rr54.0%
expm1-def98.5%
expm1-log1p98.5%
Simplified98.5%
Final simplification79.2%
(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 42.8%
Taylor expanded in x around 0 56.4%
tan-quot56.5%
expm1-log1p-u50.3%
expm1-udef27.1%
Applied egg-rr27.1%
expm1-def50.3%
expm1-log1p56.5%
Simplified56.5%
Final simplification56.5%
(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 42.8%
Taylor expanded in x around 0 56.4%
Taylor expanded in eps around 0 28.0%
Final simplification28.0%
(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 2023222
(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)))