Average Error: 28.3 → 1.7
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 := \cos \left(2 \cdot x\right)\\ t_1 := \left|c \cdot \left(s \cdot x\right)\right|\\ t_2 := \frac{t_0}{t_1}\\ \mathbf{if}\;s \leq 1.716436258888434 \cdot 10^{-218}:\\ \;\;\;\;\frac{t_2}{t_1}\\ \mathbf{elif}\;s \leq 4.184106550672061 \cdot 10^{+200}:\\ \;\;\;\;\begin{array}{l} t_3 := \left|s \cdot \left(x \cdot c\right)\right|\\ \frac{1}{t_3} \cdot \frac{t_0}{t_3} \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \frac{1}{t_1}\\ \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)\\
t_1 := \left|c \cdot \left(s \cdot x\right)\right|\\
t_2 := \frac{t_0}{t_1}\\
\mathbf{if}\;s \leq 1.716436258888434 \cdot 10^{-218}:\\
\;\;\;\;\frac{t_2}{t_1}\\

\mathbf{elif}\;s \leq 4.184106550672061 \cdot 10^{+200}:\\
\;\;\;\;\begin{array}{l}
t_3 := \left|s \cdot \left(x \cdot c\right)\right|\\
\frac{1}{t_3} \cdot \frac{t_0}{t_3}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_2 \cdot \frac{1}{t_1}\\


\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))) (t_1 (fabs (* c (* s x)))) (t_2 (/ t_0 t_1)))
   (if (<= s 1.716436258888434e-218)
     (/ t_2 t_1)
     (if (<= s 4.184106550672061e+200)
       (let* ((t_3 (fabs (* s (* x c))))) (* (/ 1.0 t_3) (/ t_0 t_3)))
       (* t_2 (/ 1.0 t_1))))))
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 t_1 = fabs(c * (s * x));
	double t_2 = t_0 / t_1;
	double tmp;
	if (s <= 1.716436258888434e-218) {
		tmp = t_2 / t_1;
	} else if (s <= 4.184106550672061e+200) {
		double t_3 = fabs(s * (x * c));
		tmp = (1.0 / t_3) * (t_0 / t_3);
	} else {
		tmp = t_2 * (1.0 / t_1);
	}
	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 s < 1.716436258888434e-218

    1. Initial program 32.6

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6432.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)}} \]
    4. Simplified32.6

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left|x \cdot s\right| \cdot \color{blue}{\left|x \cdot s\right|}\right)} \]
    6. Using strategy rm
    7. Applied add-sqr-sqrt_binary6419.9

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

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

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

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

    if 1.716436258888434e-218 < s < 4.184106550672061e200

    1. Initial program 26.4

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6426.5

      \[\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)}} \]
    4. Simplified26.4

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left|c \cdot \left(x \cdot s\right)\right| \cdot \color{blue}{\left|c \cdot \left(x \cdot s\right)\right|}} \]
    10. Using strategy rm
    11. Applied *-un-lft-identity_binary642.4

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

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

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

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

    if 4.184106550672061e200 < s

    1. Initial program 26.8

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6426.8

      \[\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)}} \]
    4. Simplified26.8

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

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

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

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left|c \cdot \left(x \cdot s\right)\right| \cdot \color{blue}{\left|c \cdot \left(x \cdot s\right)\right|}} \]
    10. Using strategy rm
    11. Applied *-un-lft-identity_binary642.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 1.716436258888434 \cdot 10^{-218}:\\ \;\;\;\;\frac{\frac{\cos \left(2 \cdot x\right)}{\left|c \cdot \left(s \cdot x\right)\right|}}{\left|c \cdot \left(s \cdot x\right)\right|}\\ \mathbf{elif}\;s \leq 4.184106550672061 \cdot 10^{+200}:\\ \;\;\;\;\frac{1}{\left|s \cdot \left(x \cdot c\right)\right|} \cdot \frac{\cos \left(2 \cdot x\right)}{\left|s \cdot \left(x \cdot c\right)\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{\left|c \cdot \left(s \cdot x\right)\right|} \cdot \frac{1}{\left|c \cdot \left(s \cdot x\right)\right|}\\ \end{array} \]

Reproduce

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