| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 26308 |
\[\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}
\]
(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}
Results
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1e-8Initial program 60.0
Taylor expanded in N around inf 0.0
Taylor expanded in N around 0 0.0
if 1e-8 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 0.3
Applied egg-rr0.3
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 26308 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 7044 |
| Alternative 3 | |
|---|---|
| Error | 0.9 |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Error | 0.9 |
| Cost | 6724 |
| Alternative 5 | |
|---|---|
| Error | 1.2 |
| Cost | 6660 |
| Alternative 6 | |
|---|---|
| Error | 31.2 |
| Cost | 192 |
| Alternative 7 | |
|---|---|
| Error | 61.1 |
| Cost | 64 |
herbie shell --seed 2023074
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
(- (log (+ N 1.0)) (log N)))