Average Error: 29.1 → 0.0
Time: 2.4s
Precision: 64
\[\log \left(N + 1\right) - \log N\]
\[\mathsf{log1p}\left(\frac{1}{N}\right)\]
\log \left(N + 1\right) - \log N
\mathsf{log1p}\left(\frac{1}{N}\right)
double f(double N) {
        double r30583 = N;
        double r30584 = 1.0;
        double r30585 = r30583 + r30584;
        double r30586 = log(r30585);
        double r30587 = log(r30583);
        double r30588 = r30586 - r30587;
        return r30588;
}

double f(double N) {
        double r30589 = 1.0;
        double r30590 = N;
        double r30591 = r30589 / r30590;
        double r30592 = log1p(r30591);
        return r30592;
}

Error

Bits error versus N

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 29.1

    \[\log \left(N + 1\right) - \log N\]
  2. Using strategy rm
  3. Applied diff-log29.0

    \[\leadsto \color{blue}{\log \left(\frac{N + 1}{N}\right)}\]
  4. Taylor expanded around 0 29.0

    \[\leadsto \log \color{blue}{\left(1 \cdot \frac{1}{N} + 1\right)}\]
  5. Simplified29.0

    \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{N}, 1\right)\right)}\]
  6. Using strategy rm
  7. Applied *-un-lft-identity29.0

    \[\leadsto \log \color{blue}{\left(1 \cdot \mathsf{fma}\left(1, \frac{1}{N}, 1\right)\right)}\]
  8. Applied log-prod29.0

    \[\leadsto \color{blue}{\log 1 + \log \left(\mathsf{fma}\left(1, \frac{1}{N}, 1\right)\right)}\]
  9. Simplified29.0

    \[\leadsto \color{blue}{0} + \log \left(\mathsf{fma}\left(1, \frac{1}{N}, 1\right)\right)\]
  10. Simplified0.0

    \[\leadsto 0 + \color{blue}{\mathsf{log1p}\left(\frac{1}{N}\right)}\]
  11. Final simplification0.0

    \[\leadsto \mathsf{log1p}\left(\frac{1}{N}\right)\]

Reproduce

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