mixedcos

Percentage Accurate: 66.2% → 99.1%
Time: 13.7s
Alternatives: 7
Speedup: 24.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 66.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.1% accurate, 2.7× speedup?

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

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


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

    1. Initial program 68.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.49999999999999989e-7 < x

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.8% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

Alternative 3: 79.2% accurate, 14.9× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 3.9999999999999996e-254

    1. Initial program 70.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.9999999999999996e-254 < c

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 79.5% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 79.6% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.6% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.6% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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