Average Error: 28.3 → 1.6
Time: 19.9s
Precision: binary64
\[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\ \;\;\;\;\frac{\frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right|}}{\left|c \cdot \left(x \cdot s\right)\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{{\left(\left|x \cdot \left(c \cdot s\right)\right|\right)}^{2}}\\ \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}
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;\frac{\frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right|}}{\left|c \cdot \left(x \cdot s\right)\right|}\\

\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{{\left(\left|x \cdot \left(c \cdot s\right)\right|\right)}^{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
 (if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* x (* x (pow s 2.0))))) INFINITY)
   (/ (/ (cos (* 2.0 x)) (fabs (* s (* x c)))) (fabs (* c (* x s))))
   (/ (cos (* 2.0 x)) (pow (fabs (* x (* c s))) 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 tmp;
	if ((cos(2.0 * x) / (pow(c, 2.0) * (x * (x * pow(s, 2.0))))) <= ((double) INFINITY)) {
		tmp = (cos(2.0 * x) / fabs(s * (x * c))) / fabs(c * (x * s));
	} else {
		tmp = cos(2.0 * x) / pow(fabs(x * (c * s)), 2.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 2 regimes
  2. if (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x))) < +inf.0

    1. Initial program 18.4

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot s\right) \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot s\right)\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt_binary64_78214.5

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right| \cdot \color{blue}{\left|s \cdot \left(x \cdot c\right)\right|}}\]
    7. Using strategy rm
    8. Applied associate-/r*_binary64_7041.3

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right|}}{\left|s \cdot \left(x \cdot c\right)\right|}}\]
    9. Simplified1.3

      \[\leadsto \frac{\color{blue}{\frac{\cos \left(x \cdot 2\right)}{\left|s \cdot \left(x \cdot c\right)\right|}}}{\left|s \cdot \left(x \cdot c\right)\right|}\]
    10. Taylor expanded around 0 1.3

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

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

    if +inf.0 < (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x)))

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot s\right) \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot s\right)\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt_binary64_78221.7

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left|s \cdot \left(x \cdot c\right)\right|} \cdot \sqrt{\left(c \cdot s\right) \cdot \left(\left(x \cdot x\right) \cdot \left(c \cdot s\right)\right)}}\]
    6. Simplified6.5

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right| \cdot \color{blue}{\left|s \cdot \left(x \cdot c\right)\right|}}\]
    7. Taylor expanded around inf 6.5

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

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

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

Reproduce

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