mixedcos

Percentage Accurate: 66.3% → 99.4%
Time: 12.9s
Alternatives: 11
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 11 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.3% 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.4% accurate, 1.5× speedup?

\[\begin{array}{l} x = |x|\\ 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(x \cdot 2\right)\\ \mathbf{if}\;x \leq 5 \cdot 10^{-75}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2} \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{t_0} \cdot \frac{1}{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 (* s (* x c))) (t_1 (cos (* x 2.0))))
   (if (<= x 5e-75)
     (* (pow (* c (* x s)) -2.0) t_1)
     (* (/ t_1 t_0) (/ 1.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 = s * (x * c);
	double t_1 = cos((x * 2.0));
	double tmp;
	if (x <= 5e-75) {
		tmp = pow((c * (x * s)), -2.0) * t_1;
	} else {
		tmp = (t_1 / t_0) * (1.0 / 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) :: t_1
    real(8) :: tmp
    t_0 = s * (x * c)
    t_1 = cos((x * 2.0d0))
    if (x <= 5d-75) then
        tmp = ((c * (x * s)) ** (-2.0d0)) * t_1
    else
        tmp = (t_1 / t_0) * (1.0d0 / 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 = s * (x * c);
	double t_1 = Math.cos((x * 2.0));
	double tmp;
	if (x <= 5e-75) {
		tmp = Math.pow((c * (x * s)), -2.0) * t_1;
	} else {
		tmp = (t_1 / t_0) * (1.0 / 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 = s * (x * c)
	t_1 = math.cos((x * 2.0))
	tmp = 0
	if x <= 5e-75:
		tmp = math.pow((c * (x * s)), -2.0) * t_1
	else:
		tmp = (t_1 / t_0) * (1.0 / 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(s * Float64(x * c))
	t_1 = cos(Float64(x * 2.0))
	tmp = 0.0
	if (x <= 5e-75)
		tmp = Float64((Float64(c * Float64(x * s)) ^ -2.0) * t_1);
	else
		tmp = Float64(Float64(t_1 / t_0) * Float64(1.0 / 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 = s * (x * c);
	t_1 = cos((x * 2.0));
	tmp = 0.0;
	if (x <= 5e-75)
		tmp = ((c * (x * s)) ^ -2.0) * t_1;
	else
		tmp = (t_1 / t_0) * (1.0 / 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[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 5e-75], N[(N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] * t$95$1), $MachinePrecision], N[(N[(t$95$1 / t$95$0), $MachinePrecision] * N[(1.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 := s \cdot \left(x \cdot c\right)\\
t_1 := \cos \left(x \cdot 2\right)\\
\mathbf{if}\;x \leq 5 \cdot 10^{-75}:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2} \cdot t_1\\

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 x around inf 60.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(x \cdot 2\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \color{blue}{\left(s \cdot \left(x \cdot c\right)\right)}} \]
      13. associate-/r*94.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)}} \]
      14. *-rgt-identity94.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)} \]
      15. associate-*r/94.2%

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

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

    if 4.99999999999999979e-75 < x

    1. Initial program 59.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. *-commutative59.1%

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

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. associate-/r*98.4%

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

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

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

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.7%

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

Alternative 2: 86.0% accurate, 2.6× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;x \leq 9 \cdot 10^{-9}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{+150}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(s \cdot {\left(x \cdot c\right)}^{2}\right)}\\ \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 (/ (/ 1.0 c) (* x s))))
   (if (<= x 9e-9)
     (* t_0 t_0)
     (if (<= x 6.6e+150)
       (/ (cos (* x 2.0)) (* s (* (* x x) (* s (* c c)))))
       (/ 1.0 (* s (* s (pow (* x c) 2.0))))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 9e-9) {
		tmp = t_0 * t_0;
	} else if (x <= 6.6e+150) {
		tmp = cos((x * 2.0)) / (s * ((x * x) * (s * (c * c))));
	} else {
		tmp = 1.0 / (s * (s * pow((x * c), 2.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 = (1.0d0 / c) / (x * s)
    if (x <= 9d-9) then
        tmp = t_0 * t_0
    else if (x <= 6.6d+150) then
        tmp = cos((x * 2.0d0)) / (s * ((x * x) * (s * (c * c))))
    else
        tmp = 1.0d0 / (s * (s * ((x * c) ** 2.0d0)))
    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 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 9e-9) {
		tmp = t_0 * t_0;
	} else if (x <= 6.6e+150) {
		tmp = Math.cos((x * 2.0)) / (s * ((x * x) * (s * (c * c))));
	} else {
		tmp = 1.0 / (s * (s * Math.pow((x * c), 2.0)));
	}
	return tmp;
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = (1.0 / c) / (x * s)
	tmp = 0
	if x <= 9e-9:
		tmp = t_0 * t_0
	elif x <= 6.6e+150:
		tmp = math.cos((x * 2.0)) / (s * ((x * x) * (s * (c * c))))
	else:
		tmp = 1.0 / (s * (s * math.pow((x * c), 2.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(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (x <= 9e-9)
		tmp = Float64(t_0 * t_0);
	elseif (x <= 6.6e+150)
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(s * Float64(Float64(x * x) * Float64(s * Float64(c * c)))));
	else
		tmp = Float64(1.0 / Float64(s * Float64(s * (Float64(x * c) ^ 2.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 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (x <= 9e-9)
		tmp = t_0 * t_0;
	elseif (x <= 6.6e+150)
		tmp = cos((x * 2.0)) / (s * ((x * x) * (s * (c * c))));
	else
		tmp = 1.0 / (s * (s * ((x * c) ^ 2.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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 9e-9], N[(t$95$0 * t$95$0), $MachinePrecision], If[LessEqual[x, 6.6e+150], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(s * N[(N[(x * x), $MachinePrecision] * N[(s * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(s * N[(s * N[Power[N[(x * c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;x \leq 9 \cdot 10^{-9}:\\
\;\;\;\;t_0 \cdot t_0\\

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

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


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

    1. Initial program 66.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*65.8%

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

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

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

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

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

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

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

      \[\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. add-sqr-sqrt60.7%

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

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

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

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

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      6. add-sqr-sqrt39.0%

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

        \[\leadsto \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      8. sqrt-prod36.9%

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{s \cdot x}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      14. sqrt-div44.0%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval44.6%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt42.7%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
      20. sqrt-prod41.8%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr84.7%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]

    if 8.99999999999999953e-9 < x < 6.59999999999999962e150

    1. Initial program 61.6%

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

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

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

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

        \[\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*75.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*77.4%

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

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

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

      \[\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)}} \]

    if 6.59999999999999962e150 < x

    1. Initial program 52.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. *-commutative52.7%

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

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

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

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

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

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

        \[\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. *-commutative95.6%

        \[\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. *-commutative95.6%

        \[\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. *-commutative95.6%

        \[\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. *-commutative95.6%

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

      \[\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 x around 0 43.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left(\left(s \cdot x\right) \cdot c\right) \cdot \color{blue}{\left(s \cdot \left(x \cdot c\right)\right)}} \]
      11. associate-*r*70.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)} \]
      12. unpow270.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.3% accurate, 2.6× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ t_1 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;x \leq 1.3 \cdot 10^{-77}:\\ \;\;\;\;t_1 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0} \cdot \frac{1}{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 (* s (* x c))) (t_1 (/ (/ 1.0 c) (* x s))))
   (if (<= x 1.3e-77) (* t_1 t_1) (* (/ (cos (* x 2.0)) t_0) (/ 1.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 = s * (x * c);
	double t_1 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 1.3e-77) {
		tmp = t_1 * t_1;
	} else {
		tmp = (cos((x * 2.0)) / t_0) * (1.0 / 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) :: t_1
    real(8) :: tmp
    t_0 = s * (x * c)
    t_1 = (1.0d0 / c) / (x * s)
    if (x <= 1.3d-77) then
        tmp = t_1 * t_1
    else
        tmp = (cos((x * 2.0d0)) / t_0) * (1.0d0 / 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 = s * (x * c);
	double t_1 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 1.3e-77) {
		tmp = t_1 * t_1;
	} else {
		tmp = (Math.cos((x * 2.0)) / t_0) * (1.0 / 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 = s * (x * c)
	t_1 = (1.0 / c) / (x * s)
	tmp = 0
	if x <= 1.3e-77:
		tmp = t_1 * t_1
	else:
		tmp = (math.cos((x * 2.0)) / t_0) * (1.0 / 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(s * Float64(x * c))
	t_1 = Float64(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (x <= 1.3e-77)
		tmp = Float64(t_1 * t_1);
	else
		tmp = Float64(Float64(cos(Float64(x * 2.0)) / t_0) * Float64(1.0 / 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 = s * (x * c);
	t_1 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (x <= 1.3e-77)
		tmp = t_1 * t_1;
	else
		tmp = (cos((x * 2.0)) / t_0) * (1.0 / 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[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.3e-77], N[(t$95$1 * t$95$1), $MachinePrecision], N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] * N[(1.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 := s \cdot \left(x \cdot c\right)\\
t_1 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;x \leq 1.3 \cdot 10^{-77}:\\
\;\;\;\;t_1 \cdot t_1\\

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


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

    1. Initial program 66.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. associate-/r*65.9%

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

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

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

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

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

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

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

      \[\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. add-sqr-sqrt60.2%

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

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      4. metadata-eval60.2%

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

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      6. add-sqr-sqrt39.9%

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{s \cdot s}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      10. add-sqr-sqrt45.8%

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{x} \cdot \sqrt{s \cdot s}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      11. sqrt-prod25.0%

        \[\leadsto \frac{\frac{1}{c}}{x \cdot \color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      12. add-sqr-sqrt45.5%

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{s \cdot x}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      14. sqrt-div45.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\sqrt{\frac{1}{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}}} \]
      15. sqrt-div46.1%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval46.1%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{\color{blue}{1}}{\sqrt{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      17. sqrt-prod23.1%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt41.5%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
      20. sqrt-prod40.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]

    if 1.3000000000000001e-77 < x

    1. Initial program 58.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. *-commutative58.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*55.4%

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

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

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. associate-/r*98.4%

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

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

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

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.0%

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

Alternative 4: 86.1% accurate, 2.7× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;s \leq 1.95 \cdot 10^{+125}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(x \cdot \left(\left(s \cdot s\right) \cdot \left(c \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;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 (/ (/ 1.0 c) (* x s))))
   (if (<= s 1.95e+125)
     (/ (cos (* x 2.0)) (* x (* x (* (* s s) (* c c)))))
     (* 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 = (1.0 / c) / (x * s);
	double tmp;
	if (s <= 1.95e+125) {
		tmp = cos((x * 2.0)) / (x * (x * ((s * s) * (c * c))));
	} else {
		tmp = t_0 * 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 = (1.0d0 / c) / (x * s)
    if (s <= 1.95d+125) then
        tmp = cos((x * 2.0d0)) / (x * (x * ((s * s) * (c * c))))
    else
        tmp = t_0 * 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 = (1.0 / c) / (x * s);
	double tmp;
	if (s <= 1.95e+125) {
		tmp = Math.cos((x * 2.0)) / (x * (x * ((s * s) * (c * c))));
	} else {
		tmp = t_0 * 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 = (1.0 / c) / (x * s)
	tmp = 0
	if s <= 1.95e+125:
		tmp = math.cos((x * 2.0)) / (x * (x * ((s * s) * (c * c))))
	else:
		tmp = t_0 * 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(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (s <= 1.95e+125)
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(x * Float64(Float64(s * s) * Float64(c * c)))));
	else
		tmp = Float64(t_0 * 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 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (s <= 1.95e+125)
		tmp = cos((x * 2.0)) / (x * (x * ((s * s) * (c * c))));
	else
		tmp = t_0 * 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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 1.95e+125], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(N[(s * s), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;s \leq 1.95 \cdot 10^{+125}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(x \cdot \left(\left(s \cdot s\right) \cdot \left(c \cdot c\right)\right)\right)}\\

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


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

    1. Initial program 66.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*69.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. *-commutative69.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. *-commutative69.2%

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

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

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

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

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

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

    if 1.9500000000000001e125 < s

    1. Initial program 47.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*46.5%

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

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

        \[\leadsto \frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot c}}{\color{blue}{x \cdot \left(x \cdot {s}^{2}\right)}} \]
      4. unpow246.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. Simplified46.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 46.5%

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

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

      \[\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. add-sqr-sqrt46.6%

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

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      4. metadata-eval46.6%

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      8. sqrt-prod39.4%

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      9. sqrt-unprod25.8%

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

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{s \cdot x}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      14. sqrt-div42.1%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\sqrt{\frac{1}{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}}} \]
      15. sqrt-div44.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval44.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{\color{blue}{1}}{\sqrt{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      17. sqrt-prod26.8%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt48.5%

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr86.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.9%

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

Alternative 5: 90.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 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;s \leq 2.05 \cdot 10^{+148}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(\left(c \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;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 (/ (/ 1.0 c) (* x s))))
   (if (<= s 2.05e+148)
     (/ (cos (* x 2.0)) (* x (* (* c (* x c)) (* s s))))
     (* 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 = (1.0 / c) / (x * s);
	double tmp;
	if (s <= 2.05e+148) {
		tmp = cos((x * 2.0)) / (x * ((c * (x * c)) * (s * s)));
	} else {
		tmp = t_0 * 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 = (1.0d0 / c) / (x * s)
    if (s <= 2.05d+148) then
        tmp = cos((x * 2.0d0)) / (x * ((c * (x * c)) * (s * s)))
    else
        tmp = t_0 * 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 = (1.0 / c) / (x * s);
	double tmp;
	if (s <= 2.05e+148) {
		tmp = Math.cos((x * 2.0)) / (x * ((c * (x * c)) * (s * s)));
	} else {
		tmp = t_0 * 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 = (1.0 / c) / (x * s)
	tmp = 0
	if s <= 2.05e+148:
		tmp = math.cos((x * 2.0)) / (x * ((c * (x * c)) * (s * s)))
	else:
		tmp = t_0 * 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(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (s <= 2.05e+148)
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(Float64(c * Float64(x * c)) * Float64(s * s))));
	else
		tmp = Float64(t_0 * 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 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (s <= 2.05e+148)
		tmp = cos((x * 2.0)) / (x * ((c * (x * c)) * (s * s)));
	else
		tmp = t_0 * 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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 2.05e+148], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision] * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;s \leq 2.05 \cdot 10^{+148}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(\left(c \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot s\right)\right)}\\

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


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

    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. associate-*r*69.6%

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

        \[\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*70.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. unpow270.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. unpow270.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. Simplified70.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 70.0%

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

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

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

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

    if 2.0499999999999999e148 < s

    1. Initial program 41.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*40.7%

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

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

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

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

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

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

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

      \[\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. add-sqr-sqrt40.7%

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      5. sqrt-prod24.0%

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      6. add-sqr-sqrt40.7%

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

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      9. sqrt-unprod29.8%

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{s \cdot s}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      10. add-sqr-sqrt40.7%

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

        \[\leadsto \frac{\frac{1}{c}}{x \cdot \color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      12. add-sqr-sqrt40.7%

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

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\sqrt{\frac{1}{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}}} \]
      15. sqrt-div43.4%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval43.4%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{\color{blue}{1}}{\sqrt{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      17. sqrt-prod28.4%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt50.8%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
      20. sqrt-prod47.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr84.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.8%

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

Alternative 6: 96.9% accurate, 2.7× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;x \leq 4.5 \cdot 10^{-60}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}\\ \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 (/ (/ 1.0 c) (* x s))))
   (if (<= x 4.5e-60)
     (* t_0 t_0)
     (/ (cos (* x 2.0)) (* (* c (* x s)) (* s (* x c)))))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	double t_0 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 4.5e-60) {
		tmp = t_0 * t_0;
	} else {
		tmp = cos((x * 2.0)) / ((c * (x * s)) * (s * (x * c)));
	}
	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 = (1.0d0 / c) / (x * s)
    if (x <= 4.5d-60) then
        tmp = t_0 * t_0
    else
        tmp = cos((x * 2.0d0)) / ((c * (x * s)) * (s * (x * c)))
    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 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 4.5e-60) {
		tmp = t_0 * t_0;
	} else {
		tmp = Math.cos((x * 2.0)) / ((c * (x * s)) * (s * (x * c)));
	}
	return tmp;
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	t_0 = (1.0 / c) / (x * s)
	tmp = 0
	if x <= 4.5e-60:
		tmp = t_0 * t_0
	else:
		tmp = math.cos((x * 2.0)) / ((c * (x * s)) * (s * (x * c)))
	return tmp
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	t_0 = Float64(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (x <= 4.5e-60)
		tmp = Float64(t_0 * t_0);
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(Float64(c * Float64(x * s)) * Float64(s * Float64(x * c))));
	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 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (x <= 4.5e-60)
		tmp = t_0 * t_0;
	else
		tmp = cos((x * 2.0)) / ((c * (x * s)) * (s * (x * c)));
	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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 4.5e-60], N[(t$95$0 * t$95$0), $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;x \leq 4.5 \cdot 10^{-60}:\\
\;\;\;\;t_0 \cdot t_0\\

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


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

    1. Initial program 65.6%

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

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

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

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

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

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

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

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

      \[\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. add-sqr-sqrt59.9%

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

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      4. metadata-eval59.9%

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      8. sqrt-prod36.9%

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{s \cdot s}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      10. add-sqr-sqrt44.8%

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

        \[\leadsto \frac{\frac{1}{c}}{x \cdot \color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      12. add-sqr-sqrt45.2%

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{s \cdot x}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      14. sqrt-div45.1%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval45.7%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{\color{blue}{1}}{\sqrt{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      17. sqrt-prod22.8%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt41.9%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
      20. sqrt-prod40.9%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr83.8%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]

    if 4.50000000000000001e-60 < x

    1. Initial program 59.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. *-commutative59.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*55.7%

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

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

        \[\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-sqr65.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. unpow265.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-sqr97.8%

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

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

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

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

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

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

      \[\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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.1%

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

Alternative 7: 99.2% accurate, 2.7× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ t_1 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;x \leq 1.15 \cdot 10^{-58}:\\ \;\;\;\;t_1 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{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 (* s (* x c))) (t_1 (/ (/ 1.0 c) (* x s))))
   (if (<= x 1.15e-58) (* t_1 t_1) (/ (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 = s * (x * c);
	double t_1 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 1.15e-58) {
		tmp = t_1 * t_1;
	} else {
		tmp = cos((x * 2.0)) / (t_0 * 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) :: t_1
    real(8) :: tmp
    t_0 = s * (x * c)
    t_1 = (1.0d0 / c) / (x * s)
    if (x <= 1.15d-58) then
        tmp = t_1 * t_1
    else
        tmp = cos((x * 2.0d0)) / (t_0 * 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 = s * (x * c);
	double t_1 = (1.0 / c) / (x * s);
	double tmp;
	if (x <= 1.15e-58) {
		tmp = t_1 * t_1;
	} else {
		tmp = Math.cos((x * 2.0)) / (t_0 * 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 = s * (x * c)
	t_1 = (1.0 / c) / (x * s)
	tmp = 0
	if x <= 1.15e-58:
		tmp = t_1 * t_1
	else:
		tmp = math.cos((x * 2.0)) / (t_0 * 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(s * Float64(x * c))
	t_1 = Float64(Float64(1.0 / c) / Float64(x * s))
	tmp = 0.0
	if (x <= 1.15e-58)
		tmp = Float64(t_1 * t_1);
	else
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(t_0 * 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 = s * (x * c);
	t_1 = (1.0 / c) / (x * s);
	tmp = 0.0;
	if (x <= 1.15e-58)
		tmp = t_1 * t_1;
	else
		tmp = cos((x * 2.0)) / (t_0 * 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[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.15e-58], N[(t$95$1 * t$95$1), $MachinePrecision], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / 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 := s \cdot \left(x \cdot c\right)\\
t_1 := \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{if}\;x \leq 1.15 \cdot 10^{-58}:\\
\;\;\;\;t_1 \cdot t_1\\

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


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

    1. Initial program 65.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. associate-/r*65.6%

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

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

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

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

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

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

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

      \[\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. add-sqr-sqrt60.1%

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

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

        \[\leadsto \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      4. metadata-eval60.1%

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

        \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      6. add-sqr-sqrt38.9%

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

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

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{s \cdot s}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      10. add-sqr-sqrt44.6%

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

        \[\leadsto \frac{\frac{1}{c}}{x \cdot \color{blue}{\left(\sqrt{s} \cdot \sqrt{s}\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      12. add-sqr-sqrt44.9%

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

        \[\leadsto \frac{\frac{1}{c}}{\color{blue}{s \cdot x}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      14. sqrt-div44.9%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \color{blue}{\frac{\sqrt{\frac{1}{c \cdot c}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}}} \]
      15. sqrt-div45.5%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      16. metadata-eval45.5%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
      18. add-sqr-sqrt42.2%

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

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
      20. sqrt-prod41.2%

        \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
    8. Applied egg-rr83.9%

      \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]

    if 1.1499999999999999e-58 < x

    1. Initial program 58.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. *-commutative58.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*55.2%

        \[\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*54.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. unpow254.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-sqr65.1%

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

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

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

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

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

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

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

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

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

Alternative 8: 80.0% accurate, 20.9× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{1}{c \cdot \left(x \cdot s\right)}\\ 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 (/ 1.0 (* c (* x s))))) (* 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 = 1.0 / (c * (x * s));
	return 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 = 1.0d0 / (c * (x * s))
    code = 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 = 1.0 / (c * (x * s));
	return 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 = 1.0 / (c * (x * s))
	return 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(1.0 / Float64(c * Float64(x * s)))
	return 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 = 1.0 / (c * (x * s));
	tmp = 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[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{1}{c \cdot \left(x \cdot s\right)}\\
t_0 \cdot t_0
\end{array}
\end{array}
Derivation
  1. Initial program 63.4%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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 x around 0 54.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto {\left(\frac{\frac{1}{\color{blue}{\sqrt{s} \cdot \sqrt{s}}}}{\sqrt{\left(c \cdot c\right) \cdot \left(x \cdot x\right)}}\right)}^{2} \]
    7. add-sqr-sqrt58.0%

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

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

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

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

      \[\leadsto {\left(\frac{\frac{1}{s}}{\color{blue}{\sqrt{x \cdot c} \cdot \sqrt{x \cdot c}}}\right)}^{2} \]
    12. add-sqr-sqrt76.4%

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

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

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

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

      \[\leadsto {\left(s \cdot \left(x \cdot c\right)\right)}^{-1} \cdot \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{-1}} \]
    17. pow-prod-up76.4%

      \[\leadsto \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{\left(-1 + -1\right)}} \]
    18. metadata-eval76.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 80.0% accurate, 20.9× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ 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 (/ (/ 1.0 c) (* x s)))) (* 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 = (1.0 / c) / (x * s);
	return 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 = (1.0d0 / c) / (x * s)
    code = 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 = (1.0 / c) / (x * s);
	return 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 = (1.0 / c) / (x * s)
	return 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(Float64(1.0 / c) / Float64(x * s))
	return 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 = (1.0 / c) / (x * s);
	tmp = 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[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{1}{c}}{x \cdot s}\\
t_0 \cdot t_0
\end{array}
\end{array}
Derivation
  1. Initial program 63.4%

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

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

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

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

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

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

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

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

    \[\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. add-sqr-sqrt57.1%

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
    4. metadata-eval57.1%

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \cdot \sqrt{\frac{\frac{1}{c \cdot c}}{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
    6. add-sqr-sqrt41.4%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\color{blue}{\frac{\sqrt{1}}{\sqrt{c \cdot c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
    16. metadata-eval45.6%

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

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{\color{blue}{\sqrt{c} \cdot \sqrt{c}}}}{\sqrt{x \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
    18. add-sqr-sqrt45.8%

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

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(s \cdot s\right)}}} \]
    20. sqrt-prod44.9%

      \[\leadsto \frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{\color{blue}{\sqrt{x \cdot x} \cdot \sqrt{s \cdot s}}} \]
  8. Applied egg-rr77.4%

    \[\leadsto \color{blue}{\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{\frac{1}{c}}{s \cdot x}} \]
  9. Final simplification77.4%

    \[\leadsto \frac{\frac{1}{c}}{x \cdot s} \cdot \frac{\frac{1}{c}}{x \cdot s} \]

Alternative 10: 55.5% accurate, 24.1× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \left(x \cdot x\right)\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 c) (* (* s s) (* x x)))))
x = abs(x);
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
	return 1.0 / ((c * c) * ((s * s) * (x * x)));
}
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 * c) * ((s * s) * (x * x)))
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 * c) * ((s * s) * (x * x)));
}
x = abs(x)
c = abs(c)
s = abs(s)
[c, s] = sort([c, s])
def code(x, c, s):
	return 1.0 / ((c * c) * ((s * s) * (x * x)))
x = abs(x)
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(s * s) * Float64(x * x))))
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 * c) * ((s * s) * (x * x)));
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[(1.0 / N[(N[(c * c), $MachinePrecision] * N[(N[(s * s), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \left(x \cdot x\right)\right)}
\end{array}
Derivation
  1. Initial program 63.4%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. associate-/r*95.8%

      \[\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)}} \]
    2. div-inv95.8%

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

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

    \[\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. Step-by-step derivation
    1. un-div-inv95.8%

      \[\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)}} \]
    2. associate-*r*93.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 78.7% accurate, 24.1× speedup?

\[\begin{array}{l} x = |x|\\ c = |c|\\ s = |s|\\ [c, s] = \mathsf{sort}([c, s])\\ \\ \frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\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)) (* x (* c 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)) * (x * (c * 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)) * (x * (c * 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)) * (x * (c * 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)) * (x * (c * s)))
x = abs(x)
c = abs(c)
s = abs(s)
c, s = sort([c, s])
function code(x, c, s)
	return Float64(1.0 / Float64(Float64(c * Float64(x * s)) * Float64(x * Float64(c * 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)) * (x * (c * 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[(1.0 / N[(N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}
\end{array}
Derivation
  1. Initial program 63.4%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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. Step-by-step derivation
    1. associate-/r*95.8%

      \[\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)}} \]
    2. div-inv95.8%

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

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

    \[\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. Step-by-step derivation
    1. clear-num95.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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