Average Error: 59.8 → 0.0
Time: 42.9s
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}{\mathsf{fma}\left(x \cdot x, \frac{-1}{5}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{75}, 3\right)\right)}\right)\]
\frac{1}{x} - \frac{1}{\tan x}
\mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\mathsf{fma}\left(x \cdot x, \frac{-1}{5}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{75}, 3\right)\right)}\right)
double f(double x) {
        double r2376052 = 1.0;
        double r2376053 = x;
        double r2376054 = r2376052 / r2376053;
        double r2376055 = tan(r2376053);
        double r2376056 = r2376052 / r2376055;
        double r2376057 = r2376054 - r2376056;
        return r2376057;
}

double f(double x) {
        double r2376058 = x;
        double r2376059 = 5.0;
        double r2376060 = pow(r2376058, r2376059);
        double r2376061 = 0.0021164021164021165;
        double r2376062 = r2376058 * r2376058;
        double r2376063 = -0.2;
        double r2376064 = r2376062 * r2376062;
        double r2376065 = 0.013333333333333334;
        double r2376066 = 3.0;
        double r2376067 = fma(r2376064, r2376065, r2376066);
        double r2376068 = fma(r2376062, r2376063, r2376067);
        double r2376069 = r2376058 / r2376068;
        double r2376070 = fma(r2376060, r2376061, r2376069);
        return r2376070;
}

Error

Bits error versus x

Target

Original59.8
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.8

    \[\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}{45} \cdot \left(x \cdot x\right) + \frac{1}{3}\right)\right)}\]
  4. Using strategy rm
  5. Applied flip-+0.3

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, x \cdot \color{blue}{\frac{\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 \frac{1}{3}}{\frac{1}{45} \cdot \left(x \cdot x\right) - \frac{1}{3}}}\right)\]
  6. Applied associate-*r/0.3

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \color{blue}{\frac{x \cdot \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 \frac{1}{3}\right)}{\frac{1}{45} \cdot \left(x \cdot x\right) - \frac{1}{3}}}\right)\]
  7. Using strategy rm
  8. Applied associate-/l*0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \color{blue}{\frac{x}{\frac{\frac{1}{45} \cdot \left(x \cdot x\right) - \frac{1}{3}}{\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 \frac{1}{3}}}}\right)\]
  9. Simplified0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\color{blue}{\frac{1}{\mathsf{fma}\left(x \cdot x, \frac{1}{45}, \frac{1}{3}\right)}}}\right)\]
  10. Taylor expanded around 0 0.0

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

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\color{blue}{\mathsf{fma}\left(x \cdot x, \frac{-1}{5}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{75}, 3\right)\right)}}\right)\]
  12. Final simplification0.0

    \[\leadsto \mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\mathsf{fma}\left(x \cdot x, \frac{-1}{5}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{75}, 3\right)\right)}\right)\]

Reproduce

herbie shell --seed 2019138 +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))))