Average Error: 60.0 → 0.4
Time: 23.6s
Precision: 64
\[-0.026 \lt x \land x \lt 0.026\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\mathsf{fma}\left(\frac{2}{945}, {x}^{5}, \mathsf{fma}\left(\frac{1}{45}, \left(x \cdot x\right) \cdot x, x \cdot \frac{1}{3}\right)\right)\]
\frac{1}{x} - \frac{1}{\tan x}
\mathsf{fma}\left(\frac{2}{945}, {x}^{5}, \mathsf{fma}\left(\frac{1}{45}, \left(x \cdot x\right) \cdot x, x \cdot \frac{1}{3}\right)\right)
double f(double x) {
        double r1593016 = 1.0;
        double r1593017 = x;
        double r1593018 = r1593016 / r1593017;
        double r1593019 = tan(r1593017);
        double r1593020 = r1593016 / r1593019;
        double r1593021 = r1593018 - r1593020;
        return r1593021;
}

double f(double x) {
        double r1593022 = 0.0021164021164021165;
        double r1593023 = x;
        double r1593024 = 5.0;
        double r1593025 = pow(r1593023, r1593024);
        double r1593026 = 0.022222222222222223;
        double r1593027 = r1593023 * r1593023;
        double r1593028 = r1593027 * r1593023;
        double r1593029 = 0.3333333333333333;
        double r1593030 = r1593023 * r1593029;
        double r1593031 = fma(r1593026, r1593028, r1593030);
        double r1593032 = fma(r1593022, r1593025, r1593031);
        return r1593032;
}

Error

Bits error versus x

Target

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

    \[\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}{\mathsf{fma}\left(\frac{2}{945}, {x}^{5}, \mathsf{fma}\left(\frac{1}{45}, \left(x \cdot x\right) \cdot x, x \cdot \frac{1}{3}\right)\right)}\]
  4. Final simplification0.4

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

Reproduce

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