Average Error: 36.7 → 9.0
Time: 40.8s
Precision: 64
Internal precision: 2176
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.9479733961868206 \cdot 10^{-39}:\\ \;\;\;\;\frac{\tan x + \tan \varepsilon}{1 - \frac{\sin x \cdot \sin \varepsilon}{\cos x \cdot \cos \varepsilon}} - \tan x\\ \mathbf{if}\;\varepsilon \le 5.496498246559763 \cdot 10^{-32}:\\ \;\;\;\;\left({x}^2 \cdot {\varepsilon}^3 + {\varepsilon}^{4} \cdot {x}^3\right) + \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2}{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x - \tan \varepsilon\right)} - \tan x\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original36.7
Comparison26.5
Herbie9.0
\[ \frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)} \]

Derivation

  1. Split input into 3 regimes.
  2. if eps < -1.9479733961868206e-39

    1. Initial program 30.3

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

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

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

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

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

    if -1.9479733961868206e-39 < eps < 5.496498246559763e-32

    1. Initial program 45.3

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

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

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

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

    if 5.496498246559763e-32 < eps

    1. Initial program 30.3

      \[\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 flip-+ 2.1

      \[\leadsto \frac{\color{blue}{\frac{{\left(\tan x\right)}^2 - {\left(\tan \varepsilon\right)}^2}{\tan x - \tan \varepsilon}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
    6. Applied associate-/l/ 2.1

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

Runtime

Time bar (total: 40.8s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(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)))