
(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 (/ (sin eps) (* (cos x) (- (* (cos x) (cos eps)) (* (sin eps) (sin x))))))
double code(double x, double eps) {
return sin(eps) / (cos(x) * ((cos(x) * cos(eps)) - (sin(eps) * sin(x))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin(eps) / (cos(x) * ((cos(x) * cos(eps)) - (sin(eps) * sin(x))))
end function
public static double code(double x, double eps) {
return Math.sin(eps) / (Math.cos(x) * ((Math.cos(x) * Math.cos(eps)) - (Math.sin(eps) * Math.sin(x))));
}
def code(x, eps): return math.sin(eps) / (math.cos(x) * ((math.cos(x) * math.cos(eps)) - (math.sin(eps) * math.sin(x))))
function code(x, eps) return Float64(sin(eps) / Float64(cos(x) * Float64(Float64(cos(x) * cos(eps)) - Float64(sin(eps) * sin(x))))) end
function tmp = code(x, eps) tmp = sin(eps) / (cos(x) * ((cos(x) * cos(eps)) - (sin(eps) * sin(x)))); end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin \varepsilon}{\cos x \cdot \left(\cos x \cdot \cos \varepsilon - \sin \varepsilon \cdot \sin x\right)}
\end{array}
Initial program 60.9%
tan-quot60.9%
tan-quot60.9%
frac-sub60.9%
Applied egg-rr60.9%
Taylor expanded in x around 0 99.8%
cos-sum100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x eps) :precision binary64 (* (/ 1.0 (cos (+ eps x))) (/ (sin eps) (cos x))))
double code(double x, double eps) {
return (1.0 / cos((eps + x))) * (sin(eps) / cos(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (1.0d0 / cos((eps + x))) * (sin(eps) / cos(x))
end function
public static double code(double x, double eps) {
return (1.0 / Math.cos((eps + x))) * (Math.sin(eps) / Math.cos(x));
}
def code(x, eps): return (1.0 / math.cos((eps + x))) * (math.sin(eps) / math.cos(x))
function code(x, eps) return Float64(Float64(1.0 / cos(Float64(eps + x))) * Float64(sin(eps) / cos(x))) end
function tmp = code(x, eps) tmp = (1.0 / cos((eps + x))) * (sin(eps) / cos(x)); end
code[x_, eps_] := N[(N[(1.0 / N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[eps], $MachinePrecision] / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\cos \left(\varepsilon + x\right)} \cdot \frac{\sin \varepsilon}{\cos x}
\end{array}
Initial program 60.9%
tan-quot60.9%
tan-quot60.9%
frac-sub60.9%
Applied egg-rr60.9%
Taylor expanded in x around 0 99.8%
*-un-lft-identity99.8%
times-frac99.8%
+-commutative99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x eps) :precision binary64 (/ (sin eps) (* (cos x) (cos (+ eps x)))))
double code(double x, double eps) {
return sin(eps) / (cos(x) * cos((eps + x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin(eps) / (cos(x) * cos((eps + x)))
end function
public static double code(double x, double eps) {
return Math.sin(eps) / (Math.cos(x) * Math.cos((eps + x)));
}
def code(x, eps): return math.sin(eps) / (math.cos(x) * math.cos((eps + x)))
function code(x, eps) return Float64(sin(eps) / Float64(cos(x) * cos(Float64(eps + x)))) end
function tmp = code(x, eps) tmp = sin(eps) / (cos(x) * cos((eps + x))); end
code[x_, eps_] := N[(N[Sin[eps], $MachinePrecision] / N[(N[Cos[x], $MachinePrecision] * N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin \varepsilon}{\cos x \cdot \cos \left(\varepsilon + x\right)}
\end{array}
Initial program 60.9%
tan-quot60.9%
tan-quot60.9%
frac-sub60.9%
Applied egg-rr60.9%
Taylor expanded in x around 0 99.8%
Final simplification99.8%
(FPCore (x eps) :precision binary64 (* (/ 1.0 (cos (+ eps x))) (/ eps (cos x))))
double code(double x, double eps) {
return (1.0 / cos((eps + x))) * (eps / cos(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (1.0d0 / cos((eps + x))) * (eps / cos(x))
end function
public static double code(double x, double eps) {
return (1.0 / Math.cos((eps + x))) * (eps / Math.cos(x));
}
def code(x, eps): return (1.0 / math.cos((eps + x))) * (eps / math.cos(x))
function code(x, eps) return Float64(Float64(1.0 / cos(Float64(eps + x))) * Float64(eps / cos(x))) end
function tmp = code(x, eps) tmp = (1.0 / cos((eps + x))) * (eps / cos(x)); end
code[x_, eps_] := N[(N[(1.0 / N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(eps / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\cos \left(\varepsilon + x\right)} \cdot \frac{\varepsilon}{\cos x}
\end{array}
Initial program 60.9%
tan-quot60.9%
tan-quot60.9%
frac-sub60.9%
Applied egg-rr60.9%
Taylor expanded in x around 0 99.8%
*-un-lft-identity99.8%
times-frac99.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in eps around 0 99.1%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (/ (* eps 2.0) (+ 1.0 (cos (* x 2.0)))))
double code(double x, double eps) {
return (eps * 2.0) / (1.0 + cos((x * 2.0)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (eps * 2.0d0) / (1.0d0 + cos((x * 2.0d0)))
end function
public static double code(double x, double eps) {
return (eps * 2.0) / (1.0 + Math.cos((x * 2.0)));
}
def code(x, eps): return (eps * 2.0) / (1.0 + math.cos((x * 2.0)))
function code(x, eps) return Float64(Float64(eps * 2.0) / Float64(1.0 + cos(Float64(x * 2.0)))) end
function tmp = code(x, eps) tmp = (eps * 2.0) / (1.0 + cos((x * 2.0))); end
code[x_, eps_] := N[(N[(eps * 2.0), $MachinePrecision] / N[(1.0 + N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\varepsilon \cdot 2}{1 + \cos \left(x \cdot 2\right)}
\end{array}
Initial program 60.9%
tan-quot60.9%
tan-quot60.9%
frac-sub60.9%
Applied egg-rr60.9%
Taylor expanded in x around 0 99.8%
cos-mult99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
associate--l+99.8%
Applied egg-rr99.8%
count-299.8%
+-inverses99.8%
Simplified99.8%
Taylor expanded in eps around 0 98.4%
associate-*r/98.4%
*-commutative98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x eps) :precision binary64 (+ eps (* eps (pow x 2.0))))
double code(double x, double eps) {
return eps + (eps * pow(x, 2.0));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps + (eps * (x ** 2.0d0))
end function
public static double code(double x, double eps) {
return eps + (eps * Math.pow(x, 2.0));
}
def code(x, eps): return eps + (eps * math.pow(x, 2.0))
function code(x, eps) return Float64(eps + Float64(eps * (x ^ 2.0))) end
function tmp = code(x, eps) tmp = eps + (eps * (x ^ 2.0)); end
code[x_, eps_] := N[(eps + N[(eps * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon + \varepsilon \cdot {x}^{2}
\end{array}
Initial program 60.9%
Taylor expanded in eps around 0 98.4%
sub-neg98.4%
mul-1-neg98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in x around 0 97.6%
*-commutative97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (x eps) :precision binary64 (* eps (fma x x 1.0)))
double code(double x, double eps) {
return eps * fma(x, x, 1.0);
}
function code(x, eps) return Float64(eps * fma(x, x, 1.0)) end
code[x_, eps_] := N[(eps * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \mathsf{fma}\left(x, x, 1\right)
\end{array}
Initial program 60.9%
Taylor expanded in eps around 0 98.4%
sub-neg98.4%
mul-1-neg98.4%
remove-double-neg98.4%
Simplified98.4%
Taylor expanded in x around 0 97.6%
*-commutative97.6%
Simplified97.6%
distribute-rgt1-in97.6%
unpow297.6%
fma-define97.6%
Applied egg-rr97.6%
Final simplification97.6%
(FPCore (x eps) :precision binary64 (tan eps))
double code(double x, double eps) {
return tan(eps);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = tan(eps)
end function
public static double code(double x, double eps) {
return Math.tan(eps);
}
def code(x, eps): return math.tan(eps)
function code(x, eps) return tan(eps) end
function tmp = code(x, eps) tmp = tan(eps); end
code[x_, eps_] := N[Tan[eps], $MachinePrecision]
\begin{array}{l}
\\
\tan \varepsilon
\end{array}
Initial program 60.9%
Taylor expanded in x around 0 97.3%
*-un-lft-identity97.3%
quot-tan97.3%
Applied egg-rr97.3%
*-lft-identity97.3%
Simplified97.3%
Final simplification97.3%
(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 60.9%
Taylor expanded in x around 0 97.3%
Taylor expanded in eps around 0 97.3%
Final simplification97.3%
(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 2024079
(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)))