Average Error: 15.2 → 0.9
Time: 13.8s
Precision: 64
\[\tan^{-1} \left(N + 1\right) - \tan^{-1} N\]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}\right)\right)\]
\tan^{-1} \left(N + 1\right) - \tan^{-1} N
\mathsf{expm1}\left(\mathsf{log1p}\left(\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}\right)\right)
double f(double N) {
        double r4666194 = N;
        double r4666195 = 1.0;
        double r4666196 = r4666194 + r4666195;
        double r4666197 = atan(r4666196);
        double r4666198 = atan(r4666194);
        double r4666199 = r4666197 - r4666198;
        return r4666199;
}

double f(double N) {
        double r4666200 = 1.0;
        double r4666201 = N;
        double r4666202 = r4666201 + r4666200;
        double r4666203 = fma(r4666201, r4666202, r4666200);
        double r4666204 = atan2(r4666200, r4666203);
        double r4666205 = log1p(r4666204);
        double r4666206 = expm1(r4666205);
        return r4666206;
}

Error

Bits error versus N

Target

Original15.2
Target0.4
Herbie0.9
\[\tan^{-1} \left(\frac{1}{1 + N \cdot \left(N + 1\right)}\right)\]

Derivation

  1. Initial program 15.2

    \[\tan^{-1} \left(N + 1\right) - \tan^{-1} N\]
  2. Using strategy rm
  3. Applied diff-atan14.1

    \[\leadsto \color{blue}{\tan^{-1}_* \frac{\left(N + 1\right) - N}{1 + \left(N + 1\right) \cdot N}}\]
  4. Simplified0.4

    \[\leadsto \tan^{-1}_* \frac{\color{blue}{1}}{1 + \left(N + 1\right) \cdot N}\]
  5. Simplified0.4

    \[\leadsto \tan^{-1}_* \frac{1}{\color{blue}{\mathsf{fma}\left(N, 1 + N, 1\right)}}\]
  6. Using strategy rm
  7. Applied expm1-log1p-u0.9

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, 1 + N, 1\right)}\right)\right)}\]
  8. Final simplification0.9

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}\right)\right)\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (N)
  :name "2atan (example 3.5)"

  :herbie-target
  (atan (/ 1 (+ 1 (* N (+ N 1)))))

  (- (atan (+ N 1)) (atan N)))