mixedcos

Percentage Accurate: 66.2% → 98.0%
Time: 17.9s
Alternatives: 7
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 7 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 98.0% accurate, 1.4× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot s_m\right) \cdot c_m\right) \cdot \left(s_m \cdot \left(x \cdot c_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 c 2) < 1.00000000000000004e-42

    1. Initial program 65.4%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt54.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000004e-42 < (pow.f64 c 2)

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)} \cdot \left(c \cdot \left|s \cdot x\right|\right)} \]
      11. add-sqr-sqrt35.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 89.2% accurate, 2.6× speedup?

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

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


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

    1. Initial program 65.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}\right)\right)} \]
      7. expm1-udef75.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}\right)} - 1} \]
      8. pow-flip75.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{\left(c \cdot \left|s \cdot x\right|\right)}^{\left(-2\right)}}\right)} - 1 \]
      9. add-sqr-sqrt49.4%

        \[\leadsto e^{\mathsf{log1p}\left({\left(c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|\right)}^{\left(-2\right)}\right)} - 1 \]
      10. fabs-sqr49.4%

        \[\leadsto e^{\mathsf{log1p}\left({\left(c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}\right)}^{\left(-2\right)}\right)} - 1 \]
      11. add-sqr-sqrt75.6%

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

        \[\leadsto e^{\mathsf{log1p}\left({\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{\left(-2\right)}\right)} - 1 \]
      13. metadata-eval78.2%

        \[\leadsto e^{\mathsf{log1p}\left({\left(\left(c \cdot s\right) \cdot x\right)}^{\color{blue}{-2}}\right)} - 1 \]
    7. Applied egg-rr78.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left({\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def82.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\right)\right)} \]
      2. expm1-log1p83.9%

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

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

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

    if 9.4999999999999996e-115 < x

    1. Initial program 66.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 97.1% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 79.6% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}\right)\right)} \]
    7. expm1-udef73.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}\right)} - 1} \]
    8. pow-flip73.5%

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

      \[\leadsto e^{\mathsf{log1p}\left({\left(c \cdot \left|\color{blue}{\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}}\right|\right)}^{\left(-2\right)}\right)} - 1 \]
    10. fabs-sqr44.8%

      \[\leadsto e^{\mathsf{log1p}\left({\left(c \cdot \color{blue}{\left(\sqrt{s \cdot x} \cdot \sqrt{s \cdot x}\right)}\right)}^{\left(-2\right)}\right)} - 1 \]
    11. add-sqr-sqrt73.5%

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

      \[\leadsto e^{\mathsf{log1p}\left({\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}^{\left(-2\right)}\right)} - 1 \]
    13. metadata-eval75.3%

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left({\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\right)} - 1} \]
  8. Step-by-step derivation
    1. expm1-def81.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\right)\right)} \]
    2. expm1-log1p81.9%

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

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

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

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

Alternative 5: 79.4% accurate, 17.4× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot s_m\right) \cdot c_m\right) \cdot \left(s_m \cdot \left(x \cdot c_m\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 2.00000000000000005e-46

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)} \cdot \left(c \cdot \left|s \cdot x\right|\right)} \]
      11. add-sqr-sqrt46.5%

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

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

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

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

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

    if 2.00000000000000005e-46 < c

    1. Initial program 63.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 78.9% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)} \cdot \left(c \cdot \left|s \cdot x\right|\right)} \]
    11. add-sqr-sqrt41.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)} \cdot \left(c \cdot \left|s \cdot x\right|\right)} \]
    11. add-sqr-sqrt41.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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