mixedcos

Percentage Accurate: 66.0% → 97.1%
Time: 14.1s
Alternatives: 9
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 9 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 97.1% accurate, 2.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 22000:\\ \;\;\;\;\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m} \cdot \left(\frac{1}{c\_m} \cdot \frac{1}{x\_m \cdot s\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\_m\right)}{s\_m \cdot \left(\left(x\_m \cdot \left(c\_m \cdot s\_m\right)\right) \cdot \left(x\_m \cdot c\_m\right)\right)}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (if (<= x_m 22000.0)
   (* (/ (/ 1.0 c_m) (* x_m s_m)) (* (/ 1.0 c_m) (/ 1.0 (* x_m s_m))))
   (/ (cos (* 2.0 x_m)) (* s_m (* (* x_m (* c_m s_m)) (* x_m c_m))))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	double tmp;
	if (x_m <= 22000.0) {
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	} else {
		tmp = cos((2.0 * x_m)) / (s_m * ((x_m * (c_m * s_m)) * (x_m * c_m)));
	}
	return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    real(8) :: tmp
    if (x_m <= 22000.0d0) then
        tmp = ((1.0d0 / c_m) / (x_m * s_m)) * ((1.0d0 / c_m) * (1.0d0 / (x_m * s_m)))
    else
        tmp = cos((2.0d0 * x_m)) / (s_m * ((x_m * (c_m * s_m)) * (x_m * c_m)))
    end if
    code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	double tmp;
	if (x_m <= 22000.0) {
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	} else {
		tmp = Math.cos((2.0 * x_m)) / (s_m * ((x_m * (c_m * s_m)) * (x_m * c_m)));
	}
	return tmp;
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	tmp = 0
	if x_m <= 22000.0:
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)))
	else:
		tmp = math.cos((2.0 * x_m)) / (s_m * ((x_m * (c_m * s_m)) * (x_m * c_m)))
	return tmp
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	tmp = 0.0
	if (x_m <= 22000.0)
		tmp = Float64(Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) * Float64(Float64(1.0 / c_m) * Float64(1.0 / Float64(x_m * s_m))));
	else
		tmp = Float64(cos(Float64(2.0 * x_m)) / Float64(s_m * Float64(Float64(x_m * Float64(c_m * s_m)) * Float64(x_m * c_m))));
	end
	return tmp
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
	tmp = 0.0;
	if (x_m <= 22000.0)
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	else
		tmp = cos((2.0 * x_m)) / (s_m * ((x_m * (c_m * s_m)) * (x_m * c_m)));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := If[LessEqual[x$95$m, 22000.0], N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c$95$m), $MachinePrecision] * N[(1.0 / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] / N[(s$95$m * N[(N[(x$95$m * N[(c$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 22000:\\
\;\;\;\;\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m} \cdot \left(\frac{1}{c\_m} \cdot \frac{1}{x\_m \cdot s\_m}\right)\\

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 55.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 22000 < x

    1. Initial program 72.4%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 22000:\\ \;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \left(\frac{1}{c} \cdot \frac{1}{x \cdot s}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot c\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.8% accurate, 1.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \cos \left(2 \cdot x\_m\right) \cdot {\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (* (cos (* 2.0 x_m)) (pow (* c_m (* x_m s_m)) -2.0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	return cos((2.0 * x_m)) * pow((c_m * (x_m * s_m)), -2.0);
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    code = cos((2.0d0 * x_m)) * ((c_m * (x_m * s_m)) ** (-2.0d0))
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	return Math.cos((2.0 * x_m)) * Math.pow((c_m * (x_m * s_m)), -2.0);
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	return math.cos((2.0 * x_m)) * math.pow((c_m * (x_m * s_m)), -2.0)
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	return Float64(cos(Float64(2.0 * x_m)) * (Float64(c_m * Float64(x_m * s_m)) ^ -2.0))
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	tmp = cos((2.0 * x_m)) * ((c_m * (x_m * s_m)) ^ -2.0);
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] * N[Power[N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\cos \left(2 \cdot x\_m\right) \cdot {\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}
\end{array}
Derivation
  1. Initial program 67.2%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.2% accurate, 2.6× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 51.0%

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

        \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
      2. *-commutative51.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.99999999999999969e-80 < x

    1. Initial program 77.4%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt77.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 95.7% accurate, 2.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \begin{array}{l} \mathbf{if}\;s\_m \leq 5.3 \cdot 10^{+194}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\_m\right)}{\left(x\_m \cdot c\_m\right) \cdot \left(s\_m \cdot \left(x\_m \cdot \left(c\_m \cdot s\_m\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m} \cdot \left(\frac{1}{c\_m} \cdot \frac{1}{x\_m \cdot s\_m}\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (if (<= s_m 5.3e+194)
   (/ (cos (* 2.0 x_m)) (* (* x_m c_m) (* s_m (* x_m (* c_m s_m)))))
   (* (/ (/ 1.0 c_m) (* x_m s_m)) (* (/ 1.0 c_m) (/ 1.0 (* x_m s_m))))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	double tmp;
	if (s_m <= 5.3e+194) {
		tmp = cos((2.0 * x_m)) / ((x_m * c_m) * (s_m * (x_m * (c_m * s_m))));
	} else {
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	}
	return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    real(8) :: tmp
    if (s_m <= 5.3d+194) then
        tmp = cos((2.0d0 * x_m)) / ((x_m * c_m) * (s_m * (x_m * (c_m * s_m))))
    else
        tmp = ((1.0d0 / c_m) / (x_m * s_m)) * ((1.0d0 / c_m) * (1.0d0 / (x_m * s_m)))
    end if
    code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	double tmp;
	if (s_m <= 5.3e+194) {
		tmp = Math.cos((2.0 * x_m)) / ((x_m * c_m) * (s_m * (x_m * (c_m * s_m))));
	} else {
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	}
	return tmp;
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	tmp = 0
	if s_m <= 5.3e+194:
		tmp = math.cos((2.0 * x_m)) / ((x_m * c_m) * (s_m * (x_m * (c_m * s_m))))
	else:
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)))
	return tmp
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	tmp = 0.0
	if (s_m <= 5.3e+194)
		tmp = Float64(cos(Float64(2.0 * x_m)) / Float64(Float64(x_m * c_m) * Float64(s_m * Float64(x_m * Float64(c_m * s_m)))));
	else
		tmp = Float64(Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) * Float64(Float64(1.0 / c_m) * Float64(1.0 / Float64(x_m * s_m))));
	end
	return tmp
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
	tmp = 0.0;
	if (s_m <= 5.3e+194)
		tmp = cos((2.0 * x_m)) / ((x_m * c_m) * (s_m * (x_m * (c_m * s_m))));
	else
		tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := If[LessEqual[s$95$m, 5.3e+194], N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] / N[(N[(x$95$m * c$95$m), $MachinePrecision] * N[(s$95$m * N[(x$95$m * N[(c$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c$95$m), $MachinePrecision] * N[(1.0 / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;s\_m \leq 5.3 \cdot 10^{+194}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\_m\right)}{\left(x\_m \cdot c\_m\right) \cdot \left(s\_m \cdot \left(x\_m \cdot \left(c\_m \cdot s\_m\right)\right)\right)}\\

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


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

    1. Initial program 66.7%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.30000000000000005e194 < s

    1. Initial program 72.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*72.4%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 66.6%

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

        \[\leadsto \color{blue}{\frac{\frac{1}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
      2. *-commutative66.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 5.3 \cdot 10^{+194}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot c\right) \cdot \left(s \cdot \left(x \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \left(\frac{1}{c} \cdot \frac{1}{x \cdot s}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 96.8% accurate, 2.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \begin{array}{l} t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\ \frac{\frac{\cos \left(2 \cdot x\_m\right)}{t\_0}}{t\_0} \end{array} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (let* ((t_0 (* c_m (* x_m s_m)))) (/ (/ (cos (* 2.0 x_m)) t_0) t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	double t_0 = c_m * (x_m * s_m);
	return (cos((2.0 * x_m)) / t_0) / t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = c_m * (x_m * s_m)
    code = (cos((2.0d0 * x_m)) / t_0) / t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	double t_0 = c_m * (x_m * s_m);
	return (Math.cos((2.0 * x_m)) / t_0) / t_0;
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	t_0 = c_m * (x_m * s_m)
	return (math.cos((2.0 * x_m)) / t_0) / t_0
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	t_0 = Float64(c_m * Float64(x_m * s_m))
	return Float64(Float64(cos(Float64(2.0 * x_m)) / t_0) / t_0)
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	t_0 = c_m * (x_m * s_m);
	tmp = (cos((2.0 * x_m)) / t_0) / t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\frac{\frac{\cos \left(2 \cdot x\_m\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 67.2%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.5% accurate, 18.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \frac{\frac{1}{c\_m}}{x\_m \cdot s\_m} \cdot \left(\frac{1}{c\_m} \cdot \frac{1}{x\_m \cdot s\_m}\right) \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (* (/ (/ 1.0 c_m) (* x_m s_m)) (* (/ 1.0 c_m) (/ 1.0 (* x_m s_m)))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	return ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    code = ((1.0d0 / c_m) / (x_m * s_m)) * ((1.0d0 / c_m) * (1.0d0 / (x_m * s_m)))
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	return ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	return ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)))
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	return Float64(Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) * Float64(Float64(1.0 / c_m) * Float64(1.0 / Float64(x_m * s_m))))
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	tmp = ((1.0 / c_m) / (x_m * s_m)) * ((1.0 / c_m) * (1.0 / (x_m * s_m)));
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c$95$m), $MachinePrecision] * N[(1.0 / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m} \cdot \left(\frac{1}{c\_m} \cdot \frac{1}{x\_m \cdot s\_m}\right)
\end{array}
Derivation
  1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.5% accurate, 24.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \frac{\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m}}{c\_m \cdot \left(x\_m \cdot s\_m\right)} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (/ (/ (/ 1.0 c_m) (* x_m s_m)) (* c_m (* x_m s_m))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	return ((1.0 / c_m) / (x_m * s_m)) / (c_m * (x_m * s_m));
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    code = ((1.0d0 / c_m) / (x_m * s_m)) / (c_m * (x_m * s_m))
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	return ((1.0 / c_m) / (x_m * s_m)) / (c_m * (x_m * s_m));
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	return ((1.0 / c_m) / (x_m * s_m)) / (c_m * (x_m * s_m))
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	return Float64(Float64(Float64(1.0 / c_m) / Float64(x_m * s_m)) / Float64(c_m * Float64(x_m * s_m)))
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	tmp = ((1.0 / c_m) / (x_m * s_m)) / (c_m * (x_m * s_m));
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision] / N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\frac{\frac{\frac{1}{c\_m}}{x\_m \cdot s\_m}}{c\_m \cdot \left(x\_m \cdot s\_m\right)}
\end{array}
Derivation
  1. Initial program 67.2%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.5% accurate, 24.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \begin{array}{l} t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\ \frac{\frac{1}{t\_0}}{t\_0} \end{array} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (let* ((t_0 (* c_m (* x_m s_m)))) (/ (/ 1.0 t_0) t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	double t_0 = c_m * (x_m * s_m);
	return (1.0 / t_0) / t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    real(8) :: t_0
    t_0 = c_m * (x_m * s_m)
    code = (1.0d0 / t_0) / t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	double t_0 = c_m * (x_m * s_m);
	return (1.0 / t_0) / t_0;
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	t_0 = c_m * (x_m * s_m)
	return (1.0 / t_0) / t_0
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	t_0 = Float64(c_m * Float64(x_m * s_m))
	return Float64(Float64(1.0 / t_0) / t_0)
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	t_0 = c_m * (x_m * s_m);
	tmp = (1.0 / t_0) / t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\frac{\frac{1}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 67.2%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 76.1% accurate, 24.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ c_m = \left|c\right| \\ s_m = \left|s\right| \\ [x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\ \\ \frac{1}{\left(c\_m \cdot s\_m\right) \cdot \left(x\_m \cdot \left(x\_m \cdot \left(c\_m \cdot s\_m\right)\right)\right)} \end{array} \]
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
 :precision binary64
 (/ 1.0 (* (* c_m s_m) (* x_m (* x_m (* c_m s_m))))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
	return 1.0 / ((c_m * s_m) * (x_m * (x_m * (c_m * s_m))));
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: c_m
    real(8), intent (in) :: s_m
    code = 1.0d0 / ((c_m * s_m) * (x_m * (x_m * (c_m * s_m))))
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
	return 1.0 / ((c_m * s_m) * (x_m * (x_m * (c_m * s_m))));
}
x_m = math.fabs(x)
c_m = math.fabs(c)
s_m = math.fabs(s)
[x_m, c_m, s_m] = sort([x_m, c_m, s_m])
def code(x_m, c_m, s_m):
	return 1.0 / ((c_m * s_m) * (x_m * (x_m * (c_m * s_m))))
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
x_m, c_m, s_m = sort([x_m, c_m, s_m])
function code(x_m, c_m, s_m)
	return Float64(1.0 / Float64(Float64(c_m * s_m) * Float64(x_m * Float64(x_m * Float64(c_m * s_m)))))
end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
	tmp = 1.0 / ((c_m * s_m) * (x_m * (x_m * (c_m * s_m))));
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := N[(1.0 / N[(N[(c$95$m * s$95$m), $MachinePrecision] * N[(x$95$m * N[(x$95$m * N[(c$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\frac{1}{\left(c\_m \cdot s\_m\right) \cdot \left(x\_m \cdot \left(x\_m \cdot \left(c\_m \cdot s\_m\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 67.2%

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt67.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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