
(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 -2.65e-5)
(- (fma (cos x) (cos eps) (* (- (sin x)) (sin eps))) (cos x))
(if (<= eps 5e-5)
(- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.65e-5) {
tmp = fma(cos(x), cos(eps), (-sin(x) * sin(eps))) - cos(x);
} else if (eps <= 5e-5) {
tmp = (cos(x) * (-0.5 * pow(eps, 2.0))) - (eps * sin(x));
} else {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -2.65e-5) tmp = Float64(fma(cos(x), cos(eps), Float64(Float64(-sin(x)) * sin(eps))) - cos(x)); elseif (eps <= 5e-5) tmp = Float64(Float64(cos(x) * Float64(-0.5 * (eps ^ 2.0))) - Float64(eps * sin(x))); else tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -2.65e-5], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision] + N[((-N[Sin[x], $MachinePrecision]) * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 5e-5], 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], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.65 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\cos x, \cos \varepsilon, \left(-\sin x\right) \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{elif}\;\varepsilon \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\end{array}
\end{array}
if eps < -2.65e-5Initial program 53.5%
cos-sum98.9%
cancel-sign-sub-inv98.9%
fma-def98.9%
Applied egg-rr98.9%
if -2.65e-5 < eps < 5.00000000000000024e-5Initial program 25.2%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-*r*99.8%
*-commutative99.8%
Simplified99.8%
if 5.00000000000000024e-5 < eps Initial program 51.1%
cos-sum98.7%
Applied egg-rr98.7%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (if (or (<= eps -4.6e-5) (not (<= eps 5e-5))) (- (* (cos x) (cos eps)) (+ (cos x) (* (sin x) (sin eps)))) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -4.6e-5) || !(eps <= 5e-5)) {
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)));
} 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 <= (-4.6d-5)) .or. (.not. (eps <= 5d-5))) then
tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps)))
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 <= -4.6e-5) || !(eps <= 5e-5)) {
tmp = (Math.cos(x) * Math.cos(eps)) - (Math.cos(x) + (Math.sin(x) * Math.sin(eps)));
} 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 <= -4.6e-5) or not (eps <= 5e-5): tmp = (math.cos(x) * math.cos(eps)) - (math.cos(x) + (math.sin(x) * math.sin(eps))) 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 <= -4.6e-5) || !(eps <= 5e-5)) tmp = Float64(Float64(cos(x) * cos(eps)) - Float64(cos(x) + Float64(sin(x) * sin(eps)))); 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 <= -4.6e-5) || ~((eps <= 5e-5))) tmp = (cos(x) * cos(eps)) - (cos(x) + (sin(x) * sin(eps))); else tmp = (cos(x) * (-0.5 * (eps ^ 2.0))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -4.6e-5], N[Not[LessEqual[eps, 5e-5]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $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 -4.6 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;\cos x \cdot \cos \varepsilon - \left(\cos x + \sin x \cdot \sin \varepsilon\right)\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -4.6e-5 or 5.00000000000000024e-5 < eps Initial program 52.3%
expm1-log1p-u25.5%
Applied egg-rr25.5%
expm1-log1p-u52.3%
cos-sum98.8%
associate--l-98.6%
*-commutative98.6%
Applied egg-rr98.6%
if -4.6e-5 < eps < 5.00000000000000024e-5Initial program 25.2%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-*r*99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x eps) :precision binary64 (if (or (<= eps -2.95e-5) (not (<= eps 3.7e-5))) (- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x)) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -2.95e-5) || !(eps <= 3.7e-5)) {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(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 <= (-2.95d-5)) .or. (.not. (eps <= 3.7d-5))) then
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(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 <= -2.95e-5) || !(eps <= 3.7e-5)) {
tmp = ((Math.cos(x) * Math.cos(eps)) - (Math.sin(x) * Math.sin(eps))) - Math.cos(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 <= -2.95e-5) or not (eps <= 3.7e-5): tmp = ((math.cos(x) * math.cos(eps)) - (math.sin(x) * math.sin(eps))) - math.cos(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 <= -2.95e-5) || !(eps <= 3.7e-5)) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(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 <= -2.95e-5) || ~((eps <= 3.7e-5))) tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(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, -2.95e-5], N[Not[LessEqual[eps, 3.7e-5]], $MachinePrecision]], N[(N[(N[(N[Cos[x], $MachinePrecision] * N[Cos[eps], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Cos[x], $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 -2.95 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 3.7 \cdot 10^{-5}\right):\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -2.9499999999999999e-5 or 3.69999999999999981e-5 < eps Initial program 52.3%
cos-sum98.8%
Applied egg-rr98.8%
if -2.9499999999999999e-5 < eps < 3.69999999999999981e-5Initial program 25.2%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-*r*99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* eps 0.5))))
(if (<= (- (cos (+ eps x)) (cos x)) -1e-6)
(* -2.0 (pow t_0 2.0))
(* (sin x) (* -2.0 t_0)))))
double code(double x, double eps) {
double t_0 = sin((eps * 0.5));
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-6) {
tmp = -2.0 * pow(t_0, 2.0);
} else {
tmp = sin(x) * (-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 * 0.5d0))
if ((cos((eps + x)) - cos(x)) <= (-1d-6)) then
tmp = (-2.0d0) * (t_0 ** 2.0d0)
else
tmp = sin(x) * ((-2.0d0) * t_0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((eps * 0.5));
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-6) {
tmp = -2.0 * Math.pow(t_0, 2.0);
} else {
tmp = Math.sin(x) * (-2.0 * t_0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((eps * 0.5)) tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-6: tmp = -2.0 * math.pow(t_0, 2.0) else: tmp = math.sin(x) * (-2.0 * t_0) return tmp
function code(x, eps) t_0 = sin(Float64(eps * 0.5)) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-6) tmp = Float64(-2.0 * (t_0 ^ 2.0)); else tmp = Float64(sin(x) * Float64(-2.0 * t_0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((eps * 0.5)); tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-6) tmp = -2.0 * (t_0 ^ 2.0); else tmp = sin(x) * (-2.0 * t_0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-6], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-6}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-2 \cdot t_0\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999955e-7Initial program 80.1%
diff-cos80.7%
div-inv80.7%
associate--l+80.7%
metadata-eval80.7%
div-inv80.7%
+-commutative80.7%
associate-+l+80.5%
metadata-eval80.5%
Applied egg-rr80.5%
associate-*r*80.5%
*-commutative80.5%
*-commutative80.5%
+-commutative80.5%
count-280.5%
fma-def80.5%
sub-neg80.5%
mul-1-neg80.5%
+-commutative80.5%
associate-+r+80.5%
mul-1-neg80.5%
sub-neg80.5%
+-inverses80.5%
remove-double-neg80.5%
mul-1-neg80.5%
sub-neg80.5%
neg-sub080.5%
mul-1-neg80.5%
remove-double-neg80.5%
Simplified80.5%
Taylor expanded in x around 0 80.7%
if -9.99999999999999955e-7 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 20.8%
diff-cos31.5%
div-inv31.5%
associate--l+31.5%
metadata-eval31.5%
div-inv31.5%
+-commutative31.5%
associate-+l+31.4%
metadata-eval31.4%
Applied egg-rr31.4%
associate-*r*31.4%
*-commutative31.4%
*-commutative31.4%
+-commutative31.4%
count-231.4%
fma-def31.4%
sub-neg31.4%
mul-1-neg31.4%
+-commutative31.4%
associate-+r+75.5%
mul-1-neg75.5%
sub-neg75.5%
+-inverses75.5%
remove-double-neg75.5%
mul-1-neg75.5%
sub-neg75.5%
neg-sub075.5%
mul-1-neg75.5%
remove-double-neg75.5%
Simplified75.5%
Taylor expanded in eps around 0 64.5%
Final simplification69.3%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-6) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-6) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-1d-6)) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-6) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-6: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-6) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-6) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-6], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-6}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999955e-7Initial program 80.1%
diff-cos80.7%
div-inv80.7%
associate--l+80.7%
metadata-eval80.7%
div-inv80.7%
+-commutative80.7%
associate-+l+80.5%
metadata-eval80.5%
Applied egg-rr80.5%
associate-*r*80.5%
*-commutative80.5%
*-commutative80.5%
+-commutative80.5%
count-280.5%
fma-def80.5%
sub-neg80.5%
mul-1-neg80.5%
+-commutative80.5%
associate-+r+80.5%
mul-1-neg80.5%
sub-neg80.5%
+-inverses80.5%
remove-double-neg80.5%
mul-1-neg80.5%
sub-neg80.5%
neg-sub080.5%
mul-1-neg80.5%
remove-double-neg80.5%
Simplified80.5%
Taylor expanded in x around 0 80.7%
if -9.99999999999999955e-7 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 20.8%
Taylor expanded in eps around 0 62.8%
mul-1-neg62.8%
*-commutative62.8%
distribute-rgt-neg-in62.8%
Simplified62.8%
Final simplification68.0%
(FPCore (x eps) :precision binary64 (if (<= (- (cos (+ eps x)) (cos x)) -1e-6) (- (cos eps) (cos x)) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((cos((eps + x)) - cos(x)) <= -1e-6) {
tmp = cos(eps) - cos(x);
} else {
tmp = sin(x) * -eps;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((cos((eps + x)) - cos(x)) <= (-1d-6)) then
tmp = cos(eps) - cos(x)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((Math.cos((eps + x)) - Math.cos(x)) <= -1e-6) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (math.cos((eps + x)) - math.cos(x)) <= -1e-6: tmp = math.cos(eps) - math.cos(x) else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if (Float64(cos(Float64(eps + x)) - cos(x)) <= -1e-6) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((cos((eps + x)) - cos(x)) <= -1e-6) tmp = cos(eps) - cos(x); else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -1e-6], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\varepsilon + x\right) - \cos x \leq -1 \cdot 10^{-6}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -9.99999999999999955e-7Initial program 80.1%
Taylor expanded in x around 0 80.3%
if -9.99999999999999955e-7 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 20.8%
Taylor expanded in eps around 0 62.8%
mul-1-neg62.8%
*-commutative62.8%
distribute-rgt-neg-in62.8%
Simplified62.8%
Final simplification67.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0105) (not (<= eps 0.00145))) (- (cos eps) (cos x)) (- (* (cos x) (* -0.5 (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0105) || !(eps <= 0.00145)) {
tmp = cos(eps) - cos(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 <= (-0.0105d0)) .or. (.not. (eps <= 0.00145d0))) then
tmp = cos(eps) - cos(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 <= -0.0105) || !(eps <= 0.00145)) {
tmp = Math.cos(eps) - Math.cos(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 <= -0.0105) or not (eps <= 0.00145): tmp = math.cos(eps) - math.cos(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 <= -0.0105) || !(eps <= 0.00145)) tmp = Float64(cos(eps) - cos(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 <= -0.0105) || ~((eps <= 0.00145))) tmp = cos(eps) - cos(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, -0.0105], N[Not[LessEqual[eps, 0.00145]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $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 -0.0105 \lor \neg \left(\varepsilon \leq 0.00145\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
if eps < -0.0105000000000000007 or 0.00145 < eps Initial program 52.3%
Taylor expanded in x around 0 54.5%
if -0.0105000000000000007 < eps < 0.00145Initial program 25.2%
Taylor expanded in eps around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-*r*99.8%
*-commutative99.8%
Simplified99.8%
Final simplification78.1%
(FPCore (x eps) :precision binary64 (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5)))))
double code(double x, double eps) {
return sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
function code(x, eps) return Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))) end
code[x_, eps_] := N[(N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)
\end{array}
Initial program 38.2%
diff-cos45.9%
div-inv45.9%
associate--l+45.9%
metadata-eval45.9%
div-inv45.9%
+-commutative45.9%
associate-+l+45.8%
metadata-eval45.8%
Applied egg-rr45.8%
associate-*r*45.8%
*-commutative45.8%
*-commutative45.8%
+-commutative45.8%
count-245.8%
fma-def45.8%
sub-neg45.8%
mul-1-neg45.8%
+-commutative45.8%
associate-+r+77.0%
mul-1-neg77.0%
sub-neg77.0%
+-inverses77.0%
remove-double-neg77.0%
mul-1-neg77.0%
sub-neg77.0%
neg-sub077.0%
mul-1-neg77.0%
remove-double-neg77.0%
Simplified77.0%
Final simplification77.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -0.00017)
t_0
(if (<= eps -2.15e-160)
t_1
(if (<= eps 7.2e-75) (* eps (- x)) (if (<= eps 0.00019) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = -0.5 * pow(eps, 2.0);
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -2.15e-160) {
tmp = t_1;
} else if (eps <= 7.2e-75) {
tmp = eps * -x;
} else if (eps <= 0.00019) {
tmp = t_1;
} else {
tmp = 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) :: t_1
real(8) :: tmp
t_0 = cos(eps) + (-1.0d0)
t_1 = (-0.5d0) * (eps ** 2.0d0)
if (eps <= (-0.00017d0)) then
tmp = t_0
else if (eps <= (-2.15d-160)) then
tmp = t_1
else if (eps <= 7.2d-75) then
tmp = eps * -x
else if (eps <= 0.00019d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.cos(eps) + -1.0;
double t_1 = -0.5 * Math.pow(eps, 2.0);
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -2.15e-160) {
tmp = t_1;
} else if (eps <= 7.2e-75) {
tmp = eps * -x;
} else if (eps <= 0.00019) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = -0.5 * math.pow(eps, 2.0) tmp = 0 if eps <= -0.00017: tmp = t_0 elif eps <= -2.15e-160: tmp = t_1 elif eps <= 7.2e-75: tmp = eps * -x elif eps <= 0.00019: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(-0.5 * (eps ^ 2.0)) tmp = 0.0 if (eps <= -0.00017) tmp = t_0; elseif (eps <= -2.15e-160) tmp = t_1; elseif (eps <= 7.2e-75) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.00019) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = cos(eps) + -1.0; t_1 = -0.5 * (eps ^ 2.0); tmp = 0.0; if (eps <= -0.00017) tmp = t_0; elseif (eps <= -2.15e-160) tmp = t_1; elseif (eps <= 7.2e-75) tmp = eps * -x; elseif (eps <= 0.00019) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.00017], t$95$0, If[LessEqual[eps, -2.15e-160], t$95$1, If[LessEqual[eps, 7.2e-75], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.00019], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := -0.5 \cdot {\varepsilon}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.00017:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -2.15 \cdot 10^{-160}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 7.2 \cdot 10^{-75}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.00019:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.7e-4 or 1.9000000000000001e-4 < eps Initial program 52.3%
Taylor expanded in x around 0 52.0%
if -1.7e-4 < eps < -2.15000000000000007e-160 or 7.2000000000000001e-75 < eps < 1.9000000000000001e-4Initial program 4.3%
Taylor expanded in x around 0 4.5%
Taylor expanded in eps around 0 37.0%
if -2.15000000000000007e-160 < eps < 7.2000000000000001e-75Initial program 35.9%
Taylor expanded in eps around 0 95.9%
mul-1-neg95.9%
*-commutative95.9%
distribute-rgt-neg-in95.9%
Simplified95.9%
Taylor expanded in x around 0 52.3%
mul-1-neg52.3%
*-commutative52.3%
distribute-rgt-neg-in52.3%
Simplified52.3%
Final simplification49.5%
(FPCore (x eps) :precision binary64 (if (or (<= eps -5.8e-7) (not (<= eps 2.2e-6))) (+ (cos eps) -1.0) (* (sin x) (- eps))))
double code(double x, double eps) {
double tmp;
if ((eps <= -5.8e-7) || !(eps <= 2.2e-6)) {
tmp = cos(eps) + -1.0;
} else {
tmp = sin(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 <= (-5.8d-7)) .or. (.not. (eps <= 2.2d-6))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = sin(x) * -eps
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -5.8e-7) || !(eps <= 2.2e-6)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = Math.sin(x) * -eps;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -5.8e-7) or not (eps <= 2.2e-6): tmp = math.cos(eps) + -1.0 else: tmp = math.sin(x) * -eps return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -5.8e-7) || !(eps <= 2.2e-6)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(sin(x) * Float64(-eps)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -5.8e-7) || ~((eps <= 2.2e-6))) tmp = cos(eps) + -1.0; else tmp = sin(x) * -eps; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -5.8e-7], N[Not[LessEqual[eps, 2.2e-6]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -5.8 \cdot 10^{-7} \lor \neg \left(\varepsilon \leq 2.2 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\
\end{array}
\end{array}
if eps < -5.7999999999999995e-7 or 2.2000000000000001e-6 < eps Initial program 52.3%
Taylor expanded in x around 0 52.0%
if -5.7999999999999995e-7 < eps < 2.2000000000000001e-6Initial program 25.2%
Taylor expanded in eps around 0 84.4%
mul-1-neg84.4%
*-commutative84.4%
distribute-rgt-neg-in84.4%
Simplified84.4%
Final simplification68.9%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.1e-41) (not (<= eps 1.1e-26))) (+ (cos eps) -1.0) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.1e-41) || !(eps <= 1.1e-26)) {
tmp = cos(eps) + -1.0;
} else {
tmp = eps * -x;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-3.1d-41)) .or. (.not. (eps <= 1.1d-26))) then
tmp = cos(eps) + (-1.0d0)
else
tmp = eps * -x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -3.1e-41) || !(eps <= 1.1e-26)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.1e-41) or not (eps <= 1.1e-26): tmp = math.cos(eps) + -1.0 else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.1e-41) || !(eps <= 1.1e-26)) tmp = Float64(cos(eps) + -1.0); else tmp = Float64(eps * Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -3.1e-41) || ~((eps <= 1.1e-26))) tmp = cos(eps) + -1.0; else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.1e-41], N[Not[LessEqual[eps, 1.1e-26]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -3.1 \cdot 10^{-41} \lor \neg \left(\varepsilon \leq 1.1 \cdot 10^{-26}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
if eps < -3.10000000000000001e-41 or 1.1e-26 < eps Initial program 49.0%
Taylor expanded in x around 0 48.8%
if -3.10000000000000001e-41 < eps < 1.1e-26Initial program 26.8%
Taylor expanded in eps around 0 86.0%
mul-1-neg86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
Simplified86.0%
Taylor expanded in x around 0 41.5%
mul-1-neg41.5%
*-commutative41.5%
distribute-rgt-neg-in41.5%
Simplified41.5%
Final simplification45.2%
(FPCore (x eps) :precision binary64 (* eps (- x)))
double code(double x, double eps) {
return eps * -x;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = eps * -x
end function
public static double code(double x, double eps) {
return eps * -x;
}
def code(x, eps): return eps * -x
function code(x, eps) return Float64(eps * Float64(-x)) end
function tmp = code(x, eps) tmp = eps * -x; end
code[x_, eps_] := N[(eps * (-x)), $MachinePrecision]
\begin{array}{l}
\\
\varepsilon \cdot \left(-x\right)
\end{array}
Initial program 38.2%
Taylor expanded in eps around 0 45.4%
mul-1-neg45.4%
*-commutative45.4%
distribute-rgt-neg-in45.4%
Simplified45.4%
Taylor expanded in x around 0 21.7%
mul-1-neg21.7%
*-commutative21.7%
distribute-rgt-neg-in21.7%
Simplified21.7%
Final simplification21.7%
herbie shell --seed 2023339
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))