
(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 12 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) (cos x))))
(/
(*
eps
(+
(cos x)
(+
t_0
(*
(pow eps 2.0)
(+
(fma
0.3333333333333333
(cos x)
(*
(pow eps 2.0)
(- (* (cos x) 0.13333333333333333) (* -0.13333333333333333 t_0))))
(* 0.3333333333333333 t_0))))))
(* (cos x) (+ 1.0 (+ 1.0 (- -1.0 (* (tan x) (tan eps)))))))))
double code(double x, double eps) {
double t_0 = pow(sin(x), 2.0) / cos(x);
return (eps * (cos(x) + (t_0 + (pow(eps, 2.0) * (fma(0.3333333333333333, cos(x), (pow(eps, 2.0) * ((cos(x) * 0.13333333333333333) - (-0.13333333333333333 * t_0)))) + (0.3333333333333333 * t_0)))))) / (cos(x) * (1.0 + (1.0 + (-1.0 - (tan(x) * tan(eps))))));
}
function code(x, eps) t_0 = Float64((sin(x) ^ 2.0) / cos(x)) return Float64(Float64(eps * Float64(cos(x) + Float64(t_0 + Float64((eps ^ 2.0) * Float64(fma(0.3333333333333333, cos(x), Float64((eps ^ 2.0) * Float64(Float64(cos(x) * 0.13333333333333333) - Float64(-0.13333333333333333 * t_0)))) + Float64(0.3333333333333333 * t_0)))))) / Float64(cos(x) * Float64(1.0 + Float64(1.0 + Float64(-1.0 - Float64(tan(x) * tan(eps))))))) end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(t$95$0 + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[(0.3333333333333333 * N[Cos[x], $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[(N[Cos[x], $MachinePrecision] * 0.13333333333333333), $MachinePrecision] - N[(-0.13333333333333333 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 + N[(1.0 + N[(-1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{\sin x}^{2}}{\cos x}\\
\frac{\varepsilon \cdot \left(\cos x + \left(t\_0 + {\varepsilon}^{2} \cdot \left(\mathsf{fma}\left(0.3333333333333333, \cos x, {\varepsilon}^{2} \cdot \left(\cos x \cdot 0.13333333333333333 - -0.13333333333333333 \cdot t\_0\right)\right) + 0.3333333333333333 \cdot t\_0\right)\right)\right)}{\cos x \cdot \left(1 + \left(1 + \left(-1 - \tan x \cdot \tan \varepsilon\right)\right)\right)}
\end{array}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 99.7%
associate--l+99.7%
Simplified99.7%
expm1-log1p-u99.7%
expm1-undefine99.7%
log1p-undefine99.7%
add-exp-log99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin x) (tan x))))
(/
(*
eps
(+
(cos x)
(+
(/ (pow (sin x) 2.0) (cos x))
(*
(pow eps 2.0)
(fma
0.3333333333333333
t_0
(fma
0.3333333333333333
(cos x)
(* (pow eps 2.0) (* 0.13333333333333333 (+ (cos x) t_0)))))))))
(* (cos x) (- 1.0 (* (tan x) (tan eps)))))))
double code(double x, double eps) {
double t_0 = sin(x) * tan(x);
return (eps * (cos(x) + ((pow(sin(x), 2.0) / cos(x)) + (pow(eps, 2.0) * fma(0.3333333333333333, t_0, fma(0.3333333333333333, cos(x), (pow(eps, 2.0) * (0.13333333333333333 * (cos(x) + t_0))))))))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
function code(x, eps) t_0 = Float64(sin(x) * tan(x)) return Float64(Float64(eps * Float64(cos(x) + Float64(Float64((sin(x) ^ 2.0) / cos(x)) + Float64((eps ^ 2.0) * fma(0.3333333333333333, t_0, fma(0.3333333333333333, cos(x), Float64((eps ^ 2.0) * Float64(0.13333333333333333 * Float64(cos(x) + t_0))))))))) / Float64(cos(x) * Float64(1.0 - Float64(tan(x) * tan(eps))))) end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[x], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(0.3333333333333333 * t$95$0 + N[(0.3333333333333333 * N[Cos[x], $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(0.13333333333333333 * N[(N[Cos[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin x \cdot \tan x\\
\frac{\varepsilon \cdot \left(\cos x + \left(\frac{{\sin x}^{2}}{\cos x} + {\varepsilon}^{2} \cdot \mathsf{fma}\left(0.3333333333333333, t\_0, \mathsf{fma}\left(0.3333333333333333, \cos x, {\varepsilon}^{2} \cdot \left(0.13333333333333333 \cdot \left(\cos x + t\_0\right)\right)\right)\right)\right)\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}
\end{array}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 99.7%
associate--l+99.7%
Simplified99.7%
distribute-lft-in99.7%
Applied egg-rr99.7%
+-commutative99.7%
distribute-lft-in99.7%
fma-undefine99.7%
/-rgt-identity99.7%
fma-undefine99.7%
*-commutative99.7%
distribute-lft-out99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (pow (sin x) 2.0) (cos x))))
(/
(*
eps
(+
(cos x)
(+
t_0
(*
(pow eps 2.0)
(+
(* 0.3333333333333333 t_0)
(fma
0.3333333333333333
(cos x)
(* (pow eps 2.0) 0.13333333333333333)))))))
(* (cos x) (- 1.0 (* (tan x) (tan eps)))))))
double code(double x, double eps) {
double t_0 = pow(sin(x), 2.0) / cos(x);
return (eps * (cos(x) + (t_0 + (pow(eps, 2.0) * ((0.3333333333333333 * t_0) + fma(0.3333333333333333, cos(x), (pow(eps, 2.0) * 0.13333333333333333))))))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
function code(x, eps) t_0 = Float64((sin(x) ^ 2.0) / cos(x)) return Float64(Float64(eps * Float64(cos(x) + Float64(t_0 + Float64((eps ^ 2.0) * Float64(Float64(0.3333333333333333 * t_0) + fma(0.3333333333333333, cos(x), Float64((eps ^ 2.0) * 0.13333333333333333))))))) / Float64(cos(x) * Float64(1.0 - Float64(tan(x) * tan(eps))))) end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(t$95$0 + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(N[(0.3333333333333333 * t$95$0), $MachinePrecision] + N[(0.3333333333333333 * N[Cos[x], $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{\sin x}^{2}}{\cos x}\\
\frac{\varepsilon \cdot \left(\cos x + \left(t\_0 + {\varepsilon}^{2} \cdot \left(0.3333333333333333 \cdot t\_0 + \mathsf{fma}\left(0.3333333333333333, \cos x, {\varepsilon}^{2} \cdot 0.13333333333333333\right)\right)\right)\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}
\end{array}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in x around 0 99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (pow (sin x) 2.0) (cos x))))
(/
(*
eps
(+
(cos x)
(+ t_0 (* (pow eps 2.0) (* 0.3333333333333333 (+ (cos x) t_0))))))
(* (cos x) (- 1.0 (* (tan x) (tan eps)))))))
double code(double x, double eps) {
double t_0 = pow(sin(x), 2.0) / cos(x);
return (eps * (cos(x) + (t_0 + (pow(eps, 2.0) * (0.3333333333333333 * (cos(x) + t_0)))))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = (sin(x) ** 2.0d0) / cos(x)
code = (eps * (cos(x) + (t_0 + ((eps ** 2.0d0) * (0.3333333333333333d0 * (cos(x) + t_0)))))) / (cos(x) * (1.0d0 - (tan(x) * tan(eps))))
end function
public static double code(double x, double eps) {
double t_0 = Math.pow(Math.sin(x), 2.0) / Math.cos(x);
return (eps * (Math.cos(x) + (t_0 + (Math.pow(eps, 2.0) * (0.3333333333333333 * (Math.cos(x) + t_0)))))) / (Math.cos(x) * (1.0 - (Math.tan(x) * Math.tan(eps))));
}
def code(x, eps): t_0 = math.pow(math.sin(x), 2.0) / math.cos(x) return (eps * (math.cos(x) + (t_0 + (math.pow(eps, 2.0) * (0.3333333333333333 * (math.cos(x) + t_0)))))) / (math.cos(x) * (1.0 - (math.tan(x) * math.tan(eps))))
function code(x, eps) t_0 = Float64((sin(x) ^ 2.0) / cos(x)) return Float64(Float64(eps * Float64(cos(x) + Float64(t_0 + Float64((eps ^ 2.0) * Float64(0.3333333333333333 * Float64(cos(x) + t_0)))))) / Float64(cos(x) * Float64(1.0 - Float64(tan(x) * tan(eps))))) end
function tmp = code(x, eps) t_0 = (sin(x) ^ 2.0) / cos(x); tmp = (eps * (cos(x) + (t_0 + ((eps ^ 2.0) * (0.3333333333333333 * (cos(x) + t_0)))))) / (cos(x) * (1.0 - (tan(x) * tan(eps)))); end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]}, N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(t$95$0 + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(0.3333333333333333 * N[(N[Cos[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{{\sin x}^{2}}{\cos x}\\
\frac{\varepsilon \cdot \left(\cos x + \left(t\_0 + {\varepsilon}^{2} \cdot \left(0.3333333333333333 \cdot \left(\cos x + t\_0\right)\right)\right)\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}
\end{array}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in eps around 0 99.5%
distribute-lft-out99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(/
(*
eps
(+
(cos x)
(+
(/ (pow (sin x) 2.0) (cos x))
(*
(pow eps 2.0)
(+ 0.3333333333333333 (* (pow eps 2.0) 0.13333333333333333))))))
(* (cos x) (- 1.0 (* (tan x) (tan eps))))))
double code(double x, double eps) {
return (eps * (cos(x) + ((pow(sin(x), 2.0) / cos(x)) + (pow(eps, 2.0) * (0.3333333333333333 + (pow(eps, 2.0) * 0.13333333333333333)))))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * (cos(x) + (((sin(x) ** 2.0d0) / cos(x)) + ((eps ** 2.0d0) * (0.3333333333333333d0 + ((eps ** 2.0d0) * 0.13333333333333333d0)))))) / (cos(x) * (1.0d0 - (tan(x) * tan(eps))))
end function
public static double code(double x, double eps) {
return (eps * (Math.cos(x) + ((Math.pow(Math.sin(x), 2.0) / Math.cos(x)) + (Math.pow(eps, 2.0) * (0.3333333333333333 + (Math.pow(eps, 2.0) * 0.13333333333333333)))))) / (Math.cos(x) * (1.0 - (Math.tan(x) * Math.tan(eps))));
}
def code(x, eps): return (eps * (math.cos(x) + ((math.pow(math.sin(x), 2.0) / math.cos(x)) + (math.pow(eps, 2.0) * (0.3333333333333333 + (math.pow(eps, 2.0) * 0.13333333333333333)))))) / (math.cos(x) * (1.0 - (math.tan(x) * math.tan(eps))))
function code(x, eps) return Float64(Float64(eps * Float64(cos(x) + Float64(Float64((sin(x) ^ 2.0) / cos(x)) + Float64((eps ^ 2.0) * Float64(0.3333333333333333 + Float64((eps ^ 2.0) * 0.13333333333333333)))))) / Float64(cos(x) * Float64(1.0 - Float64(tan(x) * tan(eps))))) end
function tmp = code(x, eps) tmp = (eps * (cos(x) + (((sin(x) ^ 2.0) / cos(x)) + ((eps ^ 2.0) * (0.3333333333333333 + ((eps ^ 2.0) * 0.13333333333333333)))))) / (cos(x) * (1.0 - (tan(x) * tan(eps)))); end
code[x_, eps_] := N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Power[eps, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[eps, 2.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot \left(\cos x + \left(\frac{{\sin x}^{2}}{\cos x} + {\varepsilon}^{2} \cdot \left(0.3333333333333333 + {\varepsilon}^{2} \cdot 0.13333333333333333\right)\right)\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 99.7%
associate--l+99.7%
Simplified99.7%
Taylor expanded in x around 0 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x eps) :precision binary64 (/ (* eps (+ (cos x) (/ (pow (sin x) 2.0) (cos x)))) (* (cos x) (- 1.0 (* (tan x) (tan eps))))))
double code(double x, double eps) {
return (eps * (cos(x) + (pow(sin(x), 2.0) / cos(x)))) / (cos(x) * (1.0 - (tan(x) * tan(eps))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * (cos(x) + ((sin(x) ** 2.0d0) / cos(x)))) / (cos(x) * (1.0d0 - (tan(x) * tan(eps))))
end function
public static double code(double x, double eps) {
return (eps * (Math.cos(x) + (Math.pow(Math.sin(x), 2.0) / Math.cos(x)))) / (Math.cos(x) * (1.0 - (Math.tan(x) * Math.tan(eps))));
}
def code(x, eps): return (eps * (math.cos(x) + (math.pow(math.sin(x), 2.0) / math.cos(x)))) / (math.cos(x) * (1.0 - (math.tan(x) * math.tan(eps))))
function code(x, eps) return Float64(Float64(eps * Float64(cos(x) + Float64((sin(x) ^ 2.0) / cos(x)))) / Float64(cos(x) * Float64(1.0 - Float64(tan(x) * tan(eps))))) end
function tmp = code(x, eps) tmp = (eps * (cos(x) + ((sin(x) ^ 2.0) / cos(x)))) / (cos(x) * (1.0 - (tan(x) * tan(eps)))); end
code[x_, eps_] := N[(N[(eps * N[(N[Cos[x], $MachinePrecision] + N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(1.0 - N[(N[Tan[x], $MachinePrecision] * N[Tan[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot \left(\cos x + \frac{{\sin x}^{2}}{\cos x}\right)}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}
\end{array}
Initial program 62.4%
tan-sum63.0%
tan-quot63.0%
frac-sub63.0%
Applied egg-rr63.0%
Taylor expanded in eps around 0 98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
*-lft-identity98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (tan (+ eps x)) (tan x)))) (if (<= t_0 2e-14) eps (exp (log t_0)))))
double code(double x, double eps) {
double t_0 = tan((eps + x)) - tan(x);
double tmp;
if (t_0 <= 2e-14) {
tmp = eps;
} else {
tmp = exp(log(t_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 = tan((eps + x)) - tan(x)
if (t_0 <= 2d-14) then
tmp = eps
else
tmp = exp(log(t_0))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan((eps + x)) - Math.tan(x);
double tmp;
if (t_0 <= 2e-14) {
tmp = eps;
} else {
tmp = Math.exp(Math.log(t_0));
}
return tmp;
}
def code(x, eps): t_0 = math.tan((eps + x)) - math.tan(x) tmp = 0 if t_0 <= 2e-14: tmp = eps else: tmp = math.exp(math.log(t_0)) return tmp
function code(x, eps) t_0 = Float64(tan(Float64(eps + x)) - tan(x)) tmp = 0.0 if (t_0 <= 2e-14) tmp = eps; else tmp = exp(log(t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan((eps + x)) - tan(x); tmp = 0.0; if (t_0 <= 2e-14) tmp = eps; else tmp = exp(log(t_0)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-14], eps, N[Exp[N[Log[t$95$0], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(\varepsilon + x\right) - \tan x\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\varepsilon\\
\mathbf{else}:\\
\;\;\;\;e^{\log t\_0}\\
\end{array}
\end{array}
if (-.f64 (tan.f64 (+.f64 x eps)) (tan.f64 x)) < 2e-14Initial program 62.5%
Taylor expanded in x around 0 100.0%
Taylor expanded in eps around 0 100.0%
if 2e-14 < (-.f64 (tan.f64 (+.f64 x eps)) (tan.f64 x)) Initial program 61.8%
add-exp-log61.9%
Applied egg-rr61.9%
Final simplification97.7%
(FPCore (x eps) :precision binary64 (if (<= (- (tan (+ eps x)) (tan x)) 2e-14) eps (- (/ 1.0 (/ (cos (+ eps x)) (sin (+ eps x)))) (tan x))))
double code(double x, double eps) {
double tmp;
if ((tan((eps + x)) - tan(x)) <= 2e-14) {
tmp = eps;
} else {
tmp = (1.0 / (cos((eps + x)) / sin((eps + x)))) - tan(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((tan((eps + x)) - tan(x)) <= 2d-14) then
tmp = eps
else
tmp = (1.0d0 / (cos((eps + x)) / sin((eps + x)))) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.tan((eps + x)) - Math.tan(x)) <= 2e-14) {
tmp = eps;
} else {
tmp = (1.0 / (Math.cos((eps + x)) / Math.sin((eps + x)))) - Math.tan(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.tan((eps + x)) - math.tan(x)) <= 2e-14: tmp = eps else: tmp = (1.0 / (math.cos((eps + x)) / math.sin((eps + x)))) - math.tan(x) return tmp
function code(x, eps) tmp = 0.0 if (Float64(tan(Float64(eps + x)) - tan(x)) <= 2e-14) tmp = eps; else tmp = Float64(Float64(1.0 / Float64(cos(Float64(eps + x)) / sin(Float64(eps + x)))) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((tan((eps + x)) - tan(x)) <= 2e-14) tmp = eps; else tmp = (1.0 / (cos((eps + x)) / sin((eps + x)))) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], 2e-14], eps, N[(N[(1.0 / N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan \left(\varepsilon + x\right) - \tan x \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\varepsilon\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\cos \left(\varepsilon + x\right)}{\sin \left(\varepsilon + x\right)}} - \tan x\\
\end{array}
\end{array}
if (-.f64 (tan.f64 (+.f64 x eps)) (tan.f64 x)) < 2e-14Initial program 62.5%
Taylor expanded in x around 0 100.0%
Taylor expanded in eps around 0 100.0%
if 2e-14 < (-.f64 (tan.f64 (+.f64 x eps)) (tan.f64 x)) Initial program 61.8%
tan-quot61.8%
clear-num61.8%
Applied egg-rr61.8%
Final simplification97.7%
(FPCore (x eps) :precision binary64 (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0)))))
double code(double x, double eps) {
return eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end function
public static double code(double x, double eps) {
return eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
def code(x, eps): return eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0)))
function code(x, eps) return Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))) end
function tmp = code(x, eps) tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end
code[x_, eps_] := 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]
\begin{array}{l}
\\
\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)
\end{array}
Initial program 62.4%
Taylor expanded in eps around 0 97.6%
sub-neg97.6%
mul-1-neg97.6%
remove-double-neg97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (x eps) :precision binary64 (if (<= eps 2e-14) eps (- (tan (+ eps x)) (tan x))))
double code(double x, double eps) {
double tmp;
if (eps <= 2e-14) {
tmp = eps;
} else {
tmp = tan((eps + x)) - tan(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= 2d-14) then
tmp = eps
else
tmp = tan((eps + x)) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= 2e-14) {
tmp = eps;
} else {
tmp = Math.tan((eps + x)) - Math.tan(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 2e-14: tmp = eps else: tmp = math.tan((eps + x)) - math.tan(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= 2e-14) tmp = eps; else tmp = Float64(tan(Float64(eps + x)) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 2e-14) tmp = eps; else tmp = tan((eps + x)) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 2e-14], eps, N[(N[Tan[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 2 \cdot 10^{-14}:\\
\;\;\;\;\varepsilon\\
\mathbf{else}:\\
\;\;\;\;\tan \left(\varepsilon + x\right) - \tan x\\
\end{array}
\end{array}
if eps < 2e-14Initial program 62.5%
Taylor expanded in x around 0 100.0%
Taylor expanded in eps around 0 100.0%
if 2e-14 < eps Initial program 61.8%
Final simplification97.7%
(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 62.4%
Taylor expanded in x around 0 95.8%
tan-quot95.8%
*-un-lft-identity95.8%
Applied egg-rr95.8%
*-lft-identity95.8%
Simplified95.8%
Final simplification95.8%
(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 62.4%
Taylor expanded in x around 0 95.8%
Taylor expanded in eps around 0 95.8%
Final simplification95.8%
(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 2024053
(FPCore (x eps)
:name "2tan (problem 3.3.2)"
:precision binary64
:pre (and (and (and (<= -10000.0 x) (<= x 10000.0)) (< (* 1e-16 (fabs x)) eps)) (< eps (fabs x)))
:alt
(/ (sin eps) (* (cos x) (cos (+ x eps))))
(- (tan (+ x eps)) (tan x)))