Average Error: 59.9 → 0.3
Time: 36.6s
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 1137770271 
(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.6s)Debug log

sample655.0ms

Algorithm
intervals
Results
101×353.0ms(body real 2560)
76×156.0ms(body real 1280)
44×91.0ms(body real 640)
22×21.0ms(body real 320)
256×11.0ms(pre true 80)
13×8.0ms(body real 160)

simplify10.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
10.0ms
(- (/ 1 x) (/ 1 (tan x)))

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.8b

localize30.0ms

Local error

Found 2 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Rules
*-un-lft-identity
div-inv
add-sqr-sqrt
add-log-exp
distribute-lft-out--
add-cube-cbrt
add-exp-log
associate-/r*
pow1
add-cbrt-cube
difference-of-squares
inv-pow
flip--
pow-flip
frac-sub
associate-/r/
tan-quot
diff-log
flip3--
frac-2neg
sub-neg
clear-num
rec-exp
Counts
2 → 35
Calls
2 calls:
Slowest
9.0ms
(- (/ 1 x) (/ 1 (tan x)))
2.0ms
(/ 1 (tan x))

series187.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
133.0ms
(- (/ 1 x) (/ 1 (tan x)))
54.0ms
(/ 1 (tan x))

simplify395.0ms

Counts
20 → 41
Calls
20 calls:
Slowest
205.0ms
(- (/ 1 x) (+ (* 1/3 x) (* 1/45 (pow x 3))))
59.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
30.0ms
(/ (exp (/ 1 x)) (exp (/ 1 (tan x))))
12.0ms
(- (/ 1 x) (/ 1 (tan x)))
10.0ms
(- (* 1 (tan x)) (* x 1))

prune490.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.3b

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

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
associate-*r*
add-log-exp
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
*-commutative
flip-+
unpow3
flip3-+
sum-log
+-commutative
cube-mult
Counts
4 → 43
Calls
4 calls:
Slowest
12.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
3.0ms
(* 1/45 (pow x 3))
3.0ms
(* 2/945 (pow x 5))
0.0ms
(* 1/3 x)

series205.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
115.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
42.0ms
(* 2/945 (pow x 5))
33.0ms
(* 1/45 (pow x 3))
15.0ms
(* 1/3 x)

simplify188.0ms

Counts
20 → 55
Calls
20 calls:
Slowest
38.0ms
(* (exp (* 1/45 (pow x 3))) (exp (* 2/945 (pow x 5))))
27.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
26.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
26.0ms
(+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))
11.0ms
(* 1/45 (pow x 3))

prune948.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.3b

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

rewrite14.0ms

Algorithm
rewrite-expression-head
Rules
pow1
pow1/3
add-cube-cbrt
add-exp-log
*-un-lft-identity
add-sqr-sqrt
cbrt-prod
add-log-exp
associate-*l*
associate-*r*
add-cbrt-cube
pow-prod-up
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 51
Calls
4 calls:
Slowest
10.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
1.0ms
(cbrt (* 1/3 x))
1.0ms
(cbrt (* 1/3 x))
1.0ms
(cbrt (* 1/3 x))

series2.1s

Counts
4 → 12
Calls
4 calls:
Slowest
574.0ms
(* (cbrt (* 1/3 x)) (cbrt (* 1/3 x)))
514.0ms
(cbrt (* 1/3 x))
485.0ms
(cbrt (* 1/3 x))
481.0ms
(cbrt (* 1/3 x))

simplify213.0ms

Counts
31 → 63
Calls
31 calls:
Slowest
19.0ms
(* (pow (cbrt -1/3) 2) (pow (pow x 2) 1/3))
19.0ms
(* (pow (cbrt 1/3) 2) (pow (pow x 2) 1/3))
18.0ms
(* (pow (cbrt 1/3) 2) (pow (pow x 2) 1/3))
17.0ms
(* (* 1/3 x) (* 1/3 x))
17.0ms
(* (* 1/3 x) (* 1/3 x))

prune1.3s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 0.2b

localize48.0ms

Local error

Found 4 expressions with local error:

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

rewrite13.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
*-un-lft-identity
pow1
add-sqr-sqrt
pow1/3
add-log-exp
associate-*l*
add-cbrt-cube
associate-*r*
cbrt-prod
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
Counts
4 → 45
Calls
4 calls:
Slowest
10.0ms
(* (cbrt (* 1/3 x)) (cbrt 1/3))
1.0ms
(cbrt (* 1/3 x))
1.0ms
(cbrt (* 1/3 x))
0.0ms
(cbrt x)

series2.0s

Counts
4 → 12
Calls
4 calls:
Slowest
578.0ms
(* (cbrt (* 1/3 x)) (cbrt 1/3))
498.0ms
(cbrt (* 1/3 x))
478.0ms
(cbrt (* 1/3 x))
446.0ms
(cbrt x)

simplify189.0ms

Counts
24 → 57
Calls
24 calls:
Slowest
26.0ms
(* (* (cbrt -1/3) (cbrt 1/3)) (pow (* x -1) 1/3))
18.0ms
(* (pow (cbrt 1/3) 2) (pow x 1/3))
16.0ms
(* (pow (cbrt 1/3) 2) (pow x 1/3))
13.0ms
(* (pow (* x -1) 1/3) (cbrt -1))
13.0ms
(* (cbrt -1/3) (pow (* x -1) 1/3))

prune1.3s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 0.1b

regimes167.0ms

Accuracy

0% (0.2b remaining)

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

bsearch4.0ms

end0.0ms

sample23.1s

Algorithm
intervals
Results
3303×13.5s(body real 2560)
2464×6.3s(body real 1280)
1243×1.8s(body real 640)
637×719.0ms(body real 320)
8000×381.0ms(pre true 80)
302×193.0ms(body real 160)
51×16.0ms(body real 80)