| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 7488 |

(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 (/ (/ (/ 1.0 s) (* x c)) (* s (/ (* x c) (cos (* x 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) {
return ((1.0 / s) / (x * c)) / (s * ((x * c) / cos((x * 2.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
code = ((1.0d0 / s) / (x * c)) / (s * ((x * c) / cos((x * 2.0d0))))
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) {
return ((1.0 / s) / (x * c)) / (s * ((x * c) / Math.cos((x * 2.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): return ((1.0 / s) / (x * c)) / (s * ((x * c) / math.cos((x * 2.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) return Float64(Float64(Float64(1.0 / s) / Float64(x * c)) / Float64(s * Float64(Float64(x * c) / cos(Float64(x * 2.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) tmp = ((1.0 / s) / (x * c)) / (s * ((x * c) / cos((x * 2.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_] := N[(N[(N[(1.0 / s), $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * N[(N[(x * c), $MachinePrecision] / N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\frac{\frac{\frac{1}{s}}{x \cdot c}}{s \cdot \frac{x \cdot c}{\cos \left(x \cdot 2\right)}}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 66.7%
Simplified97.5%
[Start]66.7% | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]66.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* [=>]59.8% | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}}
\] |
associate-*r* [=>]58.6% | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}}}
\] |
unpow2 [=>]58.6% | \[ \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 [=>]77.1% | \[ \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 [=>]77.1% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \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.5% | \[ \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)}
\] |
Applied egg-rr98.1%
[Start]97.5% | \[ \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)}
\] |
|---|---|
div-inv [=>]97.5% | \[ \color{blue}{\cos \left(2 \cdot x\right) \cdot \frac{1}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}}
\] |
*-commutative [=>]97.5% | \[ \cos \color{blue}{\left(x \cdot 2\right)} \cdot \frac{1}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}
\] |
pow2 [=>]97.5% | \[ \cos \left(x \cdot 2\right) \cdot \frac{1}{\color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}}
\] |
pow-flip [=>]98.1% | \[ \cos \left(x \cdot 2\right) \cdot \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{\left(-2\right)}}
\] |
metadata-eval [=>]98.1% | \[ \cos \left(x \cdot 2\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{\color{blue}{-2}}
\] |
Applied egg-rr98.0%
[Start]98.1% | \[ \cos \left(x \cdot 2\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}
\] |
|---|---|
metadata-eval [<=]98.1% | \[ \cos \left(x \cdot 2\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{\color{blue}{\left(-1 + -1\right)}}
\] |
pow-prod-up [<=]98.0% | \[ \cos \left(x \cdot 2\right) \cdot \color{blue}{\left({\left(s \cdot \left(x \cdot c\right)\right)}^{-1} \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-1}\right)}
\] |
unpow-1 [=>]98.0% | \[ \cos \left(x \cdot 2\right) \cdot \left(\color{blue}{\frac{1}{s \cdot \left(x \cdot c\right)}} \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-1}\right)
\] |
unpow-1 [=>]98.0% | \[ \cos \left(x \cdot 2\right) \cdot \left(\frac{1}{s \cdot \left(x \cdot c\right)} \cdot \color{blue}{\frac{1}{s \cdot \left(x \cdot c\right)}}\right)
\] |
Applied egg-rr98.1%
[Start]98.0% | \[ \cos \left(x \cdot 2\right) \cdot \left(\frac{1}{s \cdot \left(x \cdot c\right)} \cdot \frac{1}{s \cdot \left(x \cdot c\right)}\right)
\] |
|---|---|
associate-*r* [=>]98.0% | \[ \color{blue}{\left(\cos \left(x \cdot 2\right) \cdot \frac{1}{s \cdot \left(x \cdot c\right)}\right) \cdot \frac{1}{s \cdot \left(x \cdot c\right)}}
\] |
un-div-inv [=>]98.0% | \[ \color{blue}{\frac{\cos \left(x \cdot 2\right) \cdot \frac{1}{s \cdot \left(x \cdot c\right)}}{s \cdot \left(x \cdot c\right)}}
\] |
*-commutative [=>]98.0% | \[ \frac{\cos \left(x \cdot 2\right) \cdot \frac{1}{s \cdot \left(x \cdot c\right)}}{\color{blue}{\left(x \cdot c\right) \cdot s}}
\] |
frac-times [<=]93.2% | \[ \color{blue}{\frac{\cos \left(x \cdot 2\right)}{x \cdot c} \cdot \frac{\frac{1}{s \cdot \left(x \cdot c\right)}}{s}}
\] |
clear-num [=>]93.2% | \[ \color{blue}{\frac{1}{\frac{x \cdot c}{\cos \left(x \cdot 2\right)}}} \cdot \frac{\frac{1}{s \cdot \left(x \cdot c\right)}}{s}
\] |
frac-times [=>]98.1% | \[ \color{blue}{\frac{1 \cdot \frac{1}{s \cdot \left(x \cdot c\right)}}{\frac{x \cdot c}{\cos \left(x \cdot 2\right)} \cdot s}}
\] |
*-un-lft-identity [<=]98.1% | \[ \frac{\color{blue}{\frac{1}{s \cdot \left(x \cdot c\right)}}}{\frac{x \cdot c}{\cos \left(x \cdot 2\right)} \cdot s}
\] |
associate-/r* [=>]98.1% | \[ \frac{\color{blue}{\frac{\frac{1}{s}}{x \cdot c}}}{\frac{x \cdot c}{\cos \left(x \cdot 2\right)} \cdot s}
\] |
Final simplification98.1%
| Alternative 1 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 7488 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.3% |
| Cost | 7625 |
| Alternative 3 | |
|---|---|
| Accuracy | 89.4% |
| Cost | 7624 |
| Alternative 4 | |
|---|---|
| Accuracy | 94.6% |
| Cost | 7360 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 7360 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 7360 |
| Alternative 7 | |
|---|---|
| Accuracy | 76.5% |
| Cost | 964 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.6% |
| Cost | 832 |
| Alternative 9 | |
|---|---|
| Accuracy | 54.5% |
| Cost | 832 |
| Alternative 10 | |
|---|---|
| Accuracy | 74.9% |
| Cost | 832 |
| Alternative 11 | |
|---|---|
| Accuracy | 77.4% |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 832 |
herbie shell --seed 2023271
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))