Average Error: 28.7 → 2.1
Time: 11.6s
Precision: binary64
Cost: 7620
\[ \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)\\ t_1 := x \cdot \left(c \cdot s\right)\\ \mathbf{if}\;c \leq -5.621496803332658 \cdot 10^{+190}:\\ \;\;\;\;\frac{\frac{t_0}{t_1}}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_0}{x \cdot s}}{c} \cdot \frac{1}{c \cdot \left(x \cdot s\right)}\\ \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 (* x (* c s))))
   (if (<= c -5.621496803332658e+190)
     (/ (/ t_0 t_1) t_1)
     (* (/ (/ t_0 (* x s)) c) (/ 1.0 (* c (* x s)))))))
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 = x * (c * s);
	double tmp;
	if (c <= -5.621496803332658e+190) {
		tmp = (t_0 / t_1) / t_1;
	} else {
		tmp = ((t_0 / (x * s)) / c) * (1.0 / (c * (x * s)));
	}
	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 = x * (c * s)
    if (c <= (-5.621496803332658d+190)) then
        tmp = (t_0 / t_1) / t_1
    else
        tmp = ((t_0 / (x * s)) / c) * (1.0d0 / (c * (x * s)))
    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 = x * (c * s);
	double tmp;
	if (c <= -5.621496803332658e+190) {
		tmp = (t_0 / t_1) / t_1;
	} else {
		tmp = ((t_0 / (x * s)) / c) * (1.0 / (c * (x * s)));
	}
	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 = x * (c * s)
	tmp = 0
	if c <= -5.621496803332658e+190:
		tmp = (t_0 / t_1) / t_1
	else:
		tmp = ((t_0 / (x * s)) / c) * (1.0 / (c * (x * s)))
	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(x * Float64(c * s))
	tmp = 0.0
	if (c <= -5.621496803332658e+190)
		tmp = Float64(Float64(t_0 / t_1) / t_1);
	else
		tmp = Float64(Float64(Float64(t_0 / Float64(x * s)) / c) * Float64(1.0 / Float64(c * Float64(x * s))));
	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 = x * (c * s);
	tmp = 0.0;
	if (c <= -5.621496803332658e+190)
		tmp = (t_0 / t_1) / t_1;
	else
		tmp = ((t_0 / (x * s)) / c) * (1.0 / (c * (x * s)));
	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[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.621496803332658e+190], N[(N[(t$95$0 / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[(N[(t$95$0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] * N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $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)\\
t_1 := x \cdot \left(c \cdot s\right)\\
\mathbf{if}\;c \leq -5.621496803332658 \cdot 10^{+190}:\\
\;\;\;\;\frac{\frac{t_0}{t_1}}{t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t_0}{x \cdot s}}{c} \cdot \frac{1}{c \cdot \left(x \cdot s\right)}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if c < -5.6214968033326581e190

    1. Initial program 25.9

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

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

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

    if -5.6214968033326581e190 < c

    1. Initial program 29.7

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

      \[\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.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.621496803332658 \cdot 10^{+190}:\\ \;\;\;\;\frac{\frac{\cos \left(x + x\right)}{x \cdot \left(c \cdot s\right)}}{x \cdot \left(c \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x + x\right)}{x \cdot s}}{c} \cdot \frac{1}{c \cdot \left(x \cdot s\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error2.5
Cost7624
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ t_1 := \frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-200}:\\ \;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \left(\frac{1}{c} \cdot \left(-2 \cdot \frac{x}{s} + \frac{1}{x \cdot s}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.5
Cost7624
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{-242}:\\ \;\;\;\;\frac{\frac{\cos \left(x + x\right)}{t_0}}{t_0}\\ \mathbf{elif}\;x \leq 10^{-88}:\\ \;\;\;\;\frac{-1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \end{array} \]
Alternative 3
Error17.3
Cost1096
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ t_1 := \frac{1}{t_0 \cdot t_0}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-200}:\\ \;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c \cdot \left(x \cdot s\right)}}{c}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.2
Cost1096
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ t_1 := \frac{1}{t_0 \cdot t_0}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-242}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-200}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x}}{c \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error17.6
Cost1096
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ t_1 := \frac{1}{t_0 \cdot t_0}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-278}:\\ \;\;\;\;\frac{1}{s \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot x\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error17.2
Cost1028
\[\begin{array}{l} \mathbf{if}\;s \leq 10^{-90}:\\ \;\;\;\;\frac{1}{s \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(c \cdot x\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot \left(-s\right)\right)\right)}\\ \end{array} \]
Alternative 7
Error17.2
Cost832
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \]

Error

Reproduce

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