| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 192 |
\[\frac{x}{3}
\]

(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
(FPCore (x) :precision binary64 (/ x 3.0))
double code(double x) {
return (1.0 / x) - (1.0 / tan(x));
}
double code(double x) {
return x / 3.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) - (1.0d0 / tan(x))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = x / 3.0d0
end function
public static double code(double x) {
return (1.0 / x) - (1.0 / Math.tan(x));
}
public static double code(double x) {
return x / 3.0;
}
def code(x): return (1.0 / x) - (1.0 / math.tan(x))
def code(x): return x / 3.0
function code(x) return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x))) end
function code(x) return Float64(x / 3.0) end
function tmp = code(x) tmp = (1.0 / x) - (1.0 / tan(x)); end
function tmp = code(x) tmp = x / 3.0; end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x / 3.0), $MachinePrecision]
\frac{1}{x} - \frac{1}{\tan x}
\frac{x}{3}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 6.4% |
|---|---|
| Target | 99.9% |
| Herbie | 99.4% |
Initial program 6.0%
Taylor expanded in x around 0 99.3%
Applied egg-rr34.5%
[Start]99.3% | \[ 0.3333333333333333 \cdot x
\] |
|---|---|
add-cbrt-cube [=>]34.4% | \[ \color{blue}{\sqrt[3]{\left(\left(0.3333333333333333 \cdot x\right) \cdot \left(0.3333333333333333 \cdot x\right)\right) \cdot \left(0.3333333333333333 \cdot x\right)}}
\] |
pow3 [=>]34.4% | \[ \sqrt[3]{\color{blue}{{\left(0.3333333333333333 \cdot x\right)}^{3}}}
\] |
*-commutative [=>]34.4% | \[ \sqrt[3]{{\color{blue}{\left(x \cdot 0.3333333333333333\right)}}^{3}}
\] |
unpow-prod-down [=>]34.4% | \[ \sqrt[3]{\color{blue}{{x}^{3} \cdot {0.3333333333333333}^{3}}}
\] |
metadata-eval [=>]34.5% | \[ \sqrt[3]{{x}^{3} \cdot \color{blue}{0.037037037037037035}}
\] |
Applied egg-rr98.6%
[Start]34.5% | \[ \sqrt[3]{{x}^{3} \cdot 0.037037037037037035}
\] |
|---|---|
pow1/3 [=>]18.0% | \[ \color{blue}{{\left({x}^{3} \cdot 0.037037037037037035\right)}^{0.3333333333333333}}
\] |
*-commutative [=>]18.0% | \[ {\color{blue}{\left(0.037037037037037035 \cdot {x}^{3}\right)}}^{0.3333333333333333}
\] |
unpow-prod-down [=>]18.1% | \[ \color{blue}{{0.037037037037037035}^{0.3333333333333333} \cdot {\left({x}^{3}\right)}^{0.3333333333333333}}
\] |
pow1/3 [<=]34.7% | \[ {0.037037037037037035}^{0.3333333333333333} \cdot \color{blue}{\sqrt[3]{{x}^{3}}}
\] |
rem-cbrt-cube [=>]98.6% | \[ {0.037037037037037035}^{0.3333333333333333} \cdot \color{blue}{x}
\] |
Applied egg-rr99.8%
[Start]98.6% | \[ {0.037037037037037035}^{0.3333333333333333} \cdot x
\] |
|---|---|
unpow1/3 [=>]99.3% | \[ \color{blue}{\sqrt[3]{0.037037037037037035}} \cdot x
\] |
metadata-eval [<=]99.3% | \[ \sqrt[3]{\color{blue}{0.1111111111111111 \cdot 0.3333333333333333}} \cdot x
\] |
metadata-eval [<=]99.3% | \[ \sqrt[3]{\color{blue}{\left(0.3333333333333333 \cdot 0.3333333333333333\right)} \cdot 0.3333333333333333} \cdot x
\] |
add-cbrt-cube [<=]99.3% | \[ \color{blue}{0.3333333333333333} \cdot x
\] |
*-commutative [=>]99.3% | \[ \color{blue}{x \cdot 0.3333333333333333}
\] |
metadata-eval [<=]99.3% | \[ x \cdot \color{blue}{\frac{1}{3}}
\] |
div-inv [<=]99.8% | \[ \color{blue}{\frac{x}{3}}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 192 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 192 |
herbie shell --seed 2023272
(FPCore (x)
:name "invcot (example 3.9)"
:precision binary64
:pre (and (< -0.026 x) (< x 0.026))
:herbie-target
(if (< (fabs x) 0.026) (* (/ x 3.0) (+ 1.0 (/ (* x x) 15.0))) (- (/ 1.0 x) (/ 1.0 (tan x))))
(- (/ 1.0 x) (/ 1.0 (tan x))))