Average Error: 36.5 → 15.1
Time: 39.3s
Precision: 64
Internal Precision: 128
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -2.0002192550276487 \cdot 10^{-26} \lor \neg \left(\varepsilon \le 8.912544817231381 \cdot 10^{-119}\right):\\ \;\;\;\;\frac{(\left(\cos x\right) \cdot \left(\tan x + \tan \varepsilon\right) + \left(\sin x \cdot (\left(\tan x\right) \cdot \left(\tan \varepsilon\right) + -1)_*\right))_*}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{else}:\\ \;\;\;\;(\left(x \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right) + \varepsilon)_*\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original36.5
Target15.2
Herbie15.1
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -2.0002192550276487e-26 or 8.912544817231381e-119 < eps

    1. Initial program 29.9

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-sum5.4

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Using strategy rm
    5. Applied tan-quot5.4

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon} - \color{blue}{\frac{\sin x}{\cos x}}\]
    6. Applied frac-sub5.4

      \[\leadsto \color{blue}{\frac{\left(\tan x + \tan \varepsilon\right) \cdot \cos x - \left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}}\]
    7. Simplified5.4

      \[\leadsto \frac{\color{blue}{(\left(\cos x\right) \cdot \left(\tan x + \tan \varepsilon\right) + \left(\sin x \cdot (\left(\tan x\right) \cdot \left(\tan \varepsilon\right) + -1)_*\right))_*}}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \cos x}\]

    if -2.0002192550276487e-26 < eps < 8.912544817231381e-119

    1. Initial program 47.3

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Using strategy rm
    3. Applied tan-sum47.3

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    4. Using strategy rm
    5. Applied div-inv47.3

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    6. Applied fma-neg47.3

      \[\leadsto \color{blue}{(\left(\tan x + \tan \varepsilon\right) \cdot \left(\frac{1}{1 - \tan x \cdot \tan \varepsilon}\right) + \left(-\tan x\right))_*}\]
    7. Using strategy rm
    8. Applied flip3--47.3

      \[\leadsto (\left(\tan x + \tan \varepsilon\right) \cdot \left(\frac{1}{\color{blue}{\frac{{1}^{3} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}}{1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)}}}\right) + \left(-\tan x\right))_*\]
    9. Applied associate-/r/47.3

      \[\leadsto (\left(\tan x + \tan \varepsilon\right) \cdot \color{blue}{\left(\frac{1}{{1}^{3} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right) + 1 \cdot \left(\tan x \cdot \tan \varepsilon\right)\right)\right)\right)} + \left(-\tan x\right))_*\]
    10. Simplified47.3

      \[\leadsto (\left(\tan x + \tan \varepsilon\right) \cdot \left(\frac{1}{{1}^{3} - {\left(\tan x \cdot \tan \varepsilon\right)}^{3}} \cdot \color{blue}{(\left(\tan \varepsilon \cdot \tan x\right) \cdot \left((\left(\tan x\right) \cdot \left(\tan \varepsilon\right) + 1)_*\right) + 1)_*}\right) + \left(-\tan x\right))_*\]
    11. Taylor expanded around 0 31.2

      \[\leadsto \color{blue}{x \cdot {\varepsilon}^{2} + \left(\varepsilon + {x}^{2} \cdot \varepsilon\right)}\]
    12. Simplified31.1

      \[\leadsto \color{blue}{(\left(x \cdot \varepsilon\right) \cdot \left(\varepsilon + x\right) + \varepsilon)_*}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification15.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -2.0002192550276487 \cdot 10^{-26} \lor \neg \left(\varepsilon \le 8.912544817231381 \cdot 10^{-119}\right):\\ \;\;\;\;\frac{(\left(\cos x\right) \cdot \left(\tan x + \tan \varepsilon\right) + \left(\sin x \cdot (\left(\tan x\right) \cdot \left(\tan \varepsilon\right) + -1)_*\right))_*}{\cos x \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}\\ \mathbf{else}:\\ \;\;\;\;(\left(x \cdot \varepsilon\right) \cdot \left(x + \varepsilon\right) + \varepsilon)_*\\ \end{array}\]

Reproduce

herbie shell --seed 2019005 +o rules:numerics
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"

  :herbie-target
  (/ (sin eps) (* (cos x) (cos (+ x eps))))

  (- (tan (+ x eps)) (tan x)))

Details

Time bar (total: 38.0s)Debug log

sample453.0ms

Algorithm
intervals

simplify6.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

5.0ms
(- (tan (+ x eps)) (tan x))

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 36.6b

localize28.0ms

Local error

Found 2 expressions with local error:

3.8b
(tan (+ x eps))
1.8b
(- (tan (+ x eps)) (tan x))

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
2 → 41
Calls

2 calls. Slowest were:

6.0ms
(- (tan (+ x eps)) (tan x))
3.0ms
(tan (+ x eps))

series174.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

91.0ms
(- (tan (+ x eps)) (tan x))
82.0ms
(tan (+ x eps))

simplify1.1s

Counts
35 → 47
Calls

35 calls. Slowest were:

263.0ms
(- (* (+ (tan x) (tan eps)) (cos x)) (* (- 1 (* (tan x) (tan eps))) (sin x)))
210.0ms
(+ (* x (pow eps 2)) (+ eps (* (pow x 2) eps)))
171.0ms
(* (- 1 (* (tan x) (tan eps))) (cos x))

prune558.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 13.7b

localize17.0ms

Local error

Found 4 expressions with local error:

4.1b
(- (/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps)))) (tan x))
0.3b
(* (tan x) (tan eps))
0.1b
(/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps))))
0.1b
(+ (tan x) (tan eps))

rewrite90.0ms

Algorithm
rewrite-expression-head
Counts
4 → 168
Calls

4 calls. Slowest were:

62.0ms
(- (/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps)))) (tan x))
13.0ms
(/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps))))
5.0ms
(* (tan x) (tan eps))

series874.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

434.0ms
(- (/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps)))) (tan x))
243.0ms
(/ (+ (tan x) (tan eps)) (- 1 (* (tan x) (tan eps))))
102.0ms
(* (tan x) (tan eps))
94.0ms
(+ (tan x) (tan eps))

simplify14.5s

Counts
199 → 180
Calls

199 calls. Slowest were:

554.0ms
(fma (/ 1 (* (cbrt (- 1 (* (tan x) (tan eps)))) (cbrt (- 1 (* (tan x) (tan eps)))))) (/ (+ (tan x) (tan eps)) (cbrt (- 1 (* (tan x) (tan eps))))) (- (* (sqrt (tan x)) (sqrt (tan x)))))
534.0ms
(fma (/ 1 (* (cbrt (- 1 (* (tan x) (tan eps)))) (cbrt (- 1 (* (tan x) (tan eps)))))) (/ (+ (tan x) (tan eps)) (cbrt (- 1 (* (tan x) (tan eps))))) (- (* (sqrt (tan x)) (sqrt (tan x)))))
476.0ms
(fma (/ (+ (tan x) (tan eps)) (- (pow 1 3) (pow (* (tan x) (tan eps)) 3))) (+ (* 1 1) (+ (* (* (tan x) (tan eps)) (* (tan x) (tan eps))) (* 1 (* (tan x) (tan eps))))) (- (* (cbrt (tan x)) (* (cbrt (tan x)) (cbrt (tan x))))))

prune1.8s

Pruning

13 alts after pruning (13 fresh and 0 done)

Merged error: 13.5b

localize12.0ms

Local error

Found 4 expressions with local error:

4.1b
(fma (+ (tan x) (tan eps)) (/ 1 (- 1 (* (tan x) (tan eps)))) (- (tan x)))
0.3b
(* (tan x) (tan eps))
0.1b
(/ 1 (- 1 (* (tan x) (tan eps))))
0.1b
(+ (tan x) (tan eps))

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

4.0ms
(* (tan x) (tan eps))
4.0ms
(+ (tan x) (tan eps))
1.0ms
(/ 1 (- 1 (* (tan x) (tan eps))))

series645.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

301.0ms
(fma (+ (tan x) (tan eps)) (/ 1 (- 1 (* (tan x) (tan eps)))) (- (tan x)))
133.0ms
(/ 1 (- 1 (* (tan x) (tan eps))))
108.0ms
(* (tan x) (tan eps))
102.0ms
(+ (tan x) (tan eps))

simplify1.8s

Counts
36 → 82
Calls

36 calls. Slowest were:

303.0ms
(+ x (+ (* 1/3 (pow x 3)) eps))
227.0ms
(- (+ (/ (sin eps) (* (cos eps) (- 1 (/ (* (sin x) (sin eps)) (* (cos x) (cos eps)))))) (/ (sin x) (* (cos x) (- 1 (/ (* (sin x) (sin eps)) (* (cos x) (cos eps))))))) (/ (sin x) (cos x)))
198.0ms
(+ (* 1 1) (+ (* (* (tan x) (tan eps)) (* (tan x) (tan eps))) (* 1 (* (tan x) (tan eps)))))

prune735.0ms

Pruning

12 alts after pruning (12 fresh and 0 done)

Merged error: 13.5b

localize33.0ms

Local error

Found 4 expressions with local error:

4.1b
(fma (+ (tan x) (tan eps)) (* (/ 1 (- (pow 1 3) (pow (* (tan x) (tan eps)) 3))) (fma (* (tan eps) (tan x)) (fma (tan x) (tan eps) 1) 1)) (- (tan x)))
0.3b
(pow (* (tan x) (tan eps)) 3)
0.3b
(* (tan x) (tan eps))
0.3b
(* (tan eps) (tan x))

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
4 → 77
Calls

4 calls. Slowest were:

5.0ms
(* (tan eps) (tan x))
4.0ms
(* (tan x) (tan eps))
4.0ms
(pow (* (tan x) (tan eps)) 3)

series999.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

720.0ms
(fma (+ (tan x) (tan eps)) (* (/ 1 (- (pow 1 3) (pow (* (tan x) (tan eps)) 3))) (fma (* (tan eps) (tan x)) (fma (tan x) (tan eps) 1) 1)) (- (tan x)))
104.0ms
(pow (* (tan x) (tan eps)) 3)
96.0ms
(* (tan eps) (tan x))
79.0ms
(* (tan x) (tan eps))

simplify1.5s

Counts
47 → 89
Calls

47 calls. Slowest were:

192.0ms
(+ (* 1/3 (* (pow x 3) eps)) (+ (* 1/3 (* x (pow eps 3))) (* x eps)))
186.0ms
(+ (* 1/3 (* (pow x 3) eps)) (+ (* 1/3 (* x (pow eps 3))) (* x eps)))
174.0ms
(+ (* (pow x 3) (pow eps 5)) (+ (* (pow x 3) (pow eps 3)) (* (pow x 5) (pow eps 3))))

prune1.1s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 13.5b

regimes224.0ms

Accuracy

85% (1.1b remaining)

Error of 15.1b against oracle of 14.1b and baseline of 21.3b

bsearch295.0ms

end0.0ms

sample10.9s

Algorithm
intervals