mixedcos

Percentage Accurate: 67.0% → 98.0%
Time: 12.8s
Alternatives: 8
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 67.0% accurate, 1.0× speedup?

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

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

Alternative 1: 98.0% accurate, 2.6× speedup?

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

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


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

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
      10. unpow-prod-down96.8%

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
      13. pow-flip96.8%

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

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

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

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

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

    if 1.5e118 < x

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
      10. unpow-prod-down91.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.2% accurate, 2.6× speedup?

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

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


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

    1. Initial program 68.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.0000000000000002e-26 < x

    1. Initial program 61.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
      13. pow-flip93.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 98.1% accurate, 2.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{t_0} \cdot \frac{1}{t_0}\\


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

    1. Initial program 69.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. *-un-lft-identity69.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
      10. unpow-prod-down96.8%

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

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

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

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

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

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

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

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

    if 3.1000000000000002e103 < x

    1. Initial program 51.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
      10. unpow-prod-down92.1%

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot {\color{blue}{\left(c \cdot \left|s \cdot x\right|\right)}}^{-2} \]
      12. metadata-eval92.1%

        \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
      13. pow-flip90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 94.9% accurate, 2.7× speedup?

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

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.50000000000000001e-46 < x

    1. Initial program 61.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. *-un-lft-identity61.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
      10. unpow-prod-down95.4%

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

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

        \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
      13. pow-flip94.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 97.3% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
    10. unpow-prod-down96.1%

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

      \[\leadsto \cos \left(2 \cdot x\right) \cdot {\color{blue}{\left(c \cdot \left|s \cdot x\right|\right)}}^{-2} \]
    12. metadata-eval96.1%

      \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
    13. pow-flip95.8%

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

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

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

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

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

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

Alternative 6: 79.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.5% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(2 \cdot x\right) \cdot \left({\left(\left|s \cdot x\right|\right)}^{\color{blue}{-2}} \cdot {c}^{-2}\right) \]
    10. unpow-prod-down96.1%

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

      \[\leadsto \cos \left(2 \cdot x\right) \cdot {\color{blue}{\left(c \cdot \left|s \cdot x\right|\right)}}^{-2} \]
    12. metadata-eval96.1%

      \[\leadsto \cos \left(2 \cdot x\right) \cdot {\left(c \cdot \left|s \cdot x\right|\right)}^{\color{blue}{\left(-2\right)}} \]
    13. pow-flip95.8%

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

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

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

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

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

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

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

Alternative 8: 79.5% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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