Average Error: 28.8 → 8.2
Time: 9.5s
Precision: binary64
\[[c, s] = \mathsf{sort}([c, s]) \\]
\[\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 := c \cdot \left(s \cdot \sqrt{x}\right)\\ t_1 := {s}^{2} \cdot \left(x \cdot c\right)\\ t_2 := \frac{\cos \left(x + x\right)}{x}\\ t_3 := \frac{t_2}{c}\\ t_4 := \sqrt[3]{t_3}\\ t_5 := s \cdot \sqrt{x \cdot c}\\ \mathbf{if}\;x \leq -8.754996079145237 \cdot 10^{+225}:\\ \;\;\;\;\frac{t_3}{t_1}\\ \mathbf{elif}\;x \leq -4.4022230997663105 \cdot 10^{+185}:\\ \;\;\;\;\frac{{t_4}^{2}}{t_5} \cdot \frac{t_4}{t_5}\\ \mathbf{elif}\;x \leq -71415521545202600:\\ \;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot c}}{t_1}\\ \mathbf{elif}\;x \leq -4.366774230335914 \cdot 10^{-309}:\\ \;\;\;\;\frac{1}{t_5} \cdot \frac{t_3}{t_5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_2}{t_0}}{t_0}\\ \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 := c \cdot \left(s \cdot \sqrt{x}\right)\\
t_1 := {s}^{2} \cdot \left(x \cdot c\right)\\
t_2 := \frac{\cos \left(x + x\right)}{x}\\
t_3 := \frac{t_2}{c}\\
t_4 := \sqrt[3]{t_3}\\
t_5 := s \cdot \sqrt{x \cdot c}\\
\mathbf{if}\;x \leq -8.754996079145237 \cdot 10^{+225}:\\
\;\;\;\;\frac{t_3}{t_1}\\

\mathbf{elif}\;x \leq -4.4022230997663105 \cdot 10^{+185}:\\
\;\;\;\;\frac{{t_4}^{2}}{t_5} \cdot \frac{t_4}{t_5}\\

\mathbf{elif}\;x \leq -71415521545202600:\\
\;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot c}}{t_1}\\

\mathbf{elif}\;x \leq -4.366774230335914 \cdot 10^{-309}:\\
\;\;\;\;\frac{1}{t_5} \cdot \frac{t_3}{t_5}\\

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


\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 (* c (* s (sqrt x))))
        (t_1 (* (pow s 2.0) (* x c)))
        (t_2 (/ (cos (+ x x)) x))
        (t_3 (/ t_2 c))
        (t_4 (cbrt t_3))
        (t_5 (* s (sqrt (* x c)))))
   (if (<= x -8.754996079145237e+225)
     (/ t_3 t_1)
     (if (<= x -4.4022230997663105e+185)
       (* (/ (pow t_4 2.0) t_5) (/ t_4 t_5))
       (if (<= x -71415521545202600.0)
         (/ (/ (cos (* x 2.0)) (* x c)) t_1)
         (if (<= x -4.366774230335914e-309)
           (* (/ 1.0 t_5) (/ t_3 t_5))
           (/ (/ t_2 t_0) t_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 = c * (s * sqrt(x));
	double t_1 = pow(s, 2.0) * (x * c);
	double t_2 = cos((x + x)) / x;
	double t_3 = t_2 / c;
	double t_4 = cbrt(t_3);
	double t_5 = s * sqrt((x * c));
	double tmp;
	if (x <= -8.754996079145237e+225) {
		tmp = t_3 / t_1;
	} else if (x <= -4.4022230997663105e+185) {
		tmp = (pow(t_4, 2.0) / t_5) * (t_4 / t_5);
	} else if (x <= -71415521545202600.0) {
		tmp = (cos((x * 2.0)) / (x * c)) / t_1;
	} else if (x <= -4.366774230335914e-309) {
		tmp = (1.0 / t_5) * (t_3 / t_5);
	} else {
		tmp = (t_2 / t_0) / t_0;
	}
	return tmp;
}

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 5 regimes
  2. if x < -8.75499607914523745e225

    1. Initial program 28.6

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

      \[\leadsto \color{blue}{\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\cos \left(x + x\right)}{x}} \]
    3. Applied egg-rr16.9

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

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

    if -8.75499607914523745e225 < x < -4.40222309976631051e185

    1. Initial program 28.5

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

      \[\leadsto \color{blue}{\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\cos \left(x + x\right)}{x}} \]
    3. Applied egg-rr17.3

      \[\leadsto \color{blue}{\frac{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}{c \cdot \left(x \cdot \left(s \cdot s\right)\right)}} \]
    4. Applied egg-rr16.7

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

    if -4.40222309976631051e185 < x < -71415521545202600

    1. Initial program 23.6

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

      \[\leadsto \color{blue}{\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\cos \left(x + x\right)}{x}} \]
    3. Applied egg-rr15.8

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

      \[\leadsto \frac{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}{\color{blue}{{s}^{2} \cdot \left(c \cdot x\right)}} \]
    5. Taylor expanded in x around inf 13.6

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

    if -71415521545202600 < x < -4.3667742303359139e-309

    1. Initial program 33.4

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

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

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

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

    if -4.3667742303359139e-309 < x

    1. Initial program 28.6

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

      \[\leadsto \color{blue}{\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\cos \left(x + x\right)}{x}} \]
    3. Applied egg-rr0.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.754996079145237 \cdot 10^{+225}:\\ \;\;\;\;\frac{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}{{s}^{2} \cdot \left(x \cdot c\right)}\\ \mathbf{elif}\;x \leq -4.4022230997663105 \cdot 10^{+185}:\\ \;\;\;\;\frac{{\left(\sqrt[3]{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}\right)}^{2}}{s \cdot \sqrt{x \cdot c}} \cdot \frac{\sqrt[3]{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}}{s \cdot \sqrt{x \cdot c}}\\ \mathbf{elif}\;x \leq -71415521545202600:\\ \;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot c}}{{s}^{2} \cdot \left(x \cdot c\right)}\\ \mathbf{elif}\;x \leq -4.366774230335914 \cdot 10^{-309}:\\ \;\;\;\;\frac{1}{s \cdot \sqrt{x \cdot c}} \cdot \frac{\frac{\frac{\cos \left(x + x\right)}{x}}{c}}{s \cdot \sqrt{x \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{\cos \left(x + x\right)}{x}}{c \cdot \left(s \cdot \sqrt{x}\right)}}{c \cdot \left(s \cdot \sqrt{x}\right)}\\ \end{array} \]

Reproduce

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