Average Error: 59.9 → 0.4
Time: 23.6s
Precision: binary64
Cost: 58432
\[-0.026 < x \land x < 0.026\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
↓
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\right)\]
\frac{1}{x} - \frac{1}{\tan x}↓
0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\right)(FPCore (x) :precision binary64 (- (/ 1.0 x) (/ 1.0 (tan x))))
↓
(FPCore (x)
:precision binary64
(+
(* 0.022222222222222223 (pow x 3.0))
(*
(sqrt (sqrt (sqrt 0.3333333333333333)))
(*
(sqrt (sqrt (sqrt 0.3333333333333333)))
(* x (pow (sqrt 0.3333333333333333) 1.5))))))double code(double x) {
return (1.0 / x) - (1.0 / tan(x));
}
↓
double code(double x) {
return (0.022222222222222223 * pow(x, 3.0)) + (sqrt(sqrt(sqrt(0.3333333333333333))) * (sqrt(sqrt(sqrt(0.3333333333333333))) * (x * pow(sqrt(0.3333333333333333), 1.5))));
}
Try it out
Enter valid numbers for all inputs
Target
| Original | 59.9 |
|---|
| Target | 0.1 |
|---|
| Herbie | 0.4 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\left|x\right| < 0.026:\\
\;\;\;\;\frac{x}{3} \cdot \left(1 + \frac{x \cdot x}{15}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\
\end{array}\]
Alternatives
| Alternative 1 |
|---|
| Error | 0.6 |
|---|
| Cost | 71424 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(\left(x \cdot {\left(\sqrt[3]{\sqrt{0.3333333333333333}} \cdot \sqrt[3]{\sqrt{0.3333333333333333}}\right)}^{1.5}\right) \cdot {\left(\sqrt[3]{\sqrt{0.3333333333333333}}\right)}^{1.5}\right)\]
| Alternative 2 |
|---|
| Error | 0.6 |
|---|
| Cost | 58496 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(\left(x \cdot {\left(\left|\sqrt[3]{0.3333333333333333}\right|\right)}^{1.5}\right) \cdot {\left(\sqrt{\sqrt[3]{0.3333333333333333}}\right)}^{1.5}\right)\]
| Alternative 3 |
|---|
| Error | 0.4 |
|---|
| Cost | 58496 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left({\left(\sqrt{\sqrt{0.3333333333333333}}\right)}^{1.5} \cdot \left(x \cdot {\left(\sqrt{\sqrt{0.3333333333333333}}\right)}^{1.5}\right)\right)\]
| Alternative 4 |
|---|
| Error | 0.4 |
|---|
| Cost | 58432 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(\left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right) \cdot \sqrt{\sqrt{\sqrt{0.3333333333333333}}}\right)\]
| Alternative 5 |
|---|
| Error | 1.7 |
|---|
| Cost | 52352 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt[3]{\sqrt{0.3333333333333333} \cdot x} \cdot \left(\sqrt[3]{\sqrt{0.3333333333333333} \cdot x} \cdot \sqrt[3]{\sqrt{0.3333333333333333} \cdot x}\right)\right)\]
| Alternative 6 |
|---|
| Error | 32.3 |
|---|
| Cost | 52096 |
|---|
\[\sqrt{0.3333333333333333} \cdot \left(\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{x}\right) \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{x}\right)\right) + 0.022222222222222223 \cdot {x}^{3}\]
| Alternative 7 |
|---|
| Error | 1.0 |
|---|
| Cost | 52096 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt[3]{\sqrt{0.3333333333333333}} \cdot \left(x \cdot \left(\sqrt[3]{\sqrt{0.3333333333333333}} \cdot \sqrt[3]{\sqrt{0.3333333333333333}}\right)\right)\right)\]
| Alternative 8 |
|---|
| Error | 0.4 |
|---|
| Cost | 45696 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left({\left(\sqrt{0.3333333333333333}\right)}^{0.75} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{0.75}\right)\right)\]
| Alternative 9 |
|---|
| Error | 0.6 |
|---|
| Cost | 45632 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(\left(\sqrt{0.3333333333333333} \cdot x\right) \cdot \sqrt[3]{{\left(\sqrt{0.3333333333333333}\right)}^{1.5}}\right)\]
| Alternative 10 |
|---|
| Error | 62.2 |
|---|
| Cost | 39360 |
|---|
\[\left(\sqrt{\frac{1}{\tan x}} + \frac{1}{\sqrt{x}}\right) \cdot \left(\frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\tan x}}\right)\]
| Alternative 11 |
|---|
| Error | 62.2 |
|---|
| Cost | 39360 |
|---|
\[\left(\frac{1}{\sqrt{\tan x}} + \sqrt{\frac{1}{x}}\right) \cdot \left(\sqrt{\frac{1}{x}} - \frac{1}{\sqrt{\tan x}}\right)\]
| Alternative 12 |
|---|
| Error | 61.9 |
|---|
| Cost | 39360 |
|---|
\[\left(\sqrt{\frac{1}{\tan x}} + \sqrt{\frac{1}{x}}\right) \cdot \left(\sqrt{\frac{1}{x}} - \sqrt{\frac{1}{\tan x}}\right)\]
| Alternative 13 |
|---|
| Error | 32.3 |
|---|
| Cost | 39296 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt{\sqrt{0.3333333333333333} \cdot x} \cdot \sqrt{\sqrt{0.3333333333333333} \cdot x}\right)\]
| Alternative 14 |
|---|
| Error | 61.6 |
|---|
| Cost | 39232 |
|---|
\[\frac{1}{x} - \frac{1}{\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}} \cdot \sqrt[3]{\frac{1}{\tan x}}\]
| Alternative 15 |
|---|
| Error | 0.6 |
|---|
| Cost | 39168 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot x\right)\right)\]
| Alternative 16 |
|---|
| Error | 1.0 |
|---|
| Cost | 39168 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\left(x \cdot \left|\sqrt[3]{0.3333333333333333}\right|\right) \cdot \sqrt{\sqrt[3]{0.3333333333333333}}\right)\]
| Alternative 17 |
|---|
| Error | 61.7 |
|---|
| Cost | 39104 |
|---|
\[\frac{1}{x} - \frac{\frac{1}{\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}}}{\sqrt[3]{\tan x}}\]
| Alternative 18 |
|---|
| Error | 62.6 |
|---|
| Cost | 33600 |
|---|
\[\frac{{\left(\frac{1}{x}\right)}^{3} - {\left(\frac{1}{\tan x}\right)}^{3}}{\frac{\frac{1}{x}}{x} + \frac{\frac{1}{x} + \frac{1}{\tan x}}{\tan x}}\]
| Alternative 19 |
|---|
| Error | 32.3 |
|---|
| Cost | 32768 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \left(\sqrt{0.3333333333333333} \cdot \sqrt{x}\right) \cdot \left(\sqrt{0.3333333333333333} \cdot \sqrt{x}\right)\]
| Alternative 20 |
|---|
| Error | 0.5 |
|---|
| Cost | 32704 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\]
| Alternative 21 |
|---|
| Error | 1.6 |
|---|
| Cost | 26624 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt[3]{0.3333333333333333 \cdot x} \cdot \left(\sqrt[3]{0.3333333333333333 \cdot x} \cdot \sqrt[3]{0.3333333333333333 \cdot x}\right)\]
| Alternative 22 |
|---|
| Error | 0.5 |
|---|
| Cost | 26496 |
|---|
\[x \cdot \left(0.022222222222222223 \cdot \left(x \cdot x\right)\right) + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\]
| Alternative 23 |
|---|
| Error | 1.6 |
|---|
| Cost | 26368 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{x}\right)\]
| Alternative 24 |
|---|
| Error | 62.4 |
|---|
| Cost | 26304 |
|---|
\[\frac{1}{x} - \frac{1}{\sqrt{\tan x}} \cdot \frac{1}{\sqrt{\tan x}}\]
| Alternative 25 |
|---|
| Error | 62.3 |
|---|
| Cost | 26304 |
|---|
\[\frac{1}{x} - \sqrt{\frac{1}{\tan x}} \cdot \sqrt{\frac{1}{\tan x}}\]
| Alternative 26 |
|---|
| Error | 62.4 |
|---|
| Cost | 26176 |
|---|
\[\frac{1}{x} - \frac{\frac{1}{\sqrt{\tan x}}}{\sqrt{\tan x}}\]
| Alternative 27 |
|---|
| Error | 41.7 |
|---|
| Cost | 20864 |
|---|
\[\frac{{x}^{3} \cdot 0.037037037037037035 + 1.0973936899862826 \cdot 10^{-05} \cdot {x}^{9}}{\left(x \cdot x\right) \cdot \left(0.1111111111111111 + x \cdot \left({x}^{3} \cdot 0.0004938271604938272 + x \cdot -0.007407407407407408\right)\right)}\]
| Alternative 28 |
|---|
| Error | 41.8 |
|---|
| Cost | 20864 |
|---|
\[\frac{1.0973936899862826 \cdot 10^{-05} \cdot {x}^{9} + {\left(0.3333333333333333 \cdot x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(0.0004938271604938272 \cdot {x}^{4} - \left(x \cdot \left(x \cdot 0.007407407407407408\right) + -0.1111111111111111\right)\right)}\]
| Alternative 29 |
|---|
| Error | 62.1 |
|---|
| Cost | 20416 |
|---|
\[\frac{\frac{\frac{1}{x}}{x} - \frac{\frac{1}{\tan x}}{\tan x}}{\frac{1}{x} + \frac{1}{\tan x}}\]
| Alternative 30 |
|---|
| Error | 32.2 |
|---|
| Cost | 19968 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333 \cdot x} \cdot \sqrt{0.3333333333333333 \cdot x}\]
| Alternative 31 |
|---|
| Error | 0.8 |
|---|
| Cost | 19840 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt{0.3333333333333333} \cdot x\right)\]
| Alternative 32 |
|---|
| Error | 32.2 |
|---|
| Cost | 19840 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{x} \cdot \left(0.3333333333333333 \cdot \sqrt{x}\right)\]
| Alternative 33 |
|---|
| Error | 39.6 |
|---|
| Cost | 19776 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt[3]{{\left(0.3333333333333333 \cdot x\right)}^{3}}\]
| Alternative 34 |
|---|
| Error | 39.6 |
|---|
| Cost | 19776 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + \sqrt[3]{{x}^{3} \cdot 0.037037037037037035}\]
| Alternative 35 |
|---|
| Error | 62.6 |
|---|
| Cost | 19712 |
|---|
\[\frac{1}{x} - \sqrt[3]{{\left(\frac{1}{\tan x}\right)}^{3}}\]
| Alternative 36 |
|---|
| Error | 34.8 |
|---|
| Cost | 19712 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + e^{\log \left(0.3333333333333333 \cdot x\right)}\]
| Alternative 37 |
|---|
| Error | 59.9 |
|---|
| Cost | 19648 |
|---|
\[\log \left(e^{\frac{1}{x} - \frac{1}{\tan x}}\right)\]
| Alternative 38 |
|---|
| Error | 62.8 |
|---|
| Cost | 19584 |
|---|
\[\frac{1}{x} - e^{-\log \tan x}\]
| Alternative 39 |
|---|
| Error | 29.3 |
|---|
| Cost | 14016 |
|---|
\[\frac{\left(x \cdot x\right) \cdot 0.1111111111111111 + {x}^{6} \cdot -0.0004938271604938272}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}\]
| Alternative 40 |
|---|
| Error | 29.3 |
|---|
| Cost | 14016 |
|---|
\[\frac{{x}^{6} \cdot -0.0004938271604938272 + x \cdot \left(x \cdot 0.1111111111111111\right)}{0.3333333333333333 \cdot x - 0.022222222222222223 \cdot {x}^{3}}\]
| Alternative 41 |
|---|
| Error | 0.8 |
|---|
| Cost | 13632 |
|---|
\[\sqrt{0.3333333333333333} \cdot \left(\sqrt{0.3333333333333333} \cdot x\right) + x \cdot \left(0.022222222222222223 \cdot \left(x \cdot x\right)\right)\]
| Alternative 42 |
|---|
| Error | 59.9 |
|---|
| Cost | 13248 |
|---|
\[\frac{1}{x} - \frac{\cos x}{\sin x}\]
| Alternative 43 |
|---|
| Error | 62.0 |
|---|
| Cost | 13248 |
|---|
\[\frac{\tan x - x}{x \cdot \tan x}\]
| Alternative 44 |
|---|
| Error | 0.4 |
|---|
| Cost | 6912 |
|---|
\[0.022222222222222223 \cdot {x}^{3} + 0.3333333333333333 \cdot x\]
| Alternative 45 |
|---|
| Error | 59.9 |
|---|
| Cost | 6848 |
|---|
\[\frac{1}{x} - \frac{1}{\tan x}\]
| Alternative 46 |
|---|
| Error | 0.4 |
|---|
| Cost | 704 |
|---|
\[0.3333333333333333 \cdot x + x \cdot \left(0.022222222222222223 \cdot \left(x \cdot x\right)\right)\]
| Alternative 47 |
|---|
| Error | 0.7 |
|---|
| Cost | 192 |
|---|
\[0.3333333333333333 \cdot x\]
| Alternative 48 |
|---|
| Error | 61.6 |
|---|
| Cost | 64 |
|---|
\[1\]
| Alternative 49 |
|---|
| Error | 60.5 |
|---|
| Cost | 64 |
|---|
\[0\]
| Alternative 50 |
|---|
| Error | 61.6 |
|---|
| Cost | 64 |
|---|
\[-1\]
Error

Derivation
Initial program 59.9
\[\frac{1}{x} - \frac{1}{\tan x}\]
Taylor expanded around 0 0.4
\[\leadsto \color{blue}{0.3333333333333333 \cdot x + 0.022222222222222223 \cdot {x}^{3}}\]
Simplified0.4
\[\leadsto \color{blue}{x \cdot 0.3333333333333333 + 0.022222222222222223 \cdot {x}^{3}}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_24240.4
\[\leadsto x \cdot \color{blue}{\left(\sqrt{0.3333333333333333} \cdot \sqrt{0.3333333333333333}\right)} + 0.022222222222222223 \cdot {x}^{3}\]
Applied associate-*r*_binary64_23420.8
\[\leadsto \color{blue}{\left(x \cdot \sqrt{0.3333333333333333}\right) \cdot \sqrt{0.3333333333333333}} + 0.022222222222222223 \cdot {x}^{3}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_24240.8
\[\leadsto \left(x \cdot \sqrt{0.3333333333333333}\right) \cdot \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{\sqrt{0.3333333333333333}}\right)} + 0.022222222222222223 \cdot {x}^{3}\]
Applied associate-*r*_binary64_23420.6
\[\leadsto \color{blue}{\left(\left(x \cdot \sqrt{0.3333333333333333}\right) \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{0.3333333333333333}}} + 0.022222222222222223 \cdot {x}^{3}\]
Simplified0.5
\[\leadsto \color{blue}{\left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)} \cdot \sqrt{\sqrt{0.3333333333333333}} + 0.022222222222222223 \cdot {x}^{3}\]
- Using strategy
rm Applied add-sqr-sqrt_binary64_24240.5
\[\leadsto \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right) \cdot \color{blue}{\left(\sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \sqrt{\sqrt{\sqrt{0.3333333333333333}}}\right)} + 0.022222222222222223 \cdot {x}^{3}\]
Applied associate-*r*_binary64_23420.4
\[\leadsto \color{blue}{\left(\left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right) \cdot \sqrt{\sqrt{\sqrt{0.3333333333333333}}}\right) \cdot \sqrt{\sqrt{\sqrt{0.3333333333333333}}}} + 0.022222222222222223 \cdot {x}^{3}\]
Simplified0.4
\[\leadsto \color{blue}{0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(\left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right) \cdot \sqrt{\sqrt{\sqrt{0.3333333333333333}}}\right)}\]
Final simplification0.4
\[\leadsto 0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt{0.3333333333333333}}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\right)\]
Reproduce
herbie shell --seed 2021042
(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))))