mixedcos

Percentage Accurate: 67.0% → 99.2%
Time: 14.4s
Alternatives: 7
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 67.0% 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.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(2 \cdot x\right)\\ t_1 := x \cdot \left(c \cdot s\right)\\ \mathbf{if}\;\frac{t\_0}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\ \;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \frac{t\_0}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t\_0}{t\_1}}{t\_1}\\ \end{array} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (cos (* 2.0 x))) (t_1 (* x (* c s))))
   (if (<= (/ t_0 (* (pow c 2.0) (* x (* x (pow s 2.0))))) INFINITY)
     (* (/ (/ 1.0 c) (* x s)) (/ t_0 (* c (* x s))))
     (/ (/ t_0 t_1) t_1))))
double code(double x, double c, double s) {
	double t_0 = cos((2.0 * x));
	double t_1 = x * (c * s);
	double tmp;
	if ((t_0 / (pow(c, 2.0) * (x * (x * pow(s, 2.0))))) <= ((double) INFINITY)) {
		tmp = ((1.0 / c) / (x * s)) * (t_0 / (c * (x * s)));
	} else {
		tmp = (t_0 / t_1) / t_1;
	}
	return tmp;
}
public static double code(double x, double c, double s) {
	double t_0 = Math.cos((2.0 * x));
	double t_1 = x * (c * s);
	double tmp;
	if ((t_0 / (Math.pow(c, 2.0) * (x * (x * Math.pow(s, 2.0))))) <= Double.POSITIVE_INFINITY) {
		tmp = ((1.0 / c) / (x * s)) * (t_0 / (c * (x * s)));
	} else {
		tmp = (t_0 / t_1) / t_1;
	}
	return tmp;
}
def code(x, c, s):
	t_0 = math.cos((2.0 * x))
	t_1 = x * (c * s)
	tmp = 0
	if (t_0 / (math.pow(c, 2.0) * (x * (x * math.pow(s, 2.0))))) <= math.inf:
		tmp = ((1.0 / c) / (x * s)) * (t_0 / (c * (x * s)))
	else:
		tmp = (t_0 / t_1) / t_1
	return tmp
function code(x, c, s)
	t_0 = cos(Float64(2.0 * x))
	t_1 = Float64(x * Float64(c * s))
	tmp = 0.0
	if (Float64(t_0 / Float64((c ^ 2.0) * Float64(x * Float64(x * (s ^ 2.0))))) <= Inf)
		tmp = Float64(Float64(Float64(1.0 / c) / Float64(x * s)) * Float64(t_0 / Float64(c * Float64(x * s))));
	else
		tmp = Float64(Float64(t_0 / t_1) / t_1);
	end
	return tmp
end
function tmp_2 = code(x, c, s)
	t_0 = cos((2.0 * x));
	t_1 = x * (c * s);
	tmp = 0.0;
	if ((t_0 / ((c ^ 2.0) * (x * (x * (s ^ 2.0))))) <= Inf)
		tmp = ((1.0 / c) / (x * s)) * (t_0 / (c * (x * s)));
	else
		tmp = (t_0 / t_1) / t_1;
	end
	tmp_2 = tmp;
end
code[x_, c_, s_] := Block[{t$95$0 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[Power[c, 2.0], $MachinePrecision] * N[(x * N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(2 \cdot x\right)\\
t_1 := x \cdot \left(c \cdot s\right)\\
\mathbf{if}\;\frac{t\_0}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \frac{t\_0}{c \cdot \left(x \cdot s\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{t\_1}}{t\_1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < +inf.0

    1. Initial program 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x)))

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\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)}}} \]
      11. associate-/r*0.0%

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

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

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

Alternative 2: 86.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;x \leq 1.9 \cdot 10^{-15}:\\ \;\;\;\;\frac{1}{{t\_0}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot t\_0}}{x \cdot s}\\ \end{array} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* c (* x s))))
   (if (<= x 1.9e-15)
     (/ 1.0 (pow t_0 2.0))
     (/ (/ (cos (* 2.0 x)) (* c t_0)) (* x s)))))
double code(double x, double c, double s) {
	double t_0 = c * (x * s);
	double tmp;
	if (x <= 1.9e-15) {
		tmp = 1.0 / pow(t_0, 2.0);
	} else {
		tmp = (cos((2.0 * x)) / (c * t_0)) / (x * s);
	}
	return tmp;
}
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: t_0
    real(8) :: tmp
    t_0 = c * (x * s)
    if (x <= 1.9d-15) then
        tmp = 1.0d0 / (t_0 ** 2.0d0)
    else
        tmp = (cos((2.0d0 * x)) / (c * t_0)) / (x * s)
    end if
    code = tmp
end function
public static double code(double x, double c, double s) {
	double t_0 = c * (x * s);
	double tmp;
	if (x <= 1.9e-15) {
		tmp = 1.0 / Math.pow(t_0, 2.0);
	} else {
		tmp = (Math.cos((2.0 * x)) / (c * t_0)) / (x * s);
	}
	return tmp;
}
def code(x, c, s):
	t_0 = c * (x * s)
	tmp = 0
	if x <= 1.9e-15:
		tmp = 1.0 / math.pow(t_0, 2.0)
	else:
		tmp = (math.cos((2.0 * x)) / (c * t_0)) / (x * s)
	return tmp
function code(x, c, s)
	t_0 = Float64(c * Float64(x * s))
	tmp = 0.0
	if (x <= 1.9e-15)
		tmp = Float64(1.0 / (t_0 ^ 2.0));
	else
		tmp = Float64(Float64(cos(Float64(2.0 * x)) / Float64(c * t_0)) / Float64(x * s));
	end
	return tmp
end
function tmp_2 = code(x, c, s)
	t_0 = c * (x * s);
	tmp = 0.0;
	if (x <= 1.9e-15)
		tmp = 1.0 / (t_0 ^ 2.0);
	else
		tmp = (cos((2.0 * x)) / (c * t_0)) / (x * s);
	end
	tmp_2 = tmp;
end
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.9e-15], N[(1.0 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(c * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;x \leq 1.9 \cdot 10^{-15}:\\
\;\;\;\;\frac{1}{{t\_0}^{2}}\\

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


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

    1. Initial program 63.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 53.6%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot {\left(x \cdot s\right)}^{2}} \]
      9. unpow268.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-sqr85.9%

        \[\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. unpow285.9%

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

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

    if 1.9000000000000001e-15 < x

    1. Initial program 68.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 97.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ \frac{\frac{\cos \left(2 \cdot x\right)}{t\_0}}{t\_0} \end{array} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* x (* c s)))) (/ (/ (cos (* 2.0 x)) t_0) t_0)))
double code(double x, double c, double s) {
	double t_0 = x * (c * s);
	return (cos((2.0 * x)) / t_0) / t_0;
}
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 = x * (c * s)
    code = (cos((2.0d0 * x)) / t_0) / t_0
end function
public static double code(double x, double c, double s) {
	double t_0 = x * (c * s);
	return (Math.cos((2.0 * x)) / t_0) / t_0;
}
def code(x, c, s):
	t_0 = x * (c * s)
	return (math.cos((2.0 * x)) / t_0) / t_0
function code(x, c, s)
	t_0 = Float64(x * Float64(c * s))
	return Float64(Float64(cos(Float64(2.0 * x)) / t_0) / t_0)
end
function tmp = code(x, c, s)
	t_0 = x * (c * s);
	tmp = (cos((2.0 * x)) / t_0) / t_0;
end
code[x_, c_, s_] := Block[{t$95$0 = N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(c \cdot s\right)\\
\frac{\frac{\cos \left(2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\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)}}} \]
    11. associate-/r*64.3%

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

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

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

Alternative 4: 78.8% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}} \end{array} \]
(FPCore (x c s) :precision binary64 (/ 1.0 (pow (* c (* x s)) 2.0)))
double code(double x, double c, double s) {
	return 1.0 / pow((c * (x * s)), 2.0);
}
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)) ** 2.0d0)
end function
public static double code(double x, double c, double s) {
	return 1.0 / Math.pow((c * (x * s)), 2.0);
}
def code(x, c, s):
	return 1.0 / math.pow((c * (x * s)), 2.0)
function code(x, c, s)
	return Float64(1.0 / (Float64(c * Float64(x * s)) ^ 2.0))
end
function tmp = code(x, c, s)
	tmp = 1.0 / ((c * (x * s)) ^ 2.0);
end
code[x_, c_, s_] := N[(1.0 / N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}
\end{array}
Derivation
  1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 53.2%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 79.0% accurate, 3.0× speedup?

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

\\
{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}
\end{array}
Derivation
  1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.0% accurate, 24.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{\frac{1}{t\_0}}{t\_0} \end{array} \end{array} \]
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* c (* x s)))) (/ (/ 1.0 t_0) t_0)))
double code(double x, double c, double s) {
	double t_0 = c * (x * s);
	return (1.0 / t_0) / t_0;
}
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
public static double code(double x, double c, double s) {
	double t_0 = c * (x * s);
	return (1.0 / t_0) / t_0;
}
def code(x, c, s):
	t_0 = c * (x * s)
	return (1.0 / t_0) / t_0
function code(x, c, s)
	t_0 = Float64(c * Float64(x * s))
	return Float64(Float64(1.0 / t_0) / t_0)
end
function tmp = code(x, c, s)
	t_0 = c * (x * s);
	tmp = (1.0 / t_0) / t_0;
end
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}

\\
\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.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.0% accurate, 24.1× speedup?

\[\begin{array}{l} \\ \frac{1}{c \cdot \left(\left(x \cdot s\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)} \end{array} \]
(FPCore (x c s) :precision binary64 (/ 1.0 (* c (* (* x s) (* c (* x s))))))
double code(double x, double c, double s) {
	return 1.0 / (c * ((x * s) * (c * (x * s))));
}
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
public static double code(double x, double c, double s) {
	return 1.0 / (c * ((x * s) * (c * (x * s))));
}
def code(x, c, s):
	return 1.0 / (c * ((x * s) * (c * (x * s))))
function code(x, c, s)
	return Float64(1.0 / Float64(c * Float64(Float64(x * s) * Float64(c * Float64(x * s)))))
end
function tmp = code(x, c, s)
	tmp = 1.0 / (c * ((x * s) * (c * (x * s))));
end
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}

\\
\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.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{\cos \left(x \cdot -2\right)}{{c}^{2}}}{{s}^{2} \cdot {x}^{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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