?

Average Error: 27.8 → 3.7
Time: 15.9s
Precision: binary64
Cost: 7625

?

\[ \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} \mathbf{if}\;x \leq -1.1 \cdot 10^{-171} \lor \neg \left(x \leq 6 \cdot 10^{-156}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\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
 (if (or (<= x -1.1e-171) (not (<= x 6e-156)))
   (/ (cos (* x 2.0)) (* (* x (* c s)) (* c (* x s))))
   (/ (/ (/ 1.0 s) (* x c)) (* 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 tmp;
	if ((x <= -1.1e-171) || !(x <= 6e-156)) {
		tmp = cos((x * 2.0)) / ((x * (c * s)) * (c * (x * s)));
	} else {
		tmp = ((1.0 / s) / (x * c)) / (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) :: tmp
    if ((x <= (-1.1d-171)) .or. (.not. (x <= 6d-156))) then
        tmp = cos((x * 2.0d0)) / ((x * (c * s)) * (c * (x * s)))
    else
        tmp = ((1.0d0 / s) / (x * c)) / (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 tmp;
	if ((x <= -1.1e-171) || !(x <= 6e-156)) {
		tmp = Math.cos((x * 2.0)) / ((x * (c * s)) * (c * (x * s)));
	} else {
		tmp = ((1.0 / s) / (x * c)) / (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):
	tmp = 0
	if (x <= -1.1e-171) or not (x <= 6e-156):
		tmp = math.cos((x * 2.0)) / ((x * (c * s)) * (c * (x * s)))
	else:
		tmp = ((1.0 / s) / (x * c)) / (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)
	tmp = 0.0
	if ((x <= -1.1e-171) || !(x <= 6e-156))
		tmp = Float64(cos(Float64(x * 2.0)) / Float64(Float64(x * Float64(c * s)) * Float64(c * Float64(x * s))));
	else
		tmp = Float64(Float64(Float64(1.0 / s) / Float64(x * c)) / 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)
	tmp = 0.0;
	if ((x <= -1.1e-171) || ~((x <= 6e-156)))
		tmp = cos((x * 2.0)) / ((x * (c * s)) * (c * (x * s)));
	else
		tmp = ((1.0 / s) / (x * c)) / (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_] := If[Or[LessEqual[x, -1.1e-171], N[Not[LessEqual[x, 6e-156]], $MachinePrecision]], N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision] * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / s), $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(x * c), $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}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-171} \lor \neg \left(x \leq 6 \cdot 10^{-156}\right):\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\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 x < -1.1000000000000001e-171 or 6e-156 < x

    1. Initial program 25.3

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

      \[\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]25.3

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

      *-commutative [=>]25.3

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

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

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

      *-commutative [=>]26.8

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

      unpow2 [=>]26.8

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

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

      \[ \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 [=>]1.9

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

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

    if -1.1000000000000001e-171 < x < 6e-156

    1. Initial program 44.7

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

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

      [Start]44.7

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

      associate-*r* [=>]40.4

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

      unpow2 [=>]40.4

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

      unpow2 [=>]40.4

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

      \[\leadsto \color{blue}{\frac{1}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)}} \]
    4. Simplified30.5

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

      [Start]63.4

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

      associate-*r* [=>]63.4

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

      *-commutative [<=]63.4

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

      associate-*r* [<=]63.5

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

      unpow2 [=>]63.5

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

      sqr-pow [=>]63.5

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

      unpow2 [=>]63.5

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

      unswap-sqr [=>]26.2

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

      metadata-eval [=>]26.2

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

      unpow1 [=>]26.2

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

      rem-square-sqrt [<=]43.1

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

      metadata-eval [=>]43.1

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

      unpow1 [=>]43.1

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

      rem-square-sqrt [<=]43.2

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

      associate-*l* [<=]43.2

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

      associate-*l* [<=]43.2

      \[ \frac{1}{\left(c \cdot c\right) \cdot \left(\left(\left(s \cdot \sqrt{x}\right) \cdot \sqrt{x}\right) \cdot \color{blue}{\left(\left(s \cdot \sqrt{x}\right) \cdot \sqrt{x}\right)}\right)} \]
    5. Applied egg-rr30.4

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{\frac{\frac{1}{s}}{x \cdot s}}{c \cdot c}}}} \]
    6. Applied egg-rr5.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-171} \lor \neg \left(x \leq 6 \cdot 10^{-156}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error2.6
Cost13440
\[{\left(x \cdot \left(c \cdot s\right)\right)}^{-2} \cdot \cos \left(x + x\right) \]
Alternative 2
Error6.6
Cost7756
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ t_1 := \cos \left(x \cdot 2\right)\\ t_2 := \frac{t_1}{x \cdot \left(c \cdot \left(s \cdot \left(s \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{if}\;x \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-78}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+193}:\\ \;\;\;\;\frac{t_1}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error6.9
Cost7756
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ t_1 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -2.16 \cdot 10^{-7}:\\ \;\;\;\;\frac{t_1}{x \cdot \left(c \cdot \left(s \cdot \left(s \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-76}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+193}:\\ \;\;\;\;\frac{t_1}{x \cdot \left(x \cdot \left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)\right)}\\ \end{array} \]
Alternative 4
Error6.7
Cost7625
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{-8} \lor \neg \left(x \leq 1.15 \cdot 10^{-59}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(s \cdot \left(s \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot t_0\\ \end{array} \]
Alternative 5
Error12.6
Cost7624
\[\begin{array}{l} \mathbf{if}\;s \leq 1.6 \cdot 10^{-160}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{elif}\;s \leq 1.2 \cdot 10^{+80}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(c \cdot \left(x \cdot \left(s \cdot s\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \end{array} \]
Alternative 6
Error2.7
Cost7616
\[\begin{array}{l} t_0 := \frac{\frac{1}{x}}{c \cdot s}\\ \cos \left(x + x\right) \cdot \left(t_0 \cdot t_0\right) \end{array} \]
Alternative 7
Error3.1
Cost7492
\[\begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ \mathbf{if}\;s \leq 1.18 \cdot 10^{+179}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c \cdot \left(\left(x \cdot s\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]
Alternative 8
Error2.7
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 9
Error16.5
Cost6784
\[{\left(c \cdot \left(x \cdot s\right)\right)}^{-2} \]
Alternative 10
Error23.8
Cost1097
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-158} \lor \neg \left(x \leq 1.75 \cdot 10^{-157}\right):\\ \;\;\;\;\frac{1}{s \cdot \left(s \cdot \left(c \cdot \left(c \cdot \left(x \cdot x\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]
Alternative 11
Error15.8
Cost1096
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \mathbf{if}\;c \leq -8.5 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \left(x \cdot c\right)}\\ \mathbf{elif}\;c \leq 5 \cdot 10^{-183}:\\ \;\;\;\;\frac{1}{c \cdot \left(\left(x \cdot s\right) \cdot t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0 \cdot t_0}\\ \end{array} \]
Alternative 12
Error21.3
Cost964
\[\begin{array}{l} \mathbf{if}\;c \leq 2.4 \cdot 10^{-98}:\\ \;\;\;\;\frac{1}{\left(c \cdot s\right) \cdot \left(s \cdot \left(x \cdot \left(x \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)}\\ \end{array} \]
Alternative 13
Error16.5
Cost960
\[\begin{array}{l} t_0 := \frac{1}{c \cdot \left(x \cdot s\right)}\\ t_0 \cdot t_0 \end{array} \]
Alternative 14
Error16.5
Cost960
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{x \cdot s}\\ t_0 \cdot t_0 \end{array} \]
Alternative 15
Error28.2
Cost832
\[\frac{1}{s \cdot \left(s \cdot \left(c \cdot \left(c \cdot \left(x \cdot x\right)\right)\right)\right)} \]
Alternative 16
Error19.4
Cost832
\[\frac{1}{\left(c \cdot s\right) \cdot \left(x \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)} \]
Alternative 17
Error16.6
Cost832
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \]

Error

Reproduce?

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