File size: 9,022 Bytes
d1c6c9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
"""Generate exact tables and explicitly labeled model illustrations.

Run from any working directory. No network access is required. Figures are not
experimental physical data; CSV/JSON values follow the manuscript's formulas.
"""
from __future__ import annotations
import csv
import json
import math
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'src'))
import numpy as np
import sympy as sp
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from noulith import TwistedAlgebra
from noulith.protocols import root_profile
from noulith.geometry import line_arrangement_generators


def write_csv(name: str, rows: list[dict]) -> None:
    with (ROOT / 'data' / name).open('w', newline='', encoding='utf-8') as file:
        writer = csv.DictWriter(file, fieldnames=list(rows[0]))
        writer.writeheader()
        writer.writerows(rows)


def save(fig, name: str) -> None:
    fig.tight_layout()
    fig.savefig(ROOT / 'figures' / f'{name}.pdf', bbox_inches='tight')
    fig.savefig(ROOT / 'figures' / f'{name}.png', dpi=180, bbox_inches='tight')
    plt.close(fig)


def main() -> None:
    (ROOT / 'data').mkdir(exist_ok=True)
    (ROOT / 'figures').mkdir(exist_ok=True)
    gap_rows = []
    for p in range(2, 17):
        m = 2
        while math.comb(m, 2) < p + 1:
            m += 1
        gap_rows.append(dict(p=p, channels=m, state_dimension=2**m,
            length_J=p*p, length_K=p*(p+1)//2,
            length_gap=p*(p-1)//2, minimal_protocols_J=2**m+1,
            minimal_protocols_K=2**m+p, protocol_gap=p-1))
    write_csv('arc_blind_family.csv', gap_rows)
    fig, ax = plt.subplots(figsize=(6.6, 3.9))
    ax.plot([r['p'] for r in gap_rows], [r['length_J'] for r in gap_rows], 'o-', label=r'$\dim R/(a^p,b^p)=p^2$')
    ax.plot([r['p'] for r in gap_rows], [r['length_K'] for r in gap_rows], 's-', label=r'$\dim R/(a,b)^p=p(p+1)/2$')
    ax.set(xlabel='Power p', ylabel='Local algebra length', title='Equal arc orders, different analytic defects')
    ax.legend(); ax.grid(True, alpha=.25)
    save(fig, 'arc_blind_lengths')

    root_rows = []
    for ell in range(2, 8):
        for d in range(0, 25):
            for r in range(1, 9):
                root_rows.append(dict(root_order=ell, degree=d, blocks=r,
                    exponent=int(root_profile(d, r, ell))))
    write_csv('root_budget_profiles.csv', root_rows)
    fig, ax = plt.subplots(figsize=(6.6, 3.9))
    degrees = list(range(25))
    for r in (1, 2, 3, 5):
        ax.step(degrees, [root_profile(d,r,3) for d in degrees], where='mid', label=f'{r} block(s)')
    ax.set(xlabel='Complement degree d', ylabel='Vanishing exponent', title='Third-root resonance: block budget versus order')
    ax.set_xticks(range(0,25,3)); ax.legend(); ax.grid(True, alpha=.25)
    save(fig, 'root_budget_profiles')

    jet_rows=[]
    m, ell = 12, 3
    grid=[]
    for k in range(5):
        gridrow=[]
        for r in range(1,7):
            threshold=min(m, r*(ell-1)+ell*k)
            rank=sum(math.comb(m,d) for d in range(threshold+1))
            jet_rows.append(dict(channels=m, root_order=ell, blocks=r, jet_order=k, rank=rank, dimension=2**m))
            gridrow.append(rank/(2**m))
        grid.append(gridrow)
    for r in range(1,5):
        for k in range(3):
            rank=sum(math.comb(8,d) for d in range(min(8,2*r+3*k)+1))
            jet_rows.append(dict(channels=8,root_order=3,blocks=r,jet_order=k,rank=rank,dimension=256))
    write_csv('root_jet_visibility.csv',jet_rows)
    fig, ax = plt.subplots(figsize=(6.6, 3.9))
    im=ax.imshow(np.array(grid),origin='lower',aspect='auto',extent=(.5,6.5,-.5,4.5),vmin=0,vmax=1)
    ax.set(xlabel='Block budget r',ylabel='Parameter jet order k',title='Visible constant-state fraction: m = 12, root order 3')
    fig.colorbar(im,ax=ax,label='Visible fraction')
    save(fig,'jet_visibility')

    hilbert_rows=[]
    for m in range(4,11):
        for degree in range(8):
            value = 1 if degree==0 else (m-1 if degree==1 else m)
            hilbert_rows.append(dict(channels=m,degree=degree,hilbert_function=value))
    write_csv('branch_hilbert_functions.csv',hilbert_rows)
    fig,ax=plt.subplots(figsize=(6.6,3.9))
    for m in (4,6,8):
        ax.plot(range(8), [1,m-1]+[m]*6,'o-',label=f'{m} branches')
    ax.set(xlabel='Degree',ylabel='Graded dimension',title='Exact second-deficit branch-ring Hilbert functions')
    ax.set_xticks(range(8)); ax.legend(); ax.grid(True,alpha=.25)
    save(fig,'branch_hilbert')

    # Geometric illustration of the exact normal form in three log-coordinates.
    fig=plt.figure(figsize=(6.3,4.5))
    ax=fig.add_subplot(projection='3d')
    ts=np.linspace(-1,1,101)
    for direction,label in (([1,0,0],'channel 2 outlier'),([0,1,0],'channel 3 outlier'),
                            ([0,0,1],'channel 4 outlier'),([1,1,1],'channel 1 outlier')):
        a=np.outer(ts,np.array(direction,dtype=float))
        ax.plot(a[:,0],a[:,1],a[:,2],label=label)
    ax.set(xlabel=r'$z_2$',ylabel=r'$z_3$',zlabel=r'$z_4$',title='Four-channel resonance germ in logarithmic coordinates')
    ax.legend(loc='upper left',fontsize=7)
    save(fig,'four_branch_geometry')

    # Numerical illustration only; exact valuation claims have independent tests.
    import mpmath as mp
    mp.mp.dps=65
    zeta=mp.exp(2*mp.pi*1j/3)
    def qfac(d,q):
        return mp.fprod(mp.fsum(q**j for j in range(k)) for k in range(1,d+1))
    detuning_rows=[]
    figureseries=[]
    for composition in ((6,),(2,4),(2,2,2)):
        values=[]
        for exponent in np.linspace(-5,-1,41):
            t=mp.mpf(str(10**float(exponent)))
            value=abs(mp.fprod(qfac(d,zeta*(1+t)) for d in composition))
            values.append(float(value))
            detuning_rows.append(dict(composition='+'.join(map(str,composition)),t=float(t),amplitude=float(value),
                predicted_order=sum(d//3 for d in composition)))
        figureseries.append((composition, values))
    write_csv('detuning_amplitudes.csv',detuning_rows)
    fig,ax=plt.subplots(figsize=(6.6,3.9))
    ts=np.logspace(-5,-1,41)
    for composition,values in figureseries:
        ax.loglog(ts,values,label=' + '.join(map(str,composition))+f' ; order {sum(d//3 for d in composition)}')
    ax.set(xlabel='Detuning t',ylabel='Normalized isolated coefficient magnitude',title='Depth six: the cost of restricting block changes')
    ax.legend(); ax.grid(True,which='both',alpha=.25)
    save(fig,'detuning_amplitudes')

    A,B,C=sp.symbols('A B C')
    algebra=TwistedAlgebra(3,{(0,1):-1+A,(0,2):-1+B,(1,2):-1+C})
    triple=sp.expand(algebra.shuffle_table()[-1])
    z=sp.symbols('z2:5')
    certificate=dict(triple_shuffle=str(triple),
        expected_triple='A*B*C - A*C + A - B + C',
        four_branch_ideal=[str(x) for x in line_arrangement_generators(z)],
        definitions='Illustrations of proved abstract-model formulas; not physical experiments.',
        exactness={'tables':'integer arithmetic except detuning_amplitudes.csv',
            'detuning':'65-digit mpmath evaluation exported as binary64 decimal values'})
    assert sp.expand(triple-(A*B*C-A*C+A-B+C))==0
    (ROOT/'data'/'symbolic_certificates.json').write_text(json.dumps(certificate,indent=2)+'\n')

    # Exact full-state ranks, distinct from the scalar branch curve.
    strata=[]
    for m in range(4,13):
        n=2**m
        for stratum,loss in [('outside_stars',0),('generic_single_star',1),
            ('nonzero_outlier_branch',2),('nonzero_two_star_intersection',2),('exterior_origin',m+1)]:
            strata.append(dict(channels=m,blocks=m-2,stratum=stratum,rank=n-loss,state_dimension=n))
    write_csv('full_state_rank_strata.csv',strata)

    # Editable TeX tables are generated from exact data, not handwritten values.
    arc=[r'\begin{center}',r'\begin{tabular}{rrrrrrr}',r'\toprule',
         r'$p$ & $m$ & $2^m$ & $\dim R/J_p$ & $\dim R/K_p$ & $N(J_p)$ & $N(K_p)$\\',r'\midrule']
    for row in gap_rows[:7]:
        keys=['p','channels','state_dimension','length_J','length_K','minimal_protocols_J','minimal_protocols_K']
        arc.append(' & '.join(str(row[key]) for key in keys)+r'\\')
    arc += [r'\bottomrule',r'\end{tabular}',r'\end{center}']
    (ROOT/'manuscript'/'generated_arc_table.tex').write_text('\n'.join(arc)+'\n')
    jet=[r'\begin{center}',r'\begin{tabular}{rrrr}',r'\toprule',
         r'Blocks $r$ & Jet $k=0$ & Jet $k=1$ & Jet $k=2$\\',r'\midrule']
    for r in range(1,5):
        counts=[next(row['rank'] for row in jet_rows if row['channels']==8 and row['blocks']==r and row['jet_order']==k) for k in range(3)]
        jet.append(' & '.join(map(str,[r]+counts))+r'\\')
    jet += [r'\bottomrule',r'\end{tabular}',r'\end{center}']
    (ROOT/'manuscript'/'generated_jet_table.tex').write_text('\n'.join(jet)+'\n')

    print('Generated six figures, six CSV tables, two TeX tables, and symbolic_certificates.json.')

if __name__=='__main__':
    main()