| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 832 |
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (* x (* x (fma x (* x -0.041666666666666664) 0.5))))
double code(double x) {
return 1.0 - cos(x);
}
double code(double x) {
return x * (x * fma(x, (x * -0.041666666666666664), 0.5));
}
function code(x) return Float64(1.0 - cos(x)) end
function code(x) return Float64(x * Float64(x * fma(x, Float64(x * -0.041666666666666664), 0.5))) end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \cos x
x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.0 |
Initial program 30.1
Applied egg-rr0.0
Simplified0.0
[Start]0.0 | \[ \left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}
\] |
|---|---|
associate-*r/ [=>]0.0 | \[ \color{blue}{\frac{\left(\sin x \cdot \sin x\right) \cdot 1}{1 + \cos x}}
\] |
*-rgt-identity [=>]0.0 | \[ \frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}
\] |
associate-*r/ [<=]0.0 | \[ \color{blue}{\sin x \cdot \frac{\sin x}{1 + \cos x}}
\] |
hang-0p-tan [=>]0.0 | \[ \sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}
\] |
Taylor expanded in x around 0 0.0
Simplified0.0
[Start]0.0 | \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
+-commutative [=>]0.0 | \[ \color{blue}{-0.041666666666666664 \cdot {x}^{4} + 0.5 \cdot {x}^{2}}
\] |
*-commutative [=>]0.0 | \[ \color{blue}{{x}^{4} \cdot -0.041666666666666664} + 0.5 \cdot {x}^{2}
\] |
metadata-eval [<=]0.0 | \[ {x}^{\color{blue}{\left(2 \cdot 2\right)}} \cdot -0.041666666666666664 + 0.5 \cdot {x}^{2}
\] |
pow-sqr [<=]0.0 | \[ \color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot -0.041666666666666664 + 0.5 \cdot {x}^{2}
\] |
associate-*l* [=>]0.0 | \[ \color{blue}{{x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664\right)} + 0.5 \cdot {x}^{2}
\] |
*-commutative [=>]0.0 | \[ {x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664\right) + \color{blue}{{x}^{2} \cdot 0.5}
\] |
distribute-lft-out [=>]0.0 | \[ \color{blue}{{x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664 + 0.5\right)}
\] |
unpow2 [=>]0.0 | \[ \color{blue}{\left(x \cdot x\right)} \cdot \left({x}^{2} \cdot -0.041666666666666664 + 0.5\right)
\] |
unpow2 [=>]0.0 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot -0.041666666666666664 + 0.5\right)
\] |
associate-*l* [=>]0.0 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{x \cdot \left(x \cdot -0.041666666666666664\right)} + 0.5\right)
\] |
fma-def [=>]0.0 | \[ \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)}
\] |
Taylor expanded in x around 0 0.0
Simplified0.0
[Start]0.0 | \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
*-commutative [=>]0.0 | \[ \color{blue}{{x}^{2} \cdot 0.5} + -0.041666666666666664 \cdot {x}^{4}
\] |
unpow2 [=>]0.0 | \[ \color{blue}{\left(x \cdot x\right)} \cdot 0.5 + -0.041666666666666664 \cdot {x}^{4}
\] |
*-commutative [=>]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{4} \cdot -0.041666666666666664}
\] |
metadata-eval [<=]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + {x}^{\color{blue}{\left(2 \cdot 2\right)}} \cdot -0.041666666666666664
\] |
pow-sqr [<=]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot -0.041666666666666664
\] |
unpow2 [=>]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \left(\color{blue}{\left(x \cdot x\right)} \cdot {x}^{2}\right) \cdot -0.041666666666666664
\] |
unpow2 [=>]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \left(\left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot -0.041666666666666664
\] |
associate-*r* [<=]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot -0.041666666666666664\right)}
\] |
associate-*r* [<=]0.0 | \[ \left(x \cdot x\right) \cdot 0.5 + \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right)}
\] |
distribute-lft-out [=>]0.0 | \[ \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)}
\] |
+-commutative [<=]0.0 | \[ \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right) + 0.5\right)}
\] |
fma-udef [<=]0.0 | \[ \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)}
\] |
associate-*r* [<=]0.0 | \[ \color{blue}{x \cdot \left(x \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\right)}
\] |
*-commutative [=>]0.0 | \[ x \cdot \left(x \cdot \mathsf{fma}\left(x, \color{blue}{-0.041666666666666664 \cdot x}, 0.5\right)\right)
\] |
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Error | 0.7 |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Error | 61.4 |
| Cost | 64 |
herbie shell --seed 2023046
(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)))