Average Error: 37.2 → 9.6
Time: 4.9m
Precision: 64
Internal Precision: 2432
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.1197109515059853 \cdot 10^{-73}:\\ \;\;\;\;\frac{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\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}\\ \mathbf{if}\;\varepsilon \le 5.558436005007817 \cdot 10^{-38}:\\ \;\;\;\;\varepsilon + \left({\varepsilon}^{3} \cdot {x}^{2} + {\varepsilon}^{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\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}\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original37.2
Target26.5
Herbie9.6
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if eps < -1.1197109515059853e-73 or 5.558436005007817e-38 < eps

    1. Initial program 30.2

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

      \[\leadsto \tan \left(x + \varepsilon\right) - \color{blue}{\frac{\sin x}{\cos x}}\]
    4. Applied tan-sum4.5

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

      \[\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}}\]
    6. Using strategy rm
    7. Applied flip--4.6

      \[\leadsto \frac{\color{blue}{\frac{\left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) \cdot \left(\left(\tan x + \tan \varepsilon\right) \cdot \cos x\right) - \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \sin x\right)}{\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}\]

    if -1.1197109515059853e-73 < eps < 5.558436005007817e-38

    1. Initial program 47.2

      \[\tan \left(x + \varepsilon\right) - \tan x\]
    2. Taylor expanded around 0 16.7

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

Runtime

Time bar (total: 4.9m)Debug logProfile

herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)' 
(FPCore (x eps)
  :name "2tan (problem 3.3.2)"
  :herbie-expected 28

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

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