from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch
matplotlib.rcParams.update({'font.family':'DejaVu Sans','svg.hashsalt':'oa-classify-alternating-comparison-v1','mathtext.fontset':'dejavusans'})
dest=Path(__file__).resolve().parent
fig,ax=plt.subplots(figsize=(6.4,18.5));ax.set_xlim(0,1);ax.set_ylim(0,1);ax.axis('off');fig.subplots_adjust(left=.025,right=.975,top=.985,bottom=.012)
def box(y,h,color):ax.add_patch(FancyBboxPatch((.055,y),.89,h,boxstyle='round,pad=0.014,rounding_size=0.008',facecolor=color,edgecolor='#24536b',linewidth=1.4))
def text(y,s,size=15):ax.text(.5,y,s,ha='center',va='center',fontsize=size,color='#102d40')
text(.975,'Alternate, then take both limits',20)
box(.66,.265,'#e9f3fc');text(.903,'1. Prepare the source package',18)
text(.865,r'$R_n,\ B_n,\ \vartheta_n\ \longrightarrow\ \mathcal{X}_n,\ \kappa_n$',18)
text(.823,r'$R_n\ \longleftrightarrow\ R_{n+1}$',20)
text(.798,r'Error $<\kappa_n/4$ on the stored tests',13)
text(.755,r'$R_{n+1}\ \longleftrightarrow\ \mathrm{Ad}(u_{n+2})R_n$',18)
text(.732,r'Error $<\kappa_n/4$ on the same tests',13)
text(.690,r'$\|[u_{n+2,s},\chi]\|<\kappa_n/2$',18)
ax.annotate('',xy=(.5,.635),xytext=(.5,.645),arrowprops={'arrowstyle':'->','color':'#24536b','lw':1.4})
box(.345,.265,'#e8f5ef');text(.588,'2. Keep the compared action',18)
text(.550,r'$w_g=u_g\delta_g(z)z^*$',20)
text(.512,r'$\mathrm{Ad}(w_g)\delta_g^z=\mathrm{Ad}(u_g)\delta_g$',17)
text(.471,r'$B_{n+2,g}=w_g\,zB_{n,g}z^*$',19)
text(.425,r'$\varphi,\quad\varphi\circ\mathrm{Ad}(B_{n,g}^*)$',18)
text(.394,r'$r=a/8,\quad c=a^2/256$',17)
text(.365,r'$\|B_{n+2,g}-B_{n,g}\|_\varphi^\sharp<a$',17)
ax.annotate('',xy=(.5,.320),xytext=(.5,.331),arrowprops={'arrowstyle':'->','color':'#24536b','lw':1.4})
box(.075,.220,'#fff0e8');text(.273,'3. Pass both parity rows to limits',17)
text(.232,r'$\vartheta_{2m}\to\sigma,\quad\vartheta_{2m+1}\to\tau$',19)
text(.204,'Forward and inverse predual tests are summable.',12)
text(.171,r'$B_{2m,g}\to X_g,\quad B_{2m+1,g}\to Y_g$',19)
text(.129,r'$\theta=\sigma^{-1}\tau,\quad v_g=\sigma^{-1}(Y_g^*X_g)$',17)
text(.094,r'$\mathrm{Ad}(v_g)\alpha_g=\theta\beta_g\theta^{-1}$',19)
text(.040,'Proof: (3.3), (4.5)–(4.6), (5.3)–(6.6), (7.1)–(7.3)',11)
text(.022,'Exact schedule and algebraic limits; no numerical convergence model.',10)
fig.savefig(dest/'alternating-comparison.svg',metadata={'Date':None});fig.savefig(dest/'alternating-comparison.png',dpi=180,metadata={'Software':'OA-CLASSIFY reproducible figure'});plt.close(fig)
