Average Error: 59.9 → 0.0
Time: 32.3s
Precision: 64
\[-0.026 \lt x \land x \lt 0.026\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\frac{\sqrt[3]{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)\right)}}{\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \frac{1}{91125}\right) \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{27}\right)}}\right)\]
\frac{1}{x} - \frac{1}{\tan x}
\mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\frac{\sqrt[3]{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)\right)}}{\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \frac{1}{91125}\right) \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{27}\right)}}\right)
double f(double x) {
        double r2169049 = 1.0;
        double r2169050 = x;
        double r2169051 = r2169049 / r2169050;
        double r2169052 = tan(r2169050);
        double r2169053 = r2169049 / r2169052;
        double r2169054 = r2169051 - r2169053;
        return r2169054;
}

double f(double x) {
        double r2169055 = x;
        double r2169056 = 5.0;
        double r2169057 = pow(r2169055, r2169056);
        double r2169058 = 0.0021164021164021165;
        double r2169059 = r2169055 * r2169055;
        double r2169060 = 0.0004938271604938272;
        double r2169061 = -0.007407407407407408;
        double r2169062 = fma(r2169059, r2169060, r2169061);
        double r2169063 = 0.1111111111111111;
        double r2169064 = fma(r2169059, r2169062, r2169063);
        double r2169065 = r2169064 * r2169064;
        double r2169066 = r2169064 * r2169065;
        double r2169067 = cbrt(r2169066);
        double r2169068 = 1.0973936899862826e-05;
        double r2169069 = r2169059 * r2169068;
        double r2169070 = r2169069 * r2169059;
        double r2169071 = 0.037037037037037035;
        double r2169072 = fma(r2169070, r2169059, r2169071);
        double r2169073 = r2169067 / r2169072;
        double r2169074 = r2169055 / r2169073;
        double r2169075 = fma(r2169057, r2169058, r2169074);
        return r2169075;
}

Error

Bits error versus x

Target

Original59.9
Target0.1
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;\left|x\right| \lt 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}\]

Derivation

  1. Initial program 59.9

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

    \[\leadsto \color{blue}{\frac{1}{3} \cdot x + \left(\frac{1}{45} \cdot {x}^{3} + \frac{2}{945} \cdot {x}^{5}\right)}\]
  3. Simplified0.3

    \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{5}, \frac{2}{945}, x \cdot \left(\frac{1}{3} + \frac{1}{45} \cdot \left(x \cdot x\right)\right)\right)}\]
  4. Using strategy rm
  5. Applied flip3-+1.2

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, x \cdot \color{blue}{\frac{{\frac{1}{3}}^{3} + {\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)}^{3}}{\frac{1}{3} \cdot \frac{1}{3} + \left(\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) - \frac{1}{3} \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)\right)}}\right)\]
  6. Applied associate-*r/1.1

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \color{blue}{\frac{x \cdot \left({\frac{1}{3}}^{3} + {\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)}^{3}\right)}{\frac{1}{3} \cdot \frac{1}{3} + \left(\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) - \frac{1}{3} \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)\right)}}\right)\]
  7. Simplified0.3

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{\color{blue}{x \cdot \mathsf{fma}\left(\frac{1}{91125}, \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), \frac{1}{27}\right)}}{\frac{1}{3} \cdot \frac{1}{3} + \left(\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) - \frac{1}{3} \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)\right)}\right)\]
  8. Using strategy rm
  9. Applied associate-/l*0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \color{blue}{\frac{x}{\frac{\frac{1}{3} \cdot \frac{1}{3} + \left(\left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) - \frac{1}{3} \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)\right)}{\mathsf{fma}\left(\frac{1}{91125}, \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), \frac{1}{27}\right)}}}\right)\]
  10. Simplified0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\color{blue}{\frac{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)}{\mathsf{fma}\left(\left(\frac{1}{91125} \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{27}\right)}}}\right)\]
  11. Using strategy rm
  12. Applied add-cbrt-cube0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\frac{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)}}}{\mathsf{fma}\left(\left(\frac{1}{91125} \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{27}\right)}}\right)\]
  13. Final simplification0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\frac{\sqrt[3]{\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right) \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \frac{1}{2025}, \frac{-1}{135}\right), \frac{1}{9}\right)\right)}}{\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \frac{1}{91125}\right) \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{27}\right)}}\right)\]

Reproduce

herbie shell --seed 2019135 +o rules:numerics
(FPCore (x)
  :name "invcot (example 3.9)"
  :pre (and (< -0.026 x) (< x 0.026))

  :herbie-target
  (if (< (fabs x) 0.026) (* (/ x 3) (+ 1 (/ (* x x) 15))) (- (/ 1 x) (/ 1 (tan x))))

  (- (/ 1 x) (/ 1 (tan x))))