Average Error: 36.7 → 14.6
Time: 48.1s
Precision: 64
Internal Precision: 128
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.5128669689931483 \cdot 10^{-47}:\\ \;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} \cdot \left(\tan x \cdot \tan \varepsilon + 1\right) - \tan x\\ \mathbf{elif}\;\varepsilon \le 5.068526259562942 \cdot 10^{-24}:\\ \;\;\;\;(\left(\varepsilon \cdot \left(x + \varepsilon\right)\right) \cdot x + \varepsilon)_*\\ \mathbf{else}:\\ \;\;\;\;(\left(\tan \varepsilon + \tan x\right) \cdot \left(\frac{1}{\sqrt[3]{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right)}}\right) + \left(-\tan x\right))_*\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Target

Original36.7
Target15.3
Herbie14.6
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -1.5128669689931483e-47

    1. Initial program 29.8

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\frac{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}{1 + \tan x \cdot \tan \varepsilon}}} - \tan x\]
    6. Applied associate-/r/3.5

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \color{blue}{\frac{\sin \varepsilon}{\cos \varepsilon}}\right)} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right) - \tan x\]
    9. Applied associate-*r/3.6

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

    if -1.5128669689931483e-47 < eps < 5.068526259562942e-24

    1. Initial program 45.5

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

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

      \[\leadsto \frac{\tan x + \tan \varepsilon}{\color{blue}{\frac{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)}{1 + \tan x \cdot \tan \varepsilon}}} - \tan x\]
    6. Applied associate-/r/45.5

      \[\leadsto \color{blue}{\frac{\tan x + \tan \varepsilon}{1 \cdot 1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \left(\tan x \cdot \tan \varepsilon\right)} \cdot \left(1 + \tan x \cdot \tan \varepsilon\right)} - \tan x\]
    7. Taylor expanded around 0 30.2

      \[\leadsto \color{blue}{x \cdot {\varepsilon}^{2} + \left(\varepsilon + {x}^{2} \cdot \varepsilon\right)}\]
    8. Simplified30.2

      \[\leadsto \color{blue}{(\left(\varepsilon \cdot \left(\varepsilon + x\right)\right) \cdot x + \varepsilon)_*}\]

    if 5.068526259562942e-24 < eps

    1. Initial program 29.9

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

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

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

      \[\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 add-cbrt-cube1.7

      \[\leadsto (\left(\tan x + \tan \varepsilon\right) \cdot \left(\frac{1}{\color{blue}{\sqrt[3]{\left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)}}}\right) + \left(-\tan x\right))_*\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -1.5128669689931483 \cdot 10^{-47}:\\ \;\;\;\;\frac{\tan \varepsilon + \tan x}{1 - \left(\tan x \cdot \tan \varepsilon\right) \cdot \frac{\tan x \cdot \sin \varepsilon}{\cos \varepsilon}} \cdot \left(\tan x \cdot \tan \varepsilon + 1\right) - \tan x\\ \mathbf{elif}\;\varepsilon \le 5.068526259562942 \cdot 10^{-24}:\\ \;\;\;\;(\left(\varepsilon \cdot \left(x + \varepsilon\right)\right) \cdot x + \varepsilon)_*\\ \mathbf{else}:\\ \;\;\;\;(\left(\tan \varepsilon + \tan x\right) \cdot \left(\frac{1}{\sqrt[3]{\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(\left(1 - \tan x \cdot \tan \varepsilon\right) \cdot \left(1 - \tan x \cdot \tan \varepsilon\right)\right)}}\right) + \left(-\tan x\right))_*\\ \end{array}\]

Reproduce

herbie shell --seed 2019053 +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)))