Average Error: 15.6 → 0.5
Time: 4.4s
Precision: 64
\[\tan^{-1} \left(N + 1\right) - \tan^{-1} N\]
\[\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}\]
\tan^{-1} \left(N + 1\right) - \tan^{-1} N
\tan^{-1}_* \frac{1}{\mathsf{fma}\left(N, N + 1, 1\right)}
double f(double N) {
        double r443 = N;
        double r444 = 1.0;
        double r445 = r443 + r444;
        double r446 = atan(r445);
        double r447 = atan(r443);
        double r448 = r446 - r447;
        return r448;
}

double f(double N) {
        double r449 = 1.0;
        double r450 = N;
        double r451 = r450 + r449;
        double r452 = 1.0;
        double r453 = fma(r450, r451, r452);
        double r454 = atan2(r449, r453);
        return r454;
}

Error

Bits error versus N

Target

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

Derivation

  1. Initial program 15.6

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

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

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

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

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

Reproduce

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

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

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