mixedcos

Percentage Accurate: 66.9% → 97.0%
Time: 6.9s
Alternatives: 6
Speedup: 9.0×

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 6 alternatives:

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

Initial Program: 66.9% 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.0% accurate, 2.4× speedup?

\[\begin{array}{l} [x, c, s] = \mathsf{sort}([x, c, s])\\ \\ \begin{array}{l} t_0 := \left(c \cdot x\right) \cdot s\\ \frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0} \end{array} \end{array} \]
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* (* c x) s))) (/ (cos (+ x x)) (* t_0 t_0))))
assert(x < c && c < s);
double code(double x, double c, double s) {
	double t_0 = (c * x) * s;
	return cos((x + x)) / (t_0 * t_0);
}
NOTE: x, c, and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: t_0
    t_0 = (c * x) * s
    code = cos((x + x)) / (t_0 * t_0)
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
	double t_0 = (c * x) * s;
	return Math.cos((x + x)) / (t_0 * t_0);
}
[x, c, s] = sort([x, c, s])
def code(x, c, s):
	t_0 = (c * x) * s
	return math.cos((x + x)) / (t_0 * t_0)
x, c, s = sort([x, c, s])
function code(x, c, s)
	t_0 = Float64(Float64(c * x) * s)
	return Float64(cos(Float64(x + x)) / Float64(t_0 * t_0))
end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
	t_0 = (c * x) * s;
	tmp = cos((x + x)) / (t_0 * t_0);
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
\frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Derivation
  1. Initial program 66.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

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

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
    6. unswap-sqrN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
    7. unswap-sqrN/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
    8. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
    9. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    10. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    11. lower-*.f64N/A

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \color{blue}{\left(\left(c \cdot x\right) \cdot s\right)}} \]
    12. lower-*.f6498.1

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

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

      \[\leadsto \frac{\cos \color{blue}{\left(2 \cdot x\right)}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    2. count-2N/A

      \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    3. lower-+.f6498.1

      \[\leadsto \frac{\cos \color{blue}{\left(x + x\right)}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
  7. Applied rewrites98.1%

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

Alternative 2: 82.3% accurate, 0.7× speedup?

\[\begin{array}{l} [x, c, s] = \mathsf{sort}([x, c, s])\\ \\ \begin{array}{l} t_0 := \left(c \cdot x\right) \cdot s\\ \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_0 \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \end{array} \]
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (* (* c x) s)))
   (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -2e-102)
     (/ (fma -2.0 (* x x) 1.0) (* t_0 t_0))
     (pow (* s (* x c)) -2.0))))
assert(x < c && c < s);
double code(double x, double c, double s) {
	double t_0 = (c * x) * s;
	double tmp;
	if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -2e-102) {
		tmp = fma(-2.0, (x * x), 1.0) / (t_0 * t_0);
	} else {
		tmp = pow((s * (x * c)), -2.0);
	}
	return tmp;
}
x, c, s = sort([x, c, s])
function code(x, c, s)
	t_0 = Float64(Float64(c * x) * s)
	tmp = 0.0
	if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -2e-102)
		tmp = Float64(fma(-2.0, Float64(x * x), 1.0) / Float64(t_0 * t_0));
	else
		tmp = Float64(s * Float64(x * c)) ^ -2.0;
	end
	return tmp
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, If[LessEqual[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], -2e-102], N[(N[(-2.0 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_0 \cdot t\_0}\\

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


\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))) < -1.99999999999999987e-102

    1. Initial program 53.5%

      \[\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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
      6. unswap-sqrN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
      7. unswap-sqrN/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      10. lower-*.f64N/A

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      11. lower-*.f64N/A

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

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

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

      \[\leadsto \frac{\color{blue}{1 + -2 \cdot {x}^{2}}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{-2 \cdot {x}^{2} + 1}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      2. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-2, {x}^{2}, 1\right)}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      3. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(-2, \color{blue}{x \cdot x}, 1\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      4. lower-*.f6442.6

        \[\leadsto \frac{\mathsf{fma}\left(-2, \color{blue}{x \cdot x}, 1\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
    8. Applied rewrites42.6%

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

    if -1.99999999999999987e-102 < (/.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 67.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

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

        \[\leadsto \frac{1}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}} \]
      2. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{{x}^{2}}}{{c}^{2} \cdot {s}^{2}}} \]
      3. unpow2N/A

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

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

        \[\leadsto \color{blue}{\frac{\frac{\frac{1}{{x}^{2}}}{c}}{c \cdot {s}^{2}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{\frac{1}{{x}^{2}}}{c}}{c \cdot {s}^{2}}} \]
      7. lower-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{\frac{1}{{x}^{2}}}{c}}}{c \cdot {s}^{2}} \]
      8. unpow2N/A

        \[\leadsto \frac{\frac{\frac{1}{\color{blue}{x \cdot x}}}{c}}{c \cdot {s}^{2}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{\frac{\color{blue}{\frac{\frac{1}{x}}{x}}}{c}}{c \cdot {s}^{2}} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{\frac{\frac{1}{x}}{x}}}{c}}{c \cdot {s}^{2}} \]
      11. lower-/.f64N/A

        \[\leadsto \frac{\frac{\frac{\color{blue}{\frac{1}{x}}}{x}}{c}}{c \cdot {s}^{2}} \]
      12. unpow2N/A

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

        \[\leadsto \frac{\frac{\frac{\frac{1}{x}}{x}}{c}}{\color{blue}{\left(c \cdot s\right) \cdot s}} \]
      14. *-commutativeN/A

        \[\leadsto \frac{\frac{\frac{\frac{1}{x}}{x}}{c}}{\color{blue}{\left(s \cdot c\right)} \cdot s} \]
      15. lower-*.f64N/A

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

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

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

        \[\leadsto {\left(s \cdot \left(x \cdot c\right)\right)}^{\color{blue}{-2}} \]
    7. Recombined 2 regimes into one program.
    8. Add Preprocessing

    Alternative 3: 82.2% accurate, 0.9× speedup?

    \[\begin{array}{l} [x, c, s] = \mathsf{sort}([x, c, s])\\ \\ \begin{array}{l} t_0 := \left(c \cdot x\right) \cdot s\\ t_1 := t\_0 \cdot t\_0\\ \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t\_1}\\ \end{array} \end{array} \]
    NOTE: x, c, and s should be sorted in increasing order before calling this function.
    (FPCore (x c s)
     :precision binary64
     (let* ((t_0 (* (* c x) s)) (t_1 (* t_0 t_0)))
       (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -2e-102)
         (/ (fma -2.0 (* x x) 1.0) t_1)
         (/ 1.0 t_1))))
    assert(x < c && c < s);
    double code(double x, double c, double s) {
    	double t_0 = (c * x) * s;
    	double t_1 = t_0 * t_0;
    	double tmp;
    	if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -2e-102) {
    		tmp = fma(-2.0, (x * x), 1.0) / t_1;
    	} else {
    		tmp = 1.0 / t_1;
    	}
    	return tmp;
    }
    
    x, c, s = sort([x, c, s])
    function code(x, c, s)
    	t_0 = Float64(Float64(c * x) * s)
    	t_1 = Float64(t_0 * t_0)
    	tmp = 0.0
    	if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -2e-102)
    		tmp = Float64(fma(-2.0, Float64(x * x), 1.0) / t_1);
    	else
    		tmp = Float64(1.0 / t_1);
    	end
    	return tmp
    end
    
    NOTE: x, c, and s should be sorted in increasing order before calling this function.
    code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, If[LessEqual[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], -2e-102], N[(N[(-2.0 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / t$95$1), $MachinePrecision], N[(1.0 / t$95$1), $MachinePrecision]]]]
    
    \begin{array}{l}
    [x, c, s] = \mathsf{sort}([x, c, s])\\
    \\
    \begin{array}{l}
    t_0 := \left(c \cdot x\right) \cdot s\\
    t_1 := t\_0 \cdot t\_0\\
    \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_1}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{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))) < -1.99999999999999987e-102

      1. Initial program 53.5%

        \[\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

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

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

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

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

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

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
        6. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
        7. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        8. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        9. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        10. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        11. lower-*.f64N/A

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

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

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

        \[\leadsto \frac{\color{blue}{1 + -2 \cdot {x}^{2}}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \frac{\color{blue}{-2 \cdot {x}^{2} + 1}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        2. lower-fma.f64N/A

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-2, {x}^{2}, 1\right)}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        3. unpow2N/A

          \[\leadsto \frac{\mathsf{fma}\left(-2, \color{blue}{x \cdot x}, 1\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        4. lower-*.f6442.6

          \[\leadsto \frac{\mathsf{fma}\left(-2, \color{blue}{x \cdot x}, 1\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      8. Applied rewrites42.6%

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

      if -1.99999999999999987e-102 < (/.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 67.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

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

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

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

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

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

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
        6. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
        7. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        8. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        9. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        10. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        11. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \color{blue}{\left(\left(c \cdot x\right) \cdot s\right)}} \]
        12. lower-*.f6498.0

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

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

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

          \[\leadsto \frac{\color{blue}{1}}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 4: 78.9% accurate, 9.0× speedup?

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

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

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

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

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

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

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
        6. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
        7. unswap-sqrN/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        8. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
        9. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        10. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
        11. lower-*.f64N/A

          \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \color{blue}{\left(\left(c \cdot x\right) \cdot s\right)}} \]
        12. lower-*.f6498.1

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

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

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

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

        Alternative 5: 76.3% accurate, 9.0× speedup?

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

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

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

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

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

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

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
          6. unswap-sqrN/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
          7. unswap-sqrN/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
          8. lower-*.f64N/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
          9. lower-*.f64N/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
          10. lower-*.f64N/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
          11. lower-*.f64N/A

            \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \color{blue}{\left(\left(c \cdot x\right) \cdot s\right)}} \]
          12. lower-*.f6498.1

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

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

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

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

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

            Alternative 6: 67.6% accurate, 9.0× speedup?

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

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

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

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

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

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

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(s \cdot s\right)} \]
              6. unswap-sqrN/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot \left(s \cdot s\right)} \]
              7. unswap-sqrN/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
              8. lower-*.f64N/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}} \]
              9. lower-*.f64N/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
              10. lower-*.f64N/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)} \]
              11. lower-*.f64N/A

                \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \color{blue}{\left(\left(c \cdot x\right) \cdot s\right)}} \]
              12. lower-*.f6498.1

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

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

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

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

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

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

                  Reproduce

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