
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
double code(double x, double eps) {
return cos((x + eps)) - cos(x);
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = cos((x + eps)) - cos(x)
end function
public static double code(double x, double eps) {
return Math.cos((x + eps)) - Math.cos(x);
}
def code(x, eps): return math.cos((x + eps)) - math.cos(x)
function code(x, eps) return Float64(cos(Float64(x + eps)) - cos(x)) end
function tmp = code(x, eps) tmp = cos((x + eps)) - cos(x); end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(x + \varepsilon\right) - \cos x
\end{array}
(FPCore (x eps)
:precision binary64
(if (<= eps -0.00015)
(- (* (cos x) (cos eps)) (fma (sin eps) (sin x) (cos x)))
(if (<= eps 0.000125)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* (sin eps) (sin x)))
(fma (+ (cos eps) -1.0) (cos x) (* (sin eps) (- (sin x)))))))
double code(double x, double eps) {
double tmp;
if (eps <= -0.00015) {
tmp = (cos(x) * cos(eps)) - fma(sin(eps), sin(x), cos(x));
} else if (eps <= 0.000125) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (sin(eps) * sin(x));
} else {
tmp = fma((cos(eps) + -1.0), cos(x), (sin(eps) * -sin(x)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -0.00015) tmp = Float64(Float64(cos(x) * cos(eps)) - fma(sin(eps), sin(x), cos(x))); elseif (eps <= 0.000125) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(sin(eps) * sin(x))); else tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(eps) * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -0.00015], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision] + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 0.000125], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00015:\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \mathsf{fma}\left(\sin \varepsilon, \sin x, \cos x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000125:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if eps < -1.49999999999999987e-4Initial program 48.9%
sub-neg48.9%
cos-sum98.7%
cancel-sign-sub-inv98.7%
associate-+l+98.7%
*-commutative98.7%
Applied egg-rr98.7%
+-commutative98.7%
distribute-rgt-neg-out98.7%
*-commutative98.7%
unsub-neg98.7%
associate-+r-98.6%
*-commutative98.6%
neg-mul-198.6%
distribute-rgt-out98.7%
*-commutative98.7%
Simplified98.7%
sub-neg98.7%
+-commutative98.7%
distribute-rgt-in98.6%
*-commutative98.6%
mul-1-neg98.6%
associate-+r+98.7%
+-commutative98.7%
sub-neg98.7%
*-commutative98.7%
sub-neg98.7%
*-commutative98.7%
associate--l-98.7%
sub-neg98.7%
*-commutative98.7%
Applied egg-rr98.8%
if -1.49999999999999987e-4 < eps < 1.25e-4Initial program 24.4%
sub-neg24.4%
cos-sum25.4%
cancel-sign-sub-inv25.4%
associate-+l+25.4%
*-commutative25.4%
Applied egg-rr25.4%
+-commutative25.4%
distribute-rgt-neg-out25.4%
*-commutative25.4%
unsub-neg25.4%
associate-+r-77.6%
*-commutative77.6%
neg-mul-177.6%
distribute-rgt-out77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in eps around 0 99.8%
if 1.25e-4 < eps Initial program 55.1%
sub-neg55.1%
cos-sum98.9%
cancel-sign-sub-inv98.9%
associate-+l+98.8%
*-commutative98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
unsub-neg98.8%
associate-+r-98.9%
*-commutative98.9%
neg-mul-198.9%
distribute-rgt-out99.1%
*-commutative99.1%
Simplified99.1%
*-commutative99.1%
fma-neg99.1%
*-commutative99.1%
distribute-lft-neg-in99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (- (/ (* (pow (sin eps) 2.0) (- (cos x))) (+ (cos eps) 1.0)) (* (sin eps) (sin x))))
double code(double x, double eps) {
return ((pow(sin(eps), 2.0) * -cos(x)) / (cos(eps) + 1.0)) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((sin(eps) ** 2.0d0) * -cos(x)) / (cos(eps) + 1.0d0)) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return ((Math.pow(Math.sin(eps), 2.0) * -Math.cos(x)) / (Math.cos(eps) + 1.0)) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return ((math.pow(math.sin(eps), 2.0) * -math.cos(x)) / (math.cos(eps) + 1.0)) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64(Float64((sin(eps) ^ 2.0) * Float64(-cos(x))) / Float64(cos(eps) + 1.0)) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = (((sin(eps) ^ 2.0) * -cos(x)) / (cos(eps) + 1.0)) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(N[(N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] * (-N[Cos[x], $MachinePrecision])), $MachinePrecision] / N[(N[Cos[eps], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\sin \varepsilon}^{2} \cdot \left(-\cos x\right)}{\cos \varepsilon + 1} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 38.6%
sub-neg38.6%
cos-sum63.3%
cancel-sign-sub-inv63.3%
associate-+l+63.2%
*-commutative63.2%
Applied egg-rr63.2%
+-commutative63.2%
distribute-rgt-neg-out63.2%
*-commutative63.2%
unsub-neg63.2%
associate-+r-88.5%
*-commutative88.5%
neg-mul-188.5%
distribute-rgt-out88.6%
*-commutative88.6%
Simplified88.6%
*-commutative88.6%
metadata-eval88.6%
sub-neg88.6%
flip--88.1%
metadata-eval88.1%
metadata-eval88.1%
associate-*l/88.1%
metadata-eval88.1%
sub-1-cos99.1%
pow299.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (- (* (cos x) (/ (pow (sin eps) 2.0) (- -1.0 (cos eps)))) (* (sin eps) (sin x))))
double code(double x, double eps) {
return (cos(x) * (pow(sin(eps), 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (cos(x) * ((sin(eps) ** 2.0d0) / ((-1.0d0) - cos(eps)))) - (sin(eps) * sin(x))
end function
public static double code(double x, double eps) {
return (Math.cos(x) * (Math.pow(Math.sin(eps), 2.0) / (-1.0 - Math.cos(eps)))) - (Math.sin(eps) * Math.sin(x));
}
def code(x, eps): return (math.cos(x) * (math.pow(math.sin(eps), 2.0) / (-1.0 - math.cos(eps)))) - (math.sin(eps) * math.sin(x))
function code(x, eps) return Float64(Float64(cos(x) * Float64((sin(eps) ^ 2.0) / Float64(-1.0 - cos(eps)))) - Float64(sin(eps) * sin(x))) end
function tmp = code(x, eps) tmp = (cos(x) * ((sin(eps) ^ 2.0) / (-1.0 - cos(eps)))) - (sin(eps) * sin(x)); end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Power[N[Sin[eps], $MachinePrecision], 2.0], $MachinePrecision] / N[(-1.0 - N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{{\sin \varepsilon}^{2}}{-1 - \cos \varepsilon} - \sin \varepsilon \cdot \sin x
\end{array}
Initial program 38.6%
sub-neg38.6%
cos-sum63.3%
cancel-sign-sub-inv63.3%
associate-+l+63.2%
*-commutative63.2%
Applied egg-rr63.2%
+-commutative63.2%
distribute-rgt-neg-out63.2%
*-commutative63.2%
unsub-neg63.2%
associate-+r-88.5%
*-commutative88.5%
neg-mul-188.5%
distribute-rgt-out88.6%
*-commutative88.6%
Simplified88.6%
metadata-eval88.6%
sub-neg88.6%
flip--88.1%
metadata-eval88.1%
metadata-eval88.1%
frac-2neg88.1%
metadata-eval88.1%
sub-1-cos99.0%
pow299.0%
Applied egg-rr99.0%
remove-double-neg99.0%
neg-sub099.0%
+-commutative99.0%
associate--r+99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000125) (not (<= eps 0.000125))) (fma (+ (cos eps) -1.0) (cos x) (* (sin eps) (- (sin x)))) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* (sin eps) (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000125) || !(eps <= 0.000125)) {
tmp = fma((cos(eps) + -1.0), cos(x), (sin(eps) * -sin(x)));
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (sin(eps) * sin(x));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((eps <= -0.000125) || !(eps <= 0.000125)) tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(eps) * Float64(-sin(x)))); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(sin(eps) * sin(x))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000125], N[Not[LessEqual[eps, 0.000125]], $MachinePrecision]], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000125 \lor \neg \left(\varepsilon \leq 0.000125\right):\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin \varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \sin \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -1.25e-4 or 1.25e-4 < eps Initial program 51.9%
sub-neg51.9%
cos-sum98.8%
cancel-sign-sub-inv98.8%
associate-+l+98.8%
*-commutative98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
unsub-neg98.8%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.9%
*-commutative98.9%
Simplified98.9%
*-commutative98.9%
fma-neg98.9%
*-commutative98.9%
distribute-lft-neg-in98.9%
*-commutative98.9%
Applied egg-rr98.9%
if -1.25e-4 < eps < 1.25e-4Initial program 24.4%
sub-neg24.4%
cos-sum25.4%
cancel-sign-sub-inv25.4%
associate-+l+25.4%
*-commutative25.4%
Applied egg-rr25.4%
+-commutative25.4%
distribute-rgt-neg-out25.4%
*-commutative25.4%
unsub-neg25.4%
associate-+r-77.6%
*-commutative77.6%
neg-mul-177.6%
distribute-rgt-out77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in eps around 0 99.8%
Final simplification99.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (sin eps) (sin x))))
(if (or (<= eps -0.000125) (not (<= eps 0.000125)))
(- (* (cos x) (+ (cos eps) -1.0)) t_0)
(- (* (cos x) (* -0.5 (pow eps 2.0))) t_0))))
double code(double x, double eps) {
double t_0 = sin(eps) * sin(x);
double tmp;
if ((eps <= -0.000125) || !(eps <= 0.000125)) {
tmp = (cos(x) * (cos(eps) + -1.0)) - t_0;
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - 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 = sin(eps) * sin(x)
if ((eps <= (-0.000125d0)) .or. (.not. (eps <= 0.000125d0))) then
tmp = (cos(x) * (cos(eps) + (-1.0d0))) - t_0
else
tmp = (cos(x) * ((-0.5d0) * (eps ** 2.0d0))) - t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin(eps) * Math.sin(x);
double tmp;
if ((eps <= -0.000125) || !(eps <= 0.000125)) {
tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - t_0;
} else {
tmp = (Math.cos(x) * (-0.5 * Math.pow(eps, 2.0))) - t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.sin(eps) * math.sin(x) tmp = 0 if (eps <= -0.000125) or not (eps <= 0.000125): tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - t_0 else: tmp = (math.cos(x) * (-0.5 * math.pow(eps, 2.0))) - t_0 return tmp
function code(x, eps) t_0 = Float64(sin(eps) * sin(x)) tmp = 0.0 if ((eps <= -0.000125) || !(eps <= 0.000125)) tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - t_0); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - t_0); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin(eps) * sin(x); tmp = 0.0; if ((eps <= -0.000125) || ~((eps <= 0.000125))) tmp = (cos(x) * (cos(eps) + -1.0)) - t_0; else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[eps, -0.000125], N[Not[LessEqual[eps, 0.000125]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \varepsilon \cdot \sin x\\
\mathbf{if}\;\varepsilon \leq -0.000125 \lor \neg \left(\varepsilon \leq 0.000125\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - t_0\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - t_0\\
\end{array}
\end{array}
if eps < -1.25e-4 or 1.25e-4 < eps Initial program 51.9%
sub-neg51.9%
cos-sum98.8%
cancel-sign-sub-inv98.8%
associate-+l+98.8%
*-commutative98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
unsub-neg98.8%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.9%
*-commutative98.9%
Simplified98.9%
if -1.25e-4 < eps < 1.25e-4Initial program 24.4%
sub-neg24.4%
cos-sum25.4%
cancel-sign-sub-inv25.4%
associate-+l+25.4%
*-commutative25.4%
Applied egg-rr25.4%
+-commutative25.4%
distribute-rgt-neg-out25.4%
*-commutative25.4%
unsub-neg25.4%
associate-+r-77.6%
*-commutative77.6%
neg-mul-177.6%
distribute-rgt-out77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in eps around 0 99.8%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3e-5) (not (<= eps 4.8e-5))) (- (* (cos x) (+ (cos eps) -1.0)) (* (sin eps) (sin x))) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3e-5) || !(eps <= 4.8e-5)) {
tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(eps) * sin(x));
} else {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-3d-5)) .or. (.not. (eps <= 4.8d-5))) then
tmp = (cos(x) * (cos(eps) + (-1.0d0))) - (sin(eps) * sin(x))
else
tmp = (cos(x) * ((-0.5d0) * (eps ** 2.0d0))) - (eps * sin(x))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3e-5) || !(eps <= 4.8e-5)) {
tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - (Math.sin(eps) * Math.sin(x));
} else {
tmp = (Math.cos(x) * (-0.5 * Math.pow(eps, 2.0))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3e-5) or not (eps <= 4.8e-5): tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - (math.sin(eps) * math.sin(x)) else: tmp = (math.cos(x) * (-0.5 * math.pow(eps, 2.0))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3e-5) || !(eps <= 4.8e-5)) tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - Float64(sin(eps) * sin(x))); else tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3e-5) || ~((eps <= 4.8e-5))) tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(eps) * sin(x)); else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3e-5], N[Not[LessEqual[eps, 4.8e-5]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 4.8 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -3.00000000000000008e-5 or 4.8000000000000001e-5 < eps Initial program 51.9%
sub-neg51.9%
cos-sum98.8%
cancel-sign-sub-inv98.8%
associate-+l+98.8%
*-commutative98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
unsub-neg98.8%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.9%
*-commutative98.9%
Simplified98.9%
if -3.00000000000000008e-5 < eps < 4.8000000000000001e-5Initial program 24.4%
Taylor expanded in eps around 0 99.7%
+-commutative99.7%
mul-1-neg99.7%
unsub-neg99.7%
associate-*r*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (* (sin (* 0.5 (+ eps (* 2.0 x)))) (* -2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return sin((0.5 * (eps + (2.0 * x)))) * (-2.0 * sin((eps * 0.5)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = sin((0.5d0 * (eps + (2.0d0 * x)))) * ((-2.0d0) * sin((eps * 0.5d0)))
end function
public static double code(double x, double eps) {
return Math.sin((0.5 * (eps + (2.0 * x)))) * (-2.0 * Math.sin((eps * 0.5)));
}
def code(x, eps): return math.sin((0.5 * (eps + (2.0 * x)))) * (-2.0 * math.sin((eps * 0.5)))
function code(x, eps) return Float64(sin(Float64(0.5 * Float64(eps + Float64(2.0 * x)))) * Float64(-2.0 * sin(Float64(eps * 0.5)))) end
function tmp = code(x, eps) tmp = sin((0.5 * (eps + (2.0 * x)))) * (-2.0 * sin((eps * 0.5))); end
code[x_, eps_] := N[(N[Sin[N[(0.5 * N[(eps + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(0.5 \cdot \left(\varepsilon + 2 \cdot x\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.6%
diff-cos48.8%
div-inv48.8%
+-commutative48.8%
associate--l+75.3%
*-un-lft-identity75.3%
*-un-lft-identity75.3%
distribute-rgt-out--75.3%
metadata-eval75.3%
metadata-eval75.3%
div-inv75.3%
+-commutative75.3%
associate-+l+75.3%
count-275.3%
*-commutative75.3%
metadata-eval75.3%
Applied egg-rr75.3%
associate-*r*75.3%
*-commutative75.3%
*-commutative75.3%
*-commutative75.3%
mul0-rgt75.3%
Simplified75.3%
Final simplification75.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -6.8e-6) (not (<= eps 4.3e-6))) (* (cos x) (+ (cos eps) -1.0)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -6.8e-6) || !(eps <= 4.3e-6)) {
tmp = cos(x) * (cos(eps) + -1.0);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-6.8d-6)) .or. (.not. (eps <= 4.3d-6))) then
tmp = cos(x) * (cos(eps) + (-1.0d0))
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -6.8e-6) || !(eps <= 4.3e-6)) {
tmp = Math.cos(x) * (Math.cos(eps) + -1.0);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -6.8e-6) or not (eps <= 4.3e-6): tmp = math.cos(x) * (math.cos(eps) + -1.0) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -6.8e-6) || !(eps <= 4.3e-6)) tmp = Float64(cos(x) * Float64(cos(eps) + -1.0)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -6.8e-6) || ~((eps <= 4.3e-6))) tmp = cos(x) * (cos(eps) + -1.0); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -6.8e-6], N[Not[LessEqual[eps, 4.3e-6]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -6.8 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 4.3 \cdot 10^{-6}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -6.80000000000000012e-6 or 4.30000000000000033e-6 < eps Initial program 51.9%
sub-neg51.9%
cos-sum98.8%
cancel-sign-sub-inv98.8%
associate-+l+98.8%
*-commutative98.8%
Applied egg-rr98.8%
+-commutative98.8%
distribute-rgt-neg-out98.8%
*-commutative98.8%
unsub-neg98.8%
associate-+r-98.8%
*-commutative98.8%
neg-mul-198.8%
distribute-rgt-out98.9%
*-commutative98.9%
Simplified98.9%
add-cube-cbrt98.4%
pow398.4%
Applied egg-rr98.4%
rem-cube-cbrt98.9%
*-commutative98.9%
sin-mult54.3%
sub-neg54.3%
add-sqr-sqrt17.9%
sqrt-unprod28.0%
sqr-neg28.0%
sqrt-unprod18.8%
add-sqr-sqrt53.6%
+-commutative53.6%
+-commutative53.6%
Applied egg-rr53.6%
+-inverses53.6%
metadata-eval53.6%
Simplified53.6%
if -6.80000000000000012e-6 < eps < 4.30000000000000033e-6Initial program 24.4%
Taylor expanded in eps around 0 77.5%
associate-*r*77.5%
mul-1-neg77.5%
Simplified77.5%
Final simplification65.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -9.5e-6) (not (<= eps 2.9e-7))) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -9.5e-6) || !(eps <= 2.9e-7)) {
tmp = cos(eps) - cos(x);
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-9.5d-6)) .or. (.not. (eps <= 2.9d-7))) then
tmp = cos(eps) - cos(x)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -9.5e-6) || !(eps <= 2.9e-7)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -9.5e-6) or not (eps <= 2.9e-7): tmp = math.cos(eps) - math.cos(x) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -9.5e-6) || !(eps <= 2.9e-7)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -9.5e-6) || ~((eps <= 2.9e-7))) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -9.5e-6], N[Not[LessEqual[eps, 2.9e-7]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -9.5 \cdot 10^{-6} \lor \neg \left(\varepsilon \leq 2.9 \cdot 10^{-7}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -9.5000000000000005e-6 or 2.8999999999999998e-7 < eps Initial program 51.9%
Taylor expanded in x around 0 53.3%
if -9.5000000000000005e-6 < eps < 2.8999999999999998e-7Initial program 24.4%
Taylor expanded in eps around 0 77.5%
associate-*r*77.5%
mul-1-neg77.5%
Simplified77.5%
Final simplification65.0%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.000125) (not (<= eps 1.95e-5))) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.000125) || !(eps <= 1.95e-5)) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * -sin(x);
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.000125d0)) .or. (.not. (eps <= 1.95d-5))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.000125) || !(eps <= 1.95e-5)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.000125) or not (eps <= 1.95e-5): tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.000125) || !(eps <= 1.95e-5)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.000125) || ~((eps <= 1.95e-5))) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.000125], N[Not[LessEqual[eps, 1.95e-5]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.000125 \lor \neg \left(\varepsilon \leq 1.95 \cdot 10^{-5}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -1.25e-4 or 1.95e-5 < eps Initial program 51.9%
Taylor expanded in x around 0 52.3%
if -1.25e-4 < eps < 1.95e-5Initial program 24.4%
Taylor expanded in eps around 0 77.5%
associate-*r*77.5%
mul-1-neg77.5%
Simplified77.5%
Final simplification64.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -7.5e-11) (not (<= eps 1.02e-8))) (+ (cos eps) -1.0) (* x (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -7.5e-11) || !(eps <= 1.02e-8)) {
tmp = cos(eps) + -1.0;
} else {
tmp = x * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-7.5d-11)) .or. (.not. (eps <= 1.02d-8))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = x * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -7.5e-11) || !(eps <= 1.02e-8)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = x * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -7.5e-11) or not (eps <= 1.02e-8): tmp = math.cos(eps) + -1.0 else: tmp = x * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -7.5e-11) || !(eps <= 1.02e-8)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(x * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -7.5e-11) || ~((eps <= 1.02e-8))) tmp = cos(eps) + -1.0; else tmp = x * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -7.5e-11], N[Not[LessEqual[eps, 1.02e-8]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(x * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -7.5 \cdot 10^{-11} \lor \neg \left(\varepsilon \leq 1.02 \cdot 10^{-8}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -7.5e-11 or 1.02000000000000003e-8 < eps Initial program 51.5%
Taylor expanded in x around 0 52.0%
if -7.5e-11 < eps < 1.02000000000000003e-8Initial program 24.5%
Taylor expanded in eps around 0 77.7%
associate-*r*77.7%
mul-1-neg77.7%
Simplified77.7%
Taylor expanded in x around 0 35.2%
associate-*r*35.2%
mul-1-neg35.2%
Simplified35.2%
Final simplification43.9%
(FPCore (x eps) :precision binary64 (* x (- eps)))
double code(double x, double eps) {
return x * -eps;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = x * -eps
end function
public static double code(double x, double eps) {
return x * -eps;
}
def code(x, eps): return x * -eps
function code(x, eps) return Float64(x * Float64(-eps)) end
function tmp = code(x, eps) tmp = x * -eps; end
code[x_, eps_] := N[(x * (-eps)), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(-\varepsilon\right)
\end{array}
Initial program 38.6%
Taylor expanded in eps around 0 39.2%
associate-*r*39.2%
mul-1-neg39.2%
Simplified39.2%
Taylor expanded in x around 0 18.5%
associate-*r*18.5%
mul-1-neg18.5%
Simplified18.5%
Final simplification18.5%
herbie shell --seed 2023305
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))