Average Error: 28.4 → 2.4
Time: 14.9s
Precision: binary64
Cost: 13704
\[\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 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;c \leq -1 \cdot 10^{-91}:\\ \;\;\;\;\frac{t_0}{t_1 \cdot t_1}\\ \mathbf{elif}\;c \leq 10^{-228}:\\ \;\;\;\;\cos \left(-2 \cdot x\right) \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{t_0}{x \cdot s}}{c}}{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 (+ x x))) (t_1 (* c (* x s))))
   (if (<= c -1e-91)
     (/ t_0 (* t_1 t_1))
     (if (<= c 1e-228)
       (* (cos (* -2.0 x)) (pow (* (* c s) x) -2.0))
       (/ (/ (/ t_0 (* x s)) c) 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((x + x));
	double t_1 = c * (x * s);
	double tmp;
	if (c <= -1e-91) {
		tmp = t_0 / (t_1 * t_1);
	} else if (c <= 1e-228) {
		tmp = cos((-2.0 * x)) * pow(((c * s) * x), -2.0);
	} else {
		tmp = ((t_0 / (x * s)) / c) / t_1;
	}
	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) :: tmp
    t_0 = cos((x + x))
    t_1 = c * (x * s)
    if (c <= (-1d-91)) then
        tmp = t_0 / (t_1 * t_1)
    else if (c <= 1d-228) then
        tmp = cos(((-2.0d0) * x)) * (((c * s) * x) ** (-2.0d0))
    else
        tmp = ((t_0 / (x * s)) / c) / t_1
    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 = c * (x * s);
	double tmp;
	if (c <= -1e-91) {
		tmp = t_0 / (t_1 * t_1);
	} else if (c <= 1e-228) {
		tmp = Math.cos((-2.0 * x)) * Math.pow(((c * s) * x), -2.0);
	} else {
		tmp = ((t_0 / (x * s)) / c) / t_1;
	}
	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 = c * (x * s)
	tmp = 0
	if c <= -1e-91:
		tmp = t_0 / (t_1 * t_1)
	elif c <= 1e-228:
		tmp = math.cos((-2.0 * x)) * math.pow(((c * s) * x), -2.0)
	else:
		tmp = ((t_0 / (x * s)) / c) / t_1
	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(c * Float64(x * s))
	tmp = 0.0
	if (c <= -1e-91)
		tmp = Float64(t_0 / Float64(t_1 * t_1));
	elseif (c <= 1e-228)
		tmp = Float64(cos(Float64(-2.0 * x)) * (Float64(Float64(c * s) * x) ^ -2.0));
	else
		tmp = Float64(Float64(Float64(t_0 / Float64(x * s)) / c) / t_1);
	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 = c * (x * s);
	tmp = 0.0;
	if (c <= -1e-91)
		tmp = t_0 / (t_1 * t_1);
	elseif (c <= 1e-228)
		tmp = cos((-2.0 * x)) * (((c * s) * x) ^ -2.0);
	else
		tmp = ((t_0 / (x * s)) / c) / t_1;
	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[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1e-91], N[(t$95$0 / N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1e-228], N[(N[Cos[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] * N[Power[N[(N[(c * s), $MachinePrecision] * x), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / t$95$1), $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 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;c \leq -1 \cdot 10^{-91}:\\
\;\;\;\;\frac{t_0}{t_1 \cdot t_1}\\

\mathbf{elif}\;c \leq 10^{-228}:\\
\;\;\;\;\cos \left(-2 \cdot x\right) \cdot {\left(\left(c \cdot s\right) \cdot x\right)}^{-2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{t_0}{x \cdot s}}{c}}{t_1}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if c < -1.00000000000000002e-91

    1. Initial program 21.5

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

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

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

    if -1.00000000000000002e-91 < c < 1.00000000000000003e-228

    1. Initial program 53.1

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

      \[\leadsto \color{blue}{\frac{\cos \left(x + x\right)}{\left(c \cdot c\right) \cdot \left(\left(x \cdot \left(s \cdot s\right)\right) \cdot x\right)}} \]
      Proof
    3. Taylor expanded in x around inf 54.7

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

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

    if 1.00000000000000003e-228 < c

    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. Simplified26.4

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

      \[\leadsto \frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}} \]
    4. Applied egg-rr1.8

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x + x\right)}{c \cdot \left(x \cdot s\right)}}{c \cdot \left(x \cdot s\right)}} \]
    5. Applied egg-rr1.9

      \[\leadsto \frac{\color{blue}{\frac{\frac{\cos \left(x + x\right)}{x \cdot s}}{c}}}{c \cdot \left(x \cdot s\right)} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error2.5
Cost13704
\[\begin{array}{l} t_0 := \cos \left(x + x\right)\\ t_1 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;c \leq -1 \cdot 10^{-86}:\\ \;\;\;\;\frac{t_0}{t_1 \cdot t_1}\\ \mathbf{elif}\;c \leq 10^{-228}:\\ \;\;\;\;\frac{t_0}{{\left(\left(c \cdot s\right) \cdot x\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{t_0}{x \cdot s}}{c}}{t_1}\\ \end{array} \]
Alternative 2
Error2.7
Cost13572
\[\begin{array}{l} \mathbf{if}\;s \leq 10^{-257}:\\ \;\;\;\;\frac{\frac{\frac{\cos \left(x + x\right)}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(-2 \cdot x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 3
Error2.7
Cost7360
\[\frac{\frac{\frac{\cos \left(x + x\right)}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)} \]
Alternative 4
Error2.6
Cost7360
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{\frac{\cos \left(x + x\right)}{t_0}}{t_0} \end{array} \]
Alternative 5
Error17.0
Cost6784
\[{\left(c \cdot \left(s \cdot x\right)\right)}^{-2} \]
Alternative 6
Error18.5
Cost1096
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;s \leq -1.3062042617860737 \cdot 10^{+215}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{s}}{x \cdot t_0}\\ \mathbf{elif}\;s \leq 4.224848830981019 \cdot 10^{+123}:\\ \;\;\;\;\frac{\frac{1}{c \cdot x}}{s \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot t_0}\\ \end{array} \]
Alternative 7
Error18.7
Cost1096
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;s \leq -5.0014805212985674 \cdot 10^{+187}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{\left(x \cdot s\right) \cdot \left(c \cdot x\right)}}{s}\\ \mathbf{elif}\;s \leq 4.224848830981019 \cdot 10^{+123}:\\ \;\;\;\;\frac{\frac{1}{c \cdot x}}{s \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot t_0}\\ \end{array} \]
Alternative 8
Error19.1
Cost832
\[\frac{\frac{\frac{1}{c \cdot \left(x \cdot s\right)}}{c}}{x \cdot s} \]
Alternative 9
Error18.4
Cost832
\[\frac{1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
Alternative 10
Error18.0
Cost832
\[\frac{\frac{1}{s \cdot \left(c \cdot x\right)}}{c \cdot \left(x \cdot s\right)} \]
Alternative 11
Error17.0
Cost832
\[\frac{\frac{1}{c \cdot \left(s \cdot x\right)}}{c \cdot \left(x \cdot s\right)} \]

Error

Reproduce

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