| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 320 |
\[0.5 \cdot \left(x \cdot x\right)
\]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
(FPCore (x) :precision binary64 (* x (+ (* (* -0.041666666666666664 (* x x)) x) (* 0.5 x))))
double code(double x) {
return 1.0 - cos(x);
}
double code(double x) {
return x * (((-0.041666666666666664 * (x * x)) * x) + (0.5 * x));
}
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 * ((((-0.041666666666666664d0) * (x * x)) * x) + (0.5d0 * x))
end function
public static double code(double x) {
return 1.0 - Math.cos(x);
}
public static double code(double x) {
return x * (((-0.041666666666666664 * (x * x)) * x) + (0.5 * x));
}
def code(x): return 1.0 - math.cos(x)
def code(x): return x * (((-0.041666666666666664 * (x * x)) * x) + (0.5 * x))
function code(x) return Float64(1.0 - cos(x)) end
function code(x) return Float64(x * Float64(Float64(Float64(-0.041666666666666664 * Float64(x * x)) * x) + Float64(0.5 * x))) end
function tmp = code(x) tmp = 1.0 - cos(x); end
function tmp = code(x) tmp = x * (((-0.041666666666666664 * (x * x)) * x) + (0.5 * x)); end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(N[(N[(-0.041666666666666664 * N[(x * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \cos x
x \cdot \left(\left(-0.041666666666666664 \cdot \left(x \cdot x\right)\right) \cdot x + 0.5 \cdot x\right)
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.1 |
Initial program 30.1
Taylor expanded in x around 0 0.1
Simplified0.1
Applied egg-rr0.1
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Error | 0.3 |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 30.7 |
| Cost | 192 |
herbie shell --seed 2023010
(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)))