mixedcos

Percentage Accurate: 67.2% → 97.1%
Time: 15.7s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 67.2% accurate, 1.0× speedup?

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

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

Alternative 1: 97.1% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\left(-\cos \left(x \cdot 2\right)\right) \cdot -1}{\left(\left(c \cdot x\right) \cdot \left(-s\right)\right) \cdot \left(-\color{blue}{\left(c \cdot x\right) \cdot s}\right)} \]
    10. distribute-rgt-neg-in98.7%

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

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

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

Alternative 2: 93.4% accurate, 2.7× speedup?

\[\begin{array}{l} s_m = \left|s\right| \\ [x, c, s_m] = \mathsf{sort}([x, c, s_m])\\ \\ \frac{\frac{\cos \left(x \cdot 2\right)}{c}}{\left(x \cdot s_m\right) \cdot \left(c \cdot \left(x \cdot s_m\right)\right)} \end{array} \]
s_m = (fabs.f64 s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
 :precision binary64
 (/ (/ (cos (* x 2.0)) c) (* (* x s_m) (* c (* x s_m)))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
	return (cos((x * 2.0)) / c) / ((x * s_m) * (c * (x * s_m)));
}
s_m = abs(s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c, s_m)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s_m
    code = (cos((x * 2.0d0)) / c) / ((x * s_m) * (c * (x * s_m)))
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
	return (Math.cos((x * 2.0)) / c) / ((x * s_m) * (c * (x * s_m)));
}
s_m = math.fabs(s)
[x, c, s_m] = sort([x, c, s_m])
def code(x, c, s_m):
	return (math.cos((x * 2.0)) / c) / ((x * s_m) * (c * (x * s_m)))
s_m = abs(s)
x, c, s_m = sort([x, c, s_m])
function code(x, c, s_m)
	return Float64(Float64(cos(Float64(x * 2.0)) / c) / Float64(Float64(x * s_m) * Float64(c * Float64(x * s_m))))
end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
	tmp = (cos((x * 2.0)) / c) / ((x * s_m) * (c * (x * s_m)));
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision] / N[(N[(x * s$95$m), $MachinePrecision] * N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\frac{\frac{\cos \left(x \cdot 2\right)}{c}}{\left(x \cdot s_m\right) \cdot \left(c \cdot \left(x \cdot s_m\right)\right)}
\end{array}
Derivation
  1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 97.1% accurate, 2.7× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 4: 78.6% accurate, 18.3× speedup?

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

\mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\
\;\;\;\;\frac{\frac{-1}{c \cdot s_m}}{x \cdot \left(\left(x \cdot c\right) \cdot s_m\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 2.65e14

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x < 1.05e185

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e185 < x

    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. Taylor expanded in x around 0 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\ \;\;\;\;\frac{\frac{-1}{c \cdot s}}{x \cdot \left(\left(x \cdot c\right) \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\left(x \cdot c\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]

Alternative 5: 78.6% accurate, 18.3× speedup?

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

\mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\
\;\;\;\;\frac{\frac{-1}{c \cdot s_m}}{x \cdot \left(\left(x \cdot c\right) \cdot s_m\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 2.65e14

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x < 1.05e185

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e185 < x

    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. Taylor expanded in x around 0 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\ \;\;\;\;\frac{\frac{-1}{c \cdot s}}{x \cdot \left(\left(x \cdot c\right) \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s \cdot \left(\left(x \cdot c\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]

Alternative 6: 78.7% accurate, 18.3× speedup?

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

\mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\
\;\;\;\;\frac{\frac{-1}{c \cdot s_m}}{x \cdot t_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 2.65e14

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x < 1.05e185

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e185 < x

    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. Taylor expanded in x around 0 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\ \;\;\;\;\frac{\frac{-1}{c \cdot s}}{x \cdot \left(\left(x \cdot c\right) \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(x \cdot c\right) \cdot s}}{\left(x \cdot c\right) \cdot s}\\ \end{array} \]

Alternative 7: 78.7% accurate, 18.3× speedup?

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

\mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\
\;\;\;\;\frac{\frac{-1}{c \cdot s_m}}{x \cdot t_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 2.65e14

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x < 1.05e185

    1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e185 < x

    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. Taylor expanded in x around 0 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+185}:\\ \;\;\;\;\frac{\frac{-1}{c \cdot s}}{x \cdot \left(\left(x \cdot c\right) \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(x \cdot c\right) \cdot s}}{\left(x \cdot c\right) \cdot s}\\ \end{array} \]

Alternative 8: 78.9% accurate, 18.3× speedup?

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

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


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

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\color{blue}{\left(c \cdot s\right) \cdot x}} \cdot \frac{-1}{c \cdot \left(x \cdot s\right)} \]
      7. /-rgt-identity61.0%

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

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

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

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

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

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

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

Alternative 9: 78.9% accurate, 18.3× speedup?

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

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


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

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\color{blue}{\left(c \cdot s\right) \cdot x}} \cdot \frac{-1}{c \cdot \left(x \cdot s\right)} \]
      7. /-rgt-identity61.0%

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

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

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

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

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

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

Alternative 10: 78.9% accurate, 18.3× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{t_0}{\frac{-1}{t_0}}}\\


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

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{-1}{\left(c \cdot s\right) \cdot x} \cdot -1}{c \cdot \color{blue}{\left(x \cdot s\right)}} \]
      4. clear-num61.0%

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

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

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

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

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

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

Alternative 11: 78.8% accurate, 19.5× speedup?

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

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


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

    1. Initial program 72.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. *-un-lft-identity72.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.65e14 < x

    1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 75.5% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 78.4% accurate, 24.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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