mixedcos

Percentage Accurate: 67.4% → 97.1%
Time: 13.0s
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.4% 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: 97.1% accurate, 2.7× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity71.8%

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

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

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

    \[\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)}} \]
  5. Step-by-step derivation
    1. associate-*l/98.0%

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

      \[\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)} \]
    3. div-inv98.0%

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

      \[\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)} \]
    5. *-commutative98.0%

      \[\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)} \]
  6. Applied egg-rr98.0%

    \[\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)}} \]
  7. Final simplification98.0%

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

Alternative 2: 77.1% accurate, 1.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;{t_0}^{-2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 s 2) < 4.9999999999999999e-48

    1. Initial program 73.7%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity73.7%

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

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

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

      \[\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)}} \]
    5. Step-by-step derivation
      1. associate-*l/98.2%

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}} \]
      2. *-un-lft-identity98.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)} \]
      3. div-inv98.2%

        \[\leadsto \frac{\color{blue}{\cos \left(2 \cdot x\right) \cdot \frac{1}{c \cdot \left(x \cdot s\right)}}}{c \cdot \left(x \cdot s\right)} \]
      4. div-inv98.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)} \]
      5. *-commutative98.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)} \]
    6. Applied egg-rr98.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)}} \]
    7. Taylor expanded in x around 0 48.3%

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

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

    if 4.9999999999999999e-48 < (pow.f64 s 2)

    1. Initial program 69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 94.1% accurate, 2.7× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity71.8%

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

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

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

    \[\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)}} \]
  5. Step-by-step derivation
    1. *-commutative97.9%

      \[\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-/r*98.0%

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

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

      \[\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)} \]
    5. *-commutative95.3%

      \[\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)} \]
  6. Applied egg-rr95.3%

    \[\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)}} \]
  7. Final simplification95.3%

    \[\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)} \]
  8. Add Preprocessing

Alternative 4: 77.1% accurate, 13.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0} \cdot \frac{\frac{1}{c_m}}{x \cdot s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.8e-24

    1. Initial program 70.6%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity70.6%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}} \cdot \frac{\cos \left(2 \cdot x\right)}{\sqrt{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}}} \]
    4. Applied egg-rr97.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)}} \]
    5. Step-by-step derivation
      1. associate-*l/97.5%

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

        \[\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)} \]
      3. div-inv97.6%

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

        \[\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)} \]
      5. *-commutative97.5%

        \[\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)} \]
    6. Applied egg-rr97.5%

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

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

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

    if 1.8e-24 < s

    1. Initial program 75.9%

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity75.9%

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

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

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

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

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

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

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

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

Alternative 5: 79.4% accurate, 20.9× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity71.8%

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

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

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

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

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

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

Alternative 6: 79.4% accurate, 20.9× speedup?

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

    \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. *-un-lft-identity71.8%

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

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

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

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

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

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

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

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

Alternative 7: 76.2% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*72.8%

      \[\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. *-commutative72.8%

      \[\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*71.5%

      \[\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. Applied egg-rr71.5%

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

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

Alternative 8: 79.3% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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