mixedcos

Percentage Accurate: 66.7% → 95.1%
Time: 13.6s
Alternatives: 10
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 66.7% 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: 95.1% accurate, 2.5× speedup?

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

\mathbf{elif}\;x\_m \leq 1.1 \cdot 10^{+231}:\\
\;\;\;\;\frac{t\_0}{s \cdot \left(\left(x\_m \cdot \left(x\_m \cdot c\_m\right)\right) \cdot \left(s \cdot c\_m\right)\right)}\\

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


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

    1. Initial program 68.7%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. 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. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.7000000000000001e-38 < x < 1.09999999999999996e231

    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. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({c}^{2} \cdot \left(x \cdot \color{blue}{\left(x \cdot {s}^{2}\right)}\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({c}^{2} \cdot x\right) \cdot \color{blue}{\left(x \cdot {s}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left({c}^{2} \cdot x\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\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 x\right) \cdot \left(\left(x \cdot s\right) \cdot \color{blue}{s}\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}^{2} \cdot x\right) \cdot \left(x \cdot s\right)\right) \cdot \color{blue}{s}\right)\right) \]
      6. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left({c}^{2} \cdot x\right) \cdot \left(s \cdot x\right)\right), s\right)\right) \]
      8. *-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({c}^{2} \cdot x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      9. *-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(\left({c}^{2}\right), x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      10. unpow2N/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(\left(c \cdot c\right), x\right), \left(s \cdot x\right)\right), s\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(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, c\right), x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      12. *-lowering-*.f6482.1%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left(x \cdot \left(x \cdot c\right)\right) \cdot \left(c \cdot s\right)\right), s\right)\right) \]
      8. *-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 \left(x \cdot c\right)\right), \left(c \cdot s\right)\right), s\right)\right) \]
      9. *-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, \left(x \cdot c\right)\right), \left(c \cdot s\right)\right), s\right)\right) \]
      10. *-commutativeN/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, \left(c \cdot x\right)\right), \left(c \cdot s\right)\right), s\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(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(c, x\right)\right), \left(c \cdot s\right)\right), s\right)\right) \]
      12. *-lowering-*.f6486.9%

        \[\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, \mathsf{*.f64}\left(c, x\right)\right), \mathsf{*.f64}\left(c, s\right)\right), s\right)\right) \]
    6. Applied egg-rr86.9%

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

    if 1.09999999999999996e231 < x

    1. Initial program 52.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. Step-by-step derivation
      1. *-commutativeN/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
      3. 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}{\left(x \cdot x\right)}\right)\right) \]
      4. pow-prod-downN/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) \]
      5. 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) \]
      6. 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) \]
      7. 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) \]
      8. *-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) \]
      9. *-lowering-*.f6488.5%

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

      \[\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. *-rgt-identityN/A

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right) \cdot 1}{{\left(c \cdot \left(s \cdot x\right)\right)}^{2}} \]
      3. unpow-prod-downN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right) \cdot 1}{\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot \left(s \cdot x\right)\right) \cdot s} \]
      13. *-rgt-identityN/A

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

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

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

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

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

Alternative 2: 92.3% accurate, 2.6× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000008e-5 < x

    1. Initial program 64.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. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({c}^{2} \cdot \left(x \cdot \color{blue}{\left(x \cdot {s}^{2}\right)}\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({c}^{2} \cdot x\right) \cdot \color{blue}{\left(x \cdot {s}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(\left({c}^{2} \cdot x\right) \cdot \left(x \cdot \left(s \cdot \color{blue}{s}\right)\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 x\right) \cdot \left(\left(x \cdot s\right) \cdot \color{blue}{s}\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}^{2} \cdot x\right) \cdot \left(x \cdot s\right)\right) \cdot \color{blue}{s}\right)\right) \]
      6. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left({c}^{2} \cdot x\right) \cdot \left(s \cdot x\right)\right), s\right)\right) \]
      8. *-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({c}^{2} \cdot x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      9. *-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(\left({c}^{2}\right), x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      10. unpow2N/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(\left(c \cdot c\right), x\right), \left(s \cdot x\right)\right), s\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(\mathsf{*.f64}\left(\mathsf{*.f64}\left(c, c\right), x\right), \left(s \cdot x\right)\right), s\right)\right) \]
      12. *-lowering-*.f6480.1%

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\left(\left(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right) \cdot s\right), s\right)\right) \]
      3. *-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(\left(\left(c \cdot c\right) \cdot x\right) \cdot x\right), s\right), s\right)\right) \]
      4. 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(\left(\left(c \cdot \left(c \cdot x\right)\right) \cdot x\right), s\right), s\right)\right) \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\left(c \cdot \left(x \cdot c\right)\right) \cdot x\right), s\right), s\right)\right) \]
      6. 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(\left(c \cdot \left(\left(x \cdot c\right) \cdot x\right)\right), s\right), s\right)\right) \]
      7. associate-*r*N/A

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(c \cdot \left(x \cdot \left(x \cdot c\right)\right)\right), s\right), s\right)\right) \]
      9. *-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(c, \left(x \cdot \left(x \cdot c\right)\right)\right), s\right), s\right)\right) \]
      10. *-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(c, \mathsf{*.f64}\left(x, \left(x \cdot c\right)\right)\right), s\right), s\right)\right) \]
      11. *-commutativeN/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(c, \mathsf{*.f64}\left(x, \left(c \cdot x\right)\right)\right), s\right), s\right)\right) \]
      12. *-lowering-*.f6482.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 10^{-5}:\\ \;\;\;\;\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)}{s \cdot \left(s \cdot \left(c \cdot \left(x \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.4% accurate, 2.6× speedup?

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

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


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

    1. Initial program 68.7%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. 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. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.54999999999999991e-38 < x

    1. Initial program 62.0%

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      3. unpow2N/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(\color{blue}{x} \cdot {s}^{2}\right)\right)\right)\right) \]
      4. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(c \cdot \color{blue}{\left(c \cdot \left(x \cdot {s}^{2}\right)\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(x \cdot c\right) \cdot \color{blue}{\left(c \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
      6. *-lowering-*.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, c\right), \left(c \cdot \left(\left(s \cdot s\right) \cdot x\right)\right)\right)\right) \]
      10. 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, c\right), \left(c \cdot \left(s \cdot \color{blue}{\left(s \cdot x\right)}\right)\right)\right)\right) \]
      11. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, c\right), \left(\left(c \cdot s\right) \cdot \color{blue}{\left(s \cdot x\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, c\right), \mathsf{*.f64}\left(\left(c \cdot s\right), \color{blue}{\left(s \cdot x\right)}\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(x, c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), \left(\color{blue}{s} \cdot x\right)\right)\right)\right) \]
      14. *-lowering-*.f6494.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.55 \cdot 10^{-38}:\\ \;\;\;\;\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)}{\left(x \cdot c\right) \cdot \left(\left(x \cdot s\right) \cdot \left(s \cdot c\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 89.9% accurate, 2.6× speedup?

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


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

    1. Initial program 68.3%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. 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. associate-*r*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.19999999999999994e-35 < x

    1. Initial program 62.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. 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. *-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({s}^{2} \cdot \color{blue}{{c}^{2}}\right)\right)\right)\right) \]
      12. 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(s \cdot s\right) \cdot {\color{blue}{c}}^{2}\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(x, \mathsf{*.f64}\left(x, \left(s \cdot \color{blue}{\left(s \cdot {c}^{2}\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(s, \color{blue}{\left(s \cdot {c}^{2}\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(s, \left(s \cdot \left(c \cdot \color{blue}{c}\right)\right)\right)\right)\right)\right) \]
      16. associate-*r*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(s, \left(\left(s \cdot c\right) \cdot \color{blue}{c}\right)\right)\right)\right)\right) \]
      17. *-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(s, \left(c \cdot \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      18. *-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(s, \mathsf{*.f64}\left(c, \color{blue}{\left(s \cdot c\right)}\right)\right)\right)\right)\right) \]
      19. *-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(s, \mathsf{*.f64}\left(c, \left(c \cdot \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
      20. *-lowering-*.f6488.5%

        \[\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(s, \mathsf{*.f64}\left(c, \mathsf{*.f64}\left(c, \color{blue}{s}\right)\right)\right)\right)\right)\right) \]
    5. Simplified88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.2 \cdot 10^{-35}:\\ \;\;\;\;\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(s \cdot \left(c \cdot \left(s \cdot c\right)\right)\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 97.2% accurate, 2.7× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
    3. 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}{\left(x \cdot x\right)}\right)\right) \]
    4. pow-prod-downN/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) \]
    5. 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) \]
    6. 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) \]
    7. 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) \]
    8. *-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) \]
    9. *-lowering-*.f6497.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-rr97.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. *-rgt-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 78.8% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.7% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({\left(\left(c \cdot s\right) \cdot x\right)}^{2}\right)}\right) \]
    9. unpow2N/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) \]
    10. associate-*l*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, \mathsf{*.f64}\left(x, s\right)\right), \left(c \cdot \left(s \cdot x\right)\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), \mathsf{*.f64}\left(c, \color{blue}{\left(s \cdot x\right)}\right)\right)\right) \]
    10. *-commutativeN/A

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

      \[\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) \]
  9. Applied egg-rr81.6%

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

Alternative 8: 74.8% accurate, 24.1× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left({c}^{2} \cdot \left({s}^{2} \cdot \color{blue}{\left(x \cdot x\right)}\right)\right)\right) \]
    3. 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}{\left(x \cdot x\right)}\right)\right) \]
    4. pow-prod-downN/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) \]
    5. 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) \]
    6. 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) \]
    7. 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) \]
    8. *-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) \]
    9. *-lowering-*.f6497.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-rr97.7%

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

    \[\leadsto \color{blue}{\frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}} \]
  6. 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. 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) \]
    3. 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) \]
    4. *-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) \]
    5. *-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) \]
    6. unpow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 71.6% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left({\left(\left(c \cdot s\right) \cdot x\right)}^{2}\right)}\right) \]
    9. unpow2N/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) \]
    10. associate-*l*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 30.2% accurate, 34.8× speedup?

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
    3. unpow2N/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(\color{blue}{x} \cdot {s}^{2}\right)\right)\right)\right) \]
    4. associate-*l*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \left(x \cdot \left(c \cdot \color{blue}{\left(c \cdot \left(x \cdot {s}^{2}\right)\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(x \cdot c\right) \cdot \color{blue}{\left(c \cdot \left(x \cdot {s}^{2}\right)\right)}\right)\right) \]
    6. *-lowering-*.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, c\right), \left(c \cdot \left(\left(s \cdot s\right) \cdot x\right)\right)\right)\right) \]
    10. 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, c\right), \left(c \cdot \left(s \cdot \color{blue}{\left(s \cdot x\right)}\right)\right)\right)\right) \]
    11. associate-*r*N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(2, x\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(x, c\right), \left(\left(c \cdot s\right) \cdot \color{blue}{\left(s \cdot x\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, c\right), \mathsf{*.f64}\left(\left(c \cdot s\right), \color{blue}{\left(s \cdot x\right)}\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(x, c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), \left(\color{blue}{s} \cdot x\right)\right)\right)\right) \]
    14. *-lowering-*.f6493.3%

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

    \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot c\right) \cdot \left(\left(c \cdot s\right) \cdot \left(s \cdot x\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, c\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), \mathsf{*.f64}\left(s, x\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, c\right)}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(c, s\right), \mathsf{*.f64}\left(s, x\right)\right)\right)\right) \]
    2. *-commutativeN/A

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

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

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

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

    \[\leadsto \frac{\color{blue}{1 + \left(x \cdot x\right) \cdot -2}}{\left(x \cdot c\right) \cdot \left(\left(c \cdot s\right) \cdot \left(s \cdot x\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(\left(c \cdot c\right) \cdot {\color{blue}{s}}^{2}\right)\right) \]
    3. associate-*l*N/A

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

      \[\leadsto \mathsf{/.f64}\left(-2, \mathsf{*.f64}\left(c, \color{blue}{\left(c \cdot {s}^{2}\right)}\right)\right) \]
    5. *-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) \]
    6. 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) \]
    7. *-lowering-*.f6427.4%

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

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

Reproduce

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