Average Error: 60.0 → 0.3
Time: 19.2s
Precision: 64
\[-0.0259999999999999988 \lt x \land x \lt 0.0259999999999999988\]
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\mathsf{fma}\left(0.333333333333333315, x, \mathsf{fma}\left(0.0222222222222222231, {x}^{3}, 0.00211640211640211654 \cdot {x}^{5}\right)\right)\]
\frac{1}{x} - \frac{1}{\tan x}
\mathsf{fma}\left(0.333333333333333315, x, \mathsf{fma}\left(0.0222222222222222231, {x}^{3}, 0.00211640211640211654 \cdot {x}^{5}\right)\right)
double f(double x) {
        double r43087 = 1.0;
        double r43088 = x;
        double r43089 = r43087 / r43088;
        double r43090 = tan(r43088);
        double r43091 = r43087 / r43090;
        double r43092 = r43089 - r43091;
        return r43092;
}

double f(double x) {
        double r43093 = 0.3333333333333333;
        double r43094 = x;
        double r43095 = 0.022222222222222223;
        double r43096 = 3.0;
        double r43097 = pow(r43094, r43096);
        double r43098 = 0.0021164021164021165;
        double r43099 = 5.0;
        double r43100 = pow(r43094, r43099);
        double r43101 = r43098 * r43100;
        double r43102 = fma(r43095, r43097, r43101);
        double r43103 = fma(r43093, r43094, r43102);
        return r43103;
}

Error

Bits error versus x

Target

Original60.0
Target0.1
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;\left|x\right| \lt 0.0259999999999999988:\\ \;\;\;\;\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}{0.333333333333333315 \cdot x + \left(0.0222222222222222231 \cdot {x}^{3} + 0.00211640211640211654 \cdot {x}^{5}\right)}\]
  3. Simplified0.3

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.333333333333333315, x, \mathsf{fma}\left(0.0222222222222222231, {x}^{3}, 0.00211640211640211654 \cdot {x}^{5}\right)\right)}\]
  4. Final simplification0.3

    \[\leadsto \mathsf{fma}\left(0.333333333333333315, x, \mathsf{fma}\left(0.0222222222222222231, {x}^{3}, 0.00211640211640211654 \cdot {x}^{5}\right)\right)\]

Reproduce

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