Average Error: 60.0 → 0.0
Time: 1.4m
Precision: 64
\[-0.026 \lt x \land x \lt 0.026\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\frac{x}{\frac{1}{\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3}}} + {x}^{5} \cdot \frac{2}{945}\]
\frac{1}{x} - \frac{1}{\tan x}
\frac{x}{\frac{1}{\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3}}} + {x}^{5} \cdot \frac{2}{945}
double f(double x) {
        double r2522511 = 1.0;
        double r2522512 = x;
        double r2522513 = r2522511 / r2522512;
        double r2522514 = tan(r2522512);
        double r2522515 = r2522511 / r2522514;
        double r2522516 = r2522513 - r2522515;
        return r2522516;
}

double f(double x) {
        double r2522517 = x;
        double r2522518 = 1.0;
        double r2522519 = 0.022222222222222223;
        double r2522520 = r2522517 * r2522517;
        double r2522521 = r2522519 * r2522520;
        double r2522522 = 0.3333333333333333;
        double r2522523 = r2522521 + r2522522;
        double r2522524 = r2522518 / r2522523;
        double r2522525 = r2522517 / r2522524;
        double r2522526 = 5.0;
        double r2522527 = pow(r2522517, r2522526);
        double r2522528 = 0.0021164021164021165;
        double r2522529 = r2522527 * r2522528;
        double r2522530 = r2522525 + r2522529;
        return r2522530;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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

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

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

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

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

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

Reproduce

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