?

Average Error: 29.1 → 0.2
Time: 7.6s
Precision: binary64
Cost: 32836

?

\[\log \left(N + 1\right) - \log N \]
\[\begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 10^{-8}:\\ \;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{N + 1}\right) \cdot 2 - \log N\\ \end{array} \]
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 1e-8)
   (- (/ 1.0 N) (/ 0.5 (pow N 2.0)))
   (- (* (log (sqrt (+ N 1.0))) 2.0) (log N))))
double code(double N) {
	return log((N + 1.0)) - log(N);
}
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 1e-8) {
		tmp = (1.0 / N) - (0.5 / pow(N, 2.0));
	} else {
		tmp = (log(sqrt((N + 1.0))) * 2.0) - log(N);
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = log((n + 1.0d0)) - log(n)
end function
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 1d-8) then
        tmp = (1.0d0 / n) - (0.5d0 / (n ** 2.0d0))
    else
        tmp = (log(sqrt((n + 1.0d0))) * 2.0d0) - log(n)
    end if
    code = tmp
end function
public static double code(double N) {
	return Math.log((N + 1.0)) - Math.log(N);
}
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 1e-8) {
		tmp = (1.0 / N) - (0.5 / Math.pow(N, 2.0));
	} else {
		tmp = (Math.log(Math.sqrt((N + 1.0))) * 2.0) - Math.log(N);
	}
	return tmp;
}
def code(N):
	return math.log((N + 1.0)) - math.log(N)
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 1e-8:
		tmp = (1.0 / N) - (0.5 / math.pow(N, 2.0))
	else:
		tmp = (math.log(math.sqrt((N + 1.0))) * 2.0) - math.log(N)
	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)) <= 1e-8)
		tmp = Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0)));
	else
		tmp = Float64(Float64(log(sqrt(Float64(N + 1.0))) * 2.0) - log(N));
	end
	return tmp
end
function tmp = code(N)
	tmp = log((N + 1.0)) - log(N);
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 1e-8)
		tmp = (1.0 / N) - (0.5 / (N ^ 2.0));
	else
		tmp = (log(sqrt((N + 1.0))) * 2.0) - log(N);
	end
	tmp_2 = 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], 1e-8], N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Sqrt[N[(N + 1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]]
\log \left(N + 1\right) - \log N
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 10^{-8}:\\
\;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

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

    1. Initial program 60.0

      \[\log \left(N + 1\right) - \log N \]
    2. Taylor expanded in N around inf 0.0

      \[\leadsto \color{blue}{\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}} \]
    3. Taylor expanded in N around 0 0.0

      \[\leadsto \frac{1}{N} - \color{blue}{\frac{0.5}{{N}^{2}}} \]

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

    1. Initial program 0.3

      \[\log \left(N + 1\right) - \log N \]
    2. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error0.2
Cost26308
\[\begin{array}{l} t_0 := \log \left(N + 1\right) - \log N\\ \mathbf{if}\;t_0 \leq 10^{-8}:\\ \;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.6
Cost7044
\[\begin{array}{l} \mathbf{if}\;N \leq 0.9:\\ \;\;\;\;\left(\left(N - \log N\right) + 2\right) + -2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\ \end{array} \]
Alternative 3
Error0.9
Cost6980
\[\begin{array}{l} \mathbf{if}\;N \leq 1:\\ \;\;\;\;\left(\left(N - \log N\right) + 2\right) + -2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \]
Alternative 4
Error0.9
Cost6724
\[\begin{array}{l} \mathbf{if}\;N \leq 1:\\ \;\;\;\;N - \log N\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \]
Alternative 5
Error1.2
Cost6660
\[\begin{array}{l} \mathbf{if}\;N \leq 0.55:\\ \;\;\;\;-\log N\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \]
Alternative 6
Error31.2
Cost192
\[\frac{1}{N} \]
Alternative 7
Error61.1
Cost64
\[N \]

Error

Reproduce?

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