mixedcos

Percentage Accurate: 66.4% → 97.1%
Time: 29.0s
Alternatives: 9
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 9 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.4% 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| \\ s_m = \left|s\right| \\ [x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\ \\ \frac{\frac{1}{c\_m}}{s\_m \cdot x} \cdot \frac{\frac{\cos \left(x \cdot 2\right)}{s\_m \cdot x}}{c\_m} \end{array} \]
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c_m s_m)
 :precision binary64
 (* (/ (/ 1.0 c_m) (* s_m x)) (/ (/ (cos (* x 2.0)) (* s_m x)) c_m)))
c_m = fabs(c);
s_m = fabs(s);
assert(x < c_m && c_m < s_m);
double code(double x, double c_m, double s_m) {
	return ((1.0 / c_m) / (s_m * x)) * ((cos((x * 2.0)) / (s_m * x)) / c_m);
}
c_m = abs(c)
s_m = abs(s)
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c_m, s_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    code = ((1.0d0 / c_m) / (s_m * x)) * ((cos((x * 2.0d0)) / (s_m * x)) / c_m)
end function
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x < c_m && c_m < s_m;
public static double code(double x, double c_m, double s_m) {
	return ((1.0 / c_m) / (s_m * x)) * ((Math.cos((x * 2.0)) / (s_m * x)) / c_m);
}
c_m = math.fabs(c)
s_m = math.fabs(s)
[x, c_m, s_m] = sort([x, c_m, s_m])
def code(x, c_m, s_m):
	return ((1.0 / c_m) / (s_m * x)) * ((math.cos((x * 2.0)) / (s_m * x)) / c_m)
c_m = abs(c)
s_m = abs(s)
x, c_m, s_m = sort([x, c_m, s_m])
function code(x, c_m, s_m)
	return Float64(Float64(Float64(1.0 / c_m) / Float64(s_m * x)) * Float64(Float64(cos(Float64(x * 2.0)) / Float64(s_m * x)) / c_m))
end
c_m = abs(c);
s_m = abs(s);
x, c_m, s_m = num2cell(sort([x, c_m, s_m])){:}
function tmp = code(x, c_m, s_m)
	tmp = ((1.0 / c_m) / (s_m * x)) * ((cos((x * 2.0)) / (s_m * x)) / c_m);
end
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c_m, and s_m should be sorted in increasing order before calling this function.
code[x_, c$95$m_, s$95$m_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(s$95$m * x), $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(s$95$m * x), $MachinePrecision]), $MachinePrecision] / c$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x, c_m, s_m] = \mathsf{sort}([x, c_m, s_m])\\
\\
\frac{\frac{1}{c\_m}}{s\_m \cdot x} \cdot \frac{\frac{\cos \left(x \cdot 2\right)}{s\_m \cdot x}}{c\_m}
\end{array}
Derivation
  1. Initial program 65.8%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Applied egg-rr95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}} \]
  6. Taylor expanded in c around 0 95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(s \cdot x\right)}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  7. Step-by-step derivation
    1. associate-/r*95.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  8. Simplified95.7%

    \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  9. Step-by-step derivation
    1. associate-/r*95.6%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c}}{x \cdot s}} \]
    2. div-inv95.6%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\left(\frac{\cos \left(2 \cdot x\right)}{c} \cdot \frac{1}{x \cdot s}\right)} \]
    3. *-commutative95.6%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \left(\frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c} \cdot \frac{1}{x \cdot s}\right) \]
  10. Applied egg-rr95.6%

    \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\left(\frac{\cos \left(x \cdot 2\right)}{c} \cdot \frac{1}{x \cdot s}\right)} \]
  11. Step-by-step derivation
    1. associate-*l/95.6%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\cos \left(x \cdot 2\right) \cdot \frac{1}{x \cdot s}}{c}} \]
    2. un-div-inv95.6%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{x \cdot s}}}{c} \]
  12. Applied egg-rr95.6%

    \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot s}}{c}} \]
  13. Final simplification95.6%

    \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{\cos \left(x \cdot 2\right)}{s \cdot x}}{c} \]
  14. Add Preprocessing

Alternative 2: 97.0% accurate, 2.7× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Applied egg-rr95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}} \]
  6. Taylor expanded in c around 0 95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(s \cdot x\right)}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  7. Step-by-step derivation
    1. associate-/r*95.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  8. Simplified95.7%

    \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)} \]
  9. Final simplification95.7%

    \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \]
  10. Add Preprocessing

Alternative 3: 97.0% accurate, 2.7× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Applied egg-rr95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}} \]
  6. Final simplification95.7%

    \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left(s \cdot x\right)} \]
  7. Add Preprocessing

Alternative 4: 97.3% accurate, 2.7× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Applied egg-rr95.2%

    \[\leadsto \color{blue}{{\left(\frac{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}{\cos \left(2 \cdot x\right)}\right)}^{-1}} \]
  6. Step-by-step derivation
    1. unpow-195.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}{\cos \left(2 \cdot x\right)}}} \]
    2. clear-num95.2%

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
    3. unpow295.2%

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    4. associate-/r*95.8%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}} \]
    5. *-commutative95.8%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)} \]
    6. *-commutative95.8%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{\color{blue}{\left(x \cdot s\right) \cdot c}}}{c \cdot \left(x \cdot s\right)} \]
    7. associate-*l*93.7%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{\color{blue}{x \cdot \left(s \cdot c\right)}}}{c \cdot \left(x \cdot s\right)} \]
    8. *-commutative93.7%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \color{blue}{\left(c \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
    9. *-commutative93.7%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot s\right)}}{\color{blue}{\left(x \cdot s\right) \cdot c}} \]
    10. associate-*l*97.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot s\right)}}{\color{blue}{x \cdot \left(s \cdot c\right)}} \]
    11. *-commutative97.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot s\right)}}{x \cdot \color{blue}{\left(c \cdot s\right)}} \]
  7. Applied egg-rr97.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot s\right)}}{x \cdot \left(c \cdot s\right)}} \]
  8. Add Preprocessing

Alternative 5: 80.0% accurate, 3.0× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 56.3%

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  6. Step-by-step derivation
    1. associate-/r*55.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    2. *-commutative55.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot x\right)} \cdot {s}^{2}} \]
    4. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
    5. swap-sqr68.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}} \]
    6. unpow268.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{\left(x \cdot s\right)}^{2}}} \]
    7. associate-/r*68.8%

      \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot {\left(x \cdot s\right)}^{2}}} \]
    8. unpow268.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(x \cdot s\right)}^{2}} \]
    9. unpow268.8%

      \[\leadsto \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}} \]
    10. swap-sqr80.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    11. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  7. Simplified80.6%

    \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  8. Taylor expanded in c around 0 56.3%

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  9. Step-by-step derivation
    1. associate-*r*56.8%

      \[\leadsto \frac{1}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
    2. unpow256.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right) \cdot {x}^{2}} \]
    3. unpow256.8%

      \[\leadsto \frac{1}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right) \cdot {x}^{2}} \]
    4. swap-sqr68.9%

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)} \cdot {x}^{2}} \]
    5. unpow268.9%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot s\right)}^{2}} \cdot {x}^{2}} \]
    6. *-commutative68.9%

      \[\leadsto \frac{1}{\color{blue}{{x}^{2} \cdot {\left(c \cdot s\right)}^{2}}} \]
    7. unpow268.9%

      \[\leadsto \frac{1}{\color{blue}{\left(x \cdot x\right)} \cdot {\left(c \cdot s\right)}^{2}} \]
    8. unpow268.9%

      \[\leadsto \frac{1}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}} \]
    9. swap-sqr81.9%

      \[\leadsto \frac{1}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
    10. associate-/l/81.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot \left(c \cdot s\right)}}{x \cdot \left(c \cdot s\right)}} \]
    11. *-rgt-identity81.9%

      \[\leadsto \frac{\color{blue}{\frac{1}{x \cdot \left(c \cdot s\right)} \cdot 1}}{x \cdot \left(c \cdot s\right)} \]
    12. associate-*r/81.9%

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left(c \cdot s\right)} \cdot \frac{1}{x \cdot \left(c \cdot s\right)}} \]
    13. unpow-181.9%

      \[\leadsto \color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{-1}} \cdot \frac{1}{x \cdot \left(c \cdot s\right)} \]
    14. unpow-181.9%

      \[\leadsto {\left(x \cdot \left(c \cdot s\right)\right)}^{-1} \cdot \color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{-1}} \]
    15. pow-sqr81.9%

      \[\leadsto \color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{\left(2 \cdot -1\right)}} \]
    16. metadata-eval81.9%

      \[\leadsto {\left(x \cdot \left(c \cdot s\right)\right)}^{\color{blue}{-2}} \]
    17. *-commutative81.9%

      \[\leadsto {\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{-2} \]
    18. associate-*r*80.6%

      \[\leadsto {\color{blue}{\left(c \cdot \left(s \cdot x\right)\right)}}^{-2} \]
  10. Simplified80.6%

    \[\leadsto \color{blue}{{\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
  11. Add Preprocessing

Alternative 6: 80.0% accurate, 24.1× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Applied egg-rr95.7%

    \[\leadsto \color{blue}{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}} \]
  6. Taylor expanded in x around 0 80.5%

    \[\leadsto \frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\color{blue}{1}}{c \cdot \left(x \cdot s\right)} \]
  7. Step-by-step derivation
    1. un-div-inv80.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}} \]
    2. *-commutative80.5%

      \[\leadsto \frac{\frac{1}{c \cdot \color{blue}{\left(s \cdot x\right)}}}{c \cdot \left(x \cdot s\right)} \]
    3. associate-/r*80.5%

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{c}}{s \cdot x}}}{c \cdot \left(x \cdot s\right)} \]
    4. *-commutative80.5%

      \[\leadsto \frac{\frac{\frac{1}{c}}{s \cdot x}}{c \cdot \color{blue}{\left(s \cdot x\right)}} \]
  8. Applied egg-rr80.5%

    \[\leadsto \color{blue}{\frac{\frac{\frac{1}{c}}{s \cdot x}}{c \cdot \left(s \cdot x\right)}} \]
  9. Add Preprocessing

Alternative 7: 78.7% accurate, 24.1× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 56.3%

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  6. Step-by-step derivation
    1. associate-/r*55.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    2. *-commutative55.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot x\right)} \cdot {s}^{2}} \]
    4. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
    5. swap-sqr68.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}} \]
    6. unpow268.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{\left(x \cdot s\right)}^{2}}} \]
    7. associate-/r*68.8%

      \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot {\left(x \cdot s\right)}^{2}}} \]
    8. unpow268.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(x \cdot s\right)}^{2}} \]
    9. unpow268.8%

      \[\leadsto \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}} \]
    10. swap-sqr80.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    11. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  7. Simplified80.6%

    \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  8. Step-by-step derivation
    1. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    2. associate-*r*79.5%

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
    3. associate-*l*79.0%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot x\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}} \]
    4. *-commutative79.0%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)} \]
    5. associate-*l*80.7%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \color{blue}{\left(x \cdot \left(s \cdot c\right)\right)}\right)} \]
    6. *-commutative80.7%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \left(x \cdot \color{blue}{\left(c \cdot s\right)}\right)\right)} \]
  9. Applied egg-rr80.7%

    \[\leadsto \frac{1}{\color{blue}{\left(c \cdot x\right) \cdot \left(s \cdot \left(x \cdot \left(c \cdot s\right)\right)\right)}} \]
  10. Step-by-step derivation
    1. associate-*r*80.9%

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
    2. associate-*r*79.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right)} \cdot \left(x \cdot \left(c \cdot s\right)\right)} \]
    3. associate-*r*79.5%

      \[\leadsto \frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \color{blue}{\left(\left(x \cdot c\right) \cdot s\right)}} \]
    4. *-commutative79.5%

      \[\leadsto \frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{\left(c \cdot x\right)} \cdot s\right)} \]
    5. associate-*r*80.6%

      \[\leadsto \frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}} \]
    6. associate-/r*80.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}} \]
    7. *-rgt-identity80.5%

      \[\leadsto \frac{\color{blue}{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot 1}}{c \cdot \left(x \cdot s\right)} \]
    8. associate-*r*79.5%

      \[\leadsto \frac{\frac{1}{c \cdot \left(x \cdot s\right)} \cdot 1}{\color{blue}{\left(c \cdot x\right) \cdot s}} \]
    9. times-frac77.2%

      \[\leadsto \color{blue}{\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c \cdot x} \cdot \frac{1}{s}} \]
    10. *-commutative77.2%

      \[\leadsto \frac{\frac{1}{c \cdot \color{blue}{\left(s \cdot x\right)}}}{c \cdot x} \cdot \frac{1}{s} \]
    11. associate-/r*77.2%

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{c}}{s \cdot x}}}{c \cdot x} \cdot \frac{1}{s} \]
  11. Applied egg-rr77.2%

    \[\leadsto \color{blue}{\frac{\frac{\frac{1}{c}}{s \cdot x}}{c \cdot x} \cdot \frac{1}{s}} \]
  12. Step-by-step derivation
    1. frac-times79.5%

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{c}}{s \cdot x} \cdot 1}{\left(c \cdot x\right) \cdot s}} \]
    2. *-commutative79.5%

      \[\leadsto \frac{\frac{\frac{1}{c}}{s \cdot x} \cdot 1}{\color{blue}{\left(x \cdot c\right)} \cdot s} \]
    3. associate-*r*79.8%

      \[\leadsto \frac{\frac{\frac{1}{c}}{s \cdot x} \cdot 1}{\color{blue}{x \cdot \left(c \cdot s\right)}} \]
    4. *-rgt-identity79.8%

      \[\leadsto \frac{\color{blue}{\frac{\frac{1}{c}}{s \cdot x}}}{x \cdot \left(c \cdot s\right)} \]
    5. associate-/l/79.8%

      \[\leadsto \frac{\color{blue}{\frac{1}{\left(s \cdot x\right) \cdot c}}}{x \cdot \left(c \cdot s\right)} \]
    6. *-commutative79.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{\left(x \cdot s\right)} \cdot c}}{x \cdot \left(c \cdot s\right)} \]
    7. associate-*r*81.9%

      \[\leadsto \frac{\frac{1}{\color{blue}{x \cdot \left(s \cdot c\right)}}}{x \cdot \left(c \cdot s\right)} \]
    8. *-commutative81.9%

      \[\leadsto \frac{\frac{1}{x \cdot \color{blue}{\left(c \cdot s\right)}}}{x \cdot \left(c \cdot s\right)} \]
  13. Applied egg-rr81.9%

    \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot \left(c \cdot s\right)}}{x \cdot \left(c \cdot s\right)}} \]
  14. Add Preprocessing

Alternative 8: 78.7% accurate, 24.1× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 56.3%

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  6. Step-by-step derivation
    1. associate-/r*55.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    2. *-commutative55.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot x\right)} \cdot {s}^{2}} \]
    4. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
    5. swap-sqr68.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}} \]
    6. unpow268.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{\left(x \cdot s\right)}^{2}}} \]
    7. associate-/r*68.8%

      \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot {\left(x \cdot s\right)}^{2}}} \]
    8. unpow268.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(x \cdot s\right)}^{2}} \]
    9. unpow268.8%

      \[\leadsto \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}} \]
    10. swap-sqr80.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    11. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  7. Simplified80.6%

    \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  8. Step-by-step derivation
    1. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    2. *-commutative80.6%

      \[\leadsto \frac{1}{\color{blue}{\left(\left(x \cdot s\right) \cdot c\right)} \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
    3. associate-*l*79.8%

      \[\leadsto \frac{1}{\color{blue}{\left(x \cdot \left(s \cdot c\right)\right)} \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
    4. *-commutative79.8%

      \[\leadsto \frac{1}{\left(x \cdot \color{blue}{\left(c \cdot s\right)}\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
    5. *-commutative79.8%

      \[\leadsto \frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}} \]
    6. associate-*l*81.9%

      \[\leadsto \frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot \left(s \cdot c\right)\right)}} \]
    7. *-commutative81.9%

      \[\leadsto \frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \color{blue}{\left(c \cdot s\right)}\right)} \]
  9. Applied egg-rr81.9%

    \[\leadsto \frac{1}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
  10. Add Preprocessing

Alternative 9: 74.5% accurate, 24.1× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-/r*65.6%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. cos-neg65.6%

      \[\leadsto \frac{\frac{\color{blue}{\cos \left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    3. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(2 \cdot \left(-x\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    4. distribute-rgt-neg-out65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(-2 \cdot x\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    5. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(-\color{blue}{x \cdot 2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    6. distribute-rgt-neg-in65.6%

      \[\leadsto \frac{\frac{\cos \color{blue}{\left(x \cdot \left(-2\right)\right)}}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    7. metadata-eval65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot \color{blue}{-2}\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x} \]
    8. *-commutative65.6%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x} \]
    9. associate-*l*59.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{\color{blue}{{s}^{2} \cdot \left(x \cdot x\right)}} \]
    10. unpow259.1%

      \[\leadsto \frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot \color{blue}{{x}^{2}}} \]
  3. Simplified59.1%

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 56.3%

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  6. Step-by-step derivation
    1. associate-/r*55.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    2. *-commutative55.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot x\right)} \cdot {s}^{2}} \]
    4. unpow255.5%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
    5. swap-sqr68.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}} \]
    6. unpow268.0%

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{\left(x \cdot s\right)}^{2}}} \]
    7. associate-/r*68.8%

      \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot {\left(x \cdot s\right)}^{2}}} \]
    8. unpow268.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(x \cdot s\right)}^{2}} \]
    9. unpow268.8%

      \[\leadsto \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}} \]
    10. swap-sqr80.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    11. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  7. Simplified80.6%

    \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}} \]
  8. Step-by-step derivation
    1. unpow280.6%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    2. associate-*r*79.5%

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
    3. associate-*l*79.0%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot x\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}} \]
    4. *-commutative79.0%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)} \]
    5. associate-*l*80.7%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \color{blue}{\left(x \cdot \left(s \cdot c\right)\right)}\right)} \]
    6. *-commutative80.7%

      \[\leadsto \frac{1}{\left(c \cdot x\right) \cdot \left(s \cdot \left(x \cdot \color{blue}{\left(c \cdot s\right)}\right)\right)} \]
  9. Applied egg-rr80.7%

    \[\leadsto \frac{1}{\color{blue}{\left(c \cdot x\right) \cdot \left(s \cdot \left(x \cdot \left(c \cdot s\right)\right)\right)}} \]
  10. Add Preprocessing

Reproduce

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