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))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original59.9
Target0.1
Herbie0.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
Error0.6
Cost71424
\[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
Error0.6
Cost58496
\[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
Error0.4
Cost58496
\[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
Error0.4
Cost58432
\[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
Error1.7
Cost52352
\[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
Error32.3
Cost52096
\[\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
Error1.0
Cost52096
\[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
Error0.4
Cost45696
\[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
Error0.6
Cost45632
\[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
Error62.2
Cost39360
\[\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
Error62.2
Cost39360
\[\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
Error61.9
Cost39360
\[\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
Error32.3
Cost39296
\[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
Error61.6
Cost39232
\[\frac{1}{x} - \frac{1}{\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}} \cdot \sqrt[3]{\frac{1}{\tan x}}\]
Alternative 15
Error0.6
Cost39168
\[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
Error1.0
Cost39168
\[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
Error61.7
Cost39104
\[\frac{1}{x} - \frac{\frac{1}{\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}}}{\sqrt[3]{\tan x}}\]
Alternative 18
Error62.6
Cost33600
\[\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
Error32.3
Cost32768
\[0.022222222222222223 \cdot {x}^{3} + \left(\sqrt{0.3333333333333333} \cdot \sqrt{x}\right) \cdot \left(\sqrt{0.3333333333333333} \cdot \sqrt{x}\right)\]
Alternative 20
Error0.5
Cost32704
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot {\left(\sqrt{0.3333333333333333}\right)}^{1.5}\right)\]
Alternative 21
Error1.6
Cost26624
\[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
Error0.5
Cost26496
\[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
Error1.6
Cost26368
\[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
Error62.4
Cost26304
\[\frac{1}{x} - \frac{1}{\sqrt{\tan x}} \cdot \frac{1}{\sqrt{\tan x}}\]
Alternative 25
Error62.3
Cost26304
\[\frac{1}{x} - \sqrt{\frac{1}{\tan x}} \cdot \sqrt{\frac{1}{\tan x}}\]
Alternative 26
Error62.4
Cost26176
\[\frac{1}{x} - \frac{\frac{1}{\sqrt{\tan x}}}{\sqrt{\tan x}}\]
Alternative 27
Error41.7
Cost20864
\[\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
Error41.8
Cost20864
\[\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
Error62.1
Cost20416
\[\frac{\frac{\frac{1}{x}}{x} - \frac{\frac{1}{\tan x}}{\tan x}}{\frac{1}{x} + \frac{1}{\tan x}}\]
Alternative 30
Error32.2
Cost19968
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333 \cdot x} \cdot \sqrt{0.3333333333333333 \cdot x}\]
Alternative 31
Error0.8
Cost19840
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{0.3333333333333333} \cdot \left(\sqrt{0.3333333333333333} \cdot x\right)\]
Alternative 32
Error32.2
Cost19840
\[0.022222222222222223 \cdot {x}^{3} + \sqrt{x} \cdot \left(0.3333333333333333 \cdot \sqrt{x}\right)\]
Alternative 33
Error39.6
Cost19776
\[0.022222222222222223 \cdot {x}^{3} + \sqrt[3]{{\left(0.3333333333333333 \cdot x\right)}^{3}}\]
Alternative 34
Error39.6
Cost19776
\[0.022222222222222223 \cdot {x}^{3} + \sqrt[3]{{x}^{3} \cdot 0.037037037037037035}\]
Alternative 35
Error62.6
Cost19712
\[\frac{1}{x} - \sqrt[3]{{\left(\frac{1}{\tan x}\right)}^{3}}\]
Alternative 36
Error34.8
Cost19712
\[0.022222222222222223 \cdot {x}^{3} + e^{\log \left(0.3333333333333333 \cdot x\right)}\]
Alternative 37
Error59.9
Cost19648
\[\log \left(e^{\frac{1}{x} - \frac{1}{\tan x}}\right)\]
Alternative 38
Error62.8
Cost19584
\[\frac{1}{x} - e^{-\log \tan x}\]
Alternative 39
Error29.3
Cost14016
\[\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
Error29.3
Cost14016
\[\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
Error0.8
Cost13632
\[\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
Error59.9
Cost13248
\[\frac{1}{x} - \frac{\cos x}{\sin x}\]
Alternative 43
Error62.0
Cost13248
\[\frac{\tan x - x}{x \cdot \tan x}\]
Alternative 44
Error0.4
Cost6912
\[0.022222222222222223 \cdot {x}^{3} + 0.3333333333333333 \cdot x\]
Alternative 45
Error59.9
Cost6848
\[\frac{1}{x} - \frac{1}{\tan x}\]
Alternative 46
Error0.4
Cost704
\[0.3333333333333333 \cdot x + x \cdot \left(0.022222222222222223 \cdot \left(x \cdot x\right)\right)\]
Alternative 47
Error0.7
Cost192
\[0.3333333333333333 \cdot x\]
Alternative 48
Error61.6
Cost64
\[1\]
Alternative 49
Error60.5
Cost64
\[0\]
Alternative 50
Error61.6
Cost64
\[-1\]

Error

Derivation

  1. Initial program 59.9

    \[\frac{1}{x} - \frac{1}{\tan x}\]
  2. Taylor expanded around 0 0.4

    \[\leadsto \color{blue}{0.3333333333333333 \cdot x + 0.022222222222222223 \cdot {x}^{3}}\]
  3. Simplified0.4

    \[\leadsto \color{blue}{x \cdot 0.3333333333333333 + 0.022222222222222223 \cdot {x}^{3}}\]
  4. Using strategy rm
  5. 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}\]
  6. 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}\]
  7. Using strategy rm
  8. 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}\]
  9. 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}\]
  10. 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}\]
  11. Using strategy rm
  12. 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}\]
  13. 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}\]
  14. 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)}\]
  15. 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))))