Average Error: 28.5 → 0.7
Time: 7.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} t_0 := \cos \left(2 \cdot x\right)\\ \mathbf{if}\;\frac{t_0}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\ \;\;\;\;\begin{array}{l} t_1 := c \cdot \left|x \cdot s\right|\\ \frac{\frac{t_0}{t_1}}{t_1} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \left(c \cdot \left|s\right|\right) \cdot \left|x\right|\\ \frac{\frac{t_0}{t_2}}{t_2} \end{array}\\ \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(2 \cdot x\right)\\
\mathbf{if}\;\frac{t_0}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;\begin{array}{l}
t_1 := c \cdot \left|x \cdot s\right|\\
\frac{\frac{t_0}{t_1}}{t_1}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \left(c \cdot \left|s\right|\right) \cdot \left|x\right|\\
\frac{\frac{t_0}{t_2}}{t_2}
\end{array}\\


\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 (* 2.0 x))))
   (if (<= (/ t_0 (* (pow c 2.0) (* x (* x (pow s 2.0))))) INFINITY)
     (let* ((t_1 (* c (fabs (* x s))))) (/ (/ t_0 t_1) t_1))
     (let* ((t_2 (* (* c (fabs s)) (fabs x)))) (/ (/ t_0 t_2) t_2)))))
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(2.0 * x);
	double tmp;
	if ((t_0 / (pow(c, 2.0) * (x * (x * pow(s, 2.0))))) <= ((double) INFINITY)) {
		double t_1_1 = c * fabs(x * s);
		tmp = (t_0 / t_1_1) / t_1_1;
	} else {
		double t_2 = (c * fabs(s)) * fabs(x);
		tmp = (t_0 / t_2) / t_2;
	}
	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.6

      \[\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_binary6418.6

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left|s \cdot x\right| \cdot \color{blue}{\left|s \cdot x\right|}\right)} \]
    5. Applied pow2_binary649.9

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{{\left(\left|s \cdot x\right|\right)}^{2}}} \]
    6. Applied pow-prod-down_binary640.6

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot \left|s \cdot x\right|\right)}^{2}}} \]
    7. Applied unpow2_binary640.6

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(2 \cdot x\right)}{c \cdot \left|s \cdot x\right|}}{c \cdot \left|s \cdot x\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. Applied add-sqr-sqrt_binary6464.0

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{{\left(\left|s \cdot x\right|\right)}^{2}}} \]
    6. Applied pow-prod-down_binary6410.8

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

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

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

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

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

    \[\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)}{c \cdot \left|x \cdot s\right|}}{c \cdot \left|x \cdot s\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(2 \cdot x\right)}{\left(c \cdot \left|s\right|\right) \cdot \left|x\right|}}{\left(c \cdot \left|s\right|\right) \cdot \left|x\right|}\\ \end{array} \]

Reproduce

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