Average Error: 28.3 → 2.3
Time: 7.6s
Precision: binary64
\[ \begin{array}{c}[c, s] = \mathsf{sort}([c, s])\\ \end{array} \]
\[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
\[\begin{array}{l} t_0 := \cos \left(x + x\right)\\ t_1 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;s \leq 7.796448576819047 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt[3]{{t_0}^{2}}}{t_1} \cdot {\left(\frac{s \cdot c}{\frac{\sqrt[3]{t_0}}{x}}\right)}^{-1}\\ \mathbf{elif}\;s \leq 4.318738514668659 \cdot 10^{+217}:\\ \;\;\;\;{\left(\sqrt[3]{t_0 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot {t_1}^{-2}\\ \end{array} \]
(FPCore (x c s)
 :precision binary64
 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
(FPCore (x c s)
 :precision binary64
 (let* ((t_0 (cos (+ x x))) (t_1 (* x (* s c))))
   (if (<= s 7.796448576819047e-90)
     (* (/ (cbrt (pow t_0 2.0)) t_1) (pow (/ (* s c) (/ (cbrt t_0) x)) -1.0))
     (if (<= s 4.318738514668659e+217)
       (pow (cbrt (* t_0 (pow (* s (* x c)) -2.0))) 3.0)
       (* t_0 (pow t_1 -2.0))))))
double code(double x, double c, double s) {
	return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
double code(double x, double c, double s) {
	double t_0 = cos((x + x));
	double t_1 = x * (s * c);
	double tmp;
	if (s <= 7.796448576819047e-90) {
		tmp = (cbrt(pow(t_0, 2.0)) / t_1) * pow(((s * c) / (cbrt(t_0) / x)), -1.0);
	} else if (s <= 4.318738514668659e+217) {
		tmp = pow(cbrt((t_0 * pow((s * (x * c)), -2.0))), 3.0);
	} else {
		tmp = t_0 * pow(t_1, -2.0);
	}
	return tmp;
}
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));
}
public static double code(double x, double c, double s) {
	double t_0 = Math.cos((x + x));
	double t_1 = x * (s * c);
	double tmp;
	if (s <= 7.796448576819047e-90) {
		tmp = (Math.cbrt(Math.pow(t_0, 2.0)) / t_1) * Math.pow(((s * c) / (Math.cbrt(t_0) / x)), -1.0);
	} else if (s <= 4.318738514668659e+217) {
		tmp = Math.pow(Math.cbrt((t_0 * Math.pow((s * (x * c)), -2.0))), 3.0);
	} else {
		tmp = t_0 * Math.pow(t_1, -2.0);
	}
	return tmp;
}
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 code(x, c, s)
	t_0 = cos(Float64(x + x))
	t_1 = Float64(x * Float64(s * c))
	tmp = 0.0
	if (s <= 7.796448576819047e-90)
		tmp = Float64(Float64(cbrt((t_0 ^ 2.0)) / t_1) * (Float64(Float64(s * c) / Float64(cbrt(t_0) / x)) ^ -1.0));
	elseif (s <= 4.318738514668659e+217)
		tmp = cbrt(Float64(t_0 * (Float64(s * Float64(x * c)) ^ -2.0))) ^ 3.0;
	else
		tmp = Float64(t_0 * (t_1 ^ -2.0));
	end
	return tmp
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]
code[x_, c_, s_] := Block[{t$95$0 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[s, 7.796448576819047e-90], N[(N[(N[Power[N[Power[t$95$0, 2.0], $MachinePrecision], 1/3], $MachinePrecision] / t$95$1), $MachinePrecision] * N[Power[N[(N[(s * c), $MachinePrecision] / N[(N[Power[t$95$0, 1/3], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[s, 4.318738514668659e+217], N[Power[N[Power[N[(t$95$0 * N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], N[(t$95$0 * N[Power[t$95$1, -2.0], $MachinePrecision]), $MachinePrecision]]]]]
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\begin{array}{l}
t_0 := \cos \left(x + x\right)\\
t_1 := x \cdot \left(s \cdot c\right)\\
\mathbf{if}\;s \leq 7.796448576819047 \cdot 10^{-90}:\\
\;\;\;\;\frac{\sqrt[3]{{t_0}^{2}}}{t_1} \cdot {\left(\frac{s \cdot c}{\frac{\sqrt[3]{t_0}}{x}}\right)}^{-1}\\

\mathbf{elif}\;s \leq 4.318738514668659 \cdot 10^{+217}:\\
\;\;\;\;{\left(\sqrt[3]{t_0 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}}\right)}^{3}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot {t_1}^{-2}\\


\end{array}

Error

Bits error versus x

Bits error versus c

Bits error versus s

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if s < 7.7964485768190474e-90

    1. Initial program 34.4

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Simplified3.7

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{{\cos \left(x + x\right)}^{2}}}{x \cdot \left(c \cdot s\right)} \cdot \frac{\sqrt[3]{\cos \left(x + x\right)}}{x \cdot \left(c \cdot s\right)}} \]
    4. Applied egg-rr3.6

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

    if 7.7964485768190474e-90 < s < 4.3187385146686588e217

    1. Initial program 24.4

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Simplified1.9

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos \left(x + x\right) \cdot {\left(x \cdot \left(c \cdot s\right)\right)}^{-2}}\right)}^{3}} \]
    4. Taylor expanded in x around inf 1.3

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

    if 4.3187385146686588e217 < s

    1. Initial program 25.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 7.796448576819047 \cdot 10^{-90}:\\ \;\;\;\;\frac{\sqrt[3]{{\cos \left(x + x\right)}^{2}}}{x \cdot \left(s \cdot c\right)} \cdot {\left(\frac{s \cdot c}{\frac{\sqrt[3]{\cos \left(x + x\right)}}{x}}\right)}^{-1}\\ \mathbf{elif}\;s \leq 4.318738514668659 \cdot 10^{+217}:\\ \;\;\;\;{\left(\sqrt[3]{\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(x + x\right) \cdot {\left(x \cdot \left(s \cdot c\right)\right)}^{-2}\\ \end{array} \]

Reproduce

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