Average Error: 60.0 → 0.3
Time: 22.4s
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

Original60.0
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 60.0

    \[\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 2019008 
(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: 20.7s)Debug log

sample473.0ms

Algorithm
intervals

simplify5.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 60.0b

localize56.0ms

Local error

Found 2 expressions with local error:

3.2b
(- (/ 1 x) (/ 1 (tan x)))
0.0b
(/ 1 (tan x))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
2 → 35
Calls

2 calls. Slowest were:

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

series99.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

64.0ms
(- (/ 1 x) (/ 1 (tan x)))
35.0ms
(/ 1 (tan x))

simplify195.0ms

Counts
20 → 41
Calls

20 calls. Slowest were:

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

prune264.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.3b

localize31.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/45 (pow x 3)) (* 2/945 (pow x 5)))

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
4 → 43
Calls

4 calls. Slowest were:

3.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
1.0ms
(* 2/945 (pow x 5))
1.0ms
(* 1/45 (pow x 3))

series102.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

54.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
21.0ms
(* 1/45 (pow x 3))
20.0ms
(* 2/945 (pow x 5))
7.0ms
(* 1/3 x)

simplify97.0ms

Counts
20 → 55
Calls

20 calls. Slowest were:

18.0ms
(* (exp (* 1/45 (pow x 3))) (exp (* 2/945 (pow x 5))))
16.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
15.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))

prune437.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.3b

localize15.0ms

Local error

Found 4 expressions with local error:

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

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

4.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
1.0ms
(cbrt (* 1/3 x))
0.0ms
(cbrt (* 1/3 x))

series1.2s

Counts
4 → 12
Calls

4 calls. Slowest were:

343.0ms
(cbrt (* 1/3 x))
304.0ms
(cbrt (* 1/3 x))
302.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
274.0ms
(cbrt (* 1/3 x))

simplify133.0ms

Counts
31 → 63
Calls

31 calls. Slowest were:

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

prune667.0ms

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 0.2b

localize14.0ms

Local error

Found 4 expressions with local error:

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

rewrite7.0ms

Algorithm
rewrite-expression-head
Counts
4 → 50
Calls

4 calls. Slowest were:

5.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
0.0ms
(cbrt (* 1/3 x))
0.0ms
(cbrt (* 1/3 x))

series1.1s

Counts
4 → 12
Calls

4 calls. Slowest were:

306.0ms
(cbrt (* 1/3 x))
271.0ms
(cbrt x)
265.0ms
(cbrt (* 1/3 x))
263.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))

simplify89.0ms

Counts
30 → 62
Calls

30 calls. Slowest were:

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

prune666.0ms

Pruning

14 alts after pruning (12 fresh and 2 done)

Merged error: 0.2b

regimes111.0ms

Accuracy

0% (0.1b remaining)

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

bsearch3.0ms

end0.0ms

sample14.9s

Algorithm
intervals