mixedcos

Percentage Accurate: 66.9% → 97.5%
Time: 12.8s
Alternatives: 9
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 9 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.9% 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.5% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto {\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \cdot \cos \left(x \cdot 2\right) \]
  9. Add Preprocessing

Alternative 2: 97.2% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 97.5% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 79.7% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{\left|s \cdot x\right| \cdot \left|s \cdot x\right|}} \]
    3. sqr-abs68.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{-1}} \cdot \frac{1}{s \cdot \left(x \cdot c\right)} \]
    19. unpow-179.3%

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

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

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

Alternative 5: 76.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 77.5% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.7% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 78.1% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(\frac{1}{\color{blue}{c \cdot \left|s \cdot x\right|}}\right)}^{2} \]
    8. add-sqr-sqrt44.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 79.1% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(\frac{1}{\color{blue}{c \cdot \left|s \cdot x\right|}}\right)}^{2} \]
    8. add-sqr-sqrt44.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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