Average Error: 59.9 → 0.3
Time: 35.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. 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. 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))_*}\]
  4. 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))_*\]

Reproduce

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

Details

Time bar (total: 33.0s)Debug log

sample465.0ms

Algorithm
intervals

simplify5.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.8b

localize11.0ms

Local error

Found 1 expressions with local error:

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

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
1 → 44
Calls

1 calls. Slowest were:

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

series79.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

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

simplify1.9s

Counts
54 → 47
Calls

54 calls. Slowest were:

361.0ms
(fma (- (sqrt (/ 1 (tan x)))) (sqrt (/ 1 (tan x))) (* (sqrt (/ 1 (tan x))) (sqrt (/ 1 (tan x)))))
118.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))
103.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))

prune342.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.3b

localize34.0ms

Local error

Found 3 expressions with local error:

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

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
3 → 33
Calls

3 calls. Slowest were:

5.0ms
(* (pow x 5) 2/945)
0.0ms
(fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))
0.0ms
(fma 1/45 (* x x) 1/3)

series89.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

34.0ms
(fma 1/45 (* x x) 1/3)
33.0ms
(fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))
23.0ms
(* (pow x 5) 2/945)

simplify267.0ms

Counts
11 → 42
Calls

11 calls. Slowest were:

90.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
71.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
62.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune425.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.2b

localize22.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
0.5b
(* (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))) (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

10.0ms
(* (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))) (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))
5.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
1.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

series574.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

155.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
143.0ms
(* (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))) (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))
138.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
137.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

simplify5.2s

Counts
41 → 81
Calls

41 calls. Slowest were:

506.0ms
(+ (* 7/2 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 2))) (+ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (* 161/4 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 4)))))
413.0ms
(+ (exp (* 1/3 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (+ (* 371/4 (/ (exp (* 1/3 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (pow x 4))) (* 7 (/ (exp (* 1/3 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (pow x 2)))))
402.0ms
(+ (* 7/2 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 2))) (+ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (* 161/4 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 4)))))

prune999.0ms

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 0.2b

localize27.0ms

Local error

Found 4 expressions with local error:

0.7b
(cbrt (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))
0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
0.6b
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

1.0ms
(cbrt (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))
1.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
1.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

series508.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

146.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
131.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
120.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
110.0ms
(cbrt (cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))))

simplify4.2s

Counts
27 → 67
Calls

27 calls. Slowest were:

423.0ms
(+ (* 7/2 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 2))) (+ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (* 161/4 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 4)))))
399.0ms
(+ (* 7/2 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 2))) (+ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (* 161/4 (/ (exp (* 1/3 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 4)))))
394.0ms
(+ (* 7/6 (/ (exp (* 1/9 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 2))) (+ (exp (* 1/9 (- (log 2/945) (* 5 (log (/ 1 x)))))) (* 217/18 (/ (exp (* 1/9 (- (log 2/945) (* 5 (log (/ 1 x)))))) (pow x 4)))))

prune895.0ms

Pruning

15 alts after pruning (12 fresh and 3 done)

Merged error: 0.2b

regimes169.0ms

Accuracy

0% (0.1b remaining)

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

bsearch2.0ms

end0.0ms

sample16.8s

Algorithm
intervals