?

Average Error: 28.4 → 2.2
Time: 15.4s
Precision: binary64
Cost: 7753

?

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}\\


\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 < -3.2000000000000001e-189 or 1.99999999999999997e-45 < x

    1. Initial program 26.0

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

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

      *-commutative [=>]26.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* [=>]27.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* [=>]27.9

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

      *-commutative [=>]27.9

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

      unpow2 [=>]27.9

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

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

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

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

    if -3.2000000000000001e-189 < x < 1.99999999999999997e-45

    1. Initial program 38.6

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

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

      *-commutative [=>]38.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* [=>]50.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* [=>]50.6

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

      *-commutative [=>]50.6

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

      unpow2 [=>]50.6

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

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

      \[ \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 [=>]7.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 x around 0 50.8

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

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

      [Start]50.8

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

      unpow2 [=>]50.8

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

      unpow2 [=>]50.8

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

      unpow2 [=>]50.8

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

      unswap-sqr [=>]26.0

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

      swap-sqr [<=]5.1

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

      associate-*r* [=>]11.2

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

      *-commutative [<=]11.2

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

      associate-*r* [=>]7.1

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

      *-commutative [<=]7.1

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

      unpow2 [<=]7.1

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

      associate-*r* [=>]4.9

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

      *-commutative [<=]4.9

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

      *-commutative [<=]4.9

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

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

Alternatives

Alternative 1
Error2.6
Cost13440
\[\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \]
Alternative 2
Error6.1
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -3.85 \cdot 10^{-146} \lor \neg \left(x \leq 9.6 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot \left(s \cdot \left(x \cdot \left(s \cdot c\right)\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 3
Error3.7
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -1.18 \cdot 10^{-175} \lor \neg \left(x \leq 5 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 4
Error2.5
Cost7625
\[\begin{array}{l} t_0 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;x \leq -4 \cdot 10^{-165} \lor \neg \left(x \leq 5 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\ \end{array} \]
Alternative 5
Error12.5
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{1}{x}}{s \cdot c}\\ \mathbf{if}\;s \leq 3.5 \cdot 10^{-167}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{elif}\;s \leq 1.3 \cdot 10^{+123}:\\ \;\;\;\;\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
Error3.8
Cost7624
\[\begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ t_1 := \cos \left(x \cdot 2\right)\\ t_2 := x \cdot \left(s \cdot c\right)\\ \mathbf{if}\;x \leq -5.9 \cdot 10^{-185}:\\ \;\;\;\;\frac{t_1}{t_2 \cdot \left(c \cdot \left(x \cdot s\right)\right)}\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-11}:\\ \;\;\;\;{t_0}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{t_0 \cdot t_2}\\ \end{array} \]
Alternative 7
Error3.0
Cost7488
\[\frac{\cos \left(x + x\right)}{\frac{c \cdot \left(x \cdot s\right)}{\frac{\frac{1}{c}}{x \cdot s}}} \]
Alternative 8
Error22.0
Cost1097
\[\begin{array}{l} \mathbf{if}\;x \leq -1.42 \cdot 10^{-142} \lor \neg \left(x \leq 4.5 \cdot 10^{-188}\right):\\ \;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(c \cdot \left(x \cdot \left(x \cdot s\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 9
Error22.1
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1.42 \cdot 10^{-142}:\\ \;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(c \cdot \left(x \cdot \left(x \cdot s\right)\right)\right)}\\ \mathbf{elif}\;x \leq 10^{-160}:\\ \;\;\;\;\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(s \cdot c\right) \cdot \left(s \cdot \left(c \cdot \left(x \cdot x\right)\right)\right)}\\ \end{array} \]
Alternative 10
Error28.5
Cost832
\[\frac{1}{\left(c \cdot c\right) \cdot \left(x \cdot \left(s \cdot \left(x \cdot s\right)\right)\right)} \]
Alternative 11
Error19.9
Cost832
\[\frac{1}{\left(s \cdot c\right) \cdot \left(x \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)} \]
Alternative 12
Error19.1
Cost832
\[\frac{1}{\left(s \cdot c\right) \cdot \left(x \cdot \left(x \cdot \left(s \cdot c\right)\right)\right)} \]
Alternative 13
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 14
Error16.8
Cost832
\[\begin{array}{l} t_0 := c \cdot \left(x \cdot s\right)\\ \frac{\frac{1}{t_0}}{t_0} \end{array} \]

Error

Reproduce?

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