Average Error: 14.8 → 0.4
Time: 8.7s
Precision: 64
\[\tan^{-1} \left(N + 1\right) - \tan^{-1} N\]
\[\tan^{-1}_* \frac{1}{1 + \mathsf{fma}\left(N, N, N\right)}\]
\tan^{-1} \left(N + 1\right) - \tan^{-1} N
\tan^{-1}_* \frac{1}{1 + \mathsf{fma}\left(N, N, N\right)}
double f(double N) {
        double r3885691 = N;
        double r3885692 = 1.0;
        double r3885693 = r3885691 + r3885692;
        double r3885694 = atan(r3885693);
        double r3885695 = atan(r3885691);
        double r3885696 = r3885694 - r3885695;
        return r3885696;
}

double f(double N) {
        double r3885697 = 1.0;
        double r3885698 = N;
        double r3885699 = fma(r3885698, r3885698, r3885698);
        double r3885700 = r3885697 + r3885699;
        double r3885701 = atan2(r3885697, r3885700);
        return r3885701;
}

Error

Bits error versus N

Target

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

Derivation

  1. Initial program 14.8

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

    \[\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}{1 + \mathsf{fma}\left(N, N, N\right)}}\]
  6. Using strategy rm
  7. Applied add-sqr-sqrt1.0

    \[\leadsto \color{blue}{\sqrt{\tan^{-1}_* \frac{1}{1 + \mathsf{fma}\left(N, N, N\right)}} \cdot \sqrt{\tan^{-1}_* \frac{1}{1 + \mathsf{fma}\left(N, N, N\right)}}}\]
  8. Taylor expanded around 0 0.4

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

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

Reproduce

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

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

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