Average Error: 59.9 → 0.3
Time: 58.0s
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 1042149663 
(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: 54.6s)Debug log

sample693.0ms

Algorithm
intervals
Results
256×(pre true 80)
101×(body real 2560)
89×(body real 1280)
47×(body real 640)
(body real 320)
(body real 160)
(body real 80)

simplify11.0ms

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 60.2b

localize29.0ms

Local error

Found 2 expressions with local error:

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

rewrite11.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
8.0ms
(- (/ 1 x) (/ 1 (tan x)))
2.0ms
(/ 1 (tan x))

series186.0ms

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

simplify421.0ms

Counts
20 → 41
Calls
20 calls:
Slowest
213.0ms
(- (/ 1 x) (+ (* 1/3 x) (* 1/45 (pow x 3))))
63.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
33.0ms
(/ (exp (/ 1 x)) (exp (/ 1 (tan x))))
14.0ms
(- (sqrt (/ 1 x)) (sqrt (/ 1 (tan x))))
11.0ms
(- (/ 1 x) (/ (cos x) (sin x)))

prune453.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.3b

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

rewrite24.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
associate-*r*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
*-commutative
sum-log
flip-+
unpow3
flip3-+
associate-+r+
+-commutative
cube-mult
Counts
4 → 45
Calls
4 calls:
Slowest
17.0ms
(+ (* 1/3 x) (+ (* 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)

series136.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
49.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
40.0ms
(* 2/945 (pow x 5))
32.0ms
(* 1/45 (pow x 3))
15.0ms
(* 1/3 x)

simplify555.0ms

Counts
22 → 57
Calls
22 calls:
Slowest
132.0ms
(* (exp (* 1/3 x)) (exp (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
129.0ms
(* (exp (* 1/3 x)) (* (exp (* 1/45 (pow x 3))) (exp (* 2/945 (pow x 5)))))
72.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
69.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
69.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))

prune938.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 0.2b

localize27.0ms

Local error

Found 4 expressions with local error:

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

rewrite71.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
flip-+
flip3-+
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
add-cbrt-cube
frac-times
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 75
Calls
4 calls:
Slowest
42.0ms
(* (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))) (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))))
9.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
9.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
8.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))

series981.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
264.0ms
(* (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))) (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))))
242.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
239.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
236.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))

simplify12.4s

Counts
59 → 87
Calls
59 calls:
Slowest
618.0ms
(* (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))) (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
586.0ms
(* (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))) (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
508.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)))))
507.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)))))
507.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)))))

prune1.7s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 0.1b

localize49.0ms

Local error

Found 4 expressions with local error:

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

rewrite50.0ms

Algorithm
rewrite-expression-head
Rules
26×cbrt-div
10×cbrt-prod
flip-+
flip3-+
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-exp-log
pow1/3
add-cbrt-cube
pow1
frac-times
associate-*r/
associate-*l/
Counts
4 → 56
Calls
4 calls:
Slowest
23.0ms
(cbrt (* (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))) (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))))
9.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
9.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
9.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))

series1.1s

Counts
4 → 12
Calls
4 calls:
Slowest
352.0ms
(cbrt (* (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))) (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))))
238.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
237.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))
235.0ms
(cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5)))))

simplify10.2s

Counts
36 → 68
Calls
36 calls:
Slowest
887.0ms
(+ (* 917/36 (/ (exp (* 1/9 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (pow x 4))) (+ (exp (* 1/9 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (* 7/3 (/ (exp (* 1/9 (- (log 4/893025) (* 10 (log (/ 1 x)))))) (pow x 2)))))
505.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)))))
503.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)))))
503.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)))))
486.0ms
(cbrt (* (cbrt (+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))) (cbrt (- (* (* 1/3 x) (* 1/3 x)) (* (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))))))

prune1.6s

Pruning

17 alts after pruning (14 fresh and 3 done)

Merged error: 0.1b

regimes209.0ms

Accuracy

0% (0.2b remaining)

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

bsearch4.0ms

end0.0ms

sample22.8s

Algorithm
intervals
Results
8000×(pre true 80)
3278×(body real 2560)
2551×(body real 1280)
1226×(body real 640)
581×(body real 320)
318×(body real 160)
46×(body real 80)