| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 320 |
\[x \cdot \left(0.16666666666666666 \cdot x\right)
\]

(FPCore (x) :precision binary64 (/ (- x (sin x)) (tan x)))
(FPCore (x) :precision binary64 (* x (* 0.16666666666666666 x)))
double code(double x) {
return (x - sin(x)) / tan(x);
}
double code(double x) {
return x * (0.16666666666666666 * x);
}
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 = x * (0.16666666666666666d0 * x)
end function
public static double code(double x) {
return (x - Math.sin(x)) / Math.tan(x);
}
public static double code(double x) {
return x * (0.16666666666666666 * x);
}
def code(x): return (x - math.sin(x)) / math.tan(x)
def code(x): return x * (0.16666666666666666 * x)
function code(x) return Float64(Float64(x - sin(x)) / tan(x)) end
function code(x) return Float64(x * Float64(0.16666666666666666 * x)) end
function tmp = code(x) tmp = (x - sin(x)) / tan(x); end
function tmp = code(x) tmp = x * (0.16666666666666666 * x); end
code[x_] := N[(N[(x - N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[Tan[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(0.16666666666666666 * x), $MachinePrecision]), $MachinePrecision]
\frac{x - \sin x}{\tan x}
x \cdot \left(0.16666666666666666 \cdot x\right)
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 62.2% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
Initial program 66.3%
Taylor expanded in x around 0 99.8%
Simplified99.8%
[Start]99.8% | \[ 0.16666666666666666 \cdot {x}^{2}
\] |
|---|---|
unpow2 [=>]99.8% | \[ 0.16666666666666666 \cdot \color{blue}{\left(x \cdot x\right)}
\] |
Applied egg-rr99.7%
[Start]99.8% | \[ 0.16666666666666666 \cdot \left(x \cdot x\right)
\] |
|---|---|
add-sqr-sqrt [=>]99.6% | \[ \color{blue}{\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)} \cdot \sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}}
\] |
pow2 [=>]99.6% | \[ \color{blue}{{\left(\sqrt{0.16666666666666666 \cdot \left(x \cdot x\right)}\right)}^{2}}
\] |
*-commutative [=>]99.6% | \[ {\left(\sqrt{\color{blue}{\left(x \cdot x\right) \cdot 0.16666666666666666}}\right)}^{2}
\] |
sqrt-prod [=>]99.7% | \[ {\color{blue}{\left(\sqrt{x \cdot x} \cdot \sqrt{0.16666666666666666}\right)}}^{2}
\] |
sqrt-prod [=>]51.6% | \[ {\left(\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
add-sqr-sqrt [<=]99.7% | \[ {\left(\color{blue}{x} \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
Applied egg-rr99.8%
[Start]99.7% | \[ {\left(x \cdot \sqrt{0.16666666666666666}\right)}^{2}
\] |
|---|---|
unpow2 [=>]99.7% | \[ \color{blue}{\left(x \cdot \sqrt{0.16666666666666666}\right) \cdot \left(x \cdot \sqrt{0.16666666666666666}\right)}
\] |
swap-sqr [=>]99.8% | \[ \color{blue}{\left(x \cdot x\right) \cdot \left(\sqrt{0.16666666666666666} \cdot \sqrt{0.16666666666666666}\right)}
\] |
add-sqr-sqrt [<=]99.8% | \[ \left(x \cdot x\right) \cdot \color{blue}{0.16666666666666666}
\] |
*-commutative [<=]99.8% | \[ \color{blue}{0.16666666666666666 \cdot \left(x \cdot x\right)}
\] |
associate-*r* [=>]99.8% | \[ \color{blue}{\left(0.16666666666666666 \cdot x\right) \cdot x}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 320 |
herbie shell --seed 2023277
(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)))