mixedcos

Percentage Accurate: 67.4% → 99.3%
Time: 11.0s
Alternatives: 13
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 13 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.3% accurate, 1.4× speedup?

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

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


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

    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.59999999999999971e-84 < x

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.3% accurate, 2.6× speedup?

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

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


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

    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-82 < x

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 93.0% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-26 < x

    1. Initial program 66.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. *-commutative66.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 96.7% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.30000000000000004e-83 < x

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 99.1% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.14999999999999995e-83 < x

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 98.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.9999999999999995e-29 < x

    1. Initial program 66.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. *-commutative66.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 80.0% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 71.1% accurate, 18.3× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;c \leq 1.5 \cdot 10^{-157} \lor \neg \left(c \leq 1.95 \cdot 10^{-25}\right):\\ \;\;\;\;\frac{1}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (or (<= c 1.5e-157) (not (<= c 1.95e-25)))
   (/ 1.0 (* s (* s (* x (* c (* x c))))))
   (/ 1.0 (* s (* (* x x) (* s (* c c)))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if ((c <= 1.5e-157) || !(c <= 1.95e-25)) {
		tmp = 1.0 / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = 1.0 / (s * ((x * x) * (s * (c * c))));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if ((c <= 1.5d-157) .or. (.not. (c <= 1.95d-25))) then
        tmp = 1.0d0 / (s * (s * (x * (c * (x * c)))))
    else
        tmp = 1.0d0 / (s * ((x * x) * (s * (c * c))))
    end if
    code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if ((c <= 1.5e-157) || !(c <= 1.95e-25)) {
		tmp = 1.0 / (s * (s * (x * (c * (x * c)))));
	} else {
		tmp = 1.0 / (s * ((x * x) * (s * (c * c))));
	}
	return tmp;
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if (c <= 1.5e-157) or not (c <= 1.95e-25):
		tmp = 1.0 / (s * (s * (x * (c * (x * c)))))
	else:
		tmp = 1.0 / (s * ((x * x) * (s * (c * c))))
	return tmp
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if ((c <= 1.5e-157) || !(c <= 1.95e-25))
		tmp = Float64(1.0 / Float64(s * Float64(s * Float64(x * Float64(c * Float64(x * c))))));
	else
		tmp = Float64(1.0 / Float64(s * Float64(Float64(x * x) * Float64(s * Float64(c * c)))));
	end
	return tmp
end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if ((c <= 1.5e-157) || ~((c <= 1.95e-25)))
		tmp = 1.0 / (s * (s * (x * (c * (x * c)))));
	else
		tmp = 1.0 / (s * ((x * x) * (s * (c * c))));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[Or[LessEqual[c, 1.5e-157], N[Not[LessEqual[c, 1.95e-25]], $MachinePrecision]], N[(1.0 / N[(s * N[(s * N[(x * N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(s * N[(N[(x * x), $MachinePrecision] * N[(s * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;c \leq 1.5 \cdot 10^{-157} \lor \neg \left(c \leq 1.95 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{1}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 1.5e-157 or 1.95e-25 < c

    1. Initial program 64.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. *-commutative64.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5e-157 < c < 1.95e-25

    1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq 1.5 \cdot 10^{-157} \lor \neg \left(c \leq 1.95 \cdot 10^{-25}\right):\\ \;\;\;\;\frac{1}{s \cdot \left(s \cdot \left(x \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\ \end{array} \]

Alternative 9: 69.6% accurate, 20.8× speedup?

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

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


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

    1. Initial program 68.3%

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

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

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

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

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

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

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

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

    if 3.10000000000000005e115 < s

    1. Initial program 46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 69.4% accurate, 20.8× speedup?

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

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


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

    1. Initial program 68.3%

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

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

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

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

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

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

    if 1.86e115 < s

    1. Initial program 46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 69.2% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 78.1% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 28.7% accurate, 34.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Reproduce

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