| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 7360 |
\[\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}
\]

(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}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 72.7%
Simplified98.7%
[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)}
\] |
Final simplification98.7%
| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 7360 |
| Alternative 2 | |
|---|---|
| Accuracy | 91.3% |
| Cost | 7625 |
| Alternative 3 | |
|---|---|
| Accuracy | 93.9% |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.9% |
| Cost | 7624 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.0% |
| Cost | 7360 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 6912 |
| Alternative 7 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 960 |
| Alternative 8 | |
|---|---|
| Accuracy | 78.7% |
| Cost | 896 |
| Alternative 9 | |
|---|---|
| Accuracy | 55.4% |
| Cost | 832 |
| Alternative 10 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 832 |
| Alternative 11 | |
|---|---|
| Accuracy | 75.8% |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Accuracy | 75.8% |
| Cost | 832 |
| Alternative 13 | |
|---|---|
| Accuracy | 76.9% |
| Cost | 832 |
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))))