
(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 (/ (pow (sin x) 4.0) (pow (cos x) 4.0)))
(t_1 (pow (sin x) 2.0))
(t_2 (/ (sin eps) (cos eps)))
(t_3 (/ (* (sin x) -0.3333333333333333) (cos x)))
(t_4 (/ (sin x) (/ (cos x) t_3)))
(t_5 (+ (tan x) (tan eps)))
(t_6 (pow (cos x) 2.0)))
(if (<= eps -0.0305)
(fma t_5 (/ 1.0 (- 1.0 (* (tan x) (tan eps)))) (- (tan x)))
(if (<= eps 2.45e-6)
(+
(/ t_2 (- 1.0 (* t_2 (/ (sin x) (cos x)))))
(+
(fma
(- (pow eps 4.0))
(+ (/ t_1 (/ t_6 t_3)) (/ (sin x) (/ (cos x) (- t_4 t_0))))
(/ eps (/ t_6 t_1)))
(+
(/ (* eps eps) (/ (pow (cos x) 3.0) (pow (sin x) 3.0)))
(* (- t_0 t_4) (pow eps 3.0)))))
(-
(/ t_5 (- 1.0 (/ (* (sin eps) (sin x)) (* (cos eps) (cos x)))))
(tan x))))))
double code(double x, double eps) {
double t_0 = pow(sin(x), 4.0) / pow(cos(x), 4.0);
double t_1 = pow(sin(x), 2.0);
double t_2 = sin(eps) / cos(eps);
double t_3 = (sin(x) * -0.3333333333333333) / cos(x);
double t_4 = sin(x) / (cos(x) / t_3);
double t_5 = tan(x) + tan(eps);
double t_6 = pow(cos(x), 2.0);
double tmp;
if (eps <= -0.0305) {
tmp = fma(t_5, (1.0 / (1.0 - (tan(x) * tan(eps)))), -tan(x));
} else if (eps <= 2.45e-6) {
tmp = (t_2 / (1.0 - (t_2 * (sin(x) / cos(x))))) + (fma(-pow(eps, 4.0), ((t_1 / (t_6 / t_3)) + (sin(x) / (cos(x) / (t_4 - t_0)))), (eps / (t_6 / t_1))) + (((eps * eps) / (pow(cos(x), 3.0) / pow(sin(x), 3.0))) + ((t_0 - t_4) * pow(eps, 3.0))));
} else {
tmp = (t_5 / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - tan(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64((sin(x) ^ 4.0) / (cos(x) ^ 4.0)) t_1 = sin(x) ^ 2.0 t_2 = Float64(sin(eps) / cos(eps)) t_3 = Float64(Float64(sin(x) * -0.3333333333333333) / cos(x)) t_4 = Float64(sin(x) / Float64(cos(x) / t_3)) t_5 = Float64(tan(x) + tan(eps)) t_6 = cos(x) ^ 2.0 tmp = 0.0 if (eps <= -0.0305) tmp = fma(t_5, Float64(1.0 / Float64(1.0 - Float64(tan(x) * tan(eps)))), Float64(-tan(x))); elseif (eps <= 2.45e-6) tmp = Float64(Float64(t_2 / Float64(1.0 - Float64(t_2 * Float64(sin(x) / cos(x))))) + Float64(fma(Float64(-(eps ^ 4.0)), Float64(Float64(t_1 / Float64(t_6 / t_3)) + Float64(sin(x) / Float64(cos(x) / Float64(t_4 - t_0)))), Float64(eps / Float64(t_6 / t_1))) + Float64(Float64(Float64(eps * eps) / Float64((cos(x) ^ 3.0) / (sin(x) ^ 3.0))) + Float64(Float64(t_0 - t_4) * (eps ^ 3.0))))); else tmp = Float64(Float64(t_5 / Float64(1.0 - Float64(Float64(sin(eps) * sin(x)) / Float64(cos(eps) * cos(x))))) - tan(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[Sin[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[N[Cos[x], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[Sin[x], $MachinePrecision] * -0.3333333333333333), $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[x], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[eps, -0.0305], N[(t$95$5 * N[(1.0 / N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + (-N[Tan[x], $MachinePrecision])), $MachinePrecision], If[LessEqual[eps, 2.45e-6], N[(N[(t$95$2 / N[(1.0 - N[(t$95$2 * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[((-N[Power[eps, 4.0], $MachinePrecision]) * N[(N[(t$95$1 / N[(t$95$6 / t$95$3), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] / N[(t$95$4 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(eps / N[(t$95$6 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(eps * eps), $MachinePrecision] / N[(N[Power[N[Cos[x], $MachinePrecision], 3.0], $MachinePrecision] / N[Power[N[Sin[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$0 - t$95$4), $MachinePrecision] * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$5 / N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{\sin x}^{4}}{{\cos x}^{4}}\\
t_1 := {\sin x}^{2}\\
t_2 := \frac{\sin \varepsilon}{\cos \varepsilon}\\
t_3 := \frac{\sin x \cdot -0.3333333333333333}{\cos x}\\
t_4 := \frac{\sin x}{\frac{\cos x}{t_3}}\\
t_5 := \tan x + \tan \varepsilon\\
t_6 := {\cos x}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.0305:\\
\;\;\;\;\mathsf{fma}\left(t_5, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)\\
\mathbf{elif}\;\varepsilon \leq 2.45 \cdot 10^{-6}:\\
\;\;\;\;\frac{t_2}{1 - t_2 \cdot \frac{\sin x}{\cos x}} + \left(\mathsf{fma}\left(-{\varepsilon}^{4}, \frac{t_1}{\frac{t_6}{t_3}} + \frac{\sin x}{\frac{\cos x}{t_4 - t_0}}, \frac{\varepsilon}{\frac{t_6}{t_1}}\right) + \left(\frac{\varepsilon \cdot \varepsilon}{\frac{{\cos x}^{3}}{{\sin x}^{3}}} + \left(t_0 - t_4\right) \cdot {\varepsilon}^{3}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_5}{1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \tan x\\
\end{array}
\end{array}
if eps < -0.030499999999999999Initial program 57.7%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
if -0.030499999999999999 < eps < 2.44999999999999984e-6Initial program 28.8%
tan-sum30.4%
div-inv30.3%
fma-neg30.3%
Applied egg-rr30.3%
fma-neg30.3%
associate-*r/30.4%
*-rgt-identity30.4%
Simplified30.4%
Taylor expanded in x around inf 30.3%
associate--l+58.4%
associate-/r*58.4%
*-commutative58.4%
times-frac58.4%
Simplified58.4%
Taylor expanded in eps around 0 99.7%
Simplified99.8%
if 2.44999999999999984e-6 < eps Initial program 56.0%
tan-sum99.5%
div-inv99.5%
fma-neg99.5%
Applied egg-rr99.5%
fma-neg99.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Taylor expanded in x around inf 99.6%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -3.8e-7) (not (<= eps 2.75e-7)))
(-
(/
(+ (tan x) (tan eps))
(- 1.0 (/ (* (sin eps) (sin x)) (* (cos eps) (cos x)))))
(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.8e-7) || !(eps <= 2.75e-7)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - 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.8d-7)) .or. (.not. (eps <= 2.75d-7))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - 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.8e-7) || !(eps <= 2.75e-7)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - ((Math.sin(eps) * Math.sin(x)) / (Math.cos(eps) * Math.cos(x))))) - 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.8e-7) or not (eps <= 2.75e-7): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - ((math.sin(eps) * math.sin(x)) / (math.cos(eps) * math.cos(x))))) - 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.8e-7) || !(eps <= 2.75e-7)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(Float64(sin(eps) * sin(x)) / Float64(cos(eps) * cos(x))))) - 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.8e-7) || ~((eps <= 2.75e-7))) tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - 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.8e-7], N[Not[LessEqual[eps, 2.75e-7]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $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.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.75 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \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.80000000000000015e-7 or 2.7500000000000001e-7 < eps Initial program 56.7%
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 99.5%
if -3.80000000000000015e-7 < eps < 2.7500000000000001e-7Initial program 28.5%
tan-sum29.3%
div-inv29.3%
fma-neg29.4%
Applied egg-rr29.4%
fma-neg29.3%
associate-*r/29.3%
*-rgt-identity29.3%
Simplified29.3%
Taylor expanded in eps around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.7%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (sin eps) (cos eps))))
(if (or (<= eps -4.9e-9) (not (<= eps 5.4e-9)))
(-
(/
(+ (tan x) (tan eps))
(- 1.0 (/ (* (sin eps) (sin x)) (* (cos eps) (cos x)))))
(tan x))
(+
(/ t_0 (- 1.0 (* t_0 (/ (sin x) (cos x)))))
(/ (* 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 <= -4.9e-9) || !(eps <= 5.4e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - tan(x);
} else {
tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + ((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 <= (-4.9d-9)) .or. (.not. (eps <= 5.4d-9))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - tan(x)
else
tmp = (t_0 / (1.0d0 - (t_0 * (sin(x) / cos(x))))) + ((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 <= -4.9e-9) || !(eps <= 5.4e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - ((Math.sin(eps) * Math.sin(x)) / (Math.cos(eps) * Math.cos(x))))) - Math.tan(x);
} else {
tmp = (t_0 / (1.0 - (t_0 * (Math.sin(x) / Math.cos(x))))) + ((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 <= -4.9e-9) or not (eps <= 5.4e-9): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - ((math.sin(eps) * math.sin(x)) / (math.cos(eps) * math.cos(x))))) - math.tan(x) else: tmp = (t_0 / (1.0 - (t_0 * (math.sin(x) / math.cos(x))))) + ((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 <= -4.9e-9) || !(eps <= 5.4e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(Float64(sin(eps) * sin(x)) / Float64(cos(eps) * cos(x))))) - tan(x)); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(t_0 * Float64(sin(x) / cos(x))))) + 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 <= -4.9e-9) || ~((eps <= 5.4e-9))) tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - tan(x); else tmp = (t_0 / (1.0 - (t_0 * (sin(x) / cos(x))))) + ((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, -4.9e-9], N[Not[LessEqual[eps, 5.4e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(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 -4.9 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.4 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - t_0 \cdot \frac{\sin x}{\cos x}} + \frac{\varepsilon \cdot {\sin x}^{2}}{{\cos x}^{2}}\\
\end{array}
\end{array}
if eps < -4.90000000000000004e-9 or 5.4000000000000004e-9 < eps Initial program 56.7%
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 99.5%
if -4.90000000000000004e-9 < eps < 5.4000000000000004e-9Initial program 28.5%
tan-sum29.3%
div-inv29.3%
fma-neg29.4%
Applied egg-rr29.4%
fma-neg29.3%
associate-*r/29.3%
*-rgt-identity29.3%
Simplified29.3%
Taylor expanded in x around inf 29.3%
associate--l+57.9%
associate-/r*57.9%
*-commutative57.9%
times-frac57.9%
Simplified57.9%
Taylor expanded in eps around 0 99.4%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -3.15e-9) (not (<= eps 3.15e-9)))
(-
(/
(+ (tan x) (tan eps))
(- 1.0 (/ (* (sin eps) (sin x)) (* (cos eps) (cos x)))))
(tan x))
(+ eps (* eps (pow (tan x) 2.0)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.15e-9) || !(eps <= 3.15e-9)) {
tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(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.15d-9)) .or. (.not. (eps <= 3.15d-9))) then
tmp = ((tan(x) + tan(eps)) / (1.0d0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(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.15e-9) || !(eps <= 3.15e-9)) {
tmp = ((Math.tan(x) + Math.tan(eps)) / (1.0 - ((Math.sin(eps) * Math.sin(x)) / (Math.cos(eps) * Math.cos(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.15e-9) or not (eps <= 3.15e-9): tmp = ((math.tan(x) + math.tan(eps)) / (1.0 - ((math.sin(eps) * math.sin(x)) / (math.cos(eps) * math.cos(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.15e-9) || !(eps <= 3.15e-9)) tmp = Float64(Float64(Float64(tan(x) + tan(eps)) / Float64(1.0 - Float64(Float64(sin(eps) * sin(x)) / Float64(cos(eps) * cos(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.15e-9) || ~((eps <= 3.15e-9))) tmp = ((tan(x) + tan(eps)) / (1.0 - ((sin(eps) * sin(x)) / (cos(eps) * cos(x))))) - tan(x); else tmp = eps + (eps * (tan(x) ^ 2.0)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.15e-9], N[Not[LessEqual[eps, 3.15e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[x], $MachinePrecision] + N[Tan[eps], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $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.15 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.15 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin \varepsilon \cdot \sin x}{\cos \varepsilon \cdot \cos x}} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\end{array}
\end{array}
if eps < -3.1500000000000001e-9 or 3.1500000000000001e-9 < eps Initial program 56.7%
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 99.5%
if -3.1500000000000001e-9 < eps < 3.1500000000000001e-9Initial program 28.5%
Taylor expanded in eps around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
distribute-lft-in99.4%
*-rgt-identity99.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef57.9%
unpow257.9%
unpow257.9%
frac-times57.9%
tan-quot57.9%
tan-quot57.9%
pow257.9%
Applied egg-rr57.9%
expm1-def99.4%
expm1-log1p99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.4e-9) (not (<= eps 4.2e-9))) (- (/ (+ (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.4e-9) || !(eps <= 4.2e-9)) {
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.4d-9)) .or. (.not. (eps <= 4.2d-9))) 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.4e-9) || !(eps <= 4.2e-9)) {
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.4e-9) or not (eps <= 4.2e-9): 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.4e-9) || !(eps <= 4.2e-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 * (tan(x) ^ 2.0))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.4e-9) || ~((eps <= 4.2e-9))) 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.4e-9], N[Not[LessEqual[eps, 4.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[(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.4 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 4.2 \cdot 10^{-9}\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.3999999999999998e-9 or 4.20000000000000039e-9 < eps Initial program 56.7%
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%
if -3.3999999999999998e-9 < eps < 4.20000000000000039e-9Initial program 28.5%
Taylor expanded in eps around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
distribute-lft-in99.4%
*-rgt-identity99.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef57.9%
unpow257.9%
unpow257.9%
frac-times57.9%
tan-quot57.9%
tan-quot57.9%
pow257.9%
Applied egg-rr57.9%
expm1-def99.4%
expm1-log1p99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= eps -5.8e-5) (tan eps) (if (<= eps 1.15e-6) (+ eps (* eps (pow (tan x) 2.0))) (tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -5.8e-5) {
tmp = tan(eps);
} else if (eps <= 1.15e-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 <= (-5.8d-5)) then
tmp = tan(eps)
else if (eps <= 1.15d-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 <= -5.8e-5) {
tmp = Math.tan(eps);
} else if (eps <= 1.15e-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 <= -5.8e-5: tmp = math.tan(eps) elif eps <= 1.15e-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 <= -5.8e-5) tmp = tan(eps); elseif (eps <= 1.15e-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 <= -5.8e-5) tmp = tan(eps); elseif (eps <= 1.15e-6) tmp = eps + (eps * (tan(x) ^ 2.0)); else tmp = tan(eps); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -5.8e-5], N[Tan[eps], $MachinePrecision], If[LessEqual[eps, 1.15e-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 -5.8 \cdot 10^{-5}:\\
\;\;\;\;\tan \varepsilon\\
\mathbf{elif}\;\varepsilon \leq 1.15 \cdot 10^{-6}:\\
\;\;\;\;\varepsilon + \varepsilon \cdot {\tan x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -5.8e-5 or 1.15e-6 < eps Initial program 57.1%
Taylor expanded in x around 0 60.3%
tan-quot60.5%
expm1-log1p-u44.9%
expm1-udef44.4%
Applied egg-rr44.4%
expm1-def44.9%
expm1-log1p60.5%
Simplified60.5%
if -5.8e-5 < eps < 1.15e-6Initial program 28.3%
Taylor expanded in eps around 0 98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
*-lft-identity98.8%
distribute-lft-in98.9%
*-rgt-identity98.9%
Simplified98.9%
expm1-log1p-u98.9%
expm1-udef57.8%
unpow257.8%
unpow257.8%
frac-times57.8%
tan-quot57.8%
tan-quot57.8%
pow257.8%
Applied egg-rr57.8%
expm1-def99.0%
expm1-log1p99.0%
Simplified99.0%
Final simplification79.3%
(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 43.0%
Taylor expanded in x around 0 58.7%
tan-quot58.8%
expm1-log1p-u50.8%
expm1-udef25.7%
Applied egg-rr25.7%
expm1-def50.8%
expm1-log1p58.8%
Simplified58.8%
Final simplification58.8%
(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 43.0%
tan-quot42.8%
clear-num42.7%
Applied egg-rr42.7%
add-cube-cbrt41.8%
pow341.8%
clear-num41.8%
quot-tan41.8%
Applied egg-rr41.8%
Taylor expanded in eps around 0 4.2%
pow-base-14.2%
*-rgt-identity4.2%
+-inverses4.2%
Simplified4.2%
Final simplification4.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 43.0%
Taylor expanded in x around 0 58.7%
Taylor expanded in eps around 0 29.9%
Final simplification29.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 2023243
(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)))