mixedcos

Percentage Accurate: 66.3% → 99.2%
Time: 12.3s
Alternatives: 12
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 12 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.3% 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.2% 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)\\ t_1 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;x \leq 7.4 \cdot 10^{+44}:\\ \;\;\;\;\frac{t_0}{t_1 \cdot t_1}\\ \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))) (t_1 (* c (* x s))))
   (if (<= x 7.4e+44)
     (/ t_0 (* t_1 t_1))
     (* (/ 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 t_1 = c * (x * s);
	double tmp;
	if (x <= 7.4e+44) {
		tmp = t_0 / (t_1 * t_1);
	} 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) :: t_1
    real(8) :: tmp
    t_0 = cos((x * 2.0d0))
    t_1 = c * (x * s)
    if (x <= 7.4d+44) then
        tmp = t_0 / (t_1 * t_1)
    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 t_1 = c * (x * s);
	double tmp;
	if (x <= 7.4e+44) {
		tmp = t_0 / (t_1 * t_1);
	} 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))
	t_1 = c * (x * s)
	tmp = 0
	if x <= 7.4e+44:
		tmp = t_0 / (t_1 * t_1)
	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))
	t_1 = Float64(c * Float64(x * s))
	tmp = 0.0
	if (x <= 7.4e+44)
		tmp = Float64(t_0 / Float64(t_1 * t_1));
	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));
	t_1 = c * (x * s);
	tmp = 0.0;
	if (x <= 7.4e+44)
		tmp = t_0 / (t_1 * t_1);
	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]}, Block[{t$95$1 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 7.4e+44], N[(t$95$0 / N[(t$95$1 * t$95$1), $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)\\
t_1 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;x \leq 7.4 \cdot 10^{+44}:\\
\;\;\;\;\frac{t_0}{t_1 \cdot t_1}\\

\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 < 7.4000000000000002e44

    1. Initial program 62.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. *-commutative62.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*58.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*59.3%

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

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

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

        \[\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-sqr98.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
    4. Taylor expanded in s around 0 95.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)}} \]
    5. Taylor expanded in s around 0 97.2%

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

    if 7.4000000000000002e44 < x

    1. Initial program 64.3%

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

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

        \[\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.5%

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

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

        \[\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. unpow271.7%

        \[\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-sqr98.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. *-commutative98.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. *-commutative98.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. *-commutative98.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. *-commutative98.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. Simplified98.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)}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity98.1%

        \[\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*97.9%

        \[\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-frac98.0%

        \[\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. *-commutative98.0%

        \[\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-rr98.0%

      \[\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 simplification97.4%

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

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


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

    1. Initial program 60.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. *-commutative60.5%

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

        \[\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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.10000000000000005e-5 < x

    1. Initial program 68.3%

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

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

        \[\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*63.2%

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

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

        \[\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*69.5%

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

        \[\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. *-commutative71.3%

        \[\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. unpow271.3%

        \[\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. Simplified71.3%

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 60.3%

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

        \[\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*56.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2e-19 < x

    1. Initial program 68.7%

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

        \[\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*62.4%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
      3. associate-*r*63.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. unpow263.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-sqr74.9%

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

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

        \[\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. *-commutative98.4%

        \[\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. *-commutative98.4%

        \[\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. *-commutative98.4%

        \[\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. *-commutative98.4%

        \[\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. Simplified98.4%

      \[\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 simplification90.6%

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

Alternative 4: 96.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 := c \cdot \left(x \cdot s\right)\\ \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 (* 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 = c * (x * s);
	return cos((x * 2.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 = cos((x * 2.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 Math.cos((x * 2.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 math.cos((x * 2.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(cos(Float64(x * 2.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 = c * (x * s);
	tmp = cos((x * 2.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[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 := c \cdot \left(x \cdot s\right)\\
\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
  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. *-commutative62.5%

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
    3. associate-*r*59.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. unpow259.1%

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

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

      \[\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-sqr98.0%

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

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

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

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

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

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

    \[\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)}} \]
  5. Taylor expanded in s around 0 96.7%

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

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

Alternative 5: 80.1% accurate, 2.9× speedup?

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
    3. associate-*r*59.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. unpow259.1%

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

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

      \[\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-sqr98.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 80.2% accurate, 3.0× speedup?

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
    3. associate-*r*59.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. unpow259.1%

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

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

      \[\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-sqr98.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left({x}^{2} \cdot \left(s \cdot s\right)\right)}} \]
    4. unpow252.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. Simplified52.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. Step-by-step derivation
    1. *-commutative52.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.2% accurate, 18.3× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1.38 \cdot 10^{-191}:\\ \;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c \cdot s} \cdot \frac{\frac{1}{s \cdot \left(x \cdot c\right)}}{x}\\ \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 1.38e-191)
   (/ 1.0 (* (* c c) (* (* x s) (* x s))))
   (* (/ 1.0 (* c s)) (/ (/ 1.0 (* s (* x c))) x))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 1.38e-191) {
		tmp = 1.0 / ((c * c) * ((x * s) * (x * s)));
	} else {
		tmp = (1.0 / (c * s)) * ((1.0 / (s * (x * c))) / x);
	}
	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 <= 1.38d-191) then
        tmp = 1.0d0 / ((c * c) * ((x * s) * (x * s)))
    else
        tmp = (1.0d0 / (c * s)) * ((1.0d0 / (s * (x * c))) / x)
    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 <= 1.38e-191) {
		tmp = 1.0 / ((c * c) * ((x * s) * (x * s)));
	} else {
		tmp = (1.0 / (c * s)) * ((1.0 / (s * (x * c))) / x);
	}
	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 <= 1.38e-191:
		tmp = 1.0 / ((c * c) * ((x * s) * (x * s)))
	else:
		tmp = (1.0 / (c * s)) * ((1.0 / (s * (x * c))) / x)
	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 <= 1.38e-191)
		tmp = Float64(1.0 / Float64(Float64(c * c) * Float64(Float64(x * s) * Float64(x * s))));
	else
		tmp = Float64(Float64(1.0 / Float64(c * s)) * Float64(Float64(1.0 / Float64(s * Float64(x * c))) / x));
	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 <= 1.38e-191)
		tmp = 1.0 / ((c * c) * ((x * s) * (x * s)));
	else
		tmp = (1.0 / (c * s)) * ((1.0 / (s * (x * c))) / x);
	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, 1.38e-191], N[(1.0 / N[(N[(c * c), $MachinePrecision] * N[(N[(x * s), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(c * s), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.38 \cdot 10^{-191}:\\
\;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}\\

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


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

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

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

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

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

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

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

        \[\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.4%

        \[\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.4%

        \[\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.4%

        \[\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.4%

        \[\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.4%

      \[\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 95.6%

      \[\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)}} \]
    5. Step-by-step derivation
      1. associate-*r*97.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.38000000000000003e-191 < x

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 74.3% accurate, 20.8× speedup?

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

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


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

    1. Initial program 60.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. *-commutative60.9%

        \[\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.0%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
      3. associate-*r*58.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. unpow258.1%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}} \]
      5. unswap-sqr74.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. unpow274.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-sqr97.9%

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

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

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

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

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

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

      \[\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)}} \]
    5. Step-by-step derivation
      1. associate-*r*97.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 115000 < x

    1. Initial program 67.2%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. unpow267.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. *-commutative67.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. unpow267.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. Simplified67.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-identity67.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. associate-*r*68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 74.3% accurate, 20.8× speedup?

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

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


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

    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. *-commutative62.2%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
    4. Taylor expanded in s around 0 95.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)}} \]
    5. Step-by-step derivation
      1. associate-*r*97.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.00000000000000037e56 < x

    1. Initial program 63.7%

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

        \[\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.7%

        \[\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.7%

        \[\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.7%

      \[\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.7%

        \[\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. associate-*r*65.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 78.2% accurate, 20.9× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{1}{s \cdot \left(x \cdot c\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 (/ 1.0 (* s (* x c))))) (* 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 = 1.0 / (s * (x * c));
	return 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 = 1.0d0 / (s * (x * c))
    code = 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 = 1.0 / (s * (x * c));
	return 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 = 1.0 / (s * (x * c))
	return 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(1.0 / Float64(s * Float64(x * c)))
	return 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 = 1.0 / (s * (x * c));
	tmp = 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[(1.0 / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{1}{s \cdot \left(x \cdot c\right)}\\
t_0 \cdot t_0
\end{array}
\end{array}
Derivation
  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. associate-/r*61.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 70.9% 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(x \cdot s\right) \cdot \left(x \cdot s\right)\right)} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (/ 1.0 (* (* c c) (* (* x s) (* 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 * c) * ((x * s) * (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 * c) * ((x * s) * (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 * c) * ((x * s) * (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 * c) * ((x * s) * (x * s)))
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(Float64(c * c) * Float64(Float64(x * s) * 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 * c) * ((x * s) * (x * s)));
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[(1.0 / N[(N[(c * c), $MachinePrecision] * N[(N[(x * s), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}
\end{array}
Derivation
  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. *-commutative62.5%

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
    3. associate-*r*59.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. unpow259.1%

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

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

      \[\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-sqr98.0%

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

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

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

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

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

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

    \[\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)}} \]
  5. Step-by-step derivation
    1. associate-*r*96.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 25.9% accurate, 28.5× speedup?

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}} \]
    3. associate-*r*59.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. unpow259.1%

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

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

      \[\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-sqr98.0%

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

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

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

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

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

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

      \[\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*94.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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