mixedcos

Percentage Accurate: 66.5% → 99.0%
Time: 11.7s
Alternatives: 13
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 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: 99.0% accurate, 2.6× speedup?

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

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


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

    1. Initial program 62.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. unpow262.2%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac62.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.9%

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

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

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

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

    if 1.16e13 < x

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 62.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. unpow262.5%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.7%

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

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

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

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

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

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

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

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

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

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

    if 3.3499999999999999e-18 < x

    1. Initial program 70.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 90.4% 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 2.8 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \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 2.8e-5)
   (/ (/ (/ 1.0 (* x s)) c) (* c (* x s)))
   (/ (cos (* x 2.0)) (* x (* c (* c (* s (* x 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 <= 2.8e-5) {
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	} else {
		tmp = cos((x * 2.0)) / (x * (c * (c * (s * (x * s)))));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 2.8d-5) then
        tmp = ((1.0d0 / (x * s)) / c) / (c * (x * s))
    else
        tmp = cos((x * 2.0d0)) / (x * (c * (c * (s * (x * s)))))
    end if
    code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 2.8e-5) {
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	} else {
		tmp = Math.cos((x * 2.0)) / (x * (c * (c * (s * (x * 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 <= 2.8e-5:
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s))
	else:
		tmp = math.cos((x * 2.0)) / (x * (c * (c * (s * (x * 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 <= 2.8e-5)
		tmp = Float64(Float64(Float64(1.0 / Float64(x * s)) / c) / Float64(c * Float64(x * s)));
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(c * Float64(c * Float64(s * Float64(x * s))))));
	end
	return tmp
end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 2.8e-5)
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	else
		tmp = cos((x * 2.0)) / (x * (c * (c * (s * (x * s)))));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 2.8e-5], N[(N[(N[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(c * N[(c * N[(s * N[(x * 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 2.8 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\

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


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

    1. Initial program 63.1%

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac63.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.8%

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

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

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

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

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

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

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

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

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

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

    if 2.79999999999999996e-5 < x

    1. Initial program 69.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*69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 90.8% accurate, 2.7× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.0195:\\ \;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(\left(c \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot s\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 0.0195)
   (/ (/ (/ 1.0 (* x s)) c) (* c (* x s)))
   (/ (cos (* x 2.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 tmp;
	if (x <= 0.0195) {
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	} else {
		tmp = cos((x * 2.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) :: tmp
    if (x <= 0.0195d0) then
        tmp = ((1.0d0 / (x * s)) / c) / (c * (x * s))
    else
        tmp = cos((x * 2.0d0)) / (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 tmp;
	if (x <= 0.0195) {
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	} else {
		tmp = Math.cos((x * 2.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):
	tmp = 0
	if x <= 0.0195:
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s))
	else:
		tmp = math.cos((x * 2.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)
	tmp = 0.0
	if (x <= 0.0195)
		tmp = Float64(Float64(Float64(1.0 / Float64(x * s)) / c) / Float64(c * Float64(x * s)));
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(Float64(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)
	tmp = 0.0;
	if (x <= 0.0195)
		tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
	else
		tmp = cos((x * 2.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_] := If[LessEqual[x, 0.0195], N[(N[(N[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision] * N[(s * s), $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 0.0195:\\
\;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\

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


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

    1. Initial program 63.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. unpow263.0%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac62.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.8%

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

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

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

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

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

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

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

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

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

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

    if 0.0195 < x

    1. Initial program 70.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 97.3% accurate, 2.7× speedup?

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

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


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

    1. Initial program 62.9%

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac62.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.8%

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

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

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

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

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

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

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

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

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

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

    if 1e-13 < x

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 62.9%

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac62.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 95.8%

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

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

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

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

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

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

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

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

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

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

    if 2.25e-13 < x

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 98.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.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. unpow264.0%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.00000000000000039e119 < x

    1. Initial program 69.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. *-commutative69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 98.8% accurate, 2.7× speedup?

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

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


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

    1. Initial program 64.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. unpow264.0%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \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)}}} \]
      3. times-frac64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 inf 96.3%

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

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

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

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

    if 7.20000000000000025e117 < x

    1. Initial program 69.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. *-commutative69.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 55.7% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 79.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

      \[\leadsto \frac{1 \cdot \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)}}} \]
    3. times-frac64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
  7. Applied egg-rr96.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 51.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \frac{1}{c}}}{c}}{{s}^{2} \cdot {x}^{2}} \]
    8. associate-*l/51.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{x \cdot s} \cdot \frac{\frac{1}{c}}{x \cdot s}} \]
    14. unpow276.8%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{c}}{s}}{x} \cdot \frac{\frac{\frac{1}{c}}{s}}{x}} \]
    2. clear-num77.6%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{\frac{1}{c}}{s}}}} \cdot \frac{\frac{\frac{1}{c}}{s}}{x} \]
    3. clear-num77.5%

      \[\leadsto \frac{1}{\frac{x}{\frac{\frac{1}{c}}{s}}} \cdot \color{blue}{\frac{1}{\frac{x}{\frac{\frac{1}{c}}{s}}}} \]
    4. frac-times77.5%

      \[\leadsto \color{blue}{\frac{1 \cdot 1}{\frac{x}{\frac{\frac{1}{c}}{s}} \cdot \frac{x}{\frac{\frac{1}{c}}{s}}}} \]
    5. metadata-eval77.5%

      \[\leadsto \frac{\color{blue}{1}}{\frac{x}{\frac{\frac{1}{c}}{s}} \cdot \frac{x}{\frac{\frac{1}{c}}{s}}} \]
    6. div-inv77.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{\frac{c}{1}}\right)\right)} \]
    15. /-rgt-identity77.6%

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

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

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

Alternative 11: 80.5% 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 64.8%

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

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

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

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

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

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

      \[\leadsto \frac{1 \cdot \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)}}} \]
    3. times-frac64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
  7. Applied egg-rr96.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 76.8%

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

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

Alternative 12: 80.6% accurate, 24.1× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ (/ (/ 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(Float64(1.0 / c) / 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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}
\end{array}
Derivation
  1. Initial program 64.8%

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

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

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

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

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

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

      \[\leadsto \frac{1 \cdot \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)}}} \]
    3. times-frac64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
  7. Applied egg-rr96.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 76.8%

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

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

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

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

Alternative 13: 80.6% accurate, 24.1× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: 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 s)) c) (* 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 / (x * s)) / c) / (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 / (x * s)) / c) / (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 / (x * s)) / c) / (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 / (x * s)) / c) / (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(Float64(1.0 / Float64(x * s)) / c) / 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 / (x * s)) / c) / (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[(N[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}
\end{array}
Derivation
  1. Initial program 64.8%

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

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

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

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

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

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

      \[\leadsto \frac{1 \cdot \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)}}} \]
    3. times-frac64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
  7. Applied egg-rr96.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 inf 96.4%

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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