mixedcos

Percentage Accurate: 66.5% → 98.4%
Time: 12.7s
Alternatives: 12
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 66.5% accurate, 1.0× speedup?

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

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

Alternative 1: 98.4% accurate, 2.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{t\_0}{x\_m \cdot c\_m}}{x\_m \cdot c\_m} \cdot \frac{1}{s\_m}}{s\_m}\\


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

    1. Initial program 65.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. pow2N/A

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

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

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

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

        \[\leadsto \frac{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot c}}{x \cdot \left(s \cdot s\right)}}{x} \]
      6. associate-/l/N/A

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

        \[\leadsto \frac{\frac{\frac{\cos \left(2 \cdot x\right)}{c}}{c}}{\color{blue}{x} \cdot \left(x \cdot \left(s \cdot s\right)\right)} \]
      8. div-invN/A

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c} \cdot \frac{1}{c}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
      10. unswap-sqrN/A

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

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

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

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

    if 2.00000000000000009e93 < x

    1. Initial program 64.4%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot x\right)\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(\left(s \cdot s\right) \cdot x\right) \cdot x\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      6. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      8. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot {x}^{\color{blue}{2}}\right)\right) \]
      9. pow-prod-downN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(\left(c \cdot s\right) \cdot x\right)}^{\color{blue}{2}}\right)\right) \]
      10. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\left(\left(c \cdot s\right) \cdot x\right), \color{blue}{2}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), x\right), 2\right)\right) \]
      12. *-lowering-*.f6498.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), x\right), 2\right)\right) \]
    4. Applied egg-rr98.7%

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot \color{blue}{s}\right)\right)} \]
      6. swap-sqrN/A

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot c\right)}}{s}}{\color{blue}{x \cdot s}} \]
      14. div-invN/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot c\right)} \cdot \frac{1}{s}}{\color{blue}{x} \cdot s} \]
      15. times-fracN/A

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

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

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

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

Alternative 2: 96.9% accurate, 2.6× speedup?

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

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


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

    1. Initial program 65.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. pow2N/A

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

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

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

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

        \[\leadsto \frac{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot c}}{x \cdot \left(s \cdot s\right)}}{x} \]
      6. associate-/l/N/A

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

        \[\leadsto \frac{\frac{\frac{\cos \left(2 \cdot x\right)}{c}}{c}}{\color{blue}{x} \cdot \left(x \cdot \left(s \cdot s\right)\right)} \]
      8. div-invN/A

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c} \cdot \frac{1}{c}}{\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
      10. unswap-sqrN/A

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

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

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

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

    if 1.5500000000000001e95 < x

    1. Initial program 64.4%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot x\right)\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(\left(s \cdot s\right) \cdot x\right) \cdot x\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      6. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      8. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot {x}^{\color{blue}{2}}\right)\right) \]
      9. pow-prod-downN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(\left(c \cdot s\right) \cdot x\right)}^{\color{blue}{2}}\right)\right) \]
      10. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\left(\left(c \cdot s\right) \cdot x\right), \color{blue}{2}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), x\right), 2\right)\right) \]
      12. *-lowering-*.f6498.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), x\right), 2\right)\right) \]
    4. Applied egg-rr98.7%

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(x \cdot s\right) \cdot c\right) \cdot \left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)} \]
      6. *-commutativeN/A

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(x \cdot s\right)}}{x \cdot s} \]
      10. associate-*r*N/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot x\right) \cdot s}}{x \cdot s} \]
      11. *-commutativeN/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot c\right)\right) \cdot s}}{x \cdot s} \]
      12. associate-/l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \left(\left(c \cdot s\right) \cdot \left(\left(x \cdot c\right) \cdot \color{blue}{x}\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \left(\left(\left(c \cdot s\right) \cdot \left(x \cdot c\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\left(\left(c \cdot s\right) \cdot \left(x \cdot c\right)\right), \color{blue}{x}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), \left(x \cdot c\right)\right), x\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(s \cdot c\right), \left(x \cdot c\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(s, c\right), \left(x \cdot c\right)\right), x\right)\right) \]
      7. *-lowering-*.f6497.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(s, c\right), \mathsf{*.f64}\left(x, c\right)\right), x\right)\right) \]
    8. Applied egg-rr97.7%

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

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

Alternative 3: 96.8% accurate, 2.6× speedup?

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

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


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

    1. Initial program 65.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. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      4. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      8. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      9. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left(x \cdot s\right) \cdot c\right), \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(x \cdot s\right), c\right), \left(\color{blue}{\left(x \cdot s\right)} \cdot c\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \left(\left(\color{blue}{x} \cdot s\right) \cdot c\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{c}\right)\right)\right) \]
      14. *-lowering-*.f6496.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right)\right)\right) \]
    4. Applied egg-rr96.4%

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

    if 2.00000000000000009e93 < x

    1. Initial program 64.4%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot x\right)\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(\left(s \cdot s\right) \cdot x\right) \cdot x\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      6. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      8. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot {x}^{\color{blue}{2}}\right)\right) \]
      9. pow-prod-downN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(\left(c \cdot s\right) \cdot x\right)}^{\color{blue}{2}}\right)\right) \]
      10. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\left(\left(c \cdot s\right) \cdot x\right), \color{blue}{2}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), x\right), 2\right)\right) \]
      12. *-lowering-*.f6498.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), x\right), 2\right)\right) \]
    4. Applied egg-rr98.7%

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(x \cdot s\right) \cdot c\right) \cdot \left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)} \]
      6. *-commutativeN/A

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(x \cdot s\right)}}{x \cdot s} \]
      10. associate-*r*N/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot x\right) \cdot s}}{x \cdot s} \]
      11. *-commutativeN/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot c\right)\right) \cdot s}}{x \cdot s} \]
      12. associate-/l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \left(\left(c \cdot s\right) \cdot \left(\left(x \cdot c\right) \cdot \color{blue}{x}\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \left(\left(\left(c \cdot s\right) \cdot \left(x \cdot c\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\left(\left(c \cdot s\right) \cdot \left(x \cdot c\right)\right), \color{blue}{x}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), \left(x \cdot c\right)\right), x\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(s \cdot c\right), \left(x \cdot c\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(s, c\right), \left(x \cdot c\right)\right), x\right)\right) \]
      7. *-lowering-*.f6497.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), s\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(s, c\right), \mathsf{*.f64}\left(x, c\right)\right), x\right)\right) \]
    8. Applied egg-rr97.7%

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

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

Alternative 4: 96.0% accurate, 2.6× speedup?

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

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


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

    1. Initial program 65.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. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      4. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      8. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      9. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left(x \cdot s\right) \cdot c\right), \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(x \cdot s\right), c\right), \left(\color{blue}{\left(x \cdot s\right)} \cdot c\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \left(\left(\color{blue}{x} \cdot s\right) \cdot c\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{c}\right)\right)\right) \]
      14. *-lowering-*.f6496.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right)\right)\right) \]
    4. Applied egg-rr96.4%

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

    if 4.79999999999999965e94 < x

    1. Initial program 64.4%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot x\right)\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(\left(s \cdot s\right) \cdot x\right) \cdot x\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
      6. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      7. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
      8. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(c \cdot s\right)}^{2} \cdot {x}^{\color{blue}{2}}\right)\right) \]
      9. pow-prod-downN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\left(\left(c \cdot s\right) \cdot x\right)}^{\color{blue}{2}}\right)\right) \]
      10. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\left(\left(c \cdot s\right) \cdot x\right), \color{blue}{2}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\left(c \cdot s\right), x\right), 2\right)\right) \]
      12. *-lowering-*.f6498.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{pow.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), x\right), 2\right)\right) \]
    4. Applied egg-rr98.7%

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(x \cdot s\right) \cdot c\right) \cdot \left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)} \]
      6. *-commutativeN/A

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

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(x \cdot s\right)}}{x \cdot s} \]
      10. associate-*r*N/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot x\right) \cdot s}}{x \cdot s} \]
      11. *-commutativeN/A

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot c\right)\right) \cdot s}}{x \cdot s} \]
      12. associate-/l/N/A

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

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

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

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

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

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

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

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

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

Alternative 5: 92.7% accurate, 2.6× speedup?

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

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


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

    1. Initial program 65.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

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
      14. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
      17. *-lowering-*.f6473.9%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    5. Simplified73.9%

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}} \]
    6. Step-by-step derivation
      1. inv-powN/A

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\color{blue}{-1}} \]
      2. sqr-powN/A

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

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

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

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot x\right)\right)}^{\left(\frac{-1}{2}\right)} \]
      6. swap-sqrN/A

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      7. unpow2N/A

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left({\left(\left(c \cdot s\right) \cdot x\right)}^{2}\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
      8. pow-powN/A

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

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{\left(2 \cdot \frac{-1}{2}\right)} \]
      10. metadata-evalN/A

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{-1} \]
      11. inv-powN/A

        \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot \frac{1}{\color{blue}{\left(c \cdot s\right) \cdot x}} \]
      12. div-invN/A

        \[\leadsto \frac{{\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)}}{\color{blue}{\left(c \cdot s\right) \cdot x}} \]
      13. /-lowering-/.f64N/A

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

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

    if 6.00000000000000057e-20 < x

    1. Initial program 66.6%

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

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

        \[\leadsto \mathsf{/.f64}\left(\cos \left(2 \cdot x\right), \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
      2. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\left(2 \cdot x\right)\right), \left(\color{blue}{{c}^{2}} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({\color{blue}{c}}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
      6. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
      12. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
      16. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      18. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
      19. *-lowering-*.f6490.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    5. Simplified90.9%

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

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

Alternative 6: 96.9% accurate, 2.7× speedup?

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
    4. pow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
    7. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
    8. unswap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
    9. unswap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left(x \cdot s\right) \cdot c\right), \color{blue}{\left(\left(x \cdot s\right) \cdot c\right)}\right)\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(x \cdot s\right), c\right), \left(\color{blue}{\left(x \cdot s\right)} \cdot c\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \left(\left(\color{blue}{x} \cdot s\right) \cdot c\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{c}\right)\right)\right) \]
    14. *-lowering-*.f6495.0%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), c\right)\right)\right) \]
  4. Applied egg-rr95.0%

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

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

Alternative 7: 32.2% accurate, 19.5× speedup?

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

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


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

    1. Initial program 64.3%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      4. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      8. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(c \cdot c\right)\right)}\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot s\right)}\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot s\right)\right)}\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot s\right)\right)\right)\right) \]
      13. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(c \cdot \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left(x \cdot s\right)}\right)\right)\right)\right) \]
      16. *-lowering-*.f6493.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, \color{blue}{s}\right)\right)\right)\right)\right) \]
    4. Applied egg-rr93.0%

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + -2 \cdot {x}^{2}\right)}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot {x}^{2}\right)\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{*.f64}\left(x, s\right)}, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot \left(x \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\left(-2 \cdot x\right) \cdot x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6470.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    7. Simplified70.9%

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

      \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left({c}^{2} \cdot \left(s \cdot \color{blue}{s}\right)\right)\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(\left({c}^{2} \cdot s\right) \cdot \color{blue}{s}\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(s \cdot \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(\left(c \cdot c\right) \cdot s\right)\right)\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
      9. *-lowering-*.f6420.1%

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right) \]
    10. Simplified20.1%

      \[\leadsto \color{blue}{\frac{-2}{s \cdot \left(c \cdot \left(c \cdot s\right)\right)}} \]
    11. Step-by-step derivation
      1. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-2\right)}{\color{blue}{\mathsf{neg}\left(s \cdot \left(c \cdot \left(c \cdot s\right)\right)\right)}} \]
      2. metadata-evalN/A

        \[\leadsto \frac{2}{\mathsf{neg}\left(\color{blue}{s \cdot \left(c \cdot \left(c \cdot s\right)\right)}\right)} \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(2, \color{blue}{\left(\mathsf{neg}\left(s \cdot \left(c \cdot \left(c \cdot s\right)\right)\right)\right)}\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(2, \left(0 - \color{blue}{s \cdot \left(c \cdot \left(c \cdot s\right)\right)}\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \color{blue}{\left(s \cdot \left(c \cdot \left(c \cdot s\right)\right)\right)}\right)\right) \]
      6. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \left(s \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{s}\right)\right)\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \left(s \cdot \left(s \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot \left(c \cdot c\right)\right)}\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(s, \color{blue}{\left(c \cdot c\right)}\right)\right)\right)\right) \]
      10. *-lowering-*.f6443.7%

        \[\leadsto \mathsf{/.f64}\left(2, \mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{c}\right)\right)\right)\right)\right) \]
    12. Applied egg-rr43.7%

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

    if 8.99999999999999958e23 < x

    1. Initial program 69.8%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      4. pow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
      7. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      8. unswap-sqrN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
      9. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(c \cdot c\right)\right)}\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot s\right)}\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot s\right)\right)}\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot s\right)\right)\right)\right) \]
      13. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(c \cdot \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left(x \cdot s\right)}\right)\right)\right)\right) \]
      16. *-lowering-*.f6489.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, \color{blue}{s}\right)\right)\right)\right)\right) \]
    4. Applied egg-rr89.2%

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + -2 \cdot {x}^{2}\right)}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot {x}^{2}\right)\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{*.f64}\left(x, s\right)}, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot \left(x \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\left(-2 \cdot x\right) \cdot x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6432.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    7. Simplified32.8%

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

      \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left({c}^{2} \cdot \left(s \cdot \color{blue}{s}\right)\right)\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(\left({c}^{2} \cdot s\right) \cdot \color{blue}{s}\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(s \cdot \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(\left(c \cdot c\right) \cdot s\right)\right)\right) \]
      7. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
      9. *-lowering-*.f6455.2%

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right) \]
    10. Simplified55.2%

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

      \[\leadsto \mathsf{/.f64}\left(-2, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right) \]
    12. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right) \]
      2. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2}\right)}\right)\right)\right) \]
      5. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{s}\right)\right)\right)\right) \]
      6. *-lowering-*.f6460.5%

        \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{s}\right)\right)\right)\right) \]
    13. Simplified60.5%

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

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

Alternative 8: 80.4% accurate, 24.1× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
    4. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    9. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
    13. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
    14. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    16. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    17. *-lowering-*.f6472.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
  5. Simplified72.4%

    \[\leadsto \color{blue}{\frac{1}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}} \]
  6. Step-by-step derivation
    1. inv-powN/A

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\color{blue}{-1}} \]
    2. sqr-powN/A

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

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

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

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot x\right)\right)}^{\left(\frac{-1}{2}\right)} \]
    6. swap-sqrN/A

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(\left(c \cdot s\right) \cdot x\right) \cdot \left(\left(c \cdot s\right) \cdot x\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
    7. unpow2N/A

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left({\left(\left(c \cdot s\right) \cdot x\right)}^{2}\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)} \]
    8. pow-powN/A

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

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{\left(2 \cdot \frac{-1}{2}\right)} \]
    10. metadata-evalN/A

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{-1} \]
    11. inv-powN/A

      \[\leadsto {\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot \frac{1}{\color{blue}{\left(c \cdot s\right) \cdot x}} \]
    12. div-invN/A

      \[\leadsto \frac{{\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)}}{\color{blue}{\left(c \cdot s\right) \cdot x}} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({\left(x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)\right)}^{\left(\frac{-1}{2}\right)}\right), \color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}\right) \]
  7. Applied egg-rr81.2%

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

Alternative 9: 80.3% accurate, 24.1× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
    4. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    9. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
    13. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
    14. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    16. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    17. *-lowering-*.f6472.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
  5. Simplified72.4%

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

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(x \cdot x\right) \cdot \color{blue}{\left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)}\right)\right) \]
    2. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)\right) \]
    3. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right) \cdot \left(\color{blue}{x} \cdot x\right)\right)\right) \]
    4. swap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left(c \cdot s\right) \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\left(\left(c \cdot s\right) \cdot x\right), \color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\left(c \cdot \left(s \cdot x\right)\right), \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\left(c \cdot \left(x \cdot s\right)\right), \left(\left(c \cdot \color{blue}{s}\right) \cdot x\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \left(x \cdot s\right)\right), \left(\color{blue}{\left(c \cdot s\right)} \cdot x\right)\right)\right) \]
    9. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \left(\left(c \cdot \color{blue}{s}\right) \cdot x\right)\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \left(c \cdot \left(x \cdot \color{blue}{s}\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \mathsf{*.f64}\left(c, \color{blue}{\left(x \cdot s\right)}\right)\right)\right) \]
    13. *-lowering-*.f6480.9%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, \color{blue}{s}\right)\right)\right)\right) \]
  7. Applied egg-rr80.9%

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

Alternative 10: 69.5% accurate, 24.1× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
    4. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    9. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
    13. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
    14. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    16. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    17. *-lowering-*.f6472.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
  5. Simplified72.4%

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

Alternative 11: 67.5% accurate, 24.1× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{{x}^{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot \color{blue}{x}\right)\right)\right) \]
    4. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right) \cdot \color{blue}{x}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right)\right)\right) \]
    9. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right)\right)\right) \]
    10. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(c \cdot \left({s}^{2} \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot c\right)}\right)\right)\right)\right) \]
    13. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot c\right)\right)\right)\right)\right) \]
    14. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
    16. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    17. *-lowering-*.f6472.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
  5. Simplified72.4%

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

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right) \]
  7. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(\left(c \cdot c\right) \cdot \left(\color{blue}{{s}^{2}} \cdot {x}^{2}\right)\right)\right) \]
    2. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(c \cdot \color{blue}{\left(c \cdot \left({s}^{2} \cdot {x}^{2}\right)\right)}\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \left(c \cdot \left(\left({s}^{2} \cdot {x}^{2}\right) \cdot \color{blue}{c}\right)\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \color{blue}{\left(\left({s}^{2} \cdot {x}^{2}\right) \cdot c\right)}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \left(c \cdot \color{blue}{\left({s}^{2} \cdot {x}^{2}\right)}\right)\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2} \cdot {x}^{2}\right)}\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \left(\left(s \cdot s\right) \cdot {\color{blue}{x}}^{2}\right)\right)\right)\right) \]
    8. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{\left(s \cdot {x}^{2}\right)}\right)\right)\right)\right) \]
    9. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \left(s \cdot \left({x}^{2} \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{\left({x}^{2} \cdot s\right)}\right)\right)\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \left(s \cdot \color{blue}{{x}^{2}}\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(s, \color{blue}{\left({x}^{2}\right)}\right)\right)\right)\right)\right) \]
    13. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(s, \left(x \cdot \color{blue}{x}\right)\right)\right)\right)\right)\right) \]
    14. *-lowering-*.f6469.0%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(x, \color{blue}{x}\right)\right)\right)\right)\right)\right) \]
  8. Simplified69.0%

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

Alternative 12: 32.4% accurate, 34.8× speedup?

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot {s}^{2}\right)} \cdot x\right)\right)\right) \]
    2. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right) \cdot \color{blue}{x}\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
    4. pow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\right)\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right)\right) \]
    6. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right) \cdot \color{blue}{\left(c \cdot c\right)}\right)\right) \]
    7. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
    8. unswap-sqrN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right) \cdot \left(\color{blue}{c} \cdot c\right)\right)\right) \]
    9. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(c \cdot c\right)\right)}\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left(x \cdot s\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot s\right)}\right)\right)\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(x \cdot s\right), \color{blue}{\left(\left(c \cdot c\right) \cdot \left(x \cdot s\right)\right)}\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot s\right)\right)\right)\right) \]
    13. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \left(c \cdot \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
    14. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot \left(x \cdot s\right)\right)}\right)\right)\right) \]
    15. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left(x \cdot s\right)}\right)\right)\right)\right) \]
    16. *-lowering-*.f6492.2%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, \color{blue}{s}\right)\right)\right)\right)\right) \]
  4. Applied egg-rr92.2%

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

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + -2 \cdot {x}^{2}\right)}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
  6. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot {x}^{2}\right)\right), \mathsf{*.f64}\left(\color{blue}{\mathsf{*.f64}\left(x, s\right)}, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(-2 \cdot \left(x \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    3. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\left(-2 \cdot x\right) \cdot x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(-2 \cdot x\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, \color{blue}{s}\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(x \cdot -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
    7. *-lowering-*.f6462.5%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, -2\right)\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, s\right), \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right)\right)\right)\right) \]
  7. Simplified62.5%

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

    \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
  9. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \left({c}^{2} \cdot \left(s \cdot \color{blue}{s}\right)\right)\right) \]
    3. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \left(\left({c}^{2} \cdot s\right) \cdot \color{blue}{s}\right)\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(-2, \left(s \cdot \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \color{blue}{\left({c}^{2} \cdot s\right)}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(\left(c \cdot c\right) \cdot s\right)\right)\right) \]
    7. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \left(c \cdot \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot s\right)}\right)\right)\right) \]
    9. *-lowering-*.f6427.8%

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(s, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right) \]
  10. Simplified27.8%

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

    \[\leadsto \mathsf{/.f64}\left(-2, \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}\right) \]
  12. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \left(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right) \]
    2. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \left(c \cdot \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{\left({s}^{2}\right)}\right)\right)\right) \]
    5. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \left(s \cdot \color{blue}{s}\right)\right)\right)\right) \]
    6. *-lowering-*.f6429.6%

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(s, \color{blue}{s}\right)\right)\right)\right) \]
  13. Simplified29.6%

    \[\leadsto \frac{-2}{\color{blue}{c \cdot \left(c \cdot \left(s \cdot s\right)\right)}} \]
  14. Add Preprocessing

Reproduce

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