clusterlin: include topological pot subsets automatically (optimization)

Automatically add topologically-valid subsets of the potential set pot
to inc. It can be proven that these must be part of the best reachable
topologically-valid set from that work item.

This is a crucial optimization that (apparently) reduces the maximum
number of iterations from ~2^(N-1) to ~sqrt(2^N).

Co-Authored-By: Suhas Daftuar <sdaftuar@gmail.com>
This commit is contained in:
Pieter Wuille
2024-05-09 13:53:27 -04:00
parent e20fda77a2
commit 71f2629398
3 changed files with 57 additions and 6 deletions

View File

@@ -553,6 +553,12 @@ FUZZ_TARGET(clusterlin_search_finder)
// longer connected after removing certain transactions, this holds, because the connected
// components are searched separately.
assert(iterations_done <= (uint64_t{1} << (todo.Count() - 1)));
// Additionally, test that no more than sqrt(2^N)+1 iterations are required. This is just
// an empirical bound that seems to hold, without proof. Still, add a test for it so we
// can learn about counterexamples if they exist.
if (iterations_done >= 1 && todo.Count() <= 63) {
Assume((iterations_done - 1) * (iterations_done - 1) <= uint64_t{1} << todo.Count());
}
// Perform quality checks only if SearchCandidateFinder claims an optimal result.
if (iterations_done < max_iterations) {
@@ -769,6 +775,13 @@ FUZZ_TARGET(clusterlin_linearize)
if (n <= 19 && iter_count > (uint64_t{1} << n)) {
assert(optimal);
}
// Additionally, if the assumption of sqrt(2^k)+1 iterations per step holds, the maximum number
// of iterations is also bounded by (2 + sqrt(2)) * (sqrt(2^n) - 1) + n, which is less than
// (2 + sqrt(2)) * sqrt(2^n) + n. Subtracting n and squaring gives
// (6 + 4 * sqrt(2)) * 2^n < 12 * 2^n.
if (n <= 35 && iter_count > n && (iter_count - n) * (iter_count - n) >= uint64_t{12} << n) {
Assume(optimal);
}
// If Linearize claims optimal result, run quality tests.
if (optimal) {