?

Average Error: 28.1 → 3.6
Time: 14.1s
Precision: binary64
Cost: 7624

?

\[ \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 := \frac{1}{x \cdot \left(c \cdot s\right)}\\ t_1 := \cos \left(x \cdot 2\right)\\ t_2 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;x \leq -9 \cdot 10^{-16}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot t_2}\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-57}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot \left(s \cdot \left(x \cdot c\right)\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 (/ 1.0 (* x (* c s)))) (t_1 (cos (* x 2.0))) (t_2 (* c (* x s))))
   (if (<= x -9e-16)
     (/ t_1 (* t_2 t_2))
     (if (<= x 2e-57) (* t_0 t_0) (/ t_1 (* t_2 (* s (* x c))))))))
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 = 1.0 / (x * (c * s));
	double t_1 = cos((x * 2.0));
	double t_2 = c * (x * s);
	double tmp;
	if (x <= -9e-16) {
		tmp = t_1 / (t_2 * t_2);
	} else if (x <= 2e-57) {
		tmp = t_0 * t_0;
	} else {
		tmp = t_1 / (t_2 * (s * (x * c)));
	}
	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) :: tmp
    t_0 = 1.0d0 / (x * (c * s))
    t_1 = cos((x * 2.0d0))
    t_2 = c * (x * s)
    if (x <= (-9d-16)) then
        tmp = t_1 / (t_2 * t_2)
    else if (x <= 2d-57) then
        tmp = t_0 * t_0
    else
        tmp = t_1 / (t_2 * (s * (x * c)))
    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 = 1.0 / (x * (c * s));
	double t_1 = Math.cos((x * 2.0));
	double t_2 = c * (x * s);
	double tmp;
	if (x <= -9e-16) {
		tmp = t_1 / (t_2 * t_2);
	} else if (x <= 2e-57) {
		tmp = t_0 * t_0;
	} else {
		tmp = t_1 / (t_2 * (s * (x * c)));
	}
	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 = 1.0 / (x * (c * s))
	t_1 = math.cos((x * 2.0))
	t_2 = c * (x * s)
	tmp = 0
	if x <= -9e-16:
		tmp = t_1 / (t_2 * t_2)
	elif x <= 2e-57:
		tmp = t_0 * t_0
	else:
		tmp = t_1 / (t_2 * (s * (x * c)))
	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(1.0 / Float64(x * Float64(c * s)))
	t_1 = cos(Float64(x * 2.0))
	t_2 = Float64(c * Float64(x * s))
	tmp = 0.0
	if (x <= -9e-16)
		tmp = Float64(t_1 / Float64(t_2 * t_2));
	elseif (x <= 2e-57)
		tmp = Float64(t_0 * t_0);
	else
		tmp = Float64(t_1 / Float64(t_2 * Float64(s * Float64(x * c))));
	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 = 1.0 / (x * (c * s));
	t_1 = cos((x * 2.0));
	t_2 = c * (x * s);
	tmp = 0.0;
	if (x <= -9e-16)
		tmp = t_1 / (t_2 * t_2);
	elseif (x <= 2e-57)
		tmp = t_0 * t_0;
	else
		tmp = t_1 / (t_2 * (s * (x * c)));
	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[(1.0 / N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9e-16], N[(t$95$1 / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e-57], N[(t$95$0 * t$95$0), $MachinePrecision], N[(t$95$1 / N[(t$95$2 * N[(s * N[(x * c), $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 := \frac{1}{x \cdot \left(c \cdot s\right)}\\
t_1 := \cos \left(x \cdot 2\right)\\
t_2 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;x \leq -9 \cdot 10^{-16}:\\
\;\;\;\;\frac{t_1}{t_2 \cdot t_2}\\

\mathbf{elif}\;x \leq 2 \cdot 10^{-57}:\\
\;\;\;\;t_0 \cdot t_0\\

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


\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 x < -9.0000000000000003e-16

    1. Initial program 24.8

      \[\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)}} \]
      Proof

      [Start]24.8

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

      *-commutative [=>]24.8

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

      associate-*l* [=>]26.2

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

      associate-*r* [=>]26.3

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

      *-commutative [=>]26.3

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

      unpow2 [=>]26.3

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

      unpow2 [=>]26.3

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

      unswap-sqr [=>]14.0

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

      unswap-sqr [=>]2.1

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

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

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

    if -9.0000000000000003e-16 < x < 1.99999999999999991e-57

    1. Initial program 35.7

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

      [Start]35.7

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

      *-commutative [=>]35.7

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

      associate-*l* [=>]45.2

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

      associate-*r* [=>]45.0

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

      *-commutative [=>]45.0

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

      unpow2 [=>]45.0

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

      unpow2 [=>]45.0

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

      unswap-sqr [=>]35.0

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

      unswap-sqr [=>]4.2

      \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\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.2

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

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

    if 1.99999999999999991e-57 < x

    1. Initial program 24.4

      \[\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)}} \]
      Proof

      [Start]24.4

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

      *-commutative [=>]24.4

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

      associate-*l* [=>]25.9

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

      associate-*r* [=>]26.0

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

      *-commutative [=>]26.0

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

      unpow2 [=>]26.0

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

      unpow2 [=>]26.0

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

      unswap-sqr [=>]13.2

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

      unswap-sqr [=>]2.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-16}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-57}:\\ \;\;\;\;\frac{1}{x \cdot \left(c \cdot s\right)} \cdot \frac{1}{x \cdot \left(c \cdot s\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error7.9
Cost7888
\[\begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ t_1 := \frac{t_0}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}\\ t_2 := \frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ t_3 := \frac{1}{x \cdot \left(c \cdot s\right)}\\ \mathbf{if}\;x \leq -8.2 \cdot 10^{+88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.7 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-32}:\\ \;\;\;\;t_3 \cdot t_3\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error9.7
Cost7625
\[\begin{array}{l} t_0 := \frac{1}{x \cdot \left(c \cdot s\right)}\\ \mathbf{if}\;x \leq -0.008 \lor \neg \left(x \leq 0.00016\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot t_0\\ \end{array} \]
Alternative 3
Error2.9
Cost7625
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ t_1 := \frac{1}{x \cdot \left(c \cdot s\right)}\\ \mathbf{if}\;x \leq -2 \cdot 10^{-16} \lor \neg \left(x \leq 4.4 \cdot 10^{-32}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot t_1\\ \end{array} \]
Alternative 4
Error2.5
Cost7488
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ \frac{\cos \left(x + x\right)}{t_0} \cdot \frac{1}{t_0} \end{array} \]
Alternative 5
Error2.7
Cost7360
\[\begin{array}{l} t_0 := x \cdot \left(c \cdot s\right)\\ \frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0} \end{array} \]
Alternative 6
Error17.0
Cost960
\[\begin{array}{l} t_0 := \frac{1}{x \cdot \left(c \cdot s\right)}\\ t_0 \cdot t_0 \end{array} \]
Alternative 7
Error17.1
Cost832
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \]
Alternative 8
Error18.2
Cost832
\[\frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)} \]
Alternative 9
Error17.0
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 2023067 
(FPCore (x c s)
  :name "mixedcos"
  :precision binary64
  (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))