mixedcos

Percentage Accurate: 67.1% → 99.6%
Time: 17.5s
Alternatives: 8
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 8 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.1% 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.6% 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 1.75 \cdot 10^{-29}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{\cos \left(x \cdot 2\right)}{s}}{x \cdot c}}{s \cdot \left(x \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 (<= x 1.75e-29)
   (pow (* c (* x s)) -2.0)
   (/ (/ (/ (cos (* x 2.0)) s) (* x c)) (* s (* x c)))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 1.75e-29) {
		tmp = pow((c * (x * s)), -2.0);
	} else {
		tmp = ((cos((x * 2.0)) / s) / (x * c)) / (s * (x * 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 (x <= 1.75d-29) then
        tmp = (c * (x * s)) ** (-2.0d0)
    else
        tmp = ((cos((x * 2.0d0)) / s) / (x * c)) / (s * (x * 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 (x <= 1.75e-29) {
		tmp = Math.pow((c * (x * s)), -2.0);
	} else {
		tmp = ((Math.cos((x * 2.0)) / s) / (x * c)) / (s * (x * 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 x <= 1.75e-29:
		tmp = math.pow((c * (x * s)), -2.0)
	else:
		tmp = ((math.cos((x * 2.0)) / s) / (x * c)) / (s * (x * 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 (x <= 1.75e-29)
		tmp = Float64(c * Float64(x * s)) ^ -2.0;
	else
		tmp = Float64(Float64(Float64(cos(Float64(x * 2.0)) / s) / Float64(x * c)) / Float64(s * Float64(x * 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 (x <= 1.75e-29)
		tmp = (c * (x * s)) ^ -2.0;
	else
		tmp = ((cos((x * 2.0)) / s) / (x * c)) / (s * (x * 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[x, 1.75e-29], N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / s), $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $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 1.75 \cdot 10^{-29}:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\

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


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

    1. Initial program 63.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. associate-/r*62.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in65.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out65.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot \left(s \cdot x\right)\right)}} \]
      5. swap-sqr95.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)}} \]
      6. unpow295.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{-1}} \]
      15. pow-sqr81.1%

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

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

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

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

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

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

    if 1.7499999999999999e-29 < x

    1. Initial program 57.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*58.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in58.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out58.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 89.1% 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 6500:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\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 6500.0)
   (pow (* c (* x s)) -2.0)
   (/ (cos (* x 2.0)) (* x (* x (* c (* 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 <= 6500.0) {
		tmp = pow((c * (x * s)), -2.0);
	} else {
		tmp = cos((x * 2.0)) / (x * (x * (c * (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 <= 6500.0d0) then
        tmp = (c * (x * s)) ** (-2.0d0)
    else
        tmp = cos((x * 2.0d0)) / (x * (x * (c * (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 <= 6500.0) {
		tmp = Math.pow((c * (x * s)), -2.0);
	} else {
		tmp = Math.cos((x * 2.0)) / (x * (x * (c * (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 <= 6500.0:
		tmp = math.pow((c * (x * s)), -2.0)
	else:
		tmp = math.cos((x * 2.0)) / (x * (x * (c * (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 <= 6500.0)
		tmp = Float64(c * Float64(x * s)) ^ -2.0;
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(x * Float64(c * Float64(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 <= 6500.0)
		tmp = (c * (x * s)) ^ -2.0;
	else
		tmp = cos((x * 2.0)) / (x * (x * (c * (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, 6500.0], N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $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 6500:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\

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


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

    1. Initial program 63.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*63.3%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in65.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out65.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\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. unpow295.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6500 < x

    1. Initial program 55.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*56.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)\right) \cdot {c}^{2}}} \]
      7. distribute-rgt-neg-out55.7%

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in57.3%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out57.3%

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

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

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

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

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

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

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

Alternative 3: 91.9% 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 2.9 \cdot 10^{-8}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot s\right)\right)\right)\right)}\\ \end{array} \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.9e-8)
   (pow (* c (* x s)) -2.0)
   (/ (cos (* x 2.0)) (* x (* x (* c (* s (* c 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.9e-8) {
		tmp = pow((c * (x * s)), -2.0);
	} else {
		tmp = cos((x * 2.0)) / (x * (x * (c * (s * (c * 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.9d-8) then
        tmp = (c * (x * s)) ** (-2.0d0)
    else
        tmp = cos((x * 2.0d0)) / (x * (x * (c * (s * (c * 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.9e-8) {
		tmp = Math.pow((c * (x * s)), -2.0);
	} else {
		tmp = Math.cos((x * 2.0)) / (x * (x * (c * (s * (c * 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.9e-8:
		tmp = math.pow((c * (x * s)), -2.0)
	else:
		tmp = math.cos((x * 2.0)) / (x * (x * (c * (s * (c * 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.9e-8)
		tmp = Float64(c * Float64(x * s)) ^ -2.0;
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(x * Float64(c * Float64(s * Float64(c * 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.9e-8)
		tmp = (c * (x * s)) ^ -2.0;
	else
		tmp = cos((x * 2.0)) / (x * (x * (c * (s * (c * 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.9e-8], N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(c * N[(s * N[(c * s), $MachinePrecision]), $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.9 \cdot 10^{-8}:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\

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


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

    1. Initial program 64.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*63.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)\right) \cdot {c}^{2}}} \]
      7. distribute-rgt-neg-out64.0%

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in66.0%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out66.0%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg66.0%

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

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

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

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

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

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

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

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

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

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

        \[\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. unpow295.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{-1}} \]
      15. pow-sqr81.4%

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

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

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

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

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

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

    if 2.9000000000000002e-8 < x

    1. Initial program 55.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*56.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(-x\right)\right) \cdot {c}^{2}}} \]
      7. distribute-rgt-neg-out55.6%

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out57.1%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(-\color{blue}{\left(-x \cdot {s}^{2}\right)}\right) \cdot \left(x \cdot {c}^{2}\right)} \]
      12. remove-double-neg57.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.4% 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.25 \cdot 10^{-23}:\\ \;\;\;\;{\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.25e-23)
     (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.25e-23) {
		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.25d-23) 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.25e-23) {
		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.25e-23:
		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.25e-23)
		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.25e-23)
		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.25e-23], 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.25 \cdot 10^{-23}:\\
\;\;\;\;{\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.24999999999999987e-23

    1. Initial program 63.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. associate-/r*62.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in65.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out65.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot \left(s \cdot x\right)\right)}} \]
      5. swap-sqr95.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)}} \]
      6. unpow295.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{-1}} \]
      15. pow-sqr81.1%

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

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

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

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

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

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

    if 2.24999999999999987e-23 < x

    1. Initial program 57.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*58.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in58.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out58.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot \left(s \cdot x\right)\right)}} \]
      5. swap-sqr96.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)}} \]
      6. unpow296.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.25 \cdot 10^{-23}:\\ \;\;\;\;{\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 5: 99.6% 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 5 \cdot 10^{-26}:\\ \;\;\;\;{\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 5e-26) (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 <= 5e-26) {
		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 <= 5d-26) 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 <= 5e-26) {
		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 <= 5e-26:
		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 <= 5e-26)
		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 <= 5e-26)
		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, 5e-26], 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 5 \cdot 10^{-26}:\\
\;\;\;\;{\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 < 5.00000000000000019e-26

    1. Initial program 63.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. associate-/r*62.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in65.5%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out65.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot \left(s \cdot x\right)\right)}} \]
      5. swap-sqr95.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)}} \]
      6. unpow295.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{-1}} \]
      15. pow-sqr81.1%

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

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

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

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

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

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

    if 5.00000000000000019e-26 < x

    1. Initial program 57.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*58.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      10. distribute-lft-neg-in58.9%

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
      11. distribute-lft-neg-out58.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5 \cdot 10^{-26}:\\ \;\;\;\;{\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 6: 80.2% 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 61.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. associate-/r*61.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    10. distribute-lft-neg-in63.6%

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    11. distribute-lft-neg-out63.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\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. unpow295.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(s \cdot \left(c \cdot x\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(c \cdot x\right)\right)}^{-1}} \]
    15. pow-sqr74.7%

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

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

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

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

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

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

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

Alternative 7: 80.2% 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 61.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. associate-/r*61.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    10. distribute-lft-neg-in63.6%

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    11. distribute-lft-neg-out63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 80.1% accurate, 24.1× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{1}{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 (* c (* 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 = c * (x * s);
	return 1.0 / (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 = c * (x * s)
    code = 1.0d0 / (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 = c * (x * s);
	return 1.0 / (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 = c * (x * s)
	return 1.0 / (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(c * Float64(x * s))
	return Float64(1.0 / 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 = c * (x * s);
	tmp = 1.0 / (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[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / 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 := c \cdot \left(x \cdot s\right)\\
\frac{1}{t_0 \cdot t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 61.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. associate-/r*61.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{-\color{blue}{\left(\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    10. distribute-lft-neg-in63.6%

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(-\left(-x\right) \cdot {s}^{2}\right) \cdot \left(x \cdot {c}^{2}\right)}} \]
    11. distribute-lft-neg-out63.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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