mixedcos

Percentage Accurate: 66.7% → 99.3%
Time: 11.9s
Alternatives: 8
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 8 alternatives:

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

Initial Program: 66.7% 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: 99.3% accurate, 2.7× speedup?

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

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


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

    1. Initial program 70.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*70.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-neg70.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-out70.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-out70.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-out70.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/70.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-out70.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-out70.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*71.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-in71.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-out71.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-neg71.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*70.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. *-commutative70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
    8. Applied egg-rr85.5%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
    9. Step-by-step derivation
      1. associate-/l/85.6%

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

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

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

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

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

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

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

    if 5.00000000000000033e-64 < x

    1. Initial program 60.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot \left(x \cdot {c}^{2}\right)} \]
      13. associate-*r*62.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. *-commutative62.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*60.9%

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

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

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

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

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

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

        \[\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)}} \]
      6. *-un-lft-identity83.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \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)} \]
      7. add-sqr-sqrt82.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 93.6% accurate, 2.6× speedup?

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

\mathbf{elif}\;x \leq 8.5 \cdot 10^{+208}:\\
\;\;\;\;\frac{t_0}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(s \cdot c\right)\right)\right)\right)}\\

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


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

    1. Initial program 70.4%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/70.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-out70.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-out70.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*71.9%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot \left(x \cdot {c}^{2}\right)} \]
      13. associate-*r*70.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. *-commutative70.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*70.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
    8. Applied egg-rr86.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
    9. Step-by-step derivation
      1. associate-/l/86.4%

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

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

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

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

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

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

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

    if 1.19999999999999993e-17 < x < 8.4999999999999992e208

    1. Initial program 58.8%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/58.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-out58.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-out58.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*56.8%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot \left(x \cdot {c}^{2}\right)} \]
      13. associate-*r*58.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. *-commutative58.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*58.8%

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

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

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

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

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

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

    if 8.4999999999999992e208 < x

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/58.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-out58.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-out58.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*64.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-in64.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-out64.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-neg64.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*64.2%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(\left(x \cdot {c}^{2}\right) \cdot {s}^{2}\right)}} \]
      15. associate-*r*58.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. Simplified58.6%

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

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

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

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

        \[\leadsto \frac{\color{blue}{1 \cdot \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)} \]
      5. associate-*r*63.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.2 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+208}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(s \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 3: 94.3% accurate, 2.6× speedup?

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

\mathbf{elif}\;x \leq 2 \cdot 10^{+92}:\\
\;\;\;\;\frac{t_0}{\left(x \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right)}\\

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


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

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/70.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-out70.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-out70.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*72.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-in72.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-out72.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-neg72.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*71.2%

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(\left(x \cdot {c}^{2}\right) \cdot {s}^{2}\right)}} \]
      15. associate-*r*70.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. Simplified70.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
    8. Applied egg-rr85.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
    9. Step-by-step derivation
      1. associate-/l/85.8%

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

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

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

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

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

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

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

    if 1.00000000000000004e-42 < x < 2.0000000000000001e92

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)}} \]

    if 2.0000000000000001e92 < x

    1. Initial program 59.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{-\left(\left(\left(-x\right) \cdot {s}^{2}\right) \cdot x\right) \cdot {c}^{2}}} \]
      9. associate-*l*61.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-in61.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-out61.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-neg61.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*63.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. *-commutative63.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*59.1%

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

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

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

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

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

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

        \[\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)}} \]
      6. *-un-lft-identity70.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \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)} \]
      7. add-sqr-sqrt70.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 88.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 70.4%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/70.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-out70.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-out70.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*71.9%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot \left(x \cdot {c}^{2}\right)} \]
      13. associate-*r*70.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. *-commutative70.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*70.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
    8. Applied egg-rr86.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
    9. Step-by-step derivation
      1. associate-/l/86.4%

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

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

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

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

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

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

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

    if 6.9999999999999997e-18 < x

    1. Initial program 58.8%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/58.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-out58.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-out58.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*58.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-in58.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-out58.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-neg58.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*60.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. *-commutative60.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*58.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. Simplified66.4%

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.1%

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

Alternative 5: 92.0% accurate, 2.7× speedup?

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

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


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

    1. Initial program 70.4%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/70.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-out70.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-out70.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*71.9%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot \left(x \cdot {c}^{2}\right)} \]
      13. associate-*r*70.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. *-commutative70.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*70.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
    8. Applied egg-rr86.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
    9. Step-by-step derivation
      1. associate-/l/86.4%

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

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

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

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

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

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

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

    if 1.19999999999999993e-17 < x

    1. Initial program 58.8%

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

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

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{{c}^{2}}}{\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)}} \]
      6. associate-/l/58.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-out58.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-out58.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*58.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-in58.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-out58.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-neg58.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*60.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. *-commutative60.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*58.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. Simplified66.4%

      \[\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 c around 0 66.4%

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

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

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

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

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

Alternative 6: 69.2% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. associate-*r*78.8%

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

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

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

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

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

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

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

Alternative 7: 78.3% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\frac{1}{c}}{s \cdot x}} \]
  8. Applied egg-rr78.9%

    \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
  9. Step-by-step derivation
    1. associate-/l/78.9%

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

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

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

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

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

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

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

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

Reproduce

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