mixedcos

Percentage Accurate: 67.0% → 98.1%
Time: 19.8s
Alternatives: 14
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 14 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.0% 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: 98.1% accurate, 0.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ t_1 := c \cdot \left(s \cdot x\right)\\ \mathbf{if}\;s \leq 5.8 \cdot 10^{-174}:\\ \;\;\;\;\frac{\frac{t_0}{t_1}}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{{\left(\sqrt{s} \cdot \left(x \cdot \left(c \cdot \sqrt{s}\right)\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
 (let* ((t_0 (cos (* x 2.0))) (t_1 (* c (* s x))))
   (if (<= s 5.8e-174)
     (/ (/ t_0 t_1) t_1)
     (/ t_0 (pow (* (sqrt s) (* x (* c (sqrt s)))) 2.0)))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = cos((x * 2.0));
	double t_1 = c * (s * x);
	double tmp;
	if (s <= 5.8e-174) {
		tmp = (t_0 / t_1) / t_1;
	} else {
		tmp = t_0 / pow((sqrt(s) * (x * (c * sqrt(s)))), 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos((x * 2.0d0))
    t_1 = c * (s * x)
    if (s <= 5.8d-174) then
        tmp = (t_0 / t_1) / t_1
    else
        tmp = t_0 / ((sqrt(s) * (x * (c * sqrt(s)))) ** 2.0d0)
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double t_0 = Math.cos((x * 2.0));
	double t_1 = c * (s * x);
	double tmp;
	if (s <= 5.8e-174) {
		tmp = (t_0 / t_1) / t_1;
	} else {
		tmp = t_0 / Math.pow((Math.sqrt(s) * (x * (c * Math.sqrt(s)))), 2.0);
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = math.cos((x * 2.0))
	t_1 = c * (s * x)
	tmp = 0
	if s <= 5.8e-174:
		tmp = (t_0 / t_1) / t_1
	else:
		tmp = t_0 / math.pow((math.sqrt(s) * (x * (c * math.sqrt(s)))), 2.0)
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	t_0 = cos(Float64(x * 2.0))
	t_1 = Float64(c * Float64(s * x))
	tmp = 0.0
	if (s <= 5.8e-174)
		tmp = Float64(Float64(t_0 / t_1) / t_1);
	else
		tmp = Float64(t_0 / (Float64(sqrt(s) * Float64(x * Float64(c * sqrt(s)))) ^ 2.0));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	t_0 = cos((x * 2.0));
	t_1 = c * (s * x);
	tmp = 0.0;
	if (s <= 5.8e-174)
		tmp = (t_0 / t_1) / t_1;
	else
		tmp = t_0 / ((sqrt(s) * (x * (c * sqrt(s)))) ^ 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_] := Block[{t$95$0 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(s * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 5.8e-174], N[(N[(t$95$0 / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision], N[(t$95$0 / N[Power[N[(N[Sqrt[s], $MachinePrecision] * N[(x * N[(c * N[Sqrt[s], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \cos \left(x \cdot 2\right)\\
t_1 := c \cdot \left(s \cdot x\right)\\
\mathbf{if}\;s \leq 5.8 \cdot 10^{-174}:\\
\;\;\;\;\frac{\frac{t_0}{t_1}}{t_1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 5.8000000000000002e-174

    1. Initial program 58.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. *-commutative58.8%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}} \]
      5. unswap-sqr68.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 {s}^{2}} \]
      6. unpow268.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.8000000000000002e-174 < s

    1. Initial program 63.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. *-commutative63.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 90.6% accurate, 2.6× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+156}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-11}:\\ \;\;\;\;\frac{t_0}{s \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot \left(s \cdot c\right)\right)\right)}\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\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
 (let* ((t_0 (cos (* x 2.0))))
   (if (<= x -5.2e+156)
     (/ t_0 (* x (* c (* c (* s (* s x))))))
     (if (<= x -1.25e-11)
       (/ t_0 (* s (* (* x x) (* c (* s c)))))
       (if (<= x 5.4e-5)
         (/ (/ (/ 1.0 s) (* x c)) (* s (* x c)))
         (/ t_0 (* s (* s (* x (* c (* x c)))))))))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = cos((x * 2.0));
	double tmp;
	if (x <= -5.2e+156) {
		tmp = t_0 / (x * (c * (c * (s * (s * x)))));
	} else if (x <= -1.25e-11) {
		tmp = t_0 / (s * ((x * x) * (c * (s * c))));
	} else if (x <= 5.4e-5) {
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	} else {
		tmp = t_0 / (s * (s * (x * (c * (x * c)))));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = cos((x * 2.0d0))
    if (x <= (-5.2d+156)) then
        tmp = t_0 / (x * (c * (c * (s * (s * x)))))
    else if (x <= (-1.25d-11)) then
        tmp = t_0 / (s * ((x * x) * (c * (s * c))))
    else if (x <= 5.4d-5) then
        tmp = ((1.0d0 / s) / (x * c)) / (s * (x * c))
    else
        tmp = t_0 / (s * (s * (x * (c * (x * c)))))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double t_0 = Math.cos((x * 2.0));
	double tmp;
	if (x <= -5.2e+156) {
		tmp = t_0 / (x * (c * (c * (s * (s * x)))));
	} else if (x <= -1.25e-11) {
		tmp = t_0 / (s * ((x * x) * (c * (s * c))));
	} else if (x <= 5.4e-5) {
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	} else {
		tmp = t_0 / (s * (s * (x * (c * (x * c)))));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = math.cos((x * 2.0))
	tmp = 0
	if x <= -5.2e+156:
		tmp = t_0 / (x * (c * (c * (s * (s * x)))))
	elif x <= -1.25e-11:
		tmp = t_0 / (s * ((x * x) * (c * (s * c))))
	elif x <= 5.4e-5:
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c))
	else:
		tmp = t_0 / (s * (s * (x * (c * (x * c)))))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	t_0 = cos(Float64(x * 2.0))
	tmp = 0.0
	if (x <= -5.2e+156)
		tmp = Float64(t_0 / Float64(x * Float64(c * Float64(c * Float64(s * Float64(s * x))))));
	elseif (x <= -1.25e-11)
		tmp = Float64(t_0 / Float64(s * Float64(Float64(x * x) * Float64(c * Float64(s * c)))));
	elseif (x <= 5.4e-5)
		tmp = Float64(Float64(Float64(1.0 / s) / Float64(x * c)) / Float64(s * Float64(x * c)));
	else
		tmp = Float64(t_0 / Float64(s * Float64(s * Float64(x * Float64(c * Float64(x * c))))));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	t_0 = cos((x * 2.0));
	tmp = 0.0;
	if (x <= -5.2e+156)
		tmp = t_0 / (x * (c * (c * (s * (s * x)))));
	elseif (x <= -1.25e-11)
		tmp = t_0 / (s * ((x * x) * (c * (s * c))));
	elseif (x <= 5.4e-5)
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	else
		tmp = t_0 / (s * (s * (x * (c * (x * c)))));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -5.2e+156], N[(t$95$0 / N[(x * N[(c * N[(c * N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.25e-11], N[(t$95$0 / N[(s * N[(N[(x * x), $MachinePrecision] * N[(c * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5.4e-5], N[(N[(N[(1.0 / s), $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(s * N[(s * N[(x * N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \cos \left(x \cdot 2\right)\\
\mathbf{if}\;x \leq -5.2 \cdot 10^{+156}:\\
\;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\

\mathbf{elif}\;x \leq -1.25 \cdot 10^{-11}:\\
\;\;\;\;\frac{t_0}{s \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot \left(s \cdot c\right)\right)\right)}\\

\mathbf{elif}\;x \leq 5.4 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -5.20000000000000037e156

    1. Initial program 59.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*67.2%

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

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

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

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

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

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

      \[\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. unpow266.9%

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

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

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

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

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

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

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

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

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

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

    if -5.20000000000000037e156 < x < -1.25000000000000005e-11

    1. Initial program 70.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. *-commutative70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.25000000000000005e-11 < x < 5.3999999999999998e-5

    1. Initial program 58.5%

      \[\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. *-commutative58.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.3999999999999998e-5 < x

    1. Initial program 59.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. *-commutative59.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 89.7% accurate, 2.6× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -0.02 \lor \neg \left(x \leq 0.00175\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\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 (or (<= x -0.02) (not (<= x 0.00175)))
   (/ (cos (* x 2.0)) (* s (* s (* x (* c (* x c))))))
   (/ (/ (/ 1.0 s) (* x c)) (* s (* x c)))))
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if ((x <= -0.02) || !(x <= 0.00175)) {
		tmp = cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	}
	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 <= (-0.02d0)) .or. (.not. (x <= 0.00175d0))) then
        tmp = cos((x * 2.0d0)) / (s * (s * (x * (c * (x * c)))))
    else
        tmp = ((1.0d0 / s) / (x * c)) / (s * (x * c))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if ((x <= -0.02) || !(x <= 0.00175)) {
		tmp = Math.cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if (x <= -0.02) or not (x <= 0.00175):
		tmp = math.cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))))
	else:
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if ((x <= -0.02) || !(x <= 0.00175))
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(s * Float64(s * Float64(x * Float64(c * Float64(x * c))))));
	else
		tmp = Float64(Float64(Float64(1.0 / s) / Float64(x * c)) / Float64(s * Float64(x * c)));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if ((x <= -0.02) || ~((x <= 0.00175)))
		tmp = cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	else
		tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[Or[LessEqual[x, -0.02], N[Not[LessEqual[x, 0.00175]], $MachinePrecision]], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(s * N[(s * N[(x * N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / s), $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.02 \lor \neg \left(x \leq 0.00175\right):\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.0200000000000000004 or 0.00175000000000000004 < x

    1. Initial program 63.6%

      \[\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. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < x < 0.00175000000000000004

    1. Initial program 57.6%

      \[\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. *-commutative57.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.02 \lor \neg \left(x \leq 0.00175\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 4: 94.7% accurate, 2.7× speedup?

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

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 96.9% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(x \cdot c\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 (* x c)))) (/ (cos (* x 2.0)) (* t_0 t_0))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = s * (x * c);
	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 * (x * c)
    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 * (x * c);
	return Math.cos((x * 2.0)) / (t_0 * t_0);
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = s * (x * c)
	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(x * c))
	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 * (x * c);
	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[(x * c), $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(x \cdot c\right)\\
\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 97.1% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ \frac{\frac{\cos \left(x \cdot 2\right)}{t_0}}{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 (* x c)))) (/ (/ (cos (* x 2.0)) t_0) t_0)))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = s * (x * c);
	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 * (x * c)
    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 * (x * c);
	return (Math.cos((x * 2.0)) / t_0) / t_0;
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = s * (x * c)
	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(x * c))
	return Float64(Float64(cos(Float64(x * 2.0)) / t_0) / t_0)
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	t_0 = s * (x * c);
	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[(x * c), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(x \cdot c\right)\\
\frac{\frac{\cos \left(x \cdot 2\right)}{t_0}}{t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.8% accurate, 20.8× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2e-30

    1. Initial program 61.6%

      \[\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. *-commutative61.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2e-30 < c

    1. Initial program 60.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. *-commutative60.2%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}} \]
      5. unswap-sqr70.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 {s}^{2}} \]
      6. unpow270.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 77.6% accurate, 20.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;s \leq 3 \cdot 10^{+167}:\\ \;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(c \cdot t_0\right) \cdot \left(s \cdot x\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
 (let* ((t_0 (* x (* s c))))
   (if (<= s 3e+167)
     (/ 1.0 (* (* x c) (* s t_0)))
     (/ 1.0 (* (* c t_0) (* s x))))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = x * (s * c);
	double tmp;
	if (s <= 3e+167) {
		tmp = 1.0 / ((x * c) * (s * t_0));
	} else {
		tmp = 1.0 / ((c * t_0) * (s * 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) :: t_0
    real(8) :: tmp
    t_0 = x * (s * c)
    if (s <= 3d+167) then
        tmp = 1.0d0 / ((x * c) * (s * t_0))
    else
        tmp = 1.0d0 / ((c * t_0) * (s * x))
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double t_0 = x * (s * c);
	double tmp;
	if (s <= 3e+167) {
		tmp = 1.0 / ((x * c) * (s * t_0));
	} else {
		tmp = 1.0 / ((c * t_0) * (s * x));
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = x * (s * c)
	tmp = 0
	if s <= 3e+167:
		tmp = 1.0 / ((x * c) * (s * t_0))
	else:
		tmp = 1.0 / ((c * t_0) * (s * x))
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	t_0 = Float64(x * Float64(s * c))
	tmp = 0.0
	if (s <= 3e+167)
		tmp = Float64(1.0 / Float64(Float64(x * c) * Float64(s * t_0)));
	else
		tmp = Float64(1.0 / Float64(Float64(c * t_0) * Float64(s * x)));
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	t_0 = x * (s * c);
	tmp = 0.0;
	if (s <= 3e+167)
		tmp = 1.0 / ((x * c) * (s * t_0));
	else
		tmp = 1.0 / ((c * t_0) * (s * x));
	end
	tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 3e+167], N[(1.0 / N[(N[(x * c), $MachinePrecision] * N[(s * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(c * t$95$0), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(s \cdot c\right)\\
\mathbf{if}\;s \leq 3 \cdot 10^{+167}:\\
\;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot t_0\right)}\\

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


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

    1. Initial program 62.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. *-commutative62.3%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}} \]
      5. unswap-sqr74.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 {s}^{2}} \]
      6. unpow274.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.00000000000000012e167 < s

    1. Initial program 51.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. *-commutative51.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 60.8% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{c \cdot \left(\left(c \cdot \left(x \cdot x\right)\right) \cdot \left(s \cdot s\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 (* (* c (* x x)) (* s s)))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / (c * ((c * (x * x)) * (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 / (c * ((c * (x * x)) * (s * s)))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / (c * ((c * (x * x)) * (s * s)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / (c * ((c * (x * x)) * (s * s)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(c * Float64(Float64(c * Float64(x * x)) * Float64(s * s))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / (c * ((c * (x * x)) * (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[(c * N[(N[(c * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{c \cdot \left(\left(c \cdot \left(x \cdot x\right)\right) \cdot \left(s \cdot s\right)\right)}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 75.8% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{c \cdot \left(\left(x \cdot \left(s \cdot c\right)\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 (* c (* (* x (* s c)) (* s x)))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / (c * ((x * (s * 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 / (c * ((x * (s * c)) * (s * x)))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / (c * ((x * (s * c)) * (s * x)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / (c * ((x * (s * c)) * (s * x)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(c * Float64(Float64(x * Float64(s * c)) * Float64(s * x))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / (c * ((x * (s * c)) * (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[(c * N[(N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision] * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{c \cdot \left(\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(s \cdot x\right)\right)}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 77.0% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{x \cdot \left(\left(s \cdot c\right) \cdot \left(x \cdot \left(s \cdot c\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 (* (* s c) (* x (* s c))))))
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / (x * ((s * c) * (x * (s * c))));
}
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 * ((s * c) * (x * (s * c))))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return 1.0 / (x * ((s * c) * (x * (s * c))));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / (x * ((s * c) * (x * (s * c))))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(x * Float64(Float64(s * c) * Float64(x * Float64(s * c)))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = 1.0 / (x * ((s * c) * (x * (s * c))));
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[(N[(s * c), $MachinePrecision] * N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{x \cdot \left(\left(s \cdot c\right) \cdot \left(x \cdot \left(s \cdot c\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 77.7% accurate, 24.1× speedup?

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

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 78.8% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\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) (* x c)) (* s (* x c))))
assert(c < s);
double code(double x, double c, double s) {
	return ((1.0 / s) / (x * c)) / (s * (x * c));
}
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) / (x * c)) / (s * (x * c))
end function
assert c < s;
public static double code(double x, double c, double s) {
	return ((1.0 / s) / (x * c)) / (s * (x * c));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return ((1.0 / s) / (x * c)) / (s * (x * c))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(Float64(Float64(1.0 / s) / Float64(x * c)) / Float64(s * Float64(x * c)))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = ((1.0 / s) / (x * c)) / (s * (x * c));
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[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}
\end{array}
Derivation
  1. Initial program 60.6%

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 29.0% accurate, 34.8× speedup?

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

    \[\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. *-commutative60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(x \cdot 2\right) \cdot \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{\left(-2\right)}} \]
    5. metadata-eval95.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
  10. Step-by-step derivation
    1. *-commutative25.7%

      \[\leadsto \frac{-2}{\color{blue}{{s}^{2} \cdot {c}^{2}}} \]
    2. unpow225.7%

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

      \[\leadsto \frac{-2}{\left(s \cdot s\right) \cdot \color{blue}{\left(c \cdot c\right)}} \]
  11. Simplified25.7%

    \[\leadsto \color{blue}{\frac{-2}{\left(s \cdot s\right) \cdot \left(c \cdot c\right)}} \]
  12. Final simplification25.7%

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

Reproduce

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