mixedcos

Percentage Accurate: 66.5% → 97.4%
Time: 38.3s
Alternatives: 7
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 7 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.5% 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.4% accurate, 2.7× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \frac{\frac{\frac{\frac{1}{s\_m}}{x}}{c}}{\frac{c \cdot \left(s\_m \cdot x\right)}{\cos \left(x \cdot 2\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 s_m) x) c) (/ (* c (* s_m x)) (cos (* x 2.0)))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	return (((1.0 / s_m) / x) / c) / ((c * (s_m * x)) / cos((x * 2.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
    code = (((1.0d0 / s_m) / x) / c) / ((c * (s_m * x)) / cos((x * 2.0d0)))
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 / s_m) / x) / c) / ((c * (s_m * x)) / Math.cos((x * 2.0)));
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	return (((1.0 / s_m) / x) / c) / ((c * (s_m * x)) / math.cos((x * 2.0)))
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	return Float64(Float64(Float64(Float64(1.0 / s_m) / x) / c) / Float64(Float64(c * Float64(s_m * x)) / cos(Float64(x * 2.0))))
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 / s_m) / x) / c) / ((c * (s_m * x)) / cos((x * 2.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_] := N[(N[(N[(N[(1.0 / s$95$m), $MachinePrecision] / x), $MachinePrecision] / c), $MachinePrecision] / N[(N[(c * N[(s$95$m * x), $MachinePrecision]), $MachinePrecision] / N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\frac{\frac{\frac{\frac{1}{s\_m}}{x}}{c}}{\frac{c \cdot \left(s\_m \cdot x\right)}{\cos \left(x \cdot 2\right)}}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity70.6%

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

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

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

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

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

      \[\leadsto \frac{1}{{c}^{\color{blue}{1}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    7. pow150.0%

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

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

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{s}^{2} \cdot \color{blue}{{x}^{2}}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    11. pow-prod-down50.0%

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\sqrt{{c}^{2}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}}} \]
  4. Applied egg-rr88.8%

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

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

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

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    4. rem-sqrt-square88.8%

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \color{blue}{\left|s \cdot x\right|}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    5. unpow288.8%

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left|s \cdot x\right|}}{c \cdot \left|s \cdot x\right|}} \]
  7. Step-by-step derivation
    1. div-inv97.1%

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

      \[\leadsto \frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c \cdot \left|s \cdot x\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    3. add-sqr-sqrt53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    4. fabs-sqr53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    5. add-sqr-sqrt64.7%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(s \cdot x\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    6. add-sqr-sqrt47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \]
    7. fabs-sqr47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \]
    8. add-sqr-sqrt97.1%

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

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

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

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

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

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

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

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

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

Alternative 2: 97.4% 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 := c \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} \]
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 (* s_m x)))) (* (/ (cos (* x 2.0)) t_0) (/ 1.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 * (s_m * x);
	return (cos((x * 2.0)) / t_0) * (1.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 * (s_m * x)
    code = (cos((x * 2.0d0)) / t_0) * (1.0d0 / 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 * (s_m * x);
	return (Math.cos((x * 2.0)) / t_0) * (1.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 * (s_m * x)
	return (math.cos((x * 2.0)) / t_0) * (1.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(s_m * x))
	return Float64(Float64(cos(Float64(x * 2.0)) / t_0) * Float64(1.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 * (s_m * x);
	tmp = (cos((x * 2.0)) / t_0) * (1.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[(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}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := c \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 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity70.6%

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

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

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

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

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

      \[\leadsto \frac{1}{{c}^{\color{blue}{1}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    7. pow150.0%

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

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

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{s}^{2} \cdot \color{blue}{{x}^{2}}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    11. pow-prod-down50.0%

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\sqrt{{c}^{2}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}}} \]
  4. Applied egg-rr88.8%

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

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

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

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    4. rem-sqrt-square88.8%

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \color{blue}{\left|s \cdot x\right|}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    5. unpow288.8%

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left|s \cdot x\right|}}{c \cdot \left|s \cdot x\right|}} \]
  7. Step-by-step derivation
    1. div-inv97.1%

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

      \[\leadsto \frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c \cdot \left|s \cdot x\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    3. add-sqr-sqrt53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    4. fabs-sqr53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    5. add-sqr-sqrt64.7%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(s \cdot x\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    6. add-sqr-sqrt47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \]
    7. fabs-sqr47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \]
    8. add-sqr-sqrt97.1%

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

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

Alternative 3: 97.5% 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 := c \cdot \left(s\_m \cdot x\right)\\ \frac{\frac{\cos \left(x \cdot 2\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 (* c (* s_m x)))) (/ (/ (cos (* x 2.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 * (s_m * x);
	return (cos((x * 2.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 * (s_m * x)
    code = (cos((x * 2.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 * (s_m * x);
	return (Math.cos((x * 2.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 * (s_m * x)
	return (math.cos((x * 2.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(s_m * x))
	return Float64(Float64(cos(Float64(x * 2.0)) / 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 * (s_m * x);
	tmp = (cos((x * 2.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[(s$95$m * x), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(x * 2.0), $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 := c \cdot \left(s\_m \cdot x\right)\\
\frac{\frac{\cos \left(x \cdot 2\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity70.6%

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

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

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

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

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

      \[\leadsto \frac{1}{{c}^{\color{blue}{1}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    7. pow150.0%

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

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

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{s}^{2} \cdot \color{blue}{{x}^{2}}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    11. pow-prod-down50.0%

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\sqrt{{c}^{2}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}}} \]
  4. Applied egg-rr88.8%

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

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

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

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    4. rem-sqrt-square88.8%

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \color{blue}{\left|s \cdot x\right|}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    5. unpow288.8%

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left|s \cdot x\right|}}{c \cdot \left|s \cdot x\right|}} \]
  7. Step-by-step derivation
    1. div-inv97.1%

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

      \[\leadsto \frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c \cdot \left|s \cdot x\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    3. add-sqr-sqrt53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    4. fabs-sqr53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    5. add-sqr-sqrt64.7%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(s \cdot x\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    6. add-sqr-sqrt47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \]
    7. fabs-sqr47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \]
    8. add-sqr-sqrt97.1%

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

    \[\leadsto \color{blue}{\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left(s \cdot x\right)}} \]
  9. Step-by-step derivation
    1. un-div-inv97.1%

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

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

Alternative 4: 97.3% 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(s\_m \cdot c\right)\\ \frac{\cos \left(x \cdot 2\right)}{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 (* x (* s_m c)))) (/ (cos (* x 2.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 = x * (s_m * c);
	return cos((x * 2.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 = x * (s_m * c)
    code = cos((x * 2.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 = x * (s_m * c);
	return Math.cos((x * 2.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 = x * (s_m * c)
	return math.cos((x * 2.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(x * Float64(s_m * c))
	return Float64(cos(Float64(x * 2.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 = x * (s_m * c);
	tmp = cos((x * 2.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[(x * N[(s$95$m * c), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / 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 := x \cdot \left(s\_m \cdot c\right)\\
\frac{\cos \left(x \cdot 2\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Applied egg-rr80.1%

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

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

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

      \[\leadsto \frac{\color{blue}{\cos \left(2 \cdot x\right) \cdot {x}^{-2}}}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)} \]
    4. add-sqr-sqrt69.0%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{\cos \left(2 \cdot x\right)}}{x} \cdot \frac{\sqrt{\cos \left(2 \cdot x\right)}}{x}}}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)} \]
    12. frac-times72.2%

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{\cos \left(2 \cdot x\right)}}{x}}{c \cdot s} \cdot \frac{\frac{\sqrt{\cos \left(2 \cdot x\right)}}{x}}{c \cdot s}} \]
    13. associate-/l/72.2%

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

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

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

Alternative 5: 80.3% 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{\frac{1}{s\_m}}{x}}{c}}{c \cdot \left(s\_m \cdot x\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 s_m) x) c) (* c (* s_m x))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	return (((1.0 / s_m) / x) / c) / (c * (s_m * x));
}
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 / s_m) / x) / c) / (c * (s_m * x))
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 / s_m) / x) / c) / (c * (s_m * x));
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	return (((1.0 / s_m) / x) / c) / (c * (s_m * x))
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	return Float64(Float64(Float64(Float64(1.0 / s_m) / x) / c) / Float64(c * Float64(s_m * x)))
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 / s_m) / x) / c) / (c * (s_m * x));
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[(N[(1.0 / s$95$m), $MachinePrecision] / x), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(s$95$m * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\frac{\frac{\frac{\frac{1}{s\_m}}{x}}{c}}{c \cdot \left(s\_m \cdot x\right)}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity70.6%

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

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

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

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

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

      \[\leadsto \frac{1}{{c}^{\color{blue}{1}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    7. pow150.0%

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

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

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{s}^{2} \cdot \color{blue}{{x}^{2}}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \]
    11. pow-prod-down50.0%

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

      \[\leadsto \frac{1}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \cdot \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\sqrt{{c}^{2}} \cdot \sqrt{\left(x \cdot {s}^{2}\right) \cdot x}}} \]
  4. Applied egg-rr88.8%

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

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

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

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    4. rem-sqrt-square88.8%

      \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \color{blue}{\left|s \cdot x\right|}}}{c \cdot \sqrt{{\left(s \cdot x\right)}^{2}}} \]
    5. unpow288.8%

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left|s \cdot x\right|}}{c \cdot \left|s \cdot x\right|}} \]
  7. Step-by-step derivation
    1. div-inv97.1%

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

      \[\leadsto \frac{\cos \color{blue}{\left(x \cdot 2\right)}}{c \cdot \left|s \cdot x\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    3. add-sqr-sqrt53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    4. fabs-sqr53.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    5. add-sqr-sqrt64.7%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \color{blue}{\left(s \cdot x\right)}} \cdot \frac{1}{c \cdot \left|s \cdot x\right|} \]
    6. add-sqr-sqrt47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|} \]
    7. fabs-sqr47.5%

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(s \cdot x\right)} \cdot \frac{1}{c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}} \]
    8. add-sqr-sqrt97.1%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 80.3% 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(s\_m \cdot x\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 (* s_m x)))) (/ 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 * (s_m * x);
	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 * (s_m * x)
    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 * (s_m * x);
	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 * (s_m * x)
	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(s_m * x))
	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 * (s_m * x);
	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[(s$95$m * x), $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(s\_m \cdot x\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 59.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(s \cdot x\right)}^{2}} \]
    8. rem-square-sqrt70.0%

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

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

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

      \[\leadsto \frac{1}{{\left(c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}\right)}^{2}} \]
    12. rem-sqrt-square79.2%

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

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

      \[\leadsto \frac{1}{{\color{blue}{\left(\sqrt{c \cdot \left|s \cdot x\right|} \cdot \sqrt{c \cdot \left|s \cdot x\right|}\right)}}^{2}} \]
    2. sqrt-prod79.2%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\sqrt{c \cdot \left|s \cdot x\right|} \cdot \sqrt{c \cdot \left|s \cdot x\right|}\right)} \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    7. add-sqr-sqrt56.8%

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot \left|s \cdot x\right|\right)} \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    8. add-sqr-sqrt30.9%

      \[\leadsto \frac{1}{\left(c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|\right) \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    9. fabs-sqr30.9%

      \[\leadsto \frac{1}{\left(c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}\right) \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    10. add-sqr-sqrt60.1%

      \[\leadsto \frac{1}{\left(c \cdot \color{blue}{\left(s \cdot x\right)}\right) \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    11. unpow260.1%

      \[\leadsto \frac{1}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \sqrt{\color{blue}{\left(c \cdot \left|s \cdot x\right|\right) \cdot \left(c \cdot \left|s \cdot x\right|\right)}}} \]
    12. sqrt-prod37.4%

      \[\leadsto \frac{1}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \color{blue}{\left(\sqrt{c \cdot \left|s \cdot x\right|} \cdot \sqrt{c \cdot \left|s \cdot x\right|}\right)}} \]
    13. add-sqr-sqrt58.7%

      \[\leadsto \frac{1}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \color{blue}{\left(c \cdot \left|s \cdot x\right|\right)}} \]
    14. add-sqr-sqrt39.4%

      \[\leadsto \frac{1}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|\right)} \]
    15. fabs-sqr39.4%

      \[\leadsto \frac{1}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}\right)} \]
    16. add-sqr-sqrt79.2%

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

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

Alternative 7: 77.2% 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(s\_m \cdot c\right) \cdot \left(x \cdot \left(c \cdot \left(s\_m \cdot x\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 (* (* s_m c) (* x (* c (* s_m x))))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	return 1.0 / ((s_m * c) * (x * (c * (s_m * x))));
}
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 / ((s_m * c) * (x * (c * (s_m * x))))
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 / ((s_m * c) * (x * (c * (s_m * x))));
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	return 1.0 / ((s_m * c) * (x * (c * (s_m * x))))
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(s_m * c) * Float64(x * Float64(c * Float64(s_m * x)))))
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 / ((s_m * c) * (x * (c * (s_m * x))));
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[(s$95$m * c), $MachinePrecision] * N[(x * N[(c * N[(s$95$m * x), $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(s\_m \cdot c\right) \cdot \left(x \cdot \left(c \cdot \left(s\_m \cdot x\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 70.6%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 59.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(s \cdot x\right)}^{2}} \]
    8. rem-square-sqrt70.0%

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

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

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

      \[\leadsto \frac{1}{{\left(c \cdot \sqrt{\color{blue}{\left(s \cdot x\right) \cdot \left(s \cdot x\right)}}\right)}^{2}} \]
    12. rem-sqrt-square79.2%

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

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

      \[\leadsto \frac{1}{{\color{blue}{\left(\sqrt{c \cdot \left|s \cdot x\right|} \cdot \sqrt{c \cdot \left|s \cdot x\right|}\right)}}^{2}} \]
    2. sqrt-prod79.2%

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

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

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}} \cdot \sqrt{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}}} \]
    5. add-sqr-sqrt79.2%

      \[\leadsto \frac{1}{\color{blue}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    6. /-rgt-identity79.2%

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

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

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{{\left(c \cdot \left|s \cdot x\right|\right)}^{\left(-2\right)}}}} \]
    9. add-sqr-sqrt45.3%

      \[\leadsto \frac{1}{\frac{1}{{\left(c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|\right)}^{\left(-2\right)}}} \]
    10. fabs-sqr45.3%

      \[\leadsto \frac{1}{\frac{1}{{\left(c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}\right)}^{\left(-2\right)}}} \]
    11. add-sqr-sqrt79.2%

      \[\leadsto \frac{1}{\frac{1}{{\left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)}^{\left(-2\right)}}} \]
    12. metadata-eval79.2%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\left(c \cdot s\right) \cdot \left(x \cdot \left(c \cdot \left(s \cdot x\right)\right)\right)}} \]
  10. Final simplification78.0%

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

Reproduce

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