mixedcos

Percentage Accurate: 66.5% → 97.3%
Time: 14.4s
Alternatives: 10
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 10 alternatives:

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

Initial Program: 66.5% accurate, 1.0× speedup?

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

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

Alternative 1: 97.3% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\frac{\frac{1}{c}}{x \cdot s} \cdot \cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)} \]
  10. Add Preprocessing

Alternative 2: 86.7% accurate, 2.6× speedup?

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

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


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

    1. Initial program 57.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999986e-29 < x

    1. Initial program 58.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 87.0% accurate, 2.6× speedup?

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

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


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

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.75000000000000003e-22 < x

    1. Initial program 58.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 97.3% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\frac{1}{c}}{x \cdot s} \cdot \frac{\cos \left(x \cdot 2\right)}{c \cdot \left(x \cdot s\right)} \]
  10. Add Preprocessing

Alternative 5: 97.3% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.5% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.5% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 78.4% accurate, 22.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{-1}{c}}{\left(c \cdot \left(-\color{blue}{s \cdot x}\right)\right) \cdot \left(x \cdot s\right)} \]
    11. distribute-rgt-neg-in76.1%

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

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

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

Alternative 9: 77.0% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 78.8% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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