Average Error: 29.9 → 0.5
Time: 1.1m
Precision: 64
Internal Precision: 2432
\[\frac{1}{x} - \frac{1}{\tan x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{x} - \frac{1}{\tan x} \le -0.0005430901480872134:\\ \;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\ \mathbf{if}\;\frac{1}{x} - \frac{1}{\tan x} \le 0.0:\\ \;\;\;\;\frac{1}{45} \cdot {x}^{3} + \left(\frac{2}{945} \cdot {x}^{5} + \frac{1}{3} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{\tan x}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (- (/ 1 x) (/ 1 (tan x))) < -0.0005430901480872134 or 0.0 < (- (/ 1 x) (/ 1 (tan x)))

    1. Initial program 0.7

      \[\frac{1}{x} - \frac{1}{\tan x}\]

    if -0.0005430901480872134 < (- (/ 1 x) (/ 1 (tan x))) < 0.0

    1. Initial program 60.3

      \[\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. Recombined 2 regimes into one program.

Runtime

Time bar (total: 1.1m)Debug log

herbie shell --seed '#(1743936871 1855164119 3668777427 1254258049 132811564 1366975197)' 
(FPCore (x)
  :name "NMSE example 3.9"
  :pre (!= x 0)
  (- (/ 1 x) (/ 1 (tan x))))