mixedcos

Percentage Accurate: 66.4% → 97.3%
Time: 10.7s
Alternatives: 12
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 12 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 66.4% accurate, 1.0× speedup?

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

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

Alternative 1: 97.3% accurate, 1.5× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in x around inf 63.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(x \cdot 2\right)}{{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}}^{2}} \]
    15. rem-exp-log83.2%

      \[\leadsto \color{blue}{e^{\log \left(\frac{\cos \left(x \cdot 2\right)}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}\right)}} \]
    16. log-div69.8%

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

    \[\leadsto \color{blue}{\cos \left(x \cdot 2\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
  7. Final simplification96.1%

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

Alternative 2: 90.4% 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 -3.7 \cdot 10^{+148}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-33}:\\ \;\;\;\;\frac{t_0}{s \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-10}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \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 -3.7e+148)
     (/ t_0 (* x (* c (* c (* s (* x s))))))
     (if (<= x -2.8e-33)
       (/ t_0 (* s (* (* x x) (* c (* c s)))))
       (if (<= x 8e-10)
         (pow (* c (* x s)) -2.0)
         (/ 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 <= -3.7e+148) {
		tmp = t_0 / (x * (c * (c * (s * (x * s)))));
	} else if (x <= -2.8e-33) {
		tmp = t_0 / (s * ((x * x) * (c * (c * s))));
	} else if (x <= 8e-10) {
		tmp = pow((c * (x * s)), -2.0);
	} 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 <= (-3.7d+148)) then
        tmp = t_0 / (x * (c * (c * (s * (x * s)))))
    else if (x <= (-2.8d-33)) then
        tmp = t_0 / (s * ((x * x) * (c * (c * s))))
    else if (x <= 8d-10) then
        tmp = (c * (x * s)) ** (-2.0d0)
    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 <= -3.7e+148) {
		tmp = t_0 / (x * (c * (c * (s * (x * s)))));
	} else if (x <= -2.8e-33) {
		tmp = t_0 / (s * ((x * x) * (c * (c * s))));
	} else if (x <= 8e-10) {
		tmp = Math.pow((c * (x * s)), -2.0);
	} 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 <= -3.7e+148:
		tmp = t_0 / (x * (c * (c * (s * (x * s)))))
	elif x <= -2.8e-33:
		tmp = t_0 / (s * ((x * x) * (c * (c * s))))
	elif x <= 8e-10:
		tmp = math.pow((c * (x * s)), -2.0)
	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 <= -3.7e+148)
		tmp = Float64(t_0 / Float64(x * Float64(c * Float64(c * Float64(s * Float64(x * s))))));
	elseif (x <= -2.8e-33)
		tmp = Float64(t_0 / Float64(s * Float64(Float64(x * x) * Float64(c * Float64(c * s)))));
	elseif (x <= 8e-10)
		tmp = Float64(c * Float64(x * s)) ^ -2.0;
	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 <= -3.7e+148)
		tmp = t_0 / (x * (c * (c * (s * (x * s)))));
	elseif (x <= -2.8e-33)
		tmp = t_0 / (s * ((x * x) * (c * (c * s))));
	elseif (x <= 8e-10)
		tmp = (c * (x * s)) ^ -2.0;
	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, -3.7e+148], N[(t$95$0 / N[(x * N[(c * N[(c * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.8e-33], N[(t$95$0 / N[(s * N[(N[(x * x), $MachinePrecision] * N[(c * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8e-10], N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $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 -3.7 \cdot 10^{+148}:\\
\;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\

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

\mathbf{elif}\;x \leq 8 \cdot 10^{-10}:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\

\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 < -3.7000000000000002e148

    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. associate-*r*65.0%

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

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

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

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

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

      \[\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 62.5%

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

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

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

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

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

        \[\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. unpow265.0%

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

        \[\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. *-commutative77.4%

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

        \[\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. Simplified80.3%

      \[\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 -3.7000000000000002e148 < x < -2.8e-33

    1. Initial program 80.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. *-commutative80.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*80.3%

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

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

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

        \[\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*82.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*82.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. *-commutative82.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. unpow282.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. Simplified82.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. Taylor expanded in c around 0 82.9%

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

        \[\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. unpow282.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. associate-*l*91.3%

        \[\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. Simplified91.3%

      \[\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 -2.8e-33 < x < 8.00000000000000029e-10

    1. Initial program 63.4%

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

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

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

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

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

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

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

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

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

      \[\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 58.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{-1}} \cdot \frac{1}{s \cdot \left(x \cdot c\right)} \]
      17. inv-pow95.8%

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

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

    if 8.00000000000000029e-10 < x

    1. Initial program 68.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. *-commutative68.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*64.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.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. *-commutative65.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. unpow265.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*75.6%

        \[\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*76.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. *-commutative76.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. unpow276.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. Simplified76.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. Taylor expanded in x around 0 75.6%

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

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

        \[\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*79.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. unpow279.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*88.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. *-commutative88.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. Simplified88.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)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.7 \cdot 10^{+148}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-33}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-10}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \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.5% accurate, 2.6× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 8 \cdot 10^{-10}\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}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \end{array} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (or (<= x -0.46) (not (<= x 8e-10)))
   (/ (cos (* x 2.0)) (* s (* s (* x (* c (* x c))))))
   (pow (* c (* x s)) -2.0)))
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if ((x <= -0.46) || !(x <= 8e-10)) {
		tmp = cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = pow((c * (x * 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) :: tmp
    if ((x <= (-0.46d0)) .or. (.not. (x <= 8d-10))) then
        tmp = cos((x * 2.0d0)) / (s * (s * (x * (c * (x * c)))))
    else
        tmp = (c * (x * s)) ** (-2.0d0)
    end if
    code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if ((x <= -0.46) || !(x <= 8e-10)) {
		tmp = Math.cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = Math.pow((c * (x * s)), -2.0);
	}
	return tmp;
}
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if (x <= -0.46) or not (x <= 8e-10):
		tmp = math.cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))))
	else:
		tmp = math.pow((c * (x * s)), -2.0)
	return tmp
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if ((x <= -0.46) || !(x <= 8e-10))
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(s * Float64(s * Float64(x * Float64(c * Float64(x * c))))));
	else
		tmp = Float64(c * Float64(x * s)) ^ -2.0;
	end
	return tmp
end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if ((x <= -0.46) || ~((x <= 8e-10)))
		tmp = cos((x * 2.0)) / (s * (s * (x * (c * (x * c)))));
	else
		tmp = (c * (x * 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_] := If[Or[LessEqual[x, -0.46], N[Not[LessEqual[x, 8e-10]], $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[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 8 \cdot 10^{-10}\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}:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.46000000000000002 or 8.00000000000000029e-10 < x

    1. Initial program 70.4%

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

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

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

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

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

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

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

        \[\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. *-commutative72.8%

        \[\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. unpow272.8%

        \[\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. Simplified72.8%

      \[\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 72.9%

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

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

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

        \[\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. unpow277.1%

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

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

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

      \[\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.46000000000000002 < x < 8.00000000000000029e-10

    1. Initial program 64.0%

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

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

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

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

        \[\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.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. unpow271.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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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 59.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{-1}} \cdot \frac{1}{s \cdot \left(x \cdot c\right)} \]
      17. inv-pow95.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 8 \cdot 10^{-10}\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}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \end{array} \]

Alternative 4: 95.2% accurate, 2.7× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\cos \left(x \cdot 2\right)}{\left(c \cdot \left(x \cdot s\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 (* x s)) (* s (* x c)))))
assert(c < s);
double code(double x, double c, double s) {
	return cos((x * 2.0)) / ((c * (x * s)) * (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 * (x * s)) * (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 * (x * s)) * (s * (x * c)));
}
[c, s] = sort([c, s])
def code(x, c, s):
	return math.cos((x * 2.0)) / ((c * (x * s)) * (s * (x * c)))
c, s = sort([c, s])
function code(x, c, s)
	return Float64(cos(Float64(x * 2.0)) / Float64(Float64(c * Float64(x * s)) * Float64(s * Float64(x * c))))
end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = cos((x * 2.0)) / ((c * (x * s)) * (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[(x * s), $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(x \cdot s\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}
\end{array}
Derivation
  1. Initial program 67.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. *-commutative67.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*63.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*62.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. unpow262.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-sqr75.1%

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in s around 0 92.4%

    \[\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 simplification92.4%

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

Alternative 5: 97.3% 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 67.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. *-commutative67.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*63.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*62.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. unpow262.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-sqr75.1%

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Final simplification95.8%

    \[\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.3% accurate, 2.7× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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*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)}} \]
    2. associate-*r*92.5%

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

      \[\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)} \]
    4. associate-*r*96.1%

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

      \[\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)}} \]
  7. Applied egg-rr96.1%

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

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

Alternative 7: 78.9% accurate, 3.0× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in x around 0 55.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{-1}} \cdot \frac{1}{s \cdot \left(x \cdot c\right)} \]
    17. inv-pow77.9%

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

    \[\leadsto \color{blue}{{\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
  9. Final simplification78.3%

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

Alternative 8: 55.1% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot x\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(Float64(c * c) * Float64(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[(N[(c * c), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right)}
\end{array}
Derivation
  1. Initial program 67.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. *-commutative67.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*63.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*62.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. unpow262.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-sqr75.1%

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in x around 0 55.8%

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

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

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

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

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

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

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

Alternative 9: 76.4% accurate, 24.1× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in x around 0 55.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 77.3% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{1}{s}}{\left(x \cdot c\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 (/ (/ 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(1.0 / s) / Float64(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[(1.0 / s), $MachinePrecision] / N[(N[(x * c), $MachinePrecision] * N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{1}{s}}{\left(x \cdot c\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}
\end{array}
Derivation
  1. Initial program 67.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. *-commutative67.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*63.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*62.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. unpow262.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-sqr75.1%

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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. Taylor expanded in x around 0 55.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 78.9% accurate, 24.1× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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*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)}} \]
    2. associate-*r*92.5%

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

      \[\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)} \]
    4. associate-*r*96.1%

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

      \[\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)}} \]
  7. Applied egg-rr96.1%

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

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

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

Alternative 12: 28.0% accurate, 34.8× speedup?

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

      \[\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. unpow275.1%

      \[\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.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. *-commutative95.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. Simplified95.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*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. Taylor expanded in x around 0 63.2%

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

    \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
  8. Step-by-step derivation
    1. *-commutative31.0%

      \[\leadsto \frac{-2}{\color{blue}{{s}^{2} \cdot {c}^{2}}} \]
    2. associate-/r*30.6%

      \[\leadsto \color{blue}{\frac{\frac{-2}{{s}^{2}}}{{c}^{2}}} \]
    3. unpow230.6%

      \[\leadsto \frac{\frac{-2}{\color{blue}{s \cdot s}}}{{c}^{2}} \]
    4. unpow230.6%

      \[\leadsto \frac{\frac{-2}{s \cdot s}}{\color{blue}{c \cdot c}} \]
  9. Simplified30.6%

    \[\leadsto \color{blue}{\frac{\frac{-2}{s \cdot s}}{c \cdot c}} \]
  10. Taylor expanded in s around 0 31.0%

    \[\leadsto \color{blue}{\frac{-2}{{s}^{2} \cdot {c}^{2}}} \]
  11. Step-by-step derivation
    1. *-commutative31.0%

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

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

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

    \[\leadsto \color{blue}{\frac{-2}{\left(c \cdot c\right) \cdot \left(s \cdot s\right)}} \]
  13. Final simplification31.0%

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

Reproduce

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