Average Error: 59.9 → 0.4
Time: 1.7m
Precision: 64
\[-0.026 \lt x \land x \lt 0.026\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[(\left({x}^{5}\right) \cdot \frac{2}{945} + \left((x \cdot \left(\frac{1}{45} \cdot x\right) + \frac{1}{3})_* \cdot x\right))_*\]
\frac{1}{x} - \frac{1}{\tan x}
(\left({x}^{5}\right) \cdot \frac{2}{945} + \left((x \cdot \left(\frac{1}{45} \cdot x\right) + \frac{1}{3})_* \cdot x\right))_*
double f(double x) {
        double r13287947 = 1.0;
        double r13287948 = x;
        double r13287949 = r13287947 / r13287948;
        double r13287950 = tan(r13287948);
        double r13287951 = r13287947 / r13287950;
        double r13287952 = r13287949 - r13287951;
        return r13287952;
}

double f(double x) {
        double r13287953 = x;
        double r13287954 = 5.0;
        double r13287955 = pow(r13287953, r13287954);
        double r13287956 = 0.0021164021164021165;
        double r13287957 = 0.022222222222222223;
        double r13287958 = r13287957 * r13287953;
        double r13287959 = 0.3333333333333333;
        double r13287960 = fma(r13287953, r13287958, r13287959);
        double r13287961 = r13287960 * r13287953;
        double r13287962 = fma(r13287955, r13287956, r13287961);
        return r13287962;
}

Error

Bits error versus x

Target

Original59.9
Target0.1
Herbie0.4
\[\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.4

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

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

    \[\leadsto (\left({x}^{5}\right) \cdot \frac{2}{945} + \left((x \cdot \left(\frac{1}{45} \cdot x\right) + \frac{1}{3})_* \cdot x\right))_*\]

Reproduce

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