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

Error

Bits error versus x

Target

Original59.8
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 59.8

    \[\frac{1}{x} - \frac{1}{\tan x}\]
  2. Taylor expanded around 0 0.4

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

    \[\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. Using strategy rm
  5. Applied fma-udef0.4

    \[\leadsto \color{blue}{(\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_* \cdot x + {x}^{5} \cdot \frac{2}{945}}\]
  6. Final simplification0.4

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

Reproduce

herbie shell --seed 2018365 +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: 9.2s)Debug log

start737.0ms

Algorithm
intervals

setup13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.6b

localize11.0ms

Local error

Found 2 expressions with local error:

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

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
2 → 63
Calls

2 calls. Slowest were:

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

series145.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

116.0ms
(- (/ 1 x) (/ 1 (tan x)))
29.0ms
(/ 1 (tan x))

simplify2.0s

Counts
62 → 69
Calls

62 calls. Slowest were:

227.0ms
(- (/ 1 x) (+ (* 1/3 x) (* 1/45 (pow x 3))))
135.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))
132.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))

prune651.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.4b

localize33.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:

4.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)

series115.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

41.0ms
(fma 1/45 (* x x) 1/3)
39.0ms
(fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))
35.0ms
(* (pow x 5) 2/945)

simplify214.0ms

Counts
11 → 42
Calls

11 calls. Slowest were:

88.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
52.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
44.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune765.0ms

Pruning

5 alts after pruning (5 fresh and 0 done)

Merged error: 0.3b

localize10.0ms

Local error

Found 3 expressions with local error:

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

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
3 → 36
Calls

3 calls. Slowest were:

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

series126.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

58.0ms
(* (fma 1/45 (* x x) 1/3) x)
35.0ms
(fma 1/45 (* x x) 1/3)
33.0ms
(* (pow x 5) 2/945)

simplify173.0ms

Counts
13 → 45
Calls

13 calls. Slowest were:

44.0ms
(+ (* 1/3 x) (* 1/45 (pow x 3)))
37.0ms
(+ (* 1/3 x) (* 1/45 (pow x 3)))
22.0ms
(+ (* 1/3 x) (* 1/45 (pow x 3)))

prune789.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.3b

localize20.0ms

Local error

Found 4 expressions with local error:

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

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

17.0ms
(* (sqrt (fma 1/45 (* x x) 1/3)) (* (sqrt (fma 1/45 (* x x) 1/3)) x))
6.0ms
(* (sqrt (fma 1/45 (* x x) 1/3)) x)
4.0ms
(* (pow x 5) 2/945)

series186.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(* (sqrt (fma 1/45 (* x x) 1/3)) (* (sqrt (fma 1/45 (* x x) 1/3)) x))
53.0ms
(* (sqrt (fma 1/45 (* x x) 1/3)) x)
38.0ms
(fma 1/45 (* x x) 1/3)
35.0ms
(* (pow x 5) 2/945)

simplify1.9s

Counts
27 → 71
Calls

27 calls. Slowest were:

604.0ms
(- (+ (* (pow x 2) (sqrt 1/45)) (* 1/6 (/ 1 (sqrt 1/45)))) (* 1/72 (/ 1 (* (pow x 2) (pow (sqrt 1/45) 3)))))
384.0ms
(* (* (* (sqrt (fma 1/45 (* x x) 1/3)) (sqrt (fma 1/45 (* x x) 1/3))) (sqrt (fma 1/45 (* x x) 1/3))) (* (* (* (sqrt (fma 1/45 (* x x) 1/3)) x) (* (sqrt (fma 1/45 (* x x) 1/3)) x)) (* (sqrt (fma 1/45 (* x x) 1/3)) x)))
354.0ms
(- (+ (* x (sqrt 1/3)) (* 1/90 (/ (pow x 3) (sqrt 1/3)))) (* 1/16200 (/ (pow x 5) (pow (sqrt 1/3) 3))))

prune1.1s

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 0.2b

regimes106.0ms

Accuracy

0% (0.2b remaining)

Error of 0.4b against oracle of 0.1b and baseline of 0.4b

bsearch3.0ms