Average Error: 60.0 → 0.0
Time: 44.6s
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{1}{\mathsf{fma}\left(x \cdot x, \frac{1}{45}, \frac{1}{3}\right)}}\right)\]
\frac{1}{x} - \frac{1}{\tan x}
\mathsf{fma}\left({x}^{5}, \frac{2}{945}, \frac{x}{\frac{1}{\mathsf{fma}\left(x \cdot x, \frac{1}{45}, \frac{1}{3}\right)}}\right)
double f(double x) {
        double r3000615 = 1.0;
        double r3000616 = x;
        double r3000617 = r3000615 / r3000616;
        double r3000618 = tan(r3000616);
        double r3000619 = r3000615 / r3000618;
        double r3000620 = r3000617 - r3000619;
        return r3000620;
}

double f(double x) {
        double r3000621 = x;
        double r3000622 = 5.0;
        double r3000623 = pow(r3000621, r3000622);
        double r3000624 = 0.0021164021164021165;
        double r3000625 = 1.0;
        double r3000626 = r3000621 * r3000621;
        double r3000627 = 0.022222222222222223;
        double r3000628 = 0.3333333333333333;
        double r3000629 = fma(r3000626, r3000627, r3000628);
        double r3000630 = r3000625 / r3000629;
        double r3000631 = r3000621 / r3000630;
        double r3000632 = fma(r3000623, r3000624, r3000631);
        return r3000632;
}

Error

Bits error versus x

Target

Original60.0
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 60.0

    \[\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(x \cdot \left(x \cdot \frac{1}{45}\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(x \cdot \left(x \cdot \frac{1}{45}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{1}{45}\right)\right) - \frac{1}{3} \cdot \frac{1}{3}}{x \cdot \left(x \cdot \frac{1}{45}\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(x \cdot \left(x \cdot \frac{1}{45}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{1}{45}\right)\right) - \frac{1}{3} \cdot \frac{1}{3}\right)}{x \cdot \left(x \cdot \frac{1}{45}\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{x \cdot \left(x \cdot \frac{1}{45}\right) - \frac{1}{3}}{\left(x \cdot \left(x \cdot \frac{1}{45}\right)\right) \cdot \left(x \cdot \left(x \cdot \frac{1}{45}\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. Final simplification0.0

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

Reproduce

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