mixedcos

Percentage Accurate: 66.5% → 98.1%
Time: 20.2s
Alternatives: 15
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 15 alternatives:

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

Initial Program: 66.5% accurate, 1.0× speedup?

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

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

Alternative 1: 98.1% accurate, 2.6× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.2000000000000001e-18 < x < 9.9999999999999992e124

    1. Initial program 68.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999992e124 < x

    1. Initial program 65.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 97.0% accurate, 1.5× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\cos \left(2 \cdot x\right)}{{\left(x \cdot \left(c \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
 (/ (cos (* 2.0 x)) (pow (* x (* c s)) 2.0)))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	return cos((2.0 * x)) / pow((x * (c * 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 = cos((2.0d0 * x)) / ((x * (c * 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.cos((2.0 * x)) / Math.pow((x * (c * s)), 2.0);
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	return math.cos((2.0 * x)) / math.pow((x * (c * s)), 2.0)
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(cos(Float64(2.0 * x)) / (Float64(x * Float64(c * 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 = cos((2.0 * x)) / ((x * (c * 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[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[Power[N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\cos \left(2 \cdot x\right)}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}
\end{array}
Derivation
  1. Initial program 65.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. associate-/r*64.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.7% accurate, 1.5× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\cos \left(2 \cdot x\right)}{{\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
 (/ (cos (* 2.0 x)) (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 cos((2.0 * x)) / 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 = cos((2.0d0 * x)) / ((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.cos((2.0 * x)) / 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.cos((2.0 * x)) / 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(cos(Float64(2.0 * x)) / (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 = cos((2.0 * x)) / ((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[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}
\end{array}
Derivation
  1. Initial program 65.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. associate-/r*64.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < x

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 92.0% accurate, 2.7× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 4.2 \cdot 10^{-17}:\\ \;\;\;\;\frac{-1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 4.2e-17)
   (/ -1.0 (* (* c (* x s)) (* c (* x (- s)))))
   (/ (cos (* 2.0 x)) (* x (* x (* c (* s (* 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 <= 4.2e-17) {
		tmp = -1.0 / ((c * (x * s)) * (c * (x * -s)));
	} else {
		tmp = cos((2.0 * x)) / (x * (x * (c * (s * (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 <= 4.2d-17) then
        tmp = (-1.0d0) / ((c * (x * s)) * (c * (x * -s)))
    else
        tmp = cos((2.0d0 * x)) / (x * (x * (c * (s * (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 <= 4.2e-17) {
		tmp = -1.0 / ((c * (x * s)) * (c * (x * -s)));
	} else {
		tmp = Math.cos((2.0 * x)) / (x * (x * (c * (s * (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 <= 4.2e-17:
		tmp = -1.0 / ((c * (x * s)) * (c * (x * -s)))
	else:
		tmp = math.cos((2.0 * x)) / (x * (x * (c * (s * (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 <= 4.2e-17)
		tmp = Float64(-1.0 / Float64(Float64(c * Float64(x * s)) * Float64(c * Float64(x * Float64(-s)))));
	else
		tmp = Float64(cos(Float64(2.0 * x)) / Float64(x * Float64(x * Float64(c * Float64(s * Float64(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 <= 4.2e-17)
		tmp = -1.0 / ((c * (x * s)) * (c * (x * -s)));
	else
		tmp = cos((2.0 * x)) / (x * (x * (c * (s * (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, 4.2e-17], N[(-1.0 / N[(N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(c * N[(x * (-s)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(c * N[(s * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.2 \cdot 10^{-17}:\\
\;\;\;\;\frac{-1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.19999999999999984e-17 < x

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 95.4% 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.6 \cdot 10^{-60}:\\ \;\;\;\;\frac{\frac{1}{c}}{\left(x \cdot s\right) \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(t_0 \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.6e-60)
     (/ (/ 1.0 c) (* (* x s) t_0))
     (/ (cos (* 2.0 x)) (* s (* t_0 (* 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.6e-60) {
		tmp = (1.0 / c) / ((x * s) * t_0);
	} else {
		tmp = cos((2.0 * x)) / (s * (t_0 * (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.6d-60) then
        tmp = (1.0d0 / c) / ((x * s) * t_0)
    else
        tmp = cos((2.0d0 * x)) / (s * (t_0 * (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.6e-60) {
		tmp = (1.0 / c) / ((x * s) * t_0);
	} else {
		tmp = Math.cos((2.0 * x)) / (s * (t_0 * (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.6e-60:
		tmp = (1.0 / c) / ((x * s) * t_0)
	else:
		tmp = math.cos((2.0 * x)) / (s * (t_0 * (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.6e-60)
		tmp = Float64(Float64(1.0 / c) / Float64(Float64(x * s) * t_0));
	else
		tmp = Float64(cos(Float64(2.0 * x)) / Float64(s * Float64(t_0 * 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.6e-60)
		tmp = (1.0 / c) / ((x * s) * t_0);
	else
		tmp = cos((2.0 * x)) / (s * (t_0 * (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.6e-60], N[(N[(1.0 / c), $MachinePrecision] / N[(N[(x * s), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(s * N[(t$95$0 * 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.6 \cdot 10^{-60}:\\
\;\;\;\;\frac{\frac{1}{c}}{\left(x \cdot s\right) \cdot t_0}\\

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


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

    1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.6000000000000001e-60 < x

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 78.9% accurate, 13.5× 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 10^{-16}:\\ \;\;\;\;\frac{-1}{t_0 \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+122}:\\ \;\;\;\;\frac{1 + -2 \cdot \left(x \cdot x\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{s \cdot t_0}}{x \cdot c}\\ \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 1e-16)
     (/ -1.0 (* t_0 (* c (* x (- s)))))
     (if (<= x 3.6e+122)
       (/ (+ 1.0 (* -2.0 (* x x))) (* x (* x (* c (* s (* c s))))))
       (/ (/ 1.0 (* s t_0)) (* 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 <= 1e-16) {
		tmp = -1.0 / (t_0 * (c * (x * -s)));
	} else if (x <= 3.6e+122) {
		tmp = (1.0 + (-2.0 * (x * x))) / (x * (x * (c * (s * (c * s)))));
	} else {
		tmp = (1.0 / (s * t_0)) / (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 <= 1d-16) then
        tmp = (-1.0d0) / (t_0 * (c * (x * -s)))
    else if (x <= 3.6d+122) then
        tmp = (1.0d0 + ((-2.0d0) * (x * x))) / (x * (x * (c * (s * (c * s)))))
    else
        tmp = (1.0d0 / (s * t_0)) / (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 <= 1e-16) {
		tmp = -1.0 / (t_0 * (c * (x * -s)));
	} else if (x <= 3.6e+122) {
		tmp = (1.0 + (-2.0 * (x * x))) / (x * (x * (c * (s * (c * s)))));
	} else {
		tmp = (1.0 / (s * t_0)) / (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 <= 1e-16:
		tmp = -1.0 / (t_0 * (c * (x * -s)))
	elif x <= 3.6e+122:
		tmp = (1.0 + (-2.0 * (x * x))) / (x * (x * (c * (s * (c * s)))))
	else:
		tmp = (1.0 / (s * t_0)) / (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 <= 1e-16)
		tmp = Float64(-1.0 / Float64(t_0 * Float64(c * Float64(x * Float64(-s)))));
	elseif (x <= 3.6e+122)
		tmp = Float64(Float64(1.0 + Float64(-2.0 * Float64(x * x))) / Float64(x * Float64(x * Float64(c * Float64(s * Float64(c * s))))));
	else
		tmp = Float64(Float64(1.0 / Float64(s * t_0)) / 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 <= 1e-16)
		tmp = -1.0 / (t_0 * (c * (x * -s)));
	elseif (x <= 3.6e+122)
		tmp = (1.0 + (-2.0 * (x * x))) / (x * (x * (c * (s * (c * s)))));
	else
		tmp = (1.0 / (s * t_0)) / (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, 1e-16], N[(-1.0 / N[(t$95$0 * N[(c * N[(x * (-s)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.6e+122], N[(N[(1.0 + N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x * N[(c * N[(s * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(s * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x * c), $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 10^{-16}:\\
\;\;\;\;\frac{-1}{t_0 \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\

\mathbf{elif}\;x \leq 3.6 \cdot 10^{+122}:\\
\;\;\;\;\frac{1 + -2 \cdot \left(x \cdot x\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s \cdot t_0}}{x \cdot c}\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999998e-17 < x < 3.6000000000000003e122

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000003e122 < x

    1. Initial program 63.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 79.1% accurate, 14.9× 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 3.6 \cdot 10^{+122}:\\ \;\;\;\;\frac{1 + -2 \cdot \left(x \cdot x\right)}{t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{s \cdot t_0}}{x \cdot c}\\ \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 3.6e+122)
     (/ (+ 1.0 (* -2.0 (* x x))) (* t_0 t_0))
     (/ (/ 1.0 (* s t_0)) (* 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 <= 3.6e+122) {
		tmp = (1.0 + (-2.0 * (x * x))) / (t_0 * t_0);
	} else {
		tmp = (1.0 / (s * t_0)) / (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 <= 3.6d+122) then
        tmp = (1.0d0 + ((-2.0d0) * (x * x))) / (t_0 * t_0)
    else
        tmp = (1.0d0 / (s * t_0)) / (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 <= 3.6e+122) {
		tmp = (1.0 + (-2.0 * (x * x))) / (t_0 * t_0);
	} else {
		tmp = (1.0 / (s * t_0)) / (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 <= 3.6e+122:
		tmp = (1.0 + (-2.0 * (x * x))) / (t_0 * t_0)
	else:
		tmp = (1.0 / (s * t_0)) / (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 <= 3.6e+122)
		tmp = Float64(Float64(1.0 + Float64(-2.0 * Float64(x * x))) / Float64(t_0 * t_0));
	else
		tmp = Float64(Float64(1.0 / Float64(s * t_0)) / 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 <= 3.6e+122)
		tmp = (1.0 + (-2.0 * (x * x))) / (t_0 * t_0);
	else
		tmp = (1.0 / (s * t_0)) / (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, 3.6e+122], N[(N[(1.0 + N[(-2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(s * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x * c), $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 3.6 \cdot 10^{+122}:\\
\;\;\;\;\frac{1 + -2 \cdot \left(x \cdot x\right)}{t_0 \cdot t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s \cdot t_0}}{x \cdot c}\\


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

    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. associate-/r*64.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000003e122 < x

    1. Initial program 63.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 79.8% accurate, 22.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 63.2% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 69.7% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 79.0% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 79.9% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 27.4% accurate, 34.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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