Average Error: 59.9 → 0.3
Time: 27.6s
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 2019022 +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: 26.0s)Debug log

sample510.0ms

Algorithm
intervals
Results
319.0ms121×body2560valid
130.0ms72×body1280valid
30.0ms38×body640valid
11.0ms20×body320valid
8.0ms256×pre80true
2.0msbody160valid

simplify5.0ms

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 59.8b

localize10.0ms

Local error

Found 2 expressions with local error:

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

rewrite6.0ms

Algorithm
rewrite-expression-head
Rules
20×prod-diff
17×*-un-lft-identity
15×div-inv
15×add-sqr-sqrt
13×add-cube-cbrt
associate-/r/
tan-quot
add-log-exp
distribute-lft-out--
fma-neg
add-exp-log
associate-/r*
pow1
log1p-expm1-u
add-cbrt-cube
expm1-log1p-u
difference-of-squares
inv-pow
flip--
pow-flip
frac-sub
diff-log
flip3--
frac-2neg
sub-neg
clear-num
rec-exp
Counts
2 → 63
Calls
2 calls:
Slowest
5.0ms
(- (/ 1 x) (/ 1 (tan x)))
1.0ms
(/ 1 (tan x))

series93.0ms

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

simplify1.5s

Counts
62 → 69
Calls
62 calls:
Slowest
194.0ms
(- (/ 1 x) (+ (* 1/3 x) (* 1/45 (pow x 3))))
91.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))
83.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))
80.0ms
(fma 1 (/ 1 x) (- (* (cos x) (/ 1 (sin x)))))
77.0ms
(fma (- (cos x)) (/ 1 (sin x)) (* (cos x) (/ 1 (sin x))))

prune440.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 0.4b

localize20.0ms

Local error

Found 3 expressions with local error:

0.4b
(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)

rewrite3.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
associate-*l*
add-cbrt-cube
pow1
expm1-log1p-u
fma-udef
*-commutative
Counts
3 → 33
Calls
3 calls:
Slowest
2.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)

series79.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
30.0ms
(fma 1/45 (* x x) 1/3)
29.0ms
(fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945))
20.0ms
(* (pow x 5) 2/945)

simplify204.0ms

Counts
11 → 42
Calls
11 calls:
Slowest
65.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
59.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))))
10.0ms
(+ (* 1/45 (pow x 2)) 1/3)
8.0ms
(+ (* 1/45 (pow x 2)) 1/3)

prune331.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.3b

localize21.0ms

Local error

Found 4 expressions with local error:

0.4b
(fma (log (exp (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)
0.0b
(log (exp (fma 1/45 (* x x) 1/3)))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
pow1
add-log-exp
log1p-expm1-u
log-pow
add-exp-log
add-cbrt-cube
log-prod
expm1-log1p-u
fma-udef
associate-*l*
exp-prod
*-commutative
exp-sum
rem-log-exp
Counts
4 → 51
Calls
4 calls:
Slowest
4.0ms
(* (pow x 5) 2/945)
4.0ms
(log (exp (fma 1/45 (* x x) 1/3)))
0.0ms
(fma (log (exp (fma 1/45 (* x x) 1/3))) x (* (pow x 5) 2/945))
0.0ms
(fma 1/45 (* x x) 1/3)

series106.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
35.0ms
(fma (log (exp (fma 1/45 (* x x) 1/3))) x (* (pow x 5) 2/945))
26.0ms
(* (pow x 5) 2/945)
24.0ms
(fma 1/45 (* x x) 1/3)
20.0ms
(log (exp (fma 1/45 (* x x) 1/3)))

simplify302.0ms

Counts
21 → 63
Calls
21 calls:
Slowest
62.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
58.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
46.0ms
(+ (* 1/3 x) (+ (* 1/45 (pow x 3)) (* 2/945 (pow x 5))))
31.0ms
(log (* (cbrt (exp (fma 1/45 (* x x) 1/3))) (cbrt (exp (fma 1/45 (* x x) 1/3)))))
18.0ms
(log (sqrt (exp (fma 1/45 (* x x) 1/3))))

prune726.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.3b

localize21.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.6b
(* (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))))

rewrite11.0ms

Algorithm
rewrite-expression-head
Rules
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
log1p-expm1-u
add-cbrt-cube
expm1-log1p-u
pow-prod-up
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 69
Calls
4 calls:
Slowest
7.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))))
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)))
1.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

series537.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
144.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
132.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))))
132.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))
129.0ms
(cbrt (fma (fma 1/45 (* x x) 1/3) x (* (pow x 5) 2/945)))

simplify4.8s

Counts
41 → 81
Calls
41 calls:
Slowest
388.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)))))
375.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)))))
347.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)))))
322.0ms
(+ (* 2/45 (* (pow x 2) (exp (* 1/3 (+ (log 1/9) (* 2 (log x))))))) (+ (* 53/14175 (* (pow x 4) (exp (* 1/3 (+ (log 1/9) (* 2 (log x))))))) (exp (* 1/3 (+ (log 1/9) (* 2 (log x)))))))
318.0ms
(+ (exp (* 1/3 (+ (log 1/3) (log x)))) (+ (* 23/14175 (* (pow x 4) (exp (* 1/3 (+ (log 1/3) (log x)))))) (* 1/45 (* (pow x 2) (exp (* 1/3 (+ (log 1/3) (log x))))))))

prune915.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.2b

regimes80.0ms

Accuracy

0% (0.1b remaining)

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

bsearch1.0ms

end0.0ms

sample15.2s

Algorithm
intervals
Results
9.0s3255×body2560valid
3.7s2486×body1280valid
1.5s1313×body640valid
333.0ms598×body320valid
228.0ms8000×pre80true
175.0ms299×body160valid
9.0ms49×body80valid