Average Error: 28.2 → 1.8
Time: 6.7s
Precision: binary64
\[ \begin{array}{c}[c, s] = \mathsf{sort}([c, 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 + x\right)\\ \mathbf{if}\;s \leq 1.85 \cdot 10^{-243}:\\ \;\;\;\;\left({\cos x}^{2} - {\sin x}^{2}\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\ \mathbf{elif}\;s \leq 2.55 \cdot 10^{+185}:\\ \;\;\;\;t_0 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot {\left(x \cdot \left(s \cdot c\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
 (let* ((t_0 (cos (+ x x))))
   (if (<= s 1.85e-243)
     (* (- (pow (cos x) 2.0) (pow (sin x) 2.0)) (pow (* c (* s x)) -2.0))
     (if (<= s 2.55e+185)
       (* t_0 (pow (* s (* x c)) -2.0))
       (* t_0 (pow (* x (* s c)) -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 t_0 = cos((x + x));
	double tmp;
	if (s <= 1.85e-243) {
		tmp = (pow(cos(x), 2.0) - pow(sin(x), 2.0)) * pow((c * (s * x)), -2.0);
	} else if (s <= 2.55e+185) {
		tmp = t_0 * pow((s * (x * c)), -2.0);
	} else {
		tmp = t_0 * pow((x * (s * c)), -2.0);
	}
	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) :: tmp
    t_0 = cos((x + x))
    if (s <= 1.85d-243) then
        tmp = ((cos(x) ** 2.0d0) - (sin(x) ** 2.0d0)) * ((c * (s * x)) ** (-2.0d0))
    else if (s <= 2.55d+185) then
        tmp = t_0 * ((s * (x * c)) ** (-2.0d0))
    else
        tmp = t_0 * ((x * (s * c)) ** (-2.0d0))
    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 tmp;
	if (s <= 1.85e-243) {
		tmp = (Math.pow(Math.cos(x), 2.0) - Math.pow(Math.sin(x), 2.0)) * Math.pow((c * (s * x)), -2.0);
	} else if (s <= 2.55e+185) {
		tmp = t_0 * Math.pow((s * (x * c)), -2.0);
	} else {
		tmp = t_0 * Math.pow((x * (s * c)), -2.0);
	}
	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))
	tmp = 0
	if s <= 1.85e-243:
		tmp = (math.pow(math.cos(x), 2.0) - math.pow(math.sin(x), 2.0)) * math.pow((c * (s * x)), -2.0)
	elif s <= 2.55e+185:
		tmp = t_0 * math.pow((s * (x * c)), -2.0)
	else:
		tmp = t_0 * math.pow((x * (s * c)), -2.0)
	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))
	tmp = 0.0
	if (s <= 1.85e-243)
		tmp = Float64(Float64((cos(x) ^ 2.0) - (sin(x) ^ 2.0)) * (Float64(c * Float64(s * x)) ^ -2.0));
	elseif (s <= 2.55e+185)
		tmp = Float64(t_0 * (Float64(s * Float64(x * c)) ^ -2.0));
	else
		tmp = Float64(t_0 * (Float64(x * Float64(s * c)) ^ -2.0));
	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));
	tmp = 0.0;
	if (s <= 1.85e-243)
		tmp = ((cos(x) ^ 2.0) - (sin(x) ^ 2.0)) * ((c * (s * x)) ^ -2.0);
	elseif (s <= 2.55e+185)
		tmp = t_0 * ((s * (x * c)) ^ -2.0);
	else
		tmp = t_0 * ((x * (s * c)) ^ -2.0);
	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]}, If[LessEqual[s, 1.85e-243], N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[(c * N[(s * x), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[s, 2.55e+185], N[(t$95$0 * N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $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)\\
\mathbf{if}\;s \leq 1.85 \cdot 10^{-243}:\\
\;\;\;\;\left({\cos x}^{2} - {\sin x}^{2}\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\

\mathbf{elif}\;s \leq 2.55 \cdot 10^{+185}:\\
\;\;\;\;t_0 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot {\left(x \cdot \left(s \cdot c\right)\right)}^{-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 s < 1.85e-243

    1. Initial program 31.0

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
    3. Applied egg-rr2.7

      \[\leadsto \color{blue}{\cos \left(x + x\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
    4. Applied egg-rr2.7

      \[\leadsto \color{blue}{\left({\cos x}^{2} + \left(-{\sin x}^{2}\right)\right)} \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2} \]

    if 1.85e-243 < s < 2.54999999999999998e185

    1. Initial program 27.4

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
    3. Applied egg-rr2.4

      \[\leadsto \color{blue}{\cos \left(x + x\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
    4. Taylor expanded in c around 0 1.0

      \[\leadsto \cos \left(x + x\right) \cdot {\color{blue}{\left(s \cdot \left(c \cdot x\right)\right)}}^{-2} \]

    if 2.54999999999999998e185 < s

    1. Initial program 26.3

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}} \]
    3. Applied egg-rr2.9

      \[\leadsto \color{blue}{\cos \left(x + x\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}} \]
    4. Applied egg-rr2.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 1.85 \cdot 10^{-243}:\\ \;\;\;\;\left({\cos x}^{2} - {\sin x}^{2}\right) \cdot {\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\ \mathbf{elif}\;s \leq 2.55 \cdot 10^{+185}:\\ \;\;\;\;\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(x + x\right) \cdot {\left(x \cdot \left(s \cdot c\right)\right)}^{-2}\\ \end{array} \]

Reproduce

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