mixedcos

Percentage Accurate: 66.8% → 99.1%
Time: 13.6s
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.8% 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: 99.1% accurate, 0.7× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \begin{array}{l} t_0 := c \cdot \left(x \cdot s_m\right)\\ t_1 := \cos \left(2 \cdot x\right)\\ \mathbf{if}\;\frac{t_1}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s_m}^{2}\right)\right)} \leq \infty:\\ \;\;\;\;\frac{1}{t_0} \cdot \frac{t_1}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1}{x \cdot \left(c \cdot \left(-s_m\right)\right)}}{x \cdot \frac{c \cdot s_m}{t_1}}\\ \end{array} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (let* ((t_0 (* c (* x s_m))) (t_1 (cos (* 2.0 x))))
   (if (<= (/ t_1 (* (pow c 2.0) (* x (* x (pow s_m 2.0))))) INFINITY)
     (* (/ 1.0 t_0) (/ t_1 t_0))
     (/ (/ -1.0 (* x (* c (- s_m)))) (* x (/ (* c s_m) t_1))))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	double t_0 = c * (x * s_m);
	double t_1 = cos((2.0 * x));
	double tmp;
	if ((t_1 / (pow(c, 2.0) * (x * (x * pow(s_m, 2.0))))) <= ((double) INFINITY)) {
		tmp = (1.0 / t_0) * (t_1 / t_0);
	} else {
		tmp = (-1.0 / (x * (c * -s_m))) / (x * ((c * s_m) / t_1));
	}
	return tmp;
}
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	double t_0 = c * (x * s_m);
	double t_1 = Math.cos((2.0 * x));
	double tmp;
	if ((t_1 / (Math.pow(c, 2.0) * (x * (x * Math.pow(s_m, 2.0))))) <= Double.POSITIVE_INFINITY) {
		tmp = (1.0 / t_0) * (t_1 / t_0);
	} else {
		tmp = (-1.0 / (x * (c * -s_m))) / (x * ((c * s_m) / t_1));
	}
	return tmp;
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	t_0 = c * (x * s_m)
	t_1 = math.cos((2.0 * x))
	tmp = 0
	if (t_1 / (math.pow(c, 2.0) * (x * (x * math.pow(s_m, 2.0))))) <= math.inf:
		tmp = (1.0 / t_0) * (t_1 / t_0)
	else:
		tmp = (-1.0 / (x * (c * -s_m))) / (x * ((c * s_m) / t_1))
	return tmp
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	t_0 = Float64(c * Float64(x * s_m))
	t_1 = cos(Float64(2.0 * x))
	tmp = 0.0
	if (Float64(t_1 / Float64((c ^ 2.0) * Float64(x * Float64(x * (s_m ^ 2.0))))) <= Inf)
		tmp = Float64(Float64(1.0 / t_0) * Float64(t_1 / t_0));
	else
		tmp = Float64(Float64(-1.0 / Float64(x * Float64(c * Float64(-s_m)))) / Float64(x * Float64(Float64(c * s_m) / t_1)));
	end
	return tmp
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
	t_0 = c * (x * s_m);
	t_1 = cos((2.0 * x));
	tmp = 0.0;
	if ((t_1 / ((c ^ 2.0) * (x * (x * (s_m ^ 2.0))))) <= Inf)
		tmp = (1.0 / t_0) * (t_1 / t_0);
	else
		tmp = (-1.0 / (x * (c * -s_m))) / (x * ((c * s_m) / t_1));
	end
	tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[Power[c, 2.0], $MachinePrecision] * N[(x * N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / N[(x * N[(c * (-s$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[(c * s$95$m), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s_m\right)\\
t_1 := \cos \left(2 \cdot x\right)\\
\mathbf{if}\;\frac{t_1}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s_m}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;\frac{1}{t_0} \cdot \frac{t_1}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{-1}{x \cdot \left(c \cdot \left(-s_m\right)\right)}}{x \cdot \frac{c \cdot s_m}{t_1}}\\


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

Alternative 2: 93.6% accurate, 2.7× speedup?

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

Alternative 3: 94.9% accurate, 2.7× speedup?

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

Alternative 4: 97.1% accurate, 2.7× speedup?

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

Alternative 5: 79.8% accurate, 20.9× speedup?

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

Alternative 6: 76.5% accurate, 24.1× speedup?

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

Alternative 7: 79.8% accurate, 24.1× speedup?

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

Alternative 8: 79.9% accurate, 24.1× speedup?

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

Reproduce

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