(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
(FPCore (N)
:precision binary64
(let* ((t_0 (* 0.5 (log1p N))))
(if (<= (- (log (+ N 1.0)) (log N)) 8.861960054673546e-10)
(- (/ 1.0 N) (/ 0.5 (* N N)))
(+ t_0 (- t_0 (log N))))))double code(double N) {
return log((N + 1.0)) - log(N);
}
double code(double N) {
double t_0 = 0.5 * log1p(N);
double tmp;
if ((log((N + 1.0)) - log(N)) <= 8.861960054673546e-10) {
tmp = (1.0 / N) - (0.5 / (N * N));
} else {
tmp = t_0 + (t_0 - log(N));
}
return tmp;
}
public static double code(double N) {
return Math.log((N + 1.0)) - Math.log(N);
}
public static double code(double N) {
double t_0 = 0.5 * Math.log1p(N);
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 8.861960054673546e-10) {
tmp = (1.0 / N) - (0.5 / (N * N));
} else {
tmp = t_0 + (t_0 - Math.log(N));
}
return tmp;
}
def code(N): return math.log((N + 1.0)) - math.log(N)
def code(N): t_0 = 0.5 * math.log1p(N) tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 8.861960054673546e-10: tmp = (1.0 / N) - (0.5 / (N * N)) else: tmp = t_0 + (t_0 - math.log(N)) return tmp
function code(N) return Float64(log(Float64(N + 1.0)) - log(N)) end
function code(N) t_0 = Float64(0.5 * log1p(N)) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 8.861960054673546e-10) tmp = Float64(Float64(1.0 / N) - Float64(0.5 / Float64(N * N))); else tmp = Float64(t_0 + Float64(t_0 - log(N))); end return tmp end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
code[N_] := Block[{t$95$0 = N[(0.5 * N[Log[1 + N], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 8.861960054673546e-10], N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[(N * N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(t$95$0 - N[Log[N], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\log \left(N + 1\right) - \log N
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{log1p}\left(N\right)\\
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 8.861960054673546 \cdot 10^{-10}:\\
\;\;\;\;\frac{1}{N} - \frac{0.5}{N \cdot N}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \left(t_0 - \log N\right)\\
\end{array}



Bits error versus N
Results
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 8.8619601e-10Initial program 60.1
Taylor expanded in N around inf 0.0
Simplified0.0
if 8.8619601e-10 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 0.5
Applied add-sqr-sqrt_binary640.5
Applied log-prod_binary640.5
Applied associate--l+_binary640.5
Simplified0.5
Applied pow1/2_binary640.5
Applied log-pow_binary640.5
Simplified0.5
Final simplification0.2
herbie shell --seed 2022130
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
(- (log (+ N 1.0)) (log N)))