
(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 16 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 (* (cos x) (+ -1.0 (cos eps)))))
(if (<= x -1.35e-34)
(- t_0 (expm1 (log1p (* (sin eps) (sin x)))))
(if (<= x 7.2e-33)
(*
(expm1 (log1p (sin (* 0.5 (fma 2.0 x eps)))))
(* -2.0 (sin (* eps 0.5))))
(fma (sin eps) (- (sin x)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(x) * (-1.0 + cos(eps));
double tmp;
if (x <= -1.35e-34) {
tmp = t_0 - expm1(log1p((sin(eps) * sin(x))));
} else if (x <= 7.2e-33) {
tmp = expm1(log1p(sin((0.5 * fma(2.0, x, eps))))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(sin(eps), -sin(x), t_0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(cos(x) * Float64(-1.0 + cos(eps))) tmp = 0.0 if (x <= -1.35e-34) tmp = Float64(t_0 - expm1(log1p(Float64(sin(eps) * sin(x))))); elseif (x <= 7.2e-33) tmp = Float64(expm1(log1p(sin(Float64(0.5 * fma(2.0, x, eps))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(sin(eps), Float64(-sin(x)), t_0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e-34], N[(t$95$0 - N[(Exp[N[Log[1 + N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.2e-33], N[(N[(Exp[N[Log[1 + N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \left(-1 + \cos \varepsilon\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-34}:\\
\;\;\;\;t_0 - \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \varepsilon \cdot \sin x\right)\right)\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, t_0\right)\\
\end{array}
\end{array}
(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}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (- (sin x))))
(if (<= x -2.45e-33)
(fma t_0 (cos x) (* (sin eps) t_1))
(if (<= x 7.8e-33)
(*
(expm1 (log1p (sin (* 0.5 (fma 2.0 x eps)))))
(* -2.0 (sin (* eps 0.5))))
(fma (sin eps) t_1 (* (cos x) t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -sin(x);
double tmp;
if (x <= -2.45e-33) {
tmp = fma(t_0, cos(x), (sin(eps) * t_1));
} else if (x <= 7.8e-33) {
tmp = expm1(log1p(sin((0.5 * fma(2.0, x, eps))))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(sin(eps), t_1, (cos(x) * t_0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(-sin(x)) tmp = 0.0 if (x <= -2.45e-33) tmp = fma(t_0, cos(x), Float64(sin(eps) * t_1)); elseif (x <= 7.8e-33) tmp = Float64(expm1(log1p(sin(Float64(0.5 * fma(2.0, x, eps))))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(sin(eps), t_1, Float64(cos(x) * t_0)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Sin[x], $MachinePrecision])}, If[LessEqual[x, -2.45e-33], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.8e-33], N[(N[(Exp[N[Log[1 + N[Sin[N[(0.5 * N[(2.0 * x + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * N[(-2.0 * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[eps], $MachinePrecision] * t$95$1 + N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -\sin x\\
\mathbf{if}\;x \leq -2.45 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot t_1\right)\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(0.5 \cdot \mathsf{fma}\left(2, x, \varepsilon\right)\right)\right)\right) \cdot \left(-2 \cdot \sin \left(\varepsilon \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, t_1, \cos x \cdot t_0\right)\\
\end{array}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (cos x) (+ -1.0 (cos eps)))))
(if (<= x -1.7e-33)
(- t_0 (* (sin eps) (sin x)))
(if (<= x 7.5e-33)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(fma (sin eps) (- (sin x)) t_0)))))
double code(double x, double eps) {
double t_0 = cos(x) * (-1.0 + cos(eps));
double tmp;
if (x <= -1.7e-33) {
tmp = t_0 - (sin(eps) * sin(x));
} else if (x <= 7.5e-33) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(sin(eps), -sin(x), t_0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(cos(x) * Float64(-1.0 + cos(eps))) tmp = 0.0 if (x <= -1.7e-33) tmp = Float64(t_0 - Float64(sin(eps) * sin(x))); elseif (x <= 7.5e-33) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(sin(eps), Float64(-sin(x)), t_0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.7e-33], N[(t$95$0 - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.5e-33], 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], N[(N[Sin[eps], $MachinePrecision] * (-N[Sin[x], $MachinePrecision]) + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos x \cdot \left(-1 + \cos \varepsilon\right)\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{-33}:\\
\;\;\;\;t_0 - \sin \varepsilon \cdot \sin x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-33}:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, -\sin x, t_0\right)\\
\end{array}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (- (sin x))))
(if (<= x -2.45e-33)
(fma t_0 (cos x) (* (sin eps) t_1))
(if (<= x 7.5e-33)
(* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))
(fma (sin eps) t_1 (* (cos x) t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -sin(x);
double tmp;
if (x <= -2.45e-33) {
tmp = fma(t_0, cos(x), (sin(eps) * t_1));
} else if (x <= 7.5e-33) {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
} else {
tmp = fma(sin(eps), t_1, (cos(x) * t_0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(-sin(x)) tmp = 0.0 if (x <= -2.45e-33) tmp = fma(t_0, cos(x), Float64(sin(eps) * t_1)); elseif (x <= 7.5e-33) tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); else tmp = fma(sin(eps), t_1, Float64(cos(x) * t_0)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Sin[x], $MachinePrecision])}, If[LessEqual[x, -2.45e-33], N[(t$95$0 * N[Cos[x], $MachinePrecision] + N[(N[Sin[eps], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.5e-33], 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], N[(N[Sin[eps], $MachinePrecision] * t$95$1 + N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -\sin x\\
\mathbf{if}\;x \leq -2.45 \cdot 10^{-33}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \cos x, \sin \varepsilon \cdot t_1\right)\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-33}:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \varepsilon, t_1, \cos x \cdot t_0\right)\\
\end{array}
\end{array}
(FPCore (x eps) :precision binary64 (if (or (<= x -2.5e-34) (not (<= x 7.8e-33))) (- (* (cos x) (+ -1.0 (cos eps))) (* (sin eps) (sin x))) (* (sin (* 0.5 (fma 2.0 x eps))) (* -2.0 (sin (* eps 0.5))))))
double code(double x, double eps) {
double tmp;
if ((x <= -2.5e-34) || !(x <= 7.8e-33)) {
tmp = (cos(x) * (-1.0 + cos(eps))) - (sin(eps) * sin(x));
} else {
tmp = sin((0.5 * fma(2.0, x, eps))) * (-2.0 * sin((eps * 0.5)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if ((x <= -2.5e-34) || !(x <= 7.8e-33)) tmp = Float64(Float64(cos(x) * Float64(-1.0 + cos(eps))) - Float64(sin(eps) * sin(x))); else tmp = Float64(sin(Float64(0.5 * fma(2.0, x, eps))) * Float64(-2.0 * sin(Float64(eps * 0.5)))); end return tmp end
code[x_, eps_] := If[Or[LessEqual[x, -2.5e-34], N[Not[LessEqual[x, 7.8e-33]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[eps], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-34} \lor \neg \left(x \leq 7.8 \cdot 10^{-33}\right):\\
\;\;\;\;\cos x \cdot \left(-1 + \cos \varepsilon\right) - \sin \varepsilon \cdot \sin x\\
\mathbf{else}:\\
\;\;\;\;\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}
\end{array}
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.008) (not (<= eps 0.004))) (- (cos eps) (cos x)) (- (* -0.5 (* (cos x) (pow eps 2.0))) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.008) || !(eps <= 0.004)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-0.5 * (cos(x) * 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.008d0)) .or. (.not. (eps <= 0.004d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-0.5d0) * (cos(x) * (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.008) || !(eps <= 0.004)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * (Math.cos(x) * Math.pow(eps, 2.0))) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.008) or not (eps <= 0.004): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * (math.cos(x) * math.pow(eps, 2.0))) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.008) || !(eps <= 0.004)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(Float64(-0.5 * Float64(cos(x) * (eps ^ 2.0))) - Float64(eps * sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.008) || ~((eps <= 0.004))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (cos(x) * (eps ^ 2.0))) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.008], N[Not[LessEqual[eps, 0.004]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(N[Cos[x], $MachinePrecision] * 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.008 \lor \neg \left(\varepsilon \leq 0.004\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\cos x \cdot {\varepsilon}^{2}\right) - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
(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}
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.00335) (not (<= eps 0.00094))) (- (cos eps) (cos x)) (- (* -0.5 (pow eps 2.0)) (* eps (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.00335) || !(eps <= 0.00094)) {
tmp = cos(eps) - cos(x);
} else {
tmp = (-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.00335d0)) .or. (.not. (eps <= 0.00094d0))) then
tmp = cos(eps) - cos(x)
else
tmp = ((-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.00335) || !(eps <= 0.00094)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = (-0.5 * Math.pow(eps, 2.0)) - (eps * Math.sin(x));
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.00335) or not (eps <= 0.00094): tmp = math.cos(eps) - math.cos(x) else: tmp = (-0.5 * math.pow(eps, 2.0)) - (eps * math.sin(x)) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.00335) || !(eps <= 0.00094)) tmp = Float64(cos(eps) - cos(x)); else tmp = Float64(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.00335) || ~((eps <= 0.00094))) tmp = cos(eps) - cos(x); else tmp = (-0.5 * (eps ^ 2.0)) - (eps * sin(x)); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00335], N[Not[LessEqual[eps, 0.00094]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] - N[(eps * N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00335 \lor \neg \left(\varepsilon \leq 0.00094\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2} - \varepsilon \cdot \sin x\\
\end{array}
\end{array}
(FPCore (x eps) :precision binary64 (if (<= eps -2.3e-11) (* -2.0 (pow (sin (* eps 0.5)) 2.0)) (if (<= eps 1.75e-6) (* eps (- (sin x))) (- (cos eps) (cos x)))))
double code(double x, double eps) {
double tmp;
if (eps <= -2.3e-11) {
tmp = -2.0 * pow(sin((eps * 0.5)), 2.0);
} else if (eps <= 1.75e-6) {
tmp = eps * -sin(x);
} else {
tmp = cos(eps) - cos(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.3d-11)) then
tmp = (-2.0d0) * (sin((eps * 0.5d0)) ** 2.0d0)
else if (eps <= 1.75d-6) then
tmp = eps * -sin(x)
else
tmp = cos(eps) - cos(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -2.3e-11) {
tmp = -2.0 * Math.pow(Math.sin((eps * 0.5)), 2.0);
} else if (eps <= 1.75e-6) {
tmp = eps * -Math.sin(x);
} else {
tmp = Math.cos(eps) - Math.cos(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -2.3e-11: tmp = -2.0 * math.pow(math.sin((eps * 0.5)), 2.0) elif eps <= 1.75e-6: tmp = eps * -math.sin(x) else: tmp = math.cos(eps) - math.cos(x) return tmp
function code(x, eps) tmp = 0.0 if (eps <= -2.3e-11) tmp = Float64(-2.0 * (sin(Float64(eps * 0.5)) ^ 2.0)); elseif (eps <= 1.75e-6) tmp = Float64(eps * Float64(-sin(x))); else tmp = Float64(cos(eps) - cos(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -2.3e-11) tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0); elseif (eps <= 1.75e-6) tmp = eps * -sin(x); else tmp = cos(eps) - cos(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -2.3e-11], N[(-2.0 * N[Power[N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.75e-6], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision], N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -2.3 \cdot 10^{-11}:\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\
\mathbf{elif}\;\varepsilon \leq 1.75 \cdot 10^{-6}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \varepsilon - \cos x\\
\end{array}
\end{array}
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0011) (not (<= eps 1.9e-6))) (- (cos eps) (cos x)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0011) || !(eps <= 1.9e-6)) {
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 <= (-0.0011d0)) .or. (.not. (eps <= 1.9d-6))) 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 <= -0.0011) || !(eps <= 1.9e-6)) {
tmp = Math.cos(eps) - Math.cos(x);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0011) or not (eps <= 1.9e-6): tmp = math.cos(eps) - math.cos(x) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0011) || !(eps <= 1.9e-6)) 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 <= -0.0011) || ~((eps <= 1.9e-6))) tmp = cos(eps) - cos(x); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0011], N[Not[LessEqual[eps, 1.9e-6]], $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 -0.0011 \lor \neg \left(\varepsilon \leq 1.9 \cdot 10^{-6}\right):\\
\;\;\;\;\cos \varepsilon - \cos x\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ -1.0 (cos eps))) (t_1 (* -0.5 (pow eps 2.0))))
(if (<= eps -0.000175)
t_0
(if (<= eps -5.5e-157)
t_1
(if (<= eps 2.1e-121) (* eps (- x)) (if (<= eps 1.05e-9) t_1 t_0))))))
double code(double x, double eps) {
double t_0 = -1.0 + cos(eps);
double t_1 = -0.5 * pow(eps, 2.0);
double tmp;
if (eps <= -0.000175) {
tmp = t_0;
} else if (eps <= -5.5e-157) {
tmp = t_1;
} else if (eps <= 2.1e-121) {
tmp = eps * -x;
} else if (eps <= 1.05e-9) {
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 = (-1.0d0) + cos(eps)
t_1 = (-0.5d0) * (eps ** 2.0d0)
if (eps <= (-0.000175d0)) then
tmp = t_0
else if (eps <= (-5.5d-157)) then
tmp = t_1
else if (eps <= 2.1d-121) then
tmp = eps * -x
else if (eps <= 1.05d-9) 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 = -1.0 + Math.cos(eps);
double t_1 = -0.5 * Math.pow(eps, 2.0);
double tmp;
if (eps <= -0.000175) {
tmp = t_0;
} else if (eps <= -5.5e-157) {
tmp = t_1;
} else if (eps <= 2.1e-121) {
tmp = eps * -x;
} else if (eps <= 1.05e-9) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = -1.0 + math.cos(eps) t_1 = -0.5 * math.pow(eps, 2.0) tmp = 0 if eps <= -0.000175: tmp = t_0 elif eps <= -5.5e-157: tmp = t_1 elif eps <= 2.1e-121: tmp = eps * -x elif eps <= 1.05e-9: tmp = t_1 else: tmp = t_0 return tmp
function code(x, eps) t_0 = Float64(-1.0 + cos(eps)) t_1 = Float64(-0.5 * (eps ^ 2.0)) tmp = 0.0 if (eps <= -0.000175) tmp = t_0; elseif (eps <= -5.5e-157) tmp = t_1; elseif (eps <= 2.1e-121) tmp = Float64(eps * Float64(-x)); elseif (eps <= 1.05e-9) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = -1.0 + cos(eps); t_1 = -0.5 * (eps ^ 2.0); tmp = 0.0; if (eps <= -0.000175) tmp = t_0; elseif (eps <= -5.5e-157) tmp = t_1; elseif (eps <= 2.1e-121) tmp = eps * -x; elseif (eps <= 1.05e-9) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -0.000175], t$95$0, If[LessEqual[eps, -5.5e-157], t$95$1, If[LessEqual[eps, 2.1e-121], N[(eps * (-x)), $MachinePrecision], If[LessEqual[eps, 1.05e-9], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \cos \varepsilon\\
t_1 := -0.5 \cdot {\varepsilon}^{2}\\
\mathbf{if}\;\varepsilon \leq -0.000175:\\
\;\;\;\;t_0\\
\mathbf{elif}\;\varepsilon \leq -5.5 \cdot 10^{-157}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-121}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\mathbf{elif}\;\varepsilon \leq 1.05 \cdot 10^{-9}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x eps) :precision binary64 (if (or (<= eps -0.0013) (not (<= eps 3.8e-7))) (+ -1.0 (cos eps)) (* eps (- (sin x)))))
double code(double x, double eps) {
double tmp;
if ((eps <= -0.0013) || !(eps <= 3.8e-7)) {
tmp = -1.0 + cos(eps);
} 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.0013d0)) .or. (.not. (eps <= 3.8d-7))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -sin(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -0.0013) || !(eps <= 3.8e-7)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -Math.sin(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -0.0013) or not (eps <= 3.8e-7): tmp = -1.0 + math.cos(eps) else: tmp = eps * -math.sin(x) return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -0.0013) || !(eps <= 3.8e-7)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-sin(x))); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -0.0013) || ~((eps <= 3.8e-7))) tmp = -1.0 + cos(eps); else tmp = eps * -sin(x); end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -0.0013], N[Not[LessEqual[eps, 3.8e-7]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-N[Sin[x], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.0013 \lor \neg \left(\varepsilon \leq 3.8 \cdot 10^{-7}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-\sin x\right)\\
\end{array}
\end{array}
(FPCore (x eps) :precision binary64 (if (or (<= eps -9e-68) (not (<= eps 5.3e-30))) (+ -1.0 (cos eps)) (* eps (- x))))
double code(double x, double eps) {
double tmp;
if ((eps <= -9e-68) || !(eps <= 5.3e-30)) {
tmp = -1.0 + cos(eps);
} 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 <= (-9d-68)) .or. (.not. (eps <= 5.3d-30))) then
tmp = (-1.0d0) + cos(eps)
else
tmp = eps * -x
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if ((eps <= -9e-68) || !(eps <= 5.3e-30)) {
tmp = -1.0 + Math.cos(eps);
} else {
tmp = eps * -x;
}
return tmp;
}
def code(x, eps): tmp = 0 if (eps <= -9e-68) or not (eps <= 5.3e-30): tmp = -1.0 + math.cos(eps) else: tmp = eps * -x return tmp
function code(x, eps) tmp = 0.0 if ((eps <= -9e-68) || !(eps <= 5.3e-30)) tmp = Float64(-1.0 + cos(eps)); else tmp = Float64(eps * Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if ((eps <= -9e-68) || ~((eps <= 5.3e-30))) tmp = -1.0 + cos(eps); else tmp = eps * -x; end tmp_2 = tmp; end
code[x_, eps_] := If[Or[LessEqual[eps, -9e-68], N[Not[LessEqual[eps, 5.3e-30]], $MachinePrecision]], N[(-1.0 + N[Cos[eps], $MachinePrecision]), $MachinePrecision], N[(eps * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -9 \cdot 10^{-68} \lor \neg \left(\varepsilon \leq 5.3 \cdot 10^{-30}\right):\\
\;\;\;\;-1 + \cos \varepsilon\\
\mathbf{else}:\\
\;\;\;\;\varepsilon \cdot \left(-x\right)\\
\end{array}
\end{array}
(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}
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
herbie shell --seed 2023350
(FPCore (x eps)
:name "2cos (problem 3.3.5)"
:precision binary64
(- (cos (+ x eps)) (cos x)))