| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 960 |
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (fma (* x 0.5) x (* (pow x 4.0) -0.041666666666666664)))
double code(double x) {
return 1.0 - cos(x);
}
double code(double x) {
return fma((x * 0.5), x, (pow(x, 4.0) * -0.041666666666666664));
}
function code(x) return Float64(1.0 - cos(x)) end
function code(x) return fma(Float64(x * 0.5), x, Float64((x ^ 4.0) * -0.041666666666666664)) end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x * 0.5), $MachinePrecision] * x + N[(N[Power[x, 4.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]
1 - \cos x
\mathsf{fma}\left(x \cdot 0.5, x, {x}^{4} \cdot -0.041666666666666664\right)
| Original | 52.5% |
|---|---|
| Target | 100.0% |
| Herbie | 100.0% |
Initial program 57.2%
Applied egg-rr100.0%
[Start]57.2 | \[ 1 - \cos x
\] |
|---|---|
flip-- [=>]57.2 | \[ \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}
\] |
div-inv [=>]57.2 | \[ \color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}
\] |
metadata-eval [=>]57.2 | \[ \left(\color{blue}{1} - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}
\] |
1-sub-cos [=>]100.0 | \[ \color{blue}{\left(\sin x \cdot \sin x\right)} \cdot \frac{1}{1 + \cos x}
\] |
Simplified100.0%
[Start]100.0 | \[ \left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}
\] |
|---|---|
associate-*r/ [=>]100.0 | \[ \color{blue}{\frac{\left(\sin x \cdot \sin x\right) \cdot 1}{1 + \cos x}}
\] |
*-rgt-identity [=>]100.0 | \[ \frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}
\] |
associate-*r/ [<=]100.0 | \[ \color{blue}{\sin x \cdot \frac{\sin x}{1 + \cos x}}
\] |
hang-0p-tan [=>]100.0 | \[ \sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}
\] |
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0 | \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
+-commutative [=>]100.0 | \[ \color{blue}{-0.041666666666666664 \cdot {x}^{4} + 0.5 \cdot {x}^{2}}
\] |
metadata-eval [<=]100.0 | \[ -0.041666666666666664 \cdot {x}^{\color{blue}{\left(2 \cdot 2\right)}} + 0.5 \cdot {x}^{2}
\] |
pow-sqr [<=]100.0 | \[ -0.041666666666666664 \cdot \color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} + 0.5 \cdot {x}^{2}
\] |
associate-*r* [=>]100.0 | \[ \color{blue}{\left(-0.041666666666666664 \cdot {x}^{2}\right) \cdot {x}^{2}} + 0.5 \cdot {x}^{2}
\] |
distribute-rgt-out [=>]100.0 | \[ \color{blue}{{x}^{2} \cdot \left(-0.041666666666666664 \cdot {x}^{2} + 0.5\right)}
\] |
*-commutative [<=]100.0 | \[ {x}^{2} \cdot \left(\color{blue}{{x}^{2} \cdot -0.041666666666666664} + 0.5\right)
\] |
unpow2 [=>]100.0 | \[ \color{blue}{\left(x \cdot x\right)} \cdot \left({x}^{2} \cdot -0.041666666666666664 + 0.5\right)
\] |
unpow2 [=>]100.0 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot -0.041666666666666664 + 0.5\right)
\] |
associate-*l* [=>]100.0 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{x \cdot \left(x \cdot -0.041666666666666664\right)} + 0.5\right)
\] |
fma-def [=>]100.0 | \[ \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ \left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)
\] |
|---|---|
fma-udef [=>]100.0 | \[ \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right) + 0.5\right)}
\] |
distribute-rgt-in [=>]100.0 | \[ \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right)}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + 0.5 \cdot \left(x \cdot x\right)
\] |
|---|---|
+-commutative [=>]100.0 | \[ \color{blue}{0.5 \cdot \left(x \cdot x\right) + \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)}
\] |
associate-*r* [=>]100.0 | \[ \color{blue}{\left(0.5 \cdot x\right) \cdot x} + \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)
\] |
fma-def [=>]100.0 | \[ \color{blue}{\mathsf{fma}\left(0.5 \cdot x, x, \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)}
\] |
*-commutative [=>]100.0 | \[ \mathsf{fma}\left(\color{blue}{x \cdot 0.5}, x, \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)
\] |
*-commutative [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot \left(x \cdot -0.041666666666666664\right)\right)}\right)
\] |
associate-*r* [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \left(x \cdot x\right) \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot -0.041666666666666664\right)}\right)
\] |
associate-*r* [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \color{blue}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot -0.041666666666666664}\right)
\] |
pow2 [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \left(\color{blue}{{x}^{2}} \cdot \left(x \cdot x\right)\right) \cdot -0.041666666666666664\right)
\] |
pow2 [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \left({x}^{2} \cdot \color{blue}{{x}^{2}}\right) \cdot -0.041666666666666664\right)
\] |
pow-prod-up [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, \color{blue}{{x}^{\left(2 + 2\right)}} \cdot -0.041666666666666664\right)
\] |
metadata-eval [=>]100.0 | \[ \mathsf{fma}\left(x \cdot 0.5, x, {x}^{\color{blue}{4}} \cdot -0.041666666666666664\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 960 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 320 |
herbie shell --seed 2023157
(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)))