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

Error

Bits error versus x

Target

Original60.0
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 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. Simplified0.3

    \[\leadsto \color{blue}{(x \cdot \left((\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*\right) + \left({x}^{5} \cdot \frac{2}{945}\right))_*}\]
  4. Using strategy rm
  5. Applied add-log-exp0.4

    \[\leadsto (x \cdot \left((\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*\right) + \color{blue}{\left(\log \left(e^{{x}^{5} \cdot \frac{2}{945}}\right)\right)})_*\]
  6. Using strategy rm
  7. Applied add-cube-cbrt0.4

    \[\leadsto (x \cdot \left((\frac{1}{45} \cdot \left(x \cdot x\right) + \frac{1}{3})_*\right) + \left(\log \color{blue}{\left(\left(\sqrt[3]{e^{{x}^{5} \cdot \frac{2}{945}}} \cdot \sqrt[3]{e^{{x}^{5} \cdot \frac{2}{945}}}\right) \cdot \sqrt[3]{e^{{x}^{5} \cdot \frac{2}{945}}}\right)}\right))_*\]
  8. Applied log-prod0.4

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

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

Reproduce

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

start704.0ms

Algorithm
intervals

setup67.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.7b

localize26.0ms

Local error

Found 2 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
2 → 63
Calls

2 calls. Slowest were:

9.0ms
(- (/ 1 x) (/ 1 (tan x)))
2.0ms
(/ 1 (tan x))

series103.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

65.0ms
(- (/ 1 x) (/ 1 (tan x)))
38.0ms
(/ 1 (tan x))

simplify1.6s

Counts
62 → 69
Calls

62 calls. Slowest were:

189.0ms
(- (/ 1 x) (+ (* 1/3 x) (* 1/45 (pow x 3))))
83.0ms
(fma (* (cbrt (/ 1 x)) (cbrt (/ 1 x))) (cbrt (/ 1 x)) (- (* (cos x) (/ 1 (sin x)))))
83.0ms
(fma 1 (/ 1 x) (- (* (cos x) (/ 1 (sin x)))))

prune632.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.4b
(fma x (fma 1/45 (* x x) 1/3) (* (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 x (fma 1/45 (* x x) 1/3) (* (pow x 5) 2/945))
0.0ms
(fma 1/45 (* x x) 1/3)

series117.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

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

simplify169.0ms

Counts
11 → 42
Calls

11 calls. Slowest were:

53.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
45.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
31.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune739.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.3b

localize18.0ms

Local error

Found 4 expressions with local error:

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

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
4 → 49
Calls

4 calls. Slowest were:

4.0ms
(log (exp (* (pow x 5) 2/945)))
4.0ms
(* (pow x 5) 2/945)
0.0ms
(fma x (fma 1/45 (* x x) 1/3) (log (exp (* (pow x 5) 2/945))))

series144.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

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

simplify172.0ms

Counts
18 → 61
Calls

18 calls. Slowest were:

34.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
33.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
32.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune999.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.3b

localize16.0ms

Local error

Found 4 expressions with local error:

1.4b
(log (cbrt (exp (* (pow x 5) 2/945))))
1.4b
(log (* (cbrt (exp (* (pow x 5) 2/945))) (cbrt (exp (* (pow x 5) 2/945)))))
0.4b
(fma x (fma 1/45 (* x x) 1/3) (+ (log (* (cbrt (exp (* (pow x 5) 2/945))) (cbrt (exp (* (pow x 5) 2/945))))) (log (cbrt (exp (* (pow x 5) 2/945))))))
0.1b
(* (pow x 5) 2/945)

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 60
Calls

4 calls. Slowest were:

9.0ms
(log (* (cbrt (exp (* (pow x 5) 2/945))) (cbrt (exp (* (pow x 5) 2/945)))))
2.0ms
(log (cbrt (exp (* (pow x 5) 2/945))))
2.0ms
(* (pow x 5) 2/945)

series3.6s

Counts
4 → 12
Calls

4 calls. Slowest were:

1.6s
(log (cbrt (exp (* (pow x 5) 2/945))))
1.6s
(log (* (cbrt (exp (* (pow x 5) 2/945))) (cbrt (exp (* (pow x 5) 2/945)))))
407.0ms
(fma x (fma 1/45 (* x x) 1/3) (+ (log (* (cbrt (exp (* (pow x 5) 2/945))) (cbrt (exp (* (pow x 5) 2/945))))) (log (cbrt (exp (* (pow x 5) 2/945))))))
22.0ms
(* (pow x 5) 2/945)

simplify1.3s

Counts
27 → 72
Calls

27 calls. Slowest were:

544.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (+ (log (pow (pow (exp (* 2/945 (pow x 5))) 2) 1/3)) (* 2/2835 (pow x 5)))))
514.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (+ (log (pow (pow (exp (* 2/945 (pow x 5))) 2) 1/3)) (* 2/2835 (pow x 5)))))
62.0ms
(log (pow (pow (exp (* 2/945 (pow x 5))) 2) 1/3))

prune1.4s

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.3b

regimes60.0ms

Accuracy

0% (0.1b remaining)

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

bsearch3.0ms