mixedcos

Percentage Accurate: 67.5% → 99.5%
Time: 12.7s
Alternatives: 15
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 15 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: 67.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 2.7× speedup?

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

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


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

    1. Initial program 68.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.1499999999999998e-65 < x

    1. Initial program 71.2%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative71.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\sqrt[3]{\cos \left(2 \cdot x\right)} \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}\right) \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}}{\color{blue}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
      9. add-cube-cbrt96.0%

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

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

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

        \[\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)}} \]
    7. Applied egg-rr96.1%

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.15 \cdot 10^{-65}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(x \cdot c\right)}}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 2: 87.6% accurate, 1.4× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 s 2) < 2.0000000000000001e207

    1. Initial program 74.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e207 < (pow.f64 s 2)

    1. Initial program 60.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 85.8% accurate, 2.6× speedup?

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

\mathbf{elif}\;x \leq 3.95 \cdot 10^{+182}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(x \cdot s\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot t_0\\


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

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.112000000000000002 < x < 3.9500000000000001e182

    1. Initial program 76.6%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative76.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.9500000000000001e182 < x

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.112:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{elif}\;x \leq 3.95 \cdot 10^{+182}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(x \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(x \cdot c\right)} \cdot \frac{1}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 4: 86.1% accurate, 2.6× speedup?

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

\mathbf{elif}\;x \leq 1.26 \cdot 10^{+154}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot t_0\\


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

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.112000000000000002 < x < 1.26e154

    1. Initial program 78.2%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative78.2%

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

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

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

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

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

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

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

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

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

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

    if 1.26e154 < x

    1. Initial program 63.6%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.112:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{+154}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(x \cdot c\right)} \cdot \frac{1}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 5: 91.0% accurate, 2.7× speedup?

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

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


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

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.294999999999999984 < x

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.295:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(\left(c \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot s\right)\right)}\\ \end{array} \]

Alternative 6: 95.7% accurate, 2.7× speedup?

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

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


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

    1. Initial program 70.0%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)} \]

    if 1.90000000000000012e203 < x

    1. Initial program 59.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 99.2% accurate, 2.7× speedup?

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

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


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

    1. Initial program 68.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.39999999999999998e-64 < x

    1. Initial program 71.2%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative71.2%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.4 \cdot 10^{-64}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}\\ \end{array} \]

Alternative 8: 80.7% accurate, 3.0× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ {\left(c \cdot \left(x \cdot s\right)\right)}^{-2} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s) :precision binary64 (pow (* c (* x s)) -2.0))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	return pow((c * (x * s)), -2.0);
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = (c * (x * s)) ** (-2.0d0)
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	return Math.pow((c * (x * s)), -2.0);
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	return math.pow((c * (x * s)), -2.0)
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(c * Float64(x * s)) ^ -2.0
end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
	tmp = (c * (x * s)) ^ -2.0;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}
\end{array}
Derivation
  1. Initial program 68.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
  10. Step-by-step derivation
    1. add-sqr-sqrt66.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 58.5% accurate, 20.8× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 5.6000000000000005e157

    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. Step-by-step derivation
      1. *-commutative68.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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)} \]
    6. Taylor expanded in x around 0 56.2%

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

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

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

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

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

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

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

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

    if 5.6000000000000005e157 < s

    1. Initial program 70.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\sqrt[3]{\cos \left(2 \cdot x\right)} \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}\right) \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}}{\color{blue}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
      9. add-cube-cbrt95.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
    8. Step-by-step derivation
      1. unpow270.5%

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

        \[\leadsto \frac{-2}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
    9. Simplified70.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 5.6 \cdot 10^{+157}:\\ \;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \left(x \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{\left(s \cdot s\right) \cdot \left(c \cdot c\right)}\\ \end{array} \]

Alternative 10: 76.1% accurate, 20.8× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 2.8 \cdot 10^{-202}:\\ \;\;\;\;\frac{\frac{1}{c \cdot c}}{x \cdot \left(s \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 2.8e-202)
   (/ (/ 1.0 (* c c)) (* x (* s (* x s))))
   (/ 1.0 (* (* x c) (* s (* c (* x s)))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 2.8e-202) {
		tmp = (1.0 / (c * c)) / (x * (s * (x * s)));
	} else {
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 2.8d-202) then
        tmp = (1.0d0 / (c * c)) / (x * (s * (x * s)))
    else
        tmp = 1.0d0 / ((x * c) * (s * (c * (x * s))))
    end if
    code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 2.8e-202) {
		tmp = (1.0 / (c * c)) / (x * (s * (x * s)));
	} else {
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	}
	return tmp;
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if x <= 2.8e-202:
		tmp = (1.0 / (c * c)) / (x * (s * (x * s)))
	else:
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))))
	return tmp
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (x <= 2.8e-202)
		tmp = Float64(Float64(1.0 / Float64(c * c)) / Float64(x * Float64(s * Float64(x * s))));
	else
		tmp = Float64(1.0 / Float64(Float64(x * c) * Float64(s * Float64(c * Float64(x * s)))));
	end
	return tmp
end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 2.8e-202)
		tmp = (1.0 / (c * c)) / (x * (s * (x * s)));
	else
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 2.8e-202], N[(N[(1.0 / N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(x * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(x * c), $MachinePrecision] * N[(s * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.8 \cdot 10^{-202}:\\
\;\;\;\;\frac{\frac{1}{c \cdot c}}{x \cdot \left(s \cdot \left(x \cdot s\right)\right)}\\

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


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

    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. Step-by-step derivation
      1. associate-/r*66.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.8000000000000001e-202 < x

    1. Initial program 72.8%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Step-by-step derivation
      1. *-commutative72.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.8 \cdot 10^{-202}:\\ \;\;\;\;\frac{\frac{1}{c \cdot c}}{x \cdot \left(s \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]

Alternative 11: 77.6% accurate, 20.8× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 6 \cdot 10^{-123}:\\ \;\;\;\;\frac{\frac{1}{c \cdot c}}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 6e-123)
   (/ (/ 1.0 (* c c)) (* (* x s) (* x s)))
   (/ 1.0 (* (* x c) (* s (* c (* x s)))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 6e-123) {
		tmp = (1.0 / (c * c)) / ((x * s) * (x * s));
	} else {
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 6d-123) then
        tmp = (1.0d0 / (c * c)) / ((x * s) * (x * s))
    else
        tmp = 1.0d0 / ((x * c) * (s * (c * (x * s))))
    end if
    code = tmp
end function
x = Math.abs(x);
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 6e-123) {
		tmp = (1.0 / (c * c)) / ((x * s) * (x * s));
	} else {
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	}
	return tmp;
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if x <= 6e-123:
		tmp = (1.0 / (c * c)) / ((x * s) * (x * s))
	else:
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))))
	return tmp
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (x <= 6e-123)
		tmp = Float64(Float64(1.0 / Float64(c * c)) / Float64(Float64(x * s) * Float64(x * s)));
	else
		tmp = Float64(1.0 / Float64(Float64(x * c) * Float64(s * Float64(c * Float64(x * s)))));
	end
	return tmp
end
x = abs(x)
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 6e-123)
		tmp = (1.0 / (c * c)) / ((x * s) * (x * s));
	else
		tmp = 1.0 / ((x * c) * (s * (c * (x * s))));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 6e-123], N[(N[(1.0 / N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(N[(x * s), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(x * c), $MachinePrecision] * N[(s * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6 \cdot 10^{-123}:\\
\;\;\;\;\frac{\frac{1}{c \cdot c}}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}\\

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\sqrt{{x}^{4} \cdot {s}^{\color{blue}{4}}}} \]
    8. Applied egg-rr45.4%

      \[\leadsto \frac{\frac{1}{c \cdot c}}{\color{blue}{\sqrt{{x}^{4} \cdot {s}^{4}}}} \]
    9. Step-by-step derivation
      1. *-commutative45.4%

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\sqrt{\color{blue}{{s}^{4} \cdot {x}^{4}}}} \]
      2. metadata-eval45.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.99999999999999968e-123 < x

    1. Initial program 73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6 \cdot 10^{-123}:\\ \;\;\;\;\frac{\frac{1}{c \cdot c}}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot c\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]

Alternative 12: 79.1% accurate, 20.8× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t_0}}{t_0}\\


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

    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. Step-by-step derivation
      1. associate-/r*66.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\sqrt{{x}^{4} \cdot {s}^{\color{blue}{4}}}} \]
    8. Applied egg-rr45.8%

      \[\leadsto \frac{\frac{1}{c \cdot c}}{\color{blue}{\sqrt{{x}^{4} \cdot {s}^{4}}}} \]
    9. Step-by-step derivation
      1. *-commutative45.8%

        \[\leadsto \frac{\frac{1}{c \cdot c}}{\sqrt{\color{blue}{{s}^{4} \cdot {x}^{4}}}} \]
      2. metadata-eval45.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.60000000000000005e-171 < x

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\sqrt[3]{\cos \left(2 \cdot x\right)} \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}\right) \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}}{\color{blue}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
      9. add-cube-cbrt96.1%

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

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

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

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

      \[\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. Taylor expanded in x around 0 74.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.6 \cdot 10^{-171}:\\ \;\;\;\;\frac{\frac{1}{c \cdot c}}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{s \cdot \left(x \cdot c\right)}}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternative 13: 80.6% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\frac{1}{c \cdot c}}{x \cdot \color{blue}{\left(s \cdot \left(s \cdot x\right)\right)}} \]
  10. Step-by-step derivation
    1. add-sqr-sqrt66.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 75.6% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 28.7% accurate, 34.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\sqrt[3]{\cos \left(2 \cdot x\right)} \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}\right) \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}}{\color{blue}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
    9. add-cube-cbrt95.9%

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

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

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

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

    \[\leadsto \color{blue}{\frac{-2}{{c}^{2} \cdot {s}^{2}}} \]
  8. Step-by-step derivation
    1. unpow231.3%

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

      \[\leadsto \frac{-2}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
  9. Simplified31.3%

    \[\leadsto \color{blue}{\frac{-2}{\left(c \cdot c\right) \cdot \left(s \cdot s\right)}} \]
  10. Final simplification31.3%

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

Reproduce

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