mixedcos

Percentage Accurate: 66.7% → 99.6%
Time: 16.9s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 66.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 2.6× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 10^{-34}:\\ \;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\frac{1}{s}}{x}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{x \cdot c}{\frac{1}{s}}} \cdot \frac{\frac{\cos \left(x \cdot 2\right)}{s}}{x \cdot c}\\ \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 1e-34)
   (* (/ 1.0 (* c (* x s))) (/ (/ (/ 1.0 s) x) c))
   (* (/ 1.0 (/ (* x c) (/ 1.0 s))) (/ (/ (cos (* x 2.0)) 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 <= 1e-34) {
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	} else {
		tmp = (1.0 / ((x * c) / (1.0 / s))) * ((cos((x * 2.0)) / 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 <= 1d-34) then
        tmp = (1.0d0 / (c * (x * s))) * (((1.0d0 / s) / x) / c)
    else
        tmp = (1.0d0 / ((x * c) / (1.0d0 / s))) * ((cos((x * 2.0d0)) / 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 <= 1e-34) {
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	} else {
		tmp = (1.0 / ((x * c) / (1.0 / s))) * ((Math.cos((x * 2.0)) / 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 <= 1e-34:
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c)
	else:
		tmp = (1.0 / ((x * c) / (1.0 / s))) * ((math.cos((x * 2.0)) / 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 <= 1e-34)
		tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(Float64(1.0 / s) / x) / c));
	else
		tmp = Float64(Float64(1.0 / Float64(Float64(x * c) / Float64(1.0 / s))) * Float64(Float64(cos(Float64(x * 2.0)) / 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 <= 1e-34)
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	else
		tmp = (1.0 / ((x * c) / (1.0 / s))) * ((cos((x * 2.0)) / 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, 1e-34], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 / s), $MachinePrecision] / x), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(x * c), $MachinePrecision] / N[(1.0 / s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / s), $MachinePrecision] / 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 10^{-34}:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\frac{1}{s}}{x}}{c}\\

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


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

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999928e-35 < x

    1. Initial program 67.8%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Applied egg-rr98.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 97.6% accurate, 1.5× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \cos \left(x \cdot 2\right) \cdot {\left(x \cdot \left(c \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
 (* (cos (* x 2.0)) (pow (* x (* c s)) -2.0)))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	return cos((x * 2.0)) * pow((x * (c * 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 = cos((x * 2.0d0)) * ((x * (c * 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.cos((x * 2.0)) * Math.pow((x * (c * s)), -2.0);
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	return math.cos((x * 2.0)) * math.pow((x * (c * s)), -2.0)
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(cos(Float64(x * 2.0)) * (Float64(x * Float64(c * 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 = cos((x * 2.0)) * ((x * (c * 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[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\cos \left(x \cdot 2\right) \cdot {\left(x \cdot \left(c \cdot s\right)\right)}^{-2}
\end{array}
Derivation
  1. Initial program 64.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*64.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(x \cdot 2\right) \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{-2}} \]
  11. Final simplification98.2%

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

Alternative 3: 98.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 \cdot 10^{-33}:\\ \;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\frac{1}{s}}{x}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{s}}{\left(x \cdot c\right) \cdot \left(s \cdot \left(x \cdot c\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 2e-33)
   (* (/ 1.0 (* c (* x s))) (/ (/ (/ 1.0 s) x) c))
   (/ (/ (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 <= 2e-33) {
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	} 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 <= 2d-33) then
        tmp = (1.0d0 / (c * (x * s))) * (((1.0d0 / s) / x) / c)
    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 <= 2e-33) {
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	} 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 <= 2e-33:
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c)
	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 <= 2e-33)
		tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(Float64(1.0 / s) / x) / c));
	else
		tmp = Float64(Float64(cos(Float64(x * 2.0)) / s) / Float64(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 <= 2e-33)
		tmp = (1.0 / (c * (x * s))) * (((1.0 / s) / x) / c);
	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, 2e-33], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 / s), $MachinePrecision] / x), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / s), $MachinePrecision] / N[(N[(x * c), $MachinePrecision] * N[(s * N[(x * c), $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 \cdot 10^{-33}:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\frac{1}{s}}{x}}{c}\\

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


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

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-33 < x

    1. Initial program 67.8%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Applied egg-rr98.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 93.7% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

Alternative 5: 97.1% accurate, 2.7× 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{\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 (* c (* x s)))) (/ (/ (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 = c * (x * s);
	return (cos((x * 2.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 = (cos((x * 2.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 (Math.cos((x * 2.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 (math.cos((x * 2.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(Float64(cos(Float64(x * 2.0)) / 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 = (cos((x * 2.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[(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 := c \cdot \left(x \cdot s\right)\\
\frac{\frac{\cos \left(x \cdot 2\right)}{t_0}}{t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 64.7%

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

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

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

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

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

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

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

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

Alternative 6: 79.8% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 76.4% accurate, 24.1× speedup?

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

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

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

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

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow252.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 76.5% accurate, 24.1× speedup?

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

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

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

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

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow252.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 78.0% accurate, 24.1× speedup?

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

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

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

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

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow252.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 79.0% accurate, 24.1× speedup?

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

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

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

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

      \[\leadsto \frac{\frac{1}{{c}^{2}}}{\color{blue}{{x}^{2} \cdot {s}^{2}}} \]
    3. unpow252.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 79.7% 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{\frac{1}{t_0}}{t_0} \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* 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(Float64(1.0 / 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[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{\frac{1}{t_0}}{t_0}
\end{array}
\end{array}
Derivation
  1. Initial program 64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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