
(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 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (fma (sin x) (cos (* 0.5 eps)) (* t_0 (cos x)))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * fma(sin(x), cos((0.5 * eps)), (t_0 * cos(x))));
}
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * fma(sin(x), cos(Float64(0.5 * eps)), Float64(t_0 * cos(x))))) end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] + N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \mathsf{fma}\left(\sin x, \cos \left(0.5 \cdot \varepsilon\right), t_0 \cdot \cos x\right)\right)
\end{array}
\end{array}
Initial program 40.8%
diff-cos49.9%
div-inv49.9%
metadata-eval49.9%
div-inv49.9%
+-commutative49.9%
metadata-eval49.9%
Applied egg-rr49.9%
*-commutative49.9%
+-commutative49.9%
associate--l+80.8%
+-inverses80.8%
distribute-lft-in80.8%
metadata-eval80.8%
*-commutative80.8%
associate-+r+80.8%
+-commutative80.8%
Simplified80.8%
Taylor expanded in eps around 0 81.2%
sin-sum99.5%
Applied egg-rr99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
+-commutative99.5%
*-commutative99.5%
*-commutative99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x eps) :precision binary64 (let* ((t_0 (sin (* 0.5 eps)))) (* -2.0 (* t_0 (+ (* t_0 (cos x)) (* (sin x) (cos (* 0.5 eps))))))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5 * eps)))));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
t_0 = sin((0.5d0 * eps))
code = (-2.0d0) * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5d0 * eps)))))
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
return -2.0 * (t_0 * ((t_0 * Math.cos(x)) + (Math.sin(x) * Math.cos((0.5 * eps)))));
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) return -2.0 * (t_0 * ((t_0 * math.cos(x)) + (math.sin(x) * math.cos((0.5 * eps)))))
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) return Float64(-2.0 * Float64(t_0 * Float64(Float64(t_0 * cos(x)) + Float64(sin(x) * cos(Float64(0.5 * eps)))))) end
function tmp = code(x, eps) t_0 = sin((0.5 * eps)); tmp = -2.0 * (t_0 * ((t_0 * cos(x)) + (sin(x) * cos((0.5 * eps))))); end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(t$95$0 * N[Cos[x], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
-2 \cdot \left(t_0 \cdot \left(t_0 \cdot \cos x + \sin x \cdot \cos \left(0.5 \cdot \varepsilon\right)\right)\right)
\end{array}
\end{array}
Initial program 40.8%
diff-cos49.9%
div-inv49.9%
metadata-eval49.9%
div-inv49.9%
+-commutative49.9%
metadata-eval49.9%
Applied egg-rr49.9%
*-commutative49.9%
+-commutative49.9%
associate--l+80.8%
+-inverses80.8%
distribute-lft-in80.8%
metadata-eval80.8%
*-commutative80.8%
associate-+r+80.8%
+-commutative80.8%
Simplified80.8%
Taylor expanded in eps around 0 81.2%
sin-sum99.5%
Applied egg-rr99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in eps around inf 99.5%
Final simplification99.5%
(FPCore (x eps)
:precision binary64
(if (or (<= eps -0.0036) (not (<= eps 0.0037)))
(- (- (* (cos x) (cos eps)) (* (sin x) (sin eps))) (cos x))
(*
-2.0
(*
(sin (* 0.5 eps))
(+
(* (cos x) (+ (* 0.5 eps) (* -0.020833333333333332 (pow eps 3.0))))
(* (sin x) (+ (* eps (* eps -0.125)) 1.0)))))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0036) || !(eps <= 0.0037)) {
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x);
} else {
tmp = -2.0 * (sin((0.5 * eps)) * ((cos(x) * ((0.5 * eps) + (-0.020833333333333332 * pow(eps, 3.0)))) + (sin(x) * ((eps * (eps * -0.125)) + 1.0))));
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((eps <= (-0.0036d0)) .or. (.not. (eps <= 0.0037d0))) then
tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x)
else
tmp = (-2.0d0) * (sin((0.5d0 * eps)) * ((cos(x) * ((0.5d0 * eps) + ((-0.020833333333333332d0) * (eps ** 3.0d0)))) + (sin(x) * ((eps * (eps * (-0.125d0))) + 1.0d0))))
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0036) || !(eps <= 0.0037)) {
tmp = ((Math.cos(x) * Math.cos(eps)) - (Math.sin(x) * Math.sin(eps))) - Math.cos(x);
} else {
tmp = -2.0 * (Math.sin((0.5 * eps)) * ((Math.cos(x) * ((0.5 * eps) + (-0.020833333333333332 * Math.pow(eps, 3.0)))) + (Math.sin(x) * ((eps * (eps * -0.125)) + 1.0))));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0036) or not (eps <= 0.0037): tmp = ((math.cos(x) * math.cos(eps)) - (math.sin(x) * math.sin(eps))) - math.cos(x) else: tmp = -2.0 * (math.sin((0.5 * eps)) * ((math.cos(x) * ((0.5 * eps) + (-0.020833333333333332 * math.pow(eps, 3.0)))) + (math.sin(x) * ((eps * (eps * -0.125)) + 1.0)))) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0036) || !(eps <= 0.0037)) tmp = Float64(Float64(Float64(cos(x) * cos(eps)) - Float64(sin(x) * sin(eps))) - cos(x)); else tmp = Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * Float64(Float64(cos(x) * Float64(Float64(0.5 * eps) + Float64(-0.020833333333333332 * (eps ^ 3.0)))) + Float64(sin(x) * Float64(Float64(eps * Float64(eps * -0.125)) + 1.0))))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0036) || ~((eps <= 0.0037))) tmp = ((cos(x) * cos(eps)) - (sin(x) * sin(eps))) - cos(x); else tmp = -2.0 * (sin((0.5 * eps)) * ((cos(x) * ((0.5 * eps) + (-0.020833333333333332 * (eps ^ 3.0)))) + (sin(x) * ((eps * (eps * -0.125)) + 1.0)))); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0036], N[Not[LessEqual[eps, 0.0037]], $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[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[(N[(N[Cos[x], $MachinePrecision] * N[(N[(0.5 * eps), $MachinePrecision] + N[(-0.020833333333333332 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * N[(N[(eps * N[(eps * -0.125), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0036 \lor \neg \left(\varepsilon \leq 0.0037\right):\\
\;\;\;\;\left(\cos x \cdot \cos \varepsilon - \sin x \cdot \sin \varepsilon\right) - \cos x\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \left(\cos x \cdot \left(0.5 \cdot \varepsilon + -0.020833333333333332 \cdot {\varepsilon}^{3}\right) + \sin x \cdot \left(\varepsilon \cdot \left(\varepsilon \cdot -0.125\right) + 1\right)\right)\right)\\
\end{array}
\end{array}
if eps < -0.0035999999999999999 or 0.0037000000000000002 < eps Initial program 61.3%
cos-sum98.7%
Applied egg-rr98.7%
if -0.0035999999999999999 < eps < 0.0037000000000000002Initial program 21.0%
diff-cos39.2%
div-inv39.2%
metadata-eval39.2%
div-inv39.2%
+-commutative39.2%
metadata-eval39.2%
Applied egg-rr39.2%
*-commutative39.2%
+-commutative39.2%
associate--l+98.4%
+-inverses98.4%
distribute-lft-in98.4%
metadata-eval98.4%
*-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in eps around 0 99.8%
associate-+r+99.8%
+-commutative99.8%
+-commutative99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
associate-*r*99.8%
distribute-rgt1-in99.8%
unpow299.8%
associate-*r*99.8%
Simplified99.8%
Final simplification99.3%
(FPCore (x eps) :precision binary64 (let* ((t_0 (- (cos (+ eps x)) (cos x)))) (if (<= t_0 -0.002) t_0 (expm1 (* eps (- (sin x)))))))
double code(double x, double eps) {
double t_0 = cos((eps + x)) - cos(x);
double tmp;
if (t_0 <= -0.002) {
tmp = t_0;
} else {
tmp = expm1((eps * -sin(x)));
}
return tmp;
}
public static double code(double x, double eps) {
double t_0 = Math.cos((eps + x)) - Math.cos(x);
double tmp;
if (t_0 <= -0.002) {
tmp = t_0;
} else {
tmp = Math.expm1((eps * -Math.sin(x)));
}
return tmp;
}
def code(x, eps): t_0 = math.cos((eps + x)) - math.cos(x) tmp = 0 if t_0 <= -0.002: tmp = t_0 else: tmp = math.expm1((eps * -math.sin(x))) return tmp
function code(x, eps) t_0 = Float64(cos(Float64(eps + x)) - cos(x)) tmp = 0.0 if (t_0 <= -0.002) tmp = t_0; else tmp = expm1(Float64(eps * Float64(-sin(x)))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[N[(eps + x), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.002], t$95$0, N[(Exp[N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]] - 1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\varepsilon + x\right) - \cos x\\
\mathbf{if}\;t_0 \leq -0.002:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\varepsilon \cdot \left(-\sin x\right)\right)\\
\end{array}
\end{array}
if (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) < -2e-3Initial program 85.8%
if -2e-3 < (-.f64 (cos.f64 (+.f64 x eps)) (cos.f64 x)) Initial program 17.7%
expm1-log1p-u17.7%
Applied egg-rr17.7%
Taylor expanded in eps around 0 63.6%
associate-*r*63.6%
mul-1-neg63.6%
Simplified63.6%
Final simplification71.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (sin (* 0.5 eps))))
(if (or (<= x -1.9e-13) (not (<= x 5.6e-28)))
(* -2.0 (* t_0 (sin x)))
(* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
double t_0 = sin((0.5 * eps));
double tmp;
if ((x <= -1.9e-13) || !(x <= 5.6e-28)) {
tmp = -2.0 * (t_0 * sin(x));
} else {
tmp = -2.0 * pow(t_0, 2.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((0.5d0 * eps))
if ((x <= (-1.9d-13)) .or. (.not. (x <= 5.6d-28))) then
tmp = (-2.0d0) * (t_0 * sin(x))
else
tmp = (-2.0d0) * (t_0 ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.sin((0.5 * eps));
double tmp;
if ((x <= -1.9e-13) || !(x <= 5.6e-28)) {
tmp = -2.0 * (t_0 * Math.sin(x));
} else {
tmp = -2.0 * Math.pow(t_0, 2.0);
}
return tmp;
}
def code(x, eps): t_0 = math.sin((0.5 * eps)) tmp = 0 if (x <= -1.9e-13) or not (x <= 5.6e-28): tmp = -2.0 * (t_0 * math.sin(x)) else: tmp = -2.0 * math.pow(t_0, 2.0) return tmp
function code(x, eps) t_0 = sin(Float64(0.5 * eps)) tmp = 0.0 if ((x <= -1.9e-13) || !(x <= 5.6e-28)) tmp = Float64(-2.0 * Float64(t_0 * sin(x))); else tmp = Float64(-2.0 * (t_0 ^ 2.0)); end return tmp end
function tmp_2 = code(x, eps) t_0 = sin((0.5 * eps)); tmp = 0.0; if ((x <= -1.9e-13) || ~((x <= 5.6e-28))) tmp = -2.0 * (t_0 * sin(x)); else tmp = -2.0 * (t_0 ^ 2.0); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -1.9e-13], N[Not[LessEqual[x, 5.6e-28]], $MachinePrecision]], N[(-2.0 * N[(t$95$0 * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-13} \lor \neg \left(x \leq 5.6 \cdot 10^{-28}\right):\\
\;\;\;\;-2 \cdot \left(t_0 \cdot \sin x\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\
\end{array}
\end{array}
if x < -1.9e-13 or 5.5999999999999996e-28 < x Initial program 8.0%
diff-cos7.3%
div-inv7.3%
metadata-eval7.3%
div-inv7.3%
+-commutative7.3%
metadata-eval7.3%
Applied egg-rr7.3%
*-commutative7.3%
+-commutative7.3%
associate--l+61.0%
+-inverses61.0%
distribute-lft-in61.0%
metadata-eval61.0%
*-commutative61.0%
associate-+r+61.1%
+-commutative61.1%
Simplified61.1%
Taylor expanded in eps around 0 60.2%
if -1.9e-13 < x < 5.5999999999999996e-28Initial program 71.7%
diff-cos89.9%
div-inv89.9%
metadata-eval89.9%
div-inv89.9%
+-commutative89.9%
metadata-eval89.9%
Applied egg-rr89.9%
*-commutative89.9%
+-commutative89.9%
associate--l+99.4%
+-inverses99.4%
distribute-lft-in99.4%
metadata-eval99.4%
*-commutative99.4%
associate-+r+99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around 0 89.8%
Final simplification75.5%
(FPCore (x eps) :precision binary64 (* -2.0 (* (sin (* 0.5 eps)) (sin (+ (* 0.5 eps) x)))))
double code(double x, double eps) {
return -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x)));
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (-2.0d0) * (sin((0.5d0 * eps)) * sin(((0.5d0 * eps) + x)))
end function
public static double code(double x, double eps) {
return -2.0 * (Math.sin((0.5 * eps)) * Math.sin(((0.5 * eps) + x)));
}
def code(x, eps): return -2.0 * (math.sin((0.5 * eps)) * math.sin(((0.5 * eps) + x)))
function code(x, eps) return Float64(-2.0 * Float64(sin(Float64(0.5 * eps)) * sin(Float64(Float64(0.5 * eps) + x)))) end
function tmp = code(x, eps) tmp = -2.0 * (sin((0.5 * eps)) * sin(((0.5 * eps) + x))); end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(0.5 * eps), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \varepsilon + x\right)\right)
\end{array}
Initial program 40.8%
diff-cos49.9%
div-inv49.9%
metadata-eval49.9%
div-inv49.9%
+-commutative49.9%
metadata-eval49.9%
Applied egg-rr49.9%
*-commutative49.9%
+-commutative49.9%
associate--l+80.8%
+-inverses80.8%
distribute-lft-in80.8%
metadata-eval80.8%
*-commutative80.8%
associate-+r+80.8%
+-commutative80.8%
Simplified80.8%
Taylor expanded in eps around 0 81.2%
Taylor expanded in eps around inf 81.2%
Final simplification81.2%
(FPCore (x eps) :precision binary64 (if (or (<= x -4.2e-12) (not (<= x 4.1e-28))) (expm1 (* eps (- (sin x)))) (* -2.0 (pow (sin (* 0.5 eps)) 2.0))))
double code(double x, double eps) {
double tmp;
if ((x <= -4.2e-12) || !(x <= 4.1e-28)) {
tmp = expm1((eps * -sin(x)));
} else {
tmp = -2.0 * pow(sin((0.5 * eps)), 2.0);
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if ((x <= -4.2e-12) || !(x <= 4.1e-28)) {
tmp = Math.expm1((eps * -Math.sin(x)));
} else {
tmp = -2.0 * Math.pow(Math.sin((0.5 * eps)), 2.0);
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -4.2e-12) or not (x <= 4.1e-28): tmp = math.expm1((eps * -math.sin(x))) else: tmp = -2.0 * math.pow(math.sin((0.5 * eps)), 2.0) return tmp
function code(x, eps) tmp = 0.0 if ((x <= -4.2e-12) || !(x <= 4.1e-28)) tmp = expm1(Float64(eps * Float64(-sin(x)))); else tmp = Float64(-2.0 * (sin(Float64(0.5 * eps)) ^ 2.0)); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -4.2e-12], N[Not[LessEqual[x, 4.1e-28]], $MachinePrecision]], N[(Exp[N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]] - 1), $MachinePrecision], N[(-2.0 * N[Power[N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-12} \lor \neg \left(x \leq 4.1 \cdot 10^{-28}\right):\\
\;\;\;\;\mathsf{expm1}\left(\varepsilon \cdot \left(-\sin x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot {\sin \left(0.5 \cdot \varepsilon\right)}^{2}\\
\end{array}
\end{array}
if x < -4.19999999999999988e-12 or 4.1000000000000002e-28 < x Initial program 8.0%
expm1-log1p-u6.5%
Applied egg-rr6.5%
Taylor expanded in eps around 0 58.6%
associate-*r*58.6%
mul-1-neg58.6%
Simplified58.6%
if -4.19999999999999988e-12 < x < 4.1000000000000002e-28Initial program 71.7%
diff-cos89.9%
div-inv89.9%
metadata-eval89.9%
div-inv89.9%
+-commutative89.9%
metadata-eval89.9%
Applied egg-rr89.9%
*-commutative89.9%
+-commutative89.9%
associate--l+99.4%
+-inverses99.4%
distribute-lft-in99.4%
metadata-eval99.4%
*-commutative99.4%
associate-+r+99.4%
+-commutative99.4%
Simplified99.4%
Taylor expanded in x around 0 89.8%
Final simplification74.7%
(FPCore (x eps) :precision binary64 (if (<= eps -4.2e-5) (- (cos eps) (cos x)) (if (<= eps 4.8e-20) (* eps (- (sin x))) (+ (cos eps) -1.0))))
double code(double x, double eps) {
double tmp;
if (eps <= -4.2e-5) {
tmp = cos(eps) - cos(x);
} else if (eps <= 4.8e-20) {
tmp = eps * -sin(x);
} else {
tmp = cos(eps) + -1.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (eps <= (-4.2d-5)) then
tmp = cos(eps) - cos(x)
else if (eps <= 4.8d-20) then
tmp = eps * -sin(x)
else
tmp = cos(eps) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -4.2e-5) {
tmp = Math.cos(eps) - Math.cos(x);
} else if (eps <= 4.8e-20) {
tmp = eps * -Math.sin(x);
} else {
tmp = Math.cos(eps) + -1.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -4.2e-5: tmp = math.cos(eps) - math.cos(x) elif eps <= 4.8e-20: tmp = eps * -math.sin(x) else: tmp = math.cos(eps) + -1.0 return tmp
function code(x, eps) tmp = 0.0 if (eps <= -4.2e-5) tmp = Float64(cos(eps) - cos(x)); elseif (eps <= 4.8e-20) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(cos(eps) + -1.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -4.2e-5) tmp = cos(eps) - cos(x); elseif (eps <= 4.8e-20) tmp = eps * -sin(x); else tmp = cos(eps) + -1.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -4.2e-5], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.8e-20], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -4.2 \cdot 10^{-5}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{elif}\;\varepsilon \leq 4.8 \cdot 10^{-20}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon + -1\\
\end{array}
\end{array}
if eps < -4.19999999999999977e-5Initial program 62.6%
Taylor expanded in x around 0 64.5%
if -4.19999999999999977e-5 < eps < 4.79999999999999986e-20Initial program 21.1%
Taylor expanded in eps around 0 81.5%
mul-1-neg81.5%
*-commutative81.5%
distribute-rgt-neg-in81.5%
Simplified81.5%
if 4.79999999999999986e-20 < eps Initial program 58.9%
Taylor expanded in x around 0 60.0%
Final simplification72.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (cos eps) -1.0)) (t_1 (* (* eps eps) -0.5)))
(if (<= eps -0.00017)
t_0
(if (<= eps -5e-138)
t_1
(if (<= eps 6.5e-122) (* eps (- x)) (if (<= eps 0.000175) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = cos(eps) + -1.0;
double t_1 = (eps * eps) * -0.5;
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -5e-138) {
tmp = t_1;
} else if (eps <= 6.5e-122) {
tmp = eps * -x;
} else if (eps <= 0.000175) {
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 = (eps * eps) * (-0.5d0)
if (eps <= (-0.00017d0)) then
tmp = t_0
else if (eps <= (-5d-138)) then
tmp = t_1
else if (eps <= 6.5d-122) then
tmp = eps * -x
else if (eps <= 0.000175d0) 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 = (eps * eps) * -0.5;
double tmp;
if (eps <= -0.00017) {
tmp = t_0;
} else if (eps <= -5e-138) {
tmp = t_1;
} else if (eps <= 6.5e-122) {
tmp = eps * -x;
} else if (eps <= 0.000175) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = math.cos(eps) + -1.0 t_1 = (eps * eps) * -0.5 tmp = 0 if eps <= -0.00017: tmp = t_0 elif eps <= -5e-138: tmp = t_1 elif eps <= 6.5e-122: tmp = eps * -x elif eps <= 0.000175: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(cos(eps) + -1.0) t_1 = Float64(Float64(eps * eps) * -0.5) tmp = 0.0 if (eps <= -0.00017) tmp = t_0; elseif (eps <= -5e-138) tmp = t_1; elseif (eps <= 6.5e-122) tmp = Float64(eps * Float64(-x)); elseif (eps <= 0.000175) 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 = (eps * eps) * -0.5; tmp = 0.0; if (eps <= -0.00017) tmp = t_0; elseif (eps <= -5e-138) tmp = t_1; elseif (eps <= 6.5e-122) tmp = eps * -x; elseif (eps <= 0.000175) 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[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[eps, -0.00017], t$95$0, If[LessEqual[eps, -5e-138], t$95$1, If[LessEqual[eps, 6.5e-122], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 0.000175], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
t_1 := \left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\mathbf{if}\;\varepsilon \leq -0.00017:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -5 \cdot 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 6.5 \cdot 10^{-122}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 0.000175:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if eps < -1.7e-4 or 1.74999999999999998e-4 < eps Initial program 61.3%
Taylor expanded in x around 0 61.8%
if -1.7e-4 < eps < -4.99999999999999989e-138 or 6.49999999999999965e-122 < eps < 1.74999999999999998e-4Initial program 4.1%
Taylor expanded in x around 0 4.2%
Taylor expanded in eps around 0 41.7%
*-commutative41.7%
unpow241.7%
Simplified41.7%
if -4.99999999999999989e-138 < eps < 6.49999999999999965e-122Initial program 36.4%
Taylor expanded in eps around 0 98.5%
mul-1-neg98.5%
*-commutative98.5%
distribute-rgt-neg-in98.5%
Simplified98.5%
Taylor expanded in x around 0 55.0%
associate-*r*55.0%
neg-mul-155.0%
Simplified55.0%
Final simplification55.1%
(FPCore (x eps) :precision binary64 (if (or (<= eps -3.8e-5) (not (<= eps 4.8e-20))) (+ (cos eps) -1.0) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -3.8e-5) || !(eps <= 4.8e-20)) {
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 <= (-3.8d-5)) .or. (.not. (eps <= 4.8d-20))) 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 <= -3.8e-5) || !(eps <= 4.8e-20)) {
tmp = Math.cos(eps) + -1.0;
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -3.8e-5) or not (eps <= 4.8e-20): tmp = math.cos(eps) + -1.0 else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -3.8e-5) || !(eps <= 4.8e-20)) 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 <= -3.8e-5) || ~((eps <= 4.8e-20))) tmp = cos(eps) + -1.0; else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -3.8e-5], N[Not[LessEqual[eps, 4.8e-20]], $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 -3.8 \cdot 10^{-5} \lor \neg \left(\varepsilon \leq 4.8 \cdot 10^{-20}\right):\\
\;\;\;\;\cos \varepsilon + -1\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
if eps < -3.8000000000000002e-5 or 4.79999999999999986e-20 < eps Initial program 60.9%
Taylor expanded in x around 0 61.3%
if -3.8000000000000002e-5 < eps < 4.79999999999999986e-20Initial program 21.1%
Taylor expanded in eps around 0 81.5%
mul-1-neg81.5%
*-commutative81.5%
distribute-rgt-neg-in81.5%
Simplified81.5%
Final simplification71.5%
(FPCore (x eps) :precision binary64 (if (or (<= x -9.5e-88) (not (<= x 4.45e-100))) (* eps (- x)) (* (* eps eps) -0.5)))
double code(double x, double eps) {
double tmp;
if ((x <= -9.5e-88) || !(x <= 4.45e-100)) {
tmp = eps * -x;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if ((x <= (-9.5d-88)) .or. (.not. (x <= 4.45d-100))) then
tmp = eps * -x
else
tmp = (eps * eps) * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((x <= -9.5e-88) || !(x <= 4.45e-100)) {
tmp = eps * -x;
} else {
tmp = (eps * eps) * -0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if (x <= -9.5e-88) or not (x <= 4.45e-100): tmp = eps * -x else: tmp = (eps * eps) * -0.5 return tmp
function code(x, eps) tmp = 0.0 if ((x <= -9.5e-88) || !(x <= 4.45e-100)) tmp = Float64(eps * Float64(-x)); else tmp = Float64(Float64(eps * eps) * -0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((x <= -9.5e-88) || ~((x <= 4.45e-100))) tmp = eps * -x; else tmp = (eps * eps) * -0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[x, -9.5e-88], N[Not[LessEqual[x, 4.45e-100]], $MachinePrecision]], N[(eps * (-x)), $MachinePrecision], N[(N[(eps * eps), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-88} \lor \neg \left(x \leq 4.45 \cdot 10^{-100}\right):\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\varepsilon \cdot \varepsilon\right) \cdot -0.5\\
\end{array}
\end{array}
if x < -9.5e-88 or 4.4500000000000002e-100 < x Initial program 21.6%
Taylor expanded in eps around 0 52.5%
mul-1-neg52.5%
*-commutative52.5%
distribute-rgt-neg-in52.5%
Simplified52.5%
Taylor expanded in x around 0 14.8%
associate-*r*14.8%
neg-mul-114.8%
Simplified14.8%
if -9.5e-88 < x < 4.4500000000000002e-100Initial program 74.0%
Taylor expanded in x around 0 74.0%
Taylor expanded in eps around 0 50.4%
*-commutative50.4%
unpow250.4%
Simplified50.4%
Final simplification27.8%
(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 40.8%
Taylor expanded in eps around 0 43.1%
mul-1-neg43.1%
*-commutative43.1%
distribute-rgt-neg-in43.1%
Simplified43.1%
Taylor expanded in x around 0 19.2%
associate-*r*19.2%
neg-mul-119.2%
Simplified19.2%
Final simplification19.2%
herbie shell --seed 2023275
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))