| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13376 |
\[\frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \frac{\sin x}{x}
\]

(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x) :precision binary64 (* (/ (tan (* x 0.5)) x) (/ (sin x) x)))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
return (tan((x * 0.5)) / x) * (sin(x) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (tan((x * 0.5d0)) / x) * (sin(x) / x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
public static double code(double x) {
return (Math.tan((x * 0.5)) / x) * (Math.sin(x) / x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
def code(x): return (math.tan((x * 0.5)) / x) * (math.sin(x) / x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function code(x) return Float64(Float64(tan(Float64(x * 0.5)) / x) * Float64(sin(x) / x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
function tmp = code(x) tmp = (tan((x * 0.5)) / x) * (sin(x) / x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[Tan[N[(x * 0.5), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
\frac{\tan \left(x \cdot 0.5\right)}{x} \cdot \frac{\sin x}{x}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 54.3%
Applied egg-rr74.4%
[Start]54.3% | \[ \frac{1 - \cos x}{x \cdot x}
\] |
|---|---|
flip-- [=>]54.1% | \[ \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x}
\] |
div-inv [=>]54.0% | \[ \frac{\color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x}
\] |
metadata-eval [=>]54.0% | \[ \frac{\left(\color{blue}{1} - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}{x \cdot x}
\] |
1-sub-cos [=>]74.4% | \[ \frac{\color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{1 + \cos x}}{x \cdot x}
\] |
pow2 [=>]74.4% | \[ \frac{\color{blue}{{\sin x}^{2}} \cdot \frac{1}{1 + \cos x}}{x \cdot x}
\] |
Simplified74.8%
[Start]74.4% | \[ \frac{{\sin x}^{2} \cdot \frac{1}{1 + \cos x}}{x \cdot x}
\] |
|---|---|
unpow2 [=>]74.4% | \[ \frac{\color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{1 + \cos x}}{x \cdot x}
\] |
associate-*l* [=>]74.4% | \[ \frac{\color{blue}{\sin x \cdot \left(\sin x \cdot \frac{1}{1 + \cos x}\right)}}{x \cdot x}
\] |
associate-*r/ [=>]74.4% | \[ \frac{\sin x \cdot \color{blue}{\frac{\sin x \cdot 1}{1 + \cos x}}}{x \cdot x}
\] |
*-rgt-identity [=>]74.4% | \[ \frac{\sin x \cdot \frac{\color{blue}{\sin x}}{1 + \cos x}}{x \cdot x}
\] |
hang-0p-tan [=>]74.8% | \[ \frac{\sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x}
\] |
Applied egg-rr99.8%
[Start]74.8% | \[ \frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x}
\] |
|---|---|
*-commutative [=>]74.8% | \[ \frac{\color{blue}{\tan \left(\frac{x}{2}\right) \cdot \sin x}}{x \cdot x}
\] |
times-frac [=>]99.8% | \[ \color{blue}{\frac{\tan \left(\frac{x}{2}\right)}{x} \cdot \frac{\sin x}{x}}
\] |
div-inv [=>]99.8% | \[ \frac{\tan \color{blue}{\left(x \cdot \frac{1}{2}\right)}}{x} \cdot \frac{\sin x}{x}
\] |
metadata-eval [=>]99.8% | \[ \frac{\tan \left(x \cdot \color{blue}{0.5}\right)}{x} \cdot \frac{\sin x}{x}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13376 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7304 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 7241 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 7113 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Accuracy | 78.1% |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Accuracy | 8.0% |
| Cost | 64 |
| Alternative 9 | |
|---|---|
| Accuracy | 9.8% |
| Cost | 64 |
| Alternative 10 | |
|---|---|
| Accuracy | 51.2% |
| Cost | 64 |
herbie shell --seed 2023165
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))