mixedcos

?

Percentage Accurate: 67.1% → 97.1%
Time: 12.1s
Precision: binary64
Cost: 7360

?

\[\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ \frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0} \end{array} \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 (* x c)))) (/ (cos (* 2.0 x)) (* 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 = s * (x * c);
	return cos((2.0 * x)) / (t_0 * t_0);
}
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
    t_0 = s * (x * c)
    code = cos((2.0d0 * x)) / (t_0 * t_0)
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 * (x * c);
	return Math.cos((2.0 * x)) / (t_0 * t_0);
}
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 * (x * c)
	return math.cos((2.0 * x)) / (t_0 * t_0)
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(x * c))
	return Float64(cos(Float64(2.0 * x)) / Float64(t_0 * t_0))
end
function tmp = code(x, c, s)
	tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x));
end
function tmp = code(x, c, s)
	t_0 = s * (x * c);
	tmp = cos((2.0 * x)) / (t_0 * t_0);
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[(x * c), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[N[(2.0 * x), $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}

\\
\begin{array}{l}
t_0 := s \cdot \left(x \cdot c\right)\\
\frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0}
\end{array}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 72.7%

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

    \[\leadsto \color{blue}{\frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}} \]
    Step-by-step derivation

    [Start]72.7%

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

    *-commutative [=>]72.7%

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

    associate-*r* [=>]68.9%

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

    associate-*r* [=>]67.4%

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

    unpow2 [=>]67.4%

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

    unswap-sqr [=>]80.8%

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

    unpow2 [=>]80.8%

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

    swap-sqr [<=]98.7%

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

    *-commutative [<=]98.7%

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

    *-commutative [<=]98.7%

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

    *-commutative [=>]98.7%

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

    *-commutative [=>]98.7%

    \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \color{blue}{\left(x \cdot c\right)}\right)} \]
  3. Final simplification98.7%

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

Alternatives

Alternative 1
Accuracy97.1%
Cost7360
\[\begin{array}{l} t_0 := s \cdot \left(x \cdot c\right)\\ \frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0} \end{array} \]
Alternative 2
Accuracy91.3%
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-8} \lor \neg \left(x \leq 0.000225\right):\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(\left(x \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot c\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}\\ \end{array} \]
Alternative 3
Accuracy93.9%
Cost7625
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-11} \lor \neg \left(x \leq 0.00019\right):\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(c \cdot \left(\left(x \cdot c\right) \cdot \left(x \cdot s\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}\\ \end{array} \]
Alternative 4
Accuracy79.9%
Cost7624
\[\begin{array}{l} t_0 := \frac{\frac{\frac{1}{x}}{c}}{s}\\ \mathbf{if}\;c \leq -5.9 \cdot 10^{+85}:\\ \;\;\;\;t_0 \cdot t_0\\ \mathbf{elif}\;c \leq -7.6 \cdot 10^{-124}:\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{s \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot \left(c \cdot c\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}\\ \end{array} \]
Alternative 5
Accuracy95.0%
Cost7360
\[\frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)} \]
Alternative 6
Accuracy78.9%
Cost6912
\[\frac{1}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}} \]
Alternative 7
Accuracy78.8%
Cost960
\[\begin{array}{l} t_0 := \frac{\frac{\frac{1}{x}}{c}}{s}\\ t_0 \cdot t_0 \end{array} \]
Alternative 8
Accuracy78.7%
Cost896
\[\frac{-1}{\left(x \cdot \left(s \cdot c\right)\right) \cdot \left(x \cdot \left(s \cdot \left(-c\right)\right)\right)} \]
Alternative 9
Accuracy55.4%
Cost832
\[\frac{1}{\left(c \cdot c\right) \cdot \left(\left(x \cdot x\right) \cdot \left(s \cdot s\right)\right)} \]
Alternative 10
Accuracy67.2%
Cost832
\[\frac{1}{\left(x \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right)} \]
Alternative 11
Accuracy75.8%
Cost832
\[\frac{\frac{1}{x}}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(s \cdot c\right)} \]
Alternative 12
Accuracy75.8%
Cost832
\[\frac{\frac{1}{x}}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot c\right)} \]
Alternative 13
Accuracy76.9%
Cost832
\[\frac{\frac{1}{x}}{\left(s \cdot c\right) \cdot \left(x \cdot \left(s \cdot c\right)\right)} \]

Reproduce?

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