Average Error: 36.6 → 16.2
Time: 16.4s
Precision: 64
\[\tan \left(x + \varepsilon\right) - \tan x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -4.307211467193248750320315767028327223219 \cdot 10^{-112}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x}, \tan \varepsilon\right), \frac{1}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \le 7.696293304718231974151591027639771302433 \cdot 10^{-100}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, x \cdot \left(\varepsilon + x\right), \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sin x, \cos \varepsilon, \cos x \cdot \sin \varepsilon\right)}{\cos \varepsilon \cdot \cos x}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array}\]
\tan \left(x + \varepsilon\right) - \tan x
\begin{array}{l}
\mathbf{if}\;\varepsilon \le -4.307211467193248750320315767028327223219 \cdot 10^{-112}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x}, \tan \varepsilon\right), \frac{1}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)}, -\tan x\right)\\

\mathbf{elif}\;\varepsilon \le 7.696293304718231974151591027639771302433 \cdot 10^{-100}:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, x \cdot \left(\varepsilon + x\right), \varepsilon\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\sin x, \cos \varepsilon, \cos x \cdot \sin \varepsilon\right)}{\cos \varepsilon \cdot \cos x}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\

\end{array}
double f(double x, double eps) {
        double r110803 = x;
        double r110804 = eps;
        double r110805 = r110803 + r110804;
        double r110806 = tan(r110805);
        double r110807 = tan(r110803);
        double r110808 = r110806 - r110807;
        return r110808;
}

double f(double x, double eps) {
        double r110809 = eps;
        double r110810 = -4.307211467193249e-112;
        bool r110811 = r110809 <= r110810;
        double r110812 = x;
        double r110813 = tan(r110812);
        double r110814 = cbrt(r110813);
        double r110815 = r110814 * r110814;
        double r110816 = tan(r110809);
        double r110817 = fma(r110815, r110814, r110816);
        double r110818 = 1.0;
        double r110819 = r110813 * r110816;
        double r110820 = exp(r110819);
        double r110821 = log(r110820);
        double r110822 = r110818 - r110821;
        double r110823 = r110818 / r110822;
        double r110824 = -r110813;
        double r110825 = fma(r110817, r110823, r110824);
        double r110826 = 7.696293304718232e-100;
        bool r110827 = r110809 <= r110826;
        double r110828 = r110809 + r110812;
        double r110829 = r110812 * r110828;
        double r110830 = fma(r110809, r110829, r110809);
        double r110831 = sin(r110812);
        double r110832 = cos(r110809);
        double r110833 = cos(r110812);
        double r110834 = sin(r110809);
        double r110835 = r110833 * r110834;
        double r110836 = fma(r110831, r110832, r110835);
        double r110837 = r110832 * r110833;
        double r110838 = r110836 / r110837;
        double r110839 = r110818 - r110819;
        double r110840 = r110838 / r110839;
        double r110841 = r110840 - r110813;
        double r110842 = r110827 ? r110830 : r110841;
        double r110843 = r110811 ? r110825 : r110842;
        return r110843;
}

Error

Bits error versus x

Bits error versus eps

Target

Original36.6
Target14.9
Herbie16.2
\[\frac{\sin \varepsilon}{\cos x \cdot \cos \left(x + \varepsilon\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -4.307211467193249e-112

    1. Initial program 31.3

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \tan x \cdot \tan \varepsilon}, -\tan x\right)}\]
    7. Using strategy rm
    8. Applied add-log-exp8.8

      \[\leadsto \mathsf{fma}\left(\tan x + \tan \varepsilon, \frac{1}{1 - \color{blue}{\log \left(e^{\tan x \cdot \tan \varepsilon}\right)}}, -\tan x\right)\]
    9. Using strategy rm
    10. Applied add-cube-cbrt8.9

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}\right) \cdot \sqrt[3]{\tan x}} + \tan \varepsilon, \frac{1}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)}, -\tan x\right)\]
    11. Applied fma-def8.9

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x}, \tan \varepsilon\right)}, \frac{1}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)}, -\tan x\right)\]

    if -4.307211467193249e-112 < eps < 7.696293304718232e-100

    1. Initial program 47.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, x \cdot \left(\varepsilon + x\right), \varepsilon\right)}\]

    if 7.696293304718232e-100 < eps

    1. Initial program 30.6

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(\sin x, \cos \varepsilon, \cos x \cdot \sin \varepsilon\right)}}{\cos x \cdot \cos \varepsilon}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
    9. Simplified8.4

      \[\leadsto \frac{\frac{\mathsf{fma}\left(\sin x, \cos \varepsilon, \cos x \cdot \sin \varepsilon\right)}{\color{blue}{\cos \varepsilon \cdot \cos x}}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -4.307211467193248750320315767028327223219 \cdot 10^{-112}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\sqrt[3]{\tan x} \cdot \sqrt[3]{\tan x}, \sqrt[3]{\tan x}, \tan \varepsilon\right), \frac{1}{1 - \log \left(e^{\tan x \cdot \tan \varepsilon}\right)}, -\tan x\right)\\ \mathbf{elif}\;\varepsilon \le 7.696293304718231974151591027639771302433 \cdot 10^{-100}:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, x \cdot \left(\varepsilon + x\right), \varepsilon\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\sin x, \cos \varepsilon, \cos x \cdot \sin \varepsilon\right)}{\cos \varepsilon \cdot \cos x}}{1 - \tan x \cdot \tan \varepsilon} - \tan x\\ \end{array}\]

Reproduce

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

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

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