Average Error: 59.9 → 0.3
Time: 47.8s
Precision: 64
\[-0.026 \lt x \land x \lt 0.026\]
\[\frac{1.0}{x} - \frac{1.0}{\tan x}\]
\[\mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \frac{x}{\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - 0.3333333333333333 \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)\right)\]
\frac{1.0}{x} - \frac{1.0}{\tan x}
\mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \frac{x}{\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - 0.3333333333333333 \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)\right)
double f(double x) {
        double r5286423 = 1.0;
        double r5286424 = x;
        double r5286425 = r5286423 / r5286424;
        double r5286426 = tan(r5286424);
        double r5286427 = r5286423 / r5286426;
        double r5286428 = r5286425 - r5286427;
        return r5286428;
}

double f(double x) {
        double r5286429 = 0.0021164021164021165;
        double r5286430 = x;
        double r5286431 = 5.0;
        double r5286432 = pow(r5286430, r5286431);
        double r5286433 = 0.022222222222222223;
        double r5286434 = r5286433 * r5286430;
        double r5286435 = r5286430 * r5286434;
        double r5286436 = r5286435 * r5286435;
        double r5286437 = 0.3333333333333333;
        double r5286438 = r5286437 * r5286437;
        double r5286439 = r5286437 * r5286435;
        double r5286440 = r5286438 - r5286439;
        double r5286441 = r5286436 + r5286440;
        double r5286442 = r5286430 / r5286441;
        double r5286443 = r5286436 * r5286435;
        double r5286444 = fma(r5286437, r5286438, r5286443);
        double r5286445 = r5286442 * r5286444;
        double r5286446 = fma(r5286429, r5286432, r5286445);
        return r5286446;
}

Error

Bits error versus x

Target

Original59.9
Target0.1
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;\left|x\right| \lt 0.026:\\ \;\;\;\;\frac{x}{3.0} \cdot \left(1.0 + \frac{x \cdot x}{15.0}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1.0}{x} - \frac{1.0}{\tan x}\\ \end{array}\]

Derivation

  1. Initial program 59.9

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

    \[\leadsto \color{blue}{0.3333333333333333 \cdot x + \left(0.022222222222222223 \cdot {x}^{3} + 0.0021164021164021165 \cdot {x}^{5}\right)}\]
  3. Simplified0.3

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.0021164021164021165, {x}^{5}, x \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right) + 0.3333333333333333\right)\right)}\]
  4. Using strategy rm
  5. Applied flip3-+1.2

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

    \[\leadsto \mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \color{blue}{\frac{x \cdot \left({\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right)}^{3} + {0.3333333333333333}^{3}\right)}{\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot 0.3333333333333333\right)}}\right)\]
  7. Simplified0.3

    \[\leadsto \mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \frac{\color{blue}{\mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right)\right)\right) \cdot x}}{\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot 0.3333333333333333\right)}\right)\]
  8. Using strategy rm
  9. Applied *-un-lft-identity0.3

    \[\leadsto \mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \frac{\mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right)\right)\right) \cdot x}{\color{blue}{1 \cdot \left(\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot 0.3333333333333333\right)\right)}}\right)\]
  10. Applied times-frac0.3

    \[\leadsto \mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \color{blue}{\frac{\mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right)\right)\right)}{1} \cdot \frac{x}{\left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - \left(x \cdot \left(x \cdot 0.022222222222222223\right)\right) \cdot 0.3333333333333333\right)}}\right)\]
  11. Final simplification0.3

    \[\leadsto \mathsf{fma}\left(0.0021164021164021165, {x}^{5}, \frac{x}{\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) + \left(0.3333333333333333 \cdot 0.3333333333333333 - 0.3333333333333333 \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)} \cdot \mathsf{fma}\left(0.3333333333333333, 0.3333333333333333 \cdot 0.3333333333333333, \left(\left(x \cdot \left(0.022222222222222223 \cdot x\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right) \cdot \left(x \cdot \left(0.022222222222222223 \cdot x\right)\right)\right)\right)\]

Reproduce

herbie shell --seed 2019165 +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.0) (+ 1.0 (/ (* x x) 15.0))) (- (/ 1.0 x) (/ 1.0 (tan x))))

  (- (/ 1.0 x) (/ 1.0 (tan x))))