Average Error: 28.3 → 2.7
Time: 9.4s
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 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -7.468381497695001 \cdot 10^{+21}:\\ \;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \frac{\frac{t_0}{c}}{x \cdot s}\\ \mathbf{elif}\;x \leq -7.956937814384305 \cdot 10^{-263}:\\ \;\;\;\;\begin{array}{l} t_1 := s \cdot \left(x \cdot c\right)\\ \frac{1}{t_1} \cdot \frac{t_0}{t_1} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\cos x \cdot \cos x - \sin x \cdot \sin x}{c}}{x \cdot 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 \cdot 2\right)\\
\mathbf{if}\;x \leq -7.468381497695001 \cdot 10^{+21}:\\
\;\;\;\;\frac{\frac{1}{c}}{x \cdot s} \cdot \frac{\frac{t_0}{c}}{x \cdot s}\\

\mathbf{elif}\;x \leq -7.956937814384305 \cdot 10^{-263}:\\
\;\;\;\;\begin{array}{l}
t_1 := s \cdot \left(x \cdot c\right)\\
\frac{1}{t_1} \cdot \frac{t_0}{t_1}
\end{array}\\

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


\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 2.0))))
   (if (<= x -7.468381497695001e+21)
     (* (/ (/ 1.0 c) (* x s)) (/ (/ t_0 c) (* x s)))
     (if (<= x -7.956937814384305e-263)
       (let* ((t_1 (* s (* x c)))) (* (/ 1.0 t_1) (/ t_0 t_1)))
       (*
        (/ 1.0 (* c (* x s)))
        (/ (/ (- (* (cos x) (cos x)) (* (sin x) (sin x))) c) (* x s)))))))
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 * 2.0);
	double tmp;
	if (x <= -7.468381497695001e+21) {
		tmp = ((1.0 / c) / (x * s)) * ((t_0 / c) / (x * s));
	} else if (x <= -7.956937814384305e-263) {
		double t_1 = s * (x * c);
		tmp = (1.0 / t_1) * (t_0 / t_1);
	} else {
		tmp = (1.0 / (c * (x * s))) * ((((cos(x) * cos(x)) - (sin(x) * sin(x))) / c) / (x * s));
	}
	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 3 regimes
  2. if x < -7.4683814976950014e21

    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. Applied add-sqr-sqrt_binary6425.0

      \[\leadsto \frac{\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. Simplified28.5

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

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

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

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

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

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

    if -7.4683814976950014e21 < x < -7.95693781438430461e-263

    1. Initial program 33.1

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Applied add-sqr-sqrt_binary6433.1

      \[\leadsto \frac{\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. Simplified39.3

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

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

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

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

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

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

    if -7.95693781438430461e-263 < x

    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 add-sqr-sqrt_binary6428.5

      \[\leadsto \frac{\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. Simplified32.9

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

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

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

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

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

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

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

Reproduce

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