mixedcos

Percentage Accurate: 67.8% → 97.3%
Time: 18.9s
Alternatives: 15
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 15 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: 67.8% accurate, 1.0× speedup?

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

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

Alternative 1: 97.3% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{1}{s}}{c \cdot x} \cdot \frac{\cos \left(x \cdot 2\right)}{s \cdot \left(c \cdot x\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (* (/ (/ 1.0 s) (* c x)) (/ (cos (* x 2.0)) (* s (* c x)))))
assert(c < s);
double code(double x, double c, double s) {
	return ((1.0 / s) / (c * x)) * (cos((x * 2.0)) / (s * (c * x)));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = ((1.0d0 / s) / (c * x)) * (cos((x * 2.0d0)) / (s * (c * x)))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return ((1.0 / s) / (c * x)) * (Math.cos((x * 2.0)) / (s * (c * x)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return ((1.0 / s) / (c * x)) * (math.cos((x * 2.0)) / (s * (c * x)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(Float64(Float64(1.0 / s) / Float64(c * x)) * Float64(cos(Float64(x * 2.0)) / Float64(s * Float64(c * x))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = ((1.0 / s) / (c * x)) * (cos((x * 2.0)) / (s * (c * x)));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(N[(N[(1.0 / s), $MachinePrecision] / N[(c * x), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{1}{s}}{c \cdot x} \cdot \frac{\cos \left(x \cdot 2\right)}{s \cdot \left(c \cdot x\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 89.4% accurate, 2.7× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 3.1000000000000002e158

    1. Initial program 67.3%

      \[\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*67.4%

        \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
      2. remove-double-neg67.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in69.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out69.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right) \cdot \left(x \cdot x\right)} \]
      5. swap-sqr71.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right)} \cdot \left(\left(s \cdot c\right) \cdot x\right)} \]
      4. swap-sqr71.3%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right) \cdot \left(x \cdot x\right)}} \]
      5. unswap-sqr61.3%

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

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

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

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

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

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

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

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

    if 3.1000000000000002e158 < s

    1. Initial program 48.3%

      \[\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*48.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg48.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right) \cdot \left(x \cdot x\right)} \]
      5. swap-sqr73.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 3.1 \cdot 10^{+158}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}\\ \end{array} \]

Alternative 3: 89.7% accurate, 2.7× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.2499999999999999e158

    1. Initial program 67.3%

      \[\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*67.4%

        \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
      2. remove-double-neg67.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in69.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out69.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right) \cdot \left(x \cdot x\right)} \]
      5. swap-sqr71.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.2499999999999999e158 < s

    1. Initial program 48.3%

      \[\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*48.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg48.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right) \cdot \left(x \cdot x\right)} \]
      5. swap-sqr73.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 1.25 \cdot 10^{+158}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(c \cdot x\right) \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}\\ \end{array} \]

Alternative 4: 86.1% accurate, 2.7× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.5000000000000001e-147

    1. Initial program 64.1%

      \[\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*64.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in66.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out66.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot \left(c \cdot s\right)\right)}} \]
      9. unpow293.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5000000000000001e-147 < x

    1. Initial program 65.9%

      \[\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*66.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in66.8%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out66.8%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg66.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(s \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(c \cdot x\right)\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{-147}:\\ \;\;\;\;\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(s \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(c \cdot x\right)\right)\right)}\\ \end{array} \]

Alternative 5: 97.2% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(c \cdot x\right)\\ \frac{\cos \left(x \cdot 2\right)}{t_0} \cdot \frac{1}{t_0} \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* s (* c x)))) (* (/ (cos (* x 2.0)) t_0) (/ 1.0 t_0))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = s * (c * x);
	return (cos((x * 2.0)) / t_0) * (1.0 / t_0);
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = s * (c * x)
    code = (cos((x * 2.0d0)) / t_0) * (1.0d0 / t_0)
end function
assert c < s;
public static double code(double x, double c, double s) {
	double t_0 = s * (c * x);
	return (Math.cos((x * 2.0)) / t_0) * (1.0 / t_0);
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = s * (c * x)
	return (math.cos((x * 2.0)) / t_0) * (1.0 / t_0)
c, s = sort([c, s])
function code(x, c, s)
	t_0 = Float64(s * Float64(c * x))
	return Float64(Float64(cos(Float64(x * 2.0)) / t_0) * Float64(1.0 / t_0))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	t_0 = s * (c * x);
	tmp = (cos((x * 2.0)) / t_0) * (1.0 / t_0);
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(s * N[(c * 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, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(c \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 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. *-un-lft-identity97.0%

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

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

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

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

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

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

Alternative 6: 97.0% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(c \cdot x\right)\\ \frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0} \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* s (* c x)))) (/ (cos (* x 2.0)) (* t_0 t_0))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = s * (c * x);
	return cos((x * 2.0)) / (t_0 * t_0);
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = s * (c * x)
    code = cos((x * 2.0d0)) / (t_0 * t_0)
end function
assert c < s;
public static double code(double x, double c, double s) {
	double t_0 = s * (c * x);
	return Math.cos((x * 2.0)) / (t_0 * t_0);
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = s * (c * x)
	return math.cos((x * 2.0)) / (t_0 * t_0)
c, s = sort([c, s])
function code(x, c, s)
	t_0 = Float64(s * Float64(c * x))
	return Float64(cos(Float64(x * 2.0)) / Float64(t_0 * t_0))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	t_0 = s * (c * x);
	tmp = cos((x * 2.0)) / (t_0 * t_0);
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(c \cdot x\right)\\
\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.9% accurate, 2.9× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ 1.0 (pow (* c (* s x)) 2.0)))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / pow((c * (s * x)), 2.0);
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = 1.0d0 / ((c * (s * x)) ** 2.0d0)
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / Math.pow((c * (s * x)), 2.0);
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / math.pow((c * (s * x)), 2.0)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / (Float64(c * Float64(s * x)) ^ 2.0))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / ((c * (s * x)) ^ 2.0);
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(1.0 / N[Power[N[(c * N[(s * x), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}} \]

Alternative 8: 65.8% accurate, 20.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{-27}:\\ \;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot c\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 1.5e-27)
   (/ 1.0 (* x (* (* s (* s x)) (* c c))))
   (/ 1.0 (* x (* x (* c (* c (* s s))))))))
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 1.5e-27) {
		tmp = 1.0 / (x * ((s * (s * x)) * (c * c)));
	} else {
		tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
	}
	return tmp;
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 1.5d-27) then
        tmp = 1.0d0 / (x * ((s * (s * x)) * (c * c)))
    else
        tmp = 1.0d0 / (x * (x * (c * (c * (s * s)))))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 1.5e-27) {
		tmp = 1.0 / (x * ((s * (s * x)) * (c * c)));
	} else {
		tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if x <= 1.5e-27:
		tmp = 1.0 / (x * ((s * (s * x)) * (c * c)))
	else:
		tmp = 1.0 / (x * (x * (c * (c * (s * s)))))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (x <= 1.5e-27)
		tmp = Float64(1.0 / Float64(x * Float64(Float64(s * Float64(s * x)) * Float64(c * c))));
	else
		tmp = Float64(1.0 / Float64(x * Float64(x * Float64(c * Float64(c * Float64(s * s))))));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 1.5e-27)
		tmp = 1.0 / (x * ((s * (s * x)) * (c * c)));
	else
		tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 1.5e-27], N[(1.0 / N[(x * N[(N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot c\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.5000000000000001e-27

    1. Initial program 64.0%

      \[\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*64.0%

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(\left(-x\right) \cdot {s}^{2}\right) \cdot x\right)} \cdot {c}^{2}} \]
      8. distribute-lft-neg-out64.0%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in66.0%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out66.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5000000000000001e-27 < x

    1. Initial program 67.2%

      \[\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*67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.5 \cdot 10^{-27}:\\ \;\;\;\;\frac{1}{x \cdot \left(\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot c\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}\\ \end{array} \]

Alternative 9: 75.8% accurate, 20.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;c \leq 1060000:\\ \;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}\\ \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= c 1060000.0)
   (/ 1.0 (* (* s c) (* (* c x) (* s x))))
   (/ 1.0 (* (* s (* s x)) (* c (* c x))))))
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (c <= 1060000.0) {
		tmp = 1.0 / ((s * c) * ((c * x) * (s * x)));
	} else {
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	}
	return tmp;
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (c <= 1060000.0d0) then
        tmp = 1.0d0 / ((s * c) * ((c * x) * (s * x)))
    else
        tmp = 1.0d0 / ((s * (s * x)) * (c * (c * x)))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (c <= 1060000.0) {
		tmp = 1.0 / ((s * c) * ((c * x) * (s * x)));
	} else {
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if c <= 1060000.0:
		tmp = 1.0 / ((s * c) * ((c * x) * (s * x)))
	else:
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (c <= 1060000.0)
		tmp = Float64(1.0 / Float64(Float64(s * c) * Float64(Float64(c * x) * Float64(s * x))));
	else
		tmp = Float64(1.0 / Float64(Float64(s * Float64(s * x)) * Float64(c * Float64(c * x))));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (c <= 1060000.0)
		tmp = 1.0 / ((s * c) * ((c * x) * (s * x)));
	else
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[c, 1060000.0], N[(1.0 / N[(N[(s * c), $MachinePrecision] * N[(N[(c * x), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision] * N[(c * N[(c * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;c \leq 1060000:\\
\;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 1.06e6

    1. Initial program 63.0%

      \[\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*63.2%

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(\left(-x\right) \cdot {s}^{2}\right) \cdot x\right)} \cdot {c}^{2}} \]
      8. distribute-lft-neg-out63.0%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in64.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out64.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg64.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}} \]
      4. unswap-sqr79.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)}} \]
      5. pow279.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.06e6 < c

    1. Initial program 70.3%

      \[\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*70.3%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in71.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out71.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq 1060000:\\ \;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}\\ \end{array} \]

Alternative 10: 75.5% accurate, 20.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;c \leq 5000:\\ \;\;\;\;\frac{1}{\left(s \cdot x\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot c\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}\\ \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= c 5000.0)
   (/ 1.0 (* (* s x) (* (* c x) (* s c))))
   (/ 1.0 (* (* s (* s x)) (* c (* c x))))))
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (c <= 5000.0) {
		tmp = 1.0 / ((s * x) * ((c * x) * (s * c)));
	} else {
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	}
	return tmp;
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (c <= 5000.0d0) then
        tmp = 1.0d0 / ((s * x) * ((c * x) * (s * c)))
    else
        tmp = 1.0d0 / ((s * (s * x)) * (c * (c * x)))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (c <= 5000.0) {
		tmp = 1.0 / ((s * x) * ((c * x) * (s * c)));
	} else {
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if c <= 5000.0:
		tmp = 1.0 / ((s * x) * ((c * x) * (s * c)))
	else:
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (c <= 5000.0)
		tmp = Float64(1.0 / Float64(Float64(s * x) * Float64(Float64(c * x) * Float64(s * c))));
	else
		tmp = Float64(1.0 / Float64(Float64(s * Float64(s * x)) * Float64(c * Float64(c * x))));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (c <= 5000.0)
		tmp = 1.0 / ((s * x) * ((c * x) * (s * c)));
	else
		tmp = 1.0 / ((s * (s * x)) * (c * (c * x)));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[c, 5000.0], N[(1.0 / N[(N[(s * x), $MachinePrecision] * N[(N[(c * x), $MachinePrecision] * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision] * N[(c * N[(c * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;c \leq 5000:\\
\;\;\;\;\frac{1}{\left(s \cdot x\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot c\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 5e3

    1. Initial program 63.0%

      \[\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*63.2%

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(\left(-x\right) \cdot {s}^{2}\right) \cdot x\right)} \cdot {c}^{2}} \]
      8. distribute-lft-neg-out63.0%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in64.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out64.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg64.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(x \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}} \]
      4. unswap-sqr79.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)}} \]
      5. pow279.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5e3 < c

    1. Initial program 70.3%

      \[\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*70.3%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in71.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out71.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq 5000:\\ \;\;\;\;\frac{1}{\left(s \cdot x\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot c\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(s \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(c \cdot x\right)\right)}\\ \end{array} \]

Alternative 11: 77.9% accurate, 20.9× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{s \cdot \left(c \cdot x\right)} \cdot \frac{1}{c \cdot \left(s \cdot x\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (* (/ 1.0 (* s (* c x))) (/ 1.0 (* c (* s x)))))
assert(c < s);
double code(double x, double c, double s) {
	return (1.0 / (s * (c * x))) * (1.0 / (c * (s * x)));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = (1.0d0 / (s * (c * x))) * (1.0d0 / (c * (s * x)))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return (1.0 / (s * (c * x))) * (1.0 / (c * (s * x)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return (1.0 / (s * (c * x))) * (1.0 / (c * (s * x)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(Float64(1.0 / Float64(s * Float64(c * x))) * Float64(1.0 / Float64(c * Float64(s * x))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = (1.0 / (s * (c * x))) * (1.0 / (c * (s * x)));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(N[(1.0 / N[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(c * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{s \cdot \left(c \cdot x\right)} \cdot \frac{1}{c \cdot \left(s \cdot x\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. *-un-lft-identity97.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{s \cdot \left(c \cdot x\right)} \cdot \color{blue}{\frac{1}{c \cdot \left(s \cdot x\right)}} \]
  12. Final simplification82.4%

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

Alternative 12: 64.8% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ 1.0 (* x (* x (* c (* c (* s s)))))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / (x * (x * (c * (c * (s * s)))));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = 1.0d0 / (x * (x * (c * (c * (s * s)))))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / (x * (x * (c * (c * (s * s)))));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / (x * (x * (c * (c * (s * s)))))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(x * Float64(x * Float64(c * Float64(c * Float64(s * s))))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / (x * (x * (c * (c * (s * s)))));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(1.0 / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 72.7% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{\left(c \cdot x\right) \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ 1.0 (* (* c x) (* c (* s (* s x))))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / ((c * x) * (c * (s * (s * x))));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = 1.0d0 / ((c * x) * (c * (s * (s * x))))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / ((c * x) * (c * (s * (s * x))));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / ((c * x) * (c * (s * (s * x))))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(Float64(c * x) * Float64(c * Float64(s * Float64(s * x)))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / ((c * x) * (c * (s * (s * x))));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(1.0 / N[(N[(c * x), $MachinePrecision] * N[(c * N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot x\right) \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 75.4% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{\left(s \cdot c\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ 1.0 (* (* s c) (* (* c x) (* s x)))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / ((s * c) * ((c * x) * (s * x)));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = 1.0d0 / ((s * c) * ((c * x) * (s * x)))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / ((s * c) * ((c * x) * (s * x)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / ((s * c) * ((c * x) * (s * x)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(Float64(s * c) * Float64(Float64(c * x) * Float64(s * x))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / ((s * c) * ((c * x) * (s * x)));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(1.0 / N[(N[(s * c), $MachinePrecision] * N[(N[(c * x), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(s \cdot c\right) \cdot \left(\left(c \cdot x\right) \cdot \left(s \cdot x\right)\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 79.2% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{\frac{1}{s}}{c \cdot x}}{s \cdot \left(c \cdot x\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ (/ (/ 1.0 s) (* c x)) (* s (* c x))))
assert(c < s);
double code(double x, double c, double s) {
	return ((1.0 / s) / (c * x)) / (s * (c * x));
}
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = ((1.0d0 / s) / (c * x)) / (s * (c * x))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return ((1.0 / s) / (c * x)) / (s * (c * x));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return ((1.0 / s) / (c * x)) / (s * (c * x))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(Float64(Float64(1.0 / s) / Float64(c * x)) / Float64(s * Float64(c * x)))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = ((1.0 / s) / (c * x)) / (s * (c * x));
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(N[(N[(1.0 / s), $MachinePrecision] / N[(c * x), $MachinePrecision]), $MachinePrecision] / N[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{1}{s}}{c \cdot x}}{s \cdot \left(c \cdot x\right)}
\end{array}
Derivation
  1. Initial program 64.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*64.9%

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\left(x \cdot {s}^{2}\right) \cdot x}} \]
    2. remove-double-neg64.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{2}}} \]
  7. Step-by-step derivation
    1. *-un-lft-identity97.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\frac{1}{s}}{c \cdot x}}{s \cdot \left(c \cdot x\right)}} \]
  12. Final simplification82.8%

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

Reproduce

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