"""Draw the exact fixed-budget frontier for r=3 (Corollary 2.3).""" from pathlib import Path import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from math import isqrt def prime(n): return n >= 2 and all(n % k for k in range(2, isqrt(n) + 1)) def draw(output): r, limit = 3, 54 costs = [(q - 1, q) for q in range(2, limit + 2) if prime(q) and (q - 1) % r == 0] costs.append((r * (r - 1), r * r)) budgets, conductors = [0], [] for cost, conductor in sorted(costs): if budgets[-1] + cost > limit: break budgets.append(budgets[-1] + cost) conductors.append(conductor) assert budgets == [0, 6, 12, 24, 42] fig, ax = plt.subplots(figsize=(6.1, 1.98)) levels = list(range(len(budgets))) ax.step(budgets + [limit], levels + [levels[-1]], where="post", color="#1c5857", linewidth=1.65) ax.scatter(budgets, levels, s=13, color="#1c5857", zorder=3) for level, (budget, conductor) in enumerate(zip(budgets[1:], conductors), 1): ax.annotate(r"$\Phi_{%d}$" % conductor, (budget, level), xytext=(5, 5), textcoords="offset points", fontsize=9) ax.set_xticks(budgets) ax.set_xlim(-1, limit) ax.set_ylim(-0.15, levels[-1] + 0.62) ax.set_yticks(levels, ["0"] + [f"{r**j-1}/{r**j}" for j in levels[1:]]) ax.set_xlabel("Total polynomial degree available", fontsize=9) ax.set_ylabel("Fraction covered", fontsize=9) ax.tick_params(labelsize=8, length=3) ax.grid(axis="y", color="#dadfdf", linewidth=0.5) ax.set_axisbelow(True) ax.spines[["top", "right"]].set_visible(False) fig.tight_layout(pad=0.4) fig.savefig(output, metadata={"Title": "Optimal limiting coverage for cubic witnesses", "CreationDate": None, "ModDate": None}) plt.close(fig) if __name__ == "__main__": draw(Path(__file__).with_suffix(".pdf"))