Average Error: 29.5 → 0.1
Time: 16.4s
Precision: 64
\[\log \left(N + 1\right) - \log N\]
\[\begin{array}{l} \mathbf{if}\;N \le 4486.417968767682:\\ \;\;\;\;\mathsf{fma}\left(\left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(-\log N\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{\frac{1}{N}}{N \cdot N}\right), \frac{1}{3}, \left(\frac{1}{N}\right)\right) + \frac{\frac{-1}{2}}{N \cdot N}\\ \end{array}\]
\log \left(N + 1\right) - \log N
\begin{array}{l}
\mathbf{if}\;N \le 4486.417968767682:\\
\;\;\;\;\mathsf{fma}\left(\left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(-\log N\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{\frac{1}{N}}{N \cdot N}\right), \frac{1}{3}, \left(\frac{1}{N}\right)\right) + \frac{\frac{-1}{2}}{N \cdot N}\\

\end{array}
double f(double N) {
        double r933102 = N;
        double r933103 = 1.0;
        double r933104 = r933102 + r933103;
        double r933105 = log(r933104);
        double r933106 = log(r933102);
        double r933107 = r933105 - r933106;
        return r933107;
}

double f(double N) {
        double r933108 = N;
        double r933109 = 4486.417968767682;
        bool r933110 = r933108 <= r933109;
        double r933111 = log1p(r933108);
        double r933112 = sqrt(r933111);
        double r933113 = log(r933108);
        double r933114 = -r933113;
        double r933115 = fma(r933112, r933112, r933114);
        double r933116 = 1.0;
        double r933117 = r933116 / r933108;
        double r933118 = r933108 * r933108;
        double r933119 = r933117 / r933118;
        double r933120 = 0.3333333333333333;
        double r933121 = fma(r933119, r933120, r933117);
        double r933122 = -0.5;
        double r933123 = r933122 / r933118;
        double r933124 = r933121 + r933123;
        double r933125 = r933110 ? r933115 : r933124;
        return r933125;
}

Error

Bits error versus N

Derivation

  1. Split input into 2 regimes
  2. if N < 4486.417968767682

    1. Initial program 0.1

      \[\log \left(N + 1\right) - \log N\]
    2. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt0.1

      \[\leadsto \color{blue}{\sqrt{\mathsf{log1p}\left(N\right)} \cdot \sqrt{\mathsf{log1p}\left(N\right)}} - \log N\]
    5. Applied fma-neg0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(-\log N\right)\right)}\]

    if 4486.417968767682 < N

    1. Initial program 59.6

      \[\log \left(N + 1\right) - \log N\]
    2. Simplified59.6

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt60.0

      \[\leadsto \color{blue}{\sqrt{\mathsf{log1p}\left(N\right)} \cdot \sqrt{\mathsf{log1p}\left(N\right)}} - \log N\]
    5. Applied fma-neg60.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(-\log N\right)\right)}\]
    6. Taylor expanded around -inf 0.1

      \[\leadsto \color{blue}{\left(\frac{1}{3} \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \frac{1}{2} \cdot \frac{1}{{N}^{2}}}\]
    7. Simplified0.1

      \[\leadsto \color{blue}{\frac{\frac{-1}{2}}{N \cdot N} + \mathsf{fma}\left(\left(\frac{\frac{1}{N}}{N \cdot N}\right), \frac{1}{3}, \left(\frac{1}{N}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;N \le 4486.417968767682:\\ \;\;\;\;\mathsf{fma}\left(\left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(\sqrt{\mathsf{log1p}\left(N\right)}\right), \left(-\log N\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{\frac{1}{N}}{N \cdot N}\right), \frac{1}{3}, \left(\frac{1}{N}\right)\right) + \frac{\frac{-1}{2}}{N \cdot N}\\ \end{array}\]

Reproduce

herbie shell --seed 2019132 +o rules:numerics
(FPCore (N)
  :name "2log (problem 3.3.6)"
  (- (log (+ N 1)) (log N)))