Average Error: 15.2 → 0.9
Time: 32.1s
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 r5899241 = N;
        double r5899242 = 1.0;
        double r5899243 = r5899241 + r5899242;
        double r5899244 = atan(r5899243);
        double r5899245 = atan(r5899241);
        double r5899246 = r5899244 - r5899245;
        return r5899246;
}

double f(double N) {
        double r5899247 = 1.0;
        double r5899248 = N;
        double r5899249 = r5899248 + r5899247;
        double r5899250 = 1.0;
        double r5899251 = fma(r5899248, r5899249, r5899250);
        double r5899252 = atan2(r5899247, r5899251);
        double r5899253 = log1p(r5899252);
        double r5899254 = expm1(r5899253);
        return r5899254;
}

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.0 (+ 1.0 (* N (+ N 1.0)))))

  (- (atan (+ N 1.0)) (atan N)))