Average Error: 59.9 → 0.0
Time: 50.7s
Precision: 64
Internal Precision: 128
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\frac{x}{\frac{\frac{1}{3} - \frac{1}{45} \cdot \left(x \cdot x\right)}{\frac{1}{9} - \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right) \cdot \left(\frac{1}{45} \cdot \left(x \cdot x\right)\right)}} + \frac{2}{945} \cdot {x}^{5}\]

Error

Bits error versus x

Target

Original59.9
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 59.9

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

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

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

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

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

Reproduce

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