| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 27076 |

(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
(FPCore (N)
:precision binary64
(if (<= (- (log (+ N 1.0)) (log N)) 5e-5)
(+
(/ (/ (+ N -0.5) N) N)
(- (* 0.3333333333333333 (pow N -3.0)) (* 0.25 (pow N -4.0))))
(log (/ (+ N 1.0) 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)) <= 5e-5) {
tmp = (((N + -0.5) / N) / N) + ((0.3333333333333333 * pow(N, -3.0)) - (0.25 * pow(N, -4.0)));
} else {
tmp = log(((N + 1.0) / 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)) <= 5d-5) then
tmp = (((n + (-0.5d0)) / n) / n) + ((0.3333333333333333d0 * (n ** (-3.0d0))) - (0.25d0 * (n ** (-4.0d0))))
else
tmp = log(((n + 1.0d0) / 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)) <= 5e-5) {
tmp = (((N + -0.5) / N) / N) + ((0.3333333333333333 * Math.pow(N, -3.0)) - (0.25 * Math.pow(N, -4.0)));
} else {
tmp = Math.log(((N + 1.0) / 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)) <= 5e-5: tmp = (((N + -0.5) / N) / N) + ((0.3333333333333333 * math.pow(N, -3.0)) - (0.25 * math.pow(N, -4.0))) else: tmp = math.log(((N + 1.0) / 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)) <= 5e-5) tmp = Float64(Float64(Float64(Float64(N + -0.5) / N) / N) + Float64(Float64(0.3333333333333333 * (N ^ -3.0)) - Float64(0.25 * (N ^ -4.0)))); else tmp = log(Float64(Float64(N + 1.0) / 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)) <= 5e-5) tmp = (((N + -0.5) / N) / N) + ((0.3333333333333333 * (N ^ -3.0)) - (0.25 * (N ^ -4.0))); else tmp = log(((N + 1.0) / 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], 5e-5], N[(N[(N[(N[(N + -0.5), $MachinePrecision] / N), $MachinePrecision] / N), $MachinePrecision] + N[(N[(0.3333333333333333 * N[Power[N, -3.0], $MachinePrecision]), $MachinePrecision] - N[(0.25 * N[Power[N, -4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision]]
\log \left(N + 1\right) - \log N
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{N + -0.5}{N}}{N} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.00000000000000024e-5Initial program 7.9%
Simplified7.9%
[Start]7.9% | \[ \log \left(N + 1\right) - \log N
\] |
|---|---|
+-commutative [=>]7.9% | \[ \log \color{blue}{\left(1 + N\right)} - \log N
\] |
log1p-def [=>]7.9% | \[ \color{blue}{\mathsf{log1p}\left(N\right)} - \log N
\] |
Applied egg-rr8.4%
[Start]7.9% | \[ \mathsf{log1p}\left(N\right) - \log N
\] |
|---|---|
log1p-udef [=>]7.9% | \[ \color{blue}{\log \left(1 + N\right)} - \log N
\] |
diff-log [=>]8.4% | \[ \color{blue}{\log \left(\frac{1 + N}{N}\right)}
\] |
+-commutative [=>]8.4% | \[ \log \left(\frac{\color{blue}{N + 1}}{N}\right)
\] |
Taylor expanded in N around inf 100.0%
Simplified61.6%
[Start]100.0% | \[ \left(\frac{1}{N} + 0.3333333333333333 \cdot \frac{1}{{N}^{3}}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)
\] |
|---|---|
+-commutative [=>]100.0% | \[ \left(\frac{1}{N} + 0.3333333333333333 \cdot \frac{1}{{N}^{3}}\right) - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}
\] |
associate--r+ [=>]100.0% | \[ \color{blue}{\left(\left(\frac{1}{N} + 0.3333333333333333 \cdot \frac{1}{{N}^{3}}\right) - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}}
\] |
Applied egg-rr62.9%
[Start]61.6% | \[ \left(\frac{0.3333333333333333}{{N}^{3}} + \frac{N + -0.5}{N \cdot N}\right) - \frac{0.25}{{N}^{4}}
\] |
|---|---|
+-commutative [=>]61.6% | \[ \color{blue}{\left(\frac{N + -0.5}{N \cdot N} + \frac{0.3333333333333333}{{N}^{3}}\right)} - \frac{0.25}{{N}^{4}}
\] |
associate--l+ [=>]61.6% | \[ \color{blue}{\frac{N + -0.5}{N \cdot N} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)}
\] |
div-inv [=>]61.4% | \[ \color{blue}{\left(N + -0.5\right) \cdot \frac{1}{N \cdot N}} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
pow2 [=>]61.4% | \[ \left(N + -0.5\right) \cdot \frac{1}{\color{blue}{{N}^{2}}} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
metadata-eval [<=]61.4% | \[ \left(N + -0.5\right) \cdot \frac{1}{{N}^{\color{blue}{\left(\sqrt{4}\right)}}} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
pow-flip [=>]62.9% | \[ \left(N + -0.5\right) \cdot \color{blue}{{N}^{\left(-\sqrt{4}\right)}} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
metadata-eval [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{\left(-\color{blue}{2}\right)} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
metadata-eval [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{\color{blue}{-2}} + \left(\frac{0.3333333333333333}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right)
\] |
div-inv [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(\color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right)
\] |
pow-flip [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot \color{blue}{{N}^{\left(-3\right)}} - \frac{0.25}{{N}^{4}}\right)
\] |
metadata-eval [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot {N}^{\color{blue}{-3}} - \frac{0.25}{{N}^{4}}\right)
\] |
div-inv [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot {N}^{-3} - \color{blue}{0.25 \cdot \frac{1}{{N}^{4}}}\right)
\] |
pow-flip [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot \color{blue}{{N}^{\left(-4\right)}}\right)
\] |
metadata-eval [=>]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{\color{blue}{-4}}\right)
\] |
Applied egg-rr100.0%
[Start]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{-2} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
|---|---|
metadata-eval [<=]62.9% | \[ \left(N + -0.5\right) \cdot {N}^{\color{blue}{\left(-1 + -1\right)}} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
pow-prod-up [<=]62.9% | \[ \left(N + -0.5\right) \cdot \color{blue}{\left({N}^{-1} \cdot {N}^{-1}\right)} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
pow-prod-down [=>]61.4% | \[ \left(N + -0.5\right) \cdot \color{blue}{{\left(N \cdot N\right)}^{-1}} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
inv-pow [<=]61.4% | \[ \left(N + -0.5\right) \cdot \color{blue}{\frac{1}{N \cdot N}} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
div-inv [<=]61.6% | \[ \color{blue}{\frac{N + -0.5}{N \cdot N}} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
associate-/r* [=>]100.0% | \[ \color{blue}{\frac{\frac{N + -0.5}{N}}{N}} + \left(0.3333333333333333 \cdot {N}^{-3} - 0.25 \cdot {N}^{-4}\right)
\] |
if 5.00000000000000024e-5 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 99.9%
Simplified99.9%
[Start]99.9% | \[ \log \left(N + 1\right) - \log N
\] |
|---|---|
+-commutative [=>]99.9% | \[ \log \color{blue}{\left(1 + N\right)} - \log N
\] |
log1p-def [=>]99.9% | \[ \color{blue}{\mathsf{log1p}\left(N\right)} - \log N
\] |
Applied egg-rr100.0%
[Start]99.9% | \[ \mathsf{log1p}\left(N\right) - \log N
\] |
|---|---|
log1p-udef [=>]99.9% | \[ \color{blue}{\log \left(1 + N\right)} - \log N
\] |
diff-log [=>]100.0% | \[ \color{blue}{\log \left(\frac{1 + N}{N}\right)}
\] |
+-commutative [=>]100.0% | \[ \log \left(\frac{\color{blue}{N + 1}}{N}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 27076 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 20484 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 6724 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 6660 |
| Alternative 6 | |
|---|---|
| Accuracy | 56.1% |
| Cost | 324 |
| Alternative 7 | |
|---|---|
| Accuracy | 56.6% |
| Cost | 320 |
| Alternative 8 | |
|---|---|
| Accuracy | 9.9% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
(- (log (+ N 1.0)) (log N)))