Average Error: 30.0 → 0.1
Time: 2.7s
Precision: binary64
\[\log \left(N + 1\right) - \log N \]
\[\begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 1.2127060244893073 \cdot 10^{-8}:\\ \;\;\;\;\mathsf{fma}\left({N}^{-2}, -0.5, \frac{1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 1.2127060244893073e-8)
   (fma (pow N -2.0) -0.5 (/ 1.0 N))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	return log((N + 1.0)) - log(N);
}
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 1.2127060244893073e-8) {
		tmp = fma(pow(N, -2.0), -0.5, (1.0 / N));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
function code(N)
	return Float64(log(Float64(N + 1.0)) - log(N))
end
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 1.2127060244893073e-8)
		tmp = fma((N ^ -2.0), -0.5, Float64(1.0 / N));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 1.2127060244893073e-8], N[(N[Power[N, -2.0], $MachinePrecision] * -0.5 + N[(1.0 / N), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\log \left(N + 1\right) - \log N
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 1.2127060244893073 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left({N}^{-2}, -0.5, \frac{1}{N}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}

Error

Bits error versus N

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1.212706e-8

    1. Initial program 60.0

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    3. Taylor expanded in N around inf 0.0

      \[\leadsto \color{blue}{\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}} \]
    4. Simplified0.0

      \[\leadsto \color{blue}{\frac{1}{N} + \frac{-0.5}{N \cdot N}} \]
    5. Applied egg-rr0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left({N}^{-2}, -0.5, \frac{1}{N}\right)} \]

    if 1.212706e-8 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    3. Applied egg-rr0.3

      \[\leadsto \color{blue}{\log \left(\frac{N + 1}{N}\right)} \]
    4. Applied egg-rr0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 1.2127060244893073 \cdot 10^{-8}:\\ \;\;\;\;\mathsf{fma}\left({N}^{-2}, -0.5, \frac{1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022150 
(FPCore (N)
  :name "2log (problem 3.3.6)"
  :precision binary64
  (- (log (+ N 1.0)) (log N)))