mixedcos

Percentage Accurate: 66.6% → 97.1%
Time: 10.9s
Alternatives: 8
Speedup: 24.1×

Specification

?
\[\begin{array}{l} \\ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
	return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
	return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s):
	return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s)
	return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x)))
end
function tmp = code(x, c, s)
	tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x));
end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\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 8 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: 66.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
	return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
	return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s):
	return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s)
	return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x)))
end
function tmp = code(x, c, s)
	tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x));
end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}

Alternative 1: 97.1% accurate, 2.7× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \frac{\frac{1}{c_m}}{s \cdot x} \cdot \frac{\cos \left(x \cdot 2\right)}{c_m \cdot \left(s \cdot x\right)} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (* (/ (/ 1.0 c_m) (* s x)) (/ (cos (* x 2.0)) (* c_m (* s x)))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	return ((1.0 / c_m) / (s * x)) * (cos((x * 2.0)) / (c_m * (s * x)));
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    code = ((1.0d0 / c_m) / (s * x)) * (cos((x * 2.0d0)) / (c_m * (s * x)))
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	return ((1.0 / c_m) / (s * x)) * (Math.cos((x * 2.0)) / (c_m * (s * x)));
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	return ((1.0 / c_m) / (s * x)) * (math.cos((x * 2.0)) / (c_m * (s * x)))
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	return Float64(Float64(Float64(1.0 / c_m) / Float64(s * x)) * Float64(cos(Float64(x * 2.0)) / Float64(c_m * Float64(s * x))))
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	tmp = ((1.0 / c_m) / (s * x)) * (cos((x * 2.0)) / (c_m * (s * x)));
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(s * x), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\frac{\frac{1}{c_m}}{s \cdot x} \cdot \frac{\cos \left(x \cdot 2\right)}{c_m \cdot \left(s \cdot x\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 86.6% accurate, 2.7× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 8 \cdot 10^{-38}:\\ \;\;\;\;{\left(\frac{s \cdot x}{\frac{1}{c_m}}\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot -2\right)}{\left(c_m \cdot x\right) \cdot \left(s \cdot \left(c_m \cdot \left(s \cdot x\right)\right)\right)}\\ \end{array} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (if (<= x 8e-38)
   (pow (/ (* s x) (/ 1.0 c_m)) -2.0)
   (/ (cos (* x -2.0)) (* (* c_m x) (* s (* c_m (* s x)))))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	double tmp;
	if (x <= 8e-38) {
		tmp = pow(((s * x) / (1.0 / c_m)), -2.0);
	} else {
		tmp = cos((x * -2.0)) / ((c_m * x) * (s * (c_m * (s * x))));
	}
	return tmp;
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 8d-38) then
        tmp = ((s * x) / (1.0d0 / c_m)) ** (-2.0d0)
    else
        tmp = cos((x * (-2.0d0))) / ((c_m * x) * (s * (c_m * (s * x))))
    end if
    code = tmp
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	double tmp;
	if (x <= 8e-38) {
		tmp = Math.pow(((s * x) / (1.0 / c_m)), -2.0);
	} else {
		tmp = Math.cos((x * -2.0)) / ((c_m * x) * (s * (c_m * (s * x))));
	}
	return tmp;
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	tmp = 0
	if x <= 8e-38:
		tmp = math.pow(((s * x) / (1.0 / c_m)), -2.0)
	else:
		tmp = math.cos((x * -2.0)) / ((c_m * x) * (s * (c_m * (s * x))))
	return tmp
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	tmp = 0.0
	if (x <= 8e-38)
		tmp = Float64(Float64(s * x) / Float64(1.0 / c_m)) ^ -2.0;
	else
		tmp = Float64(cos(Float64(x * -2.0)) / Float64(Float64(c_m * x) * Float64(s * Float64(c_m * Float64(s * x)))));
	end
	return tmp
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp_2 = code(x, c_m, s)
	tmp = 0.0;
	if (x <= 8e-38)
		tmp = ((s * x) / (1.0 / c_m)) ^ -2.0;
	else
		tmp = cos((x * -2.0)) / ((c_m * x) * (s * (c_m * (s * x))));
	end
	tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := If[LessEqual[x, 8e-38], N[Power[N[(N[(s * x), $MachinePrecision] / N[(1.0 / c$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[Cos[N[(x * -2.0), $MachinePrecision]], $MachinePrecision] / N[(N[(c$95$m * x), $MachinePrecision] * N[(s * N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8 \cdot 10^{-38}:\\
\;\;\;\;{\left(\frac{s \cdot x}{\frac{1}{c_m}}\right)}^{-2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x \cdot -2\right)}{\left(c_m \cdot x\right) \cdot \left(s \cdot \left(c_m \cdot \left(s \cdot x\right)\right)\right)}\\


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

Alternative 3: 97.1% accurate, 2.7× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \begin{array}{l} t_0 := c_m \cdot \left(s \cdot x\right)\\ \frac{1}{t_0} \cdot \frac{\cos \left(x \cdot 2\right)}{t_0} \end{array} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (let* ((t_0 (* c_m (* s x)))) (* (/ 1.0 t_0) (/ (cos (* x 2.0)) t_0))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	return (1.0 / t_0) * (cos((x * 2.0)) / t_0);
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = c_m * (s * x)
    code = (1.0d0 / t_0) * (cos((x * 2.0d0)) / t_0)
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	return (1.0 / t_0) * (Math.cos((x * 2.0)) / t_0);
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	t_0 = c_m * (s * x)
	return (1.0 / t_0) * (math.cos((x * 2.0)) / t_0)
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	t_0 = Float64(c_m * Float64(s * x))
	return Float64(Float64(1.0 / t_0) * Float64(cos(Float64(x * 2.0)) / t_0))
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	t_0 = c_m * (s * x);
	tmp = (1.0 / t_0) * (cos((x * 2.0)) / t_0);
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\begin{array}{l}
t_0 := c_m \cdot \left(s \cdot x\right)\\
\frac{1}{t_0} \cdot \frac{\cos \left(x \cdot 2\right)}{t_0}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 79.2% accurate, 2.9× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ {\left(\frac{s \cdot x}{\frac{1}{c_m}}\right)}^{-2} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s) :precision binary64 (pow (/ (* s x) (/ 1.0 c_m)) -2.0))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	return pow(((s * x) / (1.0 / c_m)), -2.0);
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    code = ((s * x) / (1.0d0 / c_m)) ** (-2.0d0)
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	return Math.pow(((s * x) / (1.0 / c_m)), -2.0);
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	return math.pow(((s * x) / (1.0 / c_m)), -2.0)
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	return Float64(Float64(s * x) / Float64(1.0 / c_m)) ^ -2.0
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	tmp = ((s * x) / (1.0 / c_m)) ^ -2.0;
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := N[Power[N[(N[(s * x), $MachinePrecision] / N[(1.0 / c$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
{\left(\frac{s \cdot x}{\frac{1}{c_m}}\right)}^{-2}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 76.5% accurate, 20.8× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \begin{array}{l} t_0 := c_m \cdot \left(s \cdot x\right)\\ \mathbf{if}\;s \leq 9.4 \cdot 10^{+253}:\\ \;\;\;\;\frac{1}{\left(c_m \cdot x\right) \cdot \left(s \cdot t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(c_m \cdot s\right) \cdot \left(x \cdot t_0\right)}\\ \end{array} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (let* ((t_0 (* c_m (* s x))))
   (if (<= s 9.4e+253)
     (/ 1.0 (* (* c_m x) (* s t_0)))
     (/ 1.0 (* (* c_m s) (* x t_0))))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	double tmp;
	if (s <= 9.4e+253) {
		tmp = 1.0 / ((c_m * x) * (s * t_0));
	} else {
		tmp = 1.0 / ((c_m * s) * (x * t_0));
	}
	return tmp;
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    real(8) :: t_0
    real(8) :: tmp
    t_0 = c_m * (s * x)
    if (s <= 9.4d+253) then
        tmp = 1.0d0 / ((c_m * x) * (s * t_0))
    else
        tmp = 1.0d0 / ((c_m * s) * (x * t_0))
    end if
    code = tmp
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	double tmp;
	if (s <= 9.4e+253) {
		tmp = 1.0 / ((c_m * x) * (s * t_0));
	} else {
		tmp = 1.0 / ((c_m * s) * (x * t_0));
	}
	return tmp;
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	t_0 = c_m * (s * x)
	tmp = 0
	if s <= 9.4e+253:
		tmp = 1.0 / ((c_m * x) * (s * t_0))
	else:
		tmp = 1.0 / ((c_m * s) * (x * t_0))
	return tmp
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	t_0 = Float64(c_m * Float64(s * x))
	tmp = 0.0
	if (s <= 9.4e+253)
		tmp = Float64(1.0 / Float64(Float64(c_m * x) * Float64(s * t_0)));
	else
		tmp = Float64(1.0 / Float64(Float64(c_m * s) * Float64(x * t_0)));
	end
	return tmp
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp_2 = code(x, c_m, s)
	t_0 = c_m * (s * x);
	tmp = 0.0;
	if (s <= 9.4e+253)
		tmp = 1.0 / ((c_m * x) * (s * t_0));
	else
		tmp = 1.0 / ((c_m * s) * (x * t_0));
	end
	tmp_2 = tmp;
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 9.4e+253], N[(1.0 / N[(N[(c$95$m * x), $MachinePrecision] * N[(s * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(c$95$m * s), $MachinePrecision] * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\begin{array}{l}
t_0 := c_m \cdot \left(s \cdot x\right)\\
\mathbf{if}\;s \leq 9.4 \cdot 10^{+253}:\\
\;\;\;\;\frac{1}{\left(c_m \cdot x\right) \cdot \left(s \cdot t_0\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(c_m \cdot s\right) \cdot \left(x \cdot t_0\right)}\\


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

Alternative 6: 79.2% accurate, 20.9× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \begin{array}{l} t_0 := \frac{\frac{\frac{1}{s}}{x}}{c_m}\\ t_0 \cdot t_0 \end{array} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (let* ((t_0 (/ (/ (/ 1.0 s) x) c_m))) (* t_0 t_0)))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	double t_0 = ((1.0 / s) / x) / c_m;
	return t_0 * t_0;
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = ((1.0d0 / s) / x) / c_m
    code = t_0 * t_0
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	double t_0 = ((1.0 / s) / x) / c_m;
	return t_0 * t_0;
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	t_0 = ((1.0 / s) / x) / c_m
	return t_0 * t_0
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	t_0 = Float64(Float64(Float64(1.0 / s) / x) / c_m)
	return Float64(t_0 * t_0)
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	t_0 = ((1.0 / s) / x) / c_m;
	tmp = t_0 * t_0;
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(N[(N[(1.0 / s), $MachinePrecision] / x), $MachinePrecision] / c$95$m), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{\frac{1}{s}}{x}}{c_m}\\
t_0 \cdot t_0
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 76.1% accurate, 24.1× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \frac{1}{\left(c_m \cdot s\right) \cdot \left(x \cdot \left(c_m \cdot \left(s \cdot x\right)\right)\right)} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (/ 1.0 (* (* c_m s) (* x (* c_m (* s x))))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	return 1.0 / ((c_m * s) * (x * (c_m * (s * x))));
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    code = 1.0d0 / ((c_m * s) * (x * (c_m * (s * x))))
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	return 1.0 / ((c_m * s) * (x * (c_m * (s * x))));
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	return 1.0 / ((c_m * s) * (x * (c_m * (s * x))))
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	return Float64(1.0 / Float64(Float64(c_m * s) * Float64(x * Float64(c_m * Float64(s * x)))))
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	tmp = 1.0 / ((c_m * s) * (x * (c_m * (s * x))));
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := N[(1.0 / N[(N[(c$95$m * s), $MachinePrecision] * N[(x * N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\frac{1}{\left(c_m \cdot s\right) \cdot \left(x \cdot \left(c_m \cdot \left(s \cdot x\right)\right)\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 79.1% accurate, 24.1× speedup?

\[\begin{array}{l} c_m = \left|c\right| \\ [x, c_m, s] = \mathsf{sort}([x, c_m, s])\\ \\ \begin{array}{l} t_0 := c_m \cdot \left(s \cdot x\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \end{array} \]
c_m = (fabs.f64 c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
(FPCore (x c_m s)
 :precision binary64
 (let* ((t_0 (* c_m (* s x)))) (/ 1.0 (* t_0 t_0))))
c_m = fabs(c);
assert(x < c_m && c_m < s);
double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	return 1.0 / (t_0 * t_0);
}
c_m = abs(c)
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = c_m * (s * x)
    code = 1.0d0 / (t_0 * t_0)
end function
c_m = Math.abs(c);
assert x < c_m && c_m < s;
public static double code(double x, double c_m, double s) {
	double t_0 = c_m * (s * x);
	return 1.0 / (t_0 * t_0);
}
c_m = math.fabs(c)
[x, c_m, s] = sort([x, c_m, s])
def code(x, c_m, s):
	t_0 = c_m * (s * x)
	return 1.0 / (t_0 * t_0)
c_m = abs(c)
x, c_m, s = sort([x, c_m, s])
function code(x, c_m, s)
	t_0 = Float64(c_m * Float64(s * x))
	return Float64(1.0 / Float64(t_0 * t_0))
end
c_m = abs(c);
x, c_m, s = num2cell(sort([x, c_m, s])){:}
function tmp = code(x, c_m, s)
	t_0 = c_m * (s * x);
	tmp = 1.0 / (t_0 * t_0);
end
c_m = N[Abs[c], $MachinePrecision]
NOTE: x, c_m, and s should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(c$95$m * N[(s * x), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
[x, c_m, s] = \mathsf{sort}([x, c_m, s])\\
\\
\begin{array}{l}
t_0 := c_m \cdot \left(s \cdot x\right)\\
\frac{1}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2023343 
(FPCore (x c s)
  :name "mixedcos"
  :precision binary64
  (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))