Average Error: 15.6 → 0.5
Time: 2.2s
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 r171476 = N;
        double r171477 = 1.0;
        double r171478 = r171476 + r171477;
        double r171479 = atan(r171478);
        double r171480 = atan(r171476);
        double r171481 = r171479 - r171480;
        return r171481;
}

double f(double N) {
        double r171482 = 1.0;
        double r171483 = N;
        double r171484 = r171483 + r171482;
        double r171485 = 1.0;
        double r171486 = fma(r171483, r171484, r171485);
        double r171487 = atan2(r171482, r171486);
        return r171487;
}

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)))