| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 6660 |
\[\begin{array}{l}
\mathbf{if}\;N \leq 0.59:\\
\;\;\;\;-\log N\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N} + \frac{\frac{-0.5 + \frac{0.3333333333333333}{N}}{N}}{N}\\
\end{array}
\]
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
(FPCore (N) :precision binary64 (log1p (/ 1.0 N)))
double code(double N) {
return log((N + 1.0)) - log(N);
}
double code(double N) {
return log1p((1.0 / N));
}
public static double code(double N) {
return Math.log((N + 1.0)) - Math.log(N);
}
public static double code(double N) {
return Math.log1p((1.0 / N));
}
def code(N): return math.log((N + 1.0)) - math.log(N)
def code(N): return math.log1p((1.0 / N))
function code(N) return Float64(log(Float64(N + 1.0)) - log(N)) end
function code(N) return log1p(Float64(1.0 / N)) end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
code[N_] := N[Log[1 + N[(1.0 / N), $MachinePrecision]], $MachinePrecision]
\log \left(N + 1\right) - \log N
\mathsf{log1p}\left(\frac{1}{N}\right)
Results
Initial program 29.7
Simplified29.7
[Start]29.7 | \[ \log \left(N + 1\right) - \log N
\] |
|---|---|
+-commutative [=>]29.7 | \[ \log \color{blue}{\left(1 + N\right)} - \log N
\] |
log1p-def [=>]29.7 | \[ \color{blue}{\mathsf{log1p}\left(N\right)} - \log N
\] |
Applied egg-rr29.6
Applied egg-rr29.6
Simplified0.0
[Start]29.6 | \[ 0 + \log \left(\frac{N + 1}{N}\right)
\] |
|---|---|
+-lft-identity [=>]29.6 | \[ \color{blue}{\log \left(\frac{N + 1}{N}\right)}
\] |
*-lft-identity [<=]29.6 | \[ \log \left(\frac{\color{blue}{1 \cdot \left(N + 1\right)}}{N}\right)
\] |
associate-*l/ [<=]29.7 | \[ \log \color{blue}{\left(\frac{1}{N} \cdot \left(N + 1\right)\right)}
\] |
distribute-rgt-in [=>]29.7 | \[ \log \color{blue}{\left(N \cdot \frac{1}{N} + 1 \cdot \frac{1}{N}\right)}
\] |
rgt-mult-inverse [=>]29.6 | \[ \log \left(\color{blue}{1} + 1 \cdot \frac{1}{N}\right)
\] |
*-lft-identity [=>]29.6 | \[ \log \left(1 + \color{blue}{\frac{1}{N}}\right)
\] |
log1p-def [=>]0.0 | \[ \color{blue}{\mathsf{log1p}\left(\frac{1}{N}\right)}
\] |
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 6660 |
| Alternative 2 | |
|---|---|
| Error | 29.2 |
| Cost | 704 |
| Alternative 3 | |
|---|---|
| Error | 30.7 |
| Cost | 192 |
herbie shell --seed 2023187
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
(- (log (+ N 1.0)) (log N)))