| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 39808 |

(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
(FPCore (x)
:precision binary64
(let* ((t_0 (fma x 0.3333333333333333 (* (pow x 3.0) -0.022222222222222223))))
(fma
(* 0.1111111111111111 x)
(/ x t_0)
(* 0.0004938271604938272 (/ (- (pow x 6.0)) t_0)))))double code(double x) {
return (1.0 / x) - (1.0 / tan(x));
}
double code(double x) {
double t_0 = fma(x, 0.3333333333333333, (pow(x, 3.0) * -0.022222222222222223));
return fma((0.1111111111111111 * x), (x / t_0), (0.0004938271604938272 * (-pow(x, 6.0) / t_0)));
}
function code(x) return Float64(Float64(1.0 / x) - Float64(1.0 / tan(x))) end
function code(x) t_0 = fma(x, 0.3333333333333333, Float64((x ^ 3.0) * -0.022222222222222223)) return fma(Float64(0.1111111111111111 * x), Float64(x / t_0), Float64(0.0004938271604938272 * Float64(Float64(-(x ^ 6.0)) / t_0))) end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[Tan[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(x * 0.3333333333333333 + N[(N[Power[x, 3.0], $MachinePrecision] * -0.022222222222222223), $MachinePrecision]), $MachinePrecision]}, N[(N[(0.1111111111111111 * x), $MachinePrecision] * N[(x / t$95$0), $MachinePrecision] + N[(0.0004938271604938272 * N[((-N[Power[x, 6.0], $MachinePrecision]) / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{x} - \frac{1}{\tan x}
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)\\
\mathsf{fma}\left(0.1111111111111111 \cdot x, \frac{x}{t_0}, 0.0004938271604938272 \cdot \frac{-{x}^{6}}{t_0}\right)
\end{array}
| Original | 6.3% |
|---|---|
| Target | 99.9% |
| Herbie | 99.6% |
Initial program 7.0%
Taylor expanded in x around 0 99.3%
Applied egg-rr50.2%
[Start]99.3 | \[ 0.3333333333333333 \cdot x + 0.022222222222222223 \cdot {x}^{3}
\] |
|---|---|
flip-+ [=>]50.1 | \[ \color{blue}{\frac{\left(0.3333333333333333 \cdot x\right) \cdot \left(0.3333333333333333 \cdot x\right) - \left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}}
\] |
div-sub [=>]50.1 | \[ \color{blue}{\frac{\left(0.3333333333333333 \cdot x\right) \cdot \left(0.3333333333333333 \cdot x\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}}
\] |
swap-sqr [=>]50.2 | \[ \frac{\color{blue}{\left(0.3333333333333333 \cdot 0.3333333333333333\right) \cdot \left(x \cdot x\right)}}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
metadata-eval [=>]50.2 | \[ \frac{\color{blue}{0.1111111111111111} \cdot \left(x \cdot x\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
cancel-sign-sub-inv [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\color{blue}{0.3333333333333333 \cdot x + \left(-0.022222222222222223\right) \cdot {x}^{3}}} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
fma-def [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\color{blue}{\mathsf{fma}\left(0.3333333333333333, x, \left(-0.022222222222222223\right) \cdot {x}^{3}\right)}} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
metadata-eval [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, \color{blue}{-0.022222222222222223} \cdot {x}^{3}\right)} - \frac{\left(0.022222222222222223 \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
*-commutative [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{\color{blue}{\left({x}^{3} \cdot 0.022222222222222223\right)} \cdot \left(0.022222222222222223 \cdot {x}^{3}\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
*-commutative [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{\left({x}^{3} \cdot 0.022222222222222223\right) \cdot \color{blue}{\left({x}^{3} \cdot 0.022222222222222223\right)}}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
swap-sqr [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{\color{blue}{\left({x}^{3} \cdot {x}^{3}\right) \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
pow-prod-up [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{\color{blue}{{x}^{\left(3 + 3\right)}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
metadata-eval [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{\color{blue}{6}} \cdot \left(0.022222222222222223 \cdot 0.022222222222222223\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
metadata-eval [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{6} \cdot \color{blue}{0.0004938271604938272}}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}
\] |
cancel-sign-sub-inv [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\color{blue}{0.3333333333333333 \cdot x + \left(-0.022222222222222223\right) \cdot {x}^{3}}}
\] |
fma-def [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\color{blue}{\mathsf{fma}\left(0.3333333333333333, x, \left(-0.022222222222222223\right) \cdot {x}^{3}\right)}}
\] |
metadata-eval [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, \color{blue}{-0.022222222222222223} \cdot {x}^{3}\right)}
\] |
Simplified50.2%
[Start]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)}
\] |
|---|---|
div-sub [<=]50.2 | \[ \color{blue}{\frac{0.1111111111111111 \cdot \left(x \cdot x\right) - {x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, -0.022222222222222223 \cdot {x}^{3}\right)}}
\] |
*-commutative [=>]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right) - {x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, \color{blue}{{x}^{3} \cdot -0.022222222222222223}\right)}
\] |
Applied egg-rr99.5%
[Start]50.2 | \[ \frac{0.1111111111111111 \cdot \left(x \cdot x\right) - {x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}
\] |
|---|---|
div-sub [=>]50.2 | \[ \color{blue}{\frac{0.1111111111111111 \cdot \left(x \cdot x\right)}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}}
\] |
associate-*r* [=>]50.2 | \[ \frac{\color{blue}{\left(0.1111111111111111 \cdot x\right) \cdot x}}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}
\] |
*-un-lft-identity [=>]50.2 | \[ \frac{\left(0.1111111111111111 \cdot x\right) \cdot x}{\color{blue}{1 \cdot \mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}
\] |
times-frac [=>]99.5 | \[ \color{blue}{\frac{0.1111111111111111 \cdot x}{1} \cdot \frac{x}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}} - \frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}
\] |
fma-neg [=>]99.5 | \[ \color{blue}{\mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}, -\frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)}
\] |
fma-udef [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\color{blue}{0.3333333333333333 \cdot x + {x}^{3} \cdot -0.022222222222222223}}, -\frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)
\] |
*-commutative [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\color{blue}{x \cdot 0.3333333333333333} + {x}^{3} \cdot -0.022222222222222223}, -\frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)
\] |
fma-def [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\color{blue}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}}, -\frac{{x}^{6} \cdot 0.0004938271604938272}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)
\] |
*-commutative [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -\frac{\color{blue}{0.0004938271604938272 \cdot {x}^{6}}}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)
\] |
*-un-lft-identity [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -\frac{0.0004938271604938272 \cdot {x}^{6}}{\color{blue}{1 \cdot \mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}}\right)
\] |
times-frac [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -\color{blue}{\frac{0.0004938271604938272}{1} \cdot \frac{{x}^{6}}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}}\right)
\] |
metadata-eval [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -\color{blue}{0.0004938271604938272} \cdot \frac{{x}^{6}}{\mathsf{fma}\left(0.3333333333333333, x, {x}^{3} \cdot -0.022222222222222223\right)}\right)
\] |
fma-udef [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -0.0004938271604938272 \cdot \frac{{x}^{6}}{\color{blue}{0.3333333333333333 \cdot x + {x}^{3} \cdot -0.022222222222222223}}\right)
\] |
*-commutative [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -0.0004938271604938272 \cdot \frac{{x}^{6}}{\color{blue}{x \cdot 0.3333333333333333} + {x}^{3} \cdot -0.022222222222222223}\right)
\] |
fma-def [=>]99.5 | \[ \mathsf{fma}\left(\frac{0.1111111111111111 \cdot x}{1}, \frac{x}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}, -0.0004938271604938272 \cdot \frac{{x}^{6}}{\color{blue}{\mathsf{fma}\left(x, 0.3333333333333333, {x}^{3} \cdot -0.022222222222222223\right)}}\right)
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 39808 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 704 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 192 |
herbie shell --seed 2023159
(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))))