Average Error: 28.5 → 2.6
Time: 12.3s
Precision: binary64
Cost: 7492
\[ \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 := x \cdot \left(s \cdot c\right)\\ t_1 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;c \leq -1 \cdot 10^{-247}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{t_1 \cdot t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x + x\right)}{t_0}}{t_0}\\ \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 (* x (* s c))) (t_1 (* c (* x s))))
   (if (<= c -1e-247)
     (/ (cos (* 2.0 x)) (* t_1 t_1))
     (/ (/ (cos (+ x x)) t_0) t_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 = x * (s * c);
	double t_1 = c * (x * s);
	double tmp;
	if (c <= -1e-247) {
		tmp = cos((2.0 * x)) / (t_1 * t_1);
	} else {
		tmp = (cos((x + x)) / t_0) / t_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) :: t_1
    real(8) :: tmp
    t_0 = x * (s * c)
    t_1 = c * (x * s)
    if (c <= (-1d-247)) then
        tmp = cos((2.0d0 * x)) / (t_1 * t_1)
    else
        tmp = (cos((x + x)) / t_0) / t_0
    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 = x * (s * c);
	double t_1 = c * (x * s);
	double tmp;
	if (c <= -1e-247) {
		tmp = Math.cos((2.0 * x)) / (t_1 * t_1);
	} else {
		tmp = (Math.cos((x + x)) / t_0) / t_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 = x * (s * c)
	t_1 = c * (x * s)
	tmp = 0
	if c <= -1e-247:
		tmp = math.cos((2.0 * x)) / (t_1 * t_1)
	else:
		tmp = (math.cos((x + x)) / t_0) / t_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 = Float64(x * Float64(s * c))
	t_1 = Float64(c * Float64(x * s))
	tmp = 0.0
	if (c <= -1e-247)
		tmp = Float64(cos(Float64(2.0 * x)) / Float64(t_1 * t_1));
	else
		tmp = Float64(Float64(cos(Float64(x + x)) / t_0) / t_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 = x * (s * c);
	t_1 = c * (x * s);
	tmp = 0.0;
	if (c <= -1e-247)
		tmp = cos((2.0 * x)) / (t_1 * t_1);
	else
		tmp = (cos((x + x)) / t_0) / t_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[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1e-247], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $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 := x \cdot \left(s \cdot c\right)\\
t_1 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;c \leq -1 \cdot 10^{-247}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{t_1 \cdot t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cos \left(x + x\right)}{t_0}}{t_0}\\


\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 < -1e-247

    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.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. Taylor expanded in x around 0 4.9

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

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(c \cdot x\right)\right) \cdot \color{blue}{\left(s \cdot \left(c \cdot x\right)\right)}} \]
    5. Taylor expanded in s around 0 4.2

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(c \cdot \left(s \cdot x\right)\right)} \cdot \left(s \cdot \left(c \cdot x\right)\right)} \]
    6. Taylor expanded in s around 0 2.5

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

    if -1e-247 < c

    1. Initial program 31.5

      \[\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. Taylor expanded in x around 0 5.9

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1 \cdot 10^{-247}:\\ \;\;\;\;\frac{\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cos \left(x + x\right)}{x \cdot \left(s \cdot c\right)}}{x \cdot \left(s \cdot c\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error6.3
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{\cos \left(x + x\right)}{c}}{\left(x \cdot s\right) \cdot \left(x \cdot \left(s \cdot c\right)\right)}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+30}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error6.3
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{\frac{\cos \left(x + x\right)}{x \cdot \left(s \cdot c\right)}}{x \cdot s}}{c}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+30}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error5.2
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{\frac{\cos \left(x + x\right)}{x \cdot \left(s \cdot c\right)}}{x \cdot c}}{s}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-19}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.3
Cost7624
\[\begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ t_1 := \frac{\frac{\cos \left(x + x\right)}{t_0}}{t_0}\\ \mathbf{if}\;x \leq -1 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-248}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error2.8
Cost7360
\[\begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ \frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0} \end{array} \]
Alternative 6
Error28.3
Cost832
\[\frac{\frac{1}{c \cdot c}}{x \cdot \left(s \cdot \left(x \cdot s\right)\right)} \]
Alternative 7
Error16.2
Cost832
\[\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)} \]

Error

Reproduce

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