?

Average Error: 27.6 → 2.3
Time: 16.0s
Precision: binary64
Cost: 20292

?

\[ \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 := \cos \left(x + x\right)\\ \mathbf{if}\;s \leq 10^{+173}:\\ \;\;\;\;t_1 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)}{t_0 \cdot 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 (cos (+ x x))))
   (if (<= s 1e+173)
     (* t_1 (pow (* s (* x c)) -2.0))
     (/ (log1p (expm1 t_1)) (* 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 = cos((x + x));
	double tmp;
	if (s <= 1e+173) {
		tmp = t_1 * pow((s * (x * c)), -2.0);
	} else {
		tmp = log1p(expm1(t_1)) / (t_0 * t_0);
	}
	return tmp;
}
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 = Math.cos((x + x));
	double tmp;
	if (s <= 1e+173) {
		tmp = t_1 * Math.pow((s * (x * c)), -2.0);
	} else {
		tmp = Math.log1p(Math.expm1(t_1)) / (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 = math.cos((x + x))
	tmp = 0
	if s <= 1e+173:
		tmp = t_1 * math.pow((s * (x * c)), -2.0)
	else:
		tmp = math.log1p(math.expm1(t_1)) / (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 = cos(Float64(x + x))
	tmp = 0.0
	if (s <= 1e+173)
		tmp = Float64(t_1 * (Float64(s * Float64(x * c)) ^ -2.0));
	else
		tmp = Float64(log1p(expm1(t_1)) / Float64(t_0 * t_0));
	end
	return 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[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[s, 1e+173], N[(t$95$1 * N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(N[Log[1 + N[(Exp[t$95$1] - 1), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $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 := x \cdot \left(s \cdot c\right)\\
t_1 := \cos \left(x + x\right)\\
\mathbf{if}\;s \leq 10^{+173}:\\
\;\;\;\;t_1 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)}{t_0 \cdot 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 s < 1e173

    1. Initial program 28.6

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

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

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

      *-commutative [=>]28.6

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

      associate-*l* [=>]31.8

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

      associate-*r* [=>]32.1

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

      *-commutative [=>]32.1

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

      unpow2 [=>]32.1

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

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

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

      \[ \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 inf 31.8

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

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

      [Start]31.8

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

      count-2 [<=]31.8

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

      associate-*r* [=>]32.1

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

      associate-/r* [=>]32.1

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

      unpow2 [=>]32.1

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

      unpow2 [=>]32.1

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

      swap-sqr [<=]21.9

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

      *-lft-identity [<=]21.9

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

      times-frac [=>]21.8

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

      associate-*l/ [<=]17.2

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

      unpow2 [=>]17.2

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

      associate-/r* [<=]17.2

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

      associate-*r* [=>]8.1

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

      *-commutative [<=]8.1

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

      associate-/r* [=>]7.8

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

    if 1e173 < s

    1. Initial program 25.0

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

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

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

      *-commutative [=>]25.0

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

      associate-*l* [=>]29.1

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

      associate-*r* [=>]29.1

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

      *-commutative [=>]29.1

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

      unpow2 [=>]29.1

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

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

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

      \[ \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. Applied egg-rr2.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 10^{+173}:\\ \;\;\;\;\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos \left(x + x\right)\right)\right)}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(x \cdot \left(s \cdot c\right)\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error2.3
Cost13572
\[\begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;s \leq 10^{+173}:\\ \;\;\;\;\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \end{array} \]
Alternative 2
Error8.4
Cost7756
\[\begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -7.8 \cdot 10^{-6}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-7}:\\ \;\;\;\;{\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+157}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(x \cdot \left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(s \cdot \left(s \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \end{array} \]
Alternative 3
Error2.3
Cost7753
\[\begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{-264} \lor \neg \left(x \leq 9.6 \cdot 10^{-175}\right):\\ \;\;\;\;\cos \left(x + x\right) \cdot \frac{\frac{1}{t_0}}{t_0}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 4
Error9.6
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{-5} \lor \neg \left(x \leq 2.65 \cdot 10^{-5}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\ \end{array} \]
Alternative 5
Error4.3
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-263} \lor \neg \left(x \leq 2.85 \cdot 10^{-33}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(c \cdot \left(s \cdot x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 6
Error9.8
Cost7624
\[\begin{array}{l} t_0 := \cos \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -0.00185:\\ \;\;\;\;\frac{t_0}{x \cdot \left(c \cdot \left(c \cdot \left(s \cdot \left(s \cdot x\right)\right)\right)\right)}\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-12}:\\ \;\;\;\;{\left(c \cdot \left(s \cdot x\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{x \cdot \left(s \cdot \left(s \cdot \left(c \cdot \left(x \cdot c\right)\right)\right)\right)}\\ \end{array} \]
Alternative 7
Error4.5
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{1}{s}}{x \cdot c}\\ t_1 := \cos \left(x \cdot 2\right)\\ t_2 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{-264}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot \left(c \cdot \left(s \cdot x\right)\right)}\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-215}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{\left(s \cdot \left(x \cdot c\right)\right) \cdot t_2}\\ \end{array} \]
Alternative 8
Error3.6
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{1}{s}}{x \cdot c}\\ t_1 := \cos \left(x \cdot 2\right)\\ t_2 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;x \leq -6 \cdot 10^{-263}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot \left(c \cdot \left(s \cdot x\right)\right)}\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-208}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot t_2}\\ \end{array} \]
Alternative 9
Error16.6
Cost6784
\[{\left(c \cdot \left(s \cdot x\right)\right)}^{-2} \]
Alternative 10
Error16.6
Cost960
\[\begin{array}{l} t_0 := \frac{\frac{1}{c}}{s \cdot x}\\ t_0 \cdot t_0 \end{array} \]
Alternative 11
Error34.2
Cost832
\[\frac{1}{\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \left(x \cdot x\right)\right)} \]
Alternative 12
Error30.7
Cost832
\[\frac{1}{\left(c \cdot \left(x \cdot x\right)\right) \cdot \left(c \cdot \left(s \cdot s\right)\right)} \]
Alternative 13
Error27.4
Cost832
\[\frac{1}{\left(s \cdot s\right) \cdot \left(c \cdot \left(x \cdot \left(x \cdot c\right)\right)\right)} \]
Alternative 14
Error17.9
Cost832
\[\frac{1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(c \cdot \left(s \cdot x\right)\right)} \]
Alternative 15
Error16.8
Cost832
\[\begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ \frac{1}{t_0 \cdot t_0} \end{array} \]

Error

Reproduce?

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