| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 13760 |
\[\left(0.16666666666666666 \cdot \left(x \cdot x\right) + -0.0007275132275132275 \cdot {x}^{6}\right) + -0.06388888888888888 \cdot {x}^{4}
\]

(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x) :precision binary64 (+ (+ (* 0.16666666666666666 (* x x)) (* -0.0007275132275132275 (pow x 6.0))) (* -0.06388888888888888 (pow x 4.0))))
double code(double x) {
return (x - sin(x)) / tan(x);
}
double code(double x) {
return ((0.16666666666666666 * (x * x)) + (-0.0007275132275132275 * pow(x, 6.0))) + (-0.06388888888888888 * pow(x, 4.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x - sin(x)) / tan(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.16666666666666666d0 * (x * x)) + ((-0.0007275132275132275d0) * (x ** 6.0d0))) + ((-0.06388888888888888d0) * (x ** 4.0d0))
end function
public static double code(double x) {
return (x - Math.sin(x)) / Math.tan(x);
}
public static double code(double x) {
return ((0.16666666666666666 * (x * x)) + (-0.0007275132275132275 * Math.pow(x, 6.0))) + (-0.06388888888888888 * Math.pow(x, 4.0));
}
def code(x): return (x - math.sin(x)) / math.tan(x)
def code(x): return ((0.16666666666666666 * (x * x)) + (-0.0007275132275132275 * math.pow(x, 6.0))) + (-0.06388888888888888 * math.pow(x, 4.0))
function code(x) return Float64(Float64(x - sin(x)) / tan(x)) end
function code(x) return Float64(Float64(Float64(0.16666666666666666 * Float64(x * x)) + Float64(-0.0007275132275132275 * (x ^ 6.0))) + Float64(-0.06388888888888888 * (x ^ 4.0))) end
function tmp = code(x) tmp = (x - sin(x)) / tan(x); end
function tmp = code(x) tmp = ((0.16666666666666666 * (x * x)) + (-0.0007275132275132275 * (x ^ 6.0))) + (-0.06388888888888888 * (x ^ 4.0)); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[(0.16666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(-0.0007275132275132275 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.06388888888888888 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
\left(0.16666666666666666 \cdot \left(x \cdot x\right) + -0.0007275132275132275 \cdot {x}^{6}\right) + -0.06388888888888888 \cdot {x}^{4}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 53.9% |
|---|---|
| Target | 98.7% |
| Herbie | 99.5% |
Initial program 49.2%
Taylor expanded in x around 0 99.7%
Applied egg-rr99.7%
[Start]99.7% | \[ 0.16666666666666666 \cdot {x}^{2} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
|---|---|
pow2 [<=]99.7% | \[ 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
associate-*r* [=>]99.7% | \[ \color{blue}{\left(0.16666666666666666 \cdot x\right) \cdot x} + \left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)
\] |
fma-def [=>]99.7% | \[ \color{blue}{\mathsf{fma}\left(0.16666666666666666 \cdot x, x, -0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)}
\] |
+-commutative [=>]99.7% | \[ \mathsf{fma}\left(0.16666666666666666 \cdot x, x, \color{blue}{-0.06388888888888888 \cdot {x}^{4} + -0.0007275132275132275 \cdot {x}^{6}}\right)
\] |
fma-def [=>]99.7% | \[ \mathsf{fma}\left(0.16666666666666666 \cdot x, x, \color{blue}{\mathsf{fma}\left(-0.06388888888888888, {x}^{4}, -0.0007275132275132275 \cdot {x}^{6}\right)}\right)
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ \mathsf{fma}\left(0.16666666666666666 \cdot x, x, \mathsf{fma}\left(-0.06388888888888888, {x}^{4}, -0.0007275132275132275 \cdot {x}^{6}\right)\right)
\] |
|---|---|
fma-udef [=>]99.7% | \[ \mathsf{fma}\left(0.16666666666666666 \cdot x, x, \color{blue}{-0.06388888888888888 \cdot {x}^{4} + -0.0007275132275132275 \cdot {x}^{6}}\right)
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ \mathsf{fma}\left(0.16666666666666666 \cdot x, x, -0.06388888888888888 \cdot {x}^{4} + -0.0007275132275132275 \cdot {x}^{6}\right)
\] |
|---|---|
fma-udef [=>]99.7% | \[ \color{blue}{\left(0.16666666666666666 \cdot x\right) \cdot x + \left(-0.06388888888888888 \cdot {x}^{4} + -0.0007275132275132275 \cdot {x}^{6}\right)}
\] |
+-commutative [=>]99.7% | \[ \left(0.16666666666666666 \cdot x\right) \cdot x + \color{blue}{\left(-0.0007275132275132275 \cdot {x}^{6} + -0.06388888888888888 \cdot {x}^{4}\right)}
\] |
associate-+r+ [=>]99.7% | \[ \color{blue}{\left(\left(0.16666666666666666 \cdot x\right) \cdot x + -0.0007275132275132275 \cdot {x}^{6}\right) + -0.06388888888888888 \cdot {x}^{4}}
\] |
associate-*r* [<=]99.7% | \[ \left(\color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)} + -0.0007275132275132275 \cdot {x}^{6}\right) + -0.06388888888888888 \cdot {x}^{4}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 13760 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7040 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 6976 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 704 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 320 |
herbie shell --seed 2023178
(FPCore (x)
:name "ENA, Section 1.4, Exercise 4a"
:precision binary64
:pre (and (<= -1.0 x) (<= x 1.0))
:herbie-target
(* 0.16666666666666666 (* x x))
(/ (- x (sin x)) (tan x)))