mixedcos

Percentage Accurate: 67.8% → 97.0%
Time: 15.1s
Alternatives: 10
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 10 alternatives:

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

Initial Program: 67.8% accurate, 1.0× speedup?

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

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

Alternative 1: 97.0% 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(2 \cdot x\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 (* 2.0 x)) (* t_0 t_0))))
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = s * (x * c);
	return cos((2.0 * x)) / (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((2.0d0 * x)) / (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((2.0 * x)) / (t_0 * t_0);
}
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = s * (x * c)
	return math.cos((2.0 * x)) / (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(2.0 * x)) / 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((2.0 * x)) / (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[(2.0 * x), $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(2 \cdot x\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.04999999999999994e-13 < x

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 86.2% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.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. associate-/r*64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-59 < x

    1. Initial program 65.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. associate-/r*65.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 94.7% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 79.0% 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 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 75.3% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 76.2% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.0% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 78.0% accurate, 24.1× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{s \cdot \left(x \cdot c\right)} \end{array} \]
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ (/ 1.0 (* c (* 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 / Float64(c * 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 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{s \cdot \left(x \cdot c\right)}
\end{array}
Derivation
  1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{\left(\sqrt{s \cdot \left(c \cdot x\right)}\right)}^{-2} \cdot {\left(\sqrt{s \cdot \left(c \cdot x\right)}\right)}^{-2}} \]
  9. Step-by-step derivation
    1. pow-sqr50.6%

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

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

    \[\leadsto \color{blue}{{\left(\sqrt{s \cdot \left(c \cdot x\right)}\right)}^{-4}} \]
  11. Step-by-step derivation
    1. sqrt-pow282.8%

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

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

      \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{\color{blue}{\left(-1 - 1\right)}} \]
    4. pow-div82.7%

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

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

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

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

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

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

Alternative 10: 28.4% accurate, 34.8× speedup?

\[\begin{array}{l} [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{-2}{c \cdot c}}{s \cdot s} \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(Float64(-2.0 / 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[(N[(-2.0 / N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(s * s), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{-2}{c \cdot c}}{s \cdot s}
\end{array}
Derivation
  1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{-2}{c \cdot c}}{s \cdot s}} \]
  10. Final simplification25.1%

    \[\leadsto \frac{\frac{-2}{c \cdot c}}{s \cdot s} \]

Reproduce

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