Average Error: 60.0 → 0.4
Time: 2.6m
Precision: 64
Internal Precision: 2432
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\frac{1}{45} \cdot {x}^{3} + \left(\log \left(e^{\frac{2}{945} \cdot {x}^{5}}\right) + \frac{1}{3} \cdot x\right)\]

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.3

    \[\leadsto \color{blue}{\frac{1}{45} \cdot {x}^{3} + \left(\frac{2}{945} \cdot {x}^{5} + \frac{1}{3} \cdot x\right)}\]
  3. Using strategy rm
  4. Applied add-log-exp0.4

    \[\leadsto \frac{1}{45} \cdot {x}^{3} + \left(\color{blue}{\log \left(e^{\frac{2}{945} \cdot {x}^{5}}\right)} + \frac{1}{3} \cdot x\right)\]
  5. Removed slow pow expressions.

Runtime

Time bar (total: 2.6m)Debug log

herbie shell --seed '#(2094665535 3654809497 1731717781 3082199462 566033875 575777438)' 
(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))))