mixedcos

Percentage Accurate: 64.8% → 98.5%
Time: 32.0s
Alternatives: 12
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 12 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: 64.8% 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: 98.5% accurate, 2.6× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 1.5999999999999999e163

    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. *-commutative68.3%

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

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

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

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

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

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

        \[\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. *-commutative99.2%

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

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

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

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

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

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

    if 1.5999999999999999e163 < s

    1. Initial program 0.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.2% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.9% accurate, 2.6× speedup?

\[\begin{array}{l} c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.00072:\\ \;\;\;\;{\left(\frac{\frac{1 - x \cdot x}{c}}{x \cdot s}\right)}^{2}\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{+153}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(\left(c \cdot c\right) \cdot \left(s \cdot \left(x \cdot x\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{{\left(c \cdot \left(x \cdot s\right)\right)}^{2}}\\ \end{array} \end{array} \]
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 0.00072)
   (pow (/ (/ (- 1.0 (* x x)) c) (* x s)) 2.0)
   (if (<= x 8.2e+153)
     (/ (cos (* 2.0 x)) (* s (* (* c c) (* s (* x x)))))
     (/ 1.0 (pow (* c (* x s)) 2.0)))))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 0.00072) {
		tmp = pow((((1.0 - (x * x)) / c) / (x * s)), 2.0);
	} else if (x <= 8.2e+153) {
		tmp = cos((2.0 * x)) / (s * ((c * c) * (s * (x * x))));
	} else {
		tmp = 1.0 / pow((c * (x * s)), 2.0);
	}
	return tmp;
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 0.00072d0) then
        tmp = (((1.0d0 - (x * x)) / c) / (x * s)) ** 2.0d0
    else if (x <= 8.2d+153) then
        tmp = cos((2.0d0 * x)) / (s * ((c * c) * (s * (x * x))))
    else
        tmp = 1.0d0 / ((c * (x * s)) ** 2.0d0)
    end if
    code = tmp
end function
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 0.00072) {
		tmp = Math.pow((((1.0 - (x * x)) / c) / (x * s)), 2.0);
	} else if (x <= 8.2e+153) {
		tmp = Math.cos((2.0 * x)) / (s * ((c * c) * (s * (x * x))));
	} else {
		tmp = 1.0 / Math.pow((c * (x * s)), 2.0);
	}
	return tmp;
}
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if x <= 0.00072:
		tmp = math.pow((((1.0 - (x * x)) / c) / (x * s)), 2.0)
	elif x <= 8.2e+153:
		tmp = math.cos((2.0 * x)) / (s * ((c * c) * (s * (x * x))))
	else:
		tmp = 1.0 / math.pow((c * (x * s)), 2.0)
	return tmp
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (x <= 0.00072)
		tmp = Float64(Float64(Float64(1.0 - Float64(x * x)) / c) / Float64(x * s)) ^ 2.0;
	elseif (x <= 8.2e+153)
		tmp = Float64(cos(Float64(2.0 * x)) / Float64(s * Float64(Float64(c * c) * Float64(s * Float64(x * x)))));
	else
		tmp = Float64(1.0 / (Float64(c * Float64(x * s)) ^ 2.0));
	end
	return tmp
end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 0.00072)
		tmp = (((1.0 - (x * x)) / c) / (x * s)) ^ 2.0;
	elseif (x <= 8.2e+153)
		tmp = cos((2.0 * x)) / (s * ((c * c) * (s * (x * x))));
	else
		tmp = 1.0 / ((c * (x * s)) ^ 2.0);
	end
	tmp_2 = tmp;
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 0.00072], N[Power[N[(N[(N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], If[LessEqual[x, 8.2e+153], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(s * N[(N[(c * c), $MachinePrecision] * N[(s * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00072:\\
\;\;\;\;{\left(\frac{\frac{1 - x \cdot x}{c}}{x \cdot s}\right)}^{2}\\

\mathbf{elif}\;x \leq 8.2 \cdot 10^{+153}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(\left(c \cdot c\right) \cdot \left(s \cdot \left(x \cdot x\right)\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 7.20000000000000045e-4

    1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.20000000000000045e-4 < x < 8.20000000000000033e153

    1. Initial program 61.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.20000000000000033e153 < x

    1. Initial program 44.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 83.4% accurate, 2.7× speedup?

\[\begin{array}{l} c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.00072:\\ \;\;\;\;{\left(\frac{\frac{1 - x \cdot x}{c}}{x \cdot s}\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ \end{array} \end{array} \]
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
 :precision binary64
 (if (<= x 0.00072)
   (pow (/ (/ (- 1.0 (* x x)) c) (* x s)) 2.0)
   (/ (cos (* 2.0 x)) (* x (* c (* c (* s (* x s))))))))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double tmp;
	if (x <= 0.00072) {
		tmp = pow((((1.0 - (x * x)) / c) / (x * s)), 2.0);
	} else {
		tmp = cos((2.0 * x)) / (x * (c * (c * (s * (x * s)))));
	}
	return tmp;
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: tmp
    if (x <= 0.00072d0) then
        tmp = (((1.0d0 - (x * x)) / c) / (x * s)) ** 2.0d0
    else
        tmp = cos((2.0d0 * x)) / (x * (c * (c * (s * (x * s)))))
    end if
    code = tmp
end function
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
	double tmp;
	if (x <= 0.00072) {
		tmp = Math.pow((((1.0 - (x * x)) / c) / (x * s)), 2.0);
	} else {
		tmp = Math.cos((2.0 * x)) / (x * (c * (c * (s * (x * s)))));
	}
	return tmp;
}
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	tmp = 0
	if x <= 0.00072:
		tmp = math.pow((((1.0 - (x * x)) / c) / (x * s)), 2.0)
	else:
		tmp = math.cos((2.0 * x)) / (x * (c * (c * (s * (x * s)))))
	return tmp
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	tmp = 0.0
	if (x <= 0.00072)
		tmp = Float64(Float64(Float64(1.0 - Float64(x * x)) / c) / Float64(x * s)) ^ 2.0;
	else
		tmp = Float64(cos(Float64(2.0 * x)) / Float64(x * Float64(c * Float64(c * Float64(s * Float64(x * s))))));
	end
	return tmp
end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
	tmp = 0.0;
	if (x <= 0.00072)
		tmp = (((1.0 - (x * x)) / c) / (x * s)) ^ 2.0;
	else
		tmp = cos((2.0 * x)) / (x * (c * (c * (s * (x * s)))));
	end
	tmp_2 = tmp;
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := If[LessEqual[x, 0.00072], N[Power[N[(N[(N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(x * N[(c * N[(c * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00072:\\
\;\;\;\;{\left(\frac{\frac{1 - x \cdot x}{c}}{x \cdot s}\right)}^{2}\\

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


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

    1. Initial program 65.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.20000000000000045e-4 < x

    1. Initial program 56.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 98.5% accurate, 2.7× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 4.70000000000000027e181

    1. Initial program 67.2%

      \[\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. *-commutative67.2%

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

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

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

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

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

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

        \[\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. *-commutative99.2%

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

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

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

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

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

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

    if 4.70000000000000027e181 < s

    1. Initial program 1.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 96.3% accurate, 2.7× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{t_0 \cdot t_0}\\


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

    1. Initial program 65.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*67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.95e39 < x

    1. Initial program 52.9%

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right) \cdot \color{blue}{\left(s \cdot s\right)}} \]
      7. swap-sqr99.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)}} \]
      8. *-commutative99.5%

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

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

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

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

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

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

Alternative 7: 93.9% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 76.8% accurate, 2.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 73.1% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(\sqrt[3]{\cos \left(2 \cdot x\right)} \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}\right) \cdot \sqrt[3]{\cos \left(2 \cdot x\right)}}{\color{blue}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
    9. add-cube-cbrt98.2%

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

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

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

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

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

Alternative 10: 76.4% accurate, 20.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 30.0% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.6666666666666666 \cdot \frac{{x}^{2}}{{c}^{2} \cdot {s}^{2}}} \]
    3. Step-by-step derivation
      1. unpow223.5%

        \[\leadsto 0.6666666666666666 \cdot \frac{\color{blue}{x \cdot x}}{{c}^{2} \cdot {s}^{2}} \]
      2. associate-*r/23.5%

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

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

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

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

        \[\leadsto \frac{\color{blue}{0.6666666666666666 \cdot \frac{x \cdot x}{c \cdot c}}}{s \cdot s} \]
      7. associate-*r/21.9%

        \[\leadsto \color{blue}{0.6666666666666666 \cdot \frac{\frac{x \cdot x}{c \cdot c}}{s \cdot s}} \]
      8. associate-*l/29.4%

        \[\leadsto 0.6666666666666666 \cdot \frac{\color{blue}{\frac{x}{c \cdot c} \cdot x}}{s \cdot s} \]
      9. associate-*r/32.9%

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

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

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

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

    Alternative 12: 69.0% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Reproduce

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