| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 320 |
\[\left(x \cdot x\right) \cdot 0.5
\]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (+ (* (* x (* x -0.041666666666666664)) (* x x)) (* (* x x) 0.5)))
double code(double x) {
return 1.0 - cos(x);
}
double code(double x) {
return ((x * (x * -0.041666666666666664)) * (x * x)) + ((x * x) * 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - cos(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * (x * (-0.041666666666666664d0))) * (x * x)) + ((x * x) * 0.5d0)
end function
public static double code(double x) {
return 1.0 - Math.cos(x);
}
public static double code(double x) {
return ((x * (x * -0.041666666666666664)) * (x * x)) + ((x * x) * 0.5);
}
def code(x): return 1.0 - math.cos(x)
def code(x): return ((x * (x * -0.041666666666666664)) * (x * x)) + ((x * x) * 0.5)
function code(x) return Float64(1.0 - cos(x)) end
function code(x) return Float64(Float64(Float64(x * Float64(x * -0.041666666666666664)) * Float64(x * x)) + Float64(Float64(x * x) * 0.5)) end
function tmp = code(x) tmp = 1.0 - cos(x); end
function tmp = code(x) tmp = ((x * (x * -0.041666666666666664)) * (x * x)) + ((x * x) * 0.5); end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[(x * N[(x * -0.041666666666666664), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
1 - \cos x
\left(x \cdot \left(x \cdot -0.041666666666666664\right)\right) \cdot \left(x \cdot x\right) + \left(x \cdot x\right) \cdot 0.5
Results
| Original | 52.0% |
|---|---|
| Target | 100.0% |
| Herbie | 99.9% |
Initial program 52.0%
Applied egg-rr100.0%
[Start]52.0 | \[ 1 - \cos x
\] |
|---|---|
flip-- [=>]52.0 | \[ \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}
\] |
div-inv [=>]52.0 | \[ \color{blue}{\left(1 \cdot 1 - \cos x \cdot \cos x\right) \cdot \frac{1}{1 + \cos x}}
\] |
metadata-eval [=>]52.0 | \[ \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 99.9%
Simplified99.9%
[Start]99.9 | \[ 0.5 \cdot {x}^{2} + -0.041666666666666664 \cdot {x}^{4}
\] |
|---|---|
+-commutative [=>]99.9 | \[ \color{blue}{-0.041666666666666664 \cdot {x}^{4} + 0.5 \cdot {x}^{2}}
\] |
*-commutative [=>]99.9 | \[ \color{blue}{{x}^{4} \cdot -0.041666666666666664} + 0.5 \cdot {x}^{2}
\] |
metadata-eval [<=]99.9 | \[ {x}^{\color{blue}{\left(2 \cdot 2\right)}} \cdot -0.041666666666666664 + 0.5 \cdot {x}^{2}
\] |
pow-sqr [<=]99.9 | \[ \color{blue}{\left({x}^{2} \cdot {x}^{2}\right)} \cdot -0.041666666666666664 + 0.5 \cdot {x}^{2}
\] |
associate-*l* [=>]99.9 | \[ \color{blue}{{x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664\right)} + 0.5 \cdot {x}^{2}
\] |
*-commutative [=>]99.9 | \[ {x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664\right) + \color{blue}{{x}^{2} \cdot 0.5}
\] |
distribute-lft-out [=>]99.9 | \[ \color{blue}{{x}^{2} \cdot \left({x}^{2} \cdot -0.041666666666666664 + 0.5\right)}
\] |
unpow2 [=>]99.9 | \[ \color{blue}{\left(x \cdot x\right)} \cdot \left({x}^{2} \cdot -0.041666666666666664 + 0.5\right)
\] |
unpow2 [=>]99.9 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot -0.041666666666666664 + 0.5\right)
\] |
associate-*l* [=>]99.9 | \[ \left(x \cdot x\right) \cdot \left(\color{blue}{x \cdot \left(x \cdot -0.041666666666666664\right)} + 0.5\right)
\] |
fma-def [=>]99.9 | \[ \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)}
\] |
Applied egg-rr99.9%
[Start]99.9 | \[ \left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)
\] |
|---|---|
fma-udef [=>]99.9 | \[ \left(x \cdot x\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.041666666666666664\right) + 0.5\right)}
\] |
distribute-rgt-in [=>]99.9 | \[ \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)}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 320 |
herbie shell --seed 2023131
(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)))