| Alternative 1 | |
|---|---|
| Accuracy | 96.9% |
| 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}
t_0 := s \cdot \left(x \cdot c\right)\\
\frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 66.3%
Simplified97.6%
[Start]66.3% | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]66.3% | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(x \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
associate-*r* [=>]61.1% | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}}
\] |
associate-*r* [=>]60.8% | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}}}
\] |
unpow2 [=>]60.8% | \[ \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 [=>]75.3% | \[ \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 [=>]75.3% | \[ \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 [<=]97.6% | \[ \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 [<=]97.6% | \[ \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 [<=]97.6% | \[ \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 [=>]97.6% | \[ \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 [=>]97.6% | \[ \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 simplification97.6%
| Alternative 1 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 7360 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 7756 |
| Alternative 3 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 7756 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.8% |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.9% |
| Cost | 7492 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 960 |
| Alternative 7 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 832 |
| Alternative 8 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 832 |
| Alternative 9 | |
|---|---|
| Accuracy | 28.2% |
| Cost | 576 |
herbie shell --seed 2023263
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))