Average Error: 36.5 → 9.1
Time: 1.2m
Precision: 64
Internal precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -8.786347343699343 \cdot 10^{-16}:\\ \;\;\;\;\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \mathbf{if}\;\varepsilon \le 4.27193241580942 \cdot 10^{-33}:\\ \;\;\;\;{\varepsilon}^{4} \cdot {x}^3 + \left(\varepsilon + {x}^2 \cdot {\varepsilon}^3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left({\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2\right) \cdot 1\right) \cdot \cos x - \left(\left(\tan x - \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\left(\left(\tan x - \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x}\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original36.5
Comparison27.4
Herbie9.1
\[ \frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \]

Derivation

  1. Split input into 3 regimes.
  2. if eps < -8.786347343699343e-16

    1. Initial program 30.5

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

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

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

    if -8.786347343699343e-16 < eps < 4.27193241580942e-33

    1. Initial program 44.6

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Applied taylor 18.6

      \[\leadsto {\varepsilon}^{3} \cdot {x}^2 + \left(\varepsilon + {\varepsilon}^{4} \cdot {x}^{3}\right)\]
    3. Taylor expanded around 0 18.6

      \[\leadsto \color{blue}{{\varepsilon}^{3} \cdot {x}^2 + \left(\varepsilon + {\varepsilon}^{4} \cdot {x}^{3}\right)}\]
    4. Applied simplify 18.6

      \[\leadsto \color{blue}{{\varepsilon}^{4} \cdot {x}^3 + \left(\varepsilon + {x}^2 \cdot {\varepsilon}^3\right)}\]

    if 4.27193241580942e-33 < eps

    1. Initial program 29.5

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

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

      \[\leadsto \color{blue}{\left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon}} - \tan x\]
    6. Using strategy rm
    7. Applied tan-quot 2.1

      \[\leadsto \left(\tan x + \tan \varepsilon\right) \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \color{blue}{\frac{\sin x}{\cos x}}\]
    8. Applied flip-+ 2.2

      \[\leadsto \color{blue}{\frac{{\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2}{\tan x - \tan \varepsilon}} \cdot \frac{1}{1 - \tan x \cdot \tan \varepsilon} - \frac{\sin x}{\cos x}\]
    9. Applied frac-times 2.1

      \[\leadsto \color{blue}{\frac{\left({\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2\right) \cdot 1}{\left(\tan x - \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}} - \frac{\sin x}{\cos x}\]
    10. Applied frac-sub 2.2

      \[\leadsto \color{blue}{\frac{\left(\left({\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2\right) \cdot 1\right) \cdot \cos x - \left(\left(\tan x - \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right) \cdot \sin x}{\left(\left(\tan x - \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right) \cdot \cos x}}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 1.2m) Debug log

Please include this information when filing a bug report:

herbie shell --seed '#(644180380 3784176976 401987740 22459203 1940947670 3323606534)'
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :herbie-expected 28

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

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