Average Error: 28.5 → 2.4
Time: 14.6s
Precision: binary64
Cost: 7752
\[ \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 := s \cdot \left(c \cdot x\right)\\ t_1 := \cos \left(x + x\right)\\ t_2 := c \cdot \left(x \cdot s\right)\\ t_3 := \frac{\frac{t_1}{t_2}}{t_2}\\ \mathbf{if}\;c \leq -90000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-240}:\\ \;\;\;\;\frac{1}{t_0} \cdot \frac{t_1}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \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 (* s (* c x)))
        (t_1 (cos (+ x x)))
        (t_2 (* c (* x s)))
        (t_3 (/ (/ t_1 t_2) t_2)))
   (if (<= c -90000.0)
     t_3
     (if (<= c 1.25e-240) (* (/ 1.0 t_0) (/ t_1 t_0)) t_3))))
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 = s * (c * x);
	double t_1 = cos((x + x));
	double t_2 = c * (x * s);
	double t_3 = (t_1 / t_2) / t_2;
	double tmp;
	if (c <= -90000.0) {
		tmp = t_3;
	} else if (c <= 1.25e-240) {
		tmp = (1.0 / t_0) * (t_1 / t_0);
	} else {
		tmp = t_3;
	}
	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) :: tmp
    t_0 = s * (c * x)
    t_1 = cos((x + x))
    t_2 = c * (x * s)
    t_3 = (t_1 / t_2) / t_2
    if (c <= (-90000.0d0)) then
        tmp = t_3
    else if (c <= 1.25d-240) then
        tmp = (1.0d0 / t_0) * (t_1 / t_0)
    else
        tmp = t_3
    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 = s * (c * x);
	double t_1 = Math.cos((x + x));
	double t_2 = c * (x * s);
	double t_3 = (t_1 / t_2) / t_2;
	double tmp;
	if (c <= -90000.0) {
		tmp = t_3;
	} else if (c <= 1.25e-240) {
		tmp = (1.0 / t_0) * (t_1 / t_0);
	} else {
		tmp = t_3;
	}
	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 = s * (c * x)
	t_1 = math.cos((x + x))
	t_2 = c * (x * s)
	t_3 = (t_1 / t_2) / t_2
	tmp = 0
	if c <= -90000.0:
		tmp = t_3
	elif c <= 1.25e-240:
		tmp = (1.0 / t_0) * (t_1 / t_0)
	else:
		tmp = t_3
	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(s * Float64(c * x))
	t_1 = cos(Float64(x + x))
	t_2 = Float64(c * Float64(x * s))
	t_3 = Float64(Float64(t_1 / t_2) / t_2)
	tmp = 0.0
	if (c <= -90000.0)
		tmp = t_3;
	elseif (c <= 1.25e-240)
		tmp = Float64(Float64(1.0 / t_0) * Float64(t_1 / t_0));
	else
		tmp = t_3;
	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 = s * (c * x);
	t_1 = cos((x + x));
	t_2 = c * (x * s);
	t_3 = (t_1 / t_2) / t_2;
	tmp = 0.0;
	if (c <= -90000.0)
		tmp = t_3;
	elseif (c <= 1.25e-240)
		tmp = (1.0 / t_0) * (t_1 / t_0);
	else
		tmp = t_3;
	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[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$1 / t$95$2), $MachinePrecision] / t$95$2), $MachinePrecision]}, If[LessEqual[c, -90000.0], t$95$3, If[LessEqual[c, 1.25e-240], N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\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 := s \cdot \left(c \cdot x\right)\\
t_1 := \cos \left(x + x\right)\\
t_2 := c \cdot \left(x \cdot s\right)\\
t_3 := \frac{\frac{t_1}{t_2}}{t_2}\\
\mathbf{if}\;c \leq -90000:\\
\;\;\;\;t_3\\

\mathbf{elif}\;c \leq 1.25 \cdot 10^{-240}:\\
\;\;\;\;\frac{1}{t_0} \cdot \frac{t_1}{t_0}\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\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 < -9e4 or 1.2500000000000001e-240 < c

    1. Initial program 24.6

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot s\right)\right)\right)}} \]
      Proof
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 (*.f64 c c) (*.f64 x (*.f64 s s))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 (*.f64 c c) (*.f64 x (Rewrite<= unpow2_binary64 (pow.f64 s 2)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) (*.f64 x (pow.f64 s 2))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 (pow.f64 c 2) (*.f64 x (pow.f64 s 2))) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (Rewrite<= associate-*r*_binary64 (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x)))): 17 points increase in error, 7 points decrease in error
    3. Applied egg-rr32.7

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

      \[\leadsto \color{blue}{\frac{\frac{\cos \left(x + x\right)}{c \cdot \left(s \cdot x\right)}}{c \cdot \left(s \cdot x\right)}} \]
      Proof
      (/.f64 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 c (*.f64 s x))) (*.f64 c (*.f64 s x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 c (*.f64 s (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 x) (sqrt.f64 x)))))) (*.f64 c (*.f64 s x))): 143 points increase in error, 10 points decrease in error
      (/.f64 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 c (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 s (sqrt.f64 x)) (sqrt.f64 x))))) (*.f64 c (*.f64 s x))): 8 points increase in error, 12 points decrease in error
      (/.f64 (/.f64 (cos.f64 (+.f64 x x)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x)))) (*.f64 c (*.f64 s x))): 9 points increase in error, 10 points decrease in error
      (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x))))) (*.f64 c (*.f64 s x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 1 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x)))) (*.f64 c (*.f64 s (Rewrite<= rem-square-sqrt_binary64 (*.f64 (sqrt.f64 x) (sqrt.f64 x)))))): 20 points increase in error, 1 points decrease in error
      (/.f64 (*.f64 1 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x)))) (*.f64 c (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 s (sqrt.f64 x)) (sqrt.f64 x))))): 8 points increase in error, 10 points decrease in error
      (/.f64 (*.f64 1 (/.f64 (cos.f64 (+.f64 x x)) (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x)))) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x)))): 16 points increase in error, 11 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x))) (/.f64 (cos.f64 (+.f64 x x)) (*.f64 (*.f64 c (*.f64 s (sqrt.f64 x))) (sqrt.f64 x))))): 13 points increase in error, 7 points decrease in error

    if -9e4 < c < 1.2500000000000001e-240

    1. Initial program 40.6

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

      \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}} \]
      Proof
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 x (*.f64 (*.f64 c s) (*.f64 c s))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 x (Rewrite<= unswap-sqr_binary64 (*.f64 (*.f64 c c) (*.f64 s s)))))): 64 points increase in error, 6 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 x (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c 2)) (*.f64 s s))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 x (*.f64 (pow.f64 c 2) (Rewrite<= unpow2_binary64 (pow.f64 s 2)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (*.f64 x (Rewrite=> *-commutative_binary64 (*.f64 (pow.f64 s 2) (pow.f64 c 2)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x (pow.f64 s 2)) (pow.f64 c 2))))): 10 points increase in error, 12 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (pow.f64 c 2) (*.f64 x (pow.f64 s 2)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 (pow.f64 c 2) (*.f64 x (pow.f64 s 2))) x))): 0 points increase in error, 0 points decrease in error
      (/.f64 (cos.f64 (*.f64 2 x)) (Rewrite<= associate-*r*_binary64 (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x)))): 17 points increase in error, 7 points decrease in error
    3. Applied egg-rr3.7

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

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

Alternatives

Alternative 1
Error2.1
Cost20036
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ t_1 := \cos \left(x + x\right)\\ \mathbf{if}\;{c}^{2} \leq 0:\\ \;\;\;\;\frac{t_1}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_1}{t_0}}{t_0}\\ \end{array} \]
Alternative 2
Error9.9
Cost8284
\[\begin{array}{l} t_0 := c \cdot \left(c \cdot x\right)\\ t_1 := \cos \left(2 \cdot x\right)\\ t_2 := \frac{t_1}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}\\ t_3 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;s \leq -2.6 \cdot 10^{-87}:\\ \;\;\;\;\frac{\frac{-1}{s \cdot \left(c \cdot x\right)}}{s \cdot \left(c \cdot \left(-x\right)\right)}\\ \mathbf{elif}\;s \leq 2.7 \cdot 10^{-174}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;s \leq 2.3 \cdot 10^{-124}:\\ \;\;\;\;\frac{t_1}{\left(s \cdot \left(x \cdot s\right)\right) \cdot t_0}\\ \mathbf{elif}\;s \leq 2.15 \cdot 10^{-69}:\\ \;\;\;\;\frac{t_1}{c \cdot \left(c \cdot \left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right)\right)}\\ \mathbf{elif}\;s \leq 1.7 \cdot 10^{+112}:\\ \;\;\;\;\frac{t_1}{x \cdot \left(\left(s \cdot s\right) \cdot t_0\right)}\\ \mathbf{elif}\;s \leq 2.1 \cdot 10^{+124}:\\ \;\;\;\;\frac{1}{s \cdot \left(t_3 \cdot \left(c \cdot x\right)\right)}\\ \mathbf{elif}\;s \leq 4.8 \cdot 10^{+207}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{t_3}\\ \end{array} \]
Alternative 3
Error14.5
Cost7756
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ t_1 := \frac{\cos \left(2 \cdot x\right)}{c \cdot \left(c \cdot \left(x \cdot \left(x \cdot \left(s \cdot s\right)\right)\right)\right)}\\ t_2 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;x \leq -0.000185:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{-25}:\\ \;\;\;\;\frac{t_0}{t_2}\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+169}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left|t_0\right|}{t_2}\\ \end{array} \]
Alternative 4
Error8.3
Cost7624
\[\begin{array}{l} t_0 := \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{if}\;x \leq -5.5 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error2.7
Cost7624
\[\begin{array}{l} t_0 := s \cdot \left(c \cdot x\right)\\ t_1 := \frac{\cos \left(x + x\right)}{t_0 \cdot t_0}\\ \mathbf{if}\;x \leq -3.4 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{-8}:\\ \;\;\;\;\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.6
Cost7624
\[\begin{array}{l} t_0 := s \cdot \left(c \cdot x\right)\\ t_1 := \cos \left(x + x\right)\\ t_2 := c \cdot \left(x \cdot s\right)\\ t_3 := \frac{\frac{t_1}{t_2}}{t_2}\\ \mathbf{if}\;c \leq -1.45 \cdot 10^{+97}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{-242}:\\ \;\;\;\;\frac{t_1}{t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error19.2
Cost1096
\[\begin{array}{l} t_0 := \frac{1}{s \cdot \left(\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot x\right)\right)}\\ \mathbf{if}\;s \leq 1.12 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;s \leq 7 \cdot 10^{+256}:\\ \;\;\;\;\frac{1}{c \cdot \left(c \cdot \left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error22.9
Cost832
\[\frac{1}{c \cdot \left(c \cdot \left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)\right)} \]
Alternative 9
Error17.0
Cost832
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \]
Alternative 10
Error16.9
Cost832
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{\frac{1}{t_0}}{t_0} \end{array} \]
Alternative 11
Error16.9
Cost832
\[\frac{\frac{\frac{1}{c}}{x \cdot s}}{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))))