| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13312 |
\[\mathsf{fma}\left(0.5 \cdot x, x, -0.041666666666666664 \cdot {x}^{4}\right)
\]

(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (fma (* 0.5 x) x (* -0.041666666666666664 (pow x 4.0))))
double code(double x) {
return 1.0 - cos(x);
}
double code(double x) {
return fma((0.5 * x), x, (-0.041666666666666664 * pow(x, 4.0)));
}
function code(x) return Float64(1.0 - cos(x)) end
function code(x) return fma(Float64(0.5 * x), x, Float64(-0.041666666666666664 * (x ^ 4.0))) end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(0.5 * x), $MachinePrecision] * x + N[(-0.041666666666666664 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \cos x
\mathsf{fma}\left(0.5 \cdot x, x, -0.041666666666666664 \cdot {x}^{4}\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 52.9% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 55.8%
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(0.5, {x}^{2}, -0.041666666666666664 \cdot {x}^{4}\right)}
\] |
unpow2 [=>]100.0% | \[ \mathsf{fma}\left(0.5, \color{blue}{x \cdot x}, -0.041666666666666664 \cdot {x}^{4}\right)
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ \mathsf{fma}\left(0.5, x \cdot x, -0.041666666666666664 \cdot {x}^{4}\right)
\] |
|---|---|
fma-udef [=>]100.0% | \[ \color{blue}{0.5 \cdot \left(x \cdot x\right) + -0.041666666666666664 \cdot {x}^{4}}
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ 0.5 \cdot \left(x \cdot x\right) + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
associate-*r* [=>]100.0% | \[ \color{blue}{\left(0.5 \cdot x\right) \cdot x} + -0.041666666666666664 \cdot {x}^{4}
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(0.5 \cdot x, x, -0.041666666666666664 \cdot {x}^{4}\right)}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13312 |
| Alternative 2 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13120 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 7040 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 320 |
herbie shell --seed 2023165
(FPCore (x)
:name "ENA, Section 1.4, Mentioned, A"
:precision binary64
:pre (and (<= -0.01 x) (<= x 0.01))
:herbie-target
(/ (* (sin x) (sin x)) (+ 1.0 (cos x)))
(- 1.0 (cos x)))