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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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

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

Reproduce

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

Details

Time bar (total: 23.9s)Debug log

sample451.0ms

Algorithm
intervals

simplify10.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

10.0ms
(- (/ 1 x) (/ 1 (tan x)))

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.8b

localize21.0ms

Local error

Found 1 expressions with local error:

2.2b
(- (/ 1 x) (/ 1 (tan x)))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
1 → 18
Calls

1 calls. Slowest were:

7.0ms
(- (/ 1 x) (/ 1 (tan x)))

series494.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

494.0ms
(- (/ 1 x) (/ 1 (tan x)))

simplify119.0ms

Counts
12 → 21
Calls

12 calls. Slowest were:

40.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
14.0ms
(/ (exp (/ 1 x)) (exp (/ 1 (tan x))))
10.0ms
(- (/ 1 x) (/ 1 (tan x)))

prune152.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.3b

localize25.0ms

Local error

Found 4 expressions with local error:

0.3b
(* 1/3 x)
0.1b
(* 1/45 (pow x 3))
0.1b
(* 2/945 (pow x 5))
0.0b
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 45
Calls

4 calls. Slowest were:

12.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
2.0ms
(* 1/45 (pow x 3))
2.0ms
(* 2/945 (pow x 5))

series102.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

37.0ms
(* 2/945 (pow x 5))
28.0ms
(* 1/45 (pow x 3))
24.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
12.0ms
(* 1/3 x)

simplify346.0ms

Counts
22 → 57
Calls

22 calls. Slowest were:

91.0ms
(* (exp (* 1/3 x)) (exp (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
90.0ms
(* (exp (* 1/3 x)) (* (exp (* 1/45 (pow x 3))) (exp (* 2/945 (pow x 5)))))
43.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune534.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.2b

localize26.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (* 1/3 x))
0.6b
(cbrt (* 1/3 x))
0.6b
(cbrt (* 1/3 x))
0.5b
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

8.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
1.0ms
(cbrt (* 1/3 x))
1.0ms
(cbrt (* 1/3 x))

series1.3s

Counts
4 → 12
Calls

4 calls. Slowest were:

357.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
332.0ms
(cbrt (* 1/3 x))
303.0ms
(cbrt (* 1/3 x))
295.0ms
(cbrt (* 1/3 x))

simplify177.0ms

Counts
31 → 63
Calls

31 calls. Slowest were:

18.0ms
(* (pow (cbrt -1/3) 2) (pow (pow x 2) 1/3))
17.0ms
(* (pow (cbrt 1/3) 2) (pow (pow x 2) 1/3))
17.0ms
(* (pow (cbrt 1/3) 2) (pow (pow x 2) 1/3))

prune795.0ms

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 0.2b

localize35.0ms

Local error

Found 4 expressions with local error:

0.7b
(cbrt x)
0.6b
(cbrt (* 1/3 x))
0.6b
(cbrt (* 1/3 x))
0.5b
(* (cbrt (* 1/3 x)) (cbrt 1/3))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
4 → 45
Calls

4 calls. Slowest were:

6.0ms
(* (cbrt (* 1/3 x)) (cbrt 1/3))
1.0ms
(cbrt (* 1/3 x))
1.0ms
(cbrt (* 1/3 x))

series1.3s

Counts
4 → 12
Calls

4 calls. Slowest were:

356.0ms
(* (cbrt (* 1/3 x)) (cbrt 1/3))
347.0ms
(cbrt (* 1/3 x))
307.0ms
(cbrt (* 1/3 x))
256.0ms
(cbrt x)

simplify125.0ms

Counts
24 → 57
Calls

24 calls. Slowest were:

19.0ms
(* (* (cbrt -1/3) (cbrt 1/3)) (pow (* x -1) 1/3))
9.0ms
(* (pow (* x -1) 1/3) (cbrt -1))
9.0ms
(* (* 1/3 x) 1/3)

prune855.0ms

Pruning

15 alts after pruning (12 fresh and 3 done)

Merged error: 0.1b

regimes113.0ms

Accuracy

0% (0.2b remaining)

Error of 0.3b against oracle of 0.2b and baseline of 0.3b

bsearch2.0ms

end0.0ms

sample16.9s

Algorithm
intervals