
(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 8 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 eps) (tan x)))
(t_1 (* (tan eps) (tan x)))
(t_2 (- 1.0 t_1)))
(if (<= eps -5.8e-9)
(- (/ t_0 t_2) (tan x))
(if (<= eps 6.2e-9)
(+ eps (* (tan x) (/ t_1 t_2)))
(- (/ t_0 (- 1.0 (/ (* (tan x) (sin eps)) (cos eps)))) (tan x))))))
double code(double x, double eps) {
double t_0 = tan(eps) + tan(x);
double t_1 = tan(eps) * tan(x);
double t_2 = 1.0 - t_1;
double tmp;
if (eps <= -5.8e-9) {
tmp = (t_0 / t_2) - tan(x);
} else if (eps <= 6.2e-9) {
tmp = eps + (tan(x) * (t_1 / t_2));
} else {
tmp = (t_0 / (1.0 - ((tan(x) * sin(eps)) / cos(eps)))) - 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) :: t_2
real(8) :: tmp
t_0 = tan(eps) + tan(x)
t_1 = tan(eps) * tan(x)
t_2 = 1.0d0 - t_1
if (eps <= (-5.8d-9)) then
tmp = (t_0 / t_2) - tan(x)
else if (eps <= 6.2d-9) then
tmp = eps + (tan(x) * (t_1 / t_2))
else
tmp = (t_0 / (1.0d0 - ((tan(x) * sin(eps)) / cos(eps)))) - tan(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(eps) + Math.tan(x);
double t_1 = Math.tan(eps) * Math.tan(x);
double t_2 = 1.0 - t_1;
double tmp;
if (eps <= -5.8e-9) {
tmp = (t_0 / t_2) - Math.tan(x);
} else if (eps <= 6.2e-9) {
tmp = eps + (Math.tan(x) * (t_1 / t_2));
} else {
tmp = (t_0 / (1.0 - ((Math.tan(x) * Math.sin(eps)) / Math.cos(eps)))) - Math.tan(x);
}
return tmp;
}
def code(x, eps): t_0 = math.tan(eps) + math.tan(x) t_1 = math.tan(eps) * math.tan(x) t_2 = 1.0 - t_1 tmp = 0 if eps <= -5.8e-9: tmp = (t_0 / t_2) - math.tan(x) elif eps <= 6.2e-9: tmp = eps + (math.tan(x) * (t_1 / t_2)) else: tmp = (t_0 / (1.0 - ((math.tan(x) * math.sin(eps)) / math.cos(eps)))) - math.tan(x) return tmp
function code(x, eps) t_0 = Float64(tan(eps) + tan(x)) t_1 = Float64(tan(eps) * tan(x)) t_2 = Float64(1.0 - t_1) tmp = 0.0 if (eps <= -5.8e-9) tmp = Float64(Float64(t_0 / t_2) - tan(x)); elseif (eps <= 6.2e-9) tmp = Float64(eps + Float64(tan(x) * Float64(t_1 / t_2))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(Float64(tan(x) * sin(eps)) / cos(eps)))) - tan(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(eps) + tan(x); t_1 = tan(eps) * tan(x); t_2 = 1.0 - t_1; tmp = 0.0; if (eps <= -5.8e-9) tmp = (t_0 / t_2) - tan(x); elseif (eps <= 6.2e-9) tmp = eps + (tan(x) * (t_1 / t_2)); else tmp = (t_0 / (1.0 - ((tan(x) * sin(eps)) / cos(eps)))) - tan(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 - t$95$1), $MachinePrecision]}, If[LessEqual[eps, -5.8e-9], N[(N[(t$95$0 / t$95$2), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 6.2e-9], N[(eps + N[(N[Tan[x], $MachinePrecision] * N[(t$95$1 / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[(N[Tan[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \varepsilon + \tan x\\
t_1 := \tan \varepsilon \cdot \tan x\\
t_2 := 1 - t_1\\
\mathbf{if}\;\varepsilon \leq -5.8 \cdot 10^{-9}:\\
\;\;\;\;\frac{t_0}{t_2} - \tan x\\
\mathbf{elif}\;\varepsilon \leq 6.2 \cdot 10^{-9}:\\
\;\;\;\;\varepsilon + \tan x \cdot \frac{t_1}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} - \tan x\\
\end{array}
\end{array}
if eps < -5.79999999999999982e-9Initial program 65.7%
tan-sum99.7%
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.7%
if -5.79999999999999982e-9 < eps < 6.2000000000000001e-9Initial program 35.3%
tan-sum35.3%
div-inv35.3%
*-un-lft-identity35.3%
prod-diff35.3%
*-commutative35.3%
*-un-lft-identity35.3%
*-commutative35.3%
*-un-lft-identity35.3%
Applied egg-rr35.3%
+-commutative35.3%
fma-udef35.3%
associate-+r+35.3%
unsub-neg35.3%
Simplified35.3%
Taylor expanded in x around inf 35.3%
Simplified61.9%
tan-quot58.1%
clear-num55.3%
frac-sub51.5%
Applied egg-rr53.3%
associate-/r/53.3%
rgt-mult-inverse61.9%
associate--r-99.8%
metadata-eval99.8%
+-lft-identity99.8%
Simplified99.8%
Taylor expanded in eps around 0 99.8%
if 6.2000000000000001e-9 < eps Initial program 56.2%
tan-sum99.3%
div-inv99.2%
*-un-lft-identity99.2%
prod-diff99.2%
*-commutative99.2%
*-un-lft-identity99.2%
*-commutative99.2%
*-un-lft-identity99.2%
Applied egg-rr99.2%
+-commutative99.2%
fma-udef99.2%
associate-+r+99.2%
unsub-neg99.2%
Simplified99.3%
tan-quot99.4%
associate-*r/99.4%
Applied egg-rr99.4%
Final simplification99.7%
(FPCore (x eps) :precision binary64 (let* ((t_0 (* (tan eps) (tan x))) (t_1 (- 1.0 t_0))) (+ (/ (tan eps) t_1) (* (tan x) (/ t_0 t_1)))))
double code(double x, double eps) {
double t_0 = tan(eps) * tan(x);
double t_1 = 1.0 - t_0;
return (tan(eps) / t_1) + (tan(x) * (t_0 / t_1));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
t_0 = tan(eps) * tan(x)
t_1 = 1.0d0 - t_0
code = (tan(eps) / t_1) + (tan(x) * (t_0 / t_1))
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(eps) * Math.tan(x);
double t_1 = 1.0 - t_0;
return (Math.tan(eps) / t_1) + (Math.tan(x) * (t_0 / t_1));
}
def code(x, eps): t_0 = math.tan(eps) * math.tan(x) t_1 = 1.0 - t_0 return (math.tan(eps) / t_1) + (math.tan(x) * (t_0 / t_1))
function code(x, eps) t_0 = Float64(tan(eps) * tan(x)) t_1 = Float64(1.0 - t_0) return Float64(Float64(tan(eps) / t_1) + Float64(tan(x) * Float64(t_0 / t_1))) end
function tmp = code(x, eps) t_0 = tan(eps) * tan(x); t_1 = 1.0 - t_0; tmp = (tan(eps) / t_1) + (tan(x) * (t_0 / t_1)); end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, N[(N[(N[Tan[eps], $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[Tan[x], $MachinePrecision] * N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \varepsilon \cdot \tan x\\
t_1 := 1 - t_0\\
\frac{\tan \varepsilon}{t_1} + \tan x \cdot \frac{t_0}{t_1}
\end{array}
\end{array}
Initial program 48.4%
tan-sum67.9%
div-inv67.8%
*-un-lft-identity67.8%
prod-diff67.8%
*-commutative67.8%
*-un-lft-identity67.8%
*-commutative67.8%
*-un-lft-identity67.8%
Applied egg-rr67.8%
+-commutative67.8%
fma-udef67.8%
associate-+r+67.8%
unsub-neg67.8%
Simplified67.9%
Taylor expanded in x around inf 67.7%
Simplified80.8%
tan-quot78.9%
clear-num77.5%
frac-sub75.6%
Applied egg-rr76.5%
associate-/r/76.5%
rgt-mult-inverse80.8%
associate--r-99.5%
metadata-eval99.5%
+-lft-identity99.5%
Simplified99.5%
expm1-log1p-u92.4%
expm1-udef49.1%
associate-/r*49.1%
tan-quot49.2%
tan-quot49.2%
tan-quot49.2%
*-commutative49.2%
Applied egg-rr49.2%
expm1-def92.5%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (tan eps) (tan x))) (t_1 (- 1.0 t_0)))
(if (or (<= eps -7.3e-9) (not (<= eps 5.8e-9)))
(- (/ (+ (tan eps) (tan x)) t_1) (tan x))
(+ eps (* (tan x) (/ t_0 t_1))))))
double code(double x, double eps) {
double t_0 = tan(eps) * tan(x);
double t_1 = 1.0 - t_0;
double tmp;
if ((eps <= -7.3e-9) || !(eps <= 5.8e-9)) {
tmp = ((tan(eps) + tan(x)) / t_1) - tan(x);
} else {
tmp = eps + (tan(x) * (t_0 / t_1));
}
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(eps) * tan(x)
t_1 = 1.0d0 - t_0
if ((eps <= (-7.3d-9)) .or. (.not. (eps <= 5.8d-9))) then
tmp = ((tan(eps) + tan(x)) / t_1) - tan(x)
else
tmp = eps + (tan(x) * (t_0 / t_1))
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.tan(eps) * Math.tan(x);
double t_1 = 1.0 - t_0;
double tmp;
if ((eps <= -7.3e-9) || !(eps <= 5.8e-9)) {
tmp = ((Math.tan(eps) + Math.tan(x)) / t_1) - Math.tan(x);
} else {
tmp = eps + (Math.tan(x) * (t_0 / t_1));
}
return tmp;
}
def code(x, eps): t_0 = math.tan(eps) * math.tan(x) t_1 = 1.0 - t_0 tmp = 0 if (eps <= -7.3e-9) or not (eps <= 5.8e-9): tmp = ((math.tan(eps) + math.tan(x)) / t_1) - math.tan(x) else: tmp = eps + (math.tan(x) * (t_0 / t_1)) return tmp
function code(x, eps) t_0 = Float64(tan(eps) * tan(x)) t_1 = Float64(1.0 - t_0) tmp = 0.0 if ((eps <= -7.3e-9) || !(eps <= 5.8e-9)) tmp = Float64(Float64(Float64(tan(eps) + tan(x)) / t_1) - tan(x)); else tmp = Float64(eps + Float64(tan(x) * Float64(t_0 / t_1))); end return tmp end
function tmp_2 = code(x, eps) t_0 = tan(eps) * tan(x); t_1 = 1.0 - t_0; tmp = 0.0; if ((eps <= -7.3e-9) || ~((eps <= 5.8e-9))) tmp = ((tan(eps) + tan(x)) / t_1) - tan(x); else tmp = eps + (tan(x) * (t_0 / t_1)); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, If[Or[LessEqual[eps, -7.3e-9], N[Not[LessEqual[eps, 5.8e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], N[(eps + N[(N[Tan[x], $MachinePrecision] * N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \varepsilon \cdot \tan x\\
t_1 := 1 - t_0\\
\mathbf{if}\;\varepsilon \leq -7.3 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 5.8 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{t_1} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon + \tan x \cdot \frac{t_0}{t_1}\\
\end{array}
\end{array}
if eps < -7.30000000000000002e-9 or 5.79999999999999982e-9 < eps Initial program 61.1%
tan-sum99.5%
div-inv99.4%
*-un-lft-identity99.4%
prod-diff99.4%
*-commutative99.4%
*-un-lft-identity99.4%
*-commutative99.4%
*-un-lft-identity99.4%
Applied egg-rr99.4%
+-commutative99.4%
fma-udef99.4%
associate-+r+99.4%
unsub-neg99.4%
Simplified99.5%
if -7.30000000000000002e-9 < eps < 5.79999999999999982e-9Initial program 35.3%
tan-sum35.3%
div-inv35.3%
*-un-lft-identity35.3%
prod-diff35.3%
*-commutative35.3%
*-un-lft-identity35.3%
*-commutative35.3%
*-un-lft-identity35.3%
Applied egg-rr35.3%
+-commutative35.3%
fma-udef35.3%
associate-+r+35.3%
unsub-neg35.3%
Simplified35.3%
Taylor expanded in x around inf 35.3%
Simplified61.9%
tan-quot58.1%
clear-num55.3%
frac-sub51.5%
Applied egg-rr53.3%
associate-/r/53.3%
rgt-mult-inverse61.9%
associate--r-99.8%
metadata-eval99.8%
+-lft-identity99.8%
Simplified99.8%
Taylor expanded in eps around 0 99.8%
Final simplification99.7%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.6e-9) (not (<= eps 3.3e-9))) (- (/ (+ (tan eps) (tan x)) (- 1.0 (* (tan eps) (tan x)))) (tan x)) (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.6e-9) || !(eps <= 3.3e-9)) {
tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - tan(x);
} else {
tmp = eps * (1.0 + (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) :: tmp
if ((eps <= (-3.6d-9)) .or. (.not. (eps <= 3.3d-9))) then
tmp = ((tan(eps) + tan(x)) / (1.0d0 - (tan(eps) * tan(x)))) - tan(x)
else
tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.6e-9) || !(eps <= 3.3e-9)) {
tmp = ((Math.tan(eps) + Math.tan(x)) / (1.0 - (Math.tan(eps) * Math.tan(x)))) - Math.tan(x);
} else {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.6e-9) or not (eps <= 3.3e-9): tmp = ((math.tan(eps) + math.tan(x)) / (1.0 - (math.tan(eps) * math.tan(x)))) - math.tan(x) else: tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.6e-9) || !(eps <= 3.3e-9)) tmp = Float64(Float64(Float64(tan(eps) + tan(x)) / Float64(1.0 - Float64(tan(eps) * tan(x)))) - tan(x)); else tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.6e-9) || ~((eps <= 3.3e-9))) tmp = ((tan(eps) + tan(x)) / (1.0 - (tan(eps) * tan(x)))) - tan(x); else tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.6e-9], N[Not[LessEqual[eps, 3.3e-9]], $MachinePrecision]], N[(N[(N[(N[Tan[eps], $MachinePrecision] + N[Tan[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[eps], $MachinePrecision] * N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.6 \cdot 10^{-9} \lor \neg \left(\varepsilon \leq 3.3 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \tan \varepsilon \cdot \tan x} - \tan x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -3.6e-9 or 3.30000000000000018e-9 < eps Initial program 61.1%
tan-sum99.5%
div-inv99.4%
*-un-lft-identity99.4%
prod-diff99.4%
*-commutative99.4%
*-un-lft-identity99.4%
*-commutative99.4%
*-un-lft-identity99.4%
Applied egg-rr99.4%
+-commutative99.4%
fma-udef99.4%
associate-+r+99.4%
unsub-neg99.4%
Simplified99.5%
if -3.6e-9 < eps < 3.30000000000000018e-9Initial program 35.3%
Taylor expanded in eps around 0 99.7%
cancel-sign-sub-inv99.7%
metadata-eval99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(if (<= eps -5e-6)
(- (log1p (expm1 (/ (sin eps) (cos eps)))) (tan x))
(if (<= eps 0.13)
(* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))
(tan eps))))
double code(double x, double eps) {
double tmp;
if (eps <= -5e-6) {
tmp = log1p(expm1((sin(eps) / cos(eps)))) - tan(x);
} else if (eps <= 0.13) {
tmp = eps * (1.0 + (pow(sin(x), 2.0) / pow(cos(x), 2.0)));
} else {
tmp = tan(eps);
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if (eps <= -5e-6) {
tmp = Math.log1p(Math.expm1((Math.sin(eps) / Math.cos(eps)))) - Math.tan(x);
} else if (eps <= 0.13) {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
} else {
tmp = Math.tan(eps);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -5e-6: tmp = math.log1p(math.expm1((math.sin(eps) / math.cos(eps)))) - math.tan(x) elif eps <= 0.13: tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) else: tmp = math.tan(eps) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -5e-6) tmp = Float64(log1p(expm1(Float64(sin(eps) / cos(eps)))) - tan(x)); elseif (eps <= 0.13) tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); else tmp = tan(eps); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -5e-6], N[(N[Log[1 + N[(Exp[N[(N[Sin[eps], $MachinePrecision] / N[Cos[eps], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision] - N[Tan[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.13], 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[Tan[eps], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sin \varepsilon}{\cos \varepsilon}\right)\right) - \tan x\\
\mathbf{elif}\;\varepsilon \leq 0.13:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\tan \varepsilon\\
\end{array}
\end{array}
if eps < -5.00000000000000041e-6Initial program 65.7%
log1p-expm1-u65.7%
Applied egg-rr65.7%
Taylor expanded in x around 0 68.0%
Simplified68.5%
if -5.00000000000000041e-6 < eps < 0.13Initial program 35.5%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
if 0.13 < eps Initial program 56.4%
Taylor expanded in x around 0 59.3%
tan-quot59.6%
expm1-log1p-u47.8%
expm1-udef47.6%
Applied egg-rr47.6%
Simplified59.6%
Final simplification81.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -1.7e-6) (not (<= eps 0.13))) (tan eps) (* eps (+ 1.0 (/ (pow (sin x) 2.0) (pow (cos x) 2.0))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -1.7e-6) || !(eps <= 0.13)) {
tmp = tan(eps);
} else {
tmp = eps * (1.0 + (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) :: tmp
if ((eps <= (-1.7d-6)) .or. (.not. (eps <= 0.13d0))) then
tmp = tan(eps)
else
tmp = eps * (1.0d0 + ((sin(x) ** 2.0d0) / (cos(x) ** 2.0d0)))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -1.7e-6) || !(eps <= 0.13)) {
tmp = Math.tan(eps);
} else {
tmp = eps * (1.0 + (Math.pow(Math.sin(x), 2.0) / Math.pow(Math.cos(x), 2.0)));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -1.7e-6) or not (eps <= 0.13): tmp = math.tan(eps) else: tmp = eps * (1.0 + (math.pow(math.sin(x), 2.0) / math.pow(math.cos(x), 2.0))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -1.7e-6) || !(eps <= 0.13)) tmp = tan(eps); else tmp = Float64(eps * Float64(1.0 + Float64((sin(x) ^ 2.0) / (cos(x) ^ 2.0)))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -1.7e-6) || ~((eps <= 0.13))) tmp = tan(eps); else tmp = eps * (1.0 + ((sin(x) ^ 2.0) / (cos(x) ^ 2.0))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -1.7e-6], N[Not[LessEqual[eps, 0.13]], $MachinePrecision]], N[Tan[eps], $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.7 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 0.13\right):\\
\;\;\;\;\tan \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(1 + \frac{{\sin x}^{2}}{{\cos x}^{2}}\right)\\
\end{array}
\end{array}
if eps < -1.70000000000000003e-6 or 0.13 < eps Initial program 61.3%
Taylor expanded in x around 0 63.7%
tan-quot64.0%
expm1-log1p-u50.5%
expm1-udef50.3%
Applied egg-rr50.3%
Simplified64.0%
if -1.70000000000000003e-6 < eps < 0.13Initial program 35.5%
Taylor expanded in eps around 0 98.7%
cancel-sign-sub-inv98.7%
metadata-eval98.7%
*-lft-identity98.7%
Simplified98.7%
Final simplification81.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 48.4%
Taylor expanded in x around 0 62.5%
tan-quot62.7%
expm1-log1p-u55.9%
expm1-udef28.1%
Applied egg-rr28.1%
Simplified62.7%
Final simplification62.7%
(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 48.4%
Taylor expanded in x around 0 62.5%
Taylor expanded in eps around 0 32.5%
Final simplification32.5%
(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 2024014
(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)))