"""Rebuild the three vector figures used in main.tex (Python 3, Matplotlib).""" from pathlib import Path from fractions import Fraction from math import isqrt, sqrt import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt from matplotlib.patches import Rectangle OUT = Path(__file__).resolve().parent.parent / "figures" OUT.mkdir(exist_ok=True) TEAL, INK, RUST, GRAY = "#12736c", "#243c50", "#a34629", "#586674" plt.rcParams.update({"font.family":"DejaVu Sans", "font.size":9, "axes.spines.top":False, "axes.spines.right":False, "axes.labelcolor":INK, "text.color":INK, "axes.edgecolor":GRAY, "xtick.color":GRAY, "ytick.color":GRAY, "pdf.fonttype":42}) def fibonacci(): g = [1, 1] for _ in range(13): g.append(3*g[-1]-g[-2]) ac = ((1+sqrt(5))/2)**4 x, y = [], [] for j in range(len(g)-2): a, b, c = g[j:j+3] x.extend([float(Fraction(b*b,a*a)), c/a]) y.extend([b/a, c/b]) x += [ac,7]; y += [sqrt(ac),8/3] fig, axes = plt.subplots(1,2,figsize=(6.36,2.43), gridspec_kw={"width_ratios":[1.1,1]}) for ax, lo, hi in zip(axes, [1,6.19], [7,6.88]): grid = [lo+(hi-lo)*i/499 for i in range(500)] ax.plot(grid,[sqrt(t) for t in grid],color=RUST,ls="--",lw=1.4,label="Volume bound") ax.plot(x,y,color=TEAL,lw=2,label="Embedding function") ax.set_xlim(lo,hi); ax.set_xlabel("Eccentricity $a$") ax.axvline(ac,lw=.8,color=GRAY,ls=":");ax.tick_params(labelsize=8) axes[0].set_ylim(.94,2.74);axes[0].set_ylabel("Ball capacity");axes[0].set_xticks([1,2,4,6,7]) axes[0].legend(loc="lower right",frameon=False,fontsize=7.5) axes[1].set_ylim(2.47,2.655);axes[1].set_xticks([6.25,6.5,6.75]) axes[1].annotate(r"$\varphi^4$",(ac,sqrt(ac)),xytext=(6.76,2.49), arrowprops=dict(arrowstyle="-",color=GRAY,lw=.8),ha="center") fig.tight_layout(pad=.45,w_pad=1.6);fig.savefig(OUT/"fibonacci.pdf");plt.close(fig) def terminal(): fig, axes = plt.subplots(1,3,figsize=(6.42,2.13)) s=.20 panels=[(1-s,1-s,1-s,r"$5-s$"),(1,1,1,r"$5$"),(1+s,1+s,1-s,r"$5+s$")] for i,(ax,(w,low,high,title)) in enumerate(zip(axes,panels)): ax.set_aspect("equal");ax.set_xlim(-.55,1.65);ax.set_ylim(-.18,2.34);ax.axis("off") ax.add_patch(Rectangle((0,0),w,2,facecolor="#f6d6bb",edgecolor=INK,lw=1.1,hatch="////")) for yy,side,color,txt in [(0,low,"#c2e1d9",r"$1-s$" if i==0 else (r"$1$" if i==1 else r"$1+s$")),(low,high,"#e7f2ee",r"$1$" if i==1 else r"$1-s$")]: ax.add_patch(Rectangle((0,yy),side,side,facecolor=color,edgecolor=INK,lw=.9)) ax.text(side/2,yy+side/2,txt,ha="center",va="center") ax.text(w/2,2.17,title,ha="center",va="center",fontsize=10) ax.text(-.20,1,"2",ha="center",va="center",fontsize=9) if i==0: ax.annotate(r"$2s$",(w*.70,2-s),xytext=(1.16,1.72),fontsize=8, arrowprops=dict(arrowstyle="-",lw=.8,color=RUST),color=RUST) if i==2: ax.annotate(r"$2s$",(1,1.72),xytext=(1.38,1.94),fontsize=8, arrowprops=dict(arrowstyle="-",lw=.8,color=RUST),color=RUST) fig.subplots_adjust(left=.02,right=.98,top=.99,bottom=.01,wspace=.05) fig.savefig(OUT/"terminal.pdf");plt.close(fig) def residue(): # x=(3+sqrt(5))/4, y=(3-sqrt(5))/4. For m>0 the radicals are irrational. # g(m)=(3m/2)-floor(mx)-floor(my)-1. All increments are halves. def twice_g(m): if m==0: return -2 root=isqrt(5*m*m) plus=(3*m+root)//4 minus=(3*m-root-1)//4 return 3*m-2*(plus+minus+1) nmax=115 allres=[] for r in range(6): acc=0; data=[] for n in range(nmax+1): acc+=twice_g(6*n+r) data.append(float(Fraction(r*(6-r),8)-Fraction(acc,2))) allres.append(data) assert set(allres[0])=={1} fig,ax=plt.subplots(figsize=(6.32,2.05)) ax.plot(range(nmax+1),allres[0],label=r"$d(6n)$",color=INK,ls="--",lw=1.25) ax.plot(range(nmax+1),[min(v) for v in zip(*allres)],color=TEAL,lw=1.3, label=r"$\min_{0\leq r<6}d(6n+r)$") ax.set_xlabel(r"$n$");ax.set_ylabel("Lattice-count error");ax.set_xlim(0,nmax) ax.legend(frameon=False,fontsize=8,loc="lower left",ncol=2);ax.set_ylim(-3.4,1.65) fig.tight_layout(pad=.45);fig.savefig(OUT/"residues.pdf");plt.close(fig) if __name__ == "__main__": fibonacci();terminal();residue()