"""Finite ramified annihilator experiment; no global estimate is claimed.

Known infinity recurrence is tested, not inferred. The candidate scalar
operator Df(mu)=f(lambda^3*mu)-sqrt(3)*f(mu) is then tested on DR's
auxiliary cusp coefficients tau_1,tau_2, (5.13),(5.14), Appendix A d_26,d_17.
These arrays have extra lambda^(-4) support. The operator fails there.
"""
import independent as I,json
from sage.rings.complex_arb import ComplexBallField
B=ComplexBallField(640);w=I.embed(I.W,B)
d=json.load(open('/work/computation.json'));rows={tuple(r['m']):r for r in d['selection']};values={m:I.coefficient(r) for m,r in rows.items()}
train=[];withheld=[]
for m,r in rows.items():
 hold=(r['norm_d']>1 or r['n']>(0 if r['branch']=='B' else 1))
 (withheld if hold else train).append(m)
tests=[]
for m,r in rows.items():
 m2=I.rep(I.mul(m,I.powe(I.LAM,3)))
 if m2 in values:
  diff=values[m2]-B(3).sqrt()*values[m];assert diff.contains_zero();I.finite_narrow(diff,500)
  tests.append({'m':m,'target':m2,'withheld_target':m2 in withheld,'difference':str(diff)})
assert any(t['withheld_target'] for t in tests)
# Cube completion includes the permitted shared prime c=d=-2.
cube=[]
for m,r in rows.items():
 for h in [(-2,0),(1,3),(-2,-3)]:
  m3=I.rep(I.mul(m,I.powe(h,3)))
  if m3 in values:
   diff=values[m3]-B(I.norm(h)).sqrt()*values[m]
   assert diff.contains_zero();cube.append({'m':m,'h':h,'target':m3,'shared_prime':r['c']==list(h),'difference':str(diff)})
assert any(t['shared_prime'] for t in cube)
# At mu=+/-omega^j*lambda^(-4)*c*d^3, tau_1 uses the plus
# sign and tau_2 the minus sign, with the formula-specific phases below.
aux=[]
for c in [(1,0),(-2,0),(1,3),(-2,-3)]:
 for h in [(1,0),(-2,0)]:
  for j in range(3):
   # tau at mu'=omega^j*lambda^-1*c*h^3 provides the same shifted
   # sum with scalar 9*sqrt(3), versus 9 in the auxiliary array.
   row={'c':list(c),'norm_c':I.norm(c),'norm_d':I.norm(h),'branch':'A','n':1,'j':j}
   base=I.coefficient(row)/B(3).sqrt()
   t1=base*[w,w**2,B(1)][j];t2=base*[w**2,B(1),w][j]
   for name,val in [('tau_1',t1),('tau_2',t2)]:
    if c==(1,0) and h==(1,0) and j==0:
     assert (val-9*(w if name=='tau_1' else w**2)).contains_zero()
     assert not (val-9*(w**2 if name=='tau_1' else w)).contains_zero()
    after=B(0);residual=after-B(3).sqrt()*val
    assert not residual.contains_zero();I.finite_narrow(residual,500)
    aux.append({'array':name,'c':c,'d':h,'j':j,'value':str(val),'after_lambda3':str(after),'scalar_annihilator_residual':str(residual)})
# Validate nonzero controls of the independent auxiliary transcription.

print(json.dumps({'training_entries':len(train),'withheld_entries':len(withheld),'ramified_tests':tests,'cube_tests':cube,'auxiliary_counterexamples':aux,'scalar_extension_rejected':True,'next_lemma':'An operator on the full cusp coefficient vector, including nonunit projections, must have compatible action under the reflection/Voronoi transform and preserve required weight decay. Infinity coefficients alone do not establish this.','global_estimate':'unresolved; no zero-free-region or RH claim'}))
