2cos (problem 3.3.5)

Percentage Accurate: 38.1% → 99.5%
Time: 14.8s
Alternatives: 13
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \cos \left(x + \varepsilon\right) - \cos x \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 38.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos \left(x + \varepsilon\right) - \cos x \end{array} \]
(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}

Alternative 1: 99.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \cos x \cdot \left(\sin \varepsilon \cdot \left(-\tan \left(\frac{\varepsilon}{2}\right)\right)\right) - \sin x \cdot \sin \varepsilon \end{array} \]
(FPCore (x eps)
 :precision binary64
 (- (* (cos x) (* (sin eps) (- (tan (/ eps 2.0))))) (* (sin x) (sin eps))))
double code(double x, double eps) {
	return (cos(x) * (sin(eps) * -tan((eps / 2.0)))) - (sin(x) * sin(eps));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = (cos(x) * (sin(eps) * -tan((eps / 2.0d0)))) - (sin(x) * sin(eps))
end function
public static double code(double x, double eps) {
	return (Math.cos(x) * (Math.sin(eps) * -Math.tan((eps / 2.0)))) - (Math.sin(x) * Math.sin(eps));
}
def code(x, eps):
	return (math.cos(x) * (math.sin(eps) * -math.tan((eps / 2.0)))) - (math.sin(x) * math.sin(eps))
function code(x, eps)
	return Float64(Float64(cos(x) * Float64(sin(eps) * Float64(-tan(Float64(eps / 2.0))))) - Float64(sin(x) * sin(eps)))
end
function tmp = code(x, eps)
	tmp = (cos(x) * (sin(eps) * -tan((eps / 2.0)))) - (sin(x) * sin(eps));
end
code[x_, eps_] := N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Sin[eps], $MachinePrecision] * (-N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot \left(\sin \varepsilon \cdot \left(-\tan \left(\frac{\varepsilon}{2}\right)\right)\right) - \sin x \cdot \sin \varepsilon
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 99.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-14} \lor \neg \left(x \leq 2.4 \cdot 10^{-20}\right):\\ \;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= x -9.5e-14) (not (<= x 2.4e-20)))
   (fma (+ (cos eps) -1.0) (cos x) (* (sin x) (- (sin eps))))
   (* -2.0 (* (sin (/ (+ eps (- x x)) 2.0)) (sin (/ (+ eps (+ x x)) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((x <= -9.5e-14) || !(x <= 2.4e-20)) {
		tmp = fma((cos(eps) + -1.0), cos(x), (sin(x) * -sin(eps)));
	} else {
		tmp = -2.0 * (sin(((eps + (x - x)) / 2.0)) * sin(((eps + (x + x)) / 2.0)));
	}
	return tmp;
}
function code(x, eps)
	tmp = 0.0
	if ((x <= -9.5e-14) || !(x <= 2.4e-20))
		tmp = fma(Float64(cos(eps) + -1.0), cos(x), Float64(sin(x) * Float64(-sin(eps))));
	else
		tmp = Float64(-2.0 * Float64(sin(Float64(Float64(eps + Float64(x - x)) / 2.0)) * sin(Float64(Float64(eps + Float64(x + x)) / 2.0))));
	end
	return tmp
end
code[x_, eps_] := If[Or[LessEqual[x, -9.5e-14], N[Not[LessEqual[x, 2.4e-20]], $MachinePrecision]], N[(N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision] * N[Cos[x], $MachinePrecision] + N[(N[Sin[x], $MachinePrecision] * (-N[Sin[eps], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-14} \lor \neg \left(x \leq 2.4 \cdot 10^{-20}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos \varepsilon + -1, \cos x, \sin x \cdot \left(-\sin \varepsilon\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 75.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(x + \varepsilon\right) - \cos x \leq -5 \cdot 10^{-6}:\\ \;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \frac{\sin \varepsilon}{-1}\\ \mathbf{else}:\\ \;\;\;\;\cos x \cdot \left(-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right) - \sin x \cdot \varepsilon\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (<= (- (cos (+ x eps)) (cos x)) -5e-6)
   (* (tan (/ eps 2.0)) (/ (sin eps) -1.0))
   (- (* (cos x) (* -0.5 (* eps eps))) (* (sin x) eps))))
double code(double x, double eps) {
	double tmp;
	if ((cos((x + eps)) - cos(x)) <= -5e-6) {
		tmp = tan((eps / 2.0)) * (sin(eps) / -1.0);
	} else {
		tmp = (cos(x) * (-0.5 * (eps * eps))) - (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((x + eps)) - cos(x)) <= (-5d-6)) then
        tmp = tan((eps / 2.0d0)) * (sin(eps) / (-1.0d0))
    else
        tmp = (cos(x) * ((-0.5d0) * (eps * eps))) - (sin(x) * eps)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((Math.cos((x + eps)) - Math.cos(x)) <= -5e-6) {
		tmp = Math.tan((eps / 2.0)) * (Math.sin(eps) / -1.0);
	} else {
		tmp = (Math.cos(x) * (-0.5 * (eps * eps))) - (Math.sin(x) * eps);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (math.cos((x + eps)) - math.cos(x)) <= -5e-6:
		tmp = math.tan((eps / 2.0)) * (math.sin(eps) / -1.0)
	else:
		tmp = (math.cos(x) * (-0.5 * (eps * eps))) - (math.sin(x) * eps)
	return tmp
function code(x, eps)
	tmp = 0.0
	if (Float64(cos(Float64(x + eps)) - cos(x)) <= -5e-6)
		tmp = Float64(tan(Float64(eps / 2.0)) * Float64(sin(eps) / -1.0));
	else
		tmp = Float64(Float64(cos(x) * Float64(-0.5 * Float64(eps * eps))) - Float64(sin(x) * eps));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((cos((x + eps)) - cos(x)) <= -5e-6)
		tmp = tan((eps / 2.0)) * (sin(eps) / -1.0);
	else
		tmp = (cos(x) * (-0.5 * (eps * eps))) - (sin(x) * eps);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[LessEqual[N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision], -5e-6], N[(N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[eps], $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[x], $MachinePrecision] * N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(x + \varepsilon\right) - \cos x \leq -5 \cdot 10^{-6}:\\
\;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \frac{\sin \varepsilon}{-1}\\

\mathbf{else}:\\
\;\;\;\;\cos x \cdot \left(-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\right) - \sin x \cdot \varepsilon\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 99.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.38 \cdot 10^{-15} \lor \neg \left(x \leq 1.95 \cdot 10^{-19}\right):\\ \;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin x \cdot \sin \varepsilon\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= x -1.38e-15) (not (<= x 1.95e-19)))
   (- (* (cos x) (+ (cos eps) -1.0)) (* (sin x) (sin eps)))
   (* -2.0 (* (sin (/ (+ eps (- x x)) 2.0)) (sin (/ (+ eps (+ x x)) 2.0))))))
double code(double x, double eps) {
	double tmp;
	if ((x <= -1.38e-15) || !(x <= 1.95e-19)) {
		tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps));
	} else {
		tmp = -2.0 * (sin(((eps + (x - x)) / 2.0)) * sin(((eps + (x + x)) / 2.0)));
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((x <= (-1.38d-15)) .or. (.not. (x <= 1.95d-19))) then
        tmp = (cos(x) * (cos(eps) + (-1.0d0))) - (sin(x) * sin(eps))
    else
        tmp = (-2.0d0) * (sin(((eps + (x - x)) / 2.0d0)) * sin(((eps + (x + x)) / 2.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((x <= -1.38e-15) || !(x <= 1.95e-19)) {
		tmp = (Math.cos(x) * (Math.cos(eps) + -1.0)) - (Math.sin(x) * Math.sin(eps));
	} else {
		tmp = -2.0 * (Math.sin(((eps + (x - x)) / 2.0)) * Math.sin(((eps + (x + x)) / 2.0)));
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (x <= -1.38e-15) or not (x <= 1.95e-19):
		tmp = (math.cos(x) * (math.cos(eps) + -1.0)) - (math.sin(x) * math.sin(eps))
	else:
		tmp = -2.0 * (math.sin(((eps + (x - x)) / 2.0)) * math.sin(((eps + (x + x)) / 2.0)))
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((x <= -1.38e-15) || !(x <= 1.95e-19))
		tmp = Float64(Float64(cos(x) * Float64(cos(eps) + -1.0)) - Float64(sin(x) * sin(eps)));
	else
		tmp = Float64(-2.0 * Float64(sin(Float64(Float64(eps + Float64(x - x)) / 2.0)) * sin(Float64(Float64(eps + Float64(x + x)) / 2.0))));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((x <= -1.38e-15) || ~((x <= 1.95e-19)))
		tmp = (cos(x) * (cos(eps) + -1.0)) - (sin(x) * sin(eps));
	else
		tmp = -2.0 * (sin(((eps + (x - x)) / 2.0)) * sin(((eps + (x + x)) / 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[x, -1.38e-15], N[Not[LessEqual[x, 1.95e-19]], $MachinePrecision]], N[(N[(N[Cos[x], $MachinePrecision] * N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[x], $MachinePrecision] * N[Sin[eps], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.38 \cdot 10^{-15} \lor \neg \left(x \leq 1.95 \cdot 10^{-19}\right):\\
\;\;\;\;\cos x \cdot \left(\cos \varepsilon + -1\right) - \sin x \cdot \sin \varepsilon\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 76.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ -2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (* -2.0 (* (sin (/ (+ eps (- x x)) 2.0)) (sin (/ (+ eps (+ x x)) 2.0)))))
double code(double x, double eps) {
	return -2.0 * (sin(((eps + (x - x)) / 2.0)) * sin(((eps + (x + x)) / 2.0)));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = (-2.0d0) * (sin(((eps + (x - x)) / 2.0d0)) * sin(((eps + (x + x)) / 2.0d0)))
end function
public static double code(double x, double eps) {
	return -2.0 * (Math.sin(((eps + (x - x)) / 2.0)) * Math.sin(((eps + (x + x)) / 2.0)));
}
def code(x, eps):
	return -2.0 * (math.sin(((eps + (x - x)) / 2.0)) * math.sin(((eps + (x + x)) / 2.0)))
function code(x, eps)
	return Float64(-2.0 * Float64(sin(Float64(Float64(eps + Float64(x - x)) / 2.0)) * sin(Float64(Float64(eps + Float64(x + x)) / 2.0))))
end
function tmp = code(x, eps)
	tmp = -2.0 * (sin(((eps + (x - x)) / 2.0)) * sin(((eps + (x + x)) / 2.0)));
end
code[x_, eps_] := N[(-2.0 * N[(N[Sin[N[(N[(eps + N[(x - x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(eps + N[(x + x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-2 \cdot \left(\sin \left(\frac{\varepsilon + \left(x - x\right)}{2}\right) \cdot \sin \left(\frac{\varepsilon + \left(x + x\right)}{2}\right)\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 69.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{-56} \lor \neg \left(x \leq 3.3 \cdot 10^{-80}\right):\\ \;\;\;\;\left(\sin x \cdot -2\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot {t_0}^{2}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (sin (* eps 0.5))))
   (if (or (<= x -3.2e-56) (not (<= x 3.3e-80)))
     (* (* (sin x) -2.0) t_0)
     (* -2.0 (pow t_0 2.0)))))
double code(double x, double eps) {
	double t_0 = sin((eps * 0.5));
	double tmp;
	if ((x <= -3.2e-56) || !(x <= 3.3e-80)) {
		tmp = (sin(x) * -2.0) * t_0;
	} 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((eps * 0.5d0))
    if ((x <= (-3.2d-56)) .or. (.not. (x <= 3.3d-80))) then
        tmp = (sin(x) * (-2.0d0)) * t_0
    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((eps * 0.5));
	double tmp;
	if ((x <= -3.2e-56) || !(x <= 3.3e-80)) {
		tmp = (Math.sin(x) * -2.0) * t_0;
	} else {
		tmp = -2.0 * Math.pow(t_0, 2.0);
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.sin((eps * 0.5))
	tmp = 0
	if (x <= -3.2e-56) or not (x <= 3.3e-80):
		tmp = (math.sin(x) * -2.0) * t_0
	else:
		tmp = -2.0 * math.pow(t_0, 2.0)
	return tmp
function code(x, eps)
	t_0 = sin(Float64(eps * 0.5))
	tmp = 0.0
	if ((x <= -3.2e-56) || !(x <= 3.3e-80))
		tmp = Float64(Float64(sin(x) * -2.0) * t_0);
	else
		tmp = Float64(-2.0 * (t_0 ^ 2.0));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = sin((eps * 0.5));
	tmp = 0.0;
	if ((x <= -3.2e-56) || ~((x <= 3.3e-80)))
		tmp = (sin(x) * -2.0) * t_0;
	else
		tmp = -2.0 * (t_0 ^ 2.0);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[x, -3.2e-56], N[Not[LessEqual[x, 3.3e-80]], $MachinePrecision]], N[(N[(N[Sin[x], $MachinePrecision] * -2.0), $MachinePrecision] * t$95$0), $MachinePrecision], N[(-2.0 * N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin \left(\varepsilon \cdot 0.5\right)\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{-56} \lor \neg \left(x \leq 3.3 \cdot 10^{-80}\right):\\
\;\;\;\;\left(\sin x \cdot -2\right) \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;-2 \cdot {t_0}^{2}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 69.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{-56} \lor \neg \left(x \leq 3.3 \cdot 10^{-80}\right):\\ \;\;\;\;\left(\sin x \cdot -2\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \frac{\sin \varepsilon}{-1}\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= x -2.6e-56) (not (<= x 3.3e-80)))
   (* (* (sin x) -2.0) (sin (* eps 0.5)))
   (* (tan (/ eps 2.0)) (/ (sin eps) -1.0))))
double code(double x, double eps) {
	double tmp;
	if ((x <= -2.6e-56) || !(x <= 3.3e-80)) {
		tmp = (sin(x) * -2.0) * sin((eps * 0.5));
	} else {
		tmp = tan((eps / 2.0)) * (sin(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 ((x <= (-2.6d-56)) .or. (.not. (x <= 3.3d-80))) then
        tmp = (sin(x) * (-2.0d0)) * sin((eps * 0.5d0))
    else
        tmp = tan((eps / 2.0d0)) * (sin(eps) / (-1.0d0))
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((x <= -2.6e-56) || !(x <= 3.3e-80)) {
		tmp = (Math.sin(x) * -2.0) * Math.sin((eps * 0.5));
	} else {
		tmp = Math.tan((eps / 2.0)) * (Math.sin(eps) / -1.0);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (x <= -2.6e-56) or not (x <= 3.3e-80):
		tmp = (math.sin(x) * -2.0) * math.sin((eps * 0.5))
	else:
		tmp = math.tan((eps / 2.0)) * (math.sin(eps) / -1.0)
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((x <= -2.6e-56) || !(x <= 3.3e-80))
		tmp = Float64(Float64(sin(x) * -2.0) * sin(Float64(eps * 0.5)));
	else
		tmp = Float64(tan(Float64(eps / 2.0)) * Float64(sin(eps) / -1.0));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((x <= -2.6e-56) || ~((x <= 3.3e-80)))
		tmp = (sin(x) * -2.0) * sin((eps * 0.5));
	else
		tmp = tan((eps / 2.0)) * (sin(eps) / -1.0);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[x, -2.6e-56], N[Not[LessEqual[x, 3.3e-80]], $MachinePrecision]], N[(N[(N[Sin[x], $MachinePrecision] * -2.0), $MachinePrecision] * N[Sin[N[(eps * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Tan[N[(eps / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[eps], $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-56} \lor \neg \left(x \leq 3.3 \cdot 10^{-80}\right):\\
\;\;\;\;\left(\sin x \cdot -2\right) \cdot \sin \left(\varepsilon \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\tan \left(\frac{\varepsilon}{2}\right) \cdot \frac{\sin \varepsilon}{-1}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 66.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -1.9 \cdot 10^{-25} \lor \neg \left(\varepsilon \leq 4.9 \cdot 10^{-92}\right):\\ \;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -1.9e-25) (not (<= eps 4.9e-92)))
   (* -2.0 (pow (sin (* eps 0.5)) 2.0))
   (* (sin x) (- eps))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -1.9e-25) || !(eps <= 4.9e-92)) {
		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 ((eps <= (-1.9d-25)) .or. (.not. (eps <= 4.9d-92))) 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 ((eps <= -1.9e-25) || !(eps <= 4.9e-92)) {
		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 (eps <= -1.9e-25) or not (eps <= 4.9e-92):
		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 ((eps <= -1.9e-25) || !(eps <= 4.9e-92))
		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 ((eps <= -1.9e-25) || ~((eps <= 4.9e-92)))
		tmp = -2.0 * (sin((eps * 0.5)) ^ 2.0);
	else
		tmp = sin(x) * -eps;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -1.9e-25], N[Not[LessEqual[eps, 4.9e-92]], $MachinePrecision]], 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}\;\varepsilon \leq -1.9 \cdot 10^{-25} \lor \neg \left(\varepsilon \leq 4.9 \cdot 10^{-92}\right):\\
\;\;\;\;-2 \cdot {\sin \left(\varepsilon \cdot 0.5\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 67.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \varepsilon - \cos x\\ \mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-94}:\\ \;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\ \mathbf{elif}\;\varepsilon \leq 9.2 \cdot 10^{-5}:\\ \;\;\;\;-0.5 \cdot {\varepsilon}^{2} - x \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (- (cos eps) (cos x))))
   (if (<= eps -3.8e-5)
     t_0
     (if (<= eps 2.1e-94)
       (* (sin x) (- eps))
       (if (<= eps 9.2e-5) (- (* -0.5 (pow eps 2.0)) (* x eps)) t_0)))))
double code(double x, double eps) {
	double t_0 = cos(eps) - cos(x);
	double tmp;
	if (eps <= -3.8e-5) {
		tmp = t_0;
	} else if (eps <= 2.1e-94) {
		tmp = sin(x) * -eps;
	} else if (eps <= 9.2e-5) {
		tmp = (-0.5 * pow(eps, 2.0)) - (x * eps);
	} 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) :: tmp
    t_0 = cos(eps) - cos(x)
    if (eps <= (-3.8d-5)) then
        tmp = t_0
    else if (eps <= 2.1d-94) then
        tmp = sin(x) * -eps
    else if (eps <= 9.2d-5) then
        tmp = ((-0.5d0) * (eps ** 2.0d0)) - (x * eps)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double t_0 = Math.cos(eps) - Math.cos(x);
	double tmp;
	if (eps <= -3.8e-5) {
		tmp = t_0;
	} else if (eps <= 2.1e-94) {
		tmp = Math.sin(x) * -eps;
	} else if (eps <= 9.2e-5) {
		tmp = (-0.5 * Math.pow(eps, 2.0)) - (x * eps);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.cos(eps) - math.cos(x)
	tmp = 0
	if eps <= -3.8e-5:
		tmp = t_0
	elif eps <= 2.1e-94:
		tmp = math.sin(x) * -eps
	elif eps <= 9.2e-5:
		tmp = (-0.5 * math.pow(eps, 2.0)) - (x * eps)
	else:
		tmp = t_0
	return tmp
function code(x, eps)
	t_0 = Float64(cos(eps) - cos(x))
	tmp = 0.0
	if (eps <= -3.8e-5)
		tmp = t_0;
	elseif (eps <= 2.1e-94)
		tmp = Float64(sin(x) * Float64(-eps));
	elseif (eps <= 9.2e-5)
		tmp = Float64(Float64(-0.5 * (eps ^ 2.0)) - Float64(x * eps));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = cos(eps) - cos(x);
	tmp = 0.0;
	if (eps <= -3.8e-5)
		tmp = t_0;
	elseif (eps <= 2.1e-94)
		tmp = sin(x) * -eps;
	elseif (eps <= 9.2e-5)
		tmp = (-0.5 * (eps ^ 2.0)) - (x * eps);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -3.8e-5], t$95$0, If[LessEqual[eps, 2.1e-94], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 9.2e-5], N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] - N[(x * eps), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \varepsilon - \cos x\\
\mathbf{if}\;\varepsilon \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\varepsilon \leq 2.1 \cdot 10^{-94}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\

\mathbf{elif}\;\varepsilon \leq 9.2 \cdot 10^{-5}:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2} - x \cdot \varepsilon\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 66.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \varepsilon + -1\\ \mathbf{if}\;\varepsilon \leq -1.15 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-93}:\\ \;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\ \mathbf{elif}\;\varepsilon \leq 0.000118:\\ \;\;\;\;-0.5 \cdot {\varepsilon}^{2} - x \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (cos eps) -1.0)))
   (if (<= eps -1.15e-7)
     t_0
     (if (<= eps 5.2e-93)
       (* (sin x) (- eps))
       (if (<= eps 0.000118) (- (* -0.5 (pow eps 2.0)) (* x eps)) t_0)))))
double code(double x, double eps) {
	double t_0 = cos(eps) + -1.0;
	double tmp;
	if (eps <= -1.15e-7) {
		tmp = t_0;
	} else if (eps <= 5.2e-93) {
		tmp = sin(x) * -eps;
	} else if (eps <= 0.000118) {
		tmp = (-0.5 * pow(eps, 2.0)) - (x * eps);
	} 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) :: tmp
    t_0 = cos(eps) + (-1.0d0)
    if (eps <= (-1.15d-7)) then
        tmp = t_0
    else if (eps <= 5.2d-93) then
        tmp = sin(x) * -eps
    else if (eps <= 0.000118d0) then
        tmp = ((-0.5d0) * (eps ** 2.0d0)) - (x * eps)
    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 tmp;
	if (eps <= -1.15e-7) {
		tmp = t_0;
	} else if (eps <= 5.2e-93) {
		tmp = Math.sin(x) * -eps;
	} else if (eps <= 0.000118) {
		tmp = (-0.5 * Math.pow(eps, 2.0)) - (x * eps);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.cos(eps) + -1.0
	tmp = 0
	if eps <= -1.15e-7:
		tmp = t_0
	elif eps <= 5.2e-93:
		tmp = math.sin(x) * -eps
	elif eps <= 0.000118:
		tmp = (-0.5 * math.pow(eps, 2.0)) - (x * eps)
	else:
		tmp = t_0
	return tmp
function code(x, eps)
	t_0 = Float64(cos(eps) + -1.0)
	tmp = 0.0
	if (eps <= -1.15e-7)
		tmp = t_0;
	elseif (eps <= 5.2e-93)
		tmp = Float64(sin(x) * Float64(-eps));
	elseif (eps <= 0.000118)
		tmp = Float64(Float64(-0.5 * (eps ^ 2.0)) - Float64(x * eps));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = cos(eps) + -1.0;
	tmp = 0.0;
	if (eps <= -1.15e-7)
		tmp = t_0;
	elseif (eps <= 5.2e-93)
		tmp = sin(x) * -eps;
	elseif (eps <= 0.000118)
		tmp = (-0.5 * (eps ^ 2.0)) - (x * eps);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[eps, -1.15e-7], t$95$0, If[LessEqual[eps, 5.2e-93], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.000118], N[(N[(-0.5 * N[Power[eps, 2.0], $MachinePrecision]), $MachinePrecision] - N[(x * eps), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -1.15 \cdot 10^{-7}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\varepsilon \leq 5.2 \cdot 10^{-93}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\

\mathbf{elif}\;\varepsilon \leq 0.000118:\\
\;\;\;\;-0.5 \cdot {\varepsilon}^{2} - x \cdot \varepsilon\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 65.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \varepsilon + -1\\ \mathbf{if}\;\varepsilon \leq -7.2 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\varepsilon \leq 1.4 \cdot 10^{-95}:\\ \;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\ \mathbf{elif}\;\varepsilon \leq 0.00013:\\ \;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (+ (cos eps) -1.0)))
   (if (<= eps -7.2e-6)
     t_0
     (if (<= eps 1.4e-95)
       (* (sin x) (- eps))
       (if (<= eps 0.00013) (* -0.5 (* eps eps)) t_0)))))
double code(double x, double eps) {
	double t_0 = cos(eps) + -1.0;
	double tmp;
	if (eps <= -7.2e-6) {
		tmp = t_0;
	} else if (eps <= 1.4e-95) {
		tmp = sin(x) * -eps;
	} else if (eps <= 0.00013) {
		tmp = -0.5 * (eps * eps);
	} 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) :: tmp
    t_0 = cos(eps) + (-1.0d0)
    if (eps <= (-7.2d-6)) then
        tmp = t_0
    else if (eps <= 1.4d-95) then
        tmp = sin(x) * -eps
    else if (eps <= 0.00013d0) then
        tmp = (-0.5d0) * (eps * eps)
    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 tmp;
	if (eps <= -7.2e-6) {
		tmp = t_0;
	} else if (eps <= 1.4e-95) {
		tmp = Math.sin(x) * -eps;
	} else if (eps <= 0.00013) {
		tmp = -0.5 * (eps * eps);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, eps):
	t_0 = math.cos(eps) + -1.0
	tmp = 0
	if eps <= -7.2e-6:
		tmp = t_0
	elif eps <= 1.4e-95:
		tmp = math.sin(x) * -eps
	elif eps <= 0.00013:
		tmp = -0.5 * (eps * eps)
	else:
		tmp = t_0
	return tmp
function code(x, eps)
	t_0 = Float64(cos(eps) + -1.0)
	tmp = 0.0
	if (eps <= -7.2e-6)
		tmp = t_0;
	elseif (eps <= 1.4e-95)
		tmp = Float64(sin(x) * Float64(-eps));
	elseif (eps <= 0.00013)
		tmp = Float64(-0.5 * Float64(eps * eps));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, eps)
	t_0 = cos(eps) + -1.0;
	tmp = 0.0;
	if (eps <= -7.2e-6)
		tmp = t_0;
	elseif (eps <= 1.4e-95)
		tmp = sin(x) * -eps;
	elseif (eps <= 0.00013)
		tmp = -0.5 * (eps * eps);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[eps, -7.2e-6], t$95$0, If[LessEqual[eps, 1.4e-95], N[(N[Sin[x], $MachinePrecision] * (-eps)), $MachinePrecision], If[LessEqual[eps, 0.00013], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \varepsilon + -1\\
\mathbf{if}\;\varepsilon \leq -7.2 \cdot 10^{-6}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\varepsilon \leq 1.4 \cdot 10^{-95}:\\
\;\;\;\;\sin x \cdot \left(-\varepsilon\right)\\

\mathbf{elif}\;\varepsilon \leq 0.00013:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 46.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\varepsilon \leq -0.00015 \lor \neg \left(\varepsilon \leq 0.00013\right):\\ \;\;\;\;\cos \varepsilon + -1\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (if (or (<= eps -0.00015) (not (<= eps 0.00013)))
   (+ (cos eps) -1.0)
   (* -0.5 (* eps eps))))
double code(double x, double eps) {
	double tmp;
	if ((eps <= -0.00015) || !(eps <= 0.00013)) {
		tmp = cos(eps) + -1.0;
	} else {
		tmp = -0.5 * (eps * eps);
	}
	return tmp;
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: tmp
    if ((eps <= (-0.00015d0)) .or. (.not. (eps <= 0.00013d0))) then
        tmp = cos(eps) + (-1.0d0)
    else
        tmp = (-0.5d0) * (eps * eps)
    end if
    code = tmp
end function
public static double code(double x, double eps) {
	double tmp;
	if ((eps <= -0.00015) || !(eps <= 0.00013)) {
		tmp = Math.cos(eps) + -1.0;
	} else {
		tmp = -0.5 * (eps * eps);
	}
	return tmp;
}
def code(x, eps):
	tmp = 0
	if (eps <= -0.00015) or not (eps <= 0.00013):
		tmp = math.cos(eps) + -1.0
	else:
		tmp = -0.5 * (eps * eps)
	return tmp
function code(x, eps)
	tmp = 0.0
	if ((eps <= -0.00015) || !(eps <= 0.00013))
		tmp = Float64(cos(eps) + -1.0);
	else
		tmp = Float64(-0.5 * Float64(eps * eps));
	end
	return tmp
end
function tmp_2 = code(x, eps)
	tmp = 0.0;
	if ((eps <= -0.00015) || ~((eps <= 0.00013)))
		tmp = cos(eps) + -1.0;
	else
		tmp = -0.5 * (eps * eps);
	end
	tmp_2 = tmp;
end
code[x_, eps_] := If[Or[LessEqual[eps, -0.00015], N[Not[LessEqual[eps, 0.00013]], $MachinePrecision]], N[(N[Cos[eps], $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -0.00015 \lor \neg \left(\varepsilon \leq 0.00013\right):\\
\;\;\;\;\cos \varepsilon + -1\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 22.1% accurate, 41.0× speedup?

\[\begin{array}{l} \\ -0.5 \cdot \left(\varepsilon \cdot \varepsilon\right) \end{array} \]
(FPCore (x eps) :precision binary64 (* -0.5 (* eps eps)))
double code(double x, double eps) {
	return -0.5 * (eps * eps);
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = (-0.5d0) * (eps * eps)
end function
public static double code(double x, double eps) {
	return -0.5 * (eps * eps);
}
def code(x, eps):
	return -0.5 * (eps * eps)
function code(x, eps)
	return Float64(-0.5 * Float64(eps * eps))
end
function tmp = code(x, eps)
	tmp = -0.5 * (eps * eps);
end
code[x_, eps_] := N[(-0.5 * N[(eps * eps), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-0.5 \cdot \left(\varepsilon \cdot \varepsilon\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2023341 
(FPCore (x eps)
  :name "2cos (problem 3.3.5)"
  :precision binary64
  (- (cos (+ x eps)) (cos x)))