Average Error: 27.5 → 9.2
Time: 10.1s
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 + x\right)\\ t_1 := \frac{t_0}{x}\\ t_2 := c \cdot \left(s \cdot \sqrt{x}\right)\\ t_3 := \sqrt{x \cdot c} \cdot s\\ t_4 := \frac{1}{t_3} \cdot \frac{\frac{t_1}{c}}{t_3}\\ \mathbf{if}\;x \leq -1.0834493324636061 \cdot 10^{+166}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -4.4043110447982947 \cdot 10^{+77}:\\ \;\;\;\;\frac{t_0}{c \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\frac{1}{x}}{c}\\ \mathbf{elif}\;x \leq -1.16732965885438 \cdot 10^{-309}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_1}{t_2}}{t_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
 (let* ((t_0 (cos (+ x x)))
        (t_1 (/ t_0 x))
        (t_2 (* c (* s (sqrt x))))
        (t_3 (* (sqrt (* x c)) s))
        (t_4 (* (/ 1.0 t_3) (/ (/ t_1 c) t_3))))
   (if (<= x -1.0834493324636061e+166)
     t_4
     (if (<= x -4.4043110447982947e+77)
       (* (/ t_0 (* c (* x (* s s)))) (/ (/ 1.0 x) c))
       (if (<= x -1.16732965885438e-309) t_4 (/ (/ t_1 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((x + x));
	double t_1 = t_0 / x;
	double t_2 = c * (s * sqrt(x));
	double t_3 = sqrt((x * c)) * s;
	double t_4 = (1.0 / t_3) * ((t_1 / c) / t_3);
	double tmp;
	if (x <= -1.0834493324636061e+166) {
		tmp = t_4;
	} else if (x <= -4.4043110447982947e+77) {
		tmp = (t_0 / (c * (x * (s * s)))) * ((1.0 / x) / c);
	} else if (x <= -1.16732965885438e-309) {
		tmp = t_4;
	} else {
		tmp = (t_1 / t_2) / t_2;
	}
	return tmp;
}
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
real(8) function code(x, c, s)
    real(8), intent (in) :: x
    real(8), intent (in) :: c
    real(8), intent (in) :: s
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: tmp
    t_0 = cos((x + x))
    t_1 = t_0 / x
    t_2 = c * (s * sqrt(x))
    t_3 = sqrt((x * c)) * s
    t_4 = (1.0d0 / t_3) * ((t_1 / c) / t_3)
    if (x <= (-1.0834493324636061d+166)) then
        tmp = t_4
    else if (x <= (-4.4043110447982947d+77)) then
        tmp = (t_0 / (c * (x * (s * s)))) * ((1.0d0 / x) / c)
    else if (x <= (-1.16732965885438d-309)) then
        tmp = t_4
    else
        tmp = (t_1 / t_2) / t_2
    end if
    code = tmp
end function
public static double code(double x, double c, double s) {
	return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
public static double code(double x, double c, double s) {
	double t_0 = Math.cos((x + x));
	double t_1 = t_0 / x;
	double t_2 = c * (s * Math.sqrt(x));
	double t_3 = Math.sqrt((x * c)) * s;
	double t_4 = (1.0 / t_3) * ((t_1 / c) / t_3);
	double tmp;
	if (x <= -1.0834493324636061e+166) {
		tmp = t_4;
	} else if (x <= -4.4043110447982947e+77) {
		tmp = (t_0 / (c * (x * (s * s)))) * ((1.0 / x) / c);
	} else if (x <= -1.16732965885438e-309) {
		tmp = t_4;
	} else {
		tmp = (t_1 / t_2) / t_2;
	}
	return tmp;
}
def code(x, c, s):
	return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
def code(x, c, s):
	t_0 = math.cos((x + x))
	t_1 = t_0 / x
	t_2 = c * (s * math.sqrt(x))
	t_3 = math.sqrt((x * c)) * s
	t_4 = (1.0 / t_3) * ((t_1 / c) / t_3)
	tmp = 0
	if x <= -1.0834493324636061e+166:
		tmp = t_4
	elif x <= -4.4043110447982947e+77:
		tmp = (t_0 / (c * (x * (s * s)))) * ((1.0 / x) / c)
	elif x <= -1.16732965885438e-309:
		tmp = t_4
	else:
		tmp = (t_1 / t_2) / t_2
	return tmp
function code(x, c, s)
	return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x)))
end
function code(x, c, s)
	t_0 = cos(Float64(x + x))
	t_1 = Float64(t_0 / x)
	t_2 = Float64(c * Float64(s * sqrt(x)))
	t_3 = Float64(sqrt(Float64(x * c)) * s)
	t_4 = Float64(Float64(1.0 / t_3) * Float64(Float64(t_1 / c) / t_3))
	tmp = 0.0
	if (x <= -1.0834493324636061e+166)
		tmp = t_4;
	elseif (x <= -4.4043110447982947e+77)
		tmp = Float64(Float64(t_0 / Float64(c * Float64(x * Float64(s * s)))) * Float64(Float64(1.0 / x) / c));
	elseif (x <= -1.16732965885438e-309)
		tmp = t_4;
	else
		tmp = Float64(Float64(t_1 / t_2) / t_2);
	end
	return tmp
end
function tmp = code(x, c, s)
	tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x));
end
function tmp_2 = code(x, c, s)
	t_0 = cos((x + x));
	t_1 = t_0 / x;
	t_2 = c * (s * sqrt(x));
	t_3 = sqrt((x * c)) * s;
	t_4 = (1.0 / t_3) * ((t_1 / c) / t_3);
	tmp = 0.0;
	if (x <= -1.0834493324636061e+166)
		tmp = t_4;
	elseif (x <= -4.4043110447982947e+77)
		tmp = (t_0 / (c * (x * (s * s)))) * ((1.0 / x) / c);
	elseif (x <= -1.16732965885438e-309)
		tmp = t_4;
	else
		tmp = (t_1 / t_2) / t_2;
	end
	tmp_2 = tmp;
end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, c_, s_] := Block[{t$95$0 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / x), $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(s * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Sqrt[N[(x * c), $MachinePrecision]], $MachinePrecision] * s), $MachinePrecision]}, Block[{t$95$4 = N[(N[(1.0 / t$95$3), $MachinePrecision] * N[(N[(t$95$1 / c), $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0834493324636061e+166], t$95$4, If[LessEqual[x, -4.4043110447982947e+77], N[(N[(t$95$0 / N[(c * N[(x * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.16732965885438e-309], t$95$4, N[(N[(t$95$1 / t$95$2), $MachinePrecision] / t$95$2), $MachinePrecision]]]]]]]]]
\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 + x\right)\\
t_1 := \frac{t_0}{x}\\
t_2 := c \cdot \left(s \cdot \sqrt{x}\right)\\
t_3 := \sqrt{x \cdot c} \cdot s\\
t_4 := \frac{1}{t_3} \cdot \frac{\frac{t_1}{c}}{t_3}\\
\mathbf{if}\;x \leq -1.0834493324636061 \cdot 10^{+166}:\\
\;\;\;\;t_4\\

\mathbf{elif}\;x \leq -4.4043110447982947 \cdot 10^{+77}:\\
\;\;\;\;\frac{t_0}{c \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\frac{1}{x}}{c}\\

\mathbf{elif}\;x \leq -1.16732965885438 \cdot 10^{-309}:\\
\;\;\;\;t_4\\

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


\end{array}

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 < -1.0834493324636061e166 or -4.40431104479829469e77 < x < -1.167329658854381e-309

    1. Initial program 28.9

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Applied egg-rr27.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-rr18.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. Applied egg-rr17.5

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

    if -1.0834493324636061e166 < x < -4.40431104479829469e77

    1. Initial program 22.3

      \[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
    2. Applied egg-rr22.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-rr15.5

      \[\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-rr15.5

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

    if -1.167329658854381e-309 < x

    1. Initial program 27.3

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

      \[\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-rr1.0

      \[\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 3 regimes into one program.
  4. Final simplification9.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0834493324636061 \cdot 10^{+166}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;x \leq -4.4043110447982947 \cdot 10^{+77}:\\ \;\;\;\;\frac{\cos \left(x + x\right)}{c \cdot \left(x \cdot \left(s \cdot s\right)\right)} \cdot \frac{\frac{1}{x}}{c}\\ \mathbf{elif}\;x \leq -1.16732965885438 \cdot 10^{-309}:\\ \;\;\;\;\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}\\ \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 2022134 
(FPCore (x c s)
  :name "mixedcos"
  :precision binary64
  (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))