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

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} \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. Initial simplification59.9

    \[\leadsto \frac{1}{x} - \frac{1}{\tan x}\]
  3. 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)}\]
  4. Simplified0.3

    \[\leadsto \color{blue}{(\left((\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*\right) \cdot x + \left({x}^{5} \cdot \frac{2}{945}\right))_*}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt0.3

    \[\leadsto (\color{blue}{\left(\sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*} \cdot \sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*}\right)} \cdot x + \left({x}^{5} \cdot \frac{2}{945}\right))_*\]
  7. Using strategy rm
  8. Applied add-cube-cbrt0.4

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

    \[\leadsto (\color{blue}{\left(\left(\sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*} \cdot \left(\sqrt[3]{\sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*}} \cdot \sqrt[3]{\sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*}}\right)\right) \cdot \sqrt[3]{\sqrt{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*}}\right)} \cdot x + \left({x}^{5} \cdot \frac{2}{945}\right))_*\]
  10. 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)}\]
  11. Simplified0.3

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

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

Runtime

Time bar (total: 37.3s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes0.30.30.10.30%
herbie shell --seed 2018351 +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))))